Merge branch 'lab-day-search' of github.com:Budibase/budibase into lab-day-search
This commit is contained in:
commit
023f5c5813
|
@ -4,7 +4,7 @@ const processors = require("./processors")
|
|||
const { cloneDeep } = require("lodash/fp")
|
||||
const {
|
||||
removeNull,
|
||||
addConstants,
|
||||
updateContext,
|
||||
removeHandlebarsStatements,
|
||||
} = require("./utilities")
|
||||
const manifest = require("../manifest.json")
|
||||
|
@ -92,8 +92,7 @@ module.exports.processStringSync = (string, context) => {
|
|||
}
|
||||
// take a copy of input incase error
|
||||
const input = string
|
||||
let clonedContext = removeNull(cloneDeep(context))
|
||||
clonedContext = addConstants(clonedContext)
|
||||
const clonedContext = removeNull(updateContext(cloneDeep(context)))
|
||||
// remove any null/undefined properties
|
||||
if (typeof string !== "string") {
|
||||
throw "Cannot process non-string types."
|
||||
|
|
|
@ -23,11 +23,24 @@ module.exports.removeNull = obj => {
|
|||
return obj
|
||||
}
|
||||
|
||||
module.exports.addConstants = obj => {
|
||||
module.exports.updateContext = obj => {
|
||||
if (obj.now == null) {
|
||||
obj.now = new Date()
|
||||
obj.now = (new Date()).toISOString()
|
||||
}
|
||||
function recurse(obj) {
|
||||
for (let key of Object.keys(obj)) {
|
||||
if (!obj[key]) {
|
||||
continue
|
||||
}
|
||||
if (obj[key] instanceof Date) {
|
||||
obj[key] = obj[key].toISOString()
|
||||
} else if (typeof obj[key] === "object") {
|
||||
obj[key] = recurse(obj[key])
|
||||
}
|
||||
}
|
||||
return obj
|
||||
}
|
||||
return recurse(obj)
|
||||
}
|
||||
|
||||
module.exports.removeHandlebarsStatements = string => {
|
||||
|
|
|
@ -107,6 +107,12 @@ describe("check the utility functions", () => {
|
|||
const property = makePropSafe("thing")
|
||||
expect(property).toEqual("[thing]")
|
||||
})
|
||||
|
||||
it("should be able to handle an input date object", async () => {
|
||||
const date = new Date()
|
||||
const output = await processString("{{ dateObj }}", { dateObj: date })
|
||||
expect(date.toISOString()).toEqual(output)
|
||||
})
|
||||
})
|
||||
|
||||
describe("check manifest", () => {
|
||||
|
|
Loading…
Reference in New Issue