atomic-fns 0.4.3 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,378 @@
1
+ /**
2
+ * `Decimal` provides support for correct rounded floating point arithmetic.
3
+ *
4
+ * @module decimal
5
+ */
6
+ const NUMBER_REGEX = /^(-?)([0-9]+)(\.([0-9]+))?$/;
7
+ /**
8
+ * Casts the given value as a {@link Decimal}.
9
+ */
10
+ export function decimal(x) {
11
+ return new Decimal(x);
12
+ }
13
+ /**
14
+ * `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard
15
+ * `Number` type. It also supports user-defined precision (default is 20 decimal places), which
16
+ * can be as large as needed.
17
+ */
18
+ export class Decimal {
19
+ static PRECISION = 20;
20
+ i = 0n;
21
+ e = 0;
22
+ /**
23
+ * Returns a new `Decimal` instance from the value or `0`.
24
+ * @param {*} value
25
+ * @returns {Decimal}
26
+ */
27
+ constructor(value) {
28
+ if (value == null) {
29
+ return this;
30
+ }
31
+ // Check if value is a Decimal like
32
+ if (typeof value?.i === 'bigint' && typeof value.e === 'number') {
33
+ this.i = value.i;
34
+ this.e = value.e;
35
+ this._normalize();
36
+ return this;
37
+ }
38
+ const result = NUMBER_REGEX.exec(value.toString());
39
+ if (result) {
40
+ // console.log(result);
41
+ // Construct from string if possible
42
+ // this.i = parseInt(result[1] + result[2] + result[4]);
43
+ if (typeof result[2] === 'undefined')
44
+ result[2] = '';
45
+ if (typeof result[4] === 'undefined')
46
+ result[4] = '';
47
+ this.i = BigInt(result[1] + result[2] + result[4]);
48
+ this.e = result[4] ? -result[4].length : 0;
49
+ this._normalize();
50
+ }
51
+ else {
52
+ // Conversion to string failed, so construct from number
53
+ let m = 1n;
54
+ if (value < 0) {
55
+ value = -value;
56
+ m = -1n;
57
+ }
58
+ if (value === 0) {
59
+ this.i = 0n;
60
+ this.e = 0;
61
+ }
62
+ else {
63
+ // Multiply the number by 10 until it is an integer
64
+ let e = -Math.floor(Math.log10(value));
65
+ if (e > 0) {
66
+ value *= Math.pow(10, e);
67
+ }
68
+ else {
69
+ e = 0;
70
+ }
71
+ while (value !== Math.round(value)) {
72
+ e++;
73
+ value *= 10;
74
+ }
75
+ // Divide the number by 10 until the one's digit is non-zero
76
+ while (value % 10 === 0 && value > 0) {
77
+ e--;
78
+ value /= 10;
79
+ }
80
+ value = BigInt(value);
81
+ this.i = value * m;
82
+ this.e = -e;
83
+ }
84
+ }
85
+ }
86
+ /**
87
+ * Returns a new `Decimal` that has the opposite sign of this `Decimal`.
88
+ * @example
89
+ ```js
90
+ let a = decimal('5')
91
+ a.negated() // -5
92
+ ```
93
+ * @returns {Decimal}
94
+ */
95
+ negated() {
96
+ const negated = new Decimal();
97
+ negated.i = -this.i;
98
+ negated.e = this.e;
99
+ return negated;
100
+ }
101
+ /**
102
+ * Returns a new `Decimal` that is the sum of this and `x`.
103
+ * @param x
104
+ * @example
105
+ ```js
106
+ let a = decimal('50000000000')
107
+ let b = decimal('0.000000005')
108
+ a.add(b) // 50000000000.000000005
109
+ ```
110
+ * @returns {Decimal}
111
+ */
112
+ add(x) {
113
+ let a = new Decimal(this);
114
+ let b = new Decimal(x);
115
+ // a+b = a.i * 10^a.e + b.i * 10^b.e
116
+ // a+b = ( a.i * 10^(a.e-b.e) + b.i ) * 10^b.e
117
+ const result = new Decimal();
118
+ // Order arguments so that a.e >= b.e
119
+ if (a.e < b.e) {
120
+ const c = a;
121
+ a = b;
122
+ b = c;
123
+ }
124
+ const intPart = exp(a.i, a.e - b.e);
125
+ result.i = intPart + b.i;
126
+ result.e = b.e;
127
+ result._normalize();
128
+ return result;
129
+ }
130
+ /**
131
+ * Returns a new `Decimal` that is the difference between this and `x`.
132
+ * @param x
133
+ * @example
134
+ ```js
135
+ let a = decimal('1')
136
+ let b = decimal('0.0000000000000000001')
137
+ a.sub(b) // 0.9999999999999999999
138
+ ```
139
+ * @returns {Decimal}
140
+ */
141
+ sub(x) {
142
+ return this.add(decimal(x).negated());
143
+ }
144
+ /**
145
+ * Returns a new `Decimal` that is the product of this and `x`.
146
+ * @param x
147
+ * @example
148
+ ```js
149
+ let a = decimal('0.0000000000000000000025')
150
+ let b = decimal('400000000000000000000')
151
+ a.mul(b) // 1
152
+ ```
153
+ * @returns {Decimal}
154
+ */
155
+ mul(x) {
156
+ const a = new Decimal(this);
157
+ const b = new Decimal(x);
158
+ // a * b = (a.i * b.i) * 10^(a.e + b.e)
159
+ const result = new Decimal();
160
+ result.i = a.i * b.i;
161
+ result.e = a.e + b.e;
162
+ result._normalize();
163
+ return result;
164
+ }
165
+ /**
166
+ * Returns a new `Decimal` that is the quotient of this and `x`
167
+ * @param x
168
+ * @example
169
+ ```js
170
+ let a = decimal('1')
171
+ let b = decimal('3')
172
+ a.div(b) // 0.333333333333333333333333333333
173
+ ```
174
+ * @returns {Decimal}
175
+ */
176
+ div(x) {
177
+ const a = new Decimal(this);
178
+ const b = new Decimal(x);
179
+ // We need to increase the number of digits of a and b so that a / b will have the desired precision.
180
+ // In order for the integer quotient to have the correct precision, a.e - b.e must be greater than that precision.
181
+ // 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);
184
+ const intIncrease = new Decimal();
185
+ intIncrease.i = exp(a.i, increaseA);
186
+ const quotient = new Decimal();
187
+ quotient.i = intIncrease.i / b.i;
188
+ quotient.e = a.e - b.e - increaseA;
189
+ // No need to truncate since we already increased the number of digits before dividing
190
+ quotient._normalize();
191
+ return quotient;
192
+ }
193
+ /**
194
+ * Returns the square root of this `Decimal`.
195
+ * @returns {TDecimal}
196
+ */
197
+ sqrt() {
198
+ Decimal.PRECISION++;
199
+ // Let the guess value be 10^(e/2), where e is this.e
200
+ let x = new Decimal();
201
+ x.i = 1n;
202
+ x.e = Math.floor(this.e / 2);
203
+ const onehalf = new Decimal('0.5');
204
+ let xt = x.clone();
205
+ xt._truncate();
206
+ xt._normalize();
207
+ let lastxt;
208
+ let i;
209
+ for (i = 0; i < 100; i++) {
210
+ lastxt = xt;
211
+ x = this.div(x).add(x).mul(onehalf);
212
+ xt = x.clone();
213
+ xt._truncate();
214
+ xt._normalize();
215
+ if (xt.i === lastxt.i && xt.e === lastxt.e)
216
+ break;
217
+ }
218
+ if (i >= 100) {
219
+ console.log('Warning: sqrt exceeded maximum iterations. (Did it enter a cycle?)');
220
+ }
221
+ Decimal.PRECISION--;
222
+ xt._truncate();
223
+ xt._normalize();
224
+ return xt;
225
+ }
226
+ /** Returns a new copy of this Decimal value. */
227
+ clone() {
228
+ const a = new Decimal();
229
+ a.i = this.i;
230
+ a.e = this.e;
231
+ return a;
232
+ }
233
+ /**
234
+ * Remove zeroes in the least-significant digit of this `Decimal`
235
+ */
236
+ _normalize() {
237
+ while (this.i % 10n === 0n && this.i !== 0n) {
238
+ this.i /= 10n;
239
+ this.e++;
240
+ }
241
+ return this;
242
+ }
243
+ /**
244
+ * Truncate this `Decimal` to the configured precision
245
+ */
246
+ _truncate() {
247
+ // TODO: Make this better
248
+ // TODO: Rounding
249
+ const trunc = -this.e - Decimal.PRECISION;
250
+ if (trunc > 0) {
251
+ this.i /= 10n ** BigInt(trunc - 1);
252
+ this.e += trunc;
253
+ const nextDigit = this.i % 10n;
254
+ if (nextDigit >= 5) {
255
+ this.i += 10n;
256
+ }
257
+ this.i /= 10n;
258
+ }
259
+ // while(-this.e > Decimal.PRECISION) {
260
+ // this.i /= 10n;
261
+ // this.e++;
262
+ // }
263
+ return this;
264
+ }
265
+ /**
266
+ * Returns a string representation of this decimal.
267
+ * @returns {Decimal}
268
+ */
269
+ toString() {
270
+ let s = this.i.toString();
271
+ let m = '';
272
+ if (s[0] === '-') {
273
+ s = s.substring(1, s.length);
274
+ m = '-';
275
+ }
276
+ if (this.e > 0) {
277
+ return m + s + '0'.repeat(this.e);
278
+ }
279
+ else if (this.e < 0) {
280
+ if (-this.e >= s.length) {
281
+ return m + '0.' + '0'.repeat(-this.e - s.length) + s;
282
+ }
283
+ return m + s.slice(0, s.length + this.e) + '.' + s.slice(s.length + this.e, s.length);
284
+ }
285
+ else {
286
+ return m + s;
287
+ }
288
+ }
289
+ [Symbol.for('nodejs.util.inspect.custom')]() {
290
+ return this.toString();
291
+ }
292
+ /**
293
+ * Converts this decimal to the `Number` value
294
+ * @returns {number}
295
+ */
296
+ toNumber() {
297
+ return Number(Decimal.prototype.toString.call(this));
298
+ }
299
+ static get precision() {
300
+ return Decimal.PRECISION;
301
+ }
302
+ static set precision(value) {
303
+ Decimal.PRECISION = value;
304
+ }
305
+ /**
306
+ * Returns `true` if this value is equal to the value of `x`, otherwise `false`.
307
+ * @param {*} x other
308
+ * @returns {boolean}
309
+ */
310
+ eq(x) {
311
+ const other = decimal(x);
312
+ return this.i === other.i && this.e === other.e;
313
+ }
314
+ /**
315
+ * Returns `true` if this value is less than the value of `x`, otherwise `false`.
316
+ * @param {*} x
317
+ * @returns {boolean}
318
+ */
319
+ lt(x) {
320
+ const other = decimal(x);
321
+ if (this.e === other.e)
322
+ return this.i < other.i;
323
+ const e = this.e - other.e;
324
+ if (e > 0) {
325
+ return exp(this.i, e) < other.i;
326
+ }
327
+ return this.i < exp(other.i, -e);
328
+ }
329
+ /**
330
+ * Returns a comparison value representing the ordering of this value in respect to `x`.
331
+ * * `-1` if this < x
332
+ * * `1` if this > x
333
+ * * `0` if this == x
334
+ * @param {*} x
335
+ * @returns {number}
336
+ */
337
+ compare(x) {
338
+ if (this.eq(x))
339
+ return 0;
340
+ if (this.lt(x))
341
+ return -1;
342
+ return 1;
343
+ }
344
+ /**
345
+ * Returns `true` if this value is greater than the value of `x`, otherwise `false`.
346
+ * @param {*} x
347
+ * @returns {boolean}
348
+ */
349
+ gt(x) {
350
+ return this.compare(x) > 0;
351
+ }
352
+ /**
353
+ * Returns `true` if this value is less than or equal to the value of `x`, otherwise `false`.
354
+ * @param {*} x
355
+ * @returns {boolean}
356
+ */
357
+ lte(x) {
358
+ return this.compare(x) <= 0;
359
+ }
360
+ /**
361
+ * Returns `true` if this value is greater than or equal to the value of `x`, otherwise `false`.
362
+ * @param {*} x
363
+ * @returns {boolean}
364
+ */
365
+ gte(x) {
366
+ return this.compare(x) >= 0;
367
+ }
368
+ }
369
+ /** Returns a BigInt that is equal to `i` times `10^e` */
370
+ 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;
378
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This module includes functions that promote a more functional programming style.
3
3
  *
