atomic-fns 1.1.7 → 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.
Files changed (216) hide show
  1. package/README.md +405 -60
  2. package/dist/array/index.d.ts +9 -0
  3. package/dist/array/index.js +9 -0
  4. package/dist/array/list.d.ts +99 -0
  5. package/dist/array/list.js +133 -0
  6. package/dist/array/sets.d.ts +130 -0
  7. package/dist/array/sets.js +213 -0
  8. package/dist/async/index.d.ts +6 -0
  9. package/dist/async/index.js +6 -0
  10. package/dist/async/retry.d.ts +38 -0
  11. package/dist/async/retry.js +56 -0
  12. package/dist/async/sleep.d.ts +42 -0
  13. package/dist/async/sleep.js +76 -0
  14. package/dist/collections/bisect.d.ts +103 -0
  15. package/dist/collections/bisect.js +157 -0
  16. package/dist/collections/deque.d.ts +67 -97
  17. package/dist/collections/deque.js +197 -249
  18. package/dist/collections/entries.d.ts +89 -0
  19. package/dist/collections/entries.js +131 -0
  20. package/dist/collections/frozen-set.d.ts +42 -0
  21. package/dist/collections/frozen-set.js +64 -0
  22. package/dist/collections/group.d.ts +141 -0
  23. package/dist/collections/group.js +241 -0
  24. package/dist/collections/heap.d.ts +64 -0
  25. package/dist/collections/heap.js +205 -0
  26. package/dist/collections/index.d.ts +15 -642
  27. package/dist/collections/index.js +14 -716
  28. package/dist/collections/internal/arrayKeys.d.ts +19 -0
  29. package/dist/collections/internal/arrayKeys.js +83 -0
  30. package/dist/collections/internal/invariants.d.ts +4 -0
  31. package/dist/collections/internal/invariants.js +12 -0
  32. package/dist/collections/internal/iterable.d.ts +25 -0
  33. package/dist/collections/internal/iterable.js +62 -0
  34. package/dist/collections/iterate.d.ts +162 -0
  35. package/dist/collections/iterate.js +188 -0
  36. package/dist/collections/lru-cache.d.ts +58 -0
  37. package/dist/collections/lru-cache.js +164 -0
  38. package/dist/collections/order.d.ts +19 -0
  39. package/dist/collections/order.js +38 -0
  40. package/dist/collections/shape.d.ts +32 -0
  41. package/dist/collections/shape.js +86 -0
  42. package/dist/collections/sorted-map.d.ts +171 -0
  43. package/dist/collections/sorted-map.js +845 -0
  44. package/dist/collections/sorted-set.d.ts +103 -0
  45. package/dist/collections/sorted-set.js +147 -0
  46. package/dist/collections/splay-tree.d.ts +82 -0
  47. package/dist/collections/splay-tree.js +354 -0
  48. package/dist/collections/trie.d.ts +58 -0
  49. package/dist/collections/trie.js +196 -0
  50. package/dist/decimal/currency.d.ts +211 -0
  51. package/dist/decimal/currency.js +321 -0
  52. package/dist/decimal/decimal.d.ts +299 -0
  53. package/dist/decimal/decimal.js +660 -0
  54. package/dist/decimal/index.d.ts +11 -145
  55. package/dist/decimal/index.js +10 -374
  56. package/dist/decimal/internal/bits.d.ts +2 -0
  57. package/dist/decimal/internal/bits.js +7 -0
  58. package/dist/decimal/internal/echo.d.ts +4 -0
  59. package/dist/decimal/internal/echo.js +6 -0
  60. package/dist/decimal/internal/isqrt.d.ts +9 -0
  61. package/dist/decimal/internal/isqrt.js +34 -0
  62. package/dist/decimal/internal/locale.d.ts +7 -0
  63. package/dist/decimal/internal/locale.js +24 -0
  64. package/dist/decimal/internal/minor-units.d.ts +2 -0
  65. package/dist/decimal/internal/minor-units.js +33 -0
  66. package/dist/decimal/internal/pow10.d.ts +24 -0
  67. package/dist/decimal/internal/pow10.js +96 -0
  68. package/dist/encoding/base64.d.ts +39 -0
  69. package/dist/encoding/base64.js +53 -0
  70. package/dist/encoding/hex.d.ts +23 -0
  71. package/dist/encoding/hex.js +34 -0
  72. package/dist/encoding/index.d.ts +6 -0
  73. package/dist/encoding/index.js +6 -0
  74. package/dist/function/debounce.d.ts +68 -0
  75. package/dist/function/debounce.js +203 -0
  76. package/dist/function/index.d.ts +6 -0
  77. package/dist/function/index.js +6 -0
  78. package/dist/function/shared.d.ts +2 -0
  79. package/dist/function/shared.js +5 -0
  80. package/dist/function/wrap.d.ts +130 -0
  81. package/dist/function/wrap.js +113 -0
  82. package/dist/hash/digest.d.ts +18 -0
  83. package/dist/hash/digest.js +26 -0
  84. package/dist/hash/hash.d.ts +22 -0
  85. package/dist/hash/hash.js +252 -0
  86. package/dist/hash/hashString.d.ts +13 -0
  87. package/dist/hash/hashString.js +53 -0
  88. package/dist/hash/index.d.ts +8 -0
  89. package/dist/hash/index.js +8 -0
  90. package/dist/hash/stableStringify.d.ts +19 -0
  91. package/dist/hash/stableStringify.js +102 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.js +7 -0
  94. package/dist/id/nanoid.d.ts +16 -0
  95. package/dist/id/nanoid.js +65 -0
  96. package/dist/id/uniqueId.d.ts +14 -0
  97. package/dist/id/uniqueId.js +20 -0
  98. package/dist/id/uuid.d.ts +25 -0
  99. package/dist/id/uuid.js +64 -0
  100. package/dist/index.d.ts +15 -8
  101. package/dist/index.js +15 -8
  102. package/dist/internal/bytes.d.ts +11 -0
  103. package/dist/internal/bytes.js +33 -0
  104. package/dist/internal/codec.d.ts +11 -0
  105. package/dist/internal/codec.js +84 -0
  106. package/dist/internal/compare.d.ts +10 -0
  107. package/dist/internal/compare.js +26 -0
  108. package/dist/internal/crypto.d.ts +5 -0
  109. package/dist/internal/crypto.js +11 -0
  110. package/dist/internal/keys.d.ts +12 -0
  111. package/dist/internal/keys.js +23 -0
  112. package/dist/internal/kind.d.ts +44 -0
  113. package/dist/internal/kind.js +139 -0
  114. package/dist/internal/sparse.d.ts +51 -0
  115. package/dist/internal/sparse.js +104 -0
  116. package/dist/internal/text.d.ts +7 -0
  117. package/dist/internal/text.js +15 -0
  118. package/dist/internal/timer.d.ts +10 -0
  119. package/dist/internal/timer.js +17 -0
  120. package/dist/internal/truncate.d.ts +10 -0
  121. package/dist/internal/truncate.js +22 -0
  122. package/dist/internal/walk.d.ts +47 -0
  123. package/dist/internal/walk.js +100 -0
  124. package/dist/is/index.d.ts +8 -0
  125. package/dist/is/index.js +8 -0
  126. package/dist/is/isArrayLike.d.ts +18 -0
  127. package/dist/is/isArrayLike.js +25 -0
  128. package/dist/is/isError.d.ts +13 -0
  129. package/dist/is/isError.js +18 -0
  130. package/dist/is/isNil.d.ts +12 -0
  131. package/dist/is/isNil.js +14 -0
  132. package/dist/is/isPlainObject.d.ts +15 -0
  133. package/dist/is/isPlainObject.js +34 -0
  134. package/dist/number/index.d.ts +7 -0
  135. package/dist/number/index.js +7 -0
  136. package/dist/number/round.d.ts +86 -0
  137. package/dist/number/round.js +130 -0
  138. package/dist/number/stats.d.ts +52 -0
  139. package/dist/number/stats.js +115 -0
  140. package/dist/object/cloneDeep.d.ts +28 -0
  141. package/dist/object/cloneDeep.js +200 -0
  142. package/dist/object/index.d.ts +14 -0
  143. package/dist/object/index.js +13 -0
  144. package/dist/object/isEqual.d.ts +64 -0
  145. package/dist/object/isEqual.js +289 -0
  146. package/dist/object/matches.d.ts +40 -0
  147. package/dist/object/matches.js +284 -0
  148. package/dist/object/merge.d.ts +66 -0
  149. package/dist/object/merge.js +272 -0
  150. package/dist/object/parsePath.d.ts +22 -0
  151. package/dist/object/parsePath.js +111 -0
  152. package/dist/object/path.d.ts +85 -0
  153. package/dist/object/path.js +208 -0
  154. package/dist/object/pick.d.ts +91 -0
  155. package/dist/object/pick.js +180 -0
  156. package/dist/object/reshape.d.ts +73 -0
  157. package/dist/object/reshape.js +144 -0
  158. package/dist/random/index.d.ts +96 -32
  159. package/dist/random/index.js +215 -50
  160. package/dist/string/case.d.ts +71 -0
  161. package/dist/string/case.js +152 -0
  162. package/dist/string/fold.d.ts +35 -0
  163. package/dist/string/fold.js +100 -0
  164. package/dist/string/index.d.ts +6 -187
  165. package/dist/string/index.js +6 -226
  166. package/dist/string/truncate.d.ts +25 -0
  167. package/dist/string/truncate.js +44 -0
  168. package/dist/string/words.d.ts +27 -0
  169. package/dist/string/words.js +241 -0
  170. package/package.json +101 -58
  171. package/dist/collections/BTree.d.ts +0 -229
  172. package/dist/collections/BTree.js +0 -1165
  173. package/dist/collections/Heap.d.ts +0 -69
  174. package/dist/collections/Heap.js +0 -181
  175. package/dist/collections/LRUCache.d.ts +0 -80
  176. package/dist/collections/LRUCache.js +0 -126
  177. package/dist/collections/SortedMap.d.ts +0 -92
  178. package/dist/collections/SortedMap.js +0 -131
  179. package/dist/collections/SortedSet.d.ts +0 -69
  180. package/dist/collections/SortedSet.js +0 -99
  181. package/dist/collections/SortedTree.d.ts +0 -103
  182. package/dist/collections/SortedTree.js +0 -141
  183. package/dist/collections/SplayTree.d.ts +0 -105
  184. package/dist/collections/SplayTree.js +0 -338
  185. package/dist/collections/Trie.d.ts +0 -42
  186. package/dist/collections/Trie.js +0 -104
  187. package/dist/collections/abc.d.ts +0 -152
  188. package/dist/collections/abc.js +0 -39
  189. package/dist/collections/frozenset.d.ts +0 -19
  190. package/dist/collections/frozenset.js +0 -30
  191. package/dist/functools/index.d.ts +0 -130
  192. package/dist/functools/index.js +0 -235
  193. package/dist/globals/index.d.ts +0 -285
  194. package/dist/globals/index.js +0 -463
  195. package/dist/i18n/currency.d.ts +0 -24
  196. package/dist/i18n/currency.js +0 -85
  197. package/dist/i18n/date/index.d.ts +0 -203
  198. package/dist/i18n/date/index.js +0 -531
  199. package/dist/i18n/date/utils.d.ts +0 -65
  200. package/dist/i18n/date/utils.js +0 -290
  201. package/dist/i18n/duration.d.ts +0 -112
  202. package/dist/i18n/duration.js +0 -392
  203. package/dist/i18n/format.d.ts +0 -31
  204. package/dist/i18n/format.js +0 -506
  205. package/dist/i18n/index.d.ts +0 -8
  206. package/dist/i18n/index.js +0 -8
  207. package/dist/itertools/index.d.ts +0 -255
  208. package/dist/itertools/index.js +0 -437
  209. package/dist/math/index.d.ts +0 -96
  210. package/dist/math/index.js +0 -98
  211. package/dist/mod.d.ts +0 -1
  212. package/dist/mod.js +0 -1
  213. package/dist/operators/index.d.ts +0 -152
  214. package/dist/operators/index.js +0 -305
  215. package/dist/types.d.ts +0 -19
  216. package/dist/types.js +0 -1
