@creejs/commons-lang 2.0.0 → 2.0.2
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 +24 -0
- package/types/exec-utils.d.ts +10 -5
- package/types/index.d.ts +23 -7
- package/types/instance-proxy-utils.d.ts +17 -0
- 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/exec-utils.js +0 -58
- package/lib/index.js +0 -26
- 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/lib/type-utils.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @module TypeUtils
|
|
5
|
-
* @description Utility functions for type checking and validation.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Checks if the given value is an array.
|
|
10
|
-
* @param {*} value - The value to check.
|
|
11
|
-
* @returns {boolean} True if the value is an array, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
function isArray (value) {
|
|
14
|
-
return Array.isArray(value)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Checks if the given value is a boolean.
|
|
19
|
-
* @param {*} value - The value to check.
|
|
20
|
-
* @returns {boolean} True if the value is a boolean, false otherwise.
|
|
21
|
-
*/
|
|
22
|
-
function isBoolean (value) {
|
|
23
|
-
return typeof value === 'boolean'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Checks if the given value is a Buffer.
|
|
28
|
-
* @param {*} value - The value to check.
|
|
29
|
-
* @returns {boolean} True if the value is a Buffer, false otherwise.
|
|
30
|
-
*/
|
|
31
|
-
function isBuffer (value) {
|
|
32
|
-
return value != null && Buffer.isBuffer(value)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Checks if the given value is a Date.
|
|
37
|
-
* @param {*} value - The value to check.
|
|
38
|
-
* @returns {boolean} True if the value is a Date, false otherwise.
|
|
39
|
-
*/
|
|
40
|
-
function isDate (value) {
|
|
41
|
-
return value != null && value instanceof Date
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Checks if the given value is an instance of Error.
|
|
46
|
-
* @param {*} value - The value to check.
|
|
47
|
-
* @returns {boolean} True if the value is an Error, false otherwise.
|
|
48
|
-
*/
|
|
49
|
-
function isError (value) {
|
|
50
|
-
return value != null && value instanceof Error
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Checks if the given value is a function.
|
|
55
|
-
* @param {*} value - The value to check.
|
|
56
|
-
* @returns {boolean} True if the value is a function, false otherwise.
|
|
57
|
-
*/
|
|
58
|
-
function isFunction (value) {
|
|
59
|
-
return typeof value === 'function'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Checks if a value is a class instance (non-null and not a plain object).
|
|
64
|
-
* @param {*} value - The value to check.
|
|
65
|
-
* @returns {boolean} True if the value is a class instance, false otherwise.
|
|
66
|
-
*/
|
|
67
|
-
function isInstance (value) {
|
|
68
|
-
return value != null && typeof value === 'object' && !TypeUtils.isPlainObject(value)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Checks if a value is isIterable
|
|
73
|
-
* @param {*} value - The value to check.
|
|
74
|
-
* @returns {boolean} True if the value is isIterable, false otherwise.
|
|
75
|
-
*/
|
|
76
|
-
function isIterable (value) {
|
|
77
|
-
return value != null && typeof value[Symbol.iterator] === 'function'
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Checks if a value is Map
|
|
82
|
-
* @param {*} value - The value to check.
|
|
83
|
-
* @returns {boolean} True if the value is Map, otherwise false.
|
|
84
|
-
*/
|
|
85
|
-
function isMap (value) {
|
|
86
|
-
return value != null && typeof value === 'object' && value.constructor === Map
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Checks if a value is WeakMap
|
|
91
|
-
* @param {*} value - The value to check.
|
|
92
|
-
* @returns {boolean} True if the value is WeakMap, otherwise false.
|
|
93
|
-
*/
|
|
94
|
-
function isWeakMap (value) {
|
|
95
|
-
return value != null && typeof value === 'object' && value.constructor === WeakMap
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Checks if a value is null or undefined.
|
|
100
|
-
* 1. value == null
|
|
101
|
-
* 2. return true, if value is null or undefined
|
|
102
|
-
* @param {*} value - The value to check.
|
|
103
|
-
* @returns {boolean} True if the value is null or undefined, otherwise false.
|
|
104
|
-
*/
|
|
105
|
-
function isNil (value) {
|
|
106
|
-
return value == null
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Checks if a value is null or undefined.
|
|
111
|
-
* 1. same with isNil()
|
|
112
|
-
* @param {*} value - The value to check.
|
|
113
|
-
* @returns {boolean} True if the value is null or undefined, otherwise false.
|
|
114
|
-
*/
|
|
115
|
-
function isNullOrUndefined (value) {
|
|
116
|
-
return value == null
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* check that a value is a positive number.
|
|
121
|
-
* @param {number} value - The value to check.
|
|
122
|
-
* @returns {boolean}
|
|
123
|
-
*/
|
|
124
|
-
function isPositive (value) {
|
|
125
|
-
if (!isNumber(value)) {
|
|
126
|
-
return false
|
|
127
|
-
}
|
|
128
|
-
return value > 0
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* check that a value is a Negative number.
|
|
133
|
-
* @param {number} value - The value to check.
|
|
134
|
-
*/
|
|
135
|
-
function isNegative (value) {
|
|
136
|
-
if (!isNumber(value)) {
|
|
137
|
-
return false
|
|
138
|
-
}
|
|
139
|
-
return value < 0
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Checks if the given value is exactly null.
|
|
144
|
-
* @param {*} value - The value to check.
|
|
145
|
-
* @returns {boolean} True if the value is null, false otherwise.
|
|
146
|
-
*/
|
|
147
|
-
function isNull (value) {
|
|
148
|
-
return value === null
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Checks if a value is exactly undefined.
|
|
153
|
-
* @param {*} value - The value to check.
|
|
154
|
-
* @returns {boolean} True if the value is undefined, false otherwise.
|
|
155
|
-
*/
|
|
156
|
-
function isUndefined (value) {
|
|
157
|
-
return value === undefined
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Checks if a value is a number.
|
|
162
|
-
* @param {*} value - The value to check.
|
|
163
|
-
* @returns {boolean} True if the value is a number, false otherwise.
|
|
164
|
-
*/
|
|
165
|
-
function isNumber (value) {
|
|
166
|
-
return value != null && typeof value === 'number'
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Checks if a value is an object (and not null).
|
|
171
|
-
* @param {*} value - The value to check
|
|
172
|
-
* @returns {boolean} True if the value is an object (not null), false otherwise
|
|
173
|
-
*/
|
|
174
|
-
function isObject (value) {
|
|
175
|
-
return value != null && typeof value === 'object'
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Checks if a value is a plain object (created by the Object constructor).
|
|
180
|
-
* @param {*} value - The value to check.
|
|
181
|
-
* @returns {boolean} True if the value is a plain object, false otherwise.
|
|
182
|
-
*/
|
|
183
|
-
function isPlainObject (value) {
|
|
184
|
-
return value !== null && typeof value === 'object' && (value.constructor === Object || value.constructor === undefined)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* check if value is primitive: string, number, boolean
|
|
189
|
-
* 1. null/undefined returns false
|
|
190
|
-
* @param {*} value
|
|
191
|
-
* @returns {boolean}
|
|
192
|
-
*/
|
|
193
|
-
function isPrimitive (value) {
|
|
194
|
-
return value !== null && (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Checks if a value is a Promise.
|
|
199
|
-
* @param {*} value - The value to check.
|
|
200
|
-
* @returns {boolean} True if the value is a Promise, false otherwise.
|
|
201
|
-
*/
|
|
202
|
-
function isPromise (value) {
|
|
203
|
-
return value != null && typeof value.then === 'function'
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Checks if a RegExp
|
|
208
|
-
* @param {*} value - The value to check.
|
|
209
|
-
* @returns {boolean} True if the value is RegExp, otherwise false.
|
|
210
|
-
*/
|
|
211
|
-
function isRegExp (value) {
|
|
212
|
-
return value != null && typeof value === 'object' && value.constructor === RegExp
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Checks if a Set
|
|
217
|
-
* @param {*} value - The value to check.
|
|
218
|
-
* @returns {boolean} True if the value is Set, otherwise false.
|
|
219
|
-
*/
|
|
220
|
-
function isSet (value) {
|
|
221
|
-
return value != null && typeof value === 'object' && value.constructor === Set
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Checks if a WeakSet
|
|
226
|
-
* @param {*} value - The value to check.
|
|
227
|
-
* @returns {boolean} True if the value is WeakSet, otherwise false.
|
|
228
|
-
*/
|
|
229
|
-
function isWeakSet (value) {
|
|
230
|
-
return value != null && typeof value === 'object' && value.constructor === WeakSet
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Check if the value is a string
|
|
235
|
-
* @param {*} value
|
|
236
|
-
* @return {boolean}
|
|
237
|
-
*/
|
|
238
|
-
function isStream (value) {
|
|
239
|
-
return value != null && typeof value.pipe === 'function'
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Check if the value is a string
|
|
244
|
-
* @param {*} value
|
|
245
|
-
* @return {boolean}
|
|
246
|
-
*/
|
|
247
|
-
function isString (value) {
|
|
248
|
-
return value != null && typeof value === 'string'
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Checks if the given value is a Symbol.
|
|
253
|
-
* @param {*} value - The value to check.
|
|
254
|
-
* @returns {boolean} True if the value is a Symbol, false otherwise.
|
|
255
|
-
*/
|
|
256
|
-
function isSymbol (value) {
|
|
257
|
-
return value != null && typeof value === 'symbol'
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const TypeUtils = {
|
|
261
|
-
isArray,
|
|
262
|
-
isBoolean,
|
|
263
|
-
isBuffer,
|
|
264
|
-
isFunction,
|
|
265
|
-
isInstance,
|
|
266
|
-
isIterable,
|
|
267
|
-
isDate,
|
|
268
|
-
isError,
|
|
269
|
-
isMap,
|
|
270
|
-
isWeakMap,
|
|
271
|
-
isNumber,
|
|
272
|
-
isPositive,
|
|
273
|
-
isNegative,
|
|
274
|
-
isNil,
|
|
275
|
-
isNullOrUndefined,
|
|
276
|
-
isNull,
|
|
277
|
-
isUndefined,
|
|
278
|
-
isPlainObject,
|
|
279
|
-
isObject,
|
|
280
|
-
isPromise,
|
|
281
|
-
isRegExp,
|
|
282
|
-
isSet,
|
|
283
|
-
isWeakSet,
|
|
284
|
-
isStream,
|
|
285
|
-
isString,
|
|
286
|
-
isSymbol,
|
|
287
|
-
isPrimitive
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
module.exports = TypeUtils
|
package/types/lang.d.ts
DELETED
package/types/type-asset.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* if value is not a string, throw error
|
|
3
|
-
* @param {*} value
|
|
4
|
-
* @returns {void}
|
|
5
|
-
* @throws {Error}
|
|
6
|
-
*/
|
|
7
|
-
export function assertString(value: any): void;
|
|
8
|
-
/**
|
|
9
|
-
* if value is not a Number, throw error
|
|
10
|
-
* @param {*} value
|
|
11
|
-
* @returns {void}
|
|
12
|
-
* @throws {Error}
|
|
13
|
-
*/
|
|
14
|
-
export function assertNumber(value: any): void;
|
|
15
|
-
/**
|
|
16
|
-
* if value is not a string, throw error
|
|
17
|
-
* @param {*} value
|
|
18
|
-
* @returns {void}
|
|
19
|
-
* @throws {Error}
|
|
20
|
-
*/
|
|
21
|
-
export function assertBoolean(value: any): void;
|
|
22
|
-
/**
|
|
23
|
-
* if value is not a Object, throw error
|
|
24
|
-
* @param {*} value
|
|
25
|
-
* @returns {void}
|
|
26
|
-
* @throws {Error}
|
|
27
|
-
*/
|
|
28
|
-
export function assertObject(value: any): void;
|
|
29
|
-
/**
|
|
30
|
-
* if value is not a PlainObject, throw error
|
|
31
|
-
* @param {*} value
|
|
32
|
-
* @returns {void}
|
|
33
|
-
* @throws {Error}
|
|
34
|
-
*/
|
|
35
|
-
export function assertPlainObject(value: any): void;
|
|
36
|
-
/**
|
|
37
|
-
* if value is not a Symbol, throw error
|
|
38
|
-
* @param {*} value
|
|
39
|
-
* @returns {void}
|
|
40
|
-
* @throws {Error}
|
|
41
|
-
*/
|
|
42
|
-
export function assertSymbol(value: any): void;
|
|
43
|
-
/**
|
|
44
|
-
* if value is not a Function, throw error
|
|
45
|
-
* @param {*} value
|
|
46
|
-
* @returns {void}
|
|
47
|
-
* @throws {Error}
|
|
48
|
-
*/
|
|
49
|
-
export function assertFunction(value: any): void;
|
|
50
|
-
/**
|
|
51
|
-
* if value is not a Class instance, throw error
|
|
52
|
-
* @param {*} value
|
|
53
|
-
* @returns {void}
|
|
54
|
-
* @throws {Error}
|
|
55
|
-
*/
|
|
56
|
-
export function assertInstance(value: any): void;
|
|
57
|
-
/**
|
|
58
|
-
* if value is not a string, throw error
|
|
59
|
-
* @param {*} value
|
|
60
|
-
* @returns {void}
|
|
61
|
-
* @throws {Error}
|
|
62
|
-
*/
|
|
63
|
-
export function assertPromise(value: any): void;
|
|
64
|
-
/**
|
|
65
|
-
* if value is not a Null or Undefined, throw error
|
|
66
|
-
* @param {*} value
|
|
67
|
-
* @returns {void}
|
|
68
|
-
* @throws {Error}
|
|
69
|
-
*/
|
|
70
|
-
export function assertNil(value: any): void;
|
|
71
|
-
/**
|
|
72
|
-
* if value is not a Null, throw error
|
|
73
|
-
* @param {*} value
|
|
74
|
-
* @returns {void}
|
|
75
|
-
* @throws {Error}
|
|
76
|
-
*/
|
|
77
|
-
export function assertNull(value: any): void;
|
|
78
|
-
/**
|
|
79
|
-
* if value is not a Undefined, throw error
|
|
80
|
-
* @param {*} value
|
|
81
|
-
* @returns {void}
|
|
82
|
-
* @throws {Error}
|
|
83
|
-
*/
|
|
84
|
-
export function assertUndefined(value: any): void;
|