atomic-fns 0.4.2 → 0.4.3

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.
@@ -47,7 +47,7 @@ export declare const compose: (...args: any[]) => (x: any) => any;
47
47
  * @param {Function} [resolver] The function to resolve the cache key.
48
48
  * @return {Function} Returns the new memoized function.
49
49
  */
50
- export declare function memoize<T>(func: Function<T>, resolver?: Function): Function<ReturnType<typeof func>>;
50
+ export declare function memoize<T>(func: Function<T>, resolver?: Function): Function<T>;
51
51
  /**
52
52
  * Can be used as a decorator on any function or method to memoize its results.
53
53
  * **NOTE:** By default the given function is memoized using it's first argument, regardless of others.
@@ -92,7 +92,7 @@ single(3) // 1
92
92
  // `func` is invoked only once.
93
93
  ```
94
94
  */
95
- export declare function once<T>(func: Function<T>): (...args: any[]) => T;
95
+ export declare function once<T>(func: Function<T>): Function<T>;
96
96
  export declare type Maybe<T> = T | undefined;
97
97
  export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
98
98
  export declare type Optional<T> = Maybe<T>;
@@ -111,7 +111,7 @@ export declare function result<T = any, E = unknown>(fun: Function<T>, onFinally
111
111
  * @param {Function} [onFinally] Optional callback that will be invoked with `(err?, value)` on the `finally` clause.
112
112
  * @returns {Function<Promise<Result<T, E>>>} A new function that awaits the `awaitable` param and returns a {@link Result} type.
113
113
  */
114
- export declare function resultAsync<T = any, E = unknown>(awaitable: Promise<T> | Function<Promise<T>>, onFinally?: (err: E, res: T) => any): (...args: any[]) => Promise<Result<T, E>>;
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[]>;
115
115
  /**
116
116
  * Converts a function that expects a node-style callback argument like `(err, result)` to return a Promise instead.
117
117
  * @template T
@@ -119,4 +119,4 @@ export declare function resultAsync<T = any, E = unknown>(awaitable: Promise<T>
119
119
  * @param {*} thisArg
120
120
  * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
121
121
  */
122
- export declare function promisify<T = any>(fun: Function<T>, thisArg: any): (...args: any[]) => Promise<T>;
122
+ export declare function promisify<T>(fun: Function, thisArg?: any): Function<Promise<T>>;
@@ -230,7 +230,7 @@ export function resultAsync(awaitable, onFinally) {
230
230
  * @returns {Function<Promise<T>>} A function that wraps `fun` and returns a Promise.
231
231
  */
232
232
  export function promisify(fun, thisArg) {
233
- const original = fun.bind(thisArg);
233
+ const original = thisArg ? fun.bind(thisArg) : fun;
234
234
  return async (...args) => {
235
235
  return await new Promise((resolve, reject) => original(...args, (err, result) => {
236
236
  if (err)
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Casts the given value as a {@link Decimal}.
3
+ */
4
+ export declare function decimal(x: any): Decimal;
5
+ /**
6
+ * `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard Number type. It also supports user-defined precision (default is 20 decimal places) which can be as large as needed.
7
+ */
8
+ export declare class Decimal {
9
+ static PRECISION: number;
10
+ i: bigint;
11
+ e: number;
12
+ /**
13
+ * Returns a new `Decimal` instance from the value or `0`.
14
+ * @param {*} value
15
+ * @returns {Decimal}
16
+ */
17
+ constructor(value?: any);
18
+ /**
19
+ * Returns a new `Decimal` that has the opposite sign of this `Decimal`.
20
+ * @example
21
+ ```js
22
+ let a = decimal('5')
23
+ a.minus() // -5
24
+ ```
25
+ * @returns {Decimal}
26
+ */
27
+ negated(): Decimal;
28
+ /**
29
+ * Returns a new `Decimal` that is the sum of this and `x`.
30
+ * @param x
31
+ * @example
32
+ ```js
33
+ let a = decimal('50000000000')
34
+ let b = decimal('0.000000005')
35
+ a.add(b) // 50000000000.000000005
36
+ ```
37
+ * @returns {Decimal}
38
+ */
39
+ add(x: any): Decimal;
40
+ /**
41
+ * Returns a new `Decimal` that is the difference between this and `x`.
42
+ * @param x
43
+ * @example
44
+ ```js
45
+ let a = decimal('1')
46
+ let b = decimal('0.0000000000000000001')
47
+ a.sub(b) // 0.9999999999999999999
48
+ ```
49
+ * @returns {Decimal}
50
+ */
51
+ sub(x: any): Decimal;
52
+ /**
53
+ * Returns a new `Decimal` that is the product of this and `x`.
54
+ * @param x
55
+ * @example
56
+ ```js
57
+ let a = decimal('0.0000000000000000000025')
58
+ let b = decimal('400000000000000000000')
59
+ a.mul(b) // 1
60
+ ```
61
+ * @returns {Decimal}
62
+ */
63
+ mul(x: any): Decimal;
64
+ /**
65
+ * Returns a new `Decimal` that is the quotient of this and `x`
66
+ * @param x
67
+ * @example
68
+ ```js
69
+ let a = decimal('1')
70
+ let b = decimal('3')
71
+ a.div(b) // 0.333333333333333333333333333333
72
+ ```
73
+ * @returns {Decimal}
74
+ */
75
+ div(x: any): Decimal;
76
+ /**
77
+ * Returns the square root of this `Decimal`.
78
+ * @returns {TDecimal}
79
+ */
80
+ sqrt(): Decimal;
81
+ /** Returns a new copy of this Decimal value. */
82
+ clone(): Decimal;
83
+ /**
84
+ * Remove zeroes in the least-significant digit of this `Decimal`
85
+ */
86
+ _normalize(): this;
87
+ /**
88
+ * Truncate this `Decimal` to the configured precision
89
+ */
90
+ _truncate(): this;
91
+ /**
92
+ * Returns a string representation of this decimal.
93
+ * @returns {Decimal}
94
+ */
95
+ toString(): string;
96
+ /**
97
+ * Converts this decimal to the `Number` value
98
+ * @returns {number}
99
+ */
100
+ toNumber(): number;
101
+ static get precision(): number;
102
+ static set precision(value: number);
103
+ /**
104
+ * Returns `true` if this value is equal to the value of `x`, otherwise `false`.
105
+ * @param {*} x other
106
+ * @returns {boolean}
107
+ */
108
+ eq(x: any): boolean;
109
+ /**
110
+ * Returns `true` if this value is less than the value of `x`, otherwise `false`.
111
+ * @param {*} x
112
+ * @returns {boolean}
113
+ */
114
+ lt(x: any): boolean;
115
+ /**
116
+ * Returns a comparison value representing the ordering of this value in respect to `x`.
117
+ * * `-1` if this < x
118
+ * * `1` if this > x
119
+ * * `0` if this == x
120
+ * @param {*} x
121
+ * @returns {number}
122
+ */
123
+ compare(x: any): 1 | -1 | 0;
124
+ /**
125
+ * Returns `true` if this value is greater than the value of `x`, otherwise `false`.
126
+ * @param {*} x
127
+ * @returns {boolean}
128
+ */
129
+ gt(x: any): boolean;
130
+ /**
131
+ * Returns `true` if this value is less than or equal to the value of `x`, otherwise `false`.
132
+ * @param {*} x
133
+ * @returns {boolean}
134
+ */
135
+ lte(x: any): boolean;
136
+ /**
137
+ * Returns `true` if this value is greater than or equal to the value of `x`, otherwise `false`.
138
+ * @param {*} x
139
+ * @returns {boolean}
140
+ */
141
+ gte(x: any): boolean;
142
+ }
@@ -0,0 +1,371 @@
1
+ const NUMBER_REGEX = /^(-?)([0-9]+)(\.([0-9]+))?$/;
2
+ /**
3
+ * Casts the given value as a {@link Decimal}.
4
+ */
5
+ export function decimal(x) {
6
+ return new Decimal(x);
7
+ }
8
+ /**
9
+ * `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard Number type. It also supports user-defined precision (default is 20 decimal places) which can be as large as needed.
10
+ */
11
+ export class Decimal {
12
+ static PRECISION = 20;
13
+ i = 0n;
14
+ e = 0;
15
+ /**
16
+ * Returns a new `Decimal` instance from the value or `0`.
17
+ * @param {*} value
18
+ * @returns {Decimal}
19
+ */
20
+ constructor(value) {
21
+ if (value == null) {
22
+ return this;
23
+ }
24
+ // Check if value is a Decimal like
25
+ if (typeof value?.i === 'bigint' && typeof value.e === 'number') {
26
+ this.i = value.i;
27
+ this.e = value.e;
28
+ this._normalize();
29
+ return this;
30
+ }
31
+ const result = NUMBER_REGEX.exec(value.toString());
32
+ if (result) {
33
+ // console.log(result);
34
+ // Construct from string if possible
35
+ // this.i = parseInt(result[1] + result[2] + result[4]);
36
+ if (typeof result[2] === 'undefined')
37
+ result[2] = '';
38
+ if (typeof result[4] === 'undefined')
39
+ result[4] = '';
40
+ this.i = BigInt(result[1] + result[2] + result[4]);
41
+ this.e = result[4] ? -result[4].length : 0;
42
+ this._normalize();
43
+ }
44
+ else {
45
+ // Conversion to string failed, so construct from number
46
+ let m = 1n;
47
+ if (value < 0) {
48
+ value = -value;
49
+ m = -1n;
50
+ }
51
+ if (value === 0) {
52
+ this.i = 0n;
53
+ this.e = 0;
54
+ }
55
+ else {
56
+ // Multiply the number by 10 until it is an integer
57
+ let e = -Math.floor(Math.log10(value));
58
+ if (e > 0) {
59
+ value *= Math.pow(10, e);
60
+ }
61
+ else {
62
+ e = 0;
63
+ }
64
+ while (value !== Math.round(value)) {
65
+ e++;
66
+ value *= 10;
67
+ }
68
+ // Divide the number by 10 until the one's digit is non-zero
69
+ while (value % 10 === 0 && value > 0) {
70
+ e--;
71
+ value /= 10;
72
+ }
73
+ value = BigInt(value);
74
+ this.i = value * m;
75
+ this.e = -e;
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * Returns a new `Decimal` that has the opposite sign of this `Decimal`.
81
+ * @example
82
+ ```js
83
+ let a = decimal('5')
84
+ a.minus() // -5
85
+ ```
86
+ * @returns {Decimal}
87
+ */
88
+ negated() {
89
+ const negated = new Decimal();
90
+ negated.i = -this.i;
91
+ negated.e = this.e;
92
+ return negated;
93
+ }
94
+ /**
95
+ * Returns a new `Decimal` that is the sum of this and `x`.
96
+ * @param x
97
+ * @example
98
+ ```js
99
+ let a = decimal('50000000000')
100
+ let b = decimal('0.000000005')
101
+ a.add(b) // 50000000000.000000005
102
+ ```
103
+ * @returns {Decimal}
104
+ */
105
+ add(x) {
106
+ let a = new Decimal(this);
107
+ let b = new Decimal(x);
108
+ // a+b = a.i * 10^a.e + b.i * 10^b.e
109
+ // a+b = ( a.i * 10^(a.e-b.e) + b.i ) * 10^b.e
110
+ const result = new Decimal();
111
+ // Order arguments so that a.e >= b.e
112
+ if (a.e < b.e) {
113
+ const c = a;
114
+ a = b;
115
+ b = c;
116
+ }
117
+ const intPart = exp(a.i, a.e - b.e);
118
+ result.i = intPart + b.i;
119
+ result.e = b.e;
120
+ result._normalize();
121
+ return result;
122
+ }
123
+ /**
124
+ * Returns a new `Decimal` that is the difference between this and `x`.
125
+ * @param x
126
+ * @example
127
+ ```js
128
+ let a = decimal('1')
129
+ let b = decimal('0.0000000000000000001')
130
+ a.sub(b) // 0.9999999999999999999
131
+ ```
132
+ * @returns {Decimal}
133
+ */
134
+ sub(x) {
135
+ return this.add(decimal(x).negated());
136
+ }
137
+ /**
138
+ * Returns a new `Decimal` that is the product of this and `x`.
139
+ * @param x
140
+ * @example
141
+ ```js
142
+ let a = decimal('0.0000000000000000000025')
143
+ let b = decimal('400000000000000000000')
144
+ a.mul(b) // 1
145
+ ```
146
+ * @returns {Decimal}
147
+ */
148
+ mul(x) {
149
+ const a = new Decimal(this);
150
+ const b = new Decimal(x);
151
+ // a * b = (a.i * b.i) * 10^(a.e + b.e)
152
+ const result = new Decimal();
153
+ result.i = a.i * b.i;
154
+ result.e = a.e + b.e;
155
+ result._normalize();
156
+ return result;
157
+ }
158
+ /**
159
+ * Returns a new `Decimal` that is the quotient of this and `x`
160
+ * @param x
161
+ * @example
162
+ ```js
163
+ let a = decimal('1')
164
+ let b = decimal('3')
165
+ a.div(b) // 0.333333333333333333333333333333
166
+ ```
167
+ * @returns {Decimal}
168
+ */
169
+ div(x) {
170
+ const a = new Decimal(this);
171
+ const b = new Decimal(x);
172
+ // We need to increase the number of digits of a and b so that a / b will have the desired precision.
173
+ // In order for the integer quotient to have the correct precision, a.e - b.e must be greater than that precision.
174
+ // So we need only to increase a.e.
175
+ // TODO: Revisit the value of increaseA. Is it correct in every circumstance?
176
+ const increaseA = Math.max(Decimal.precision - (a.e + b.e), 0);
177
+ const intIncrease = new Decimal();
178
+ intIncrease.i = exp(a.i, increaseA);
179
+ const quotient = new Decimal();
180
+ quotient.i = intIncrease.i / b.i;
181
+ quotient.e = a.e - b.e - increaseA;
182
+ // No need to truncate since we already increased the number of digits before dividing
183
+ quotient._normalize();
184
+ return quotient;
185
+ }
186
+ /**
187
+ * Returns the square root of this `Decimal`.
188
+ * @returns {TDecimal}
189
+ */
190
+ sqrt() {
191
+ Decimal.PRECISION++;
192
+ // Let the guess value be 10^(e/2), where e is this.e
193
+ let x = new Decimal();
194
+ x.i = 1n;
195
+ x.e = Math.floor(this.e / 2);
196
+ const onehalf = new Decimal('0.5');
197
+ let xt = x.clone();
198
+ xt._truncate();
199
+ xt._normalize();
200
+ let lastxt;
201
+ let i;
202
+ for (i = 0; i < 100; i++) {
203
+ lastxt = xt;
204
+ x = this.div(x).add(x).mul(onehalf);
205
+ xt = x.clone();
206
+ xt._truncate();
207
+ xt._normalize();
208
+ if (xt.i === lastxt.i && xt.e === lastxt.e)
209
+ break;
210
+ }
211
+ if (i >= 100) {
212
+ console.log('Warning: sqrt exceeded maximum iterations. (Did it enter a cycle?)');
213
+ }
214
+ Decimal.PRECISION--;
215
+ xt._truncate();
216
+ xt._normalize();
217
+ return xt;
218
+ }
219
+ /** Returns a new copy of this Decimal value. */
220
+ clone() {
221
+ const a = new Decimal();
222
+ a.i = this.i;
223
+ a.e = this.e;
224
+ return a;
225
+ }
226
+ /**
227
+ * Remove zeroes in the least-significant digit of this `Decimal`
228
+ */
229
+ _normalize() {
230
+ while (this.i % 10n === 0n && this.i !== 0n) {
231
+ this.i /= 10n;
232
+ this.e++;
233
+ }
234
+ return this;
235
+ }
236
+ /**
237
+ * Truncate this `Decimal` to the configured precision
238
+ */
239
+ _truncate() {
240
+ // TODO: Make this better
241
+ // TODO: Rounding
242
+ const trunc = -this.e - Decimal.PRECISION;
243
+ if (trunc > 0) {
244
+ this.i /= 10n ** BigInt(trunc - 1);
245
+ this.e += trunc;
246
+ const nextDigit = this.i % 10n;
247
+ if (nextDigit >= 5) {
248
+ this.i += 10n;
249
+ }
250
+ this.i /= 10n;
251
+ }
252
+ // while(-this.e > Decimal.PRECISION) {
253
+ // this.i /= 10n;
254
+ // this.e++;
255
+ // }
256
+ return this;
257
+ }
258
+ /**
259
+ * Returns a string representation of this decimal.
260
+ * @returns {Decimal}
261
+ */
262
+ toString() {
263
+ let s = this.i.toString();
264
+ let m = '';
265
+ if (s[0] === '-') {
266
+ s = s.substring(1, s.length);
267
+ m = '-';
268
+ }
269
+ if (this.e > 0) {
270
+ return m + s + '0'.repeat(this.e);
271
+ }
272
+ else if (this.e < 0) {
273
+ if (-this.e >= s.length) {
274
+ return m + '0.' + '0'.repeat(-this.e - s.length) + s;
275
+ }
276
+ return m + s.slice(0, s.length + this.e) + '.' + s.slice(s.length + this.e, s.length);
277
+ }
278
+ else {
279
+ return m + s;
280
+ }
281
+ }
282
+ [Symbol.for('nodejs.util.inspect.custom')]() {
283
+ return this.toString();
284
+ }
285
+ /**
286
+ * Converts this decimal to the `Number` value
287
+ * @returns {number}
288
+ */
289
+ toNumber() {
290
+ return Number(Decimal.prototype.toString.call(this));
291
+ }
292
+ static get precision() {
293
+ return Decimal.PRECISION;
294
+ }
295
+ static set precision(value) {
296
+ Decimal.PRECISION = value;
297
+ }
298
+ /**
299
+ * Returns `true` if this value is equal to the value of `x`, otherwise `false`.
300
+ * @param {*} x other
301
+ * @returns {boolean}
302
+ */
303
+ eq(x) {
304
+ const other = decimal(x);
305
+ return this.i === other.i && this.e === other.e;
306
+ }
307
+ /**
308
+ * Returns `true` if this value is less than the value of `x`, otherwise `false`.
309
+ * @param {*} x
310
+ * @returns {boolean}
311
+ */
312
+ lt(x) {
313
+ const other = decimal(x);
314
+ if (this.e === other.e)
315
+ return this.i < other.i;
316
+ const e = this.e - other.e;
317
+ if (e > 0) {
318
+ return exp(this.i, e) < other.i;
319
+ }
320
+ return this.i < exp(other.i, -e);
321
+ }
322
+ /**
323
+ * Returns a comparison value representing the ordering of this value in respect to `x`.
324
+ * * `-1` if this < x
325
+ * * `1` if this > x
326
+ * * `0` if this == x
327
+ * @param {*} x
328
+ * @returns {number}
329
+ */
330
+ compare(x) {
331
+ if (this.eq(x))
332
+ return 0;
333
+ if (this.lt(x))
334
+ return -1;
335
+ return 1;
336
+ }
337
+ /**
338
+ * Returns `true` if this value is greater than the value of `x`, otherwise `false`.
339
+ * @param {*} x
340
+ * @returns {boolean}
341
+ */
342
+ gt(x) {
343
+ return this.compare(x) > 0;
344
+ }
345
+ /**
346
+ * Returns `true` if this value is less than or equal to the value of `x`, otherwise `false`.
347
+ * @param {*} x
348
+ * @returns {boolean}
349
+ */
350
+ lte(x) {
351
+ return this.compare(x) <= 0;
352
+ }
353
+ /**
354
+ * Returns `true` if this value is greater than or equal to the value of `x`, otherwise `false`.
355
+ * @param {*} x
356
+ * @returns {boolean}
357
+ */
358
+ gte(x) {
359
+ return this.compare(x) >= 0;
360
+ }
361
+ }
362
+ /** Returns a BigInt that is equal to `i` times `10^e` */
363
+ function exp(i, e) {
364
+ // TODO: Make this better
365
+ // The implementation is faster than 10n ** BigInt(e). But could we make it faster still?
366
+ let ii = i;
367
+ for (let j = 0; j < e; j++) {
368
+ ii *= 10n;
369
+ }
370
+ return ii;
371
+ }
@@ -3,12 +3,13 @@
3
3
  *
4
4
  * @module Globals
5
5
  */
6
+ export * from './decimal.js';
6
7
  /** This is just a noop function. */
7
8
  export declare const noop: () => void;
8
9
  /**
9
10
  * A generic function type with arbitrary arguments and return.
10
11
  */
11
- export declare type Function<T = any> = (...args: any) => T;
12
+ export declare type Function<TReturn = any> = (...args: any) => TReturn;
12
13
  /**
13
14
  * An iteratee function used for collection methods.
14
15
  * @see {@link Collections.filter}
@@ -22,8 +23,8 @@ export declare type Function<T = any> = (...args: any) => T;
22
23
  * @see {@link Collections.sortedUniq}
23
24
  * @see {@link Collections.groupBy}
24
25
  */
25
- export declare type Iteratee<T = any, K = any> = (value: T, key?: K, arr?: any) => any;
26
- export declare type Predicate<T = any> = (value: T) => any;
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;
27
28
  /** A function that always returns `true`. */
28
29
  export declare const True: () => boolean;
29
30
  /** A function that always returns `false`. */
@@ -79,12 +80,12 @@ export declare class ValueError extends CustomError {
79
80
  export declare class ZeroDivisionError extends CustomError {
80
81
  }
81
82
  /**
82
- * Returns the true type of any value with correct detection for null, Array,
83
- * Object, Promise, Symbol, and NaN. The correct values are inferred from {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag | Symbol.toStringTag} and the value's prototype.
83
+ * Returns the true type of any value with correct detection for `null`, `Array`,
84
+ * `Object`, `Promise`, `Symbol`, and `NaN`. The correct values are inferred from {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag | Symbol.toStringTag} and the value's prototype.
84
85
  * @param value
85
86
  * @returns The value type.
86
87
  */
87
- export declare function type(value: any): any;
88
+ export declare function type(value: any): string;
88
89
  /**
89
90
  * Returns a string representing the object.
90
91
  * @param obj
@@ -153,7 +154,7 @@ export declare const isWeakMap: <K extends object, V>(x: any) => x is WeakMap<K,
153
154
  * @param value
154
155
  * @returns The number of elements in the collection or `undefined`.
155
156
  */
156
- export declare function len(value: any): any;
157
+ export declare function len(value: any): number;
157
158
  /**
158
159
  * Generates a unique ID using random numbers. If a prefix is given, the ID is appended to it and returned as a string.
159
160
  * @param {string} [pre=''] The id prefix.
@@ -167,7 +168,7 @@ uniqueId('user_')
167
168
  // 'user_1033763188'
168
169
  ```
169
170
  */
170
- export declare const uniqueId: (pre?: string) => any;
171
+ export declare const uniqueId: (pre?: string) => string;
171
172
  /**
172
173
  * Generates a monotonically increasing, pseudo-random based uuid-v4 string. These are sortable, url-friendly and are 100% unique if the IDs are generated more than 1 millisecond apart. If two IDs are generated at the same millisecond, the chance of collision is still pretty low (1 in 10^15).
173
174
  * @returns Returns a GUID formatted string.
@@ -218,14 +219,15 @@ export declare const has: (obj: any, attr: PropertyKey) => boolean;
218
219
  * @param {*} [value=undefined]
219
220
  * @return The property value or default value.
220
221
  */
221
- export declare function get(key: PropertyKey | PropertyKey[], obj: any, value?: any): any;
222
+ export declare function get<T>(key: PropertyKey, obj: T, value?: any): any;
223
+ export declare function get<T>(key: PropertyKey[], obj: T, value?: any): any;
222
224
  /**
223
225
  * Deletes a given property key from an object.
224
226
  * @param attr The property name.
225
227
  * @param x The given object.
226
228
  * @returns The modified object.
227
229
  */
228
- export declare function del(attr: PropertyKey, x: any): any;
230
+ export declare function del<T>(attr: PropertyKey, x: T): T;
229
231
  /**
230
232
  * Adds a property to an object, or modifies the existing value.
231
233
  * @param attr The name or Symbol of the property to be defined or modified.
@@ -242,7 +244,8 @@ export declare const HASH_KEY: unique symbol;
242
244
  * @param obj The given object.
243
245
  * @returns The hash value.
244
246
  */
245
- export declare function hash(obj: any): any;
247
+ export declare function hash(obj: string): number;
248
+ export declare function hash<T>(obj: T): T;
246
249
  /**
247
250
  * A hash value generator for strings.
248
251
  * @param {string} str The given string.
@@ -274,24 +277,25 @@ export declare const oct: (n: number) => string;
274
277
  * @returns A floating point number parsed from the given value or `NaN`.
275
278
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
276
279
  */
277
- export declare const float: (x: any) => number;
280
+ export declare const float: (x: string) => number;
278
281
  /**
279
282
  * Returns an integer number constructed from a number or string `x`.
280
283
  * @param x The number or string.
281
284
  * @returns An integer number parsed from the given value or `NaN`.
282
285
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
283
286
  */
284
- export declare const int: (x: any, base?: number) => number;
287
+ export declare const int: (x: string, base?: number) => number;
285
288
  /**
286
289
  * Converts the value to an array using `Array.from()`.
287
290
  * @param value
288
291
  * @returns A new array value.
289
292
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
290
293
  */
291
- export declare const list: (value?: any) => unknown[];
294
+ export declare const list: <T>(value?: any) => T[];
292
295
  /**
293
296
  * Retrieve the next item from the iterator by calling its `next()` method.
294
297
  * @param iter The iterator.
295
298
  * @returns The next value from the iterator.
296
299
  */
297
- export declare const next: (iter: Iterator<any> | Generator) => any;
300
+ export declare function next<T>(iter: Iterator<T>): T | undefined;
301
+ export declare function next<T>(iter: Generator<any, T>): T | undefined;