jz-toolkit 1.0.6 → 1.0.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.
Files changed (38) hide show
  1. package/README.md +2 -98
  2. package/dist/array/filterDuplicateValues.d.ts +27 -0
  3. package/dist/array/filterDuplicateValues.d.ts.map +1 -0
  4. package/dist/array/filterDuplicateValues.js +49 -0
  5. package/dist/array/index.d.ts +3 -2
  6. package/dist/array/index.d.ts.map +1 -1
  7. package/dist/array/index.js +1 -0
  8. package/dist/demo/index.d.ts +2 -0
  9. package/dist/demo/index.d.ts.map +1 -0
  10. package/dist/demo/index.js +17 -0
  11. package/dist/esm/array/filterDuplicateValues.d.ts +27 -0
  12. package/dist/esm/array/filterDuplicateValues.d.ts.map +1 -0
  13. package/dist/esm/array/filterDuplicateValues.js +44 -0
  14. package/dist/esm/array/index.d.ts +3 -2
  15. package/dist/esm/array/index.d.ts.map +1 -1
  16. package/dist/esm/array/index.js +3 -2
  17. package/dist/esm/demo/index.d.ts +2 -0
  18. package/dist/esm/demo/index.d.ts.map +1 -0
  19. package/dist/esm/demo/index.js +15 -0
  20. package/dist/esm/index.d.ts +2 -0
  21. package/dist/esm/index.d.ts.map +1 -1
  22. package/dist/esm/index.js +4 -0
  23. package/dist/esm/number/index.d.ts +2 -0
  24. package/dist/esm/number/index.d.ts.map +1 -0
  25. package/dist/esm/number/index.js +1 -0
  26. package/dist/esm/number/toFixed.d.ts +10 -0
  27. package/dist/esm/number/toFixed.d.ts.map +1 -0
  28. package/dist/esm/number/toFixed.js +14 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +5 -1
  32. package/dist/number/index.d.ts +2 -0
  33. package/dist/number/index.d.ts.map +1 -0
  34. package/dist/number/index.js +17 -0
  35. package/dist/number/toFixed.d.ts +10 -0
  36. package/dist/number/toFixed.d.ts.map +1 -0
  37. package/dist/number/toFixed.js +18 -0
  38. package/package.json +6 -1
package/README.md CHANGED
@@ -17,10 +17,10 @@
17
17
  ## 安装
18
18
 
19
19
  ```bash
20
- npm i jz-toolkit
20
+ npm i jz-toolkit
21
21
  ```
22
22
 
23
- ## 官方文档地址
23
+ ## 官方文档地址 📚 API 文档查阅
24
24
 
25
25
  http://172.81.245.148:8098/api/utils.html
26
26
 
@@ -56,102 +56,6 @@ object.pick({ a: 1, b: 2 }, ["a"]);
56
56
  string.capitalize("world");
