forked from tsai/budibase
6 changed files with 71 additions and 8 deletions
@ -1,9 +1,43 @@ |
|||||
|
const { LITERAL_MARKER } = require("../helpers/constants") |
||||
|
|
||||
|
const PostProcessorNames = { |
||||
|
CONVERT_LITERALS: "convert-literals", |
||||
|
} |
||||
|
|
||||
/* eslint-disable no-unused-vars */ |
/* eslint-disable no-unused-vars */ |
||||
class Postprocessor { |
class Postprocessor { |
||||
constructor(name, fn) { |
constructor(name, fn) { |
||||
this.name = name |
this.name = name |
||||
this.fn = fn |
this.fn = fn |
||||
} |
} |
||||
|
|
||||
|
process(statement) { |
||||
|
return this.fn(statement) |
||||
|
} |
||||
} |
} |
||||
|
|
||||
module.exports.processors = [] |
module.exports.processors = [ |
||||
|
new Postprocessor(PostProcessorNames.CONVERT_LITERALS, statement => { |
||||
|
if (!statement.includes(LITERAL_MARKER)) { |
||||
|
return statement |
||||
|
} |
||||
|
|
||||
|
const components = statement.split("-") |
||||
|
// pop and shift remove the empty array elements from the first and last dash
|
||||
|
components.pop() |
||||
|
components.shift() |
||||
|
const type = components[1] |
||||
|
const value = components[2] |
||||
|
switch (type) { |
||||
|
case "string": |
||||
|
return value |
||||
|
case "number": |
||||
|
return parseFloat(value) |
||||
|
case "boolean": |
||||
|
return value === "true" |
||||
|
case "object": |
||||
|
return JSON.parse(value) |
||||
|
} |
||||
|
return value |
||||
|
}) |
||||
|
] |
||||
|
|||||
Loading…
Reference in new issue