atomic-fns 1.2.0 → 2.0.0
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/README.md +397 -91
- package/dist/array/index.d.ts +9 -0
- package/dist/array/index.js +9 -0
- package/dist/array/list.d.ts +99 -0
- package/dist/array/list.js +133 -0
- package/dist/array/sets.d.ts +130 -0
- package/dist/array/sets.js +213 -0
- package/dist/async/index.d.ts +6 -0
- package/dist/async/index.js +6 -0
- package/dist/async/retry.d.ts +38 -0
- package/dist/async/retry.js +56 -0
- package/dist/async/sleep.d.ts +42 -0
- package/dist/async/sleep.js +76 -0
- package/dist/collections/bisect.d.ts +103 -0
- package/dist/collections/bisect.js +157 -0
- package/dist/collections/deque.d.ts +67 -97
- package/dist/collections/deque.js +197 -256
- package/dist/collections/entries.d.ts +89 -0
- package/dist/collections/entries.js +131 -0
- package/dist/collections/frozen-set.d.ts +42 -0
- package/dist/collections/frozen-set.js +64 -0
- package/dist/collections/group.d.ts +141 -0
- package/dist/collections/group.js +241 -0
- package/dist/collections/heap.d.ts +64 -0
- package/dist/collections/heap.js +205 -0
- package/dist/collections/index.d.ts +15 -623
- package/dist/collections/index.js +14 -844
- package/dist/collections/internal/arrayKeys.d.ts +19 -0
- package/dist/collections/internal/arrayKeys.js +83 -0
- package/dist/collections/internal/invariants.d.ts +4 -0
- package/dist/collections/internal/invariants.js +12 -0
- package/dist/collections/internal/iterable.d.ts +25 -0
- package/dist/collections/internal/iterable.js +62 -0
- package/dist/collections/iterate.d.ts +162 -0
- package/dist/collections/iterate.js +188 -0
- package/dist/collections/lru-cache.d.ts +58 -0
- package/dist/collections/lru-cache.js +164 -0
- package/dist/collections/order.d.ts +19 -0
- package/dist/collections/order.js +38 -0
- package/dist/collections/shape.d.ts +32 -0
- package/dist/collections/shape.js +86 -0
- package/dist/collections/sorted-map.d.ts +171 -0
- package/dist/collections/sorted-map.js +845 -0
- package/dist/collections/sorted-set.d.ts +103 -0
- package/dist/collections/sorted-set.js +147 -0
- package/dist/collections/splay-tree.d.ts +82 -0
- package/dist/collections/splay-tree.js +354 -0
- package/dist/collections/trie.d.ts +58 -0
- package/dist/collections/trie.js +196 -0
- package/dist/decimal/currency.d.ts +211 -0
- package/dist/decimal/currency.js +321 -0
- package/dist/decimal/decimal.d.ts +299 -0
- package/dist/decimal/decimal.js +660 -0
- package/dist/decimal/index.d.ts +11 -148
- package/dist/decimal/index.js +10 -410
- package/dist/decimal/internal/bits.d.ts +2 -0
- package/dist/decimal/internal/bits.js +7 -0
- package/dist/decimal/internal/echo.d.ts +4 -0
- package/dist/decimal/internal/echo.js +6 -0
- package/dist/decimal/internal/isqrt.d.ts +9 -0
- package/dist/decimal/internal/isqrt.js +34 -0
- package/dist/decimal/internal/locale.d.ts +7 -0
- package/dist/decimal/internal/locale.js +24 -0
- package/dist/decimal/internal/minor-units.d.ts +2 -0
- package/dist/decimal/internal/minor-units.js +33 -0
- package/dist/decimal/internal/pow10.d.ts +24 -0
- package/dist/decimal/internal/pow10.js +96 -0
- package/dist/encoding/base64.d.ts +39 -0
- package/dist/encoding/base64.js +53 -0
- package/dist/encoding/hex.d.ts +23 -0
- package/dist/encoding/hex.js +34 -0
- package/dist/encoding/index.d.ts +6 -0
- package/dist/encoding/index.js +6 -0
- package/dist/function/debounce.d.ts +68 -0
- package/dist/function/debounce.js +203 -0
- package/dist/function/index.d.ts +6 -0
- package/dist/function/index.js +6 -0
- package/dist/function/shared.d.ts +2 -0
- package/dist/function/shared.js +5 -0
- package/dist/function/wrap.d.ts +130 -0
- package/dist/function/wrap.js +113 -0
- package/dist/hash/digest.d.ts +18 -0
- package/dist/hash/digest.js +26 -0
- package/dist/hash/hash.d.ts +22 -0
- package/dist/hash/hash.js +252 -0
- package/dist/hash/hashString.d.ts +13 -0
- package/dist/hash/hashString.js +53 -0
- package/dist/hash/index.d.ts +8 -0
- package/dist/hash/index.js +8 -0
- package/dist/hash/stableStringify.d.ts +19 -0
- package/dist/hash/stableStringify.js +102 -0
- package/dist/id/index.d.ts +7 -0
- package/dist/id/index.js +7 -0
- package/dist/id/nanoid.d.ts +16 -0
- package/dist/id/nanoid.js +65 -0
- package/dist/id/uniqueId.d.ts +14 -0
- package/dist/id/uniqueId.js +20 -0
- package/dist/id/uuid.d.ts +25 -0
- package/dist/id/uuid.js +64 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.js +15 -8
- package/dist/internal/bytes.d.ts +11 -0
- package/dist/internal/bytes.js +33 -0
- package/dist/internal/codec.d.ts +11 -0
- package/dist/internal/codec.js +84 -0
- package/dist/internal/compare.d.ts +10 -0
- package/dist/internal/compare.js +26 -0
- package/dist/internal/crypto.d.ts +5 -0
- package/dist/internal/crypto.js +11 -0
- package/dist/internal/keys.d.ts +12 -0
- package/dist/internal/keys.js +23 -0
- package/dist/internal/kind.d.ts +44 -0
- package/dist/internal/kind.js +139 -0
- package/dist/internal/sparse.d.ts +51 -0
- package/dist/internal/sparse.js +104 -0
- package/dist/internal/text.d.ts +7 -0
- package/dist/internal/text.js +15 -0
- package/dist/internal/timer.d.ts +10 -0
- package/dist/internal/timer.js +17 -0
- package/dist/internal/truncate.d.ts +10 -0
- package/dist/internal/truncate.js +22 -0
- package/dist/internal/walk.d.ts +47 -0
- package/dist/internal/walk.js +100 -0
- package/dist/is/index.d.ts +8 -0
- package/dist/is/index.js +8 -0
- package/dist/is/isArrayLike.d.ts +18 -0
- package/dist/is/isArrayLike.js +25 -0
- package/dist/is/isError.d.ts +13 -0
- package/dist/is/isError.js +18 -0
- package/dist/is/isNil.d.ts +12 -0
- package/dist/is/isNil.js +14 -0
- package/dist/is/isPlainObject.d.ts +15 -0
- package/dist/is/isPlainObject.js +34 -0
- package/dist/number/index.d.ts +7 -0
- package/dist/number/index.js +7 -0
- package/dist/number/round.d.ts +86 -0
- package/dist/number/round.js +130 -0
- package/dist/number/stats.d.ts +52 -0
- package/dist/number/stats.js +115 -0
- package/dist/object/cloneDeep.d.ts +28 -0
- package/dist/object/cloneDeep.js +200 -0
- package/dist/object/index.d.ts +14 -0
- package/dist/object/index.js +13 -0
- package/dist/object/isEqual.d.ts +64 -0
- package/dist/object/isEqual.js +289 -0
- package/dist/object/matches.d.ts +40 -0
- package/dist/object/matches.js +284 -0
- package/dist/object/merge.d.ts +66 -0
- package/dist/object/merge.js +272 -0
- package/dist/object/parsePath.d.ts +22 -0
- package/dist/object/parsePath.js +111 -0
- package/dist/object/path.d.ts +85 -0
- package/dist/object/path.js +208 -0
- package/dist/object/pick.d.ts +91 -0
- package/dist/object/pick.js +180 -0
- package/dist/object/reshape.d.ts +73 -0
- package/dist/object/reshape.js +144 -0
- package/dist/random/index.d.ts +96 -32
- package/dist/random/index.js +215 -53
- package/dist/string/case.d.ts +71 -0
- package/dist/string/case.js +152 -0
- package/dist/string/fold.d.ts +35 -0
- package/dist/string/fold.js +100 -0
- package/dist/string/index.d.ts +6 -187
- package/dist/string/index.js +6 -224
- package/dist/string/truncate.d.ts +25 -0
- package/dist/string/truncate.js +44 -0
- package/dist/string/words.d.ts +27 -0
- package/dist/string/words.js +241 -0
- package/package.json +99 -51
- package/dist/collections/BTree.d.ts +0 -230
- package/dist/collections/BTree.js +0 -1143
- package/dist/collections/Heap.d.ts +0 -69
- package/dist/collections/Heap.js +0 -181
- package/dist/collections/LRUCache.d.ts +0 -83
- package/dist/collections/LRUCache.js +0 -139
- package/dist/collections/SortedMap.d.ts +0 -92
- package/dist/collections/SortedMap.js +0 -131
- package/dist/collections/SortedSet.d.ts +0 -69
- package/dist/collections/SortedSet.js +0 -99
- package/dist/collections/SortedTree.d.ts +0 -103
- package/dist/collections/SortedTree.js +0 -142
- package/dist/collections/SplayTree.d.ts +0 -107
- package/dist/collections/SplayTree.js +0 -351
- package/dist/collections/Trie.d.ts +0 -42
- package/dist/collections/Trie.js +0 -104
- package/dist/collections/abc.d.ts +0 -152
- package/dist/collections/abc.js +0 -39
- package/dist/collections/frozenset.d.ts +0 -19
- package/dist/collections/frozenset.js +0 -33
- package/dist/functools/index.d.ts +0 -106
- package/dist/functools/index.js +0 -203
- package/dist/globals/index.d.ts +0 -268
- package/dist/globals/index.js +0 -447
- package/dist/i18n/currency.d.ts +0 -27
- package/dist/i18n/currency.js +0 -100
- package/dist/i18n/date/index.d.ts +0 -210
- package/dist/i18n/date/index.js +0 -552
- package/dist/i18n/date/utils.d.ts +0 -64
- package/dist/i18n/date/utils.js +0 -192
- package/dist/i18n/duration.d.ts +0 -113
- package/dist/i18n/duration.js +0 -398
- package/dist/i18n/format.d.ts +0 -34
- package/dist/i18n/format.js +0 -378
- package/dist/i18n/index.d.ts +0 -9
- package/dist/i18n/index.js +0 -8
- package/dist/itertools/index.d.ts +0 -251
- package/dist/itertools/index.js +0 -434
- package/dist/math/index.d.ts +0 -79
- package/dist/math/index.js +0 -81
- package/dist/mod.d.ts +0 -1
- package/dist/mod.js +0 -1
- package/dist/operators/index.d.ts +0 -148
- package/dist/operators/index.js +0 -325
- package/dist/types.d.ts +0 -19
- package/dist/types.js +0 -1
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic operations for both values and objects.
|
|
3
|
-
*
|
|
4
|
-
* @module operators
|
|
5
|
-
*/
|
|
6
|
-
/** This is the identity function. It always returns the same value that was passed in. */
|
|
7
|
-
export declare const identity: <T>(x: T) => T;
|
|
8
|
-
/**
|
|
9
|
-
* Called to implement truth value testing.
|
|
10
|
-
* @param x
|
|
11
|
-
* @returns {boolean} `x.bool()` if exists or `!!x`.
|
|
12
|
-
*/
|
|
13
|
-
export declare function bool(x: any): any;
|
|
14
|
-
/**
|
|
15
|
-
* Returns `true` if `x` is a falsy value.
|
|
16
|
-
* @see {@link bool}
|
|
17
|
-
*/
|
|
18
|
-
export declare function not(x: any): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Returns `true` if `x` is an instance of class `y`
|
|
21
|
-
* @param x The instance object
|
|
22
|
-
* @param y The parent class
|
|
23
|
-
* @returns {boolean}
|
|
24
|
-
*/
|
|
25
|
-
export declare function isinstance(x: any, y: any): boolean;
|
|
26
|
-
/** Describes a function used to compare two values.
|
|
27
|
-
*
|
|
28
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
|
|
29
|
-
*/
|
|
30
|
-
export type Comparer<T = any> = (x: T, y: T) => number;
|
|
31
|
-
/**
|
|
32
|
-
* Checks whether `x` is a comparable type and returns the result of `x.compare(y)`.
|
|
33
|
-
* Otherwise the return value of the compare function is equivalent to `obj === other ? 0 : obj < other ? -1 : 1`
|
|
34
|
-
* @param {*} x An initial value
|
|
35
|
-
* @param {*} y Other value to compare
|
|
36
|
-
* @returns {number} The comparison result
|
|
37
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
|
|
38
|
-
* @see {@link operators.eq}
|
|
39
|
-
* @see {@link operators.lt}
|
|
40
|
-
*/
|
|
41
|
-
export declare function compare(x: any, y: any): number;
|
|
42
|
-
/**
|
|
43
|
-
* Compares two values to check if they are the same. If `x` is an object with an `eq` method, it returns `x.eq(y)`.
|
|
44
|
-
* Otherwise it returns the result of `x === y`.
|
|
45
|
-
* @param {*} x
|
|
46
|
-
* @param {*} y
|
|
47
|
-
* @returns {boolean} `true` if `x` and `y` are equal or `false` otherwise.
|
|
48
|
-
*/
|
|
49
|
-
export declare function eq(x: any, y: any): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Compares two values to check if `x` is strictly less than `y`. If `x` is an object with a `lt` method, it returns `x.lt(y)`.
|
|
52
|
-
* Otherwise it returns the result of `x < y`.
|
|
53
|
-
* @param {*} x
|
|
54
|
-
* @param {*} y
|
|
55
|
-
* @returns {boolean} `true` if `x` is strictly less than `y` or `false` otherwise.
|
|
56
|
-
*/
|
|
57
|
-
export declare function lt(x: any, y: any): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Compares two values to check if `x <= y`. If `x` is an object with a `lte` method, it returns `x.lte(y)`, also checks `x.eq(y)` and `x.lt(y)`.
|
|
60
|
-
* Otherwise it returns the result of `x <= y`.
|
|
61
|
-
* @param {*} x
|
|
62
|
-
* @param {*} y
|
|
63
|
-
* @returns {boolean} `true` if `x` is less than or equal to `y` or `false` otherwise.
|
|
64
|
-
* @see {@link eq}
|
|
65
|
-
* @see {@link lt}
|
|
66
|
-
*/
|
|
67
|
-
export declare function lte(x: any, y: any): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Compares two values to check if `x` is strictly greater than `y`. If `x` is an object with a `gt` method, it returns `x.gt(y)`.
|
|
70
|
-
* Otherwise it returns the result of `x > y`.
|
|
71
|
-
* @param {*} x
|
|
72
|
-
* @param {*} y
|
|
73
|
-
* @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
|
|
74
|
-
*/
|
|
75
|
-
export declare function gt(x: any, y: any): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Compares two values to check if `x >= y`. If `x` is an object with a `gte` method, it returns `x.gte(y)`, also checks `x.eq(y)` and `x.gt(y)`.
|
|
78
|
-
* Otherwise it returns the result of `x >= y`.
|
|
79
|
-
* @param {*} x
|
|
80
|
-
* @param {*} y
|
|
81
|
-
* @returns {boolean} `true` if `x` is less greater than or equal to `y` or `false` otherwise.
|
|
82
|
-
* @see {@link eq}
|
|
83
|
-
* @see {@link gt}
|
|
84
|
-
*/
|
|
85
|
-
export declare function gte(x: any, y: any): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* The addition (+) operator. If `x` is an object with an `add` method, it returns `x.add(y)`.
|
|
88
|
-
* Otherwise it returns the result of `x + y`.
|
|
89
|
-
* @param {*} x
|
|
90
|
-
* @param {*} y
|
|
91
|
-
* @returns {*} x + y
|
|
92
|
-
*/
|
|
93
|
-
export declare function add(x: any, y: any): any;
|
|
94
|
-
/**
|
|
95
|
-
* The subtraction (-) operator. If `x` is an object with a `sub` method, it returns `x.sub(y)`.
|
|
96
|
-
* Otherwise it returns the result of `x - y`.
|
|
97
|
-
* @param {*} x
|
|
98
|
-
* @param {*} y
|
|
99
|
-
* @returns {*} x - y
|
|
100
|
-
*/
|
|
101
|
-
export declare function sub(x: any, y: any): any;
|
|
102
|
-
/**
|
|
103
|
-
* The multiplication (*) operator. If `x` is an object with an `mul` method, it returns `x.mul(y)`.
|
|
104
|
-
* Otherwise it returns the result of `x * y`.
|
|
105
|
-
* @param {*} x
|
|
106
|
-
* @param {*} y
|
|
107
|
-
* @returns {*} x * y
|
|
108
|
-
*/
|
|
109
|
-
export declare function mul(x: any, y: any): any;
|
|
110
|
-
/**
|
|
111
|
-
* The division (/) operator. If `x` is an object with a `div` method, it returns `x.div(y)`.
|
|
112
|
-
* Otherwise it returns the result of `x / y`.
|
|
113
|
-
* @param {*} x
|
|
114
|
-
* @param {*} y
|
|
115
|
-
* @returns {*} x / y
|
|
116
|
-
*/
|
|
117
|
-
export declare function div(x: any, y: any): any;
|
|
118
|
-
/**
|
|
119
|
-
* The modulo (%) operator. If `x` is an object with a `mod` method, it returns `x.mod(y)`.
|
|
120
|
-
* Otherwise it returns the result of `x % y`.
|
|
121
|
-
* @param {*} x
|
|
122
|
-
* @param {*} y
|
|
123
|
-
* @returns {*} x % y
|
|
124
|
-
*/
|
|
125
|
-
export declare function mod(x: any, y: any): any;
|
|
126
|
-
/**
|
|
127
|
-
* The power (**) operator. If `x` is an object with a `pow` method, it returns `x.pow(y)`.
|
|
128
|
-
* Otherwise it returns the result of `x ** y`.
|
|
129
|
-
* @param {*} x
|
|
130
|
-
* @param {*} y
|
|
131
|
-
* @returns {*} x ** y
|
|
132
|
-
*/
|
|
133
|
-
export declare function pow(x: any, y: any): any;
|
|
134
|
-
/**
|
|
135
|
-
* Performs a shallow comparison of two objects or arrays to check if they have the same keys, length and values.
|
|
136
|
-
* @param obj
|
|
137
|
-
* @param other
|
|
138
|
-
* @returns `true` if the objects are considered equal.
|
|
139
|
-
* @see {@link deepEqual}
|
|
140
|
-
*/
|
|
141
|
-
export declare function shallowEqual(obj: any, other: any): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Performs a recursive comparison of two objects or arrays to check if they have the same keys, length and values. Unlike {@link shallowEqual} this method compares nested values also.
|
|
144
|
-
* @param obj
|
|
145
|
-
* @param other
|
|
146
|
-
* @returns `true` if the objects are considered equal.
|
|
147
|
-
*/
|
|
148
|
-
export declare function deepEqual(obj: any, other: any, checker?: Function, seen?: any): boolean;
|
package/dist/operators/index.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic operations for both values and objects.
|
|
3
|
-
*
|
|
4
|
-
* @module operators
|
|
5
|
-
*/
|
|
6
|
-
import { call, isObject } from '../globals/index.js';
|
|
7
|
-
/** This is the identity function. It always returns the same value that was passed in. */
|
|
8
|
-
export const identity = (x) => x;
|
|
9
|
-
/**
|
|
10
|
-
* Called to implement truth value testing.
|
|
11
|
-
* @param x
|
|
12
|
-
* @returns {boolean} `x.bool()` if exists or `!!x`.
|
|
13
|
-
*/
|
|
14
|
-
export function bool(x) {
|
|
15
|
-
const r = call(x, 'bool');
|
|
16
|
-
if (r != null)
|
|
17
|
-
return r;
|
|
18
|
-
return !!x;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns `true` if `x` is a falsy value.
|
|
22
|
-
* @see {@link bool}
|
|
23
|
-
*/
|
|
24
|
-
export function not(x) {
|
|
25
|
-
return !bool(x);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns `true` if `x` is an instance of class `y`
|
|
29
|
-
* @param x The instance object
|
|
30
|
-
* @param y The parent class
|
|
31
|
-
* @returns {boolean}
|
|
32
|
-
*/
|
|
33
|
-
export function isinstance(x, y) {
|
|
34
|
-
return x instanceof y;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Checks whether `x` is a comparable type and returns the result of `x.compare(y)`.
|
|
38
|
-
* Otherwise the return value of the compare function is equivalent to `obj === other ? 0 : obj < other ? -1 : 1`
|
|
39
|
-
* @param {*} x An initial value
|
|
40
|
-
* @param {*} y Other value to compare
|
|
41
|
-
* @returns {number} The comparison result
|
|
42
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
|
|
43
|
-
* @see {@link operators.eq}
|
|
44
|
-
* @see {@link operators.lt}
|
|
45
|
-
*/
|
|
46
|
-
export function compare(x, y) {
|
|
47
|
-
if (x === y || eq(x, y))
|
|
48
|
-
return 0;
|
|
49
|
-
const op = call(x, 'compare', y);
|
|
50
|
-
if (typeof op === 'number')
|
|
51
|
-
return op;
|
|
52
|
-
if (x instanceof Date && y instanceof Date)
|
|
53
|
-
return Math.sign(x.getTime() - y.getTime()) || 0;
|
|
54
|
-
if (lt(x, y))
|
|
55
|
-
return -1;
|
|
56
|
-
return 1;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Compares two values to check if they are the same. If `x` is an object with an `eq` method, it returns `x.eq(y)`.
|
|
60
|
-
* Otherwise it returns the result of `x === y`.
|
|
61
|
-
* @param {*} x
|
|
62
|
-
* @param {*} y
|
|
63
|
-
* @returns {boolean} `true` if `x` and `y` are equal or `false` otherwise.
|
|
64
|
-
*/
|
|
65
|
-
export function eq(x, y) {
|
|
66
|
-
return x === y || Object.is(x, y) || !!call(x, 'eq', y);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Compares two values to check if `x` is strictly less than `y`. If `x` is an object with a `lt` method, it returns `x.lt(y)`.
|
|
70
|
-
* Otherwise it returns the result of `x < y`.
|
|
71
|
-
* @param {*} x
|
|
72
|
-
* @param {*} y
|
|
73
|
-
* @returns {boolean} `true` if `x` is strictly less than `y` or `false` otherwise.
|
|
74
|
-
*/
|
|
75
|
-
export function lt(x, y) {
|
|
76
|
-
const op = call(x, 'lt', y);
|
|
77
|
-
return op != null ? !!op : x < y;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Compares two values to check if `x <= y`. If `x` is an object with a `lte` method, it returns `x.lte(y)`, also checks `x.eq(y)` and `x.lt(y)`.
|
|
81
|
-
* Otherwise it returns the result of `x <= y`.
|
|
82
|
-
* @param {*} x
|
|
83
|
-
* @param {*} y
|
|
84
|
-
* @returns {boolean} `true` if `x` is less than or equal to `y` or `false` otherwise.
|
|
85
|
-
* @see {@link eq}
|
|
86
|
-
* @see {@link lt}
|
|
87
|
-
*/
|
|
88
|
-
export function lte(x, y) {
|
|
89
|
-
const op = call(x, 'lte', y);
|
|
90
|
-
if (op != null)
|
|
91
|
-
return !!op;
|
|
92
|
-
const less = call(x, 'lt', y);
|
|
93
|
-
if (less != null)
|
|
94
|
-
return !!less || eq(x, y) || (call(y, 'lt', x) === false && x <= y);
|
|
95
|
-
return x <= y || eq(x, y);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Compares two values to check if `x` is strictly greater than `y`. If `x` is an object with a `gt` method, it returns `x.gt(y)`.
|
|
99
|
-
* Otherwise it returns the result of `x > y`.
|
|
100
|
-
* @param {*} x
|
|
101
|
-
* @param {*} y
|
|
102
|
-
* @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
|
|
103
|
-
*/
|
|
104
|
-
export function gt(x, y) {
|
|
105
|
-
const op = call(x, 'gt', y);
|
|
106
|
-
return op != null ? !!op : x > y;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Compares two values to check if `x >= y`. If `x` is an object with a `gte` method, it returns `x.gte(y)`, also checks `x.eq(y)` and `x.gt(y)`.
|
|
110
|
-
* Otherwise it returns the result of `x >= y`.
|
|
111
|
-
* @param {*} x
|
|
112
|
-
* @param {*} y
|
|
113
|
-
* @returns {boolean} `true` if `x` is less greater than or equal to `y` or `false` otherwise.
|
|
114
|
-
* @see {@link eq}
|
|
115
|
-
* @see {@link gt}
|
|
116
|
-
*/
|
|
117
|
-
export function gte(x, y) {
|
|
118
|
-
const op = call(x, 'gte', y);
|
|
119
|
-
if (op != null)
|
|
120
|
-
return !!op;
|
|
121
|
-
const greater = call(x, 'gt', y);
|
|
122
|
-
if (greater != null)
|
|
123
|
-
return !!greater || eq(x, y) || (call(y, 'gt', x) === false && x >= y);
|
|
124
|
-
return x >= y || eq(x, y);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* The addition (+) operator. If `x` is an object with an `add` method, it returns `x.add(y)`.
|
|
128
|
-
* Otherwise it returns the result of `x + y`.
|
|
129
|
-
* @param {*} x
|
|
130
|
-
* @param {*} y
|
|
131
|
-
* @returns {*} x + y
|
|
132
|
-
*/
|
|
133
|
-
export function add(x, y) {
|
|
134
|
-
const op = call(x, 'add', y);
|
|
135
|
-
if (op != null)
|
|
136
|
-
return op;
|
|
137
|
-
return x + y;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* The subtraction (-) operator. If `x` is an object with a `sub` method, it returns `x.sub(y)`.
|
|
141
|
-
* Otherwise it returns the result of `x - y`.
|
|
142
|
-
* @param {*} x
|
|
143
|
-
* @param {*} y
|
|
144
|
-
* @returns {*} x - y
|
|
145
|
-
*/
|
|
146
|
-
export function sub(x, y) {
|
|
147
|
-
const op = call(x, 'sub', y);
|
|
148
|
-
if (op != null)
|
|
149
|
-
return op;
|
|
150
|
-
return x - y;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The multiplication (*) operator. If `x` is an object with an `mul` method, it returns `x.mul(y)`.
|
|
154
|
-
* Otherwise it returns the result of `x * y`.
|
|
155
|
-
* @param {*} x
|
|
156
|
-
* @param {*} y
|
|
157
|
-
* @returns {*} x * y
|
|
158
|
-
*/
|
|
159
|
-
export function mul(x, y) {
|
|
160
|
-
const op = call(x, 'mul', y);
|
|
161
|
-
if (op != null)
|
|
162
|
-
return op;
|
|
163
|
-
return x * y;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* The division (/) operator. If `x` is an object with a `div` method, it returns `x.div(y)`.
|
|
167
|
-
* Otherwise it returns the result of `x / y`.
|
|
168
|
-
* @param {*} x
|
|
169
|
-
* @param {*} y
|
|
170
|
-
* @returns {*} x / y
|
|
171
|
-
*/
|
|
172
|
-
export function div(x, y) {
|
|
173
|
-
const op = call(x, 'div', y);
|
|
174
|
-
if (op != null)
|
|
175
|
-
return op;
|
|
176
|
-
return x / y;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* The modulo (%) operator. If `x` is an object with a `mod` method, it returns `x.mod(y)`.
|
|
180
|
-
* Otherwise it returns the result of `x % y`.
|
|
181
|
-
* @param {*} x
|
|
182
|
-
* @param {*} y
|
|
183
|
-
* @returns {*} x % y
|
|
184
|
-
*/
|
|
185
|
-
export function mod(x, y) {
|
|
186
|
-
const op = call(x, 'mod', y);
|
|
187
|
-
if (op != null)
|
|
188
|
-
return op;
|
|
189
|
-
return x % y;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* The power (**) operator. If `x` is an object with a `pow` method, it returns `x.pow(y)`.
|
|
193
|
-
* Otherwise it returns the result of `x ** y`.
|
|
194
|
-
* @param {*} x
|
|
195
|
-
* @param {*} y
|
|
196
|
-
* @returns {*} x ** y
|
|
197
|
-
*/
|
|
198
|
-
export function pow(x, y) {
|
|
199
|
-
const op = call(x, 'pow', y);
|
|
200
|
-
if (op != null)
|
|
201
|
-
return op;
|
|
202
|
-
return x ** y;
|
|
203
|
-
}
|
|
204
|
-
/** Class names tell kinds apart across realms, where prototypes differ. */
|
|
205
|
-
function sameKind(x, y) {
|
|
206
|
-
if (!x || !y || typeof x !== 'object' || typeof y !== 'object')
|
|
207
|
-
return false;
|
|
208
|
-
const tag = Object.prototype.toString;
|
|
209
|
-
if (tag.call(x) !== tag.call(y))
|
|
210
|
-
return false;
|
|
211
|
-
return (x.constructor?.name ?? 'Object') === (y.constructor?.name ?? 'Object');
|
|
212
|
-
}
|
|
213
|
-
function isList(x) {
|
|
214
|
-
return Array.isArray(x) || (ArrayBuffer.isView(x) && !(x instanceof DataView));
|
|
215
|
-
}
|
|
216
|
-
function isDateOrRegExp(x) {
|
|
217
|
-
return x instanceof Date || x instanceof RegExp;
|
|
218
|
-
}
|
|
219
|
-
function sameDateOrRegExp(x, y) {
|
|
220
|
-
if (x instanceof Date)
|
|
221
|
-
return Object.is(x.getTime(), y.getTime());
|
|
222
|
-
return String(x) === String(y);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Performs a shallow comparison of two objects or arrays to check if they have the same keys, length and values.
|
|
226
|
-
* @param obj
|
|
227
|
-
* @param other
|
|
228
|
-
* @returns `true` if the objects are considered equal.
|
|
229
|
-
* @see {@link deepEqual}
|
|
230
|
-
*/
|
|
231
|
-
export function shallowEqual(obj, other) {
|
|
232
|
-
if (obj === other)
|
|
233
|
-
return true;
|
|
234
|
-
if (!sameKind(obj, other))
|
|
235
|
-
return false;
|
|
236
|
-
if (isDateOrRegExp(obj))
|
|
237
|
-
return sameDateOrRegExp(obj, other);
|
|
238
|
-
if (Array.isArray(obj)) {
|
|
239
|
-
// compare the arrays
|
|
240
|
-
if (obj.length !== other.length)
|
|
241
|
-
return false;
|
|
242
|
-
for (let i = 0; i < obj.length; i++) {
|
|
243
|
-
if (obj[i] !== other[i]) {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
else if (isObject(obj)) {
|
|
250
|
-
// compare the object keys
|
|
251
|
-
const objKeys = Object.keys(obj);
|
|
252
|
-
const otherKeys = Object.keys(other);
|
|
253
|
-
if (objKeys.length !== otherKeys.length)
|
|
254
|
-
return false;
|
|
255
|
-
for (const key of objKeys) {
|
|
256
|
-
if (!Object.hasOwn(other, key) || obj[key] !== other[key]) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
export function deepEqual(obj, other, checker = eq, seen = new WeakMap()) {
|
|
265
|
-
if (!(seen instanceof WeakMap))
|
|
266
|
-
seen = new WeakMap();
|
|
267
|
-
if (checker(obj, other))
|
|
268
|
-
return true;
|
|
269
|
-
if (!sameKind(obj, other))
|
|
270
|
-
return false;
|
|
271
|
-
if (isDateOrRegExp(obj))
|
|
272
|
-
return sameDateOrRegExp(obj, other);
|
|
273
|
-
// A pair that was compared before needs no second walk: it either held, or the call has returned.
|
|
274
|
-
const partners = seen.get(obj) ?? new WeakSet();
|
|
275
|
-
if (partners.has(other))
|
|
276
|
-
return true;
|
|
277
|
-
seen.set(obj, partners.add(other));
|
|
278
|
-
if (isList(obj)) {
|
|
279
|
-
// compare the arrays
|
|
280
|
-
if (obj.length !== other.length)
|
|
281
|
-
return false;
|
|
282
|
-
for (let i = 0; i < obj.length; i++) {
|
|
283
|
-
if (!deepEqual(obj[i], other[i], checker, seen)) {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
if (obj instanceof Set) {
|
|
290
|
-
if (obj.size !== other.size)
|
|
291
|
-
return false;
|
|
292
|
-
for (const value of obj.values()) {
|
|
293
|
-
if (!other.has(value))
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
if (obj instanceof Map) {
|
|
299
|
-
// compare keys and values
|
|
300
|
-
if (obj.size !== other.size)
|
|
301
|
-
return false;
|
|
302
|
-
for (const key of obj.keys()) {
|
|
303
|
-
if (!other.has(key))
|
|
304
|
-
return false;
|
|
305
|
-
if (!deepEqual(obj.get(key), other.get(key), checker, seen)) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
if (isObject(obj)) {
|
|
312
|
-
// compare the object own enumerable keys
|
|
313
|
-
const objKeys = Object.keys(obj);
|
|
314
|
-
const otherKeys = Object.keys(other);
|
|
315
|
-
if (objKeys.length !== otherKeys.length)
|
|
316
|
-
return false;
|
|
317
|
-
for (const key of objKeys) {
|
|
318
|
-
if (!Object.hasOwn(other, key) || !deepEqual(obj[key], other[key], checker, seen)) {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return true;
|
|
323
|
-
}
|
|
324
|
-
return false;
|
|
325
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A generic function type with arbitrary arguments and return.
|
|
3
|
-
*/
|
|
4
|
-
export type Function<TReturn = any> = (...args: any) => TReturn;
|
|
5
|
-
/**
|
|
6
|
-
* An iteratee function used for collection methods.
|
|
7
|
-
* @see {@link collections.filter}
|
|
8
|
-
* @see {@link collections.find}
|
|
9
|
-
* @see {@link collections.forEach}
|
|
10
|
-
* @see {@link collections.index}
|
|
11
|
-
* @see {@link collections.map}
|
|
12
|
-
* @see {@link collections.pick}
|
|
13
|
-
* @see {@link collections.omit}
|
|
14
|
-
* @see {@link collections.uniq}
|
|
15
|
-
* @see {@link collections.sortedUniq}
|
|
16
|
-
* @see {@link collections.groupBy}
|
|
17
|
-
*/
|
|
18
|
-
export type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
|
|
19
|
-
export type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|