mikel 0.37.0 → 0.38.0
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/index.d.ts +3 -3
- package/index.js +5 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type MikelHelper = (params: {
|
|
|
12
12
|
fn: MikelHelperCallback;
|
|
13
13
|
}) => string;
|
|
14
14
|
|
|
15
|
-
export type MikelPartial = {
|
|
15
|
+
export type MikelPartial = string | {
|
|
16
16
|
body: string;
|
|
17
17
|
data: Record<string, any>;
|
|
18
18
|
};
|
|
@@ -28,7 +28,7 @@ export type MikelState = Record<string, string>;
|
|
|
28
28
|
|
|
29
29
|
export type MikelOptions = {
|
|
30
30
|
helpers?: Record<string, MikelHelper>;
|
|
31
|
-
partials?: Record<string,
|
|
31
|
+
partials?: Record<string, MikelPartial>;
|
|
32
32
|
functions?: Record<string, MikelFunction>;
|
|
33
33
|
};
|
|
34
34
|
|
|
@@ -52,7 +52,7 @@ export type Mikel = {
|
|
|
52
52
|
removeHelper(name: string): void;
|
|
53
53
|
addFunction(name: string, fn: MikelFunction): void;
|
|
54
54
|
removeFunction(name: string): void;
|
|
55
|
-
addPartial(name: string, partial:
|
|
55
|
+
addPartial(name: string, partial: MikelPartial): void;
|
|
56
56
|
removePartial(name: string): void;
|
|
57
57
|
};
|
|
58
58
|
|
package/index.js
CHANGED
|
@@ -29,8 +29,8 @@ const untokenize = (ts = [], s = "{{", e = "}}") => {
|
|
|
29
29
|
// @description tokenize args
|
|
30
30
|
const tokenizeArgs = (str = "", tokens = [], strings = []) => {
|
|
31
31
|
let current = "", depth = 0;
|
|
32
|
-
// 1. replace strings
|
|
33
|
-
str = str.replace(/"([^"\\]|\\.)*"/g, (match) => {
|
|
32
|
+
// 1. replace strings in single/double quotes
|
|
33
|
+
str = str.replace(/("([^"\\]|\\.)*"|'([^'\\]|\\.)*')/g, (match) => {
|
|
34
34
|
const id = `__STR${strings.length}__`;
|
|
35
35
|
strings.push(match);
|
|
36
36
|
return id;
|
|
@@ -100,8 +100,9 @@ const parse = (v, data = {}, state = {}, fns = {}) => {
|
|
|
100
100
|
if (v.startsWith("(") && v.endsWith(")")) {
|
|
101
101
|
return evaluateExpression(v.slice(1, -1).trim(), data, state, fns);
|
|
102
102
|
}
|
|
103
|
-
if ((v.startsWith(`"`) && v.endsWith(`"`)) || /^-?\d+\.?\d*$/.test(v) || v === "true" || v === "false" || v === "null") {
|
|
104
|
-
|
|
103
|
+
if ((v.startsWith(`"`) && v.endsWith(`"`)) || (v.startsWith(`'`) && v.endsWith(`'`)) || /^-?\d+\.?\d*$/.test(v) || v === "true" || v === "false" || v === "null") {
|
|
104
|
+
const normalized = (v.startsWith(`'`) && v.endsWith(`'`)) ? `"${v.slice(1, -1).replace(/"/g, '\\"')}"` : v;
|
|
105
|
+
return JSON.parse(normalized);
|
|
105
106
|
}
|
|
106
107
|
return (v || "").startsWith("@") ? get(state, v.slice(1)) : get(data, v || ".");
|
|
107
108
|
};
|