atomic-fns 0.1.1 → 0.2.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/.esdoc.json +27 -0
- package/.eslintrc.json +1 -0
- package/README.md +16 -17
- package/package.json +24 -13
- package/{build → src}/collections.d.ts +34 -10
- package/src/collections.js +553 -0
- package/src/collections.ts +48 -21
- package/{build → src}/datetime.d.ts +4 -0
- package/src/datetime.js +5 -0
- package/src/datetime.ts +5 -0
- package/{build → src}/functools.d.ts +7 -3
- package/{build → src}/functools.js +48 -49
- package/src/functools.ts +7 -3
- package/src/globals.d.ts +178 -4
- package/src/globals.js +309 -0
- package/src/globals.ts +24 -24
- package/{build → src}/index.d.ts +0 -0
- package/src/index.js +7 -0
- package/{build → src}/itertools.d.ts +4 -0
- package/src/itertools.js +98 -0
- package/src/itertools.ts +8 -5
- package/{build → src}/math.d.ts +1 -1
- package/src/math.js +70 -0
- package/src/math.ts +5 -1
- package/{build → src}/objects.d.ts +0 -0
- package/src/objects.js +1 -0
- package/{build → src}/operators.d.ts +1 -1
- package/src/operators.js +109 -0
- package/src/operators.ts +5 -1
- package/src/random.d.ts +22 -0
- package/src/random.js +48 -0
- package/src/random.ts +32 -8
- package/{build → src}/strings.d.ts +0 -0
- package/src/strings.js +1 -0
- package/{build → src}/util.d.ts +0 -0
- package/src/util.js +1 -0
- package/tests/collections.spec.ts +81 -9
- package/tests/globals.spec.ts +44 -4
- package/tests/itertools.spec.ts +17 -10
- package/tests/operators.spec.ts +8 -5
- package/tsconfig.json +17 -3
- package/build/collections.js +0 -545
- package/build/datetime.js +0 -1
- package/build/globals.d.ts +0 -175
- package/build/globals.js +0 -332
- package/build/index.js +0 -7
- package/build/itertools.js +0 -102
- package/build/math.js +0 -67
- package/build/objects.js +0 -1
- package/build/operators.js +0 -128
- package/build/random.d.ts +0 -5
- package/build/random.js +0 -28
- package/build/strings.js +0 -1
- package/build/util.js +0 -1
package/src/collections.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Collections
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
2
5
|
import {
|
|
3
6
|
call,
|
|
4
7
|
Function,
|
|
@@ -14,14 +17,15 @@ import {
|
|
|
14
17
|
isString,
|
|
15
18
|
Iteratee,
|
|
16
19
|
keys,
|
|
17
|
-
NotImplementedError
|
|
20
|
+
NotImplementedError,
|
|
21
|
+
set
|
|
18
22
|
} from './globals.js'
|
|
19
23
|
import { comp, eq, id } from './operators.js'
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* A container type that provides contains().
|
|
23
27
|
*
|
|
24
|
-
*
|
|
28
|
+
*
|
|
25
29
|
* @interface Container
|
|
26
30
|
*/
|
|
27
31
|
export interface Container {
|
|
@@ -29,9 +33,9 @@ export interface Container {
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
|
-
* These are the "rich comparison" methods,
|
|
36
|
+
* These are the "rich comparison" methods, inspired by Python operators.
|
|
37
|
+
*
|
|
33
38
|
*
|
|
34
|
-
* @export
|
|
35
39
|
* @interface Comparable
|
|
36
40
|
*/
|
|
37
41
|
export interface Comparable {
|
|
@@ -53,7 +57,7 @@ export interface Comparable {
|
|
|
53
57
|
* A Collection is an iterable container type.
|
|
54
58
|
* This is an abstract base class for user-defined collection types.
|
|
55
59
|
*
|
|
56
|
-
*
|
|
60
|
+
*
|
|
57
61
|
* @abstract
|
|
58
62
|
* @class Collection
|
|
59
63
|
* @implements {Container}
|
|
@@ -122,7 +126,7 @@ export interface Reversible<T = unknown> {
|
|
|
122
126
|
/**
|
|
123
127
|
* A sequence is an iterable type with efficient index-based access.
|
|
124
128
|
*
|
|
125
|
-
*
|
|
129
|
+
*
|
|
126
130
|
* @abstract
|
|
127
131
|
* @class Sequence
|
|
128
132
|
* @extends {Collection}
|
|
@@ -196,6 +200,14 @@ export abstract class Sequence<T> extends Collection implements Reversible<T> {
|
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
|
|
205
|
+
*
|
|
206
|
+
*
|
|
207
|
+
* @class FrozenSet
|
|
208
|
+
* @extends {Set<T>}
|
|
209
|
+
* @template T
|
|
210
|
+
*/
|
|
199
211
|
export class FrozenSet<T = any> extends Set<T> {
|
|
200
212
|
constructor(iterable: Iterable<T>) {
|
|
201
213
|
super(iterable)
|
|
@@ -224,23 +236,35 @@ export class FrozenSet<T = any> extends Set<T> {
|
|
|
224
236
|
|
|
225
237
|
export const compact = (...arr) => arr.filter((x) => !isEmpty(x))
|
|
226
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Creates a function that can be used to create named tuple-like objects.
|
|
241
|
+
* @example
|
|
242
|
+
* ```
|
|
243
|
+
* let Point = namedtuple('x', 'y', 'z')
|
|
244
|
+
* let userObj = User(0, 0, 0)
|
|
245
|
+
* // -> {x: 0, y: 0, z: 0}
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
*
|
|
249
|
+
* @param {...string[]} fields
|
|
250
|
+
* @return
|
|
251
|
+
*/
|
|
227
252
|
export function namedtuple(...fields: string[]) {
|
|
228
|
-
return (...args) => fields.
|
|
253
|
+
return (...args) => fields.reduce((prev, f, i) => set(prev, f, args[i], false, true), {})
|
|
229
254
|
}
|
|
230
255
|
|
|
231
256
|
export function filter(arr, fn: Iteratee | PropertyKey | Object = isNull) {
|
|
232
257
|
if (Array.isArray(arr)) {
|
|
233
258
|
// @ts-expect-error function is not compatible?
|
|
234
259
|
if (typeof fn === 'function') return arr.filter(fn)
|
|
235
|
-
if (typeof fn === 'string') return arr.filter((x) => x
|
|
260
|
+
if (typeof fn === 'string') return arr.filter((x) => get(x, fn))
|
|
236
261
|
if (isObject(fn)) return arr.filter(matches(fn))
|
|
237
262
|
}
|
|
238
263
|
}
|
|
239
264
|
|
|
240
265
|
export function find(arr, fn: Iteratee | PropertyKey | Object) {
|
|
241
266
|
if (Array.isArray(arr)) {
|
|
242
|
-
|
|
243
|
-
if (typeof fn === 'function') return arr.find(fn)
|
|
267
|
+
if (typeof fn === 'function') return arr.find(fn as Iteratee)
|
|
244
268
|
if (typeof fn === 'string') return arr.find((x) => x?.[fn])
|
|
245
269
|
if (isObject(fn)) return arr.find(matches(fn))
|
|
246
270
|
}
|
|
@@ -262,8 +286,9 @@ export function findRight(arr, fn: Iteratee | PropertyKey | Object) {
|
|
|
262
286
|
}
|
|
263
287
|
|
|
264
288
|
export const matches = (o) => (x) => {
|
|
289
|
+
if (!o || !x) return false
|
|
265
290
|
for (const key in o) {
|
|
266
|
-
if (!eq(x
|
|
291
|
+
if (!eq(x[key], o[key])) return false
|
|
267
292
|
}
|
|
268
293
|
return true
|
|
269
294
|
}
|
|
@@ -329,7 +354,7 @@ export const map = (arr, fn: Function | string) => {
|
|
|
329
354
|
}
|
|
330
355
|
if (isObject(arr)) {
|
|
331
356
|
return Object.keys(arr).map((key) => {
|
|
332
|
-
if (typeof fn === 'string') return arr[key]
|
|
357
|
+
if (typeof fn === 'string') return get(arr[key], fn)
|
|
333
358
|
return fn(arr[key], key, arr)
|
|
334
359
|
})
|
|
335
360
|
}
|
|
@@ -374,13 +399,14 @@ export function contains(arr, y) {
|
|
|
374
399
|
}
|
|
375
400
|
|
|
376
401
|
export function indexOf(obj, x, start = 0) {
|
|
402
|
+
if (obj == null) return
|
|
377
403
|
const op = call(obj, 'indexOf', x, start)
|
|
378
404
|
if (op != null) return op
|
|
379
|
-
const length = obj
|
|
380
|
-
if (!length || start >= length) return -1
|
|
405
|
+
const length = obj.length
|
|
381
406
|
if (length && start < 0) {
|
|
382
407
|
start = Math.max(start + length, 0)
|
|
383
408
|
}
|
|
409
|
+
if (!length || start >= length) return -1
|
|
384
410
|
for (; start < length; start++) {
|
|
385
411
|
if (eq(x, obj[start])) return start
|
|
386
412
|
}
|
|
@@ -388,11 +414,12 @@ export function indexOf(obj, x, start = 0) {
|
|
|
388
414
|
}
|
|
389
415
|
|
|
390
416
|
export function lastIndexOf(obj, x, start?) {
|
|
417
|
+
if (obj == null) return
|
|
391
418
|
const op = call(obj, 'lastIndexOf', x, start)
|
|
392
419
|
if (op != null) return op
|
|
393
|
-
const length = obj
|
|
394
|
-
if (!length) return -1
|
|
420
|
+
const length = obj.length
|
|
395
421
|
if (start == null) start = length - 1
|
|
422
|
+
if (!length || start < 0) return -1
|
|
396
423
|
for (; start >= 0; start--) {
|
|
397
424
|
if (eq(x, obj[start])) return start
|
|
398
425
|
}
|
|
@@ -402,7 +429,7 @@ export function lastIndexOf(obj, x, start?) {
|
|
|
402
429
|
/**
|
|
403
430
|
* Creates a clone of the given `obj`. If `deep` is `true` it will clone it recursively.
|
|
404
431
|
*
|
|
405
|
-
*
|
|
432
|
+
*
|
|
406
433
|
* @param {*} obj
|
|
407
434
|
* @param {boolean} [deep=false]
|
|
408
435
|
* @return The clone value
|
|
@@ -512,7 +539,7 @@ function baseMerge(obj, source, stack?) {
|
|
|
512
539
|
const srcValue = source[key]
|
|
513
540
|
const objValue = obj[key]
|
|
514
541
|
if (typeof srcValue === 'object' && srcValue !== null) {
|
|
515
|
-
baseMergeDeep(obj, source, key, stack
|
|
542
|
+
baseMergeDeep(obj, source, key, stack || new WeakMap())
|
|
516
543
|
} else {
|
|
517
544
|
if (objValue !== srcValue) {
|
|
518
545
|
obj[key] = srcValue
|
|
@@ -526,7 +553,7 @@ function baseMerge(obj, source, stack?) {
|
|
|
526
553
|
*
|
|
527
554
|
* Note: this method mutates `obj`
|
|
528
555
|
*
|
|
529
|
-
*
|
|
556
|
+
*
|
|
530
557
|
* @param {Object} obj
|
|
531
558
|
* @param {...Object} sources
|
|
532
559
|
* @return {Object} The destination object.
|
|
@@ -586,7 +613,7 @@ export function* union(...args) {
|
|
|
586
613
|
/**
|
|
587
614
|
* Creates an object composed of keys generated from the results of running each element of `arr` thru `func`. The order of grouped values is determined by the order they occur in `arr`. The corresponding value of each key is an array of elements responsible for generating the key.
|
|
588
615
|
*
|
|
589
|
-
*
|
|
616
|
+
*
|
|
590
617
|
* @param {(any[] | Object)} arr The collection to iterate over.
|
|
591
618
|
* @param {(Iteratee | PropertyKey)} [func=id] The iteratee to transform keys.
|
|
592
619
|
* @return {Object} Returns the composed aggregate object.
|
package/src/datetime.js
ADDED
package/src/datetime.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FP
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
import { Function } from './globals.js';
|
|
2
6
|
export declare const bind: (fn: any, self: any, ...args: any[]) => any;
|
|
3
7
|
export declare const partial: (fn: any, ...args: any[]) => any;
|
|
@@ -7,7 +11,7 @@ export declare const compose: (...args: any[]) => (x: any) => any;
|
|
|
7
11
|
/**
|
|
8
12
|
* Creates a function that memoizes the result of `func`. If `resolver` is provided, it determines the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the map cache key.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
14
|
+
*
|
|
11
15
|
* @param {Function} func The function to have its output memoized.
|
|
12
16
|
* @param {Function} [resolver] The function to resolve the cache key.
|
|
13
17
|
* @return {Function} Returns the new memoized function.
|
|
@@ -16,7 +20,7 @@ export declare function memoize(func: Function, resolver?: Function): Function;
|
|
|
16
20
|
/**
|
|
17
21
|
* Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
|
|
18
22
|
*
|
|
19
|
-
*
|
|
23
|
+
*
|
|
20
24
|
* @param {Function} func The function to debounce.
|
|
21
25
|
* @param {number} wait The number of milliseconds to delay.
|
|
22
26
|
* @param {{ maxWait: number }} { maxWait } The maximum time `func` is allowed to be delayed before it's invoked.
|
|
@@ -28,7 +32,7 @@ export declare function debounce(func: Function, wait: number, { maxWait }: {
|
|
|
28
32
|
/**
|
|
29
33
|
* Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds. Subsequent calls to the throttled function return the result of the last successful invocation.
|
|
30
34
|
*
|
|
31
|
-
*
|
|
35
|
+
*
|
|
32
36
|
* @param {Function} func The function to throttle.
|
|
33
37
|
* @param {number} time The number of milliseconds to throttle invocations to.
|
|
34
38
|
* @return {Function} Returns the new throttled function.
|
|
@@ -1,79 +1,78 @@
|
|
|
1
|
-
export const bind = (fn, self, ...args) => fn.bind(self, ...args)
|
|
2
|
-
export const partial = (fn, ...args) => bind(fn, {}, ...args)
|
|
3
|
-
export const flow =
|
|
1
|
+
export const bind = (fn, self, ...args) => fn.bind(self, ...args)
|
|
2
|
+
export const partial = (fn, ...args) => bind(fn, {}, ...args)
|
|
3
|
+
export const flow =
|
|
4
|
+
(...args) =>
|
|
5
|
+
(x) => {
|
|
4
6
|
for (const fn of args) {
|
|
5
|
-
|
|
7
|
+
x = fn(x)
|
|
6
8
|
}
|
|
7
|
-
return x
|
|
8
|
-
}
|
|
9
|
-
export const pipe = flow
|
|
10
|
-
export const compose = (...args) => flow(args.reverse())
|
|
9
|
+
return x
|
|
10
|
+
}
|
|
11
|
+
export const pipe = flow
|
|
12
|
+
export const compose = (...args) => flow(args.reverse())
|
|
11
13
|
/**
|
|
12
14
|
* Creates a function that memoizes the result of `func`. If `resolver` is provided, it determines the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the map cache key.
|
|
13
15
|
*
|
|
14
|
-
*
|
|
16
|
+
*
|
|
15
17
|
* @param {Function} func The function to have its output memoized.
|
|
16
18
|
* @param {Function} [resolver] The function to resolve the cache key.
|
|
17
19
|
* @return {Function} Returns the new memoized function.
|
|
18
20
|
*/
|
|
19
21
|
export function memoize(func, resolver) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
22
|
+
const cache = new Map()
|
|
23
|
+
return (...args) => {
|
|
24
|
+
const key = resolver ? resolver(...args) : args[0]
|
|
25
|
+
const prev = cache.get(key)
|
|
26
|
+
if (prev !== undefined) return prev
|
|
27
|
+
const value = func(...args)
|
|
28
|
+
cache.set(key, value)
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
+
*
|
|
35
36
|
* @param {Function} func The function to debounce.
|
|
36
37
|
* @param {number} wait The number of milliseconds to delay.
|
|
37
38
|
* @param {{ maxWait: number }} { maxWait } The maximum time `func` is allowed to be delayed before it's invoked.
|
|
38
39
|
* @return {Function} Returns the new debounced function.
|
|
39
40
|
*/
|
|
40
41
|
export function debounce(func, wait, { maxWait }) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
42
|
+
let timer, maxTimer, lastResult
|
|
43
|
+
return (...args) => {
|
|
44
|
+
if (timer) clearTimeout(timer)
|
|
45
|
+
timer = setTimeout(() => {
|
|
46
|
+
clearTimeout(maxTimer)
|
|
47
|
+
maxTimer = null
|
|
48
|
+
lastResult = func(...args)
|
|
49
|
+
}, wait)
|
|
50
|
+
if (maxWait && !maxTimer) {
|
|
51
|
+
maxTimer = setTimeout(() => {
|
|
52
|
+
clearTimeout(timer)
|
|
53
|
+
maxTimer = null
|
|
54
|
+
lastResult = func(...args)
|
|
55
|
+
}, maxWait)
|
|
56
|
+
}
|
|
57
|
+
return lastResult
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds. Subsequent calls to the throttled function return the result of the last successful invocation.
|
|
62
62
|
*
|
|
63
|
-
*
|
|
63
|
+
*
|
|
64
64
|
* @param {Function} func The function to throttle.
|
|
65
65
|
* @param {number} time The number of milliseconds to throttle invocations to.
|
|
66
66
|
* @return {Function} Returns the new throttled function.
|
|
67
67
|
*/
|
|
68
68
|
export function throttle(func, time) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
69
|
+
let pending = false
|
|
70
|
+
return (...args) => {
|
|
71
|
+
if (pending) return
|
|
72
|
+
func(...args)
|
|
73
|
+
pending = true
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
pending = false
|
|
76
|
+
}, time)
|
|
77
|
+
}
|
|
79
78
|
}
|
package/src/functools.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FP
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
1
5
|
import { Function } from './globals.js'
|
|
2
6
|
|
|
3
7
|
export const bind = (fn, self, ...args) => fn.bind(self, ...args)
|
|
@@ -20,7 +24,7 @@ export const compose = (...args) => flow(args.reverse())
|
|
|
20
24
|
/**
|
|
21
25
|
* Creates a function that memoizes the result of `func`. If `resolver` is provided, it determines the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the map cache key.
|
|
22
26
|
*
|
|
23
|
-
*
|
|
27
|
+
*
|
|
24
28
|
* @param {Function} func The function to have its output memoized.
|
|
25
29
|
* @param {Function} [resolver] The function to resolve the cache key.
|
|
26
30
|
* @return {Function} Returns the new memoized function.
|
|
@@ -40,7 +44,7 @@ export function memoize(func: Function, resolver?: Function): Function {
|
|
|
40
44
|
/**
|
|
41
45
|
* Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
|
|
42
46
|
*
|
|
43
|
-
*
|
|
47
|
+
*
|
|
44
48
|
* @param {Function} func The function to debounce.
|
|
45
49
|
* @param {number} wait The number of milliseconds to delay.
|
|
46
50
|
* @param {{ maxWait: number }} { maxWait } The maximum time `func` is allowed to be delayed before it's invoked.
|
|
@@ -71,7 +75,7 @@ export function debounce(func: Function, wait: number, { maxWait }: { maxWait: n
|
|
|
71
75
|
/**
|
|
72
76
|
* Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds. Subsequent calls to the throttled function return the result of the last successful invocation.
|
|
73
77
|
*
|
|
74
|
-
*
|
|
78
|
+
*
|
|
75
79
|
* @param {Function} func The function to throttle.
|
|
76
80
|
* @param {number} time The number of milliseconds to throttle invocations to.
|
|
77
81
|
* @return {Function} Returns the new throttled function.
|
package/src/globals.d.ts
CHANGED
|
@@ -1,5 +1,179 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Globals
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
export declare type Comp = (x: any, y: any) => number;
|
|
6
|
+
export declare type Function = (...args: any[]) => any;
|
|
7
|
+
export declare type Iteratee = (value: any, key?: any, arr?: any) => any;
|
|
8
|
+
export declare const True: () => boolean;
|
|
9
|
+
export declare const False: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A custom error class that inherits from the Error object.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @class CustomError
|
|
15
|
+
* @extends {Error}
|
|
16
|
+
*/
|
|
17
|
+
export declare class CustomError extends Error {
|
|
18
|
+
/**
|
|
19
|
+
* Returns a new CustomError with the specified message.
|
|
20
|
+
* @param {string} message
|
|
21
|
+
* @constructor
|
|
22
|
+
*/
|
|
23
|
+
constructor(message?: string);
|
|
5
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Custom error to signal an invalid index access.
|
|
27
|
+
* @extends {CustomError}
|
|
28
|
+
*/
|
|
29
|
+
export declare class IndexError extends CustomError {
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Raised when a system function returns an I/O failure such as "file not found"
|
|
33
|
+
* or "disk full".
|
|
34
|
+
* @extends {CustomError}
|
|
35
|
+
*/
|
|
36
|
+
export declare class IOError extends CustomError {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Custom error to signal an invalid key access.
|
|
40
|
+
* @extends {CustomError}
|
|
41
|
+
*/
|
|
42
|
+
export declare class KeyError extends CustomError {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Custom error to signal an invalid operation.
|
|
46
|
+
* @extends {CustomError}
|
|
47
|
+
*/
|
|
48
|
+
export declare class NotImplementedError extends CustomError {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Custom error to signal an invalid value.
|
|
52
|
+
* @extends {CustomError}
|
|
53
|
+
*/
|
|
54
|
+
export declare class ValueError extends CustomError {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Raised when the second argument of a division or modulo operation is zero.
|
|
58
|
+
* @extends {CustomError}
|
|
59
|
+
*/
|
|
60
|
+
export declare class ZeroDivisionError extends CustomError {
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the true type of any value with correct detection for null, Array,
|
|
64
|
+
* Object, Promise, Symbol, and NaN.
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
* @param {*} value
|
|
68
|
+
* @return
|
|
69
|
+
*/
|
|
70
|
+
export declare function type(value: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "promise" | "null" | "NaN";
|
|
71
|
+
/** Same as `x.toString()`. Returns `''` when x is null or undefined */
|
|
72
|
+
export declare const str: (x: any) => any;
|
|
73
|
+
/** Check if value is a boolean type */
|
|
74
|
+
export declare const isBool: (x: any) => boolean;
|
|
75
|
+
/** Check if value is an object type */
|
|
76
|
+
export declare const isObject: (x: any) => boolean;
|
|
77
|
+
/** Check if value is a string type */
|
|
78
|
+
export declare const isString: (x: any) => boolean;
|
|
79
|
+
/** Check if value is an Array type */
|
|
80
|
+
export declare const isArray: (x: any) => boolean;
|
|
81
|
+
/** Check if value is Array-like type.
|
|
82
|
+
* A value is considered array-like if it's not a function and has a
|
|
83
|
+
* `.length` number property.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isArrayLike: (x: any) => boolean;
|
|
86
|
+
/** Check if value is a function type */
|
|
87
|
+
export declare const isFunc: (x: any) => boolean;
|
|
88
|
+
/** Check if value is a number type */
|
|
89
|
+
export declare const isNumber: (x: any) => boolean;
|
|
90
|
+
/** Check if value is a Bigint type */
|
|
91
|
+
export declare const isBigint: (x: any) => boolean;
|
|
92
|
+
/** Check if value is NaN based on `Number.isNaN` */
|
|
93
|
+
export declare const isNaN: (x: any) => boolean;
|
|
94
|
+
/** Check if value is a Promise type */
|
|
95
|
+
export declare const isPromise: (x: any) => boolean;
|
|
96
|
+
/** Check if value is an async function type */
|
|
97
|
+
export declare const isAsync: (x: any) => boolean;
|
|
98
|
+
/** Check if value is a generator function type */
|
|
99
|
+
export declare const isGenerator: (x: any) => boolean;
|
|
100
|
+
/** Check if value is null or undefined */
|
|
101
|
+
export declare const isNull: (x: any) => boolean;
|
|
102
|
+
/** Check if value is not null or undefined */
|
|
103
|
+
export declare const notNull: (x: any) => boolean;
|
|
104
|
+
export declare function len(x: any): any;
|
|
105
|
+
/** Returns true for objects without length or falsey values. */
|
|
106
|
+
export declare const isEmpty: (x: any) => boolean;
|
|
107
|
+
/** Check if value is a Symbol type */
|
|
108
|
+
export declare const isSymbol: (x: any) => boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Generates a unique ID using random numbers.
|
|
111
|
+
* If prefix is given, the ID is appended to it
|
|
112
|
+
*/
|
|
113
|
+
export declare const uniqueId: (pre?: string) => any;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if `obj.key` is a function, and calls it with any `args`.
|
|
116
|
+
*
|
|
117
|
+
*
|
|
118
|
+
* @param {*} obj
|
|
119
|
+
* @param {PropertyKey} key
|
|
120
|
+
* @param {...any[]} args
|
|
121
|
+
* @return `obj.key(...args)`
|
|
122
|
+
*/
|
|
123
|
+
export declare function call(obj: any, key: PropertyKey, ...args: any[]): any;
|
|
124
|
+
/** Convert number to unicode character */
|
|
125
|
+
export declare const chr: (x: number) => string;
|
|
126
|
+
/** Convert character to Unicode code point */
|
|
127
|
+
export declare const ord: (x: string) => number;
|
|
128
|
+
/** `Object.keys(x)` */
|
|
129
|
+
export declare const keys: (x: any) => string[];
|
|
130
|
+
/** `Object.values(x)` */
|
|
131
|
+
export declare const values: (x: any) => unknown[];
|
|
132
|
+
/**
|
|
133
|
+
* Round `x` to the number of digits after the decimal point. If `digits` is
|
|
134
|
+
* omitted, it returns the nearest integer to x.
|
|
135
|
+
*
|
|
136
|
+
* @param {number} x
|
|
137
|
+
* @param {number} [digits=0]
|
|
138
|
+
*/
|
|
139
|
+
export declare function round(x: number, digits?: number): number;
|
|
140
|
+
export declare const floor: (x: number) => number;
|
|
141
|
+
export declare const ceil: (x: number) => number;
|
|
142
|
+
/**
|
|
143
|
+
* Yields elements like `[index, item]` from an iterable.
|
|
144
|
+
*
|
|
145
|
+
*
|
|
146
|
+
* @template T
|
|
147
|
+
* @param {Iterable<T>} iterable
|
|
148
|
+
*/
|
|
149
|
+
export declare function enumerate<T = unknown>(iterable: Iterable<T>): Generator<(number | T)[], void, unknown>;
|
|
150
|
+
export declare const has: (obj: any, attr: PropertyKey) => any;
|
|
151
|
+
/**
|
|
152
|
+
* Check if the attribute is present in the object, or return optional default.
|
|
153
|
+
*
|
|
154
|
+
*
|
|
155
|
+
* @param {*} obj
|
|
156
|
+
* @param {PropertyKey} key
|
|
157
|
+
* @param {*} [value=undefined]
|
|
158
|
+
* @return The property value or default value
|
|
159
|
+
*/
|
|
160
|
+
export declare function get(obj: any, key: PropertyKey | PropertyKey[], value?: any): any;
|
|
161
|
+
export declare function del(x: any, attr: any): any;
|
|
162
|
+
export declare function set(self: any, attr: PropertyKey, value: any, writable?: boolean, enumerable?: boolean): any;
|
|
163
|
+
export declare const HASH_KEY: unique symbol;
|
|
164
|
+
export declare function hash(obj: any): any;
|
|
165
|
+
/**
|
|
166
|
+
* A hash value generator for strings
|
|
167
|
+
*
|
|
168
|
+
* @param {string} str
|
|
169
|
+
* @return {number}
|
|
170
|
+
* @see http://isthe.com/chongo/tech/comp/fnv/
|
|
171
|
+
*/
|
|
172
|
+
export declare function hashCode(str: string): number;
|
|
173
|
+
export declare const bin: (n: number) => string;
|
|
174
|
+
export declare const hex: (n: number) => string;
|
|
175
|
+
export declare const oct: (n: number) => string;
|
|
176
|
+
export declare const float: (x: any) => number;
|
|
177
|
+
export declare const int: (x: any, base?: number) => number;
|
|
178
|
+
export declare const list: (arr?: any) => unknown[];
|
|
179
|
+
export declare const next: (iter: Iterator<unknown>) => any;
|