@planarcat/js-toolkit 1.2.2 → 1.3.1

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 CHANGED
@@ -53,9 +53,12 @@ console.log(formatDate(new Date(), 'dd HH:mm', { locale: 'en-US' }));
53
53
  import { debounce } from '@planarcat/js-toolkit';
54
54
 
55
55
  // 创建防抖函数
56
- const debouncedFn = debounce(() => {
57
- console.log('函数执行了!');
58
- }, { delay: 500 });
56
+ const debouncedFn = debounce(
57
+ () => {
58
+ console.log('函数执行了!');
59
+ },
60
+ { delay: 500 }
61
+ );
59
62
 
60
63
  // 多次调用,只会执行最后一次
61
64
  debouncedFn();
@@ -64,12 +67,44 @@ debouncedFn();
64
67
  // 500ms 后执行一次
65
68
  ```
66
69
 
70
+ ### 数字格式化
71
+
72
+ ```typescript
73
+ import { toFormattedNumber } from '@planarcat/js-toolkit';
74
+
75
+ // 基本使用
76
+ console.log(toFormattedNumber(1234.5678));
77
+ // 输出: 1234.5678
78
+
79
+ // 保留两位小数
80
+ console.log(toFormattedNumber(1234.5678, { decimalPlaces: 2 }));
81
+ // 输出: 1234.57
82
+
83
+ // 处理字符串
84
+ console.log(toFormattedNumber('123.45abc'));
85
+ // 输出: 123.45
86
+
87
+ // 处理数组
88
+ console.log(toFormattedNumber([123.456, '456.789']));
89
+ // 输出: [123.456, 456.789]
90
+
91
+ // 处理深层数组
92
+ console.log(
93
+ toFormattedNumber([
94
+ [1, '1.23'],
95
+ ['45.67', [89.01, 'abc']],
96
+ ])
97
+ );
98
+ // 输出: [[1, 1.23], [45.67, [89.01, NaN]]]
99
+ ```
100
+
67
101
  ## API 文档
68
102
 
69
103
  详细的 API 文档请查看 [docs/](docs/) 目录下的模块文档:
70
104
 
71
105
  - [日期格式化](docs/functions/formatDate.md)
72
106
  - [函数防抖](docs/functions/debounce.md)
107
+ - [数字格式化](docs/functions/toFormattedNumber.md)
73
108
  - [类型定义](docs/interfaces/)
74
109
 
75
110
  ### 生成文档
@@ -92,9 +127,12 @@ src/
92
127
  │ └── formatDate.ts # 日期格式化函数
93
128
  ├── function/
94
129
  │ └── debounce.ts # 函数防抖功能
130
+ ├── object/
131
+ │ └── toFormattedNumber.ts # 数字格式化函数
95
132
  ├── types/
96
133
  │ ├── date.ts # 日期相关类型定义
97
- │ ├── debounce.ts # 防抖相关类型定义
134
+ │ ├── function.ts # 防抖相关类型定义
135
+ │ ├── object.ts # 数字格式化相关类型定义
98
136
  │ └── index.ts # 类型导出
99
137
  ├── utils/
100
138
  │ └── constants.ts # 常量定义
@@ -158,6 +196,15 @@ npm run test:coverage
158
196
 
159
197
  ## 更新日志
160
198
 
199
+ ### v1.3.0
200
+
201
+ - ✨ 添加数字格式化功能 `toFormattedNumber`
202
+ - ✨ 支持处理任意输入类型(number、string、array、deep array)
203
+ - ✨ 支持自定义小数位数和 NaN 显示
204
+ - ✨ 支持深层数组递归处理
205
+ - ✨ 完善的类型定义和 JSDoc 注释
206
+ - ✨ 新增 object 分类目录结构
207
+
161
208
  ### v1.2.0
162
209
 
163
210
  - ✨ 优化日期格式化功能,支持使用 `dd` 标记直接显示周几
@@ -177,4 +224,4 @@ npm run test:coverage
177
224
  - ✨ 实现日期格式化功能 `formatDate`
178
225
  - ✨ 完整的 TypeScript 类型支持
179
226
  - ✨ 单元测试覆盖
180
- - ✨ 构建和发布配置
227
+ - ✨ 构建和发布配置
@@ -1,9 +1,9 @@
1
- import { DebounceOptions, DebouncedFunction } from "@/types/debounce";
1
+ import { DebounceOptions, DebouncedFunction } from "@/types/function";
2
2
  /**
3
3
  * 将函数进行防抖处理
4
4
  * @param fn - 需要防抖处理的函数
5
5
  * @param delay - 防抖延迟时间,默认100ms
6
- * @param options - 配置选项
6
+ * @param _options - 配置选项(当前未使用)
7
7
  * @returns 防抖处理后的函数,带有cancel方法
8
8
  */
9
9
  declare function debounce<T extends unknown[]>(fn: (...args: T) => void, delay?: number, _options?: DebounceOptions): DebouncedFunction<T>;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  * 将函数进行防抖处理
5
5
  * @param fn - 需要防抖处理的函数
6
6
  * @param delay - 防抖延迟时间,默认100ms
7
- * @param options - 配置选项
7
+ * @param _options - 配置选项(当前未使用)
8
8
  * @returns 防抖处理后的函数,带有cancel方法
9
9
  */
10
10
  function debounce(fn, delay = 100, _options = {}) {
package/dist/index.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  export { default as formatDate } from "./date/formatDate";
7
7
  export type { DateFormatOptions, DateInput } from "./types/date";
8
8
  export { default as debounce } from "./function/debounce";
9
- export type { DebounceOptions, DebouncedFunction } from "./types/debounce";
9
+ export type { DebounceOptions, DebouncedFunction } from "./types/function";
10
10
  export declare const VERSION = "__VERSION__";
11
11
  export declare const LIBRARY_NAME = "@planarcat/js-toolkit";
12
+ export { default as toFormattedNumber } from "./object/toFormattedNumber";
13
+ export type { ToFormattedNumberOptions } from "./types/object";
12
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,eAAO,MAAM,OAAO,gBAAgB,CAAC;AACrC,eAAO,MAAM,YAAY,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,eAAO,MAAM,OAAO,gBAAgB,CAAC;AACrC,eAAO,MAAM,YAAY,0BAA0B,CAAC;AAGpD,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.LIBRARY_NAME = exports.VERSION = exports.debounce = exports.formatDate = void 0;
11
+ exports.toFormattedNumber = exports.LIBRARY_NAME = exports.VERSION = exports.debounce = exports.formatDate = void 0;
12
12
  // 日期相关工具
13
13
  var formatDate_1 = require("./date/formatDate");
14
14
  Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return __importDefault(formatDate_1).default; } });
@@ -18,6 +18,9 @@ Object.defineProperty(exports, "debounce", { enumerable: true, get: function ()
18
18
  // 工具库元数据
19
19
  exports.VERSION = "__VERSION__"; // 构建时替换
20
20
  exports.LIBRARY_NAME = "@planarcat/js-toolkit";
21
+ // 对象相关工具
22
+ var toFormattedNumber_1 = require("./object/toFormattedNumber");
23
+ Object.defineProperty(exports, "toFormattedNumber", { enumerable: true, get: function () { return __importDefault(toFormattedNumber_1).default; } });
21
24
  // 工具函数(后续添加)
22
25
  // export { default as toNumber } from './number/toNumber';
23
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,SAAS;AACT,gDAA0D;AAAjD,yHAAA,OAAO,OAAc;AAG9B,SAAS;AACT,gDAA0D;AAAjD,qHAAA,OAAO,OAAY;AAG5B,SAAS;AACI,QAAA,OAAO,GAAG,aAAa,CAAC,CAAC,QAAQ;AACjC,QAAA,YAAY,GAAG,uBAAuB,CAAC;AAEpD,aAAa;AACb,2DAA2D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,SAAS;AACT,gDAA0D;AAAjD,yHAAA,OAAO,OAAc;AAG9B,SAAS;AACT,gDAA0D;AAAjD,qHAAA,OAAO,OAAY;AAG5B,SAAS;AACI,QAAA,OAAO,GAAG,aAAa,CAAC,CAAC,QAAQ;AACjC,QAAA,YAAY,GAAG,uBAAuB,CAAC;AAEpD,SAAS;AACT,gEAA0E;AAAjE,uIAAA,OAAO,OAAqB;AAGrC,aAAa;AACb,2DAA2D"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 将任意对象转化为数字,然后根据格式化参数对转化后的数字进行格式化
3
+ *
4
+ * 该函数支持多种输入类型,包括数字、字符串、布尔值、null、undefined、数组等
5
+ * 对于字符串,会提取其中的数字部分进行转换
6
+ * 支持深层数组递归处理
7
+ *
8
+ * @param object - 要格式化的对象,可以是任何类型
9
+ * @param options - 格式化选项
10
+ * @param options.decimalPlaces - 保留多少位小数,默认true(保留所有小数位)
11
+ * true: 保留所有小数位,不额外处理
12
+ * number: 保留指定小数位,四舍五入
13
+ * @param options.nanDisplay - 当值为NaN时的显示,默认NaN
14
+ *
15
+ * @returns 格式化后的数字或数字数组
16
+ * - 如果输入是单个值,返回格式化后的数字
17
+ * - 如果输入是数组,返回格式化后的数字数组
18
+ * - 支持深层数组递归处理
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // 单个数字值
23
+ * toFormattedNumber(123.456); // 123.456
24
+ *
25
+ * // 字符串中的数字提取
26
+ * toFormattedNumber('123.456abc'); // 123.456
27
+ * toFormattedNumber('abc123.456def'); // 123.456
28
+ * toFormattedNumber('1.23e3'); // 1230
29
+ *
30
+ * // 布尔值转换
31
+ * toFormattedNumber(true); // 1
32
+ * toFormattedNumber(false); // 0
33
+ *
34
+ * // 特殊类型处理
35
+ * toFormattedNumber(null); // NaN
36
+ * toFormattedNumber(undefined); // NaN
37
+ * toFormattedNumber(Symbol('test')); // NaN
38
+ * toFormattedNumber(() => {}); // NaN
39
+ *
40
+ * // 一维数组
41
+ * toFormattedNumber([123.456, '456.789def']); // [123.456, 456.789]
42
+ *
43
+ * // 深层数组
44
+ * toFormattedNumber([[1, '1', null], 'xxx', ['123a', ['123', '456ff']]]);
45
+ * // 返回: [[1, 1, NaN], NaN, [123, [123, 456]]]
46
+ *
47
+ * // 保留指定小数位
48
+ * toFormattedNumber(123.456, { decimalPlaces: 2 }); // 123.46
49
+ * toFormattedNumber(123.456, { decimalPlaces: 0 }); // 123
50
+ *
51
+ * // 自定义NaN显示
52
+ * toFormattedNumber(null, { nanDisplay: 0 }); // 0
53
+ * toFormattedNumber('abc', { nanDisplay: -1 }); // -1
54
+ * ```
55
+ */
56
+ declare function toFormattedNumber(object: unknown[], options?: import('../types/object').ToFormattedNumberOptions): number[];
57
+ declare function toFormattedNumber(object: unknown, options?: import('../types/object').ToFormattedNumberOptions): number | number[];
58
+ export default toFormattedNumber;
59
+ //# sourceMappingURL=toFormattedNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFormattedNumber.d.ts","sourceRoot":"","sources":["../../src/object/toFormattedNumber.ts"],"names":[],"mappings":"AA0CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,iBAAS,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,iBAAiB,EAAE,wBAAwB,GAAG,MAAM,EAAE,CAAC;AAEtH,iBAAS,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,iBAAiB,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAgD7H,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 从字符串中提取数字部分
5
+ * @param str - 输入字符串
6
+ * @returns 提取的数字字符串
7
+ */
8
+ function extractNumberFromString(str) {
9
+ // 匹配数字体系:0~9,小数点,正负号,科学计数法
10
+ const match = str.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/);
11
+ return match ? match[0] : '';
12
+ }
13
+ /**
14
+ * 将单个值转换为数字
15
+ * @param value - 输入值
16
+ * @returns 转换后的数字
17
+ */
18
+ function convertToNumber(value) {
19
+ switch (typeof value) {
20
+ case 'number':
21
+ return value;
22
+ case 'string': {
23
+ const numStr = extractNumberFromString(value);
24
+ return numStr ? Number(numStr) : NaN;
25
+ }
26
+ case 'boolean':
27
+ return value ? 1 : 0;
28
+ case 'function':
29
+ case 'symbol':
30
+ return NaN;
31
+ case 'object':
32
+ if (value === null) {
33
+ return NaN;
34
+ }
35
+ // 其他对象类型返回NaN
36
+ return NaN;
37
+ case 'undefined':
38
+ return NaN;
39
+ default:
40
+ return NaN;
41
+ }
42
+ }
43
+ // 主函数实现
44
+ function toFormattedNumber(object, options) {
45
+ // 解构并设置默认值
46
+ const { decimalPlaces = true, nanDisplay = NaN } = options || {};
47
+ /**
48
+ * 格式化单个数字
49
+ * @param num - 要格式化的数字
50
+ * @returns 格式化后的数字
51
+ */
52
+ const formatSingleNumber = (num) => {
53
+ // 处理NaN情况
54
+ if (isNaN(num)) {
55
+ return nanDisplay;
56
+ }
57
+ // 根据decimalPlaces选项处理小数位
58
+ if (decimalPlaces === true) {
59
+ // 保留所有小数位,不额外处理
60
+ return num;
61
+ }
62
+ else {
63
+ // 保留指定小数位,四舍五入
64
+ return Number(num.toFixed(decimalPlaces));
65
+ }
66
+ };
67
+ /**
68
+ * 转换单个值为数字,支持深层数组递归处理
69
+ * @param value - 要转换的值
70
+ * @returns 转换后的数字或数字数组
71
+ */
72
+ const processValue = (value) => {
73
+ if (Array.isArray(value)) {
74
+ // 递归处理深层数组
75
+ return value.map(processValue);
76
+ }
77
+ else {
78
+ // 转换为数字
79
+ const num = convertToNumber(value);
80
+ // 格式化数字
81
+ return formatSingleNumber(num);
82
+ }
83
+ };
84
+ // 处理输入值
85
+ return processValue(object);
86
+ }
87
+ exports.default = toFormattedNumber;
88
+ //# sourceMappingURL=toFormattedNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFormattedNumber.js","sourceRoot":"","sources":["../../src/object/toFormattedNumber.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,GAAW;IACxC,2BAA2B;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,KAAc;IACnC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACnB,KAAK,QAAQ;YACT,OAAO,KAAK,CAAC;QACjB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,MAAM,MAAM,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzC,CAAC;QACD,KAAK,SAAS;YACV,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,KAAK,UAAU,CAAC;QAChB,KAAK,QAAQ;YACT,OAAO,GAAG,CAAC;QACf,KAAK,QAAQ;YACT,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACjB,OAAO,GAAG,CAAC;YACf,CAAC;YACD,cAAc;YACd,OAAO,GAAG,CAAC;QACf,KAAK,WAAW;YACZ,OAAO,GAAG,CAAC;QACf;YACI,OAAO,GAAG,CAAC;IACnB,CAAC;AACL,CAAC;AA6DD,QAAQ;AACR,SAAS,iBAAiB,CAAC,MAAe,EAAE,OAA4D;IACpG,WAAW;IACX,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,UAAU,GAAG,GAAG,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEjE;;;;OAIG;IACH,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAU,EAAE;QAC/C,UAAU;QACV,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACb,OAAO,UAAU,CAAC;QACtB,CAAC;QAED,yBAAyB;QACzB,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YACzB,gBAAgB;YAChB,OAAO,GAAG,CAAC;QACf,CAAC;aAAM,CAAC;YACJ,eAAe;YACf,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC,CAAC;IAEF;;;;OAIG;IACH,MAAM,YAAY,GAAG,CAAC,KAAc,EAAqB,EAAE;QACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,WAAW;YACX,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAa,CAAC;QAC/C,CAAC;aAAM,CAAC;YACJ,QAAQ;YACR,MAAM,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;YACnC,QAAQ;YACR,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;IACL,CAAC,CAAC;IAEF,QAAQ;IACR,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
@@ -15,4 +15,4 @@ export interface DebouncedFunction<T extends unknown[]> {
15
15
  */
16
16
  cancel(): void;
17
17
  }