57
57
  ```
58
58
 
59
- ## 📚 API 文档
60
-
61
- ### 数组 (Array)
62
-
63
- #### `chunk(array, size)`
64
-
65
- 将数组分成指定大小的块。
66
-
67
- ```typescript
68
- chunk([1, 2, 3, 4, 5], 2);
69
- // => [[1, 2], [3, 4], [5]]
70
- ```
71
-
72
- #### `compact(array)`
73
-
74
- 移除数组中的虚值。
75
-
76
- ```typescript
77
- compact([0, 1, false, 2, "", 3, undefined, 4, null, NaN]);
78
- // => [1, 2, 3, 4]
79
- ```
80
-
81
- ### 对象 (Object)
82
-
83
- #### `pick(obj, keys)`
84
-
85
- 从对象中选择指定的属性。
86
-
87
- ```typescript
88
- pick({ a: 1, b: 2, c: 3 }, ["a", "c"]);
89
- // => { a: 1, c: 3 }
90
- ```
91
-
92
- #### `omit(obj, keys)`
93
-
94
- 从对象中排除指定的属性。
95
-
96
- ```typescript
97
- omit({ a: 1, b: 2, c: 3 }, ["b"]);
98
- // => { a: 1, c: 3 }
99
- ```
100
-
101
- ### 字符串 (String)
102
-
103
- #### `capitalize(str)`
104
-
105
- 将字符串首字母转为大写。
106
-
107
- ```typescript
108
- capitalize("hello");
109
- // => 'Hello'
110
- ```
111
-
112
- #### `camelCase(str)`
113
-
114
- 将字符串转换为驼峰式命名法。
115
-
116
- ```typescript
117
- camelCase("hello-world");
118
- // => 'helloWorld'
119
- ```
120
-
121
- ### 工具函数 (Utility)
122
-
123
- #### 类型检查
124
-
125
- - `isString(value)` - 检查是否为字符串
126
- - `isNumber(value)` - 检查是否为数字
127
- - `isBoolean(value)` - 检查是否为布尔值
128
- - `isArray(value)` - 检查是否为数组
129
- - `isObject(value)` - 检查是否为对象
130
- - `isFunction(value)` - 检查是否为函数
131
- - `isDate(value)` - 检查是否为日期
132
- - `isRegExp(value)` - 检查是否为正则表达式
133
- - `isMap(value)` - 检查是否为 Map
134
- - `isSet(value)` - 检查是否为 Set
135
- - `isNull(value)` - 检查是否为 null
136
- - `isUndefined(value)` - 检查是否为 undefined
137
- - `isNullOrUndefined(value)` - 检查是否为 null 或 undefined
138
-
139
- #### `isEmpty(value)`
140
-
141
- 检查值是否为空。
142
-
143
- ```typescript
144
- isEmpty([]); // => true
145
- isEmpty({}); // => true
146
- isEmpty(""); // => true
147
- isEmpty(null); // => true
148
- isEmpty("hello"); // => false
149
- ```
150
-
151
- ### mapToArray
152
-
153
- mapToArray(new Map<string, number>([["a", 1], ["b", 2], ["c", 3]])) // => [1, 2, 3]
154
-
155
59
  ## 开发
156
60
 
157
61
  ### 安装依赖
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Filters duplicate values from an array, keeping only unique items.
3
+ * For objects, duplicates are determined by the key returned by the iteratee function.
4
+ * For primitives, duplicates are determined by strict equality (===).
5
+ *
6
+ * @param array - The array to filter for duplicate values.
7
+ * @param iteratee - The function to determine the key for comparison. Optional for primitive values.
8
+ * @returns A new array containing only unique values.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * filterDuplicateValues([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]
13
+ * filterDuplicateValues([{id: 1}, {id: 2}, {id: 1}], item => item.id); // [{id: 1}, {id: 2}]
14
+ * ```
15
+ */
16
+ export declare function filterDuplicateValues<T>(array: T[], iteratee?: (item: T) => any): T[];
17
+ /**
18
+ *
19
+ * @param array - The array to filter.
20
+ * @param extendParams - The parameters for filtering the array.
21
+ * @returns
22
+ */
23
+ export declare function filterArrayAttr<T extends Record<string, any>>(array: T[], extendParams: {
24
+ key: keyof T;
25
+ value: string | number;
26
+ }): T[];
27
+ //# sourceMappingURL=filterDuplicateValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterDuplicateValues.d.ts","sourceRoot":"","sources":["../../src/array/filterDuplicateValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,GAC1B,CAAC,EAAE,CAkBL;AAED;;;;;GAKG;AAEH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,KAAK,EAAE,CAAC,EAAE,EACV,YAAY,EAAE;IACZ,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,GACA,CAAC,EAAE,CAML"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterArrayAttr = exports.filterDuplicateValues = void 0;
4
+ /**
5
+ * Filters duplicate values from an array, keeping only unique items.
6
+ * For objects, duplicates are determined by the key returned by the iteratee function.
7
+ * For primitives, duplicates are determined by strict equality (===).
8
+ *
9
+ * @param array - The array to filter for duplicate values.
10
+ * @param iteratee - The function to determine the key for comparison. Optional for primitive values.
11
+ * @returns A new array containing only unique values.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * filterDuplicateValues([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]
16
+ * filterDuplicateValues([{id: 1}, {id: 2}, {id: 1}], item => item.id); // [{id: 1}, {id: 2}]
17
+ * ```
18
+ */
19
+ function filterDuplicateValues(array, iteratee) {
20
+ if (array.length === 0) {
21
+ return [];
22
+ }
23
+ const seen = new Set();
24
+ const result = [];
25
+ for (const item of array) {
26
+ // For objects, use the iteratee function to get the comparison key
27
+ // For primitives, use the item itself
28
+ const key = iteratee ? iteratee(item) : item;
29
+ if (!seen.has(key)) {
30
+ seen.add(key);
31
+ result.push(item);
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+ exports.filterDuplicateValues = filterDuplicateValues;
37
+ /**
38
+ *
39
+ * @param array - The array to filter.
40
+ * @param extendParams - The parameters for filtering the array.
41
+ * @returns
42
+ */
43
+ function filterArrayAttr(array, extendParams) {
44
+ if (!array || array.length === 0)
45
+ return [];
46
+ const res = array.filter((item) => item[extendParams.key] === extendParams.value);
47
+ return res;
48
+ }
49
+ exports.filterArrayAttr = filterArrayAttr;
@@ -1,3 +1,4 @@
1
- export * from './chunk';
2
- export * from './compact';
1
+ export * from "./chunk";
2
+ export * from "./compact";
3
+ export * from "./filterDuplicateValues";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC"}
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./chunk"), exports);
18
18
  __exportStar(require("./compact"), exports);
19
+ __exportStar(require("./filterDuplicateValues"), exports);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/demo/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filterDuplicateValues_1 = require("../array/filterDuplicateValues");
4
+ const toFixed_1 = require("../number/toFixed");
5
+ const res = (0, filterDuplicateValues_1.filterArrayAttr)([
6
+ {
7
+ id: 1,
8
+ name: "test",
9
+ },
10
+ {
11
+ id: 2,
12
+ name: "Jet",
13
+ },
14
+ ], { key: "id", value: 1 });
15
+ console.log("res :>> ", res);
16
+ const price = 19.956;
17
+ console.log((0, toFixed_1.numberToFixed)(price, 2)); // "19.96" - 保留两位小数
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Filters duplicate values from an array, keeping only unique items.
3
+ * For objects, duplicates are determined by the key returned by the iteratee function.
4
+ * For primitives, duplicates are determined by strict equality (===).
5
+ *
6
+ * @param array - The array to filter for duplicate values.
7
+ * @param iteratee - The function to determine the key for comparison. Optional for primitive values.
8
+ * @returns A new array containing only unique values.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * filterDuplicateValues([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]
13
+ * filterDuplicateValues([{id: 1}, {id: 2}, {id: 1}], item => item.id); // [{id: 1}, {id: 2}]
14
+ * ```
15
+ */
16
+ export declare function filterDuplicateValues<T>(array: T[], iteratee?: (item: T) => any): T[];
17
+ /**
18
+ *
19
+ * @param array - The array to filter.
20
+ * @param extendParams - The parameters for filtering the array.
21
+ * @returns
22
+ */
23
+ export declare function filterArrayAttr<T extends Record<string, any>>(array: T[], extendParams: {
24
+ key: keyof T;
25
+ value: string | number;
26
+ }): T[];
27
+ //# sourceMappingURL=filterDuplicateValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterDuplicateValues.d.ts","sourceRoot":"","sources":["../../../src/array/filterDuplicateValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,GAC1B,CAAC,EAAE,CAkBL;AAED;;;;;GAKG;AAEH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,KAAK,EAAE,CAAC,EAAE,EACV,YAAY,EAAE;IACZ,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,GACA,CAAC,EAAE,CAML"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Filters duplicate values from an array, keeping only unique items.
3
+ * For objects, duplicates are determined by the key returned by the iteratee function.
4
+ * For primitives, duplicates are determined by strict equality (===).
5
+ *
6
+ * @param array - The array to filter for duplicate values.
7
+ * @param iteratee - The function to determine the key for comparison. Optional for primitive values.
8
+ * @returns A new array containing only unique values.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * filterDuplicateValues([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]
13
+ * filterDuplicateValues([{id: 1}, {id: 2}, {id: 1}], item => item.id); // [{id: 1}, {id: 2}]
14
+ * ```
15
+ */
16
+ export function filterDuplicateValues(array, iteratee) {
17
+ if (array.length === 0) {
18
+ return [];
19
+ }
20
+ const seen = new Set();
21
+ const result = [];
22
+ for (const item of array) {
23
+ // For objects, use the iteratee function to get the comparison key
24
+ // For primitives, use the item itself
25
+ const key = iteratee ? iteratee(item) : item;
26
+ if (!seen.has(key)) {
27
+ seen.add(key);
28
+ result.push(item);
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ /**
34
+ *
35
+ * @param array - The array to filter.
36
+ * @param extendParams - The parameters for filtering the array.
37
+ * @returns
38
+ */
39
+ export function filterArrayAttr(array, extendParams) {
40
+ if (!array || array.length === 0)
41
+ return [];
42
+ const res = array.filter((item) => item[extendParams.key] === extendParams.value);
43
+ return res;
44
+ }
@@ -1,3 +1,4 @@
1
- export * from './chunk';
2
- export * from './compact';
1
+ export * from "./chunk";
2
+ export * from "./compact";
3
+ export * from "./filterDuplicateValues";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC"}
@@ -1,2 +1,3 @@
1
- export * from './chunk';
2
- export * from './compact';
1
+ export * from "./chunk";
2
+ export * from "./compact";
3
+ export * from "./filterDuplicateValues";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/demo/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { filterArrayAttr } from "../array/filterDuplicateValues";
2
+ import { numberToFixed } from "../number/toFixed";
3
+ const res = filterArrayAttr([
4
+ {
5
+ id: 1,
6
+ name: "test",
7
+ },
8
+ {
9
+ id: 2,
10
+ name: "Jet",
11
+ },
12
+ ], { key: "id", value: 1 });
13
+ console.log("res :>> ", res);
14
+ const price = 19.956;
15
+ console.log(numberToFixed(price, 2)); // "19.96" - 保留两位小数
@@ -6,8 +6,10 @@ export * as array from "./array";
6
6
  export * as object from "./object";
7
7
  export * as string from "./string";
8
8
  export * as utility from "./utility";
9
+ export * as number from "./number";
9
10
  export { chunk, compact, } from "./array";
10
11
  export { pick, omit, } from "./object";
11
12
  export { capitalize, camelCase, } from "./string";
13
+ export { numberToFixed, } from "./number";
12
14
  export { isString, isNumber, isBoolean, isNull, isUndefined, isNullOrUndefined, isArray, isObject, isFunction, isDate, isRegExp, isMap, isSet, isEmpty, } from "./utility";
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAGrC,OAAO,EAEL,KAAK,EACL,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,IAAI,EACJ,IAAI,GACL,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EACV,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,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,GACR,MAAM,WAAW,CAAC"}
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;AAGnC,OAAO,EAEL,KAAK,EACL,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,IAAI,EACJ,IAAI,GACL,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EACV,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,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,GACR,MAAM,WAAW,CAAC"}
package/dist/esm/index.js CHANGED
@@ -8,6 +8,7 @@ export * as array from "./array";
8
8
  export * as object from "./object";
9
9
  export * as string from "./string";
10
10
  export * as utility from "./utility";
11
+ export * as number from "./number";
11
12
  // 直接导出常用函数
12
13
  export {
13
14
  // 数组
@@ -19,5 +20,8 @@ export {
19
20
  // 字符串
20
21
  capitalize, camelCase, } from "./string";
21
22
  export {
23
+ // 数字
24
+ numberToFixed, } from "./number";
25
+ export {
22
26
  // 工具类
23
27
  isString, isNumber, isBoolean, isNull, isUndefined, isNullOrUndefined, isArray, isObject, isFunction, isDate, isRegExp, isMap, isSet, isEmpty, } from "./utility";
@@ -0,0 +1,2 @@
1
+ export * from "./toFixed";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./toFixed";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 将数字转换为指定小数位数的字符串表示
3
+ * @param number 输入数字
4
+ * @param fixed 小数位数
5
+ * @returns 转换后的字符串
6
+ * @example
7
+ * numberToFixed(19.956, 2) // => "19.96"
8
+ */
9
+ export declare function numberToFixed(number: number, fixed: number): string;
10
+ //# sourceMappingURL=toFixed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFixed.d.ts","sourceRoot":"","sources":["../../../src/number/toFixed.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKnE"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 将数字转换为指定小数位数的字符串表示
3
+ * @param number 输入数字
4
+ * @param fixed 小数位数
5
+ * @returns 转换后的字符串
6
+ * @example
7
+ * numberToFixed(19.956, 2) // => "19.96"
8
+ */
9
+ export function numberToFixed(number, fixed) {
10
+ if (typeof number !== "number" || typeof fixed !== "number") {
11
+ return "";
12
+ }
13
+ return number.toFixed(fixed);
14
+ }
package/dist/index.d.ts CHANGED
@@ -6,8 +6,10 @@ export * as array from "./array";
6
6
  export * as object from "./object";
7
7
  export * as string from "./string";
8
8
  export * as utility from "./utility";
9
+ export * as number from "./number";
9
10
  export { chunk, compact, } from "./array";
10
11
  export { pick, omit, } from "./object";
11
12
  export { capitalize, camelCase, } from "./string";
13
+ export { numberToFixed, } from "./number";
12
14
  export { isString, isNumber, isBoolean, isNull, isUndefined, isNullOrUndefined, isArray, isObject, isFunction, isDate, isRegExp, isMap, isSet, isEmpty, } from "./utility";
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAGrC,OAAO,EAEL,KAAK,EACL,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,IAAI,EACJ,IAAI,GACL,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EACV,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,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,GACR,MAAM,WAAW,CAAC"}
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;AAGnC,OAAO,EAEL,KAAK,EACL,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,IAAI,EACJ,IAAI,GACL,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EACV,SAAS,GACV,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,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,GACR,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  return result;
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.isEmpty = exports.isSet = exports.isMap = exports.isRegExp = exports.isDate = exports.isFunction = exports.isObject = exports.isArray = exports.isNullOrUndefined = exports.isUndefined = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.camelCase = exports.capitalize = exports.omit = exports.pick = exports.compact = exports.chunk = exports.utility = exports.string = exports.object = exports.array = void 0;
32
+ exports.isEmpty = exports.isSet = exports.isMap = exports.isRegExp = exports.isDate = exports.isFunction = exports.isObject = exports.isArray = exports.isNullOrUndefined = exports.isUndefined = exports.isNull = exports.isBoolean = exports.isNumber = exports.isString = exports.numberToFixed = exports.camelCase = exports.capitalize = exports.omit = exports.pick = exports.compact = exports.chunk = exports.number = exports.utility = exports.string = exports.object = exports.array = void 0;
33
33
  // 类型导出
34
34
  __exportStar(require("./types"), exports);
35
35
  // 功能模块导出
@@ -37,6 +37,7 @@ exports.array = __importStar(require("./array"));
37
37
  exports.object = __importStar(require("./object"));
38
38
  exports.string = __importStar(require("./string"));
39
39
  exports.utility = __importStar(require("./utility"));
40
+ exports.number = __importStar(require("./number"));
40
41
  // 直接导出常用函数
41
42
  var array_1 = require("./array");
42
43
  // 数组
@@ -50,6 +51,9 @@ var string_1 = require("./string");
50
51
  // 字符串
51
52
  Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return string_1.capitalize; } });
52
53
  Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return string_1.camelCase; } });
54
+ var number_1 = require("./number");
55
+ // 数字
56
+ Object.defineProperty(exports, "numberToFixed", { enumerable: true, get: function () { return number_1.numberToFixed; } });
53
57
  var utility_1 = require("./utility");
54
58
  // 工具类
55
59
  Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return utility_1.isString; } });