4
- * @module Functions
4
+ * @module functools
5
5
  */
6
6
  import { Function } from '../globals/index.js';
7
7
  /**
@@ -16,10 +16,9 @@ export declare const bind: (fn: Function, thisArg: any, ...partials: any[]) => a
16
16
  /**
17
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.
18
18
  * @param {Function} func The function to curry.
19
- * @param {number} [arity=func.length]
20
19
  * @returns Returns the new curried function.
21
20
  */
22
- export declare const curry: (func: Function, arity?: number) => Function<any>;
21
+ export declare const curry: (func: Function) => (...args: any[]) => any;
23
22
  /**
24
23
  * Creates a function that invokes `fn` with partials prepended to the arguments it receives.
25
24
  * **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider {@link bind} instead.
@@ -39,6 +38,11 @@ export declare const flow: (...args: any[]) => (x: any) => any;
39
38
  * @see {@link flow}
40
39
  */
41
40
  export declare const pipe: (...args: any[]) => (x: any) => any;
41
+ /**
42
+ * Creates a function composition from a given set of functions that will be each applied on the result of the previous one from right to left.
43
+ * @param {...*} [args] The set of functions to apply.
44
+ * @returns {Function} A new function that applies each given function on the result of the previous step.
45
+ */
42
46
  export declare const compose: (...args: any[]) => (x: any) => any;
