atomic-fns 1.1.1 → 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 +19 -17
- package/dist/collections/SortedMap.d.ts +2 -2
- package/dist/collections/SortedMap.js +2 -2
- package/dist/collections/index.d.ts +3 -14
- package/dist/collections/index.js +13 -22
- package/dist/decimal/index.d.ts +4 -2
- package/dist/decimal/index.js +4 -2
- package/dist/functools/index.d.ts +7 -7
- package/dist/functools/index.js +20 -12
- package/dist/globals/index.d.ts +41 -41
- package/dist/globals/index.js +118 -47
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/itertools/index.d.ts +4 -4
- package/dist/itertools/index.js +6 -6
- package/dist/math/index.d.ts +3 -3
- package/dist/math/index.js +7 -3
- package/dist/operators/index.d.ts +7 -7
- package/dist/operators/index.js +14 -8
- package/dist/random/index.d.ts +3 -3
- package/dist/random/index.js +7 -3
- package/dist/types.d.ts +10 -10
- 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/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# atomic-fns
|
|
2
2
|
|
|
3
|
-
[Read the Docs](https://atomic-fns
|
|
3
|
+
[Read the Docs](https://atomic-stack.github.io/atomic-fns/)
|
|
4
4
|
|
|
5
|
-
## Like Lodash, but in TypeScript and for
|
|
5
|
+
## Like Lodash, but in TypeScript and for ESNext.
|
|
6
6
|
|
|
7
|
-
Stop shipping code built for browsers from 2015.
|
|
7
|
+
Stop shipping code built for browsers from 2015.
|
|
8
8
|
|
|
9
9
|
You may prefer this because it's:
|
|
10
10
|
|
|
11
11
|
* **TypeScript & docs**: Includes type declaration files and js with JSDocs for best in class experience.
|
|
12
12
|
* **Zero deps**: Built from scratch with no runtime dependencies or polyfills.
|
|
13
|
-
* **
|
|
14
|
-
* **Modular**: Pick what you need. Supports tree-shaking, no side effects and works with all bundlers.
|
|
13
|
+
* **ESNext**: Uses modern idiomatic syntax, data structures, and control flow techniques.
|
|
14
|
+
* **Modular**: Pick what you need. Supports tree-shaking, no side effects, and works with all bundlers.
|
|
15
15
|
* **Lazy**: Leverage generators, iterators, and functional composition.
|
|
16
|
-
* **
|
|
16
|
+
* **Tests**: All modules have comprehensive test suites and public apis are 100% covered.
|
|
17
17
|
|
|
18
18
|
## Docs
|
|
19
19
|
|
|
20
|
-
📖 Available at [atomic-fns
|
|
20
|
+
📖 Available at [https://atomic-stack.github.io/atomic-fns/](atomic-stack.github.io/atomic-fns)
|
|
21
21
|
|
|
22
22
|
## Get Started
|
|
23
23
|
|
|
@@ -47,12 +47,12 @@ uniqueId('user_')
|
|
|
47
47
|
...
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
See the full list of [modules](https://atomic-
|
|
50
|
+
See the full list of [modules](https://atomic-stack.github.io/atomic-fns/modules.html).
|
|
51
51
|
|
|
52
52
|
## Data model
|
|
53
53
|
This library features a data model similar to [Python](https://docs.python.org/3/reference/datamodel.html#special-method-names) but not always. Only the missing parts have been implemented, while respecting the JS standards.
|
|
54
54
|
|
|
55
|
-
For example in Python collections `size()` is a method while in JS
|
|
55
|
+
For example, in Python collections, `size()` is a method, while in JS it's just a property. So this library uses `size` property instead of method. Similarly, the `len` function implementation checks for both `length` and `size` since many JS objects have a `length` property.
|
|
56
56
|
|
|
57
57
|
## Special method names
|
|
58
58
|
This library adds support for operators using object methods such as:
|
|
@@ -63,21 +63,23 @@ This library adds support for operators using object methods such as:
|
|
|
63
63
|
- `obj.gte(other)` adds custom `obj >= other`.
|
|
64
64
|
- `obj.compare(other)` overloads sorting operations.
|
|
65
65
|
|
|
66
|
-
When
|
|
66
|
+
When working with objects, functions in this library use these custom operators for equality and sorting. You can also apply operators to values like `eq(x, y)`, `lte(x, y)`, `compare(x, y)`, etc.
|
|
67
67
|
|
|
68
68
|
## New Types
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
[`Decimal`](https://atomic-stack.github.io/atomic-fns/classes/decimal.Decimal.html) provides support for correct rounded floating point arithmetic, with arbitrary precision.
|
|
71
|
+
|
|
72
|
+
Some common base interfaces and typing patterns you may have seen like `Optional`, `Result`, `Comparable`, `Iterator`, and others.
|
|
71
73
|
|
|
72
74
|
### Sorted Containers
|
|
73
|
-
- [SortedSet](https://atomic-
|
|
74
|
-
- [SortedMap](https://atomic-
|
|
75
|
-
- [SortedTree](https://atomic-
|
|
75
|
+
- [SortedSet](https://atomic-stack.github.io/atomic-fns/classes/collections.SortedSet.html)
|
|
76
|
+
- [SortedMap](https://atomic-stack.github.io/atomic-fns/classes/collections.SortedMap.html)
|
|
77
|
+
- [SortedTree](https://atomic-stack.github.io/atomic-fns/classes/collections.SortedTree.html)
|
|
76
78
|
|
|
77
79
|
### Other Containers
|
|
78
|
-
- [Deque](https://atomic-
|
|
79
|
-
- [FrozenSet](https://atomic-
|
|
80
|
-
- [LRUCache](https://atomic-
|
|
80
|
+
- [Deque](https://atomic-stack.github.io/atomic-fns/classes/collections.Deque.html)
|
|
81
|
+
- [FrozenSet](https://atomic-stack.github.io/atomic-fns/classes/collections.FrozenSet.html)
|
|
82
|
+
- [LRUCache](https://atomic-stack.github.io/atomic-fns/classes/collections.LRUCache.html)
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
## Contributing
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Mapping } from './abc.js';
|
|
2
2
|
/**
|
|
3
3
|
* A `SortedMap` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
|
|
4
|
-
* @see {@link
|
|
5
|
-
* @see {@link
|
|
4
|
+
* @see {@link operators.compare}
|
|
5
|
+
* @see {@link operators.lt}
|
|
6
6
|
* @template K, V
|
|
7
7
|
*/
|
|
8
8
|
export declare class SortedMap<K, V> extends Mapping<K, V> {
|
|
@@ -2,8 +2,8 @@ import { Mapping } from './abc.js';
|
|
|
2
2
|
import { SplayTree } from './SplayTree.js';
|
|
3
3
|
/**
|
|
4
4
|
* A `SortedMap` is a map that holds key value pairs ordered by keys. Any primitive value (and objects that implement {@link Comparable} or {@link Ordered} interfaces) can be used as keys or values.
|
|
5
|
-
* @see {@link
|
|
6
|
-
* @see {@link
|
|
5
|
+
* @see {@link operators.compare}
|
|
6
|
+
* @see {@link operators.lt}
|
|
7
7
|
* @template K, V
|
|
8
8
|
*/
|
|
9
9
|
export class SortedMap extends Mapping {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module includes classes and functions to work with Container types.
|
|
3
3
|
*
|
|
4
|
-
* @module
|
|
4
|
+
* @module collections
|
|
5
5
|
*/
|
|
6
6
|
import { compare } from '../operators/index.js';
|
|
7
7
|
import { Iteratee } from '../types';
|
|
@@ -15,6 +15,7 @@ export * from './SortedMap.js';
|
|
|
15
15
|
export * from './SortedSet.js';
|
|
16
16
|
export * from './SortedTree.js';
|
|
17
17
|
export * from './SplayTree.js';
|
|
18
|
+
export * from './Trie.js';
|
|
18
19
|
/**
|
|
19
20
|
* Creates a new array with all falsy and empty values removed.
|
|
20
21
|
* @param arr The array to compact
|
|
@@ -44,18 +45,6 @@ count(['one', 'two', 'three'], x => x.length);
|
|
|
44
45
|
*/
|
|
45
46
|
export declare function count<T>(obj: T[], fn: Iteratee<T>): Record<string, number>;
|
|
46
47
|
export declare function count<T>(obj: Object, fn: Iteratee<T>): Record<string, number>;
|
|
47
|
-
/**
|
|
48
|
-
* Creates a function that can be used to create named tuple-like objects.
|
|
49
|
-
* @example
|
|
50
|
-
```js
|
|
51
|
-
let Point = namedtuple('x', 'y', 'z')
|
|
52
|
-
let userObj = User(0, 0, 0)
|
|
53
|
-
// {x: 0, y: 0, z: 0}
|
|
54
|
-
```
|
|
55
|
-
* @param fields - A list of field names
|
|
56
|
-
* @returns A function that can be called with the field values
|
|
57
|
-
*/
|
|
58
|
-
export declare const namedtuple: (...fields: string[]) => (...args: any[]) => any;
|
|
59
48
|
/**
|
|
60
49
|
* Iterates over elements of collection, returning an array of all elements where predicate returns truthy value.
|
|
61
50
|
*
|
|
@@ -145,7 +134,7 @@ filter(objects, matches({ a: 4, c: 6 }))
|
|
|
145
134
|
* @param shape
|
|
146
135
|
* @returns
|
|
147
136
|
*/
|
|
148
|
-
export declare
|
|
137
|
+
export declare function matches(shape: any): (obj: any) => boolean;
|
|
149
138
|
/**
|
|
150
139
|
* Iterates over elements of collection and invokes `iteratee` for each element. The iteratee is invoked with three arguments: `(value, index|key, collection)`. Iteratee functions may exit iteration early by explicitly returning `false`.
|
|
151
140
|
* @example
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module includes classes and functions to work with Container types.
|
|
3
3
|
*
|
|
4
|
-
* @module
|
|
4
|
+
* @module collections
|
|
5
5
|
*/
|
|
6
|
-
import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunction, isIterable, isNull, isNumber, isObject, isString, keys
|
|
6
|
+
import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunction, isIterable, isNull, isNumber, isObject, isString, keys } from '../globals/index.js';
|
|
7
7
|
import { enumerate } from '../itertools/index.js';
|
|
8
8
|
import { compare, eq, id } from '../operators/index.js';
|
|
9
9
|
export * from './abc.js';
|
|
@@ -16,6 +16,7 @@ export * from './SortedMap.js';
|
|
|
16
16
|
export * from './SortedSet.js';
|
|
17
17
|
export * from './SortedTree.js';
|
|
18
18
|
export * from './SplayTree.js';
|
|
19
|
+
export * from './Trie.js';
|
|
19
20
|
export function compact(arr) {
|
|
20
21
|
if (!arr)
|
|
21
22
|
return;
|
|
@@ -37,18 +38,6 @@ export function count(obj, func) {
|
|
|
37
38
|
});
|
|
38
39
|
return counters;
|
|
39
40
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates a function that can be used to create named tuple-like objects.
|
|
42
|
-
* @example
|
|
43
|
-
```js
|
|
44
|
-
let Point = namedtuple('x', 'y', 'z')
|
|
45
|
-
let userObj = User(0, 0, 0)
|
|
46
|
-
// {x: 0, y: 0, z: 0}
|
|
47
|
-
```
|
|
48
|
-
* @param fields - A list of field names
|
|
49
|
-
* @returns A function that can be called with the field values
|
|
50
|
-
*/
|
|
51
|
-
export const namedtuple = (...fields) => (...args) => fields.reduce((prev, f, i) => set(f, prev, args[i], false, true), {});
|
|
52
41
|
export function filter(arr, fn = isNull) {
|
|
53
42
|
if (!arr)
|
|
54
43
|
return;
|
|
@@ -104,15 +93,17 @@ filter(objects, matches({ a: 4, c: 6 }))
|
|
|
104
93
|
* @param shape
|
|
105
94
|
* @returns
|
|
106
95
|
*/
|
|
107
|
-
export
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (const key in shape) {
|
|
111
|
-
if (obj[key] !== shape[key])
|
|
96
|
+
export function matches(shape) {
|
|
97
|
+
return function (obj) {
|
|
98
|
+
if (!shape || !obj)
|
|
112
99
|
return false;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
for (const key in shape) {
|
|
101
|
+
if (obj[key] !== shape[key])
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
116
107
|
export function forEach(collection, fn) {
|
|
117
108
|
if (Array.isArray(collection)) {
|
|
118
109
|
for (let i = 0; i < collection.length; i++) {
|
package/dist/decimal/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function decimal(x: any): Decimal;
|
|
10
10
|
/**
|
|
11
|
-
* `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard
|
|
11
|
+
* `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard
|
|
12
|
+
* `Number` type. It also supports user-defined precision (default is 20 decimal places), which
|
|
13
|
+
* can be as large as needed.
|
|
12
14
|
*/
|
|
13
15
|
export declare class Decimal {
|
|
14
16
|
static PRECISION: number;
|
|
@@ -25,7 +27,7 @@ export declare class Decimal {
|
|
|
25
27
|
* @example
|
|
26
28
|
```js
|
|
27
29
|
let a = decimal('5')
|
|
28
|
-
a.
|
|
30
|
+
a.negated() // -5
|
|
29
31
|
```
|
|
30
32
|
* @returns {Decimal}
|
|
31
33
|
*/
|
package/dist/decimal/index.js
CHANGED
|
@@ -11,7 +11,9 @@ export function decimal(x) {
|
|
|
11
11
|
return new Decimal(x);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* `Decimal` provides support for correct rounded floating point arithmetic, unlike the standard
|
|
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.
|
|
15
17
|
*/
|
|
16
18
|
export class Decimal {
|
|
17
19
|
static PRECISION = 20;
|
|
@@ -86,7 +88,7 @@ export class Decimal {
|
|
|
86
88
|
* @example
|
|
87
89
|
```js
|
|
88
90
|
let a = decimal('5')
|
|
89
|
-
a.
|
|
91
|
+
a.negated() // -5
|
|
90
92
|
```
|
|
91
93
|
* @returns {Decimal}
|
|
92
94
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module includes functions that promote a more functional programming style.
|
|
3
3
|
*
|
|
4
|
-
* @module
|
|
4
|
+
* @module functools
|
|
5
5
|
*/
|
|
6
6
|
import { Function } from '../globals/index.js';
|
|
7
7
|
/**
|
|
@@ -12,13 +12,13 @@ import { Function } from '../globals/index.js';
|
|
|
12
12
|
* @returns {Function} Returns the new bound function.
|
|
13
13
|
* @see {@link partial}
|
|
14
14
|
*/
|
|
15
|
-
export declare
|
|
15
|
+
export declare function bind(fn: Function, thisArg: any, ...partials: any[]): any;
|
|
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
19
|
* @returns Returns the new curried function.
|
|
20
20
|
*/
|
|
21
|
-
export declare
|
|
21
|
+
export declare function curry(func: Function): (...args: any[]) => any;
|
|
22
22
|
/**
|
|
23
23
|
* Creates a function that invokes `fn` with partials prepended to the arguments it receives.
|
|
24
24
|
* **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider {@link bind} instead.
|
|
@@ -26,24 +26,24 @@ export declare const curry: (func: Function) => (...args: any[]) => any;
|
|
|
26
26
|
* @param {...*} [args] The arguments to apply to `fn`.
|
|
27
27
|
* @returns {Function} Returns the new partially applied function
|
|
28
28
|
*/
|
|
29
|
-
export declare
|
|
29
|
+
export declare function partial(fn: any, ...args: any[]): any;
|
|
30
30
|
/**
|
|
31
31
|
* 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
32
|
* @param {...*} [args] The set of functions to apply.
|
|
33
33
|
* @returns {Function} A new function that applies each given function on the result of the previous one.
|
|
34
34
|
*/
|
|
35
|
-
export declare
|
|
35
|
+
export declare function flow(...args: any[]): (x: any) => any;
|
|
36
36
|
/**
|
|
37
37
|
* This is just an alias for the {@link flow} function.
|
|
38
38
|
* @see {@link flow}
|
|
39
39
|
*/
|
|
40
|
-
export declare const pipe:
|
|
40
|
+
export declare const pipe: typeof flow;
|
|
41
41
|
/**
|
|
42
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
43
|
* @param {...*} [args] The set of functions to apply.
|
|
44
44
|
* @returns {Function} A new function that applies each given function on the result of the previous step.
|
|
45
45
|
*/
|
|
46
|
-
export declare
|
|
46
|
+
export declare function compose(...args: any[]): (x: any) => any;
|
|
47
47
|
/**
|
|
48
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.
|
|
49
49
|
*
|
package/dist/functools/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module includes functions that promote a more functional programming style.
|
|
3
3
|
*
|
|
4
|
-
* @module
|
|
4
|
+
* @module functools
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Creates a function that invokes `fn` with the this binding of `thisArg` and `partials` as partially applied arguments.
|
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
* @returns {Function} Returns the new bound function.
|
|
12
12
|
* @see {@link partial}
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export function bind(fn, thisArg, ...partials) {
|
|
15
|
+
return fn.bind(thisArg, ...partials);
|
|
16
|
+
}
|
|
15
17
|
/**
|
|
16
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.
|
|
17
19
|
* @param {Function} func The function to curry.
|
|
18
20
|
* @returns Returns the new curried function.
|
|
19
21
|
*/
|
|
20
|
-
export
|
|
22
|
+
export function curry(func) {
|
|
21
23
|
return function curried(...args) {
|
|
22
24
|
if (args.length >= func.length) {
|
|
23
25
|
return func.apply(this, args);
|
|
@@ -26,7 +28,7 @@ export const curry = (func) => {
|
|
|
26
28
|
return curried.apply(this, args.concat(args2));
|
|
27
29
|
};
|
|
28
30
|
};
|
|
29
|
-
}
|
|
31
|
+
}
|
|
30
32
|
/**
|
|
31
33
|
* Creates a function that invokes `fn` with partials prepended to the arguments it receives.
|
|
32
34
|
* **Note:** The given function will have `this` bound to `undefined`. If using `this` inside `fn`, consider {@link bind} instead.
|
|
@@ -34,18 +36,22 @@ export const curry = (func) => {
|
|
|
34
36
|
* @param {...*} [args] The arguments to apply to `fn`.
|
|
35
37
|
* @returns {Function} Returns the new partially applied function
|
|
36
38
|
*/
|
|
37
|
-
export
|
|
39
|
+
export function partial(fn, ...args) {
|
|
40
|
+
return bind(fn, undefined, ...args);
|
|
41
|
+
}
|
|
38
42
|
/**
|
|
39
43
|
* 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.
|
|
40
44
|
* @param {...*} [args] The set of functions to apply.
|
|
41
45
|
* @returns {Function} A new function that applies each given function on the result of the previous one.
|
|
42
46
|
*/
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export function flow(...args) {
|
|
48
|
+
return (x) => {
|
|
49
|
+
for (const fn of args) {
|
|
50
|
+
x = fn(x);
|
|
51
|
+
}
|
|
52
|
+
return x;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
49
55
|
/**
|
|
50
56
|
* This is just an alias for the {@link flow} function.
|
|
51
57
|
* @see {@link flow}
|
|
@@ -56,7 +62,9 @@ export const pipe = flow;
|
|
|
56
62
|
* @param {...*} [args] The set of functions to apply.
|
|
57
63
|
* @returns {Function} A new function that applies each given function on the result of the previous step.
|
|
58
64
|
*/
|
|
59
|
-
export
|
|
65
|
+
export function compose(...args) {
|
|
66
|
+
return flow(args.reverse());
|
|
67
|
+
}
|
|
60
68
|
/**
|
|
61
69
|
* 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.
|
|
62
70
|
*
|
package/dist/globals/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This module includes global functions and constants.
|
|
3
3
|
*
|
|
4
|
-
* @module
|
|
4
|
+
* @module globals
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* A generic function type with arbitrary arguments and return.
|
|
8
8
|
*/
|
|
9
9
|
export declare type Function<TReturn = any> = (...args: any) => TReturn;
|
|
10
10
|
/** This is just a noop function. */
|
|
11
|
-
export declare
|
|
11
|
+
export declare function noop(): void;
|
|
12
12
|
/** A function that always returns `true`. */
|
|
13
13
|
export declare const True: () => boolean;
|
|
14
14
|
/** A function that always returns `false`. */
|
|
@@ -76,60 +76,60 @@ export declare function type(value: any): string;
|
|
|
76
76
|
* @returns `obj.toString()` or `''` if `obj` is `null` or `undefined`.
|
|
77
77
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
|
|
78
78
|
*/
|
|
79
|
-
export declare
|
|
79
|
+
export declare function str(obj: any): any;
|
|
80
80
|
/** Check if value is a boolean type. */
|
|
81
|
-
export declare
|
|
81
|
+
export declare function isBool(x: any): x is boolean;
|
|
82
82
|
/** Check if value is an `Error` type. */
|
|
83
|
-
export declare
|
|
83
|
+
export declare function isError(x: any): x is Error;
|
|
84
84
|
/** Check if value is an iterable type. */
|
|
85
|
-
export declare
|
|
85
|
+
export declare function isIterable(x: any): x is IterableIterator<any>;
|
|
86
86
|
/** Check if value is a native `Date` type. */
|
|
87
|
-
export declare
|
|
87
|
+
export declare function isDate(x: any): x is Date;
|
|
88
88
|
/** Check if value is an object type. */
|
|
89
|
-
export declare
|
|
89
|
+
export declare function isObject(x: any): x is Object;
|
|
90
90
|
/** Check if value is a string type. */
|
|
91
|
-
export declare
|
|
91
|
+
export declare function isString(x: any): x is string;
|
|
92
92
|
/** Check if value is an Array type. */
|
|
93
|
-
export declare
|
|
93
|
+
export declare function isArray(x: any): x is any[];
|
|
94
94
|
/**
|
|
95
95
|
* Check if value is Array-like type.
|
|
96
96
|
* A value is considered array-like if it's not a function and has a `.length` number property.
|
|
97
97
|
*/
|
|
98
|
-
export declare
|
|
98
|
+
export declare function isArrayLike(x: any): boolean;
|
|
99
99
|
/** Check if value is a number type. */
|
|
100
|
-
export declare
|
|
100
|
+
export declare function isNumber(x: any): x is number;
|
|
101
101
|
/** Check if value is an integer number type. */
|
|
102
|
-
export declare
|
|
102
|
+
export declare function isInteger(x: any): x is number;
|
|
103
103
|
/** Check if value is a bigint type. */
|
|
104
|
-
export declare
|
|
104
|
+
export declare function isBigint(x: any): x is BigInt;
|
|
105
105
|
/** Check if value is a Promise type. */
|
|
106
|
-
export declare
|
|
106
|
+
export declare function isPromise(x: any): x is Promise<any>;
|
|
107
107
|
/** Check if value is a function type. */
|
|
108
|
-
export declare
|
|
108
|
+
export declare function isFunction(x: any): x is Function;
|
|
109
109
|
/** Check if value is an async function type. */
|
|
110
|
-
export declare
|
|
110
|
+
export declare function isAsyncFunction(x: any): boolean;
|
|
111
111
|
/** Check if value is a generator function type. */
|
|
112
|
-
export declare
|
|
112
|
+
export declare function isGenerator(x: any): x is Generator;
|
|
113
113
|
/** Check if value is `null` or `undefined`. */
|
|
114
|
-
export declare
|
|
114
|
+
export declare function isNull(x: any): x is null | undefined;
|
|
115
115
|
/** Check if value === `undefined`. */
|
|
116
|
-
export declare
|
|
116
|
+
export declare function isUndefined(x: any): x is undefined;
|
|
117
117
|
/** Check if value is not `null` or `undefined`. */
|
|
118
|
-
export declare
|
|
118
|
+
export declare function notNull(x: any): boolean;
|
|
119
119
|
/** Returns `true` for objects without length or falsy values. */
|
|
120
|
-
export declare
|
|
120
|
+
export declare function isEmpty(x: any): boolean;
|
|
121
121
|
/** Check if value is a `RegExp` type */
|
|
122
|
-
export declare
|
|
122
|
+
export declare function isRegExp(x: any): x is RegExp;
|
|
123
123
|
/** Check if value is a `Symbol` type */
|
|
124
|
-
export declare
|
|
124
|
+
export declare function isSymbol(x: any): x is symbol;
|
|
125
125
|
/** Check if value is a `Set` type. */
|
|
126
|
-
export declare
|
|
126
|
+
export declare function isSet<T>(x: any): x is Set<T>;
|
|
127
127
|
/** Check if value is a `Map` type. */
|
|
128
|
-
export declare
|
|
128
|
+
export declare function isMap<K, V>(x: any): x is Map<K, V>;
|
|
129
129
|
/** Check if value is a `WeakSet` type. */
|
|
130
|
-
export declare
|
|
130
|
+
export declare function isWeakSet<T extends object>(x: any): x is WeakSet<T>;
|
|
131
131
|
/** Check if value is a `WeakMap` type. */
|
|
132
|
-
export declare
|
|
132
|
+
export declare function isWeakMap<K extends object, V>(x: any): x is WeakMap<K, V>;
|
|
133
133
|
/**
|
|
134
134
|
* Returns the number of elements in a collection type.
|
|
135
135
|
*
|
|
@@ -152,7 +152,7 @@ uniqueId('user_')
|
|
|
152
152
|
// 'user_1033763188'
|
|
153
153
|
```
|
|
154
154
|
*/
|
|
155
|
-
export declare
|
|
155
|
+
export declare function uniqueId(pre?: string): string;
|
|
156
156
|
/**
|
|
157
157
|
* 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).
|
|
158
158
|
* @returns Returns a GUID formatted string.
|
|
@@ -162,7 +162,7 @@ uuid()
|
|
|
162
162
|
// '183f8ef3-b8f0-4000-81f5-89234c836d00'
|
|
163
163
|
```
|
|
164
164
|
*/
|
|
165
|
-
export declare
|
|
165
|
+
export declare function uuid(): string;
|
|
166
166
|
/**
|
|
167
167
|
* Checks if `obj.key` is a function, and calls it with any given `args`.
|
|
168
168
|
* @param {*} obj
|
|
@@ -172,30 +172,30 @@ export declare const uuid: () => string;
|
|
|
172
172
|
*/
|
|
173
173
|
export declare function call(obj: any, key: PropertyKey, ...args: any[]): any;
|
|
174
174
|
/** Convert number to unicode character */
|
|
175
|
-
export declare
|
|
175
|
+
export declare function chr(x: number): string;
|
|
176
176
|
/** Convert character to Unicode code point */
|
|
177
|
-
export declare
|
|
177
|
+
export declare function ord(x: string): number;
|
|
178
178
|
/**
|
|
179
179
|
* Returns an array of the own enumerable property names of `object`.
|
|
180
180
|
* @param object The given object.
|
|
181
181
|
* @returns The array of object keys.
|
|
182
182
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
|
|
183
183
|
*/
|
|
184
|
-
export declare
|
|
184
|
+
export declare function keys<T>(object: T): (keyof T)[];
|
|
185
185
|
/**
|
|
186
186
|
* Returns an array of the own enumerable property values of `object`.
|
|
187
187
|
* @param object The given object.
|
|
188
188
|
* @returns The array of object keys.
|
|
189
189
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Object.values()}
|
|
190
190
|
*/
|
|
191
|
-
export declare
|
|
191
|
+
export declare function values(object: any): unknown[];
|
|
192
192
|
/**
|
|
193
193
|
* Check if a given property is present in a given object.
|
|
194
194
|
* @param obj The object to check.
|
|
195
195
|
* @param attr A property key name.
|
|
196
196
|
* @returns `true` if the object has the property name.
|
|
197
197
|
*/
|
|
198
|
-
export declare
|
|
198
|
+
export declare function has(obj: any, attr: PropertyKey): boolean;
|
|
199
199
|
/**
|
|
200
200
|
* Check if the attribute is present in the object or return a default value instead.
|
|
201
201
|
* @param {PropertyKey} key
|
|
@@ -242,40 +242,40 @@ export declare function hashCode(str: string): number;
|
|
|
242
242
|
* @param n The given number.
|
|
243
243
|
* @returns The binary string representation of `n`.
|
|
244
244
|
*/
|
|
245
|
-
export declare
|
|
245
|
+
export declare function bin(n: number): string;
|
|
246
246
|
/**
|
|
247
247
|
* Converts a number to a hexadecimal string.
|
|
248
248
|
* @param n The given number.
|
|
249
249
|
* @returns The hexadecimal string representation of `n`.
|
|
250
250
|
*/
|
|
251
|
-
export declare
|
|
251
|
+
export declare function hex(n: number): string;
|
|
252
252
|
/**
|
|
253
253
|
* Converts a number to an octal string.
|
|
254
254
|
* @param n The given number.
|
|
255
255
|
* @returns The octal string representation of `n`.
|
|
256
256
|
*/
|
|
257
|
-
export declare
|
|
257
|
+
export declare function oct(n: number): string;
|
|
258
258
|
/**
|
|
259
259
|
* Returns a floating point number constructed from a number or string `x`.
|
|
260
260
|
* @param x The number or string.
|
|
261
261
|
* @returns A floating point number parsed from the given value or `NaN`.
|
|
262
262
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
|
|
263
263
|
*/
|
|
264
|
-
export declare
|
|
264
|
+
export declare function float(x: string): number;
|
|
265
265
|
/**
|
|
266
266
|
* Returns an integer number constructed from a number or string `x`.
|
|
267
267
|
* @param x The number or string.
|
|
268
268
|
* @returns An integer number parsed from the given value or `NaN`.
|
|
269
269
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
|
|
270
270
|
*/
|
|
271
|
-
export declare
|
|
271
|
+
export declare function int(x: string, base?: number): number;
|
|
272
272
|
/**
|
|
273
273
|
* Converts the value to an array using `Array.from()`.
|
|
274
274
|
* @param value
|
|
275
275
|
* @returns A new array value.
|
|
276
276
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
|
|
277
277
|
*/
|
|
278
|
-
export declare
|
|
278
|
+
export declare function list<T>(value?: any): T[];
|
|
279
279
|
/**
|
|
280
280
|
* Retrieve the next item from the iterator by calling its `next()` method.
|
|
281
281
|
* @param iter The iterator.
|