@@ -0,0 +1,2 @@
1
+ export * from "./toFixed";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./toFixed"), exports);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 将数字转换为指定小数位数的字符串表示
3
+ * @param number 输入数字
4
+ * @param fixed 小数位数
5
+ * @returns 转换后的字符串
6
+ * @example
7
+ * numberToFixed(19.956, 2) // => "19.96"
8
+ */
9
+ export declare function numberToFixed(number: number, fixed: number): string;
10
+ //# sourceMappingURL=toFixed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFixed.d.ts","sourceRoot":"","sources":["../../src/number/toFixed.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKnE"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numberToFixed = void 0;
4
+ /**
5
+ * 将数字转换为指定小数位数的字符串表示
6
+ * @param number 输入数字
7
+ * @param fixed 小数位数
8
+ * @returns 转换后的字符串
9
+ * @example
10
+ * numberToFixed(19.956, 2) // => "19.96"
11
+ */
12
+ function numberToFixed(number, fixed) {
13
+ if (typeof number !== "number" || typeof fixed !== "number") {
14
+ return "";
15
+ }
16
+ return number.toFixed(fixed);
17
+ }
18
+ exports.numberToFixed = numberToFixed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jz-toolkit",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "一个轻量级的JavaScript/TypeScript 工具库",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -46,6 +46,11 @@
46
46
  "require": "./dist/utility/index.js",
47
47
  "import": "./dist/esm/utility/index.js",
48
48
  "types": "./dist/utility/index.d.ts"
49
+ },
50
+ "./number": {
51
+ "require": "./dist/number/index.js",
52
+ "import": "./dist/esm/number/index.js",
53
+ "types": "./dist/number/index.d.ts"
49
54
  }
50
55
  },
51
56
  "scripts": {