43
47
  /**
44
48
  * 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.
@@ -97,26 +101,30 @@ export declare type Maybe<T> = T | undefined;
97
101
  export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
98
102
  export declare type Optional<T> = Maybe<T>;
99
103
  /**
100
- * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
104
+ * Wraps a function to catch any exceptions inside and return a {@link Result} tuple with the value and error, if any.
101
105
  * @template T,E
102
- * @param {Function} fun The function to wrap and catch if it throws.
103
- * @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
104
- * @returns {Function} A new function that wraps `fun`.
106
+ * @param {Function<T>} fn The function to wrap.
107
+ * @returns {Function} A new function that wraps `fn` and returns the result tuple.
105
108
  */
106
- export declare function result<T = any, E = unknown>(fun: Function<T>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Result<T, E>;
109
+ export declare function result<T = any, E = unknown>(fn: Function<T>): Function<Result<T, E>>;
107
110
  /**
108
- * Wraps a function or promise to catch any exceptions inside and return a `go` style error-return type. This is like {@link result} but it deals with async functions or promises.
111
+ * Wraps an async function to catch any exceptions inside and return a {@link Result} tuple with the value and error, if any.
109
112
  * @template T,E
110
- * @param {Function<T>|Promise<T>} awaitable The function or promise to await.
111
- * @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
112
- * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the `awaitable` param and returns a {@link Result} type.
113
+ * @param {Function<Promise<T>>} fn The async function to await.
114
+ * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the given function and returns the result tuple.
113
115
  */
114
- export declare function resultAsync<T = any, E = unknown>(awaitable: Promise<T> | Function<Promise<T>>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Promise<any[]>;
116
+ export declare function resultAsync<T = any, E = unknown>(fn: Function<Promise<T>>): Function<Promise<Result<T, E>>>;
115
117
  /**
116
- * Converts a function that expects a node-style callback argument like `(err, result)` to return a Promise instead.
118
+ * Converts a function that expects a node-style callback argument like `(err, result)` to return a `Promise` instead.
117
119
  * @template T
118
- * @param {Function<T>} fun The given function to convert from callback style to Promise.
120
+ * @param {Function<T>} fun The given function to convert from callback style to `Promise`.
119
121
  * @param {*} thisArg
120
- * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
122
+ * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a `Promise`.
121
123
  */
122
124
  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>;
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * This module includes functions that promote a more functional programming style.
3
3
  *
4
- * @module Functions
4
+ * @module functools
5
5
  */
6
- import { isPromise } from '../globals/index.js';
7
6
  /**
8
7
  * Creates a function that invokes `fn` with the this binding of `thisArg` and `partials` as partially applied arguments.
9
8
  * @param {Function} fn The function to bind.
@@ -16,34 +15,17 @@ export const bind = (fn, thisArg, ...partials) => fn.bind(thisArg, ...partials);
16
15
  /**
17
16
  * 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.
18
17
  * @param {Function} func The function to curry.
19
- * @param {number} [arity=func.length]
20
18
  * @returns Returns the new curried function.
21
19
  */
22
- export const curry = (func, arity) => {
23
- if (typeof func !== 'function' || func.length < 2)
24
- return func;
25
- if (typeof arity !== 'number')
26
- arity = func.length;
27
- switch (arity) {
28
- case 2:
29
- return (arg0) => (arg1) => func(arg0, arg1);
30
- case 3:
31
- return (arg0) => (arg1) => (arg2) => func(arg0, arg1, arg2);
32
- case 4:
33
- return (arg0) => (arg1) => (arg2) => (arg3) => func(arg0, arg1, arg2, arg3);
34
- case 5:
35
- return (arg0) => (arg1) => (arg2) => (arg3) => (arg4) => func(arg0, arg1, arg2, arg3, arg4);
36
- case 6:
37
- return (arg0) => (arg1) => (arg2) => (arg3) => (arg4) => (arg5) => func(arg0, arg1, arg2, arg3, arg4, arg5);
38
- case 7:
39
- return (arg0) => (arg1) => (arg2) => (arg3) => (arg4) => (arg5) => (arg6) => func(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
40
- case 8:
41
- return (arg0) => (arg1) => (arg2) => (arg3) => (arg4) => (arg5) => (arg6) => (arg7) => func(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
42
- case 9:
43
- return (arg0) => (arg1) => (arg2) => (arg3) => (arg4) => (arg5) => (arg6) => (arg7) => (arg8) => func(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
44
- default:
45
- throw Error('The specified function uses too many arguments. Consider refactoring it.');
46
- }
20
+ export const curry = (func) => {
21
+ return function curried(...args) {
22
+ if (args.length >= func.length) {
23
+ return func.apply(this, args);
24
+ }
25
+ return (...args2) => {
26
+ return curried.apply(this, args.concat(args2));
27
+ };
28
+ };
47
29
  };
48
30
  /**
49
31
  * Creates a function that invokes `fn` with partials prepended to the arguments it receives.
@@ -69,6 +51,11 @@ export const flow = (...args) => (x) => {
69
51
  * @see {@link flow}
70
52
  */
71
53
  export const pipe = flow;
54
+ /**
55
+ * Creates a function composition from a given set of functions that will be each applied on the result of the previous one from right to left.
56
+ * @param {...*} [args] The set of functions to apply.
57
+ * @returns {Function} A new function that applies each given function on the result of the previous step.
58
+ */
72
59
  export const compose = (...args) => flow(args.reverse());
73
60
  /**
74
61
  * 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.
@@ -178,56 +165,47 @@ export function once(func) {
178
165
  };
179
166
  }
180
167
  /**
181
- * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
168
+ * Wraps a function to catch any exceptions inside and return a {@link Result} tuple with the value and error, if any.
182
169
  * @template T,E
183
- * @param {Function} fun The function to wrap and catch if it throws.
184
- * @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
185
- * @returns {Function} A new function that wraps `fun`.
170
+ * @param {Function<T>} fn The function to wrap.
171
+ * @returns {Function} A new function that wraps `fn` and returns the result tuple.
186
172
  */
187
- export function result(fun, onFinally) {
173
+ export function result(fn) {
188
174
  return (...args) => {
189
175
  let value, err;
190
176
  try {
191
- value = fun(...args);
177
+ value = fn(...args);
192
178
  }
193
179
  catch (error) {
194
180
  err = error;
195
181
  }
196
- finally {
197
- onFinally?.(err, value);
198
- }
199
182
  return [value, err];
200
183
  };
201
184
  }
202
185
  /**
203
- * Wraps a function or promise to catch any exceptions inside and return a `go` style error-return type. This is like {@link result} but it deals with async functions or promises.
186
+ * Wraps an async function to catch any exceptions inside and return a {@link Result} tuple with the value and error, if any.
204
187
  * @template T,E
205
- * @param {Function<T>|Promise<T>} awaitable The function or promise to await.
206
- * @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
207
- * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the `awaitable` param and returns a {@link Result} type.
188
+ * @param {Function<Promise<T>>} fn The async function to await.
189
+ * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the given function and returns the result tuple.
208
190
  */
209
- export function resultAsync(awaitable, onFinally) {
191
+ export function resultAsync(fn) {
210
192
  return async (...args) => {
211
193
  let value, err;
212
194
  try {
213
- const promise = isPromise(awaitable) ? awaitable : awaitable(...args);
214
- value = await promise;
195
+ value = await fn(...args);
215
196
  }
216
197
  catch (error) {
217
198
  err = error;
218
199
  }
219
- finally {
220
- onFinally?.(err, value);
221
- }
222
200
  return [value, err];
223
201
  };
224
202
  }
225
203
  /**
226
- * Converts a function that expects a node-style callback argument like `(err, result)` to return a Promise instead.
204
+ * Converts a function that expects a node-style callback argument like `(err, result)` to return a `Promise` instead.
227
205
  * @template T
228
- * @param {Function<T>} fun The given function to convert from callback style to Promise.
206
+ * @param {Function<T>} fun The given function to convert from callback style to `Promise`.
229
207
  * @param {*} thisArg
230
- * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
208
+ * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a `Promise`.
231
209
  */
232
210
  export function promisify(fun, thisArg) {
233
211
  const original = thisArg ? fun.bind(thisArg) : fun;
@@ -239,3 +217,11 @@ export function promisify(fun, thisArg) {
239
217
  }));
240
218
  };
241
219
  }
220
+ /**
221
+ * Invokes a given function that accepts callback arguments for success, error and returns a `Promise` of the results.
222
+ * @param {Function} fn A function that accepts callback arguments for success, error.
223
+ * @returns {Promise<T>} A `Promise` that will be resolved when `successCallback` is called or rejected when `errorCallback` is called.
224
+ */
225
+ export async function callAsync(fn) {
226
+ return await new Promise(fn);
227
+ }
@@ -7,8 +7,8 @@ export declare function decimal(x: any): Decimal;
7
7
  */
8
8
  export declare class Decimal {
9
9
  static PRECISION: number;
10
- i: bigint;
11
- e: number;
10
+ private i;
11
+ private e;
12
12
  /**
13
13
  * Returns a new `Decimal` instance from the value or `0`.
14
14
  * @param {*} value
@@ -83,11 +83,11 @@ export declare class Decimal {
83
83
  /**
84
84
  * Remove zeroes in the least-significant digit of this `Decimal`
85
85
  */
86
- _normalize(): this;
86
+ private _normalize;
87
87
  /**
88
88
  * Truncate this `Decimal` to the configured precision
89
89
  */
90
- _truncate(): this;
90
+ private _truncate;
91
91
  /**
92
92
  * Returns a string representation of this decimal.
93
93
  * @returns {Decimal}
@@ -1,30 +1,14 @@
1
1
  /**
2
2
  * This module includes global functions and constants.
3
3
  *
4
- * @module Globals
4
+ * @module globals
5
5
  */
6
- export * from './decimal.js';
7
- /** This is just a noop function. */
8
- export declare const noop: () => void;
9
6
  /**
10
7
  * A generic function type with arbitrary arguments and return.
11
8
  */
12
9
  export declare type Function<TReturn = any> = (...args: any) => TReturn;
13
- /**
14
- * An iteratee function used for collection methods.
15
- * @see {@link Collections.filter}
16
- * @see {@link Collections.find}
17
- * @see {@link Collections.forEach}
18
- * @see {@link Collections.index}
19
- * @see {@link Collections.map}
20
- * @see {@link Collections.pick}
21
- * @see {@link Collections.omit}
22
- * @see {@link Collections.uniq}
23
- * @see {@link Collections.sortedUniq}
24
- * @see {@link Collections.groupBy}
25
- */
26
- export declare type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
27
- export declare type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
10
+ /** This is just a noop function. */
11
+ export declare const noop: () => void;
28
12
  /** A function that always returns `true`. */
29
13
  export declare const True: () => boolean;
30
14
  /** A function that always returns `false`. */
@@ -197,7 +181,7 @@ export declare const ord: (x: string) => number;
197
181
  * @returns The array of object keys.
198
182
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
199
183
  */
200
- export declare const keys: (object: Object) => string[];
184
+ export declare const keys: <T>(object: T) => (keyof T)[];
201
185
  /**
202
186
  * Returns an array of the own enumerable property values of `object`.
203
187
  * @param object The given object.
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * This module includes global functions and constants.
3
3
  *
4
- * @module Globals
4
+ * @module globals
5
5
  */
6
- export * from './decimal.js';
7
6
  /** This is just a noop function. */
8
7
  export const noop = () => { };
9
8
  /** A function that always returns `true`. */