@creejs/commons-lang 1.0.8 → 1.0.10
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/cjs/index-dev.cjs +1547 -0
- package/dist/cjs/index-dev.cjs.map +1 -0
- package/dist/cjs/index-min.cjs +2 -0
- package/dist/cjs/index-min.cjs.map +1 -0
- package/dist/esm/index-dev.js +1532 -0
- package/dist/esm/index-dev.js.map +1 -0
- package/dist/esm/index-min.js +2 -0
- package/dist/esm/index-min.js.map +1 -0
- package/dist/umd/index.dev.js +1553 -0
- package/dist/umd/index.dev.js.map +1 -0
- package/dist/umd/index.min.js +2 -0
- package/dist/umd/index.min.js.map +1 -0
- package/index.js +2 -2
- package/package.json +42 -7
- package/types/class-proxy-utils.d.ts +7 -5
- package/types/exec-utils.d.ts +10 -5
- package/types/index.d.ts +23 -9
- package/types/instance-proxy-utils.d.ts +5 -1
- package/types/lang-utils.d.ts +10 -5
- package/types/promise-utils.d.ts +31 -19
- package/types/string-utils.d.ts +21 -1
- package/types/type-assert.d.ts +53 -32
- package/types/type-utils.d.ts +69 -43
- package/lib/class-proxy-utils.js +0 -66
- package/lib/exec-utils.js +0 -58
- package/lib/index.js +0 -30
- package/lib/instance-proxy-utils.js +0 -27
- package/lib/lang-utils.js +0 -110
- package/lib/promise-utils.js +0 -317
- package/lib/string-utils.js +0 -428
- package/lib/type-assert.js +0 -253
- package/lib/type-utils.js +0 -290
- package/types/lang.d.ts +0 -5
- package/types/type-asset.d.ts +0 -84
package/types/promise-utils.d.ts
CHANGED
|
@@ -5,23 +5,11 @@
|
|
|
5
5
|
* @param {string} [timeoutMessage]
|
|
6
6
|
* @returns {{promise: Promise<*>, reject: function, resolve: function}}
|
|
7
7
|
*/
|
|
8
|
-
export function defer(timeout?: number, timeoutMessage?: string): {
|
|
8
|
+
export function defer(timeout?: number | undefined, timeoutMessage?: string | undefined): {
|
|
9
9
|
promise: Promise<any>;
|
|
10
10
|
reject: Function;
|
|
11
11
|
resolve: Function;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Delays a promise by a specified time.
|
|
15
|
-
* 1. delay(), wait 1ms
|
|
16
|
-
* 2. delay(1000), wait 1000ms
|
|
17
|
-
* 3. delay(promise), after promise settled, wait 1000ms
|
|
18
|
-
* 4. delay(promise, 2000), after promise settled, wait 2000ms
|
|
19
|
-
*
|
|
20
|
-
* @param {Promise<*>|number|undefined} [promise] - The input promise to delay
|
|
21
|
-
* @param {number|undefined} [ms] - Minimum delay in milliseconds (default: 1)
|
|
22
|
-
* @returns {Promise} A new promise that settles after the delay period
|
|
23
|
-
*/
|
|
24
|
-
export function delay(promise?: Promise<any> | number | undefined, ms?: number | undefined): Promise<any>;
|
|
25
13
|
/**
|
|
26
14
|
* Creates a timeout wrapper around a promise that rejects if the promise doesn't resolve within the given time.
|
|
27
15
|
* @param {Promise<*>} promise - The promise to wrap with a timeout
|
|
@@ -30,7 +18,7 @@ export function delay(promise?: Promise<any> | number | undefined, ms?: number |
|
|
|
30
18
|
* @returns {Promise<*>} A new promise that either resolves with the original promise's value, rejects with original promise's error or timeout error
|
|
31
19
|
* @throws {TypeError} If input is not a promise or timeout is not a number
|
|
32
20
|
*/
|
|
33
|
-
export function timeout(promise: Promise<any>, time?: number, message?: string): Promise<any>;
|
|
21
|
+
export function timeout(promise: Promise<any>, time?: number | undefined, message?: string | undefined): Promise<any>;
|
|
34
22
|
/**
|
|
35
23
|
* Excutes All promises in parallel and returns an array of results.
|
|
36
24
|
*
|
|
@@ -54,9 +42,21 @@ export function allSettled(promises: Promise<any>): Array<{
|
|
|
54
42
|
* @returns {Promise<*>}
|
|
55
43
|
*/
|
|
56
44
|
export function returnValuePromised(task: Function): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Delays a promise by a specified time.
|
|
47
|
+
* 1. delay(), wait 1ms
|
|
48
|
+
* 2. delay(1000), wait 1000ms
|
|
49
|
+
* 3. delay(promise), after promise settled, wait 1000ms
|
|
50
|
+
* 4. delay(promise, 2000), after promise settled, wait 2000ms
|
|
51
|
+
*
|
|
52
|
+
* @param {Promise<*>|number|undefined} [promise] - The input promise to delay
|
|
53
|
+
* @param {number|undefined} [ms] - Minimum delay in milliseconds (default: 1)
|
|
54
|
+
* @returns {Promise} A new promise that settles after the delay period
|
|
55
|
+
*/
|
|
56
|
+
export function delay(promise?: Promise<any> | number | undefined, ms?: number | undefined): Promise<any>;
|
|
57
57
|
/**
|
|
58
58
|
* Fast-Fail mode to execute Tasks(functions) in series (one after another) and returns their results in order.
|
|
59
|
-
* 1. function are executed one by one
|
|
59
|
+
* 1. export function are executed one by one
|
|
60
60
|
* 2. Fast Fail: if any tasks fail, the whole chain is rejected with the first error
|
|
61
61
|
* 3. if an element is not function, rejects the whole chain with Error(Not Function)
|
|
62
62
|
* @param {Function[]} promises
|
|
@@ -82,9 +82,9 @@ export function seriesAllSettled(tasks: Function[]): Promise<Array<{
|
|
|
82
82
|
* @param {Function[]} tasks
|
|
83
83
|
* @param {number} [maxParallel=5]
|
|
84
84
|
* @returns {Promise<Array>} Array of resolved values from all promises
|
|
85
|
-
* @throws {TypeError} If input is not an array of function or maxParallel is not a number
|
|
85
|
+
* @throws {TypeError} If input is not an array of export function or maxParallel is not a number
|
|
86
86
|
*/
|
|
87
|
-
export function parallel(tasks: Function[], maxParallel?: number): Promise<any[]>;
|
|
87
|
+
export function parallel(tasks: Function[], maxParallel?: number | undefined): Promise<any[]>;
|
|
88
88
|
/**
|
|
89
89
|
* AllSettled Mode to execute tasks in parallel with a maximum concurrency limit
|
|
90
90
|
* 1. tasks are executed in parallel with a maximum concurrency limit
|
|
@@ -92,6 +92,18 @@ export function parallel(tasks: Function[], maxParallel?: number): Promise<any[]
|
|
|
92
92
|
* @param {Function[]} tasks
|
|
93
93
|
* @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
|
|
94
94
|
* @returns {Promise<Array>} Array of resolved values from all promises
|
|
95
|
-
* @throws {TypeError} If input is not an array of function or maxParallel is not a number
|
|
95
|
+
* @throws {TypeError} If input is not an array of export function or maxParallel is not a number
|
|
96
96
|
*/
|
|
97
|
-
export function parallelAllSettled(tasks: Function[], maxParallel?: number): Promise<any[]>;
|
|
97
|
+
export function parallelAllSettled(tasks: Function[], maxParallel?: number | undefined): Promise<any[]>;
|
|
98
|
+
declare namespace _default {
|
|
99
|
+
export { defer };
|
|
100
|
+
export { delay };
|
|
101
|
+
export { timeout };
|
|
102
|
+
export { allSettled };
|
|
103
|
+
export { returnValuePromised };
|
|
104
|
+
export { series };
|
|
105
|
+
export { seriesAllSettled };
|
|
106
|
+
export { parallel };
|
|
107
|
+
export { parallelAllSettled };
|
|
108
|
+
}
|
|
109
|
+
export default _default;
|
package/types/string-utils.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export function decapitalize(str: string): string;
|
|
|
48
48
|
* @returns {string[]} An array of string chunks with fixed length.
|
|
49
49
|
* @throws {Error} If `str` is not a string or `length` is not a number.
|
|
50
50
|
*/
|
|
51
|
-
export function splitWithFixedLength(str: string, length: number, padding?: string): string[];
|
|
51
|
+
export function splitWithFixedLength(str: string, length: number, padding?: string | undefined): string[];
|
|
52
52
|
/**
|
|
53
53
|
* Splits a string into chunks using the specified markers.
|
|
54
54
|
* 1. If no markers are provided, defaults to comma (',').
|
|
@@ -150,3 +150,23 @@ export function substringBetweenGreedy(str: string, startMarker: string, endMark
|
|
|
150
150
|
* @throws {Error} If any input is not a string
|
|
151
151
|
*/
|
|
152
152
|
export function substringsBetween(str: string, startMarker: string, endMarker: string): string[];
|
|
153
|
+
declare namespace _default {
|
|
154
|
+
export { isEmpty };
|
|
155
|
+
export { assertNotEmpty };
|
|
156
|
+
export { isBlank };
|
|
157
|
+
export { assertNotBlank };
|
|
158
|
+
export { capitalize };
|
|
159
|
+
export { decapitalize };
|
|
160
|
+
export { splitWithFixedLength };
|
|
161
|
+
export { split };
|
|
162
|
+
export { findMarkerPositions };
|
|
163
|
+
export { findMarkerPositionsRegex };
|
|
164
|
+
export { substringBefore };
|
|
165
|
+
export { substringBeforeLast };
|
|
166
|
+
export { substringAfter };
|
|
167
|
+
export { substringAfterLast };
|
|
168
|
+
export { substringBetween };
|
|
169
|
+
export { substringBetweenGreedy };
|
|
170
|
+
export { substringsBetween };
|
|
171
|
+
}
|
|
172
|
+
export default _default;
|
package/types/type-assert.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* if value is not Array, throw error
|
|
3
|
+
* @param {*} value
|
|
4
|
+
* @param {string} [paramName] - The name of the parameter to check
|
|
5
|
+
* @returns {void}
|
|
6
|
+
* @throws {Error}
|
|
7
|
+
*/
|
|
8
|
+
export function assertArray(value: any, paramName?: string | undefined): void;
|
|
9
|
+
/**
|
|
10
|
+
* if value is not a string, throw error
|
|
11
|
+
* @param {*} value
|
|
12
|
+
* @param {string} [paramName] - The name of the parameter to check
|
|
13
|
+
* @returns {void}
|
|
14
|
+
* @throws {Error}
|
|
15
|
+
*/
|
|
16
|
+
export function assertString(value: any, paramName?: string | undefined): void;
|
|
1
17
|
/**
|
|
2
18
|
* if value is not a Number, throw error
|
|
3
19
|
* @param {*} value
|
|
@@ -5,21 +21,21 @@
|
|
|
5
21
|
* @returns {void}
|
|
6
22
|
* @throws {Error}
|
|
7
23
|
*/
|
|
8
|
-
export function assertNumber(value: any, paramName?: string): void;
|
|
24
|
+
export function assertNumber(value: any, paramName?: string | undefined): void;
|
|
9
25
|
/**
|
|
10
26
|
* Asserts that a value is a positive number.
|
|
11
27
|
* @param {number} value - The value to check.
|
|
12
28
|
* @param {string} [paramName] - Optional name of the parameter for error message.
|
|
13
29
|
* @throws {Error} If the value is not a number or is less than or equal to zero.
|
|
14
30
|
*/
|
|
15
|
-
export function assertPositive(value: number, paramName?: string): void;
|
|
31
|
+
export function assertPositive(value: number, paramName?: string | undefined): void;
|
|
16
32
|
/**
|
|
17
33
|
* Asserts that a value is a Negative number.
|
|
18
34
|
* @param {number} value - The value to check.
|
|
19
35
|
* @param {string} [paramName] - Optional name of the parameter for error message.
|
|
20
36
|
* @throws {Error} If the value is not a number or is less than or equal to zero.
|
|
21
37
|
*/
|
|
22
|
-
export function assertNegative(value: number, paramName?: string): void;
|
|
38
|
+
export function assertNegative(value: number, paramName?: string | undefined): void;
|
|
23
39
|
/**
|
|
24
40
|
* if value is not a string, throw error
|
|
25
41
|
* @param {*} value
|
|
@@ -27,7 +43,7 @@ export function assertNegative(value: number, paramName?: string): void;
|
|
|
27
43
|
* @returns {void}
|
|
28
44
|
* @throws {Error}
|
|
29
45
|
*/
|
|
30
|
-
export function assertBoolean(value: any, paramName?: string): void;
|
|
46
|
+
export function assertBoolean(value: any, paramName?: string | undefined): void;
|
|
31
47
|
/**
|
|
32
48
|
* if value is not a Object, throw error
|
|
33
49
|
* @param {*} value
|
|
@@ -35,7 +51,7 @@ export function assertBoolean(value: any, paramName?: string): void;
|
|
|
35
51
|
* @returns {void}
|
|
36
52
|
* @throws {Error}
|
|
37
53
|
*/
|
|
38
|
-
export function assertObject(value: any, paramName?: string): void;
|
|
54
|
+
export function assertObject(value: any, paramName?: string | undefined): void;
|
|
39
55
|
/**
|
|
40
56
|
* if value is not a PlainObject, throw error
|
|
41
57
|
* @param {*} value
|
|
@@ -43,7 +59,7 @@ export function assertObject(value: any, paramName?: string): void;
|
|
|
43
59
|
* @returns {void}
|
|
44
60
|
* @throws {Error}
|
|
45
61
|
*/
|
|
46
|
-
export function assertPlainObject(value: any, paramName?: string): void;
|
|
62
|
+
export function assertPlainObject(value: any, paramName?: string | undefined): void;
|
|
47
63
|
/**
|
|
48
64
|
* if value is not a Symbol, throw error
|
|
49
65
|
* @param {*} value
|
|
@@ -51,7 +67,7 @@ export function assertPlainObject(value: any, paramName?: string): void;
|
|
|
51
67
|
* @returns {void}
|
|
52
68
|
* @throws {Error}
|
|
53
69
|
*/
|
|
54
|
-
export function assertSymbol(value: any, paramName?: string): void;
|
|
70
|
+
export function assertSymbol(value: any, paramName?: string | undefined): void;
|
|
55
71
|
/**
|
|
56
72
|
* if value is not a Function, throw error
|
|
57
73
|
* @param {*} value
|
|
@@ -59,7 +75,7 @@ export function assertSymbol(value: any, paramName?: string): void;
|
|
|
59
75
|
* @returns {void}
|
|
60
76
|
* @throws {Error}
|
|
61
77
|
*/
|
|
62
|
-
export function assertFunction(value: any, paramName?: string): void;
|
|
78
|
+
export function assertFunction(value: any, paramName?: string | undefined): void;
|
|
63
79
|
/**
|
|
64
80
|
* if value is not a Class instance, throw error
|
|
65
81
|
* @param {*} value
|
|
@@ -67,7 +83,7 @@ export function assertFunction(value: any, paramName?: string): void;
|
|
|
67
83
|
* @returns {void}
|
|
68
84
|
* @throws {Error}
|
|
69
85
|
*/
|
|
70
|
-
export function assertInstance(value: any, paramName?: string): void;
|
|
86
|
+
export function assertInstance(value: any, paramName?: string | undefined): void;
|
|
71
87
|
/**
|
|
72
88
|
* if value is not a string, throw error
|
|
73
89
|
* @param {*} value
|
|
@@ -75,7 +91,7 @@ export function assertInstance(value: any, paramName?: string): void;
|
|
|
75
91
|
* @returns {void}
|
|
76
92
|
* @throws {Error}
|
|
77
93
|
*/
|
|
78
|
-
export function assertPromise(value: any, paramName?: string): void;
|
|
94
|
+
export function assertPromise(value: any, paramName?: string | undefined): void;
|
|
79
95
|
/**
|
|
80
96
|
* if value is not a Null or Undefined, throw error
|
|
81
97
|
* @param {*} value
|
|
@@ -83,14 +99,14 @@ export function assertPromise(value: any, paramName?: string): void;
|
|
|
83
99
|
* @returns {void}
|
|
84
100
|
* @throws {Error}
|
|
85
101
|
*/
|
|
86
|
-
export function assertNil(value: any, paramName?: string): void;
|
|
102
|
+
export function assertNil(value: any, paramName?: string | undefined): void;
|
|
87
103
|
/**
|
|
88
104
|
* Asserts that the given value is not nil.
|
|
89
105
|
* @param {*} value - The value to check
|
|
90
106
|
* @param {string} [paramName] - The name of the parameter to check
|
|
91
107
|
* @throws {Error} Throws an error if the value is nil
|
|
92
108
|
*/
|
|
93
|
-
export function assertNotNil(value: any, paramName?: string): void;
|
|
109
|
+
export function assertNotNil(value: any, paramName?: string | undefined): void;
|
|
94
110
|
/**
|
|
95
111
|
* if value is not a Null, throw error
|
|
96
112
|
* @param {*} value
|
|
@@ -98,14 +114,14 @@ export function assertNotNil(value: any, paramName?: string): void;
|
|
|
98
114
|
* @returns {void}
|
|
99
115
|
* @throws {Error}
|
|
100
116
|
*/
|
|
101
|
-
export function assertNull(value: any, paramName?: string): void;
|
|
117
|
+
export function assertNull(value: any, paramName?: string | undefined): void;
|
|
102
118
|
/**
|
|
103
119
|
* Asserts that the given value is not null.
|
|
104
120
|
* @param {*} value - The value to check
|
|
105
121
|
* @param {string} [paramName] - The name of the parameter to check
|
|
106
122
|
* @throws {Error} Throws an error if the value is null
|
|
107
123
|
*/
|
|
108
|
-
export function assertNotNull(value: any, paramName?: string): void;
|
|
124
|
+
export function assertNotNull(value: any, paramName?: string | undefined): void;
|
|
109
125
|
/**
|
|
110
126
|
* if value is not a Undefined, throw error
|
|
111
127
|
* @param {*} value
|
|
@@ -113,27 +129,32 @@ export function assertNotNull(value: any, paramName?: string): void;
|
|
|
113
129
|
* @returns {void}
|
|
114
130
|
* @throws {Error}
|
|
115
131
|
*/
|
|
116
|
-
export function assertUndefined(value: any, paramName?: string): void;
|
|
117
|
-
/**
|
|
118
|
-
* if value is not a string, throw error
|
|
119
|
-
* @param {*} value
|
|
120
|
-
* @param {string} [paramName] - The name of the parameter to check
|
|
121
|
-
* @returns {void}
|
|
122
|
-
* @throws {Error}
|
|
123
|
-
*/
|
|
124
|
-
export function assertString(value: any, paramName?: string): void;
|
|
125
|
-
/**
|
|
126
|
-
* if value is not Array, throw error
|
|
127
|
-
* @param {*} value
|
|
128
|
-
* @param {string} [paramName] - The name of the parameter to check
|
|
129
|
-
* @returns {void}
|
|
130
|
-
* @throws {Error}
|
|
131
|
-
*/
|
|
132
|
-
export function assertArray(value: any, paramName?: string): void;
|
|
132
|
+
export function assertUndefined(value: any, paramName?: string | undefined): void;
|
|
133
133
|
/**
|
|
134
134
|
* Asserts that the given value is either a string or a symbol.
|
|
135
135
|
* @param {*} value - The value to check.
|
|
136
136
|
* @param {string} [paramName] - Optional parameter name for error message.
|
|
137
137
|
* @throws {Error} Throws an error if the value is not a string or symbol.
|
|
138
138
|
*/
|
|
139
|
-
export function assertStringOrSymbol(value: any, paramName?: string): void;
|
|
139
|
+
export function assertStringOrSymbol(value: any, paramName?: string | undefined): void;
|
|
140
|
+
declare namespace _default {
|
|
141
|
+
export { assertNumber };
|
|
142
|
+
export { assertPositive };
|
|
143
|
+
export { assertNegative };
|
|
144
|
+
export { assertBoolean };
|
|
145
|
+
export { assertObject };
|
|
146
|
+
export { assertPlainObject };
|
|
147
|
+
export { assertSymbol };
|
|
148
|
+
export { assertFunction };
|
|
149
|
+
export { assertInstance };
|
|
150
|
+
export { assertPromise };
|
|
151
|
+
export { assertNil };
|
|
152
|
+
export { assertNotNil };
|
|
153
|
+
export { assertNull };
|
|
154
|
+
export { assertNotNull };
|
|
155
|
+
export { assertUndefined };
|
|
156
|
+
export { assertString };
|
|
157
|
+
export { assertArray };
|
|
158
|
+
export { assertStringOrSymbol };
|
|
159
|
+
}
|
|
160
|
+
export default _default;
|
package/types/type-utils.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module TypeUtils
|
|
3
|
-
* @description Utility functions for type checking and validation.
|
|
4
|
-
*/
|
|
5
1
|
/**
|
|
6
2
|
* Checks if the given value is an array.
|
|
7
3
|
* @param {*} value - The value to check.
|
|
@@ -20,6 +16,18 @@ export function isBoolean(value: any): boolean;
|
|
|
20
16
|
* @returns {boolean} True if the value is a Buffer, false otherwise.
|
|
21
17
|
*/
|
|
22
18
|
export function isBuffer(value: any): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the given value is a Date.
|
|
21
|
+
* @param {*} value - The value to check.
|
|
22
|
+
* @returns {boolean} True if the value is a Date, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export function isDate(value: any): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the given value is an instance of Error.
|
|
27
|
+
* @param {*} value - The value to check.
|
|
28
|
+
* @returns {boolean} True if the value is an Error, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export function isError(value: any): boolean;
|
|
23
31
|
/**
|
|
24
32
|
* Checks if the given value is a function.
|
|
25
33
|
* @param {*} value - The value to check.
|
|
@@ -38,18 +46,6 @@ export function isInstance(value: any): boolean;
|
|
|
38
46
|
* @returns {boolean} True if the value is isIterable, false otherwise.
|
|
39
47
|
*/
|
|
40
48
|
export function isIterable(value: any): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Checks if the given value is a Date.
|
|
43
|
-
* @param {*} value - The value to check.
|
|
44
|
-
* @returns {boolean} True if the value is a Date, false otherwise.
|
|
45
|
-
*/
|
|
46
|
-
export function isDate(value: any): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Checks if the given value is an instance of Error.
|
|
49
|
-
* @param {*} value - The value to check.
|
|
50
|
-
* @returns {boolean} True if the value is an Error, false otherwise.
|
|
51
|
-
*/
|
|
52
|
-
export function isError(value: any): boolean;
|
|
53
49
|
/**
|
|
54
50
|
* Checks if a value is Map
|
|
55
51
|
* @param {*} value - The value to check.
|
|
@@ -62,23 +58,6 @@ export function isMap(value: any): boolean;
|
|
|
62
58
|
* @returns {boolean} True if the value is WeakMap, otherwise false.
|
|
63
59
|
*/
|
|
64
60
|
export function isWeakMap(value: any): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Checks if a value is a number.
|
|
67
|
-
* @param {*} value - The value to check.
|
|
68
|
-
* @returns {boolean} True if the value is a number, false otherwise.
|
|
69
|
-
*/
|
|
70
|
-
export function isNumber(value: any): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* check that a value is a positive number.
|
|
73
|
-
* @param {number} value - The value to check.
|
|
74
|
-
* @returns {boolean}
|
|
75
|
-
*/
|
|
76
|
-
export function isPositive(value: number): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* check that a value is a Negative number.
|
|
79
|
-
* @param {number} value - The value to check.
|
|
80
|
-
*/
|
|
81
|
-
export function isNegative(value: number): boolean;
|
|
82
61
|
/**
|
|
83
62
|
* Checks if a value is null or undefined.
|
|
84
63
|
* 1. value == null
|
|
@@ -94,6 +73,17 @@ export function isNil(value: any): boolean;
|
|
|
94
73
|
* @returns {boolean} True if the value is null or undefined, otherwise false.
|
|
95
74
|
*/
|
|
96
75
|
export function isNullOrUndefined(value: any): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* check that a value is a positive number.
|
|
78
|
+
* @param {number} value - The value to check.
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
export function isPositive(value: number): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* check that a value is a Negative number.
|
|
84
|
+
* @param {number} value - The value to check.
|
|
85
|
+
*/
|
|
86
|
+
export function isNegative(value: number): boolean;
|
|
97
87
|
/**
|
|
98
88
|
* Checks if the given value is exactly null.
|
|
99
89
|
* @param {*} value - The value to check.
|
|
@@ -107,17 +97,30 @@ export function isNull(value: any): boolean;
|
|
|
107
97
|
*/
|
|
108
98
|
export function isUndefined(value: any): boolean;
|
|
109
99
|
/**
|
|
110
|
-
* Checks if a value is a
|
|
100
|
+
* Checks if a value is a number.
|
|
111
101
|
* @param {*} value - The value to check.
|
|
112
|
-
* @returns {boolean} True if the value is a
|
|
102
|
+
* @returns {boolean} True if the value is a number, false otherwise.
|
|
113
103
|
*/
|
|
114
|
-
export function
|
|
104
|
+
export function isNumber(value: any): boolean;
|
|
115
105
|
/**
|
|
116
106
|
* Checks if a value is an object (and not null).
|
|
117
107
|
* @param {*} value - The value to check
|
|
118
108
|
* @returns {boolean} True if the value is an object (not null), false otherwise
|
|
119
109
|
*/
|
|
120
110
|
export function isObject(value: any): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Checks if a value is a plain object (created by the Object constructor).
|
|
113
|
+
* @param {*} value - The value to check.
|
|
114
|
+
* @returns {boolean} True if the value is a plain object, false otherwise.
|
|
115
|
+
*/
|
|
116
|
+
export function isPlainObject(value: any): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* check if value is primitive: string, number, boolean
|
|
119
|
+
* 1. null/undefined returns false
|
|
120
|
+
* @param {*} value
|
|
121
|
+
* @returns {boolean}
|
|
122
|
+
*/
|
|
123
|
+
export function isPrimitive(value: any): boolean;
|
|
121
124
|
/**
|
|
122
125
|
* Checks if a value is a Promise.
|
|
123
126
|
* @param {*} value - The value to check.
|
|
@@ -160,10 +163,33 @@ export function isString(value: any): boolean;
|
|
|
160
163
|
* @returns {boolean} True if the value is a Symbol, false otherwise.
|
|
161
164
|
*/
|
|
162
165
|
export function isSymbol(value: any): boolean;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
export
|
|
166
|
+
declare namespace _default {
|
|
167
|
+
export { isArray };
|
|
168
|
+
export { isBoolean };
|
|
169
|
+
export { isBuffer };
|
|
170
|
+
export { isFunction };
|
|
171
|
+
export { isInstance };
|
|
172
|
+
export { isIterable };
|
|
173
|
+
export { isDate };
|
|
174
|
+
export { isError };
|
|
175
|
+
export { isMap };
|
|
176
|
+
export { isWeakMap };
|
|
177
|
+
export { isNumber };
|
|
178
|
+
export { isPositive };
|
|
179
|
+
export { isNegative };
|
|
180
|
+
export { isNil };
|
|
181
|
+
export { isNullOrUndefined };
|
|
182
|
+
export { isNull };
|
|
183
|
+
export { isUndefined };
|
|
184
|
+
export { isPlainObject };
|
|
185
|
+
export { isObject };
|
|
186
|
+
export { isPromise };
|
|
187
|
+
export { isRegExp };
|
|
188
|
+
export { isSet };
|
|
189
|
+
export { isWeakSet };
|
|
190
|
+
export { isStream };
|
|
191
|
+
export { isString };
|
|
192
|
+
export { isSymbol };
|
|
193
|
+
export { isPrimitive };
|
|
194
|
+
}
|
|
195
|
+
export default _default;
|
package/lib/class-proxy-utils.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { isPlainObject } = require('./type-utils')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @module ClassProxyUtils
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a Proxy Class for given class.
|
|
11
|
-
* @template {object} T
|
|
12
|
-
* @param {Function} cls - The class to proxycls - The class to proxy
|
|
13
|
-
* @param {ProxyHandler<T>} [propertyHandler = {}] - Proxy Property Handler
|
|
14
|
-
* @param {boolean} [sealed=true] - Whether to seal the instance
|
|
15
|
-
* @returns {Function} A proxied classA proxied instance of the class
|
|
16
|
-
*/
|
|
17
|
-
function proxy (cls, propertyHandler, sealed = true) {
|
|
18
|
-
if (typeof cls !== 'function') {
|
|
19
|
-
throw new TypeError(`Not Class: type=${typeof cls}, value=${JSON.stringify(cls)}`)
|
|
20
|
-
}
|
|
21
|
-
if (propertyHandler != null) {
|
|
22
|
-
if (!isPlainObject(propertyHandler)) {
|
|
23
|
-
throw new TypeError(`Not PropertyHandler: type=${typeof propertyHandler}, value=${JSON.stringify(propertyHandler)}`)
|
|
24
|
-
}
|
|
25
|
-
const { get, set } = propertyHandler
|
|
26
|
-
if (get != null && typeof get !== 'function') {
|
|
27
|
-
throw new TypeError(`Not PropertyHandler.get: type=${typeof get}, value=${JSON.stringify(get)}`)
|
|
28
|
-
}
|
|
29
|
-
if (set != null && typeof set !== 'function') {
|
|
30
|
-
throw new TypeError(`Not PropertyHandler.set: type=${typeof set}, value=${JSON.stringify(set)}`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const construcHandler = {
|
|
34
|
-
/**
|
|
35
|
-
* Creates a proxied instance of a class, optionally sealing it.
|
|
36
|
-
* @param {Function} constructor - The class constructor to instantiate.
|
|
37
|
-
* @param {any[]} args - Arguments to pass to the constructor.
|
|
38
|
-
* @param {Function} [newTarget] - The constructor that was originally called by `new`.
|
|
39
|
-
* @returns {Proxy} A proxied instance of the constructed class.
|
|
40
|
-
*/
|
|
41
|
-
construct (constructor, args, newTarget) {
|
|
42
|
-
const clsInstance = Reflect.construct(constructor, args)
|
|
43
|
-
return new Proxy(sealed ? Object.preventExtensions(clsInstance) : clsInstance, propertyHandler ?? {})
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return new Proxy(cls, construcHandler)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Creates a proxied instance of a class with custom property handling.
|
|
51
|
-
* @template {object} T
|
|
52
|
-
* @param {Function} cls - The class to proxy
|
|
53
|
-
* @param {any[]} args - Arguments to pass to the constructor
|
|
54
|
-
* @param {ProxyHandler<T>} propertyHandler - Handler for property access/mutation
|
|
55
|
-
* @param {boolean} [sealed=true] - Whether the proxy should be sealed
|
|
56
|
-
* @returns {T} Proxied class instance
|
|
57
|
-
*/
|
|
58
|
-
function newProxyInstance (cls, args, propertyHandler, sealed = true) {
|
|
59
|
-
const proxyCls = proxy(cls, propertyHandler, sealed)
|
|
60
|
-
return Reflect.construct(proxyCls, args ?? [])
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = {
|
|
64
|
-
proxy,
|
|
65
|
-
newProxyInstance
|
|
66
|
-
}
|
package/lib/exec-utils.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* @module ExecUtils
|
|
4
|
-
* @description Utils about how to execute task functions.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const { assertFunction, assertArray } = require('./type-assert')
|
|
9
|
-
const { isPromise } = require('./type-utils')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Executes a task silently, suppressing any errors or rejections.
|
|
13
|
-
* @param {Function} task - The function to execute.
|
|
14
|
-
* @returns {Promise<*>|*} The return value of the task, or a Promise if the task is asynchronous.
|
|
15
|
-
*/
|
|
16
|
-
function quiet (task) {
|
|
17
|
-
assertFunction(task)
|
|
18
|
-
try {
|
|
19
|
-
const rtnVal = task()
|
|
20
|
-
if (isPromise(rtnVal)) {
|
|
21
|
-
return rtnVal.catch(() => {
|
|
22
|
-
// do nothing
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
return rtnVal
|
|
26
|
-
} catch (e) {
|
|
27
|
-
// do nothing
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Executes a task quietly, capturing any errors and passing them to the errorKeeper.
|
|
33
|
-
* 1. Handles both synchronous and asynchronous (Promise) tasks.
|
|
34
|
-
* @param {Function} task - The function to execute.
|
|
35
|
-
* @param {Error[]} errorKeeper - The array to store any caught errors.
|
|
36
|
-
* @returns {Promise<*>|*} The return value of the task, or a Promise if the task is asynchronous.
|
|
37
|
-
*/
|
|
38
|
-
function quietKeepError (task, errorKeeper) {
|
|
39
|
-
assertFunction(task)
|
|
40
|
-
assertArray(errorKeeper)
|
|
41
|
-
try {
|
|
42
|
-
const rtnVal = task()
|
|
43
|
-
if (isPromise(rtnVal)) {
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
return rtnVal.catch(e => errorKeeper.push(e))
|
|
46
|
-
}
|
|
47
|
-
return rtnVal
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
errorKeeper.push(e)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const ExecUtils = {
|
|
54
|
-
quiet,
|
|
55
|
-
quietKeepError
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = ExecUtils
|
package/lib/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @module Lang
|
|
5
|
-
* @description Core language utilities for type checking, string manipulation, and common operations.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const LangUtils = require('./lang-utils')
|
|
9
|
-
const StringUtils = require('./string-utils')
|
|
10
|
-
const TypeUtils = require('./type-utils')
|
|
11
|
-
const TypeAssert = require('./type-assert')
|
|
12
|
-
const ExecUtils = require('./exec-utils')
|
|
13
|
-
const PromiseUtils = require('./promise-utils')
|
|
14
|
-
const ClassProxyUtils = require('./class-proxy-utils')
|
|
15
|
-
const InstanceProxyUtils = require('./instance-proxy-utils')
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
LangUtils,
|
|
19
|
-
StringUtils,
|
|
20
|
-
TypeUtils,
|
|
21
|
-
TypeAssert,
|
|
22
|
-
ExecUtils,
|
|
23
|
-
PromiseUtils,
|
|
24
|
-
Lang: LangUtils,
|
|
25
|
-
String: StringUtils,
|
|
26
|
-
Type: TypeUtils,
|
|
27
|
-
Exec: ExecUtils,
|
|
28
|
-
ClassProxyUtils,
|
|
29
|
-
InstanceProxyUtils
|
|
30
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { isObject, isNil, isArray } = require('./type-utils')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @module InstanceProxyUtils
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a proxy wrapper around an object instance with optional property handler.
|
|
11
|
-
* @template {object} T
|
|
12
|
-
* @param {T} instance - The target object to proxy
|
|
13
|
-
* @param {ProxyHandler<T>} [propertyHandler] - Optional proxy handler for property access
|
|
14
|
-
* @param {boolean} [sealed=true] - Whether to prevent extensions on the target object
|
|
15
|
-
* @returns {T} The proxied object instance
|
|
16
|
-
* @throws {TypeError} If instance is not an object
|
|
17
|
-
*/
|
|
18
|
-
function proxy (instance, propertyHandler, sealed = true) {
|
|
19
|
-
if (isNil(instance) || !isObject(instance) || isArray(instance)) {
|
|
20
|
-
throw new TypeError(`Not Object: type=${typeof instance}, value=${JSON.stringify(instance)}`)
|
|
21
|
-
}
|
|
22
|
-
return new Proxy(sealed ? Object.preventExtensions(instance) : instance, propertyHandler ?? {})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
proxy
|
|
27
|
-
}
|