@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.
- package/README.md +27 -5
- package/dist/date/compileDateFormatter.d.ts +16 -0
- package/dist/date/compileDateFormatter.d.ts.map +1 -0
- package/dist/date/compileDateFormatter.js +316 -0
- package/dist/date/compileDateFormatter.js.map +1 -0
- package/dist/date/formatDate.d.ts +81 -16
- package/dist/date/formatDate.d.ts.map +1 -1
- package/dist/date/formatDate.js +114 -130
- package/dist/date/formatDate.js.map +1 -1
- package/dist/date/formatDateCompiled.d.ts +30 -0
- package/dist/date/formatDateCompiled.d.ts.map +1 -0
- package/dist/date/formatDateCompiled.js +126 -0
- package/dist/date/formatDateCompiled.js.map +1 -0
- package/dist/date/formatDatePlain.d.ts +34 -0
- package/dist/date/formatDatePlain.d.ts.map +1 -0
- package/dist/date/formatDatePlain.js +128 -0
- package/dist/date/formatDatePlain.js.map +1 -0
- package/dist/date/regularDateFormatter.d.ts +33 -0
- package/dist/date/regularDateFormatter.d.ts.map +1 -0
- package/dist/date/regularDateFormatter.js +302 -0
- package/dist/date/regularDateFormatter.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/object/toFormattedNumber.d.ts +2 -2
- package/dist/object/toFormattedNumber.d.ts.map +1 -1
- package/dist/object/toFormattedNumber.js +8 -8
- package/dist/object/toFormattedNumber.js.map +1 -1
- package/dist/object/toFormattedNumberString.d.ts +2 -2
- package/dist/object/toFormattedNumberString.d.ts.map +1 -1
- package/dist/object/toFormattedNumberString.js +13 -9
- package/dist/object/toFormattedNumberString.js.map +1 -1
- package/dist/types/date.d.ts +19 -2
- package/dist/types/date.d.ts.map +1 -1
- package/dist/types/object.d.ts.map +1 -1
- package/dist/utils/cache.d.ts +38 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +69 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -13
- package/dist/utils/constants.js.map +1 -1
- 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;;
|
|
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"}
|
package/dist/utils/constants.js
CHANGED
|
@@ -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:
|
|
9
|
-
locale:
|
|
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;
|
|
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