@takeshape/util 11.85.2 → 11.87.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/common/strings.d.ts +6 -0
- package/dist/common/strings.js +11 -0
- package/package.json +3 -3
package/dist/common/strings.d.ts
CHANGED
|
@@ -16,3 +16,9 @@ export declare function isIntegerLike(value: string | number): boolean;
|
|
|
16
16
|
export declare function encodePropertyName(value: string): string;
|
|
17
17
|
export declare function base64Encode(str: string): string;
|
|
18
18
|
export declare function base64Decode(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Replace {{key}} or {key} in a string with the value of the key in the data object.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tmpl(str: string, data: Record<string, unknown>, options?: {
|
|
23
|
+
style: 'singleBrace' | 'doubleBrace';
|
|
24
|
+
}): string;
|
package/dist/common/strings.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isBrowser } from 'browser-or-node';
|
|
2
2
|
import _camelCase from 'lodash/camelCase.js';
|
|
3
3
|
import isEmpty from 'lodash/isEmpty.js';
|
|
4
|
+
import isNil from 'lodash/isNil.js';
|
|
4
5
|
import isString from 'lodash/isString.js';
|
|
5
6
|
import upperFirst from 'lodash/upperFirst.js';
|
|
6
7
|
import { ensureArray } from "./arrays.js";
|
|
@@ -58,3 +59,13 @@ export function base64Encode(str) {
|
|
|
58
59
|
export function base64Decode(str) {
|
|
59
60
|
return isBrowser ? window.atob(str) : Buffer.from(str, 'base64').toString();
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Replace {{key}} or {key} in a string with the value of the key in the data object.
|
|
64
|
+
*/
|
|
65
|
+
export function tmpl(str, data, options) {
|
|
66
|
+
const pattern = options?.style === 'doubleBrace' ? /\{\{([^{}]+)\}\}/g : /\{([^{}]+)\}/g;
|
|
67
|
+
return str.replace(pattern, (_, key) => {
|
|
68
|
+
const value = data[key.trim()];
|
|
69
|
+
return !isNil(value) ? String(value) : '';
|
|
70
|
+
});
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.87.0",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"tiny-invariant": "^1.2.0",
|
|
46
46
|
"uint8array-extras": "^1.4.0",
|
|
47
47
|
"url-parse": "^1.5.3",
|
|
48
|
-
"@takeshape/routing": "11.
|
|
49
|
-
"@takeshape/prism": "11.
|
|
48
|
+
"@takeshape/routing": "11.87.0",
|
|
49
|
+
"@takeshape/prism": "11.87.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/classnames": "^2.2.9",
|