@qwreey-js/ts-util 1.0.3 → 1.0.5
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/dist/base32.d.ts +16 -0
- package/dist/base32.d.ts.map +1 -0
- package/dist/base32.js +67 -0
- package/dist/base32.js.map +1 -0
- package/dist/base64.d.ts +34 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +81 -0
- package/dist/base64.js.map +1 -0
- package/dist/cached-getter.d.ts +22 -0
- package/dist/cached-getter.d.ts.map +1 -1
- package/dist/cached-getter.js +22 -0
- package/dist/cached-getter.js.map +1 -1
- package/dist/color.d.ts +72 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +187 -0
- package/dist/color.js.map +1 -0
- package/dist/date.d.ts +37 -4
- package/dist/date.d.ts.map +1 -1
- package/dist/date.js +105 -14
- package/dist/date.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interval.d.ts +66 -7
- package/dist/interval.d.ts.map +1 -1
- package/dist/interval.js +123 -16
- package/dist/interval.js.map +1 -1
- package/dist/mixin.d.ts +45 -0
- package/dist/mixin.d.ts.map +1 -1
- package/dist/mixin.js +77 -12
- package/dist/mixin.js.map +1 -1
- package/dist/params-builder.d.ts +31 -0
- package/dist/params-builder.d.ts.map +1 -0
- package/dist/params-builder.js +40 -0
- package/dist/params-builder.js.map +1 -0
- package/dist/result.d.ts +13 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +10 -0
- package/dist/result.js.map +1 -1
- package/dist/timeid.d.ts +24 -0
- package/dist/timeid.d.ts.map +1 -0
- package/dist/timeid.js +62 -0
- package/dist/timeid.js.map +1 -0
- package/dist/utils.d.ts +81 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +141 -1
- package/dist/utils.js.map +1 -1
- package/package.json +3 -2
package/dist/base32.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare namespace Base32 {
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a Uint8Array into a Base32 string according to RFC 4648.
|
|
4
|
+
* * @param {Uint8Array} uint8Array - The byte array to encode.
|
|
5
|
+
* @returns {string} The resulting Base32 encoded string.
|
|
6
|
+
*/
|
|
7
|
+
function fromUint8Array(uint8Array: Uint8Array): string;
|
|
8
|
+
/**
|
|
9
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
10
|
+
* Ignores padding characters ('=') and is case-insensitive.
|
|
11
|
+
* @param {string} base32 - The Base32 encoded string to decode.
|
|
12
|
+
* @returns {Uint8Array} The decoded byte array.
|
|
13
|
+
*/
|
|
14
|
+
function toUint8Array(base32: string): Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=base32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../src/base32.ts"],"names":[],"mappings":"AAAA,yBAAiB,MAAM,CAAC;IAGtB;;;;OAIG;IACH,SAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAwB7D;IAWD;;;;;OAKG;IACH,SAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAwBvD;CACF"}
|
package/dist/base32.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export var Base32;
|
|
2
|
+
(function (Base32) {
|
|
3
|
+
const Base32Alpabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
4
|
+
/**
|
|
5
|
+
* Encodes a Uint8Array into a Base32 string according to RFC 4648.
|
|
6
|
+
* * @param {Uint8Array} uint8Array - The byte array to encode.
|
|
7
|
+
* @returns {string} The resulting Base32 encoded string.
|
|
8
|
+
*/
|
|
9
|
+
function fromUint8Array(uint8Array) {
|
|
10
|
+
let bits = 0;
|
|
11
|
+
let value = 0;
|
|
12
|
+
const output = [];
|
|
13
|
+
for (const byte of uint8Array) {
|
|
14
|
+
value = (value << 8) | byte;
|
|
15
|
+
bits += 8;
|
|
16
|
+
while (bits >= 5) {
|
|
17
|
+
output.push(Base32Alpabet[(value >>> (bits - 5)) & 31]);
|
|
18
|
+
bits -= 5;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (bits > 0) {
|
|
22
|
+
output.push(Base32Alpabet[(value << (5 - bits)) & 31]);
|
|
23
|
+
}
|
|
24
|
+
while (output.length % 8 !== 0) {
|
|
25
|
+
output.push("=");
|
|
26
|
+
}
|
|
27
|
+
return output.join("");
|
|
28
|
+
}
|
|
29
|
+
Base32.fromUint8Array = fromUint8Array;
|
|
30
|
+
const Base32Lookup = (() => {
|
|
31
|
+
const arr = new Int8Array(256);
|
|
32
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
33
|
+
for (let i = 0; i < chars.length; i++) {
|
|
34
|
+
arr[chars.charCodeAt(i)] = i;
|
|
35
|
+
}
|
|
36
|
+
return arr;
|
|
37
|
+
})();
|
|
38
|
+
/**
|
|
39
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
40
|
+
* Ignores padding characters ('=') and is case-insensitive.
|
|
41
|
+
* @param {string} base32 - The Base32 encoded string to decode.
|
|
42
|
+
* @returns {Uint8Array} The decoded byte array.
|
|
43
|
+
*/
|
|
44
|
+
function toUint8Array(base32) {
|
|
45
|
+
// 소문자가 들어와도 대문자로 처리. 패딩(=) 제거
|
|
46
|
+
const str = base32.toUpperCase().replace(/=/g, "");
|
|
47
|
+
const outLen = Math.floor((str.length * 5) / 8);
|
|
48
|
+
const result = new Uint8Array(outLen);
|
|
49
|
+
let bits = 0;
|
|
50
|
+
let value = 0;
|
|
51
|
+
let index = 0;
|
|
52
|
+
for (let i = 0; i < str.length; i++) {
|
|
53
|
+
const charCode = str.charCodeAt(i);
|
|
54
|
+
// 5비트씩 가져오기
|
|
55
|
+
value = (value << 5) | Base32Lookup[charCode];
|
|
56
|
+
bits += 5;
|
|
57
|
+
// 8비트가 모이면 하나의 바이트로 결과 배열에 넣기
|
|
58
|
+
if (bits >= 8) {
|
|
59
|
+
result[index++] = (value >>> (bits - 8)) & 255;
|
|
60
|
+
bits -= 8;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
Base32.toUint8Array = toUint8Array;
|
|
66
|
+
})(Base32 || (Base32 = {}));
|
|
67
|
+
//# sourceMappingURL=base32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base32.js","sourceRoot":"","sources":["../src/base32.ts"],"names":[],"mappings":"AAAA,MAAM,KAAW,MAAM,CA0EtB;AA1ED,WAAiB,MAAM;IACrB,MAAM,aAAa,GAAG,kCAAkC,CAAC;IAEzD;;;;OAIG;IACH,SAAgB,cAAc,CAAC,UAAsB;QACnD,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;YAC5B,IAAI,IAAI,CAAC,CAAC;YAEV,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;gBACxD,IAAI,IAAI,CAAC,CAAC;YACZ,CAAC;QACH,CAAC;QAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,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AAI,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAE,CAAC;YAC/C,IAAI,IAAI,CAAC,CAAC;YAEV,8BAA8B;YAC9B,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;gBACd,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;gBAC/C,IAAI,IAAI,CAAC,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAxBe,mBAAY,eAwB3B,CAAA;AACH,CAAC,EA1EgB,MAAM,KAAN,MAAM,QA0EtB"}
|
package/dist/base64.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare namespace Base64 {
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for Base64 encoding.
|
|
4
|
+
*/
|
|
5
|
+
interface ToBase64Options {
|
|
6
|
+
/**
|
|
7
|
+
* The alphabet to use for encoding.
|
|
8
|
+
* 'base64' uses the standard Base64 alphabet (RFC 4648).
|
|
9
|
+
* 'base64url' uses the URL-safe Base64 alphabet.
|
|
10
|
+
* @default 'base64'
|
|
11
|
+
*/
|
|
12
|
+
alphabet?: "base64" | "base64url";
|
|
13
|
+
/**
|
|
14
|
+
* Whether to omit the padding character ('=') at the end of the output.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
omitPadding?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Encodes a Uint8Array into a Base64 or Base64URL string.
|
|
21
|
+
* @param {Uint8Array} uint8Array - The byte array to encode.
|
|
22
|
+
* @param {ToBase64Options} [options] - Optional encoding configuration.
|
|
23
|
+
* @returns {string} The resulting Base64 or Base64URL encoded string.
|
|
24
|
+
*/
|
|
25
|
+
function fromUint8Array(uint8Array: Uint8Array, options?: ToBase64Options): string;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a Base64 or Base64URL string into a Uint8Array.
|
|
28
|
+
* Automatically handles both standard and URL-safe alphabets and ignores padding characters ('=').
|
|
29
|
+
* @param {string} base64 - The Base64 or Base64URL encoded string to decode.
|
|
30
|
+
* @returns {Uint8Array} The decoded byte array.
|
|
31
|
+
*/
|
|
32
|
+
function toUint8Array(base64: string): Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,yBAAiB,MAAM,CAAC;IACtB;;OAEG;IACH,UAAiB,eAAe;QAC9B;;;;;WAKG;QACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;QAClC;;;WAGG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB;IAOD;;;;;OAKG;IACH,SAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,MAAM,CAuCR;IAYD;;;;;OAKG;IACH,SAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAwBvD;CACF"}
|
package/dist/base64.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export var Base64;
|
|
2
|
+
(function (Base64) {
|
|
3
|
+
const Base64Alpabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
|
+
const Base64AlpabetUrl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
5
|
+
/**
|
|
6
|
+
* Encodes a Uint8Array into a Base64 or Base64URL string.
|
|
7
|
+
* @param {Uint8Array} uint8Array - The byte array to encode.
|
|
8
|
+
* @param {ToBase64Options} [options] - Optional encoding configuration.
|
|
9
|
+
* @returns {string} The resulting Base64 or Base64URL encoded string.
|
|
10
|
+
*/
|
|
11
|
+
function fromUint8Array(uint8Array, options) {
|
|
12
|
+
if (uint8Array.toBase64) {
|
|
13
|
+
return uint8Array.toBase64(options);
|
|
14
|
+
}
|
|
15
|
+
const alphabetName = options?.alphabet ?? "base64";
|
|
16
|
+
const omitPadding = options?.omitPadding ?? false;
|
|
17
|
+
const chars = alphabetName === "base64url" ? Base64AlpabetUrl : Base64Alpabet;
|
|
18
|
+
let result = "";
|
|
19
|
+
const len = uint8Array.length;
|
|
20
|
+
// 3바이트(24비트)씩 끊어서 4개의 6비트 문자로 변환
|
|
21
|
+
for (let i = 0; i < len; i += 3) {
|
|
22
|
+
const b1 = uint8Array[i];
|
|
23
|
+
const b2 = i + 1 < len ? uint8Array[i + 1] : 0;
|
|
24
|
+
const b3 = i + 2 < len ? uint8Array[i + 2] : 0;
|
|
25
|
+
const bits = (b1 << 16) | (b2 << 8) | b3;
|
|
26
|
+
result += chars[(bits >> 18) & 63];
|
|
27
|
+
result += chars[(bits >> 12) & 63];
|
|
28
|
+
if (i + 1 < len) {
|
|
29
|
+
result += chars[(bits >> 6) & 63];
|
|
30
|
+
}
|
|
31
|
+
else if (!omitPadding) {
|
|
32
|
+
result += "=";
|
|
33
|
+
}
|
|
34
|
+
if (i + 2 < len) {
|
|
35
|
+
result += chars[bits & 63];
|
|
36
|
+
}
|
|
37
|
+
else if (!omitPadding) {
|
|
38
|
+
result += "=";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
Base64.fromUint8Array = fromUint8Array;
|
|
44
|
+
const Base64Lookup = (() => {
|
|
45
|
+
const arr = new Int8Array(256);
|
|
46
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
47
|
+
for (let i = 0; i < chars.length; i++) {
|
|
48
|
+
arr[chars.charCodeAt(i)] = i;
|
|
49
|
+
}
|
|
50
|
+
return arr;
|
|
51
|
+
})();
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a Base64 or Base64URL string into a Uint8Array.
|
|
54
|
+
* Automatically handles both standard and URL-safe alphabets and ignores padding characters ('=').
|
|
55
|
+
* @param {string} base64 - The Base64 or Base64URL encoded string to decode.
|
|
56
|
+
* @returns {Uint8Array} The decoded byte array.
|
|
57
|
+
*/
|
|
58
|
+
function toUint8Array(base64) {
|
|
59
|
+
// Base64URL의 -, _ 문자를 표준 +, / 로 바꾸고 패딩 제거
|
|
60
|
+
const str = base64.replace(/-/g, "+").replace(/_/g, "/").replace(/=/g, "");
|
|
61
|
+
const outLen = Math.floor((str.length * 3) / 4);
|
|
62
|
+
const result = new Uint8Array(outLen);
|
|
63
|
+
let bits = 0;
|
|
64
|
+
let value = 0;
|
|
65
|
+
let index = 0;
|
|
66
|
+
for (let i = 0; i < str.length; i++) {
|
|
67
|
+
const charCode = str.charCodeAt(i);
|
|
68
|
+
// 6비트씩 가져오기
|
|
69
|
+
value = (value << 6) | Base64Lookup[charCode];
|
|
70
|
+
bits += 6;
|
|
71
|
+
// 8비트가 모일 때마다 바이트로 저장
|
|
72
|
+
if (bits >= 8) {
|
|
73
|
+
result[index++] = (value >>> (bits - 8)) & 255;
|
|
74
|
+
bits -= 8;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
Base64.toUint8Array = toUint8Array;
|
|
80
|
+
})(Base64 || (Base64 = {}));
|
|
81
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,MAAM,KAAW,MAAM,CAmHtB;AAnHD,WAAiB,MAAM;IAmBrB,MAAM,aAAa,GACjB,kEAAkE,CAAC;IACrE,MAAM,gBAAgB,GACpB,kEAAkE,CAAC;IAErE;;;;;OAKG;IACH,SAAgB,cAAc,CAC5B,UAAsB,EACtB,OAAyB;QAEzB,IAAK,UAAkB,CAAC,QAAQ,EAAE,CAAC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AAC,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACnC,YAAY;YACZ,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAE,CAAC;YAC/C,IAAI,IAAI,CAAC,CAAC;YAEV,sBAAsB;YACtB,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;gBACd,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;gBAC/C,IAAI,IAAI,CAAC,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAxBe,mBAAY,eAwB3B,CAAA;AACH,CAAC,EAnHgB,MAAM,KAAN,MAAM,QAmHtB"}
|
package/dist/cached-getter.d.ts
CHANGED
|
@@ -1,16 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility for caching the result of an asynchronous function for a specified Time-To-Live (TTL, interval).
|
|
3
|
+
* If `getValue` is called multiple times within the TTL, it returns the cached result instead of executing the function again.
|
|
4
|
+
*/
|
|
1
5
|
export declare class CachedGetter<Res> {
|
|
2
6
|
private func;
|
|
3
7
|
private interval;
|
|
4
8
|
private value?;
|
|
5
9
|
private last?;
|
|
10
|
+
/**
|
|
11
|
+
* @param func The asynchronous function to execute and cache.
|
|
12
|
+
* @param interval The Time-To-Live interval in milliseconds.
|
|
13
|
+
*/
|
|
6
14
|
constructor(func: () => Promise<Res>, interval: number);
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the cached value or executes the function if the cache has expired or is missing.
|
|
17
|
+
*/
|
|
7
18
|
getValue(): Promise<Res>;
|
|
8
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A mapped variant of `CachedGetter`. It caches multiple asynchronous function results based on unique keys.
|
|
22
|
+
*/
|
|
9
23
|
export declare class CachedGetterMap<Res, Key> {
|
|
10
24
|
private func;
|
|
11
25
|
private interval;
|
|
12
26
|
private values;
|
|
27
|
+
/**
|
|
28
|
+
* @param func The asynchronous function to execute and cache per key.
|
|
29
|
+
* @param interval The Time-To-Live interval in milliseconds.
|
|
30
|
+
*/
|
|
13
31
|
constructor(func: (key: Key) => Promise<Res>, interval: number);
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the cached value for the specific key, or executes the function if the cache has expired or is missing.
|
|
34
|
+
* @param key The unique key identifying the cached result.
|
|
35
|
+
*/
|
|
14
36
|
getValue(key: Key): Promise<Res>;
|
|
15
37
|
}
|
|
16
38
|
export declare namespace CachedGetterMap {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-getter.d.ts","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY,CAAC,GAAG;IAC3B,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAS;
|
|
1
|
+
{"version":3,"file":"cached-getter.d.ts","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,YAAY,CAAC,GAAG;IAC3B,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAS;IAEtB;;;OAGG;gBACgB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM;IAK7D;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC;CAStC;AAED;;GAEG;AACH,qBAAa,eAAe,CAAC,GAAG,EAAE,GAAG;IACnC,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAwC;IAEtD;;;OAGG;gBACgB,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM;IAMrE;;;OAGG;IACU,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAc9C;AACD,yBAAiB,eAAe,CAAC;IAC/B,KAAY,MAAM,CAAC,GAAG,IAAI;QACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH"}
|
package/dist/cached-getter.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility for caching the result of an asynchronous function for a specified Time-To-Live (TTL, interval).
|
|
3
|
+
* If `getValue` is called multiple times within the TTL, it returns the cached result instead of executing the function again.
|
|
4
|
+
*/
|
|
1
5
|
export class CachedGetter {
|
|
2
6
|
func;
|
|
3
7
|
interval;
|
|
4
8
|
value;
|
|
5
9
|
last;
|
|
10
|
+
/**
|
|
11
|
+
* @param func The asynchronous function to execute and cache.
|
|
12
|
+
* @param interval The Time-To-Live interval in milliseconds.
|
|
13
|
+
*/
|
|
6
14
|
constructor(func, interval) {
|
|
7
15
|
this.func = func;
|
|
8
16
|
this.interval = interval;
|
|
9
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the cached value or executes the function if the cache has expired or is missing.
|
|
20
|
+
*/
|
|
10
21
|
async getValue() {
|
|
11
22
|
const curr = +new Date();
|
|
12
23
|
if (!this.value || !this.last || this.last + this.interval < curr) {
|
|
@@ -17,15 +28,26 @@ export class CachedGetter {
|
|
|
17
28
|
return await this.value;
|
|
18
29
|
}
|
|
19
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A mapped variant of `CachedGetter`. It caches multiple asynchronous function results based on unique keys.
|
|
33
|
+
*/
|
|
20
34
|
export class CachedGetterMap {
|
|
21
35
|
func;
|
|
22
36
|
interval;
|
|
23
37
|
values;
|
|
38
|
+
/**
|
|
39
|
+
* @param func The asynchronous function to execute and cache per key.
|
|
40
|
+
* @param interval The Time-To-Live interval in milliseconds.
|
|
41
|
+
*/
|
|
24
42
|
constructor(func, interval) {
|
|
25
43
|
this.func = func;
|
|
26
44
|
this.values = new Map();
|
|
27
45
|
this.interval = interval;
|
|
28
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the cached value for the specific key, or executes the function if the cache has expired or is missing.
|
|
49
|
+
* @param key The unique key identifying the cached result.
|
|
50
|
+
*/
|
|
29
51
|
async getValue(key) {
|
|
30
52
|
const curr = +new Date();
|
|
31
53
|
const record = this.values.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-getter.js","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACf,IAAI,CAAqB;IACzB,QAAQ,CAAS;IACjB,KAAK,CAAgB;IACrB,IAAI,CAAU;IAEtB,YAAmB,IAAwB,EAAE,QAAgB;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;
|
|
1
|
+
{"version":3,"file":"cached-getter.js","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,YAAY;IACf,IAAI,CAAqB;IACzB,QAAQ,CAAS;IACjB,KAAK,CAAgB;IACrB,IAAI,CAAU;IAEtB;;;OAGG;IACH,YAAmB,IAAwB,EAAE,QAAgB;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3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AAC;QACrB,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export declare class RGBColor {
|
|
2
|
+
/** 0-255 sRGB red value */
|
|
3
|
+
readonly r: number;
|
|
4
|
+
/** 0-255 sRGB green value */
|
|
5
|
+
readonly g: number;
|
|
6
|
+
/** 0-255 sRGB blue value */
|
|
7
|
+
readonly b: number;
|
|
8
|
+
constructor(r: number, g: number, b: number);
|
|
9
|
+
/**
|
|
10
|
+
* Converts a hex color string to an RGB object.
|
|
11
|
+
* @param hex 3-digit (#FFF) or 6-digit (#FFFFFF) hex string
|
|
12
|
+
*/
|
|
13
|
+
static fromHex(hex: string): RGBColor;
|
|
14
|
+
/**
|
|
15
|
+
* Converts an Oklab color back to an RGB color.
|
|
16
|
+
*/
|
|
17
|
+
static fromOKLab(okLab: OKLabColor): RGBColor;
|
|
18
|
+
/**
|
|
19
|
+
* Linearly interpolates (Lerps) between two sRGB colors based on an amount (0~1).
|
|
20
|
+
*/
|
|
21
|
+
static lerp(from: RGBColor, to: RGBColor, amount: number): RGBColor;
|
|
22
|
+
/**
|
|
23
|
+
* Convert to a hex color string.
|
|
24
|
+
*/
|
|
25
|
+
toHex(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Convert to a OKLab color.
|
|
28
|
+
*/
|
|
29
|
+
toOKLab(): OKLabColor;
|
|
30
|
+
}
|
|
31
|
+
export declare class OKLabColor {
|
|
32
|
+
/** Lightness */
|
|
33
|
+
readonly l: number;
|
|
34
|
+
/** Green-Red component */
|
|
35
|
+
readonly a: number;
|
|
36
|
+
/** Blue-Yellow component */
|
|
37
|
+
readonly b: number;
|
|
38
|
+
constructor(l: number, a: number, b: number);
|
|
39
|
+
/**
|
|
40
|
+
* Converts an RGB color to an Oklab color.
|
|
41
|
+
* Note: Uses Björn Ottosson's standard Oklab transformation matrices.
|
|
42
|
+
*/
|
|
43
|
+
static fromRGB(rgb: RGBColor): OKLabColor;
|
|
44
|
+
/**
|
|
45
|
+
* Converts an Hex color to an Oklab color.
|
|
46
|
+
* Note: Uses Björn Ottosson's standard Oklab transformation matrices.
|
|
47
|
+
*/
|
|
48
|
+
static fromHex(hex: string): OKLabColor;
|
|
49
|
+
/**
|
|
50
|
+
* Linearly interpolates (Lerps) between two Oklab colors based on an amount (0~1).
|
|
51
|
+
*/
|
|
52
|
+
static lerp(from: OKLabColor, to: OKLabColor, amount: number): OKLabColor;
|
|
53
|
+
toHex(): string;
|
|
54
|
+
toRGB(): RGBColor;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Naturally interpolates between two hex colors in the Oklab color space, then returns the resulting hex color.
|
|
58
|
+
* @param fromHex Start color (e.g., "#FF0000")
|
|
59
|
+
* @param toHex Target color (e.g., "#0000FF")
|
|
60
|
+
* @param amount Transition value (0.0 ~ 1.0)
|
|
61
|
+
* @returns Interpolated hex color string
|
|
62
|
+
*/
|
|
63
|
+
export declare function lerpHexColorInOKLab(fromHex: string, toHex: string, amount: number): string;
|
|
64
|
+
/**
|
|
65
|
+
* sRGB interpolates between two hex color, then returns the resulting hex color.
|
|
66
|
+
* @param fromHex Start color (e.g., "#FF0000")
|
|
67
|
+
* @param toHex Target color (e.g., "#0000FF")
|
|
68
|
+
* @param amount Transition value (0.0 ~ 1.0)
|
|
69
|
+
* @returns Interpolated hex color string
|
|
70
|
+
*/
|
|
71
|
+
export declare function lerpHexColorInSRGB(fromHex: string, toHex: string, amount: number): string;
|
|
72
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAcA,qBAAa,QAAQ;IACnB,2BAA2B;IAC3B,SAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6BAA6B;IAC7B,SAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4B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R"}
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Convert sRGB value to Linear sRGB space (Remove Gamma)
|
|
2
|
+
const toLinear = (c) => c > 0.04045 ? Math.pow((c + 0.055) / 1.055, 2.4) : c / 12.92;
|
|
3
|
+
// Convert Linear sRGB space to sRGB value (Apply Gamma)
|
|
4
|
+
const toSrgb = (c) => c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
5
|
+
// Clamp to prevent out-of-bounds values after Oklab conversion
|
|
6
|
+
const clampSrgb = (val) => Math.max(0, Math.min(255, Math.round(val)));
|
|
7
|
+
// Clamp amount between 0 and 1
|
|
8
|
+
const clampAmount = (amount) => Math.max(0, Math.min(1, amount));
|
|
9
|
+
export class RGBColor {
|
|
10
|
+
/** 0-255 sRGB red value */
|
|
11
|
+
r;
|
|
12
|
+
/** 0-255 sRGB green value */
|
|
13
|
+
g;
|
|
14
|
+
/** 0-255 sRGB blue value */
|
|
15
|
+
b;
|
|
16
|
+
constructor(r, g, b) {
|
|
17
|
+
this.r = r;
|
|
18
|
+
this.g = g;
|
|
19
|
+
this.b = b;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts a hex color string to an RGB object.
|
|
23
|
+
* @param hex 3-digit (#FFF) or 6-digit (#FFFFFF) hex string
|
|
24
|
+
*/
|
|
25
|
+
static fromHex(hex) {
|
|
26
|
+
let cleaned = hex.replace("#", "");
|
|
27
|
+
if (cleaned.length === 3) {
|
|
28
|
+
cleaned = cleaned
|
|
29
|
+
.split("")
|
|
30
|
+
.map((char) => char + char)
|
|
31
|
+
.join("");
|
|
32
|
+
}
|
|
33
|
+
const num = parseInt(cleaned, 16);
|
|
34
|
+
if (isNaN(num)) {
|
|
35
|
+
throw new Error(`Invalid hex color: ${hex}`);
|
|
36
|
+
}
|
|
37
|
+
return new RGBColor((num >> 16) & 255, (num >> 8) & 255, num & 255);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts an Oklab color back to an RGB color.
|
|
41
|
+
*/
|
|
42
|
+
static fromOKLab(okLab) {
|
|
43
|
+
// 1. Oklab to Non-linear LMS (Inverse Matrix M2)
|
|
44
|
+
const l_ = okLab.l + 0.3963377774 * okLab.a + 0.2158037573 * okLab.b;
|
|
45
|
+
const m_ = okLab.l - 0.1055613458 * okLab.a - 0.0638541728 * okLab.b;
|
|
46
|
+
const s_ = okLab.l - 0.0894841775 * okLab.a - 1.291485548 * okLab.b;
|
|
47
|
+
// 2. Linear LMS (cube)
|
|
48
|
+
const lmsL = l_ * l_ * l_;
|
|
49
|
+
const lmsM = m_ * m_ * m_;
|
|
50
|
+
const lmsS = s_ * s_ * s_;
|
|
51
|
+
// 3. LMS to Linear RGB (Inverse Matrix M1)
|
|
52
|
+
const lr = 4.0767416621 * lmsL - 3.3077115913 * lmsM + 0.2309699292 * lmsS;
|
|
53
|
+
const lg = -1.2684380046 * lmsL + 2.6097574011 * lmsM - 0.3413193965 * lmsS;
|
|
54
|
+
const lb = -0.0041960863 * lmsL - 0.7034186147 * lmsM + 1.707614701 * lmsS;
|
|
55
|
+
// 4. Linear RGB to sRGB (apply Gamma) & Scale back to [0, 255]
|
|
56
|
+
return new RGBColor(toSrgb(lr) * 255, toSrgb(lg) * 255, toSrgb(lb) * 255);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Linearly interpolates (Lerps) between two sRGB colors based on an amount (0~1).
|
|
60
|
+
*/
|
|
61
|
+
static lerp(from, to, amount) {
|
|
62
|
+
const t = clampAmount(amount);
|
|
63
|
+
if (t === 0)
|
|
64
|
+
return from;
|
|
65
|
+
if (t === 1)
|
|
66
|
+
return to;
|
|
67
|
+
// Linear interpolation for each color component
|
|
68
|
+
const r = Math.round(from.r + (to.r - from.r) * t);
|
|
69
|
+
const g = Math.round(from.g + (to.g - from.g) * t);
|
|
70
|
+
const b = Math.round(from.b + (to.b - from.b) * t);
|
|
71
|
+
return new RGBColor(r, g, b);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convert to a hex color string.
|
|
75
|
+
*/
|
|
76
|
+
toHex() {
|
|
77
|
+
const r = clampSrgb(this.r).toString(16).padStart(2, "0");
|
|
78
|
+
const g = clampSrgb(this.g).toString(16).padStart(2, "0");
|
|
79
|
+
const b = clampSrgb(this.b).toString(16).padStart(2, "0");
|
|
80
|
+
return `#${r}${g}${b}`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert to a OKLab color.
|
|
84
|
+
*/
|
|
85
|
+
toOKLab() {
|
|
86
|
+
return OKLabColor.fromRGB(this);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export class OKLabColor {
|
|
90
|
+
/** Lightness */
|
|
91
|
+
l;
|
|
92
|
+
/** Green-Red component */
|
|
93
|
+
a;
|
|
94
|
+
/** Blue-Yellow component */
|
|
95
|
+
b;
|
|
96
|
+
constructor(l, a, b) {
|
|
97
|
+
this.l = l;
|
|
98
|
+
this.a = a;
|
|
99
|
+
this.b = b;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Converts an RGB color to an Oklab color.
|
|
103
|
+
* Note: Uses Björn Ottosson's standard Oklab transformation matrices.
|
|
104
|
+
*/
|
|
105
|
+
static fromRGB(rgb) {
|
|
106
|
+
// 1. Normalize sRGB to [0, 1] & Convert to Linear RGB
|
|
107
|
+
const lr = toLinear(rgb.r / 255);
|
|
108
|
+
const lg = toLinear(rgb.g / 255);
|
|
109
|
+
const lb = toLinear(rgb.b / 255);
|
|
110
|
+
// 2. Linear RGB to LMS space (Matrix M1)
|
|
111
|
+
const lmsL = 0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb;
|
|
112
|
+
const lmsM = 0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb;
|
|
113
|
+
const lmsS = 0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb;
|
|
114
|
+
// 3. Non-linear LMS (cube root)
|
|
115
|
+
const l_ = Math.cbrt(lmsL);
|
|
116
|
+
const m_ = Math.cbrt(lmsM);
|
|
117
|
+
const s_ = Math.cbrt(lmsS);
|
|
118
|
+
// 4. LMS to Oklab (Matrix M2)
|
|
119
|
+
return new OKLabColor(0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_, 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_, 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Converts an Hex color to an Oklab color.
|
|
123
|
+
* Note: Uses Björn Ottosson's standard Oklab transformation matrices.
|
|
124
|
+
*/
|
|
125
|
+
static fromHex(hex) {
|
|
126
|
+
return OKLabColor.fromRGB(RGBColor.fromHex(hex));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Linearly interpolates (Lerps) between two Oklab colors based on an amount (0~1).
|
|
130
|
+
*/
|
|
131
|
+
static lerp(from, to, amount) {
|
|
132
|
+
// Clamp amount between 0 and 1
|
|
133
|
+
const t = clampAmount(amount);
|
|
134
|
+
if (t === 0)
|
|
135
|
+
return from;
|
|
136
|
+
if (t === 1)
|
|
137
|
+
return to;
|
|
138
|
+
return new OKLabColor(from.l + (to.l - from.l) * t, from.a + (to.a - from.a) * t, from.b + (to.b - from.b) * t);
|
|
139
|
+
}
|
|
140
|
+
toHex() {
|
|
141
|
+
return RGBColor.fromOKLab(this).toHex();
|
|
142
|
+
}
|
|
143
|
+
toRGB() {
|
|
144
|
+
return RGBColor.fromOKLab(this);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Naturally interpolates between two hex colors in the Oklab color space, then returns the resulting hex color.
|
|
149
|
+
* @param fromHex Start color (e.g., "#FF0000")
|
|
150
|
+
* @param toHex Target color (e.g., "#0000FF")
|
|
151
|
+
* @param amount Transition value (0.0 ~ 1.0)
|
|
152
|
+
* @returns Interpolated hex color string
|
|
153
|
+
*/
|
|
154
|
+
export function lerpHexColorInOKLab(fromHex, toHex, amount) {
|
|
155
|
+
// 1. Clamp amount
|
|
156
|
+
const t = clampAmount(amount);
|
|
157
|
+
if (t === 0)
|
|
158
|
+
return fromHex;
|
|
159
|
+
if (t === 1)
|
|
160
|
+
return toHex;
|
|
161
|
+
// 2. Convert RGB to Oklab color space
|
|
162
|
+
const oklab1 = OKLabColor.fromHex(fromHex);
|
|
163
|
+
const oklab2 = OKLabColor.fromHex(toHex);
|
|
164
|
+
// 3. Safely interpolate (Lerp) in the Oklab space
|
|
165
|
+
const lerpedOklab = OKLabColor.lerp(oklab1, oklab2, t);
|
|
166
|
+
// 5. Assemble final RGB values back to a hex string (includes clamping)
|
|
167
|
+
return lerpedOklab.toHex();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* sRGB interpolates between two hex color, then returns the resulting hex color.
|
|
171
|
+
* @param fromHex Start color (e.g., "#FF0000")
|
|
172
|
+
* @param toHex Target color (e.g., "#0000FF")
|
|
173
|
+
* @param amount Transition value (0.0 ~ 1.0)
|
|
174
|
+
* @returns Interpolated hex color string
|
|
175
|
+
*/
|
|
176
|
+
export function lerpHexColorInSRGB(fromHex, toHex, amount) {
|
|
177
|
+
const t = clampAmount(amount);
|
|
178
|
+
if (t === 0)
|
|
179
|
+
return fromHex;
|
|
180
|
+
if (t === 1)
|
|
181
|
+
return toHex;
|
|
182
|
+
const rgb1 = RGBColor.fromHex(fromHex);
|
|
183
|
+
const rgb2 = RGBColor.fromHex(toHex);
|
|
184
|
+
const lerpedRgb = RGBColor.lerp(rgb1, rgb2, t);
|
|
185
|
+
return lerpedRgb.toHex();
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,QAAQ,GAAG,CAAC,CAAS,E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K,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE1B,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAErC,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE/C,OAAO,SAAS,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/date.d.ts
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions for Date manipulation.
|
|
3
|
+
* * @remarks
|
|
4
|
+
* **Known Limitations:**
|
|
5
|
+
* - **Two-digit Year Behavior:** Due to native JavaScript `Date` constructor rules, year values between 0 and 99 are interpreted as 1900-1999 (e.g., year 26 becomes 1926).
|
|
6
|
+
* - **Automatic Date Rollover:** Invalid dates (such as month 13 or day 32) do not throw errors. The native `Date` object will silently roll over and recalculate to the next valid date.
|
|
7
|
+
*/
|
|
1
8
|
export declare namespace DateUtil {
|
|
9
|
+
/** Create new date without time */
|
|
2
10
|
function removeTime(dateTime: Date): Date;
|
|
11
|
+
/** Create new date without time and days */
|
|
3
12
|
function removeDay(dateTime: Date): Date;
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
function
|
|
13
|
+
/** Formats a date to YYYY-MM-DD */
|
|
14
|
+
function formatYYYYMMDD(date: Date, delimit?: string): string;
|
|
15
|
+
/** Formats a date to YYYY-MM */
|
|
16
|
+
function formatYYYYMM(date: Date, delimit?: string): string;
|
|
17
|
+
/** Formats a date to HH:MM:SS */
|
|
18
|
+
function formatHHMMSS(date: Date, delimit?: string): string;
|
|
19
|
+
/** Formats a date to HH:MM */
|
|
20
|
+
function formatHHMM(date: Date, delimit?: string): string;
|
|
21
|
+
/** Formats a date to UTC YYYY-MM-DD */
|
|
22
|
+
function formatUTCYYYYMMDD(date: Date, delimit?: string): string;
|
|
23
|
+
/** Formats a date to UTC YYYY-MM */
|
|
24
|
+
function formatUTCYYYYMM(date: Date, delimit?: string): string;
|
|
25
|
+
/** Formats a date to UTC HH:MM:SS */
|
|
26
|
+
function formatUTCHHMMSS(date: Date, delimit?: string): string;
|
|
27
|
+
/** Formats a date to UTC HH:MM */
|
|
28
|
+
function formatUTCHHMM(date: Date, delimit?: string): string;
|
|
29
|
+
/** Parses a string formatted as YYYY-MM-DD into a Date */
|
|
30
|
+
function fromYYYYMMDD(str: string, delimit?: string): Date;
|
|
31
|
+
/** Parses a string formatted as YYYY-MM-DD into a UTC Date */
|
|
32
|
+
function fromUTCYYYYMMDD(str: string, delimit?: string): Date;
|
|
33
|
+
/** Korean full names of the days of the week */
|
|
34
|
+
const KoreanWeekNames: string[];
|
|
35
|
+
/** Korean short names of the days of the week */
|
|
36
|
+
const KoreanWeekNamesShort: string[];
|
|
37
|
+
/** English full names of the days of the week */
|
|
38
|
+
const EnglishWeekNames: string[];
|
|
39
|
+
/** English short names of the days of the week */
|
|
40
|
+
const EnglishWeekNamesShort: string[];
|
|
8
41
|
}
|
|
9
42
|
//# sourceMappingURL=date.d.ts.map
|