Merge pull request #12572 from Budibase/feature/uuid-helper
HBS/JS UUID helper
This commit is contained in:
commit
22c0e81308
|
@ -79,6 +79,7 @@
|
||||||
bind:this={popover}
|
bind:this={popover}
|
||||||
anchor={popoverAnchor}
|
anchor={popoverAnchor}
|
||||||
maxWidth={300}
|
maxWidth={300}
|
||||||
|
maxHeight={300}
|
||||||
dismissible={false}
|
dismissible={false}
|
||||||
>
|
>
|
||||||
<Layout gap="S">
|
<Layout gap="S">
|
||||||
|
|
|
@ -1180,6 +1180,14 @@
|
||||||
"description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n"
|
"description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"uuid": {
|
||||||
|
"uuid": {
|
||||||
|
"args": [],
|
||||||
|
"numArgs": 0,
|
||||||
|
"example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc",
|
||||||
|
"description": "<p>Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).</p>\n"
|
||||||
|
}
|
||||||
|
},
|
||||||
"date": {
|
"date": {
|
||||||
"date": {
|
"date": {
|
||||||
"args": [
|
"args": [
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
"manifest": "node ./scripts/gen-collection-info.js"
|
"manifest": "node ./scripts/gen-collection-info.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@budibase/handlebars-helpers": "^0.11.9",
|
"@budibase/handlebars-helpers": "^0.11.11",
|
||||||
"dayjs": "^1.10.8",
|
"dayjs": "^1.10.8",
|
||||||
"handlebars": "^4.7.6",
|
"handlebars": "^4.7.6",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
|
|
|
@ -20,6 +20,7 @@ const COLLECTIONS = [
|
||||||
"string",
|
"string",
|
||||||
"comparison",
|
"comparison",
|
||||||
"object",
|
"object",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
const FILENAME = join(__dirname, "..", "manifest.json")
|
const FILENAME = join(__dirname, "..", "manifest.json")
|
||||||
const outputJSON = {}
|
const outputJSON = {}
|
||||||
|
|
|
@ -16,6 +16,7 @@ const EXTERNAL_FUNCTION_COLLECTIONS = [
|
||||||
"comparison",
|
"comparison",
|
||||||
"object",
|
"object",
|
||||||
"regex",
|
"regex",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
const ADDED_HELPERS = {
|
const ADDED_HELPERS = {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
module.exports.UUID_REGEX =
|
||||||
|
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
|
@ -1,6 +1,7 @@
|
||||||
const { processString, processObject, isValid } = require("../src/index.cjs")
|
const { processString, processObject, isValid } = require("../src/index.cjs")
|
||||||
const tableJson = require("./examples/table.json")
|
const tableJson = require("./examples/table.json")
|
||||||
const dayjs = require("dayjs")
|
const dayjs = require("dayjs")
|
||||||
|
const { UUID_REGEX } = require("./constants")
|
||||||
|
|
||||||
describe("test the custom helpers we have applied", () => {
|
describe("test the custom helpers we have applied", () => {
|
||||||
it("should be able to use the object helper", async () => {
|
it("should be able to use the object helper", async () => {
|
||||||
|
@ -477,3 +478,10 @@ describe("Cover a few complex use cases", () => {
|
||||||
expect(output.dataProvider).toBe("%5B%221%22%2C%221%22%5D")
|
expect(output.dataProvider).toBe("%5B%221%22%2C%221%22%5D")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("uuid", () => {
|
||||||
|
it("should be able to generate a UUID", async () => {
|
||||||
|
const output = await processString("{{ uuid }}", {})
|
||||||
|
expect(output).toMatch(UUID_REGEX)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const { processStringSync, encodeJSBinding } = require("../src/index.cjs")
|
const { processStringSync, encodeJSBinding } = require("../src/index.cjs")
|
||||||
|
const { UUID_REGEX } = require("./constants")
|
||||||
|
|
||||||
const processJS = (js, context) => {
|
const processJS = (js, context) => {
|
||||||
return processStringSync(encodeJSBinding(js), context)
|
return processStringSync(encodeJSBinding(js), context)
|
||||||
|
@ -140,4 +141,9 @@ describe("check JS helpers", () => {
|
||||||
const output = processJS(`return helpers.toInt(4.3)`)
|
const output = processJS(`return helpers.toInt(4.3)`)
|
||||||
expect(output).toBe(4)
|
expect(output).toBe(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should be able to use uuid", () => {
|
||||||
|
const output = processJS(`return helpers.uuid()`)
|
||||||
|
expect(output).toMatch(UUID_REGEX)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue