@budibase/string-templates 2.16.0 → 2.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.mjs +1 -1
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/list.d.ts +2 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +2 -1
- package/manifest.json +281 -149
- package/package.json +3 -3
- package/src/conversion/index.js +2 -2
- package/src/helpers/date.js +1 -1
- package/src/helpers/index.js +2 -2
- package/src/helpers/javascript.js +2 -2
- package/src/helpers/list.js +10 -2
- package/src/index.cjs +1 -0
- package/src/index.js +2 -0
- package/src/index.mjs +1 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@budibase/string-templates",
|
3
|
-
"version": "2.16.
|
3
|
+
"version": "2.16.1",
|
4
4
|
"description": "Handlebars wrapper for Budibase templating.",
|
5
5
|
"main": "src/index.cjs",
|
6
6
|
"module": "dist/bundle.mjs",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"manifest": "node ./scripts/gen-collection-info.js"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"@budibase/handlebars-helpers": "^0.13.
|
28
|
+
"@budibase/handlebars-helpers": "^0.13.1",
|
29
29
|
"dayjs": "^1.10.8",
|
30
30
|
"handlebars": "^4.7.6",
|
31
31
|
"lodash.clonedeep": "^4.5.0",
|
@@ -45,5 +45,5 @@
|
|
45
45
|
"rollup-plugin-terser": "^7.0.2",
|
46
46
|
"typescript": "5.2.2"
|
47
47
|
},
|
48
|
-
"gitHead": "
|
48
|
+
"gitHead": "125c5bf609dd0befb8c4d387dc841412b6dc91f8"
|
49
49
|
}
|
package/src/conversion/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const {
|
1
|
+
const { getJsHelperList } = require("../helpers")
|
2
2
|
|
3
3
|
function getLayers(fullBlock) {
|
4
4
|
let layers = []
|
@@ -109,7 +109,7 @@ module.exports.convertHBSBlock = (block, blockNumber) => {
|
|
109
109
|
const layers = getLayers(block)
|
110
110
|
|
111
111
|
let value = null
|
112
|
-
const list =
|
112
|
+
const list = getJsHelperList()
|
113
113
|
for (let layer of layers) {
|
114
114
|
const parts = splitBySpace(layer)
|
115
115
|
if (value || parts.length > 1 || list[parts[0]]) {
|
package/src/helpers/date.js
CHANGED
@@ -115,7 +115,7 @@ module.exports.duration = (str, pattern, format) => {
|
|
115
115
|
setLocale(config.str, config.pattern)
|
116
116
|
|
117
117
|
const duration = dayjs.duration(config.str, config.pattern)
|
118
|
-
if (!isOptions(format)) {
|
118
|
+
if (format && !isOptions(format)) {
|
119
119
|
return duration.format(format)
|
120
120
|
} else {
|
121
121
|
return duration.humanize()
|
package/src/helpers/index.js
CHANGED
@@ -7,7 +7,7 @@ const {
|
|
7
7
|
HelperFunctionBuiltin,
|
8
8
|
LITERAL_MARKER,
|
9
9
|
} = require("./constants")
|
10
|
-
const {
|
10
|
+
const { getJsHelperList } = require("./list")
|
11
11
|
|
12
12
|
const HTML_SWAPS = {
|
13
13
|
"<": "<",
|
@@ -97,4 +97,4 @@ module.exports.unregisterAll = handlebars => {
|
|
97
97
|
externalHandlebars.unregisterAll(handlebars)
|
98
98
|
}
|
99
99
|
|
100
|
-
module.exports.
|
100
|
+
module.exports.getJsHelperList = getJsHelperList
|
@@ -1,7 +1,7 @@
|
|
1
1
|
const { atob } = require("../utilities")
|
2
2
|
const cloneDeep = require("lodash.clonedeep")
|
3
3
|
const { LITERAL_MARKER } = require("../helpers/constants")
|
4
|
-
const {
|
4
|
+
const { getJsHelperList } = require("./list")
|
5
5
|
|
6
6
|
// The method of executing JS scripts depends on the bundle being built.
|
7
7
|
// This setter is used in the entrypoint (either index.cjs or index.mjs).
|
@@ -49,7 +49,7 @@ module.exports.processJS = (handlebars, context) => {
|
|
49
49
|
// app context.
|
50
50
|
const sandboxContext = {
|
51
51
|
$: path => getContextValue(path, cloneDeep(context)),
|
52
|
-
helpers:
|
52
|
+
helpers: getJsHelperList(),
|
53
53
|
}
|
54
54
|
|
55
55
|
// Create a sandbox with our context and run the JS
|
package/src/helpers/list.js
CHANGED
@@ -3,7 +3,10 @@ const helperList = require("@budibase/handlebars-helpers")
|
|
3
3
|
|
4
4
|
let helpers = undefined
|
5
5
|
|
6
|
-
|
6
|
+
const helpersToRemoveForJs = ["sortBy"]
|
7
|
+
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
8
|
+
|
9
|
+
module.exports.getJsHelperList = () => {
|
7
10
|
if (helpers) {
|
8
11
|
return helpers
|
9
12
|
}
|
@@ -15,12 +18,17 @@ module.exports.getHelperList = () => {
|
|
15
18
|
}
|
16
19
|
for (let collection of constructed) {
|
17
20
|
for (let [key, func] of Object.entries(collection)) {
|
18
|
-
helpers
|
21
|
+
// Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it
|
22
|
+
helpers[key] = (...props) => func(...props, {})
|
19
23
|
}
|
20
24
|
}
|
21
25
|
for (let key of Object.keys(externalHandlebars.addedHelpers)) {
|
22
26
|
helpers[key] = externalHandlebars.addedHelpers[key]
|
23
27
|
}
|
28
|
+
|
29
|
+
for (const toRemove of helpersToRemoveForJs) {
|
30
|
+
delete helpers[toRemove]
|
31
|
+
}
|
24
32
|
Object.freeze(helpers)
|
25
33
|
return helpers
|
26
34
|
}
|
package/src/index.cjs
CHANGED
@@ -20,6 +20,7 @@ module.exports.findHBSBlocks = templates.findHBSBlocks
|
|
20
20
|
module.exports.convertToJS = templates.convertToJS
|
21
21
|
module.exports.setJSRunner = templates.setJSRunner
|
22
22
|
module.exports.FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
|
23
|
+
module.exports.helpersToRemoveForJs = templates.helpersToRemoveForJs
|
23
24
|
|
24
25
|
if (!process.env.NO_JS) {
|
25
26
|
const { VM } = require("vm2")
|
package/src/index.js
CHANGED
@@ -10,6 +10,7 @@ const {
|
|
10
10
|
} = require("./utilities")
|
11
11
|
const { convertHBSBlock } = require("./conversion")
|
12
12
|
const javascript = require("./helpers/javascript")
|
13
|
+
const { helpersToRemoveForJs } = require("./helpers/list")
|
13
14
|
|
14
15
|
const hbsInstance = handlebars.create()
|
15
16
|
registerAll(hbsInstance)
|
@@ -394,3 +395,4 @@ module.exports.convertToJS = hbs => {
|
|
394
395
|
}
|
395
396
|
|
396
397
|
module.exports.FIND_ANY_HBS_REGEX = FIND_ANY_HBS_REGEX
|
398
|
+
module.exports.helpersToRemoveForJs = helpersToRemoveForJs
|
package/src/index.mjs
CHANGED
@@ -21,6 +21,7 @@ export const findHBSBlocks = templates.findHBSBlocks
|
|
21
21
|
export const convertToJS = templates.convertToJS
|
22
22
|
export const setJSRunner = templates.setJSRunner
|
23
23
|
export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
|
24
|
+
export const helpersToRemoveForJs = templates.helpersToRemoveForJs
|
24
25
|
|
25
26
|
if (process && !process.env.NO_JS) {
|
26
27
|
/**
|