atomic-fns 1.1.6 → 1.2.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 (51) hide show
  1. package/README.md +51 -12
  2. package/dist/collections/BTree.d.ts +11 -10
  3. package/dist/collections/BTree.js +58 -80
  4. package/dist/collections/Heap.d.ts +2 -2
  5. package/dist/collections/Heap.js +1 -1
  6. package/dist/collections/LRUCache.d.ts +8 -5
  7. package/dist/collections/LRUCache.js +24 -11
  8. package/dist/collections/SortedMap.d.ts +4 -4
  9. package/dist/collections/SortedMap.js +4 -3
  10. package/dist/collections/SortedSet.d.ts +2 -2
  11. package/dist/collections/SortedTree.d.ts +9 -9
  12. package/dist/collections/SortedTree.js +7 -6
  13. package/dist/collections/SplayTree.d.ts +17 -15
  14. package/dist/collections/SplayTree.js +42 -29
  15. package/dist/collections/Trie.d.ts +2 -2
  16. package/dist/collections/Trie.js +26 -26
  17. package/dist/collections/deque.d.ts +11 -11
  18. package/dist/collections/deque.js +17 -10
  19. package/dist/collections/frozenset.js +4 -1
  20. package/dist/collections/index.d.ts +30 -48
  21. package/dist/collections/index.js +210 -82
  22. package/dist/decimal/index.d.ts +7 -5
  23. package/dist/decimal/index.js +63 -28
  24. package/dist/functools/index.d.ts +10 -34
  25. package/dist/functools/index.js +25 -57
  26. package/dist/globals/index.d.ts +5 -22
  27. package/dist/globals/index.js +24 -40
  28. package/dist/i18n/currency.d.ts +10 -7
  29. package/dist/i18n/currency.js +22 -7
  30. package/dist/i18n/date/index.d.ts +22 -16
  31. package/dist/i18n/date/index.js +89 -67
  32. package/dist/i18n/date/utils.d.ts +6 -7
  33. package/dist/i18n/date/utils.js +15 -113
  34. package/dist/i18n/duration.d.ts +13 -12
  35. package/dist/i18n/duration.js +38 -32
  36. package/dist/i18n/format.d.ts +10 -2
  37. package/dist/i18n/format.js +100 -217
  38. package/dist/i18n/index.d.ts +2 -1
  39. package/dist/itertools/index.d.ts +21 -25
  40. package/dist/itertools/index.js +41 -44
  41. package/dist/math/index.d.ts +12 -29
  42. package/dist/math/index.js +16 -33
  43. package/dist/mod.d.ts +1 -0
  44. package/dist/mod.js +1 -0
  45. package/dist/operators/index.d.ts +3 -3
  46. package/dist/operators/index.js +62 -38
  47. package/dist/random/index.js +9 -6
  48. package/dist/string/index.d.ts +1 -1
  49. package/dist/string/index.js +2 -4
  50. package/dist/types.d.ts +3 -3
  51. package/package.json +16 -21
@@ -3,7 +3,10 @@
3
3
  *
4
4
  * @module decimal
5
5
  */
6
- const NUMBER_REGEX = /^(-?)([0-9]+)(\.([0-9]+))?$/;
6
+ import { ValueError } from '../globals/index.js';
7
+ const NUMBER_REGEX = /^\s*([+-]?)(?=\.?[0-9])([0-9]*)(\.([0-9]*))?(?:[eE]([+-]?[0-9]+))?\s*$/;
8
+ /** Largest power of ten an exponent may reach, so a short string cannot freeze the page. */
9
+ const MAX_EXPONENT = 10_000;
7
10
  /**
8
11
  * Casts the given value as a {@link Decimal}.
9
12
  */
