atomic-fns 1.1.2 → 1.1.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.
- package/README.md +11 -11
- package/dist/collections/index.d.ts +1 -13
- package/dist/collections/index.js +11 -21
- package/dist/functools/index.d.ts +6 -6
- package/dist/functools/index.js +19 -11
- package/dist/globals/index.d.ts +40 -40
- package/dist/globals/index.js +117 -46
- package/dist/itertools/index.d.ts +2 -2
- package/dist/itertools/index.js +4 -4
- package/dist/math/index.d.ts +2 -2
- package/dist/math/index.js +6 -2
- package/dist/operators/index.d.ts +4 -4
- package/dist/operators/index.js +11 -5
- package/dist/random/index.d.ts +2 -2
- package/dist/random/index.js +6 -2
- package/package.json +6 -3
- package/dist/globals/decimal.d.ts +0 -142
- package/dist/globals/decimal.js +0 -371
- package/dist/i18n/date/format.d.ts +0 -16
- package/dist/i18n/date/format.js +0 -313
- package/dist/i18n/date/test.html +0 -72
package/dist/globals/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module globals
|
|
5
5
|
*/
|
|
6
6
|
/** This is just a noop function. */
|
|
7
|
-
export
|
|
7
|
+
export function noop() { }
|
|
8
8
|
/** A function that always returns `true`. */
|
|
9
9
|
export const True = () => true;
|
|
10
10
|
/** A function that always returns `false`. */
|
|
@@ -121,69 +121,115 @@ export function type(value) {
|
|
|
121
121
|
* @returns `obj.toString()` or `''` if `obj` is `null` or `undefined`.
|
|
122
122
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
|
|
123
123
|
*/
|
|
124
|
-
export
|
|
124
|
+
export function str(obj) {
|
|
125
|
+
return obj?.toString() ?? '';
|
|
126
|
+
}
|
|
125
127
|
/** Check if value is a boolean type. */
|
|
126
|
-
export
|
|
128
|
+
export function isBool(x) {
|
|
129
|
+
return type(x) === 'boolean';
|
|
130
|
+
}
|
|
127
131
|
/** Check if value is an `Error` type. */
|
|
128
|
-
export
|
|
132
|
+
export function isError(x) {
|
|
133
|
+
return x instanceof Error;
|
|
134
|
+
}
|
|
129
135
|
/** Check if value is an iterable type. */
|
|
130
|
-
export
|
|
136
|
+
export function isIterable(x) {
|
|
131
137
|
if (x == null)
|
|
132
138
|
return false;
|
|
133
139
|
return typeof x[Symbol.iterator] === 'function';
|
|
134
|
-
}
|
|
140
|
+
}
|
|
135
141
|
/** Check if value is a native `Date` type. */
|
|
136
|
-
export
|
|
142
|
+
export function isDate(x) {
|
|
143
|
+
return x instanceof Date;
|
|
144
|
+
}
|
|
137
145
|
/** Check if value is an object type. */
|
|
138
|
-
export
|
|
146
|
+
export function isObject(x) {
|
|
147
|
+
return type(x) === 'object';
|
|
148
|
+
}
|
|
139
149
|
/** Check if value is a string type. */
|
|
140
|
-
export
|
|
150
|
+
export function isString(x) {
|
|
151
|
+
return type(x) === 'string';
|
|
152
|
+
}
|
|
141
153
|
/** Check if value is an Array type. */
|
|
142
|
-
export
|
|
154
|
+
export function isArray(x) {
|
|
155
|
+
return Array.isArray(x);
|
|
156
|
+
}
|
|
143
157
|
/**
|
|
144
158
|
* Check if value is Array-like type.
|
|
145
159
|
* A value is considered array-like if it's not a function and has a `.length` number property.
|
|
146
160
|
*/
|
|
147
|
-
export
|
|
161
|
+
export function isArrayLike(x) {
|
|
148
162
|
const T = type(x);
|
|
149
163
|
return T === 'array' || (T === 'object' && isNumber(x.length));
|
|
150
|
-
}
|
|
164
|
+
}
|
|
151
165
|
/** Check if value is a number type. */
|
|
152
|
-
export
|
|
166
|
+
export function isNumber(x) {
|
|
167
|
+
return type(x) === 'number';
|
|
168
|
+
}
|
|
153
169
|
/** Check if value is an integer number type. */
|
|
154
|
-
export
|
|
170
|
+
export function isInteger(x) {
|
|
171
|
+
return type(x) === 'number' && Math.trunc(x) === x;
|
|
172
|
+
}
|
|
155
173
|
/** Check if value is a bigint type. */
|
|
156
|
-
export
|
|
174
|
+
export function isBigint(x) {
|
|
175
|
+
return type(x) === 'bigint';
|
|
176
|
+
}
|
|
157
177
|
/** Check if value is a Promise type. */
|
|
158
|
-
export
|
|
178
|
+
export function isPromise(x) {
|
|
179
|
+
return type(x) === 'Promise';
|
|
180
|
+
}
|
|
159
181
|
/** Check if value is a function type. */
|
|
160
|
-
export
|
|
182
|
+
export function isFunction(x) {
|
|
183
|
+
return x?.constructor === Function;
|
|
184
|
+
}
|
|
161
185
|
/** Check if value is an async function type. */
|
|
162
|
-
export
|
|
186
|
+
export function isAsyncFunction(x) {
|
|
187
|
+
return x?.constructor.name === 'AsyncFunction';
|
|
188
|
+
}
|
|
163
189
|
/** Check if value is a generator function type. */
|
|
164
|
-
export
|
|
190
|
+
export function isGenerator(x) {
|
|
165
191
|
return x?.constructor.constructor?.name === 'GeneratorFunction';
|
|
166
|
-
}
|
|
192
|
+
}
|
|
167
193
|
/** Check if value is `null` or `undefined`. */
|
|
168
|
-
export
|
|
194
|
+
export function isNull(x) {
|
|
195
|
+
return x == null;
|
|
196
|
+
}
|
|
169
197
|
/** Check if value === `undefined`. */
|
|
170
|
-
export
|
|
198
|
+
export function isUndefined(x) {
|
|
199
|
+
return x === undefined;
|
|
200
|
+
}
|
|
171
201
|
/** Check if value is not `null` or `undefined`. */
|
|
172
|
-
export
|
|
202
|
+
export function notNull(x) {
|
|
203
|
+
return x != null;
|
|
204
|
+
}
|
|
173
205
|
/** Returns `true` for objects without length or falsy values. */
|
|
174
|
-
export
|
|
206
|
+
export function isEmpty(x) {
|
|
207
|
+
return len(x) === 0 ? true : !x;
|
|
208
|
+
}
|
|
175
209
|
/** Check if value is a `RegExp` type */
|
|
176
|
-
export
|
|
210
|
+
export function isRegExp(x) {
|
|
211
|
+
return x instanceof RegExp;
|
|
212
|
+
}
|
|
177
213
|
/** Check if value is a `Symbol` type */
|
|
178
|
-
export
|
|
214
|
+
export function isSymbol(x) {
|
|
215
|
+
return type(x) === 'symbol';
|
|
216
|
+
}
|
|
179
217
|
/** Check if value is a `Set` type. */
|
|
180
|
-
export
|
|
218
|
+
export function isSet(x) {
|
|
219
|
+
return x instanceof Set;
|
|
220
|
+
}
|
|
181
221
|
/** Check if value is a `Map` type. */
|
|
182
|
-
export
|
|
222
|
+
export function isMap(x) {
|
|
223
|
+
return x instanceof Map;
|
|
224
|
+
}
|
|
183
225
|
/** Check if value is a `WeakSet` type. */
|
|
184
|
-
export
|
|
226
|
+
export function isWeakSet(x) {
|
|
227
|
+
return x instanceof WeakSet;
|
|
228
|
+
}
|
|
185
229
|
/** Check if value is a `WeakMap` type. */
|
|
186
|
-
export
|
|
230
|
+
export function isWeakMap(x) {
|
|
231
|
+
return x instanceof WeakMap;
|
|
232
|
+
}
|
|
187
233
|
/**
|
|
188
234
|
* Returns the number of elements in a collection type.
|
|
189
235
|
*
|
|
@@ -221,9 +267,10 @@ uniqueId('user_')
|
|
|
221
267
|
// 'user_1033763188'
|
|
222
268
|
```
|
|
223
269
|
*/
|
|
224
|
-
export
|
|
225
|
-
// @ts-expect-error
|
|
226
|
-
(pre || 0) + ((Math.random() * 1e10) >>> 0);
|
|
270
|
+
export function uniqueId(pre = '') {
|
|
271
|
+
// @ts-expect-error
|
|
272
|
+
return (pre || 0) + ((Math.random() * 1e10) >>> 0);
|
|
273
|
+
}
|
|
227
274
|
/**
|
|
228
275
|
* 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).
|
|
229
276
|
* @returns Returns a GUID formatted string.
|
|
@@ -233,10 +280,10 @@ uuid()
|
|
|
233
280
|
// '183f8ef3-b8f0-4000-81f5-89234c836d00'
|
|
234
281
|
```
|
|
235
282
|
*/
|
|
236
|
-
export
|
|
283
|
+
export function uuid() {
|
|
237
284
|
const u = Date.now().toString(16) + Math.random().toString(16) + '0'.repeat(16);
|
|
238
285
|
return [u.substr(0, 8), u.substr(8, 4), '4000-8' + u.substr(13, 3), u.substr(16, 12)].join('-');
|
|
239
|
-
}
|
|
286
|
+
}
|
|
240
287
|
/**
|
|
241
288
|
* Checks if `obj.key` is a function, and calls it with any given `args`.
|
|
242
289
|
* @param {*} obj
|
|
@@ -250,30 +297,40 @@ export function call(obj, key, ...args) {
|
|
|
250
297
|
}
|
|
251
298
|
}
|
|
252
299
|
/** Convert number to unicode character */
|
|
253
|
-
export
|
|
300
|
+
export function chr(x) {
|
|
301
|
+
return String.fromCodePoint(x);
|
|
302
|
+
}
|
|
254
303
|
/** Convert character to Unicode code point */
|
|
255
|
-
export
|
|
304
|
+
export function ord(x) {
|
|
305
|
+
return x.charCodeAt(0);
|
|
306
|
+
}
|
|
256
307
|
/**
|
|
257
308
|
* Returns an array of the own enumerable property names of `object`.
|
|
258
309
|
* @param object The given object.
|
|
259
310
|
* @returns The array of object keys.
|
|
260
311
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
|
|
261
312
|
*/
|
|
262
|
-
export
|
|
313
|
+
export function keys(object) {
|
|
314
|
+
return Object.keys(object);
|
|
315
|
+
}
|
|
263
316
|
/**
|
|
264
317
|
* Returns an array of the own enumerable property values of `object`.
|
|
265
318
|
* @param object The given object.
|
|
266
319
|
* @returns The array of object keys.
|
|
267
320
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Object.values()}
|
|
268
321
|
*/
|
|
269
|
-
export
|
|
322
|
+
export function values(object) {
|
|
323
|
+
return Object.values(object);
|
|
324
|
+
}
|
|
270
325
|
/**
|
|
271
326
|
* Check if a given property is present in a given object.
|
|
272
327
|
* @param obj The object to check.
|
|
273
328
|
* @param attr A property key name.
|
|
274
329
|
* @returns `true` if the object has the property name.
|
|
275
330
|
*/
|
|
276
|
-
export
|
|
331
|
+
export function has(obj, attr) {
|
|
332
|
+
return obj && attr in obj;
|
|
333
|
+
}
|
|
277
334
|
export function get(key, obj, value) {
|
|
278
335
|
if (obj == null)
|
|
279
336
|
return value;
|
|
@@ -353,40 +410,54 @@ export function hashCode(str) {
|
|
|
353
410
|
* @param n The given number.
|
|
354
411
|
* @returns The binary string representation of `n`.
|
|
355
412
|
*/
|
|
356
|
-
export
|
|
413
|
+
export function bin(n) {
|
|
414
|
+
return n.toString(2);
|
|
415
|
+
}
|
|
357
416
|
/**
|
|
358
417
|
* Converts a number to a hexadecimal string.
|
|
359
418
|
* @param n The given number.
|
|
360
419
|
* @returns The hexadecimal string representation of `n`.
|
|
361
420
|
*/
|
|
362
|
-
export
|
|
421
|
+
export function hex(n) {
|
|
422
|
+
return n.toString(16);
|
|
423
|
+
}
|
|
363
424
|
/**
|
|
364
425
|
* Converts a number to an octal string.
|
|
365
426
|
* @param n The given number.
|
|
366
427
|
* @returns The octal string representation of `n`.
|
|
367
428
|
*/
|
|
368
|
-
export
|
|
429
|
+
export function oct(n) {
|
|
430
|
+
return n.toString(8);
|
|
431
|
+
}
|
|
369
432
|
/**
|
|
370
433
|
* Returns a floating point number constructed from a number or string `x`.
|
|
371
434
|
* @param x The number or string.
|
|
372
435
|
* @returns A floating point number parsed from the given value or `NaN`.
|
|
373
436
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
|
|
374
437
|
*/
|
|
375
|
-
export
|
|
438
|
+
export function float(x) {
|
|
439
|
+
return parseFloat(x);
|
|
440
|
+
}
|
|
376
441
|
/**
|
|
377
442
|
* Returns an integer number constructed from a number or string `x`.
|
|
378
443
|
* @param x The number or string.
|
|
379
444
|
* @returns An integer number parsed from the given value or `NaN`.
|
|
380
445
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
|
|
381
446
|
*/
|
|
382
|
-
export
|
|
447
|
+
export function int(x, base = 10) {
|
|
448
|
+
return parseInt(x, base);
|
|
449
|
+
}
|
|
383
450
|
/**
|
|
384
451
|
* Converts the value to an array using `Array.from()`.
|
|
385
452
|
* @param value
|
|
386
453
|
* @returns A new array value.
|
|
387
454
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
|
|
388
455
|
*/
|
|
389
|
-
export
|
|
456
|
+
export function list(value) {
|
|
457
|
+
if (value != null)
|
|
458
|
+
return Array.from(value);
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
390
461
|
export function next(iter) {
|
|
391
462
|
return iter.next().value;
|
|
392
463
|
}
|
|
@@ -31,7 +31,7 @@ all([2, 4, 6] => (n) => n > 1)
|
|
|
31
31
|
```
|
|
32
32
|
@see {@link any}
|
|
33
33
|
*/
|
|
34
|
-
export declare
|
|
34
|
+
export declare function all<T>(iterable: Iterable<T>, fn?: Predicate<T>): boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Returns true when any of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
|
|
37
37
|
* @param iterable
|
|
@@ -50,7 +50,7 @@ any([1, 4, 5] => (n) => n % 2 === 0)
|
|
|
50
50
|
```
|
|
51
51
|
@see {@link all}
|
|
52
52
|
*/
|
|
53
|
-
export declare
|
|
53
|
+
export declare function any<T>(iterable: Iterable<T>, fn?: Predicate<T>): boolean;
|
|
54
54
|
export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T, void, unknown>;
|
|
55
55
|
/**
|
|
56
56
|
* Checks if the `value` is in `collection`.
|
package/dist/itertools/index.js
CHANGED
|
@@ -44,13 +44,13 @@ all([2, 4, 6] => (n) => n > 1)
|
|
|
44
44
|
```
|
|
45
45
|
@see {@link any}
|
|
46
46
|
*/
|
|
47
|
-
export
|
|
47
|
+
export function all(iterable, fn = bool) {
|
|
48
48
|
for (const item of iterable) {
|
|
49
49
|
if (!fn(item))
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
52
|
return true;
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
/**
|
|
55
55
|
* Returns true when any of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
|
|
56
56
|
* @param iterable
|
|
@@ -69,13 +69,13 @@ any([1, 4, 5] => (n) => n % 2 === 0)
|
|
|
69
69
|
```
|
|
70
70
|
@see {@link all}
|
|
71
71
|
*/
|
|
72
|
-
export
|
|
72
|
+
export function any(iterable, fn = bool) {
|
|
73
73
|
for (const item of iterable) {
|
|
74
74
|
if (fn(item))
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
return false;
|
|
78
|
-
}
|
|
78
|
+
}
|
|
79
79
|
export function chain(...iterables) {
|
|
80
80
|
return iflatten(iterables);
|
|
81
81
|
}
|
package/dist/math/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare function round(x: number, digits?: number): number;
|
|
|
27
27
|
*
|
|
28
28
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor Math.floor()}
|
|
29
29
|
*/
|
|
30
|
-
export declare
|
|
30
|
+
export declare function floor(x: number): number;
|
|
31
31
|
/**
|
|
32
32
|
* Rounds up and returns the largest integer greater than or equal to a given number.
|
|
33
33
|
* @param x A number.
|
|
@@ -35,7 +35,7 @@ export declare const floor: (x: number) => number;
|
|
|
35
35
|
*
|
|
36
36
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil Math.ceil()}
|
|
37
37
|
*/
|
|
38
|
-
export declare
|
|
38
|
+
export declare function ceil(x: number): number;
|
|
39
39
|
/**
|
|
40
40
|
* Returns a tuple like `[x / y, x % y]`.
|
|
41
41
|
*
|
package/dist/math/index.js
CHANGED
|
@@ -37,7 +37,9 @@ export function round(x, digits = 0) {
|
|
|
37
37
|
*
|
|
38
38
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor Math.floor()}
|
|
39
39
|
*/
|
|
40
|
-
export
|
|
40
|
+
export function floor(x) {
|
|
41
|
+
return Math.floor(x);
|
|
42
|
+
}
|
|
41
43
|
/**
|
|
42
44
|
* Rounds up and returns the largest integer greater than or equal to a given number.
|
|
43
45
|
* @param x A number.
|
|
@@ -45,7 +47,9 @@ export const floor = (x) => Math.floor(x);
|
|
|
45
47
|
*
|
|
46
48
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil Math.ceil()}
|
|
47
49
|
*/
|
|
48
|
-
export
|
|
50
|
+
export function ceil(x) {
|
|
51
|
+
return Math.ceil(x);
|
|
52
|
+
}
|
|
49
53
|
/**
|
|
50
54
|
* Returns a tuple like `[x / y, x % y]`.
|
|
51
55
|
*
|
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
* @module operators
|
|
5
5
|
*/
|
|
6
6
|
/** This is the identity function. It always returns the same value that was passed in */
|
|
7
|
-
export declare
|
|
7
|
+
export declare function id(x: any): any;
|
|
8
8
|
/**
|
|
9
9
|
* Called to implement truth value testing.
|
|
10
10
|
* @param x
|
|
11
11
|
* @returns {boolean} `x.bool()` if exists or `!!x`.
|
|
12
12
|
*/
|
|
13
|
-
export declare
|
|
13
|
+
export declare function bool(x: any): any;
|
|
14
14
|
/**
|
|
15
15
|
* Returns `true` if `x` is a falsy value.
|
|
16
16
|
* @see {@link bool}
|
|
17
17
|
*/
|
|
18
|
-
export declare
|
|
18
|
+
export declare function not(x: any): boolean;
|
|
19
19
|
/**
|
|
20
20
|
* Returns `true` if `x` is an instance of class `y`
|
|
21
21
|
* @param x The instance object
|
|
22
22
|
* @param y The parent class
|
|
23
23
|
* @returns {boolean}
|
|
24
24
|
*/
|
|
25
|
-
export declare
|
|
25
|
+
export declare function isinstance(x: any, y: any): boolean;
|
|
26
26
|
/** Describes a function used to compare two values.
|
|
27
27
|
*
|
|
28
28
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters Array.sort()}
|
package/dist/operators/index.js
CHANGED
|
@@ -5,30 +5,36 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { call, isObject } from '../globals/index.js';
|
|
7
7
|
/** This is the identity function. It always returns the same value that was passed in */
|
|
8
|
-
export
|
|
8
|
+
export function id(x) {
|
|
9
|
+
return x;
|
|
10
|
+
}
|
|
9
11
|
/**
|
|
10
12
|
* Called to implement truth value testing.
|
|
11
13
|
* @param x
|
|
12
14
|
* @returns {boolean} `x.bool()` if exists or `!!x`.
|
|
13
15
|
*/
|
|
14
|
-
export
|
|
16
|
+
export function bool(x) {
|
|
15
17
|
const r = call(x, 'bool');
|
|
16
18
|
if (r != null)
|
|
17
19
|
return r;
|
|
18
20
|
return !!x;
|
|
19
|
-
}
|
|
21
|
+
}
|
|
20
22
|
/**
|
|
21
23
|
* Returns `true` if `x` is a falsy value.
|
|
22
24
|
* @see {@link bool}
|
|
23
25
|
*/
|
|
24
|
-
export
|
|
26
|
+
export function not(x) {
|
|
27
|
+
return !bool(x);
|
|
28
|
+
}
|
|
25
29
|
/**
|
|
26
30
|
* Returns `true` if `x` is an instance of class `y`
|
|
27
31
|
* @param x The instance object
|
|
28
32
|
* @param y The parent class
|
|
29
33
|
* @returns {boolean}
|
|
30
34
|
*/
|
|
31
|
-
export
|
|
35
|
+
export function isinstance(x, y) {
|
|
36
|
+
return x instanceof y;
|
|
37
|
+
}
|
|
32
38
|
/**
|
|
33
39
|
* Checks whether `x` is a comparable type and returns the result of `x.compare(y)`.
|
|
34
40
|
* Otherwise the return value of the compare function is equivalent to `obj === other ? 0 : obj < other ? -1 : 1`
|
package/dist/random/index.d.ts
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* @param {number} max
|
|
10
10
|
* @returns {number}
|
|
11
11
|
*/
|
|
12
|
-
export declare
|
|
12
|
+
export declare function random(min?: number, max?: number): number;
|
|
13
13
|
/**
|
|
14
14
|
* Returns a random integer between a [min, max] value (inclusive).
|
|
15
15
|
* @param {number} min
|
|
16
16
|
* @param {number} max
|
|
17
17
|
* @returns {number}
|
|
18
18
|
*/
|
|
19
|
-
export declare
|
|
19
|
+
export declare function randomInt(min?: number, max?: number): number;
|
|
20
20
|
/**
|
|
21
21
|
* Returns the item at some random index in a sequence.
|
|
22
22
|
* @returns {T}
|
package/dist/random/index.js
CHANGED
|
@@ -10,14 +10,18 @@ import { isObject } from '../globals/index.js';
|
|
|
10
10
|
* @param {number} max
|
|
11
11
|
* @returns {number}
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export function random(min = 0, max = 1) {
|
|
14
|
+
return Math.random() * (max - min) + min;
|
|
15
|
+
}
|
|
14
16
|
/**
|
|
15
17
|
* Returns a random integer between a [min, max] value (inclusive).
|
|
16
18
|
* @param {number} min
|
|
17
19
|
* @param {number} max
|
|
18
20
|
* @returns {number}
|
|
19
21
|
*/
|
|
20
|
-
export
|
|
22
|
+
export function randomInt(min = 0, max = 1) {
|
|
23
|
+
return Math.round(random(min, max));
|
|
24
|
+
}
|
|
21
25
|
/**
|
|
22
26
|
* Returns the item at some random index in a sequence.
|
|
23
27
|
* @returns {T}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atomic-fns",
|
|
3
3
|
"description": "Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/*"
|
|
7
7
|
],
|
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"scripts": {
|
|
14
|
+
"preversion": "npm test",
|
|
15
|
+
"version": "npm run build && npm run docs && git add -A dist",
|
|
16
|
+
"postversion": "git push && git push --tags",
|
|
14
17
|
"prepublishOnly": "npm run build",
|
|
15
18
|
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
|
|
16
19
|
"tsc": "tsc -p . --declaration",
|
|
17
20
|
"tsc:w": "tsc -p . --declaration --watch",
|
|
18
21
|
"lint": "eslint src/**/*.ts --fix",
|
|
19
|
-
"build": "npm run lint && npm test && npm run tsc",
|
|
22
|
+
"build": "npm run lint && npm test && npm run tsc && npm run docs",
|
|
20
23
|
"docs": "typedoc"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
@@ -67,5 +70,5 @@
|
|
|
67
70
|
"bugs": {
|
|
68
71
|
"url": "https://github.com/adrian2x/atomic-fns/issues"
|
|
69
72
|
},
|
|
70
|
-
"homepage": "https://atomic-fns
|
|
73
|
+
"homepage": "https://atomic-stack.github.io/atomic-fns/"
|
|
71
74
|
}
|
|
@@ -1,142 +0,0 @@
|
|
|
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
|
-
private i;
|
|
11
|
-
private e;
|
|
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
|
-
private _normalize;
|
|
87
|
-
/**
|
|
88
|
-
* Truncate this `Decimal` to the configured precision
|
|
89
|
-
*/
|
|
90
|
-
private _truncate;
|
|
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
|
-
}
|