jz-toolkit 1.1.6 → 1.1.8
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/README.md +14 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/string/index.d.ts +1 -0
- package/dist/esm/string/index.d.ts.map +1 -1
- package/dist/esm/string/index.js +1 -0
- package/dist/esm/string/renderTemplate.d.ts +18 -0
- package/dist/esm/string/renderTemplate.d.ts.map +1 -0
- package/dist/esm/string/renderTemplate.js +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.d.ts.map +1 -1
- package/dist/string/index.js +1 -0
- package/dist/string/renderTemplate.d.ts +18 -0
- package/dist/string/renderTemplate.d.ts.map +1 -0
- package/dist/string/renderTemplate.js +34 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,7 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
#### 🆕 最近更新
|
|
6
6
|
|
|
7
|
-
##### v1.1.
|
|
7
|
+
##### v1.1.9
|
|
8
|
+
- 新增 `renderTemplate()` - 字符串模板替换函数,支持灵活的变量替换
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { renderTemplate } from "jz-toolkit";
|
|
12
|
+
|
|
13
|
+
const result = renderTemplate(
|
|
14
|
+
{ name: "张三", money: 100.50 },
|
|
15
|
+
"你好, {{name}}! 你的余额是 {{money}} 元。"
|
|
16
|
+
);
|
|
17
|
+
// 返回: "你好, 张三! 你的余额是 100.50 元。"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
##### v1.1.8
|
|
8
21
|
- 新增 `toThousandsIntl()` - 国际化数字千分位格式化函数,支持多地区格式
|
|
9
22
|
- 新增 `toThousands()` - 常规数字千分位格式化函数
|
|
10
23
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * as dom from "./generDom";
|
|
|
17
17
|
export { chunk, compact, filterDuplicateValues, filterArrayAttr, uniq, uniqBy, flatten, flattenDeep, groupBy, sortBy, intersection, difference, union, first, last, take, takeRight, } from "./array";
|
|
18
18
|
export { flattenTree, convertToArray } from "./mapToArray";
|
|
19
19
|
export { pick, omit, deepClone, merge, get, set, flattenObject, unflattenObject, } from "./object";
|
|
20
|
-
export { capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands } from "./string";
|
|
20
|
+
export { capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands, renderTemplate, } from "./string";
|
|
21
21
|
export { numberToFixed, random, randomInt, clamp, inRange, formatNumber, sum, average, max, min, } from "./number";
|
|
22
22
|
export { debounce, throttle, once, sleep, delay, } from "./function";
|
|
23
23
|
export { formatDate, addDays, addMonths, addYears, diffDays, diffHours, diffMinutes, isValidDate, isSameDay, isToday, isYesterday, isTomorrow, isDateInRange, } from "./date";
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AA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EACL,OAAO,EACP,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,EACX,YAAY,GACb,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,EACR,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,EACN,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,OAAO,GACR,MAAM,YAAY,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -26,7 +26,7 @@ export {
|
|
|
26
26
|
pick, omit, deepClone, merge, get, set, flattenObject, unflattenObject, } from "./object";
|
|
27
27
|
export {
|
|
28
28
|
// 字符串
|
|
29
|
-
capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands } from "./string";
|
|
29
|
+
capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands, renderTemplate, } from "./string";
|
|
30
30
|
export {
|
|
31
31
|
// 数字
|
|
32
32
|
numberToFixed, random, randomInt, clamp, inRange, formatNumber, sum, average, max, min, } from "./number";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAA"}
|
package/dist/esm/string/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字符串模板替换函数
|
|
3
|
+
* @param params - 替换的键值对数据,支持字符串、数字、布尔值
|
|
4
|
+
* @param template - 模板字符串
|
|
5
|
+
* @param regex - 匹配模式,默认为 {{key}} 格式,必须包含全局标志 g
|
|
6
|
+
* @returns 替换后的字符串
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = renderTemplate(
|
|
11
|
+
* { name: "张三", money: 100.50 },
|
|
12
|
+
* "你好, {{name}}! 你的余额是 {{money}} 元。"
|
|
13
|
+
* );
|
|
14
|
+
* // 返回: "你好, 张三! 你的余额是 100.50 元。"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function renderTemplate(params: Record<string, string | number | boolean>, template: string, regex?: RegExp): string;
|
|
18
|
+
//# sourceMappingURL=renderTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTemplate.d.ts","sourceRoot":"","sources":["../../../src/string/renderTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EACjD,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAqB,GAC7B,MAAM,CAaR"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字符串模板替换函数
|
|
3
|
+
* @param params - 替换的键值对数据,支持字符串、数字、布尔值
|
|
4
|
+
* @param template - 模板字符串
|
|
5
|
+
* @param regex - 匹配模式,默认为 {{key}} 格式,必须包含全局标志 g
|
|
6
|
+
* @returns 替换后的字符串
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = renderTemplate(
|
|
11
|
+
* { name: "张三", money: 100.50 },
|
|
12
|
+
* "你好, {{name}}! 你的余额是 {{money}} 元。"
|
|
13
|
+
* );
|
|
14
|
+
* // 返回: "你好, 张三! 你的余额是 100.50 元。"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function renderTemplate(params, template, regex = /{{(.*?)}}/g) {
|
|
18
|
+
// 验证正则表达式是否包含全局标志
|
|
19
|
+
if (!regex.global) {
|
|
20
|
+
throw new Error('regex must have global flag (g)');
|
|
21
|
+
}
|
|
22
|
+
return template.replace(regex, (match, key) => {
|
|
23
|
+
const trimmedKey = key.trim();
|
|
24
|
+
const value = params[trimmedKey];
|
|
25
|
+
// 使用严格判断而不是 ||,避免 0、false 等值被误判
|
|
26
|
+
return value !== undefined && value !== null
|
|
27
|
+
? String(value)
|
|
28
|
+
: match;
|
|
29
|
+
});
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * as dom from "./generDom";
|
|
|
17
17
|
export { chunk, compact, filterDuplicateValues, filterArrayAttr, uniq, uniqBy, flatten, flattenDeep, groupBy, sortBy, intersection, difference, union, first, last, take, takeRight, } from "./array";
|
|
18
18
|
export { flattenTree, convertToArray } from "./mapToArray";
|
|
19
19
|
export { pick, omit, deepClone, merge, get, set, flattenObject, unflattenObject, } from "./object";
|
|
20
|
-
export { capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands } from "./string";
|
|
20
|
+
export { capitalize, camelCase, kebabCase, snakeCase, pascalCase, truncate, trim, trimStart, trimEnd, randomString, randomNumericString, randomAlphaString, toThousandsIntl, toThousands, renderTemplate, } from "./string";
|
|
21
21
|
export { numberToFixed, random, randomInt, clamp, inRange, formatNumber, sum, average, max, min, } from "./number";
|
|
22
22
|
export { debounce, throttle, once, sleep, delay, } from "./function";
|
|
23
23
|
export { formatDate, addDays, addMonths, addYears, diffDays, diffHours, diffMinutes, isValidDate, isSameDay, isToday, isYesterday, isTomorrow, isDateInRange, } from "./date";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAGlC,OAAO,EAEL,KA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,EACR,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,EACN,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,OAAO,GACR,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.randomNumericString = exports.randomString = exports.trimEnd = exports.trimStart = exports.trim = exports.truncate = exports.pascalCase = exports.snakeCase = exports.kebabCase = exports.camelCase = exports.capitalize = exports.unflattenObject = exports.flattenObject = exports.set = exports.get = exports.merge = exports.deepClone = exports.omit = exports.pick = exports.convertToArray = exports.flattenTree = exports.takeRight = exports.take = exports.last = exports.first = exports.union = exports.difference = exports.intersection = exports.sortBy = exports.groupBy = exports.flattenDeep = exports.flatten = exports.uniqBy = exports.uniq = exports.filterArrayAttr = exports.filterDuplicateValues = exports.compact = exports.chunk = exports.dom = exports.validate = exports.url = exports.async = exports.date = exports.func = exports.mapToArray = exports.number = exports.utility = exports.string = exports.object = exports.array = void 0;
|
|
33
|
-
exports.
|
|
34
|
-
exports.message = exports.uniqueId = exports.shortId = exports.uuid = exports.isEmptyObject = exports.isEmptyArray = exports.isEmpty = exports.isSet = exports.isMap = exports.isRegExp = exports.isDate = exports.isFunction = exports.isObject = exports.isArray = exports.isNullOrUndefined = exports.isUndefined = void 0;
|
|
33
|
+
exports.isBoolean = exports.isNumber = exports.isString = exports.isEmptyValue = exports.isPositiveInteger = exports.isInteger = exports.isNumeric = exports.isIdCard = exports.isURL = exports.isPhone = exports.isEmail = exports.addUrlParams = exports.getUrlParam = exports.stringifyQueryString = exports.parseQueryString = exports.promiseAllWithLimit = exports.timeout = exports.retry = exports.isDateInRange = exports.isTomorrow = exports.isYesterday = exports.isToday = exports.isSameDay = exports.isValidDate = exports.diffMinutes = exports.diffHours = exports.diffDays = exports.addYears = exports.addMonths = exports.addDays = exports.formatDate = exports.delay = exports.sleep = exports.once = exports.throttle = exports.debounce = exports.min = exports.max = exports.average = exports.sum = exports.formatNumber = exports.inRange = exports.clamp = exports.randomInt = exports.random = exports.numberToFixed = exports.renderTemplate = exports.toThousands = exports.toThousandsIntl = exports.randomAlphaString = void 0;
|
|
34
|
+
exports.message = exports.uniqueId = exports.shortId = exports.uuid = exports.isEmptyObject = exports.isEmptyArray = exports.isEmpty = exports.isSet = exports.isMap = exports.isRegExp = exports.isDate = exports.isFunction = exports.isObject = exports.isArray = exports.isNullOrUndefined = exports.isUndefined = exports.isNull = void 0;
|
|
35
35
|
// 类型导出
|
|
36
36
|
__exportStar(require("./types"), exports);
|
|
37
37
|
// 功能模块导出
|
|
@@ -96,6 +96,7 @@ Object.defineProperty(exports, "randomNumericString", { enumerable: true, get: f
|
|
|
96
96
|
Object.defineProperty(exports, "randomAlphaString", { enumerable: true, get: function () { return string_1.randomAlphaString; } });
|
|
97
97
|
Object.defineProperty(exports, "toThousandsIntl", { enumerable: true, get: function () { return string_1.toThousandsIntl; } });
|
|
98
98
|
Object.defineProperty(exports, "toThousands", { enumerable: true, get: function () { return string_1.toThousands; } });
|
|
99
|
+
Object.defineProperty(exports, "renderTemplate", { enumerable: true, get: function () { return string_1.renderTemplate; } });
|
|
99
100
|
var number_1 = require("./number");
|
|
100
101
|
// 数字
|
|
101
102
|
Object.defineProperty(exports, "numberToFixed", { enumerable: true, get: function () { return number_1.numberToFixed; } });
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAA"}
|
package/dist/string/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字符串模板替换函数
|
|
3
|
+
* @param params - 替换的键值对数据,支持字符串、数字、布尔值
|
|
4
|
+
* @param template - 模板字符串
|
|
5
|
+
* @param regex - 匹配模式,默认为 {{key}} 格式,必须包含全局标志 g
|
|
6
|
+
* @returns 替换后的字符串
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = renderTemplate(
|
|
11
|
+
* { name: "张三", money: 100.50 },
|
|
12
|
+
* "你好, {{name}}! 你的余额是 {{money}} 元。"
|
|
13
|
+
* );
|
|
14
|
+
* // 返回: "你好, 张三! 你的余额是 100.50 元。"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function renderTemplate(params: Record<string, string | number | boolean>, template: string, regex?: RegExp): string;
|
|
18
|
+
//# sourceMappingURL=renderTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTemplate.d.ts","sourceRoot":"","sources":["../../src/string/renderTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EACjD,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAqB,GAC7B,MAAM,CAaR"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderTemplate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 字符串模板替换函数
|
|
6
|
+
* @param params - 替换的键值对数据,支持字符串、数字、布尔值
|
|
7
|
+
* @param template - 模板字符串
|
|
8
|
+
* @param regex - 匹配模式,默认为 {{key}} 格式,必须包含全局标志 g
|
|
9
|
+
* @returns 替换后的字符串
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const result = renderTemplate(
|
|
14
|
+
* { name: "张三", money: 100.50 },
|
|
15
|
+
* "你好, {{name}}! 你的余额是 {{money}} 元。"
|
|
16
|
+
* );
|
|
17
|
+
* // 返回: "你好, 张三! 你的余额是 100.50 元。"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function renderTemplate(params, template, regex = /{{(.*?)}}/g) {
|
|
21
|
+
// 验证正则表达式是否包含全局标志
|
|
22
|
+
if (!regex.global) {
|
|
23
|
+
throw new Error('regex must have global flag (g)');
|
|
24
|
+
}
|
|
25
|
+
return template.replace(regex, (match, key) => {
|
|
26
|
+
const trimmedKey = key.trim();
|
|
27
|
+
const value = params[trimmedKey];
|
|
28
|
+
// 使用严格判断而不是 ||,避免 0、false 等值被误判
|
|
29
|
+
return value !== undefined && value !== null
|
|
30
|
+
? String(value)
|
|
31
|
+
: match;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.renderTemplate = renderTemplate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jz-toolkit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "一个轻量级的JavaScript/TypeScript 工具库",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -91,7 +91,8 @@
|
|
|
91
91
|
"format": "prettier --write 'src/**/*.ts'",
|
|
92
92
|
"prepublishOnly": "npm run build && npm run test",
|
|
93
93
|
"setNpm":"npm config set registry https://registry.npmjs.org",
|
|
94
|
-
"setPnpm":"npm config set registry https://registry.npmmirror.com"
|
|
94
|
+
"setPnpm":"npm config set registry https://registry.npmmirror.com",
|
|
95
|
+
"testNpm": "node ./scripts/getNpm.js"
|
|
95
96
|
},
|
|
96
97
|
"keywords": [
|
|
97
98
|
"utility",
|