@@ -23,6 +26,8 @@ export class Decimal {
23
26
  * Returns a new `Decimal` instance from the value or `0`.
24
27
  * @param {*} value
25
28
  * @returns {Decimal}
29
+ * @throws {ValueError} if the value is not numeric.
30
+ * @throws {RangeError} if the value is infinite or its exponent is past 10,000.
26
31
  */
27
32
  constructor(value) {
28
33
  if (value == null) {
@@ -35,7 +40,8 @@ export class Decimal {
35
40
  this._normalize();
36
41
  return this;
37
42
  }
38
- const result = NUMBER_REGEX.exec(value.toString());
43
+ const text = value.toString();
44
+ const result = NUMBER_REGEX.exec(text);
39
45
  if (result) {
40
46
  // console.log(result);
41
47
  // Construct from string if possible
@@ -45,11 +51,22 @@ export class Decimal {
45
51
  if (typeof result[4] === 'undefined')
46
52
  result[4] = '';
47
53
  this.i = BigInt(result[1] + result[2] + result[4]);
48
- this.e = result[4] ? -result[4].length : 0;
54
+ this.e = Number(result[5] ?? 0) - result[4].length;
49
55
  this._normalize();
56
+ if (result[5]) {
57
+ const magnitude = this.e + (this.i < 0n ? -this.i : this.i).toString().length - 1;
58
+ if (this.i === 0n)
59
+ this.e = 0;
60
+ else if (Math.abs(magnitude) > MAX_EXPONENT)
61
+ throw new RangeError('exponent out of range');
62
+ }
50
63
  }
51
64
  else {
52
65
  // Conversion to string failed, so construct from number
66
+ value = Number(value);
67
+ if (Number.isNaN(value) || (value === 0 && text.trim() === '')) {
68
+ throw new ValueError('Decimal value must be numeric');
69
+ }
53
70
  let m = 1n;
54
71
  if (value < 0) {
55
72
  value = -value;
@@ -63,7 +80,7 @@ export class Decimal {
63
80
  // Multiply the number by 10 until it is an integer
64
81
  let e = -Math.floor(Math.log10(value));
65
82
  if (e > 0) {
66
- value *= Math.pow(10, e);
83
+ value *= 10 ** e;
67
84
  }
68
85
  else {
69
86
  e = 0;
@@ -169,7 +186,7 @@ export class Decimal {
169
186
  ```js
170
187
  let a = decimal('1')
171
188
  let b = decimal('3')
172
- a.div(b) // 0.333333333333333333333333333333
189
+ a.div(b) // 0.33333333333333333333
173
190
  ```
174
191
  * @returns {Decimal}
175
192
  */
@@ -179,8 +196,8 @@ export class Decimal {
179
196
  // We need to increase the number of digits of a and b so that a / b will have the desired precision.
180
197
  // In order for the integer quotient to have the correct precision, a.e - b.e must be greater than that precision.
181
198
  // So we need only to increase a.e.
182
- // TODO: Revisit the value of increaseA. Is it correct in every circumstance?
183
- const increaseA = Math.max(Decimal.precision - (a.e + b.e), 0);
199
+ // The quotient needs precision + a.e - b.e, and a negative a.e keeps the digits it always had
200
+ const increaseA = Math.max(Decimal.precision + Math.abs(a.e) - b.e, 0);
184
201
  const intIncrease = new Decimal();
185
202
  intIncrease.i = exp(a.i, increaseA);
186
203
  const quotient = new Decimal();
@@ -192,14 +209,17 @@ export class Decimal {
192
209
  }
193
210
  /**
194
211
  * Returns the square root of this `Decimal`.
195
- * @returns {TDecimal}
212
+ * @returns {Decimal}
213
+ * @throws {ValueError} if this value is negative.
196
214
  */
197
215
  sqrt() {
216
+ if (this.i < 0n)
217
+ throw new ValueError('square root of a negative number');
198
218
  Decimal.PRECISION++;
199
- // Let the guess value be 10^(e/2), where e is this.e
219
+ // Let the guess value be 10^(m/2), where m is the magnitude of this value
200
220
  let x = new Decimal();
201
221
  x.i = 1n;
202
- x.e = Math.floor(this.e / 2);
222
+ x.e = Math.floor((this.e + this.i.toString().length) / 2);
203
223
  const onehalf = new Decimal('0.5');
204
224
  let xt = x.clone();
205
225
  xt._truncate();
@@ -221,6 +241,13 @@ export class Decimal {
221
241
  Decimal.PRECISION--;
222
242
  xt._truncate();
223
243
  xt._normalize();
244
+ // Rounding twice can leave the last digit one too high, so check it against the exact square
245
+ const half = new Decimal();
246
+ half.i = 5n;
247
+ half.e = -Decimal.PRECISION - 1;
248
+ const low = xt.sub(half);
249
+ if (low.gt(0) && low.mul(low).gt(this))
250
+ return low.sub(half);
224
251
  return xt;
225
252
  }
226
253
  /** Returns a new copy of this Decimal value. */
@@ -234,10 +261,16 @@ export class Decimal {
234
261
  * Remove zeroes in the least-significant digit of this `Decimal`
235
262
  */
236
263
  _normalize() {
237
- while (this.i % 10n === 0n && this.i !== 0n) {
238
- this.i /= 10n;
239
- this.e++;
240
- }
264
+ if (this.i === 0n)
265
+ this.e = Math.min(this.e, 0);
266
+ if (this.i === 0n || this.i % 10n !== 0n)
267
+ return this;
268
+ const digits = this.i.toString();
269
+ let end = digits.length;
270
+ while (digits[end - 1] === '0')
271
+ end--;
272
+ this.i = BigInt(digits.slice(0, end));
273
+ this.e += digits.length - end;
241
274
  return this;
242
275
  }
243
276
  /**
@@ -264,7 +297,6 @@ export class Decimal {
264
297
  }
265
298
  /**
266
299
  * Returns a string representation of this decimal.
267
- * @returns {Decimal}
268
300
  */
269
301
  toString() {
270
302
  let s = this.i.toString();
@@ -278,9 +310,9 @@ export class Decimal {
278
310
  }
279
311
  else if (this.e < 0) {
280
312
  if (-this.e >= s.length) {
281
- return m + '0.' + '0'.repeat(-this.e - s.length) + s;
313
+ return `${m}0.${'0'.repeat(-this.e - s.length)}${s}`;
282
314
  }
283
- return m + s.slice(0, s.length + this.e) + '.' + s.slice(s.length + this.e, s.length);
315
+ return `${m}${s.slice(0, s.length + this.e)}.${s.slice(s.length + this.e, s.length)}`;
284
316
  }
285
317
  else {
286
318
  return m + s;
@@ -308,8 +340,16 @@ export class Decimal {
308
340
  * @returns {boolean}
309
341
  */
310
342
  eq(x) {
311
- const other = decimal(x);
312
- return this.i === other.i && this.e === other.e;
343
+ if (x == null || typeof x === 'boolean')
344
+ return false;
345
+ let other;
346
+ try {
347
+ other = decimal(x);
348
+ }
349
+ catch {
350
+ return false;
351
+ }
352
+ return this.i === other.i && (this.e === other.e || this.i === 0n);
313
353
  }
314
354
  /**
315
355
  * Returns `true` if this value is less than the value of `x`, otherwise `false`.
@@ -335,9 +375,10 @@ export class Decimal {
335
375
  * @returns {number}
336
376
  */
337
377
  compare(x) {
338
- if (this.eq(x))
378
+ const other = x == null || typeof x === 'boolean' ? decimal(x) : x;
379
+ if (this.eq(other))
339
380
  return 0;
340
- if (this.lt(x))
381
+ if (this.lt(other))
341
382
  return -1;
342
383
  return 1;
343
384
  }
@@ -368,11 +409,5 @@ export class Decimal {
368
409
  }
369
410
  /** Returns a BigInt that is equal to `i` times `10^e` */
370
411
  function exp(i, e) {
371
- // TODO: Make this better
372
- // The implementation is faster than 10n ** BigInt(e). But could we make it faster still?
373
- let ii = i;
374
- for (let j = 0; j < e; j++) {
375
- ii *= 10n;
376
- }
377
- return ii;
412
+ return i * 10n ** BigInt(e);
378
413
  }
@@ -3,36 +3,27 @@
3
3
  *
4
4
  * @module functools
5
5
  */
6
- import { Function } from '../globals/index.js';
6
+ import type { Function } from '../globals/index.js';
7
7
  /**
8
- * Creates a function that invokes `fn` with the this binding of `thisArg` and `partials` as partially applied arguments.
9
- * @param {Function} fn The function to bind.
10
- * @param {*} thisArg The `this` value of `fn`.
11
- * @param {...*} [partials] The arguments to prepend to `fn`.
12
- * @returns {Function} Returns the new bound function.
13
- * @see {@link partial}
14
- */
15
- export declare function bind(fn: Function, thisArg: any, ...partials: any[]): any;
16
- /**
17
- * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on. The arity of `func` may be specified if `func.length` is not sufficient.
8
+ * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `func.length` arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
18
9
  * @param {Function} func The function to curry.
19
10
  * @returns Returns the new curried function.
20
11
  */
21
- export declare function curry(func: Function): (...args: any[]) => any;
12
+ export declare function curry(func: Function): Function<ReturnType<typeof func>>;
22
13
  /**
23
14
  * Creates a function that invokes `fn` with partials prepended to the arguments it receives.
24
- * **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider {@link bind} instead.
15
+ * **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider `Function.prototype.bind` instead.
25
16
  * @param {Function} fn The function to bind.
26
17
  * @param {...*} [args] The arguments to apply to `fn`.
27
18
  * @returns {Function} Returns the new partially applied function
28
19
  */
29
- export declare function partial(fn: any, ...args: any[]): any;
20
+ export declare function partial(fn: Function, ...args: any[]): Function<ReturnType<typeof fn>>;
30
21
  /**
31
22
  * Creates a function composition from a given set of functions that will be each applied on the result of the previous one from left to right.
32
23
  * @param {...*} [args] The set of functions to apply.
33
24
  * @returns {Function} A new function that applies each given function on the result of the previous one.
34
25
  */
35
- export declare function flow(...args: any[]): (x: any) => any;
26
+ export declare function flow(...args: Function[]): Function;
36
27
  /**
37
28
  * This is just an alias for the {@link flow} function.
38
29
  * @see {@link flow}
@@ -43,7 +34,7 @@ export declare const pipe: typeof flow;
43
34
  * @param {...*} [args] The set of functions to apply.
44
35
  * @returns {Function} A new function that applies each given function on the result of the previous step.
45
36
  */
46
- export declare function compose(...args: any[]): (x: any) => any;
37
+ export declare function compose(...args: Function[]): Function;
47
38
  /**
48
39
  * 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.
49
40
  *
@@ -52,15 +43,6 @@ export declare function compose(...args: any[]): (x: any) => any;
52
43
  * @return {Function} Returns the new memoized function.
53
44
  */
54
45
  export declare function memoize<T>(func: Function<T>, resolver?: Function): Function<T>;
55
- /**
56
- * Can be used as a decorator on any function or method to memoize its results.
57
- * **NOTE:** By default the given function is memoized using it's first argument, regardless of others.
58
- * @param target
59
- * @param name
60
- * @param descriptor
61
- * @returns A memoized version of the given function
62
- */
63
- export declare function cache(target: any, name: any, descriptor: any): any;
64
46
  /**
65
47
  * 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.
66
48
  *
@@ -97,9 +79,9 @@ single(3) // 1
97
79
  ```
98
80
  */
99
81
  export declare function once<T>(func: Function<T>): Function<T>;
100
- export declare type Maybe<T> = T | undefined;
101
- export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
102
- export declare type Optional<T> = Maybe<T>;
82
+ export type Maybe<T> = T | undefined;
83
+ export type Result<T, E = any> = [Maybe<T>, Maybe<E>];
84
+ export type Optional<T> = Maybe<T>;
103
85
  /**
104
86
  * Wraps a function to catch any exceptions inside and return a {@link Result} tuple with the value and error, if any.
105
87
  * @template T,E
@@ -122,9 +104,3 @@ export declare function resultAsync<T = any, E = unknown>(fn: Function<Promise<T
122
104
  * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a `Promise`.
123
105
  */
124
106
  export declare function promisify<T>(fun: Function, thisArg?: any): Function<Promise<T>>;
125
- /**
126
- * Invokes a given function that accepts callback arguments for success, error and returns a `Promise` of the results.
127
- * @param {Function} fn A function that accepts callback arguments for success, error.
128
- * @returns {Promise<T>} A `Promise` that will be resolved when `successCallback` is called or rejected when `errorCallback` is called.
129
- */
130
- export declare function callAsync<T = any>(fn: (successCallback: (data: T) => any, errorCallback: Function) => any): Promise<T>;
@@ -4,18 +4,7 @@
4
4
  * @module functools
5
5
  */
6
6
  /**
7
- * Creates a function that invokes `fn` with the this binding of `thisArg` and `partials` as partially applied arguments.
8
- * @param {Function} fn The function to bind.
9
- * @param {*} thisArg The `this` value of `fn`.
10
- * @param {...*} [partials] The arguments to prepend to `fn`.
11
- * @returns {Function} Returns the new bound function.
12
- * @see {@link partial}
13
- */
14
- export function bind(fn, thisArg, ...partials) {
15
- return fn.bind(thisArg, ...partials);
16
- }
17
- /**
18
- * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on. The arity of `func` may be specified if `func.length` is not sufficient.
7
+ * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `func.length` arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
19
8
  * @param {Function} func The function to curry.
20
9
  * @returns Returns the new curried function.
21
10
  */
@@ -31,13 +20,13 @@ export function curry(func) {
31
20
  }
32
21
  /**
33
22
  * Creates a function that invokes `fn` with partials prepended to the arguments it receives.
34
- * **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider {@link bind} instead.
23
+ * **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider `Function.prototype.bind` instead.
35
24
  * @param {Function} fn The function to bind.
36
25
  * @param {...*} [args] The arguments to apply to `fn`.
37
26
  * @returns {Function} Returns the new partially applied function
38
27
  */
39
28
  export function partial(fn, ...args) {
40
- return bind(fn, undefined, ...args);
29
+ return fn.bind(undefined, ...args);
41
30
  }
42
31
  /**
43
32
  * Creates a function composition from a given set of functions that will be each applied on the result of the previous one from left to right.
@@ -63,7 +52,7 @@ export const pipe = flow;
63
52
  * @returns {Function} A new function that applies each given function on the result of the previous step.
64
53
  */
65
54
  export function compose(...args) {
66
- return flow(args.reverse());
55
+ return flow(...args.reverse());
67
56
  }
68
57
  /**
69
58
  * 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.
@@ -74,31 +63,15 @@ export function compose(...args) {
74
63
  */
75
64
  export function memoize(func, resolver) {
76
65
  const cache = new Map();
77
- return (...args) => {
78
- const key = resolver ? resolver(...args) : args[0];
79
- const prev = cache.get(key);
80
- if (prev !== undefined)
81
- return prev;
82
- const value = func(...args);
66
+ return function (...args) {
67
+ const key = resolver ? resolver.apply(this, args) : args[0];
68
+ if (cache.has(key))
69
+ return cache.get(key);
70
+ const value = func.apply(this, args);
83
71
  cache.set(key, value);
84
72
  return value;
85
73
  };
86
74
  }
87
- /**
88
- * Can be used as a decorator on any function or method to memoize its results.
89
- * **NOTE:** By default the given function is memoized using it's first argument, regardless of others.
90
- * @param target
91
- * @param name
92
- * @param descriptor
93
- * @returns A memoized version of the given function
94
- */
95
- export function cache(target, name, descriptor) {
96
- const original = descriptor.value;
97
- if (typeof original === 'function') {
98
- descriptor.value = memoize(original);
99
- }
100
- return descriptor;
101
- }
102
75
  /**
103
76
  * 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.
104
77
  *
@@ -108,20 +81,21 @@ export function cache(target, name, descriptor) {
108
81
  * @returns Returns the new debounced function.
109
82
  */
110
83
  export function debounce(func, wait, { maxWait } = {}) {
111
- let timer, maxTimer, lastResult;
112
- return (...args) => {
84
+ let timer, maxTimer, lastResult, latestCall;
85
+ return function (...args) {
86
+ latestCall = () => func.apply(this, args);
113
87
  if (timer)
114
88
  clearTimeout(timer);
115
89
  timer = setTimeout(() => {
116
90
  clearTimeout(maxTimer);
117
91
  maxTimer = null;
118
- lastResult = func(...args);
92
+ lastResult = func.apply(this, args);
119
93
  }, wait);
120
94
  if (maxWait && !maxTimer) {
121
95
  maxTimer = setTimeout(() => {
122
96
  clearTimeout(timer);
123
97
  maxTimer = null;
124
- lastResult = func(...args);
98
+ lastResult = latestCall();
125
99
  }, maxWait);
126
100
  }
127
101
  return lastResult;
@@ -136,14 +110,16 @@ export function debounce(func, wait, { maxWait } = {}) {
136
110
  */
137
111
  export function throttle(func, wait) {
138
112
  let pending = false;
139
- return (...args) => {
113
+ let lastResult;
114
+ return function (...args) {
140
115
  if (pending)
141
- return;
142
- func(...args);
116
+ return lastResult;
117
+ lastResult = func.apply(this, args);
143
118
  pending = true;
144
119
  setTimeout(() => {
145
120
  pending = false;
146
121
  }, wait);
122
+ return lastResult;
147
123
  };
148
124
  }
149
125
  /**
@@ -164,9 +140,9 @@ single(3) // 1
164
140
  */
165
141
  export function once(func) {
166
142
  let result, isCalled;
167
- return (...args) => {
143
+ return function (...args) {
168
144
  if (!isCalled) {
169
- result = func(...args);
145
+ result = func.apply(this, args);
170
146
  isCalled = true;
171
147
  }
172
148
  return result;
@@ -179,10 +155,10 @@ export function once(func) {
179
155
  * @returns {Function} A new function that wraps `fn` and returns the result tuple.
180
156
  */
181
157
  export function result(fn) {
182
- return (...args) => {
158
+ return function (...args) {
183
159
  let value, err;
184
160
  try {
185
- value = fn(...args);
161
+ value = fn.apply(this, args);
186
162
  }
187
163
  catch (error) {
188
164
  err = error;
@@ -197,10 +173,10 @@ export function result(fn) {
197
173
  * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the given function and returns the result tuple.
198
174
  */
199
175
  export function resultAsync(fn) {
200
- return async (...args) => {
176
+ return async function (...args) {
201
177
  let value, err;
202
178
  try {
203
- value = await fn(...args);
179
+ value = await fn.apply(this, args);
204
180
  }
205
181
  catch (error) {
206
182
  err = error;
@@ -225,11 +201,3 @@ export function promisify(fun, thisArg) {
225
201
  }));
226
202
  };
227
203
  }
228
- /**
229
- * Invokes a given function that accepts callback arguments for success, error and returns a `Promise` of the results.
230
- * @param {Function} fn A function that accepts callback arguments for success, error.
231
- * @returns {Promise<T>} A `Promise` that will be resolved when `successCallback` is called or rejected when `errorCallback` is called.
232
- */
233
- export async function callAsync(fn) {
234
- return await new Promise(fn);
235
- }
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * A generic function type with arbitrary arguments and return.
8
8
  */
9
- export declare type Function<TReturn = any> = (...args: any) => TReturn;
9
+ export type Function<TReturn = any> = (...args: any) => TReturn;
10
10
  /** This is just a noop function. */
11
11
  export declare function noop(): void;
12
12
  /** A function that always returns `true`. */
@@ -22,9 +22,10 @@ export declare class CustomError extends Error {
22
22
  /**
23
23
  * Returns a new CustomError with the specified message.
24
24
  * @param {string} message
25
+ * @param {ErrorOptions} [options] Standard error options such as `cause`.
25
26
  * @constructor
26
27
  */
27
- constructor(message?: string);
28
+ constructor(message?: string, options?: ErrorOptions);
28
29
  }
29
30
  /**
30
31
  * Custom error to signal an invalid index access.
@@ -76,7 +77,7 @@ export declare function type(value: any): string;
76
77
  * @returns `obj.toString()` or `''` if `obj` is `null` or `undefined`.
77
78
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
78
79
  */
79
- export declare function str(obj: any): any;
80
+ export declare function str(obj: any): string;
80
81
  /** Check if value is a boolean type. */
81
82
  export declare function isBool(x: any): x is boolean;
82
83
  /** Check if value is an `Error` type. */
@@ -89,8 +90,6 @@ export declare function isDate(x: any): x is Date;
89
90
  export declare function isObject(x: any): x is Object;
90
91
  /** Check if value is a string type. */
91
92
  export declare function isString(x: any): x is string;
92
- /** Check if value is an Array type. */
93
- export declare function isArray(x: any): x is any[];
94
93
  /**
95
94
  * Check if value is Array-like type.
96
95
  * A value is considered array-like if it's not a function and has a `.length` number property.
@@ -98,8 +97,6 @@ export declare function isArray(x: any): x is any[];
98
97
  export declare function isArrayLike(x: any): boolean;
99
98
  /** Check if value is a number type. */
100
99
  export declare function isNumber(x: any): x is number;
101
- /** Check if value is an integer number type. */
102
- export declare function isInteger(x: any): x is number;
103
100
  /** Check if value is a bigint type. */
104
101
  export declare function isBigint(x: any): x is BigInt;
105
102
  /** Check if value is a Promise type. */
@@ -170,25 +167,11 @@ export declare function uuid(): string;
170
167
  * @param {...any[]} args
171
168
  * @return `obj.key(...args)` or `undefined`.
172
169
  */
173
- export declare function call(obj: any, key: PropertyKey, ...args: any[]): any;
170
+ export declare function call<T = any>(obj: any, key: PropertyKey, ...args: any[]): T;
174
171
  /** Convert number to unicode character */
175
172
  export declare function chr(x: number): string;
176
173
  /** Convert character to Unicode code point */
177
174
  export declare function ord(x: string): number;
178
- /**
179
- * Returns an array of the own enumerable property names of `object`.
180
- * @param object The given object.
181
- * @returns The array of object keys.
182
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
183
- */
184
- export declare function keys<T>(object: T): (keyof T)[];
185
- /**
186
- * Returns an array of the own enumerable property values of `object`.
187
- * @param object The given object.
188
- * @returns The array of object keys.
189
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Object.values()}
190
- */
191
- export declare function values(object: any): unknown[];
192
175
  /**
193
176
  * Check if a given property is present in a given object.
194
177
  * @param obj The object to check.