@@ -1,96 +0,0 @@
1
- /**
2
- * Math and algebraic operations.
3
- *
4
- * @module math
5
- */
6
- import { Predicate } from '../types.js';
7
- /**
8
- * Returns the absolute value of a number. The argument may be a number or an object implementing the `abs()`.
9
- * @param x The value.
10
- * @returns The absolute value.
11
- */
12
- export declare function abs(x: any): number;
13
- /**
14
- * Round `x` to the number of digits after the decimal point. If `digits` is
15
- * omitted, it returns the nearest integer to x.
16
- *
17
- * @param {number} x
18
- * @param {number} [digits=0]
19
- *
20
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round Math.round()}
21
- */
22
- export declare function round(x: number, digits?: number): number;
23
- /**
24
- * Rounds down and returns the largest integer less than or equal to a given number.
25
- * @param x A number.
26
- * @returns Nearest integer less than or equal to number.
27
- *
28
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor Math.floor()}
29
- */
30
- export declare function floor(x: number): number;
31
- /**
32
- * Rounds up and returns the largest integer greater than or equal to a given number.
33
- * @param x A number.
34
- * @returns Nearest integer greater than or equal to number.
35
- *
36
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil Math.ceil()}
37
- */
38
- export declare function ceil(x: number): number;
39
- /**
40
- * Returns a tuple like `[x / y, x % y]`.
41
- *
42
- * @param x
43
- * @param y
44
- * @returns
45
- */
46
- export declare function divmod(x: number, y: number): [number, number];
47
- export declare function log2(x: number): number;
48
- export declare function logBase(x: number, y: number): number;
49
- /**
50
- * Returns the smallest element in an iterable. The optional `key` argument specifies a transform on the elements before comparing them. If the elements in the iterable are objects that implement a custom `lt` method, this will be called to compare.
51
- * @param iterable The iterable to inspect.
52
- * @param key Optional key function to transform the elements (default `id`).
53
- * @returns The smallest element in the iterable.
54
- */
55
- export declare function min(iterable: number[]): number;
56
- export declare function min<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
57
- /**
58
- * Returns the largest element in an iterable. The optional `key` argument specifies a transform on the elements before comparing them. If the elements in the iterable are objects that implement a custom `gt` method, this will be called to compare.
59
- * @param iterable The iterable to inspect.
60
- * @param key Optional key function to transform the elements (default `id`).
61
- * @returns The largest element in the iterable.
62
- */
63
- export declare function max(iterable: number[]): number;
64
- export declare function max<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
65
- /**
66
- * Computes the mean of the values in `iterable` and accepts an optional `key` function which is invoked for each element to generate the values to be averaged.
67
- * @param {Array<number>|Iterable<T>} iterable
68
- * @param {Function} [key] Optional iteratee invoked per element.
69
- * @returns Returns the mean value or `NaN` if no elements.
70
- * @template T
71
- * @example
72
- ```js
73
- let objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]
74
-
75
- mean(objects, o => o.n)
76
- // 5
77
- ```
78
- */
79
- export declare function mean(iterable: number[]): number;
80
- export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>): number;
81
- /**
82
- * Sums `initial` and the items of an iterable and returns the total.
83
- * @param args The elements to add to `initial`.
84
- * @param initial The initial value to add to (default `0`).
85
- * @returns The total sum of initial and iterable elements.
86
- * @example
87
- ```js
88
- sum([1, 2, 3, 4])
89
- // 10
90
-
91
- sum([1, 2, 3, 4], 5)
92
- // 15
93
- ```
94
- */
95
- export declare function sum(args: number[]): number;
96
- export declare function sum<T>(args: Iterable<T>, key?: Predicate<T>): number;
@@ -1,98 +0,0 @@
1
- /**
2
- * Math and algebraic operations.
3
- *
4
- * @module math
5
- */
6
- import { call } from '../globals/index.js';
7
- import { reduce } from '../itertools/index.js';
8
- import { gt, id, lt } from '../operators/index.js';
9
- /**
10
- * Returns the absolute value of a number. The argument may be a number or an object implementing the `abs()`.
11
- * @param x The value.
12
- * @returns The absolute value.
13
- */
14
- export function abs(x) {
15
- const op = call(x, 'abs');
16
- if (op != null)
17
- return op;
18
- return Math.abs(x);
19
- }
20
- /**
21
- * Round `x` to the number of digits after the decimal point. If `digits` is
22
- * omitted, it returns the nearest integer to x.
23
- *
24
- * @param {number} x
25
- * @param {number} [digits=0]
26
- *
27
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round Math.round()}
28
- */
29
- export function round(x, digits = 0) {
30
- const base = 10 ** digits;
31
- return Math.round(x * base) / base;
32
- }
33
- /**
34
- * Rounds down and returns the largest integer less than or equal to a given number.
35
- * @param x A number.
36
- * @returns Nearest integer less than or equal to number.
37
- *
38
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor Math.floor()}
39
- */
40
- export function floor(x) {
41
- return Math.floor(x);
42
- }
43
- /**
44
- * Rounds up and returns the largest integer greater than or equal to a given number.
45
- * @param x A number.
46
- * @returns Nearest integer greater than or equal to number.
47
- *
48
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil Math.ceil()}
49
- */
50
- export function ceil(x) {
51
- return Math.ceil(x);
52
- }
53
- /**
54
- * Returns a tuple like `[x / y, x % y]`.
55
- *
56
- * @param x
57
- * @param y
58
- * @returns
59
- */
60
- export function divmod(x, y) {
61
- return [Math.floor(x / y), x % y];
62
- }
63
- export function log2(x) {
64
- if (x > 0) {
65
- return Math.log(x) * 1.442695;
66
- }
67
- return Number.NaN;
68
- }
69
- export function logBase(x, y) {
70
- if (x > 0 && y > 0) {
71
- return Math.log(y) / Math.log(x);
72
- }
73
- return Number.NaN;
74
- }
75
- export function min(iterable, key = id) {
76
- return reduce(iterable, (x, y) => (lt(key(x), key(y)) ? x : y));
77
- }
78
- export function max(iterable, key = id) {
79
- return reduce(iterable, (x, y) => (gt(key(x), key(y)) ? x : y));
80
- }
81
- export function mean(iterable, key = id) {
82
- let total = 0;
83
- let count = 0;
84
- for (const value of iterable) {
85
- total += key(value);
86
- count++;
87
- }
88
- if (count !== 0)
89
- return total / count;
90
- return Number.NaN;
91
- }
92
- export function sum(args, key = id) {
93
- let initial = 0;
94
- for (const x of args) {
95
- initial += key(x);
96
- }
97
- return initial;
98
- }
package/dist/mod.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './index.js';
package/dist/mod.js DELETED
@@ -1 +0,0 @@
1
- export * from './index.js';
@@ -1,152 +0,0 @@
1
- /**
2
- * Generic operations for both values and objects.
3
- *
4
- * @module operators
5
- */
6
- /** @deprecated Use the `identity` function instead.
7
- * @see {@link identity}
8
- */
9
- export declare function id(x: any): any;
10
- /** This is the identity function. It always returns the same value that was passed in. */
11
- export declare const identity: <T>(x: T) => T;
12
- /**
13
- * Called to implement truth value testing.
14
- * @param x
15
- * @returns {boolean} `x.bool()` if exists or `!!x`.
16
- */
17
- export declare function bool(x: any): any;
18
- /**
19
- * Returns `true` if `x` is a falsy value.
20
- * @see {@link bool}
21
- */
22
- export declare function not(x: any): boolean;
23
- /**
24
- * Returns `true` if `x` is an instance of class `y`
25
- * @param x The instance object
26
- * @param y The parent class
27
- * @returns {boolean}
28
- */
29
- export declare function isinstance(x: any, y: any): boolean;
30
- /** Describes a function used to compare two values.
31
- *
32
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
33
- */
34
- export declare type Comparer<T = any> = (x: T, y: T) => number;
35
- /**
36
- * Checks whether `x` is a comparable type and returns the result of `x.compare(y)`.
37
- * Otherwise the return value of the compare function is equivalent to `obj === other ? 0 : obj < other ? -1 : 1`
38
- * @param {*} x An initial value
39
- * @param {*} y Other value to compare
40
- * @returns {number} The comparison result
41
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
42
- * @see {@link operators.eq}
43
- * @see {@link operators.lt}
44
- */
45
- export declare function compare(x: any, y: any): number;
46
- /**
47
- * Compares two values to check if they are the same. If `x` is an object with an `eq` method, it returns `x.eq(y)`.
48
- * Otherwise it returns the result of `x === y`.
49
- * @param {*} x
50
- * @param {*} y
51
- * @returns {boolean} `true` if `x` and `y` are equal or `false` otherwise.
52
- */
53
- export declare function eq(x: any, y: any): boolean;
54
- /**
55
- * 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)`.
56
- * Otherwise it returns the result of `x < y`.
57
- * @param {*} x
58
- * @param {*} y
59
- * @returns {boolean} `true` if `x` is strictly less than `y` or `false` otherwise.
60
- */
61
- export declare function lt(x: any, y: any): boolean;
62
- /**
63
- * 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)`.
64
- * Otherwise it returns the result of `x <= y`.
65
- * @param {*} x
66
- * @param {*} y
67
- * @returns {boolean} `true` if `x` is less than or equal to `y` or `false` otherwise.
68
- * @see {@link eq}
69
- * @see {@link lt}
70
- */
71
- export declare function lte(x: any, y: any): boolean;
72
- /**
73
- * 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)`.
74
- * Otherwise it returns the result of `x > y`.
75
- * @param {*} x
76
- * @param {*} y
77
- * @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
78
- */
79
- export declare function gt(x: any, y: any): boolean;
80
- /**
81
- * 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)`.
82
- * Otherwise it returns the result of `x >= y`.
83
- * @param {*} x
84
- * @param {*} y
85
- * @returns {boolean} `true` if `x` is less greater than or equal to `y` or `false` otherwise.
86
- * @see {@link eq}
87
- * @see {@link gt}
88
- */
89
- export declare function gte(x: any, y: any): boolean;
90
- /**
91
- * The addition (+) operator. If `x` is an object with an `add` method, it returns `x.add(y)`.
92
- * Otherwise it returns the result of `x + y`.
93
- * @param {*} x
94
- * @param {*} y
95
- * @returns {*} x + y
96
- */
97
- export declare function add(x: any, y: any): any;
98
- /**
99
- * The subtraction (-) operator. If `x` is an object with a `sub` method, it returns `x.sub(y)`.
100
- * Otherwise it returns the result of `x - y`.
101
- * @param {*} x
102
- * @param {*} y
103
- * @returns {*} x - y
104
- */
105
- export declare function sub(x: any, y: any): any;
106
- /**
107
- * The multiplication (*) operator. If `x` is an object with an `mul` method, it returns `x.mul(y)`.
108
- * Otherwise it returns the result of `x * y`.
109
- * @param {*} x
110
- * @param {*} y
111
- * @returns {*} x * y
112
- */
113
- export declare function mul(x: any, y: any): any;
114
- /**
115
- * The division (/) operator. If `x` is an object with a `div` method, it returns `x.div(y)`.
116
- * Otherwise it returns the result of `x / y`.
117
- * @param {*} x
118
- * @param {*} y
119
- * @returns {*} x / y
120
- */
121
- export declare function div(x: any, y: any): any;
122
- /**
123
- * The modulo (%) operator. If `x` is an object with a `mod` method, it returns `x.mod(y)`.
124
- * Otherwise it returns the result of `x % y`.
125
- * @param {*} x
126
- * @param {*} y
127
- * @returns {*} x % y
128
- */
129
- export declare function mod(x: any, y: any): any;
130
- /**
131
- * The power (**) operator. If `x` is an object with a `pow` method, it returns `x.pow(y)`.
132
- * Otherwise it returns the result of `x ** y`.
133
- * @param {*} x
134
- * @param {*} y
135
- * @returns {*} x ** y
136
- */
137
- export declare function pow(x: any, y: any): any;
138
- /**
139
- * Performs a shallow comparison of two objects or arrays to check if they have the same keys, length and values.
140
- * @param obj
141
- * @param other
142
- * @returns `true` if the objects are considered equal.
143
- * @see {@link deepEqual}
144
- */
145
- export declare function shallowEqual(obj: any, other: any): boolean;
146
- /**
147
- * 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.
148
- * @param obj
149
- * @param other
150
- * @returns `true` if the objects are considered equal.
151
- */
152
- export declare function deepEqual(obj: any, other: any, checker?: Function, seen?: any): boolean;
@@ -1,305 +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
- /** @deprecated Use the `identity` function instead.
8
- * @see {@link identity}
9
- */
10
- export function id(x) {
11
- return x;
12
- }
13
- /** This is the identity function. It always returns the same value that was passed in. */
14
- export const identity = (x) => x;
15
- /**
16
- * Called to implement truth value testing.
17
- * @param x
18
- * @returns {boolean} `x.bool()` if exists or `!!x`.
19
- */
20
- export function bool(x) {
21
- const r = call(x, 'bool');
22
- if (r != null)
23
- return r;
24
- return !!x;
25
- }
26
- /**
27
- * Returns `true` if `x` is a falsy value.
28
- * @see {@link bool}
29
- */
30
- export function not(x) {
31
- return !bool(x);
32
- }
33
- /**
34
- * Returns `true` if `x` is an instance of class `y`
35
- * @param x The instance object
36
- * @param y The parent class
37
- * @returns {boolean}
38
- */
39
- export function isinstance(x, y) {
40
- return x instanceof y;
41
- }
42
- /**
43
- * Checks whether `x` is a comparable type and returns the result of `x.compare(y)`.
44
- * Otherwise the return value of the compare function is equivalent to `obj === other ? 0 : obj < other ? -1 : 1`
45
- * @param {*} x An initial value
46
- * @param {*} y Other value to compare
47
- * @returns {number} The comparison result
48
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
49
- * @see {@link operators.eq}
50
- * @see {@link operators.lt}
51
- */
52
- export function compare(x, y) {
53
- if (x === y || eq(x, y))
54
- return 0;
55
- const op = call(x, 'compare', y);
56
- if (typeof op === 'number')
57
- return op;
58
- if (x < y || lt(x, y))
59
- return -1;
60
- return 1;
61
- }
62
- /**
63
- * Compares two values to check if they are the same. If `x` is an object with an `eq` method, it returns `x.eq(y)`.
64
- * Otherwise it returns the result of `x === y`.
65
- * @param {*} x
66
- * @param {*} y
67
- * @returns {boolean} `true` if `x` and `y` are equal or `false` otherwise.
68
- */
69
- export function eq(x, y) {
70
- return Object.is(x, y) || call(x, 'eq', y) != null;
71
- }
72
- /**
73
- * 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)`.
74
- * Otherwise it returns the result of `x < y`.
75
- * @param {*} x
76
- * @param {*} y
77
- * @returns {boolean} `true` if `x` is strictly less than `y` or `false` otherwise.
78
- */
79
- export function lt(x, y) {
80
- return x < y || call(x, 'lt', y) != null;
81
- }
82
- /**
83
- * 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)`.
84
- * Otherwise it returns the result of `x <= y`.
85
- * @param {*} x
86
- * @param {*} y
87
- * @returns {boolean} `true` if `x` is less than or equal to `y` or `false` otherwise.
88
- * @see {@link eq}
89
- * @see {@link lt}
90
- */
91
- export function lte(x, y) {
92
- if (x <= y || call(x, 'lte', y))
93
- return true;
94
- if (x === y || eq(x, y))
95
- return true;
96
- if (x < y || lt(x, y))
97
- return true;
98
- return false;
99
- }
100
- /**
101
- * 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)`.
102
- * Otherwise it returns the result of `x > y`.
103
- * @param {*} x
104
- * @param {*} y
105
- * @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
106
- */
107
- export function gt(x, y) {
108
- return x > y || call(x, 'gt', y);
109
- }
110
- /**
111
- * 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)`.
112
- * Otherwise it returns the result of `x >= y`.
113
- * @param {*} x
114
- * @param {*} y
115
- * @returns {boolean} `true` if `x` is less greater than or equal to `y` or `false` otherwise.
116
- * @see {@link eq}
117
- * @see {@link gt}
118
- */
119
- export function gte(x, y) {
120
- if (x <= y || call(x, 'gte', y))
121
- return true;
122
- if (x === y || eq(x, y))
123
- return true;
124
- if (x > y || gt(x, y))
125
- return true;
126
- return false;
127
- }
128
- /**
129
- * The addition (+) operator. If `x` is an object with an `add` method, it returns `x.add(y)`.
130
- * Otherwise it returns the result of `x + y`.
131
- * @param {*} x
132
- * @param {*} y
133
- * @returns {*} x + y
134
- */
135
- export function add(x, y) {
136
- const op = call(x, 'add', y);
137
- if (op != null)
138
- return op;
139
- return x + y;
140
- }
141
- /**
142
- * The subtraction (-) operator. If `x` is an object with a `sub` method, it returns `x.sub(y)`.
143
- * Otherwise it returns the result of `x - y`.
144
- * @param {*} x
145
- * @param {*} y
146
- * @returns {*} x - y
147
- */
148
- export function sub(x, y) {
149
- const op = call(x, 'sub', y);
150
- if (op != null)
151
- return op;
152
- return x - y;
153
- }
154
- /**
155
- * The multiplication (*) operator. If `x` is an object with an `mul` method, it returns `x.mul(y)`.
156
- * Otherwise it returns the result of `x * y`.
157
- * @param {*} x
158
- * @param {*} y
159
- * @returns {*} x * y
160
- */
161
- export function mul(x, y) {
162
- const op = call(x, 'mul', y);
163
- if (op != null)
164
- return op;
165
- return x * y;
166
- }
167
- /**
168
- * The division (/) operator. If `x` is an object with a `div` method, it returns `x.div(y)`.
169
- * Otherwise it returns the result of `x / y`.
170
- * @param {*} x
171
- * @param {*} y
172
- * @returns {*} x / y
173
- */
174
- export function div(x, y) {
175
- const op = call(x, 'div', y);
176
- if (op != null)
177
- return op;
178
- return x / y;
179
- }
180
- /**
181
- * The modulo (%) operator. If `x` is an object with a `mod` method, it returns `x.mod(y)`.
182
- * Otherwise it returns the result of `x % y`.
183
- * @param {*} x
184
- * @param {*} y
185
- * @returns {*} x % y
186
- */
187
- export function mod(x, y) {
188
- const op = call(x, 'mod', y);
189
- if (op != null)
190
- return op;
191
- return x % y;
192
- }
193
- /**
194
- * The power (**) operator. If `x` is an object with a `pow` method, it returns `x.pow(y)`.
195
- * Otherwise it returns the result of `x ** y`.
196
- * @param {*} x
197
- * @param {*} y
198
- * @returns {*} x ** y
199
- */
200
- export function pow(x, y) {
201
- const op = call(x, 'pow', y);
202
- if (op != null)
203
- return op;
204
- return x ** y;
205
- }
206
- /**
207
- * Performs a shallow comparison of two objects or arrays to check if they have the same keys, length and values.
208
- * @param obj
209
- * @param other
210
- * @returns `true` if the objects are considered equal.
211
- * @see {@link deepEqual}
212
- */
213
- export function shallowEqual(obj, other) {
214
- if (obj === other)
215
- return true;
216
- if (!obj || !other)
217
- return false;
218
- if (Array.isArray(obj)) {
219
- // compare the arrays
220
- if (obj.length !== other.length)
221
- return false;
222
- for (let i = 0; i < obj.length; i++) {
223
- if (obj[i] !== other[i]) {
224
- return false;
225
- }
226
- }
227
- return true;
228
- }
229
- else if (isObject(obj)) {
230
- // compare the object keys
231
- const objKeys = Object.keys(obj);
232
- const otherKeys = Object.keys(other);
233
- if (objKeys.length !== otherKeys.length)
234
- return false;
235
- for (const key of objKeys) {
236
- if (!Object.prototype.hasOwnProperty.call(other, key) || obj[key] !== other[key]) {
237
- return false;
238
- }
239
- }
240
- return true;
241
- }
242
- return false;
243
- }
244
- export function deepEqual(obj, other, checker = eq, seen = new WeakSet()) {
245
- if (checker(obj, other))
246
- return true;
247
- if (!obj || !other)
248
- return false;
249
- if (obj.prototype !== other.prototype)
250
- return false;
251
- if (seen.has(obj) && seen.has(other))
252
- return false;
253
- if (Array.isArray(obj)) {
254
- // compare the arrays
255
- if (obj.length !== other.length)
256
- return false;
257
- for (let i = 0; i < obj.length; i++) {
258
- if (!deepEqual(obj[i], other[i], checker)) {
259
- return false;
260
- }
261
- }
262
- return true;
263
- }
264
- if (obj instanceof Set) {
265
- if (obj.size !== other.size)
266
- return false;
267
- for (const value of obj.values()) {
268
- if (!other.has(value))
269
- return false;
270
- }
271
- return true;
272
- }
273
- if (obj instanceof Map) {
274
- // compare keys and values
275
- if (obj.size !== other.size)
276
- return false;
277
- seen.add(obj);
278
- seen.add(other);
279
- for (const key of obj.keys()) {
280
- if (!other.has(key))
281
- return false;
282
- if (!deepEqual(obj.get(key), other.get(key), checker, seen)) {
283
- return false;
284
- }
285
- }
286
- return true;
287
- }
288
- if (isObject(obj)) {
289
- // compare the object own enumerable keys
290
- const objKeys = Object.keys(obj);
291
- const otherKeys = Object.keys(other);
292
- if (objKeys.length !== otherKeys.length)
293
- return false;
294
- seen.add(obj);
295
- seen.add(other);
296
- for (const key of objKeys) {
297
- if (!Object.prototype.hasOwnProperty.call(other, key) ||
298
- !deepEqual(obj[key], other[key], checker, seen)) {
299
- return false;
300
- }
301
- }
302
- return true;
303
- }
304
- return false;
305
- }
package/dist/types.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * A generic function type with arbitrary arguments and return.
3
- */
4
- export declare 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 declare type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
19
- export declare type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};