@planarcat/js-toolkit 1.5.6 → 1.7.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.
Files changed (43) hide show
  1. package/README.md +27 -5
  2. package/dist/date/compileDateFormatter.d.ts +16 -0
  3. package/dist/date/compileDateFormatter.d.ts.map +1 -0
  4. package/dist/date/compileDateFormatter.js +316 -0
  5. package/dist/date/compileDateFormatter.js.map +1 -0
  6. package/dist/date/formatDate.d.ts +81 -16
  7. package/dist/date/formatDate.d.ts.map +1 -1
  8. package/dist/date/formatDate.js +114 -130
  9. package/dist/date/formatDate.js.map +1 -1
  10. package/dist/date/formatDateCompiled.d.ts +30 -0
  11. package/dist/date/formatDateCompiled.d.ts.map +1 -0
  12. package/dist/date/formatDateCompiled.js +126 -0
  13. package/dist/date/formatDateCompiled.js.map +1 -0
  14. package/dist/date/formatDatePlain.d.ts +34 -0
  15. package/dist/date/formatDatePlain.d.ts.map +1 -0
  16. package/dist/date/formatDatePlain.js +128 -0
  17. package/dist/date/formatDatePlain.js.map +1 -0
  18. package/dist/date/regularDateFormatter.d.ts +33 -0
  19. package/dist/date/regularDateFormatter.d.ts.map +1 -0
  20. package/dist/date/regularDateFormatter.js +302 -0
  21. package/dist/date/regularDateFormatter.js.map +1 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/object/toFormattedNumber.d.ts +2 -2
  25. package/dist/object/toFormattedNumber.d.ts.map +1 -1
  26. package/dist/object/toFormattedNumber.js +8 -8
  27. package/dist/object/toFormattedNumber.js.map +1 -1
  28. package/dist/object/toFormattedNumberString.d.ts +2 -2
  29. package/dist/object/toFormattedNumberString.d.ts.map +1 -1
  30. package/dist/object/toFormattedNumberString.js +13 -9
  31. package/dist/object/toFormattedNumberString.js.map +1 -1
  32. package/dist/types/date.d.ts +19 -2
  33. package/dist/types/date.d.ts.map +1 -1
  34. package/dist/types/object.d.ts.map +1 -1
  35. package/dist/utils/cache.d.ts +38 -0
  36. package/dist/utils/cache.d.ts.map +1 -0
  37. package/dist/utils/cache.js +69 -0
  38. package/dist/utils/cache.js.map +1 -0
  39. package/dist/utils/constants.d.ts +2 -2
  40. package/dist/utils/constants.d.ts.map +1 -1
  41. package/dist/utils/constants.js +5 -13
  42. package/dist/utils/constants.js.map +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * LRU 缓存实现
4
+ * 用于存储编译后的日期格式化函数
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LRUCache = void 0;
8
+ /**
9
+ * LRU 缓存类
10
+ */
11
+ class LRUCache {
12
+ /**
13
+ * 构造函数
14
+ * @param maxSize 缓存最大容量,默认 100
15
+ */
16
+ constructor(maxSize = 100) {
17
+ this.cache = new Map();
18
+ this.maxSize = maxSize;
19
+ }
20
+ /**
21
+ * 获取缓存项
22
+ * @param key 缓存键
23
+ * @returns 缓存值,不存在返回 undefined
24
+ */
25
+ get(key) {
26
+ const value = this.cache.get(key);
27
+ if (value !== undefined) {
28
+ // 移动到末尾表示最近使用
29
+ this.cache.delete(key);
30
+ this.cache.set(key, value);
31
+ }
32
+ return value;
33
+ }
34
+ /**
35
+ * 设置缓存项
36
+ * @param key 缓存键
37
+ * @param value 缓存值
38
+ */
39
+ set(key, value) {
40
+ // 如果已存在,先删除
41
+ if (this.cache.has(key)) {
42
+ this.cache.delete(key);
43
+ }
44
+ else if (this.cache.size >= this.maxSize) {
45
+ // 缓存已满,删除最久未使用的项(Map 的第一个元素)
46
+ const firstKeyResult = this.cache.keys().next();
47
+ if (!firstKeyResult.done) {
48
+ this.cache.delete(firstKeyResult.value);
49
+ }
50
+ }
51
+ // 添加到末尾
52
+ this.cache.set(key, value);
53
+ }
54
+ /**
55
+ * 清空缓存
56
+ */
57
+ clear() {
58
+ this.cache.clear();
59
+ }
60
+ /**
61
+ * 获取缓存大小
62
+ * @returns 缓存大小
63
+ */
64
+ size() {
65
+ return this.cache.size;
66
+ }
67
+ }
68
+ exports.LRUCache = LRUCache;
69
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,MAAa,QAAQ;IAIjB;;;OAGG;IACH,YAAY,UAAkB,GAAG;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAQ,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAM;QACN,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,cAAc;YACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAM,EAAE,KAAQ;QAChB,YAAY;QACZ,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,6BAA6B;YAC7B,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAChD,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;gBACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;QACD,QAAQ;QACR,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,IAAI;QACA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3B,CAAC;CACJ;AA9DD,4BA8DC"}
@@ -7,6 +7,6 @@ export declare const DEFAULT_DATE_FORMAT_OPTIONS: {
7
7
  };
8
8
  /**
9
9
  * 周几中英文映射
10
- */
11
- export declare const WEEKDAY_MAP: Record<string, string[]>;
10
+ */
11
+ export declare const WEEKDAY_MAP: Record<string, [string, string, string, string, string, string, string]>;
12
12
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;CAGvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAWhD,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;CAGvC,CAAC;AAEF;;IAEI;AACJ,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAGhG,CAAC"}
@@ -5,22 +5,14 @@ exports.WEEKDAY_MAP = exports.DEFAULT_DATE_FORMAT_OPTIONS = void 0;
5
5
  * 默认格式化选项
6
6
  */
7
7
  exports.DEFAULT_DATE_FORMAT_OPTIONS = {
8
- timeZone: "local",
9
- locale: "zh-CN",
8
+ timeZone: 'local',
9
+ locale: 'zh-CN',
10
10
  };
11
11
  /**
12
12
  * 周几中英文映射
13
- */
13
+ */
14
14
  exports.WEEKDAY_MAP = {
15
- zh: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
16
- en: [
17
- "Sunday",
18
- "Monday",
19
- "Tuesday",
20
- "Wednesday",
21
- "Thursday",
22
- "Friday",
23
- "Saturday",
24
- ],
15
+ zh: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
16
+ en: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
25
17
  };
26
18
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,2BAA2B,GAAG;IACzC,QAAQ,EAAE,OAAgB;IAC1B,MAAM,EAAE,OAAO;CAChB,CAAC;AAEF;;GAEG;AACU,QAAA,WAAW,GAA6B;IACnD,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC9C,EAAE,EAAE;QACF,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,WAAW;QACX,UAAU;QACV,QAAQ;QACR,UAAU;KACX;CACF,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,2BAA2B,GAAG;IACvC,QAAQ,EAAE,OAAgB;IAC1B,MAAM,EAAE,OAAO;CAClB,CAAC;AAEF;;IAEI;AACS,QAAA,WAAW,GAA6E;IACjG,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC9C,EAAE,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC;CACrF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planarcat/js-toolkit",
3
- "version": "1.5.6",
3
+ "version": "1.7.0",
4
4
  "description": "一个自用的带学习性质的(目前)现代化的 JavaScript/TypeScript 实用工具库,提供类型安全、高性能的常用函数,包括对象转换、日期处理、函数优化等开发常用工具。",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",