atomic-fns 1.1.2 → 1.1.4

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  # atomic-fns
2
2
 
3
- [Read the Docs](https://atomic-fns.dev)
3
+ [Read the Docs](https://atomic-stack.github.io/atomic-fns/)
4
4
 
5
5
  ## Like Lodash, but in TypeScript and for ESNext.
6
6
 
7
- Stop shipping code built for browsers from 2015. Really though, look at all the [issues](https://github.com/lodash/lodash/issues/2930).
7
+ Stop shipping code built for browsers from 2015.
8
8
 
9
9
  You may prefer this because it's:
10
10
 
@@ -17,7 +17,7 @@ You may prefer this because it's:
17
17
 
18
18
  ## Docs
19
19
 
20
- 📖 Available at [atomic-fns.dev](https://atomic-fns.dev)
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,7 +47,7 @@ uniqueId('user_')
47
47
  ...
48
48
  ```
49
49
 
50
- See the full list of [modules](https://atomic-fns.dev/modules.html).
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.
@@ -67,19 +67,19 @@ When working with objects, functions in this library use these custom operators
67
67
 
68
68
  ## New Types
69
69
 
70
- [`Decimal`](https://atomic-fns.dev/classes/decimal.Decimal.html) provides support for correct rounded floating point arithmetic, with arbitrary precision.
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
71
 
72
72
  Some common base interfaces and typing patterns you may have seen like `Optional`, `Result`, `Comparable`, `Iterator`, and others.
73
73
 
74
74
  ### Sorted Containers
75
- - [SortedSet](https://atomic-fns.dev/classes/Collections.SortedSet.html)
76
- - [SortedMap](https://atomic-fns.dev/classes/Collections.SortedMap.html)
77
- - [SortedTree](https://atomic-fns.dev/classes/Collections.SortedTree.html)
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)
78
78
 
79
79
  ### Other Containers
80
- - [Deque](https://atomic-fns.dev/classes/Collections.Deque.html)
81
- - [FrozenSet](https://atomic-fns.dev/classes/Collections.FrozenSet.html)
82
- - [LRUCache](https://atomic-fns.dev/classes/Collections.LRUCache.html)
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)
83
83
 
84
84
 
85
85
  ## Contributing
@@ -45,18 +45,6 @@ count(['one', 'two', 'three'], x => x.length);
45
45
  */
46
46
  export declare function count<T>(obj: T[], fn: Iteratee<T>): Record<string, number>;
47
47
  export declare function count<T>(obj: Object, fn: Iteratee<T>): Record<string, number>;
48
- /**
49
- * Creates a function that can be used to create named tuple-like objects.
50
- * @example
51
- ```js
52
- let Point = namedtuple('x', 'y', 'z')
53
- let userObj = User(0, 0, 0)
54
- // {x: 0, y: 0, z: 0}
55
- ```
56
- * @param fields - A list of field names
57
- * @returns A function that can be called with the field values
58
- */
59
- export declare const namedtuple: (...fields: string[]) => (...args: any[]) => any;
60
48
  /**
61
49
  * Iterates over elements of collection, returning an array of all elements where predicate returns truthy value.
62
50
  *
@@ -146,7 +134,7 @@ filter(objects, matches({ a: 4, c: 6 }))
146
134
  * @param shape
147
135
  * @returns
148
136
  */
149
- export declare const matches: (shape: any) => (obj: any) => boolean;
137
+ export declare function matches(shape: any): (obj: any) => boolean;
150
138
  /**
151
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`.
152
140
  * @example
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module collections
5
5
  */
6
- import { call, get, isArray, isArrayLike, isBool, isEmpty, isFunction, isIterable, isNull, isNumber, isObject, isString, keys, set } from '../globals/index.js';
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';
@@ -38,18 +38,6 @@ export function count(obj, func) {
38
38
  });
39
39
  return counters;
40
40
  }
41
- /**
42
- * Creates a function that can be used to create named tuple-like objects.
43
- * @example
44
- ```js
45
- let Point = namedtuple('x', 'y', 'z')
46
- let userObj = User(0, 0, 0)
47
- // {x: 0, y: 0, z: 0}
48
- ```
49
- * @param fields - A list of field names
50
- * @returns A function that can be called with the field values
51
- */
52
- export const namedtuple = (...fields) => (...args) => fields.reduce((prev, f, i) => set(f, prev, args[i], false, true), {});
53
41
  export function filter(arr, fn = isNull) {
54
42
  if (!arr)
55
43
  return;
@@ -105,15 +93,17 @@ filter(objects, matches({ a: 4, c: 6 }))
105
93
  * @param shape
106
94
  * @returns
107
95
  */
108
- export const matches = (shape) => (obj) => {
109
- if (!shape || !obj)
110
- return false;
111
- for (const key in shape) {
112
- if (obj[key] !== shape[key])
96
+ export function matches(shape) {
97
+ return function (obj) {
98
+ if (!shape || !obj)
113
99
  return false;
114
- }
115
- return true;
116
- };
100
+ for (const key in shape) {
101
+ if (obj[key] !== shape[key])
102
+ return false;
103
+ }
104
+ return true;
105
+ };
106
+ }
117
107
  export function forEach(collection, fn) {
118
108
  if (Array.isArray(collection)) {
119
109
  for (let i = 0; i < collection.length; i++) {
@@ -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 const bind: (fn: Function, thisArg: any, ...partials: any[]) => any;
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 const curry: (func: Function) => (...args: any[]) => any;
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 const partial: (fn: any, ...args: any[]) => any;
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 const flow: (...args: any[]) => (x: any) => any;
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: (...args: any[]) => (x: any) => any;
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 const compose: (...args: any[]) => (x: any) => any;
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
  *
@@ -11,13 +11,15 @@
11
11
  * @returns {Function} Returns the new bound function.
12
12
  * @see {@link partial}
13
13
  */
14
- export const bind = (fn, thisArg, ...partials) => fn.bind(thisArg, ...partials);
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 const curry = (func) => {
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 const partial = (fn, ...args) => bind(fn, undefined, ...args);
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 const flow = (...args) => (x) => {
44
- for (const fn of args) {
45
- x = fn(x);
46
- }
47
- return x;
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 const compose = (...args) => flow(args.reverse());
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
  *
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export declare type Function<TReturn = any> = (...args: any) => TReturn;
10
10
  /** This is just a noop function. */
11
- export declare const noop: () => void;
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 const str: (obj: any) => any;
79
+ export declare function str(obj: any): any;
80
80
  /** Check if value is a boolean type. */
81
- export declare const isBool: (x: any) => x is boolean;
81
+ export declare function isBool(x: any): x is boolean;
82
82
  /** Check if value is an `Error` type. */
83
- export declare const isError: (x: any) => x is Error;
83
+ export declare function isError(x: any): x is Error;
84
84
  /** Check if value is an iterable type. */
85
- export declare const isIterable: (x: any) => x is IterableIterator<any>;
85
+ export declare function isIterable(x: any): x is IterableIterator<any>;
86
86
  /** Check if value is a native `Date` type. */
87
- export declare const isDate: (x: any) => x is Date;
87
+ export declare function isDate(x: any): x is Date;
88
88
  /** Check if value is an object type. */
89
- export declare const isObject: (x: any) => x is Object;
89
+ export declare function isObject(x: any): x is Object;
90
90
  /** Check if value is a string type. */
91
- export declare const isString: (x: any) => x is string;
91
+ export declare function isString(x: any): x is string;
92
92
  /** Check if value is an Array type. */
93
- export declare const isArray: (x: any) => x is any[];
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 const isArrayLike: (x: any) => boolean;
98
+ export declare function isArrayLike(x: any): boolean;
99
99
  /** Check if value is a number type. */
100
- export declare const isNumber: (x: any) => x is number;
100
+ export declare function isNumber(x: any): x is number;
101
101
  /** Check if value is an integer number type. */
102
- export declare const isInteger: (x: any) => x is number;
102
+ export declare function isInteger(x: any): x is number;
103
103
  /** Check if value is a bigint type. */
104
- export declare const isBigint: (x: any) => x is BigInt;
104
+ export declare function isBigint(x: any): x is BigInt;
105
105
  /** Check if value is a Promise type. */
106
- export declare const isPromise: (x: any) => x is Promise<any>;
106
+ export declare function isPromise(x: any): x is Promise<any>;
107
107
  /** Check if value is a function type. */
108
- export declare const isFunction: (x: any) => x is Function<any>;
108
+ export declare function isFunction(x: any): x is Function;
109
109
  /** Check if value is an async function type. */
110
- export declare const isAsyncFunction: (x: any) => boolean;
110
+ export declare function isAsyncFunction(x: any): boolean;
111
111
  /** Check if value is a generator function type. */
112
- export declare const isGenerator: (x: any) => x is Generator<unknown, any, unknown>;
112
+ export declare function isGenerator(x: any): x is Generator;
113
113
  /** Check if value is `null` or `undefined`. */
114
- export declare const isNull: (x: any) => x is null;
114
+ export declare function isNull(x: any): x is null | undefined;
115
115
  /** Check if value === `undefined`. */
116
- export declare const isUndefined: (x: any) => x is undefined;
116
+ export declare function isUndefined(x: any): x is undefined;
117
117
  /** Check if value is not `null` or `undefined`. */
118
- export declare const notNull: (x: any) => boolean;
118
+ export declare function notNull(x: any): boolean;
119
119
  /** Returns `true` for objects without length or falsy values. */
120
- export declare const isEmpty: (x: any) => boolean;
120
+ export declare function isEmpty(x: any): boolean;
121
121
  /** Check if value is a `RegExp` type */
122
- export declare const isRegExp: (x: any) => x is RegExp;
122
+ export declare function isRegExp(x: any): x is RegExp;
123
123
  /** Check if value is a `Symbol` type */
124
- export declare const isSymbol: (x: any) => x is symbol;
124
+ export declare function isSymbol(x: any): x is symbol;
125
125
  /** Check if value is a `Set` type. */
126
- export declare const isSet: <T>(x: any) => x is Set<T>;
126
+ export declare function isSet<T>(x: any): x is Set<T>;
127
127
  /** Check if value is a `Map` type. */
128
- export declare const isMap: <K, V>(x: any) => x is Map<K, V>;
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 const isWeakSet: <T extends object>(x: any) => x is WeakSet<T>;
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 const isWeakMap: <K extends object, V>(x: any) => x is WeakMap<K, V>;
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 const uniqueId: (pre?: string) => string;
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 const uuid: () => string;
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 const chr: (x: number) => string;
175
+ export declare function chr(x: number): string;
176
176
  /** Convert character to Unicode code point */
177
- export declare const ord: (x: string) => number;
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 const keys: <T>(object: T) => (keyof T)[];
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 const values: (object: any) => unknown[];
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 const has: (obj: any, attr: PropertyKey) => boolean;
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 const bin: (n: number) => string;
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 const hex: (n: number) => string;
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 const oct: (n: number) => string;
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 const float: (x: string) => number;
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 const int: (x: string, base?: number) => number;
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 const list: <T>(value?: any) => T[];
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.