@qwreey-js/ts-util 1.0.4 → 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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mixin.d.ts +19 -0
- package/dist/mixin.d.ts.map +1 -1
- package/dist/mixin.js +67 -12
- package/dist/mixin.js.map +1 -1
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +2 -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/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;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|
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;YACjC,OAAQ,UAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,EAAE,QAAQ,IAAI,QAAQ,CAAC;QACnD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,KAAK,CAAC;QAElD,MAAM,KAAK,GACT,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,aAAa,CAAC;QAElE,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;QAE9B,iCAAiC;QACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;YAC1B,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ACZ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAxBe,mBAAY,eAwB3B,CAAA;AACH,CAAC,EAnHgB,MAAM,KAAN,MAAM,QAmHtB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./mixin.js";
|
|
|
6
6
|
export * from "./params-builder.js";
|
|
7
7
|
export * from "./result.js";
|
|
8
8
|
export * from "./utils.js";
|
|
9
|
+
export * from "./base32.js";
|
|
10
|
+
export * from "./base64.js";
|
|
9
11
|
import { setLogErr as _setLogErr } from "./libLog.js";
|
|
10
12
|
export declare namespace UtilLogging {
|
|
11
13
|
const setLogErr: typeof _setLogErr;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,SAAS,IAAI,UAAU,EAAqB,MAAM,aAAa,CAAC;AACzE,yBAAiB,WAAW,CAAC;IACpB,MAAM,SAAS,mBAAa,CAAC;IAC7B,MAAM,MAAM,8BAAU,CAAC;CAC/B"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./mixin.js";
|
|
|
6
6
|
export * from "./params-builder.js";
|
|
7
7
|
export * from "./result.js";
|
|
8
8
|
export * from "./utils.js";
|
|
9
|
+
export * from "./base32.js";
|
|
10
|
+
export * from "./base64.js";
|
|
9
11
|
import { setLogErr as _setLogErr, logErr as _logErr } from "./libLog.js";
|
|
10
12
|
export var UtilLogging;
|
|
11
13
|
(function (UtilLogging) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AACzE,MAAM,KAAW,WAAW,CAG3B;AAHD,WAAiB,WAAW;IACb,qBAAS,GAAG,UAAU,CAAC;IACvB,kBAAM,GAAG,OAAO,CAAC;AAChC,CAAC,EAHgB,WAAW,KAAX,WAAW,QAG3B"}
|
package/dist/mixin.d.ts
CHANGED
|
@@ -23,6 +23,25 @@ export type Mixin<T extends AbstractConstructor[]> = T extends [
|
|
|
23
23
|
* @param baseClassList An array of base classes to mix into the `targetClass`.
|
|
24
24
|
*/
|
|
25
25
|
export declare function applyRuntimeMixins(targetClass: any, baseClassList: any[]): void;
|
|
26
|
+
export declare function isNonNullObject(instance: any): instance is object;
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether the given instance incorporates a specific mixin or base class.
|
|
29
|
+
* This utility serves as an alternative to the native `instanceof` operator for custom
|
|
30
|
+
* mixin implementations where the prototype chain does not inherently preserve the relationship.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The constructor type of the target mixin or base class.
|
|
33
|
+
* @param {T} baseClass - The mixin or base class constructor to verify against.
|
|
34
|
+
* @param {*} instance - The object instance to inspect.
|
|
35
|
+
* @returns {instance is T} `true` if the instance incorporates the specified mixin; otherwise, `false`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function hasMixin<T extends AbstractConstructor>(baseClass: T, instance: any): instance is T;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the sequence of mixins associated with the specified instance.
|
|
40
|
+
*
|
|
41
|
+
* @param {*} instance - The object instance to inspect.
|
|
42
|
+
* @returns {ReadonlyArray<AbstractConstructor> | undefined} A read-only array of mixin constructors applied to the instance, or `undefined` if no mixins are registered.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getMixins(instance: any): ReadonlyArray<AbstractConstructor> | undefined;
|
|
26
45
|
/**
|
|
27
46
|
* Creates an anonymous target class, applies the `baseClassList` to it, and returns the constructed mixin class.
|
|
28
47
|
* @param baseClassList A list of base classes you want to compose.
|
package/dist/mixin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,GAAG,IAAI,QAAQ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AAS,IAAI,GACxC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACzB,MAAM;CACX,CAAC,MAAM,CAAC,CACV,CAAC"}
|
package/dist/mixin.js
CHANGED
|
@@ -5,24 +5,78 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export function applyRuntimeMixins(targetClass, baseClassList) {
|
|
7
7
|
for (const baseClass of baseClassList) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
Object.
|
|
8
|
+
let currentProto = baseClass.prototype;
|
|
9
|
+
while (currentProto && currentProto !== Object.prototype) {
|
|
10
|
+
Object.getOwnPropertyNames(currentProto).forEach((name) => {
|
|
11
|
+
if (name !== "constructor") {
|
|
12
|
+
const descriptor = Object.getOwnPropertyDescriptor(currentProto, name);
|
|
13
|
+
if (descriptor) {
|
|
14
|
+
Object.defineProperty(targetClass.prototype, name, descriptor);
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
});
|
|
18
|
+
currentProto = Object.getPrototypeOf(currentProto);
|
|
19
|
+
}
|
|
20
|
+
let currentClass = baseClass;
|
|
21
|
+
while (currentClass &&
|
|
22
|
+
currentClass !== Function.prototype &&
|
|
23
|
+
currentClass !== Object) {
|
|
24
|
+
for (const name of Object.getOwnPropertyNames(currentClass)) {
|
|
25
|
+
if (!["length", "prototype", "name"].includes(name)) {
|
|
26
|
+
const descriptor = Object.getOwnPropertyDescriptor(currentClass, name);
|
|
27
|
+
if (descriptor) {
|
|
28
|
+
Object.defineProperty(targetClass, name, descriptor);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
}
|
|
32
|
+
currentClass = Object.getPrototypeOf(currentClass);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
}
|
|
36
|
+
export function isNonNullObject(instance) {
|
|
37
|
+
if (typeof instance !== "object")
|
|
38
|
+
return false;
|
|
39
|
+
if (instance === null)
|
|
40
|
+
return false;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether the given instance incorporates a specific mixin or base class.
|
|
45
|
+
* This utility serves as an alternative to the native `instanceof` operator for custom
|
|
46
|
+
* mixin implementations where the prototype chain does not inherently preserve the relationship.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The constructor type of the target mixin or base class.
|
|
49
|
+
* @param {T} baseClass - The mixin or base class constructor to verify against.
|
|
50
|
+
* @param {*} instance - The object instance to inspect.
|
|
51
|
+
* @returns {instance is T} `true` if the instance incorporates the specified mixin; otherwise, `false`.
|
|
52
|
+
*/
|
|
53
|
+
export function hasMixin(baseClass, instance) {
|
|
54
|
+
const mixins = getMixins(instance);
|
|
55
|
+
if (!mixins)
|
|
56
|
+
return false;
|
|
57
|
+
return mixins.includes(baseClass);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the sequence of mixins associated with the specified instance.
|
|
61
|
+
*
|
|
62
|
+
* @param {*} instance - The object instance to inspect.
|
|
63
|
+
* @returns {ReadonlyArray<AbstractConstructor> | undefined} A read-only array of mixin constructors applied to the instance, or `undefined` if no mixins are registered.
|
|
64
|
+
*/
|
|
65
|
+
export function getMixins(instance) {
|
|
66
|
+
if (!isNonNullObject(instance))
|
|
67
|
+
return;
|
|
68
|
+
if (!("constructor" in instance))
|
|
69
|
+
return;
|
|
70
|
+
const instConstructor = instance.constructor;
|
|
71
|
+
if (typeof instConstructor !== "function")
|
|
72
|
+
return;
|
|
73
|
+
if (!("$baseClassList" in instConstructor))
|
|
74
|
+
return;
|
|
75
|
+
const baseClassList = instConstructor["$baseClassList"];
|
|
76
|
+
if (!Array.isArray(baseClassList))
|
|
77
|
+
return;
|
|
78
|
+
return baseClassList;
|
|
79
|
+
}
|
|
26
80
|
/**
|
|
27
81
|
* Creates an anonymous target class, applies the `baseClassList` to it, and returns the constructed mixin class.
|
|
28
82
|
* @param baseClassList A list of base classes you want to compose.
|
|
@@ -30,6 +84,7 @@ export function applyRuntimeMixins(targetClass, baseClassList) {
|
|
|
30
84
|
*/
|
|
31
85
|
export function mixin(...baseClassList) {
|
|
32
86
|
const targetClass = class {
|
|
87
|
+
static $baseClassList = baseClassList;
|
|
33
88
|
};
|
|
34
89
|
applyRuntimeMixins(targetClass, baseClassList);
|
|
35
90
|
return targetClass;
|
package/dist/mixin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAgB,EAAE,aAAoB;IACvE,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE,CAAC;QACtC,
|
|
1
|
+
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAgB,EAAE,aAAoB;IACvE,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE,CAAC;QACtC,IAAI,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC;QACvC,OAAO,YAAY,IAAI,YAAY,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;YACzD,MAAM,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxD,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;oBAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAChD,YAAY,EACZ,IAAI,CACL,CAAC;oBACF,IAAI,UAAU,EAAE,CAAC;wBACf,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;oBACjE,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YACH,YAAY,GAAG,MAA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C,aAAa,IAAI,QAAQ,CAAC;QAAE,OAAO;IAEzC,MAAM,eAAe,GAAG,QAAQ,CAAC,WAAW,CAAC;IAC7C,IAAI,OAAO,eAAe,KAAK,UAAU;QAAE,OAAO;IAClD,IAAI,CAAC,CAAC,gBAAgB,IAAI,eAAe,CAAC;QAAE,OAAO;IACnD,MAAM,aAAa,GAAG,eAAe,CAAC,gBAAgB,CAAQ,CAAC;IAC/D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;QAAE,OAAO;IAE1C,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACnB,GAAG,aAAgB;IAEnB,MAAM,WAAW,GAAG;QAClB,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC;KACvC,CAAC;IACF,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC/C,OAAO,WAAkB,CAAC;AAC5B,CAAC"}
|
package/dist/result.d.ts
CHANGED
package/dist/result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEN,yBAAiB,MAAM,CAAC;IACtB;;;OAGG;IACH,SAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAEhE;IAED;;;OAGG;IACH,SAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAEhE;CACF"}
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEN,yBAAiB,MAAM,CAAC;IACtB;;;OAGG;IACH,SAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAEhE;IAED;;;OAGG;IACH,SAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAEhE;CACF;AAED,eAAO,MAAM,EAAE,kBAAY,CAAC;AAC5B,eAAO,MAAM,GAAG,mBAAa,CAAC"}
|
package/dist/result.js
CHANGED
package/dist/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAaA,MAAM,KAAW,MAAM,CAgBtB;AAhBD,WAAiB,MAAM;IACrB;;;OAGG;IACH,SAAgB,EAAE,CAAI,MAAS;QAC7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;IAFe,SAAE,KAEjB,CAAA;IAED;;;OAGG;IACH,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;IAFe,UAAG,MAElB,CAAA;AACH,CAAC,EAhBgB,MAAM,KAAN,MAAM,QAgBtB"}
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAaA,MAAM,KAAW,MAAM,CAgBtB;AAhBD,WAAiB,MAAM;IACrB;;;OAGG;IACH,SAAgB,EAAE,CAAI,MAAS;QAC7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;IAFe,SAAE,KAEjB,CAAA;IAED;;;OAGG;IACH,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;IAFe,UAAG,MAElB,CAAA;AACH,CAAC,EAhBgB,MAAM,KAAN,MAAM,QAgBtB;AAED,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;AAC5B,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC"}
|
package/dist/timeid.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare namespace TimeId {
|
|
2
|
+
/**
|
|
3
|
+
* Generates a unique, time-sortable identifier string.
|
|
4
|
+
*
|
|
5
|
+
* The identifier is composed of four hyphen-separated segments:
|
|
6
|
+
* - The first two segments encode the current millisecond timestamp.
|
|
7
|
+
* - The last two segments (16 characters) contain random entropy.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} A unique ID string (e.g., "XXXX-XXXX-YYYY-YYYY").
|
|
10
|
+
*/
|
|
11
|
+
function create(timebase?: Date | null): string;
|
|
12
|
+
/**
|
|
13
|
+
* Parses a timeId string and returns the original Date and random bytes.
|
|
14
|
+
*
|
|
15
|
+
* @param id The timeId string to parse.
|
|
16
|
+
* @returns An object containing the decoded `date` and `randbytes`.
|
|
17
|
+
* @throws If the timeId format or payload is invalid.
|
|
18
|
+
*/
|
|
19
|
+
function parse(id: string): {
|
|
20
|
+
date: Date;
|
|
21
|
+
randbytes: Uint8Array;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=timeid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeid.d.ts","sourceRoot":"","sources":["../src/timeid.ts"],"names":[],"mappings":"AAEA,yBAAiB,MAAM,CAAC;IACtB;;;;;;;;OAQG;IACH,SAAgB,MAAM,CAAC,QAAQ,GAAE,IAAI,GAAG,IAAW,GAAG,MAAM,CAsB3D;IAED;;;;;;OAMG;IACH,SAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,SAAS,EAAE,UAAU,CAAA;KAAE,CA+BvE;CACF"}
|
package/dist/timeid.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Base32 } from "./base32.js";
|
|
2
|
+
export var TimeId;
|
|
3
|
+
(function (TimeId) {
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique, time-sortable identifier string.
|
|
6
|
+
*
|
|
7
|
+
* The identifier is composed of four hyphen-separated segments:
|
|
8
|
+
* - The first two segments encode the current millisecond timestamp.
|
|
9
|
+
* - The last two segments (16 characters) contain random entropy.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} A unique ID string (e.g., "XXXX-XXXX-YYYY-YYYY").
|
|
12
|
+
*/
|
|
13
|
+
function create(timebase = null) {
|
|
14
|
+
// Create random values
|
|
15
|
+
const randbytes = crypto.getRandomValues(new Uint8Array(8));
|
|
16
|
+
const k32 = Base32.fromUint8Array(randbytes);
|
|
17
|
+
const lower = k32.substring(0, 8);
|
|
18
|
+
const upper = k32.substring(8, 16);
|
|
19
|
+
const timepad = k32.substring(16, 19);
|
|
20
|
+
// Construct time Uint8Array
|
|
21
|
+
timebase ??= new Date();
|
|
22
|
+
const timestamp = BigInt(timebase.getTime());
|
|
23
|
+
const timebuffer = new ArrayBuffer(8);
|
|
24
|
+
const timeview = new DataView(timebuffer);
|
|
25
|
+
timeview.setBigUint64(0, timestamp, false);
|
|
26
|
+
const timearr = new Uint8Array(timebuffer);
|
|
27
|
+
// Assemble id
|
|
28
|
+
const timestr = Base32.fromUint8Array(timearr).substring(0, 13) + timepad;
|
|
29
|
+
const timelower = timestr.substring(0, 8);
|
|
30
|
+
const timeupper = timestr.substring(8, 16);
|
|
31
|
+
const generated = `${timelower}-${timeupper}-${lower}-${upper}`;
|
|
32
|
+
return generated;
|
|
33
|
+
}
|
|
34
|
+
TimeId.create = create;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a timeId string and returns the original Date and random bytes.
|
|
37
|
+
*
|
|
38
|
+
* @param id The timeId string to parse.
|
|
39
|
+
* @returns An object containing the decoded `date` and `randbytes`.
|
|
40
|
+
* @throws If the timeId format or payload is invalid.
|
|
41
|
+
*/
|
|
42
|
+
function parse(id) {
|
|
43
|
+
const parts = id.split("-");
|
|
44
|
+
if (parts.length !== 4) {
|
|
45
|
+
throw new Error("Invalid timeId format");
|
|
46
|
+
}
|
|
47
|
+
const [timeLower, timeUpper, randLower, randUpper] = parts;
|
|
48
|
+
const randStr = randLower + randUpper;
|
|
49
|
+
const randbytes = Base32.toUint8Array(randStr);
|
|
50
|
+
const timeStr = timeLower + timeUpper;
|
|
51
|
+
const timearr = Base32.toUint8Array(timeStr);
|
|
52
|
+
if (randbytes.length !== 8 || timearr.length !== 8) {
|
|
53
|
+
throw new Error("Invalid timeId payload");
|
|
54
|
+
}
|
|
55
|
+
const timeview = new DataView(timearr.buffer, timearr.byteOffset, timearr.byteLength);
|
|
56
|
+
const timestamp = timeview.getBigUint64(0, false);
|
|
57
|
+
const date = new Date(Number(timestamp));
|
|
58
|
+
return { date, randbytes };
|
|
59
|
+
}
|
|
60
|
+
TimeId.parse = parse;
|
|
61
|
+
})(TimeId || (TimeId = {}));
|
|
62
|
+
//# sourceMappingURL=timeid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeid.js","sourceRoot":"","sources":["../src/timeid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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EAzEgB,MAAM,KAAN,MAAM,QAyEtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwreey-js/ts-util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Qwreey's typescript utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"check:format": "npm run --prefix ../../ prettier -- --check packages/ts-util/src",
|
|
27
27
|
"fix:format": "npm run --prefix ../../ prettier -- --write packages/ts-util/src",
|
|
28
28
|
"init": "npm ci --include-workspace-root --include=dev",
|
|
29
|
-
"prepack": "npm run init && npm run check && npm run build"
|
|
29
|
+
"prepack": "npm run init && npm run check && npm run build",
|
|
30
|
+
"test": "../../node_modules/.bin/tsx src/test/index.ts"
|
|
30
31
|
},
|
|
31
32
|
"exports": {
|
|
32
33
|
".": {
|