@j2inn/resolvable-ui-elements 1.0.3 → 1.0.4-beta.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/dist/resolvableElements/resolveTemplatedExpression.d.ts +1 -1
- package/dist/resolvableElements/resolveTemplatedExpression.js +7 -2
- package/dist/resolvableElements/resolveTemplatedExpression.js.map +1 -1
- package/dist_es/resolvableElements/resolveTemplatedExpression.d.ts +1 -1
- package/dist_es/resolvableElements/resolveTemplatedExpression.js +7 -2
- package/dist_es/resolvableElements/resolveTemplatedExpression.js.map +1 -1
- package/package.json +2 -2
|
@@ -16,4 +16,4 @@ export declare const resolveTemplateExpression: (expr: string, parameters?: HDic
|
|
|
16
16
|
* @param replacer
|
|
17
17
|
* @returns a new string containing the compiled template string
|
|
18
18
|
*/
|
|
19
|
-
export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string) => string) => string;
|
|
19
|
+
export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string, optional: string) => string) => string;
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.replaceTemplateVariables = exports.resolveTemplateExpression = exports.REG_EXPR_MATCHING_TEMPLATE = void 0;
|
|
7
|
-
|
|
7
|
+
const haystack_core_1 = require("haystack-core");
|
|
8
|
+
exports.REG_EXPR_MATCHING_TEMPLATE = new RegExp(/{{([^{}?]*)(\??)}}/, 'g');
|
|
8
9
|
/**
|
|
9
10
|
* Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
|
|
10
11
|
* The HVal.toAxon function is used for conversion to a string.
|
|
@@ -16,11 +17,15 @@ exports.REG_EXPR_MATCHING_TEMPLATE = new RegExp('{{([^{}]*)}}', 'g');
|
|
|
16
17
|
*/
|
|
17
18
|
const resolveTemplateExpression = (expr, parameters) => {
|
|
18
19
|
const paramDict = parameters;
|
|
19
|
-
return (0, exports.replaceTemplateVariables)(expr, (_substring, match) => {
|
|
20
|
+
return (0, exports.replaceTemplateVariables)(expr, (_substring, match, optional) => {
|
|
21
|
+
const isOptional = optional === '?';
|
|
20
22
|
const parameter = paramDict?.get(match)?.toAxon();
|
|
21
23
|
if (parameter != null) {
|
|
22
24
|
return parameter;
|
|
23
25
|
}
|
|
26
|
+
else if (isOptional) {
|
|
27
|
+
return haystack_core_1.AXON_NULL;
|
|
28
|
+
}
|
|
24
29
|
throw new Error(`ERROR: Missing parameter: ${match} in ${paramDict?.toAxon()}`);
|
|
25
30
|
});
|
|
26
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAgD;AAEnC,QAAA,0BAA0B,GAAG,IAAI,MAAM,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;AAE/E;;;;;;;;GAQG;AACI,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,IAAA,gCAAwB,EAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,QAAQ,KAAK,GAAG,CAAA;QACnC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;aAAM,IAAI,UAAU,EAAE;YACtB,OAAO,yBAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AArBY,QAAA,yBAAyB,6BAqBrC;AAED;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAwE,EAC/D,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,kCAA0B,EAAE,QAAQ,CAAC,CAAA;AAH5D,QAAA,wBAAwB,4BAGoC"}
|
|
@@ -16,4 +16,4 @@ export declare const resolveTemplateExpression: (expr: string, parameters?: HDic
|
|
|
16
16
|
* @param replacer
|
|
17
17
|
* @returns a new string containing the compiled template string
|
|
18
18
|
*/
|
|
19
|
-
export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string) => string) => string;
|
|
19
|
+
export declare const replaceTemplateVariables: (templateString: string, replacer: (substring: string, match: string, optional: string) => string) => string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import { AXON_NULL } from 'haystack-core';
|
|
5
|
+
export const REG_EXPR_MATCHING_TEMPLATE = new RegExp(/{{([^{}?]*)(\??)}}/, 'g');
|
|
5
6
|
/**
|
|
6
7
|
* Replaces variables (defined as <$parameterName>) in an expression with the values given in the parameters dict.
|
|
7
8
|
* The HVal.toAxon function is used for conversion to a string.
|
|
@@ -13,11 +14,15 @@ export const REG_EXPR_MATCHING_TEMPLATE = new RegExp('{{([^{}]*)}}', 'g');
|
|
|
13
14
|
*/
|
|
14
15
|
export const resolveTemplateExpression = (expr, parameters) => {
|
|
15
16
|
const paramDict = parameters;
|
|
16
|
-
return replaceTemplateVariables(expr, (_substring, match) => {
|
|
17
|
+
return replaceTemplateVariables(expr, (_substring, match, optional) => {
|
|
18
|
+
const isOptional = optional === '?';
|
|
17
19
|
const parameter = paramDict?.get(match)?.toAxon();
|
|
18
20
|
if (parameter != null) {
|
|
19
21
|
return parameter;
|
|
20
22
|
}
|
|
23
|
+
else if (isOptional) {
|
|
24
|
+
return AXON_NULL;
|
|
25
|
+
}
|
|
21
26
|
throw new Error(`ERROR: Missing parameter: ${match} in ${paramDict?.toAxon()}`);
|
|
22
27
|
});
|
|
23
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"resolveTemplatedExpression.js","sourceRoot":"","sources":["../../src/resolvableElements/resolveTemplatedExpression.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAS,MAAM,eAAe,CAAA;AAEhD,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,MAAM,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;AAE/E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,IAAY,EACZ,UAAkB,EACT,EAAE;IACX,MAAM,SAAS,GAAG,UAAU,CAAA;IAE5B,OAAO,wBAAwB,CAC9B,IAAI,EACJ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,QAAQ,KAAK,GAAG,CAAA;QACnC,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,SAAS,IAAI,IAAI,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;aAAM,IAAI,UAAU,EAAE;YACtB,OAAO,SAAS,CAAA;SAChB;QACD,MAAM,IAAI,KAAK,CACd,6BAA6B,KAAK,OAAO,SAAS,EAAE,MAAM,EAAE,EAAE,CAC9D,CAAA;IACF,CAAC,CACD,CAAA;AACF,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACvC,cAAsB,EACtB,QAAwE,EAC/D,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j2inn/resolvable-ui-elements",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,4 +49,4 @@
|
|
|
49
49
|
"ts-jest": "^28.0.8",
|
|
50
50
|
"typescript": "^4.8.2"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|