@budibase/string-templates 2.2.26 → 2.2.27-alpha.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/package.json +2 -2
- package/src/helpers/index.js +5 -1
- package/src/index.js +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/string-templates",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.27-alpha.1",
|
|
4
4
|
"description": "Handlebars wrapper for Budibase templating.",
|
|
5
5
|
"main": "src/index.cjs",
|
|
6
6
|
"module": "dist/bundle.mjs",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"rollup-plugin-terser": "^7.0.2",
|
|
47
47
|
"typescript": "4.7.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "90a1d96a205fe5355653640655eb7844dba1d789"
|
|
50
50
|
}
|
package/src/helpers/index.js
CHANGED
|
@@ -32,11 +32,15 @@ const HELPERS = [
|
|
|
32
32
|
// javascript helper
|
|
33
33
|
new Helper(HelperFunctionNames.JS, processJS, false),
|
|
34
34
|
// this help is applied to all statements
|
|
35
|
-
new Helper(HelperFunctionNames.ALL, (value,
|
|
35
|
+
new Helper(HelperFunctionNames.ALL, (value, inputs) => {
|
|
36
|
+
const { __opts } = inputs
|
|
36
37
|
if (isObject(value)) {
|
|
37
38
|
return new SafeString(JSON.stringify(value))
|
|
38
39
|
}
|
|
39
40
|
// null/undefined values produce bad results
|
|
41
|
+
if (__opts && __opts.onlyFound && value == null) {
|
|
42
|
+
return __opts.input
|
|
43
|
+
}
|
|
40
44
|
if (value == null || typeof value !== "string") {
|
|
41
45
|
return value == null ? "" : value
|
|
42
46
|
}
|
package/src/index.js
CHANGED
|
@@ -146,16 +146,31 @@ module.exports.processStringSync = (string, context, opts) => {
|
|
|
146
146
|
if (typeof string !== "string") {
|
|
147
147
|
throw "Cannot process non-string types."
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
const template = createTemplate(
|
|
149
|
+
function process(stringPart) {
|
|
150
|
+
const template = createTemplate(stringPart, opts)
|
|
151
151
|
const now = Math.floor(Date.now() / 1000) * 1000
|
|
152
152
|
return processors.postprocess(
|
|
153
153
|
template({
|
|
154
154
|
now: new Date(now).toISOString(),
|
|
155
|
-
__opts:
|
|
155
|
+
__opts: {
|
|
156
|
+
...opts,
|
|
157
|
+
input: stringPart,
|
|
158
|
+
},
|
|
156
159
|
...context,
|
|
157
160
|
})
|
|
158
161
|
)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
if (opts && opts.onlyFound) {
|
|
165
|
+
const blocks = exports.findHBSBlocks(string)
|
|
166
|
+
for (let block of blocks) {
|
|
167
|
+
const outcome = process(block)
|
|
168
|
+
string = string.replace(block, outcome)
|
|
169
|
+
}
|
|
170
|
+
return string
|
|
171
|
+
} else {
|
|
172
|
+
return process(string)
|
|
173
|
+
}
|
|
159
174
|
} catch (err) {
|
|
160
175
|
return input
|
|
161
176
|
}
|