@qwreey-js/ts-util 1.0.3 → 1.0.4
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/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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -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 +26 -0
- package/dist/mixin.d.ts.map +1 -1
- package/dist/mixin.js +10 -0
- 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 +11 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +8 -0
- package/dist/result.js.map +1 -1
- 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 +1 -1
package/dist/interval.d.ts
CHANGED
|
@@ -1,16 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Executes a standard, synchronous function repeatedly based on the provided millisecond interval.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Interval<T> {
|
|
2
5
|
private func;
|
|
3
6
|
private interval;
|
|
4
7
|
private id?;
|
|
5
8
|
private running;
|
|
6
9
|
private name;
|
|
7
|
-
|
|
10
|
+
private _result?;
|
|
11
|
+
/**
|
|
12
|
+
* @param func The synchronous function to execute.
|
|
13
|
+
* @param interval The execution interval in milliseconds.
|
|
14
|
+
* @param name Optional name for logging purposes.
|
|
15
|
+
*/
|
|
16
|
+
constructor(func: () => T, interval: number, name?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Schedules the function execution using a timeout. Throws an error if the interval is already running.
|
|
19
|
+
*/
|
|
8
20
|
run(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Clears the current timeout and stops the interval.
|
|
23
|
+
*/
|
|
9
24
|
drop(): void;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Immediately executes the function. Resets the timeout if it is already running.
|
|
27
|
+
*/
|
|
28
|
+
execute(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Immediately executes the function and guarantees that the interval continues running afterward.
|
|
31
|
+
*/
|
|
32
|
+
executeThenRun(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the return value of the last executed function.
|
|
35
|
+
*/
|
|
36
|
+
get result(): T | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Executes an asynchronous function repeatedly based on the provided millisecond interval.
|
|
40
|
+
*/
|
|
41
|
+
export declare class IntervalAsync<T> {
|
|
42
|
+
private func;
|
|
43
|
+
private interval;
|
|
44
|
+
private id?;
|
|
45
|
+
private running;
|
|
46
|
+
private name;
|
|
47
|
+
private _result?;
|
|
48
|
+
/**
|
|
49
|
+
* @param func The asynchronous function to execute.
|
|
50
|
+
* @param interval The execution interval in milliseconds.
|
|
51
|
+
* @param name Optional name for logging purposes.
|
|
52
|
+
*/
|
|
53
|
+
constructor(func: () => Promise<T>, interval: number, name?: string);
|
|
54
|
+
/**
|
|
55
|
+
* Schedules the function execution using a timeout. Throws an error if the interval is already running.
|
|
56
|
+
*/
|
|
57
|
+
run(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Clears the current timeout and stops the interval.
|
|
60
|
+
*/
|
|
61
|
+
drop(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Immediately executes the function. Resets the timeout if it is already running.
|
|
64
|
+
*/
|
|
65
|
+
execute(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Immediately executes the function and guarantees that the interval continues running afterward.
|
|
68
|
+
*/
|
|
69
|
+
executeThenRun(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the Promise of the last executed function.
|
|
72
|
+
*/
|
|
73
|
+
get result(): Promise<T> | undefined;
|
|
15
74
|
}
|
|
16
75
|
//# sourceMappingURL=interval.d.ts.map
|
package/dist/interval.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,QAAQ,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,EAAE,CAAC,CAAM;IACjB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,OAAO,CAAC,CAAI;IAEpB;;;;OAIG;gBAED,IAAI,EAAE,MAAM,CAAC,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAAkB;IAQ1B;;OAEG;IACI,GAAG;IAkBV;;OAEG;IACI,IAAI;IAQX;;OAEG;IACI,OAAO;IAWd;;OAEG;IACI,cAAc;IAOrB;;OAEG;IACH,IAAW,MAAM,IAAI,CAAC,GAAG,SAAS,CAEjC;CACF;AAED;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC;IAC1B,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,EAAE,CAAC,CAAM;IACjB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,OAAO,CAAC,CAAa;IAE7B;;;;OAIG;gBAED,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAAkB;IAQ1B;;OAEG;IACI,GAAG;IAkBV;;OAEG;IACI,IAAI;IAQX;;OAEG;IACU,OAAO;IAWpB;;OAEG;IACU,cAAc;IAO3B;;OAEG;IACH,IAAW,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAE1C;CACF"}
|
package/dist/interval.js
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
import { logErr } from "./libLog.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// 내부 구현은 setInterval 로 구현됩니다
|
|
2
|
+
/**
|
|
3
|
+
* Executes a standard, synchronous function repeatedly based on the provided millisecond interval.
|
|
4
|
+
*/
|
|
6
5
|
export class Interval {
|
|
7
6
|
func;
|
|
8
7
|
interval;
|
|
9
8
|
id;
|
|
10
9
|
running;
|
|
11
10
|
name;
|
|
11
|
+
_result;
|
|
12
|
+
/**
|
|
13
|
+
* @param func The synchronous function to execute.
|
|
14
|
+
* @param interval The execution interval in milliseconds.
|
|
15
|
+
* @param name Optional name for logging purposes.
|
|
16
|
+
*/
|
|
12
17
|
constructor(func, interval, name = "default") {
|
|
13
18
|
this.func = func;
|
|
14
19
|
this.interval = interval;
|
|
15
20
|
this.running = false;
|
|
16
21
|
this.name = name;
|
|
17
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Schedules the function execution using a timeout. Throws an error if the interval is already running.
|
|
25
|
+
*/
|
|
18
26
|
run() {
|
|
19
27
|
if (this.running) {
|
|
20
28
|
throw Error("interval already started");
|
|
21
29
|
}
|
|
22
30
|
this.running = true;
|
|
23
|
-
this.id = setTimeout(
|
|
31
|
+
const currId = (this.id = setTimeout(() => {
|
|
24
32
|
try {
|
|
25
|
-
|
|
33
|
+
this._result = this.func();
|
|
26
34
|
}
|
|
27
35
|
catch (e) {
|
|
28
36
|
logErr(`interval failed(${this.name}): ${e}`);
|
|
29
37
|
}
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
if (currId == this.id) {
|
|
39
|
+
this.running = false;
|
|
40
|
+
this.run();
|
|
41
|
+
}
|
|
42
|
+
}, this.interval));
|
|
33
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Clears the current timeout and stops the interval.
|
|
46
|
+
*/
|
|
34
47
|
drop() {
|
|
35
48
|
this.running = false;
|
|
36
49
|
if (this.id) {
|
|
@@ -38,12 +51,15 @@ export class Interval {
|
|
|
38
51
|
delete this.id;
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Immediately executes the function. Resets the timeout if it is already running.
|
|
56
|
+
*/
|
|
57
|
+
execute() {
|
|
42
58
|
const running = this.running;
|
|
43
59
|
if (running)
|
|
44
60
|
this.drop();
|
|
45
61
|
try {
|
|
46
|
-
|
|
62
|
+
this._result = this.func();
|
|
47
63
|
}
|
|
48
64
|
catch (e) {
|
|
49
65
|
logErr(`interval failed(${this.name}): ${e}`);
|
|
@@ -51,13 +67,104 @@ export class Interval {
|
|
|
51
67
|
if (running)
|
|
52
68
|
this.run();
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Immediately executes the function and guarantees that the interval continues running afterward.
|
|
72
|
+
*/
|
|
73
|
+
executeThenRun() {
|
|
74
|
+
this.execute();
|
|
75
|
+
if (!this.running) {
|
|
76
|
+
this.run();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the return value of the last executed function.
|
|
81
|
+
*/
|
|
82
|
+
get result() {
|
|
83
|
+
return this._result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Executes an asynchronous function repeatedly based on the provided millisecond interval.
|
|
88
|
+
*/
|
|
89
|
+
export class IntervalAsync {
|
|
90
|
+
func;
|
|
91
|
+
interval;
|
|
92
|
+
id;
|
|
93
|
+
running;
|
|
94
|
+
name;
|
|
95
|
+
_result;
|
|
96
|
+
/**
|
|
97
|
+
* @param func The asynchronous function to execute.
|
|
98
|
+
* @param interval The execution interval in milliseconds.
|
|
99
|
+
* @param name Optional name for logging purposes.
|
|
100
|
+
*/
|
|
101
|
+
constructor(func, interval, name = "default") {
|
|
102
|
+
this.func = func;
|
|
103
|
+
this.interval = interval;
|
|
104
|
+
this.running = false;
|
|
105
|
+
this.name = name;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Schedules the function execution using a timeout. Throws an error if the interval is already running.
|
|
109
|
+
*/
|
|
110
|
+
run() {
|
|
111
|
+
if (this.running) {
|
|
112
|
+
throw Error("interval already started");
|
|
113
|
+
}
|
|
114
|
+
this.running = true;
|
|
115
|
+
const currId = (this.id = setTimeout(async () => {
|
|
116
|
+
try {
|
|
117
|
+
await (this._result = this.func());
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
logErr(`interval failed(${this.name}): ${e}`);
|
|
121
|
+
}
|
|
122
|
+
if (currId == this.id) {
|
|
123
|
+
this.running = false;
|
|
58
124
|
this.run();
|
|
59
125
|
}
|
|
60
|
-
},
|
|
126
|
+
}, this.interval));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Clears the current timeout and stops the interval.
|
|
130
|
+
*/
|
|
131
|
+
drop() {
|
|
132
|
+
this.running = false;
|
|
133
|
+
if (this.id) {
|
|
134
|
+
clearTimeout(this.id);
|
|
135
|
+
delete this.id;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Immediately executes the function. Resets the timeout if it is already running.
|
|
140
|
+
*/
|
|
141
|
+
async execute() {
|
|
142
|
+
const running = this.running;
|
|
143
|
+
if (running)
|
|
144
|
+
this.drop();
|
|
145
|
+
try {
|
|
146
|
+
await (this._result = this.func());
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
logErr(`interval failed(${this.name}): ${e}`);
|
|
150
|
+
}
|
|
151
|
+
if (running)
|
|
152
|
+
this.run();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Immediately executes the function and guarantees that the interval continues running afterward.
|
|
156
|
+
*/
|
|
157
|
+
async executeThenRun() {
|
|
158
|
+
await this.execute();
|
|
159
|
+
if (!this.running) {
|
|
160
|
+
this.run();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the Promise of the last executed function.
|
|
165
|
+
*/
|
|
166
|
+
get result() {
|
|
167
|
+
return this._result;
|
|
61
168
|
}
|
|
62
169
|
}
|
|
63
170
|
//# sourceMappingURL=interval.js.map
|
package/dist/interval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interval.js","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"interval.js","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACX,IAAI,CAAU;IACd,QAAQ,CAAS;IACjB,EAAE,CAAO;IACT,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,OAAO,CAAK;IAEpB;;;;OAIG;IACH,YACE,IAAa,EACb,QAAgB,EAChB,OAAe,SAAS;QAExB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG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tB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;gBACrB,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAQ,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,IAAI;QACT,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,YAAY,CAAC,IAAI,CAAC,EAAS,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,OAAO;YAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,mBAAmB,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,OAAO;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc;QACzB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
package/dist/mixin.d.ts
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import type { UnionToIntersection } from "./utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a generic constructor function, capable of accepting both concrete and abstract classes.
|
|
4
|
+
*/
|
|
2
5
|
export type AbstractConstructor<T = any> = abstract new (...args: any[]) => T;
|
|
6
|
+
/**
|
|
7
|
+
* A utility type that combines two constructor types `A` and `B`.
|
|
8
|
+
* Returns a new constructor type intersecting instances and static properties.
|
|
9
|
+
*/
|
|
3
10
|
export type MixinBoth<A extends AbstractConstructor<InstanceType<A>>, B extends AbstractConstructor<InstanceType<B>>> = (A & B) & AbstractConstructor<InstanceType<A> & InstanceType<B>>;
|
|
11
|
+
/**
|
|
12
|
+
* A recursive utility type that combines an array of constructor types `T` into a single constructor type.
|
|
13
|
+
*/
|
|
4
14
|
export type Mixin<T extends AbstractConstructor[]> = T extends [
|
|
5
15
|
infer First extends AbstractConstructor
|
|
6
16
|
] ? First : T extends [
|
|
7
17
|
...infer Others extends AbstractConstructor[],
|
|
8
18
|
infer Last extends AbstractConstructor
|
|
9
19
|
] ? MixinBoth<Mixin<Others>, Last> : never;
|
|
20
|
+
/**
|
|
21
|
+
* Copies prototype methods and static properties from a list of base classes directly onto a target class.
|
|
22
|
+
* @param targetClass The class to which the mixins will be applied.
|
|
23
|
+
* @param baseClassList An array of base classes to mix into the `targetClass`.
|
|
24
|
+
*/
|
|
10
25
|
export declare function applyRuntimeMixins(targetClass: any, baseClassList: any[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an anonymous target class, applies the `baseClassList` to it, and returns the constructed mixin class.
|
|
28
|
+
* @param baseClassList A list of base classes you want to compose.
|
|
29
|
+
* @returns A new class constructor containing all instance and static properties of the base classes.
|
|
30
|
+
*/
|
|
11
31
|
export declare function mixin<T extends AbstractConstructor[]>(...baseClassList: T): Mixin<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Represents an array of tuples where the first element is a condition and the second is a constructor.
|
|
34
|
+
*/
|
|
12
35
|
export type MixinApplyList = [
|
|
13
36
|
boolean | undefined | null,
|
|
14
37
|
AbstractConstructor
|
|
15
38
|
][];
|
|
39
|
+
/**
|
|
40
|
+
* Computes an intersection of instance types from a `MixinApplyList` where the condition is strictly true.
|
|
41
|
+
*/
|
|
16
42
|
export type MixinInstance<Apply extends MixinApplyList> = UnionToIntersection<{
|
|
17
43
|
[K in keyof Apply]: Apply[K][0] extends true ? InstanceType<Apply[K][1]> : object;
|
|
18
44
|
}[number]>;
|
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,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,GAAG,IAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE9E,MAAM,MAAM,SAAS,CACnB,CAAC,SAAS,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAC9C,CAAC,SAAS,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAC5C,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,mBAAmB,EAAE,IAAI,CAAC,SAAS;IAC7D,MAAM,KAAK,SAAS,mBAAmB;CACxC,GACG,KAAK,GACL,CAAC,SAAS;IACN,GAAG,MAAM,MAAM,SAAS,mBAAmB,EAAE;IAC7C,MAAM,IAAI,SAAS,mBAAmB;CACvC,GACD,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,GAC9B,KAAK,CAAC;AAEZ,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,QAwBxE;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,mBAAmB,EAAE,EACnD,GAAG,aAAa,EAAE,CAAC,GAClB,KAAK,CAAC,CAA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CAAC,GAC9B,KAAK,CAAC;AAEZ;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,QAwBxE;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,mBAAmB,EAAE,EACnD,GAAG,aAAa,EAAE,CAAC,GAClB,KAAK,CAAC,CAAC,CAAC,CAIV;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,GAAG,SAAS,GAAG,IAAI;IAC1B,mBAAmB;CACpB,EAAE,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,cAAc,IAAI,mBAAmB,CAC3E;KACG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,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
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies prototype methods and static properties from a list of base classes directly onto a target class.
|
|
3
|
+
* @param targetClass The class to which the mixins will be applied.
|
|
4
|
+
* @param baseClassList An array of base classes to mix into the `targetClass`.
|
|
5
|
+
*/
|
|
1
6
|
export function applyRuntimeMixins(targetClass, baseClassList) {
|
|
2
7
|
for (const baseClass of baseClassList) {
|
|
3
8
|
Object.getOwnPropertyNames(baseClass.prototype).forEach((name) => {
|
|
@@ -18,6 +23,11 @@ export function applyRuntimeMixins(targetClass, baseClassList) {
|
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an anonymous target class, applies the `baseClassList` to it, and returns the constructed mixin class.
|
|
28
|
+
* @param baseClassList A list of base classes you want to compose.
|
|
29
|
+
* @returns A new class constructor containing all instance and static properties of the base classes.
|
|
30
|
+
*/
|
|
21
31
|
export function mixin(...baseClassList) {
|
|
22
32
|
const targetClass = class {
|
|
23
33
|
};
|
package/dist/mixin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"
|
|
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,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC/D,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAChD,SAAS,CAAC,SAAS,EACnB,IAAI,CACL,CAAC;gBACF,IAAI,UAAU,EAAE,CAAC;oBACf,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;gBAEpE,IAAI,UAAU,EAAE,CAAC;oBACf,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACnB,GAAG,aAAgB;IAEnB,MAAM,WAAW,GAAG;KAAQ,CAAC;IAC7B,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC/C,OAAO,WAAkB,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** URLSearchParams builder pattern wrapper */
|
|
2
|
+
export declare class ParamsBuilder {
|
|
3
|
+
private inner;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new ParamsBuilder instance.
|
|
6
|
+
* @param base - An optional existing {@link URLSearchParams} to wrap.
|
|
7
|
+
*/
|
|
8
|
+
constructor(base?: URLSearchParams);
|
|
9
|
+
/**
|
|
10
|
+
* Appends a new query parameter.
|
|
11
|
+
* @param name - The name of the parameter.
|
|
12
|
+
* @param value - The value of the parameter.
|
|
13
|
+
* @returns The current instance for method chaining.
|
|
14
|
+
*/
|
|
15
|
+
push(name: string, value: string): ParamsBuilder;
|
|
16
|
+
/**
|
|
17
|
+
* Finalizes the builder and returns the query string.
|
|
18
|
+
* @returns The serialized query parameters as a string.
|
|
19
|
+
*/
|
|
20
|
+
finalize(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the underlying {@link URLSearchParams} instance.
|
|
23
|
+
*
|
|
24
|
+
* @note **Terminal Operation**: This method transfers ownership of the
|
|
25
|
+
* internal state. Do not use this builder instance after calling this method.
|
|
26
|
+
*
|
|
27
|
+
* @returns The raw URLSearchParams object.
|
|
28
|
+
*/
|
|
29
|
+
asInner(): URLSearchParams;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=params-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params-builder.d.ts","sourceRoot":"","sources":["../src/params-builder.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAkB;IAE/B;;;OAGG;gBACgB,IAAI,CAAC,EAAE,eAAe;IAIzC;;;;;OAKG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa;IAKvD;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;;;;OAOG;IACI,OAAO,IAAI,eAAe;CAGlC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** URLSearchParams builder pattern wrapper */
|
|
2
|
+
export class ParamsBuilder {
|
|
3
|
+
inner;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new ParamsBuilder instance.
|
|
6
|
+
* @param base - An optional existing {@link URLSearchParams} to wrap.
|
|
7
|
+
*/
|
|
8
|
+
constructor(base) {
|
|
9
|
+
this.inner = base ?? new URLSearchParams();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Appends a new query parameter.
|
|
13
|
+
* @param name - The name of the parameter.
|
|
14
|
+
* @param value - The value of the parameter.
|
|
15
|
+
* @returns The current instance for method chaining.
|
|
16
|
+
*/
|
|
17
|
+
push(name, value) {
|
|
18
|
+
this.inner.append(name, value);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Finalizes the builder and returns the query string.
|
|
23
|
+
* @returns The serialized query parameters as a string.
|
|
24
|
+
*/
|
|
25
|
+
finalize() {
|
|
26
|
+
return this.inner.toString();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the underlying {@link URLSearchParams} instance.
|
|
30
|
+
*
|
|
31
|
+
* @note **Terminal Operation**: This method transfers ownership of the
|
|
32
|
+
* internal state. Do not use this builder instance after calling this method.
|
|
33
|
+
*
|
|
34
|
+
* @returns The raw URLSearchParams object.
|
|
35
|
+
*/
|
|
36
|
+
asInner() {
|
|
37
|
+
return this.inner;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=params-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params-builder.js","sourceRoot":"","sources":["../src/params-builder.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,MAAM,OAAO,aAAa;IAChB,KAAK,CAAkB;IAE/B;;;OAGG;IACH,YAAmB,IAAsB;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,IAAI,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,IAAI,CAAC,IAAY,EAAE,KAAa;QACrC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED;;;;;;;OAOG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/dist/result.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A discriminated union type that can represent either a successful value of type `T` or an error of type `U`.
|
|
3
|
+
*/
|
|
1
4
|
export type Result<T, U> = {
|
|
2
5
|
result: undefined;
|
|
3
6
|
error: U;
|
|
@@ -6,10 +9,18 @@ export type Result<T, U> = {
|
|
|
6
9
|
error: undefined;
|
|
7
10
|
};
|
|
8
11
|
export declare namespace Result {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a successful result object containing the provided `result` value.
|
|
14
|
+
* @param result The successful value to wrap.
|
|
15
|
+
*/
|
|
9
16
|
function ok<T>(result: T): {
|
|
10
17
|
result: T;
|
|
11
18
|
error: undefined;
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Creates an error result object containing the provided `error` value.
|
|
22
|
+
* @param error The error value or object to wrap.
|
|
23
|
+
*/
|
|
13
24
|
function err<U>(error: U): {
|
|
14
25
|
result: undefined;
|
|
15
26
|
error: U;
|
package/dist/result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,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,SAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAEhE;
|
|
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"}
|
package/dist/result.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export var Result;
|
|
2
2
|
(function (Result) {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a successful result object containing the provided `result` value.
|
|
5
|
+
* @param result The successful value to wrap.
|
|
6
|
+
*/
|
|
3
7
|
function ok(result) {
|
|
4
8
|
return { error: undefined, result };
|
|
5
9
|
}
|
|
6
10
|
Result.ok = ok;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an error result object containing the provided `error` value.
|
|
13
|
+
* @param error The error value or object to wrap.
|
|
14
|
+
*/
|
|
7
15
|
function err(error) {
|
|
8
16
|
return { error, result: undefined };
|
|
9
17
|
}
|
package/dist/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,83 @@
|
|
|
1
|
+
import { Result } from "./result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a union type to an intersection type.
|
|
4
|
+
* @template U The union type to be converted.
|
|
5
|
+
*/
|
|
1
6
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
7
|
+
/**
|
|
8
|
+
* Pads a given number with leading zeros to meet the specified length.
|
|
9
|
+
* @param {number} num The number to be padded.
|
|
10
|
+
* @param {number} [zeroLength=2] The desired total length of the resulting string. Defaults to 2.
|
|
11
|
+
* @returns {string} The padded string representation of the number.
|
|
12
|
+
*/
|
|
13
|
+
export declare function zeroPadding(num: number, length?: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Safely parses a JSON string. Returns null if a parsing error occurs.
|
|
16
|
+
* @template T The expected type of the parsed data.
|
|
17
|
+
* @param {string | undefined | null} content The JSON string to parse.
|
|
18
|
+
* @returns {T | null} The parsed object, or null if parsing fails.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseJsonSafe<T = any>(content: string | undefined | null): T | null;
|
|
21
|
+
/**
|
|
22
|
+
* Executes a promise and returns a boolean indicating success.
|
|
23
|
+
* Logs an error and returns false if the promise is rejected.
|
|
24
|
+
* @param {Promise<any>} promise The promise to execute.
|
|
25
|
+
* @returns {Promise<boolean>} True if the promise resolves successfully, false otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function AsOk(promise: Promise<any>): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Executes a promise and returns a wrapped result.
|
|
30
|
+
* @param {Promise<T>} promise The promise to execute.
|
|
31
|
+
* @returns {Promise<Result<T, Error>>} Result.ok(T) if the promise resolves successfully, Result.err(Error) otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export declare function AsResult<T>(promise: Promise<T>): Promise<Result<T, Error>>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes a promise and returns its result, or null if an error occurs.
|
|
36
|
+
* Logs the error if the promise is rejected.
|
|
37
|
+
* @template T The expected return type of the promise.
|
|
38
|
+
* @param {Promise<T>} promise The promise to execute.
|
|
39
|
+
* @returns {Promise<T | null>} The result of the promise, or null if it fails.
|
|
40
|
+
*/
|
|
41
|
+
export declare function NullCatch<T>(promise: Promise<T>): Promise<T | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns an empty promise that resolves to undefined.
|
|
44
|
+
* @returns {Promise<undefined>}
|
|
45
|
+
*/
|
|
46
|
+
export declare function EmptyPromise(): Promise<undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns an promise that resolves to input value.
|
|
49
|
+
* @param {T} input The input value
|
|
50
|
+
* @returns {Promise<T>}
|
|
51
|
+
*/
|
|
52
|
+
export declare function ValuePromise<T>(input: T): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a promise that immediately rejects with the provided error.
|
|
55
|
+
* @param {Error} err The error to be thrown.
|
|
56
|
+
* @returns {Promise<any>}
|
|
57
|
+
*/
|
|
58
|
+
export declare function ErrorPromise(err: Error): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Represents a valid CSS class name or a falsy value to be ignored during the merge process.
|
|
61
|
+
*/
|
|
62
|
+
export type ClassNameType = string | undefined | false | null;
|
|
63
|
+
/**
|
|
64
|
+
* Merges multiple class names and arrays of class names into a single space-separated string.
|
|
65
|
+
* Falsy values such as null, undefined, or false are automatically filtered out.
|
|
66
|
+
* This function handles single-level arrays but does not support deep nesting.
|
|
67
|
+
*
|
|
68
|
+
* @param {...(ClassNameType | ClassNameType[])} classNameList - A list of class names or arrays containing class names.
|
|
69
|
+
* @returns {string} A combined string of valid class names separated by a space.
|
|
70
|
+
*/
|
|
71
|
+
export declare function mergeClassName(...classNameList: (ClassNameType | ClassNameType[])[]): string;
|
|
72
|
+
export declare const TIB_UNIT: number;
|
|
73
|
+
export declare const GIB_UNIT: number;
|
|
74
|
+
export declare const MIB_UNIT: number;
|
|
75
|
+
export declare const KIB_UNIT: number;
|
|
76
|
+
/**
|
|
77
|
+
* Formats a file size in bytes into a human-readable string using binary prefixes (IEC standard).
|
|
78
|
+
*
|
|
79
|
+
* @param {number} sizeBytes - The size of the file in bytes.
|
|
80
|
+
* @returns {string} The formatted file size string with its corresponding unit (e.g., "1.5GiB", "500B").
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatFileSize(sizeBytes: number): string;
|
|
2
83
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file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