18
- //# sourceMappingURL=debounce.d.ts.map
18
+ //# sourceMappingURL=function.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/types/debounce.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE;IACpD,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACnB;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;CAChB"}
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,OAAO,EAAE;IACpD,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACnB;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;CAChB"}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=debounce.js.map
3
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":""}
@@ -1,3 +1,3 @@
1
1
  export * from "./date";
2
- export * from "./debounce";
2
+ export * from "./function";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // 导出所有类型
18
18
  __exportStar(require("./date"), exports);
19
- __exportStar(require("./debounce"), exports);
19
+ __exportStar(require("./function"), exports);
20
20
  // 后续添加更多类型
21
21
  // export * from './number';
22
22
  // export * from './function';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 公共格式化选项接口
3
+ */
4
+ export interface CommonFormatOptions {
5
+ /**
6
+ * 保留多少位小数,
7
+ * 默认true(保留所有小数位,不额外处理),
8
+ * 可选值:number(保留指定小数位) | true(保留所有小数位,不额外处理)。
9
+ */
10
+ decimalPlaces?: number | true;
11
+ }
12
+ /**
13
+ * toFormattedNumber 函数的选项接口
14
+ */
15
+ export interface ToFormattedNumberOptions extends CommonFormatOptions {
16
+ /**
17
+ * 当值为NaN时的显示,
18
+ * 默认NaN。
19
+ */
20
+ nanDisplay?: number;
21
+ }
22
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB;IACjE;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,76 +1,76 @@
1
1
  {
2
- "name": "@planarcat/js-toolkit",
3
- "version": "1.2.2",
4
- "description": "一个自用的带学习性质的(目前)现代化的 JavaScript/TypeScript 实用工具库,提供类型安全、高性能的常用函数,包括对象转换、日期处理、函数优化等开发常用工具。",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist",
9
- "README.md",
10
- "LICENSE"
11
- ],
12
- "scripts": {
13
- "build": "tsc",
14
- "build:watch": "tsc --watch",
15
- "test": "jest",
16
- "test:watch": "jest --watch",
17
- "test:coverage": "jest --coverage",
18
- "lint": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\"",
19
- "lint:fix": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\" --fix",
20
- "format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
21
- "format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
22
- "prepare": "husky",
23
- "prepublishOnly": "npm run lint && npm test && npm run build",
24
- "clean": "rimraf dist coverage",
25
- "docs": "typedoc",
26
- "docs:watch": "typedoc --watch"
27
- },
28
- "keywords": [
29
- "javascript",
30
- "typescript",
31
- "utility",
32
- "toolkit",
33
- "format-date",
34
- "type-safe"
35
- ],
36
- "author": "planarcat",
37
- "license": "MIT",
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/planarcat/js-toolkit.git"
41
- },
42
- "bugs": {
43
- "url": "https://github.com/planarcat/js-toolkit/issues"
44
- },
45
- "homepage": "https://github.com/planarcat/js-toolkit#readme",
46
- "devDependencies": {
47
- "@types/jest": "^29.5.14",
48
- "@types/node": "^25.0.7",
49
- "@typescript-eslint/eslint-plugin": "^6.21.0",
50
- "@typescript-eslint/parser": "^6.21.0",
51
- "eslint": "^8.57.1",
52
- "eslint-config-prettier": "^9.1.2",
53
- "eslint-plugin-prettier": "^5.5.4",
54
- "husky": "^9.1.7",
55
- "jest": "^29.7.0",
56
- "lint-staged": "^13.3.0",
57
- "prettier": "^3.7.4",
58
- "rimraf": "^5.0.10",
59
- "ts-jest": "^29.4.6",
60
- "ts-node": "^10.9.2",
61
- "ts-node-dev": "^2.0.0",
62
- "typedoc": "^0.28.16",
63
- "typedoc-plugin-markdown": "^4.9.0",
64
- "typescript": "^5.3.3"
65
- },
66
- "lint-staged": {
67
- "*.{js,ts,tsx}": [
68
- "eslint --fix",
69
- "prettier --write"
2
+ "name": "@planarcat/js-toolkit",
3
+ "version": "1.3.1",
4
+ "description": "一个自用的带学习性质的(目前)现代化的 JavaScript/TypeScript 实用工具库,提供类型安全、高性能的常用函数,包括对象转换、日期处理、函数优化等开发常用工具。",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
70
11
  ],
71
- "\"*.{js,ts,tsx}\"": "[\"eslint --fix\", \"prettier --write\"]"
72
- },
73
- "publishConfig": {
74
- "access": "public"
75
- }
12
+ "scripts": {
13
+ "build": "tsc -p tsconfig.build.json",
14
+ "build:watch": "tsc --watch",
15
+ "test": "jest",
16
+ "test:watch": "jest --watch",
17
+ "test:coverage": "jest --coverage",
18
+ "lint": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\"",
19
+ "lint:fix": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\" --fix",
20
+ "format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
21
+ "format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
22
+ "prepare": "husky",
23
+ "prepublishOnly": "npm run lint && npm test && npm run build",
24
+ "clean": "rimraf dist coverage",
25
+ "docs": "typedoc",
26
+ "docs:watch": "typedoc --watch"
27
+ },
28
+ "keywords": [
29
+ "javascript",
30
+ "typescript",
31
+ "utility",
32
+ "toolkit",
33
+ "format-date",
34
+ "type-safe"
35
+ ],
36
+ "author": "planarcat",
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/planarcat/js-toolkit.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/planarcat/js-toolkit/issues"
44
+ },
45
+ "homepage": "https://github.com/planarcat/js-toolkit#readme",
46
+ "devDependencies": {
47
+ "@types/jest": "^29.5.14",
48
+ "@types/node": "^25.0.7",
49
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
50
+ "@typescript-eslint/parser": "^6.21.0",
51
+ "eslint": "^8.57.1",
52
+ "eslint-config-prettier": "^9.1.2",
53
+ "eslint-plugin-prettier": "^5.5.4",
54
+ "husky": "^9.1.7",
55
+ "jest": "^29.7.0",
56
+ "lint-staged": "^13.3.0",
57
+ "prettier": "^3.7.4",
58
+ "rimraf": "^5.0.10",
59
+ "ts-jest": "^29.4.6",
60
+ "ts-node": "^10.9.2",
61
+ "ts-node-dev": "^2.0.0",
62
+ "typedoc": "^0.28.16",
63
+ "typedoc-plugin-markdown": "^4.9.0",
64
+ "typescript": "^5.3.3"
65
+ },
66
+ "lint-staged": {
67
+ "*.{js,ts,tsx}": [
68
+ "eslint --fix",
69
+ "prettier --write"
70
+ ],
71
+ "\"*.{js,ts,tsx}\"": "[\"eslint --fix\", \"prettier --write\"]"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public"
75
+ }
76
76
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/types/debounce.ts"],"names":[],"mappings":""}