atomic-fns 0.2.2 → 0.2.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.
Files changed (64) hide show
  1. package/README.md +5 -3
  2. package/package.json +6 -7
  3. package/src/collections/index.d.ts +658 -0
  4. package/src/collections/index.js +1068 -0
  5. package/src/collections/index.ts +1162 -0
  6. package/src/datetime/index.d.ts +6 -0
  7. package/src/datetime/index.js +6 -0
  8. package/src/datetime/index.ts +7 -0
  9. package/src/{functools.d.ts → functools/index.d.ts} +8 -7
  10. package/src/functools/index.js +84 -0
  11. package/src/{functools.ts → functools/index.ts} +9 -7
  12. package/src/globals/index.d.ts +291 -0
  13. package/src/globals/index.js +391 -0
  14. package/src/globals/index.ts +456 -0
  15. package/src/index.d.ts +8 -7
  16. package/src/index.js +8 -7
  17. package/src/index.ts +8 -7
  18. package/src/itertools/index.d.ts +254 -0
  19. package/src/itertools/index.js +485 -0
  20. package/src/itertools/index.ts +511 -0
  21. package/src/math/index.d.ts +21 -0
  22. package/src/math/index.js +39 -0
  23. package/src/math/index.ts +44 -0
  24. package/src/{operators.d.ts → operators/index.d.ts} +8 -6
  25. package/src/operators/index.js +171 -0
  26. package/src/{operators.ts → operators/index.ts} +75 -30
  27. package/src/random/index.d.ts +42 -0
  28. package/src/random/index.js +65 -0
  29. package/src/random/index.ts +66 -0
  30. package/tests/collections.spec.ts +42 -25
  31. package/tests/globals.spec.ts +51 -47
  32. package/tests/itertools.spec.ts +190 -4
  33. package/tests/operators.spec.ts +1 -26
  34. package/tests/random.spec.ts +46 -0
  35. package/tsconfig.json +12 -4
  36. package/src/collections.d.ts +0 -228
  37. package/src/collections.js +0 -553
  38. package/src/collections.ts +0 -641
  39. package/src/datetime.d.ts +0 -5
  40. package/src/datetime.js +0 -5
  41. package/src/datetime.ts +0 -6
  42. package/src/functools.js +0 -78
  43. package/src/globals.d.ts +0 -179
  44. package/src/globals.js +0 -309
  45. package/src/globals.ts +0 -377
  46. package/src/itertools.d.ts +0 -20
  47. package/src/itertools.js +0 -98
  48. package/src/itertools.ts +0 -116
  49. package/src/math.d.ts +0 -16
  50. package/src/math.js +0 -70
  51. package/src/math.ts +0 -77
  52. package/src/objects.d.ts +0 -0
  53. package/src/objects.js +0 -1
  54. package/src/objects.ts +0 -0
  55. package/src/operators.js +0 -109
  56. package/src/random.d.ts +0 -22
  57. package/src/random.js +0 -48
  58. package/src/random.ts +0 -53
  59. package/src/strings.d.ts +0 -0
  60. package/src/strings.js +0 -1
  61. package/src/strings.ts +0 -0
  62. package/src/util.d.ts +0 -0
  63. package/src/util.js +0 -1
  64. package/src/util.ts +0 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This module includes classes and functions to work with Date types.
3
+ *
4
+ * @module Date
5
+ */
6
+ export declare const now: number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This module includes classes and functions to work with Date types.
3
+ *
4
+ * @module Date
5
+ */
6
+ export const now = new Date().getTime();
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This module includes classes and functions to work with Date types.
3
+ *
4
+ * @module Date
5
+ */
6
+
7
+ export const now = new Date().getTime()
@@ -1,8 +1,9 @@
1
1
  /**
2
- * FP
3
- * @module
2
+ * This module includes functions that promote a more functional programming style.
3
+ *
4
+ * @module Functions
4
5
  */
5
- import { Function } from './globals.js';
6
+ import { Function } from '../globals/index.js';
6
7
  export declare const bind: (fn: any, self: any, ...args: any[]) => any;
7
8
  export declare const partial: (fn: any, ...args: any[]) => any;
8
9
  export declare const flow: (...args: any[]) => (x: any) => any;
@@ -21,10 +22,10 @@ export declare function memoize(func: Function, resolver?: Function): Function;
21
22
  * Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
22
23
  *
23
24
  *
24
- * @param {Function} func The function to debounce.
25
- * @param {number} wait The number of milliseconds to delay.
26
- * @param {{ maxWait: number }} { maxWait } The maximum time `func` is allowed to be delayed before it's invoked.
27
- * @return {Function} Returns the new debounced function.
25
+ * @param func The function to debounce.
26
+ * @param wait The number of milliseconds to delay.
27
+ * @param maxWait The maximum time `func` is allowed to be delayed before it's invoked.
28
+ * @returns Returns the new debounced function.
28
29
  */
29
30
  export declare function debounce(func: Function, wait: number, { maxWait }: {
30
31
  maxWait: number;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * This module includes functions that promote a more functional programming style.
3
+ *
4
+ * @module Functions
5
+ */
6
+ export const bind = (fn, self, ...args) => fn.bind(self, ...args);
7
+ export const partial = (fn, ...args) => bind(fn, {}, ...args);
8
+ export const flow = (...args) => (x) => {
9
+ for (const fn of args) {
10
+ x = fn(x);
11
+ }
12
+ return x;
13
+ };
14
+ export const pipe = flow;
15
+ export const compose = (...args) => flow(args.reverse());
16
+ /**
17
+ * 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.
18
+ *
19
+ *
20
+ * @param {Function} func The function to have its output memoized.
21
+ * @param {Function} [resolver] The function to resolve the cache key.
22
+ * @return {Function} Returns the new memoized function.
23
+ */
24
+ export function memoize(func, resolver) {
25
+ const cache = new Map();
26
+ return (...args) => {
27
+ const key = resolver ? resolver(...args) : args[0];
28
+ const prev = cache.get(key);
29
+ if (prev !== undefined)
30
+ return prev;
31
+ const value = func(...args);
32
+ cache.set(key, value);
33
+ return value;
34
+ };
35
+ }
36
+ /**
37
+ * Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
38
+ *
39
+ *
40
+ * @param func The function to debounce.
41
+ * @param wait The number of milliseconds to delay.
42
+ * @param maxWait The maximum time `func` is allowed to be delayed before it's invoked.
43
+ * @returns Returns the new debounced function.
44
+ */
45
+ export function debounce(func, wait, { maxWait }) {
46
+ let timer, maxTimer, lastResult;
47
+ return (...args) => {
48
+ if (timer)
49
+ clearTimeout(timer);
50
+ timer = setTimeout(() => {
51
+ clearTimeout(maxTimer);
52
+ maxTimer = null;
53
+ lastResult = func(...args);
54
+ }, wait);
55
+ if (maxWait && !maxTimer) {
56
+ maxTimer = setTimeout(() => {
57
+ clearTimeout(timer);
58
+ maxTimer = null;
59
+ lastResult = func(...args);
60
+ }, maxWait);
61
+ }
62
+ return lastResult;
63
+ };
64
+ }
65
+ /**
66
+ * Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds. Subsequent calls to the throttled function return the result of the last successful invocation.
67
+ *
68
+ *
69
+ * @param {Function} func The function to throttle.
70
+ * @param {number} time The number of milliseconds to throttle invocations to.
71
+ * @return {Function} Returns the new throttled function.
72
+ */
73
+ export function throttle(func, time) {
74
+ let pending = false;
75
+ return (...args) => {
76
+ if (pending)
77
+ return;
78
+ func(...args);
79
+ pending = true;
80
+ setTimeout(() => {
81
+ pending = false;
82
+ }, time);
83
+ };
84
+ }
@@ -1,8 +1,10 @@
1
1
  /**
2
- * FP
3
- * @module
2
+ * This module includes functions that promote a more functional programming style.
3
+ *
4
+ * @module Functions
4
5
  */
5
- import { Function } from './globals.js'
6
+
7
+ import { Function } from '../globals/index.js'
6
8
 
7
9
  export const bind = (fn, self, ...args) => fn.bind(self, ...args)
8
10
 
@@ -45,10 +47,10 @@ export function memoize(func: Function, resolver?: Function): Function {
45
47
  * Creates a debounced function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time the debounced function was invoked. Subsequent calls to the debounced function return the result of the last successful invocation. Provide options to set the `maxWait` milliseconds, regardless of when the function was last invoked.
46
48
  *
47
49
  *
48
- * @param {Function} func The function to debounce.
49
- * @param {number} wait The number of milliseconds to delay.
50
- * @param {{ maxWait: number }} { maxWait } The maximum time `func` is allowed to be delayed before it's invoked.
51
- * @return {Function} Returns the new debounced function.
50
+ * @param func The function to debounce.
51
+ * @param wait The number of milliseconds to delay.
52
+ * @param maxWait The maximum time `func` is allowed to be delayed before it's invoked.
53
+ * @returns Returns the new debounced function.
52
54
  */
53
55
  export function debounce(func: Function, wait: number, { maxWait }: { maxWait: number }): Function {
54
56
  let timer, maxTimer, lastResult
@@ -0,0 +1,291 @@
1
+ /**
2
+ * This module includes global functions and constants.
3
+ *
4
+ * @module Globals
5
+ */
6
+ /** Describes a function used to compare two values.
7
+ *
8
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description}
9
+ */
10
+ export declare type Comp = (x: any, y: any) => -1 | 0 | 1;
11
+ /**
12
+ * A generic function type with arbitrary arguments and return.
13
+ */
14
+ export declare type Function = (...args: any[]) => any;
15
+ /**
16
+ * An iteratee function used for collection methods.
17
+ * @see {@link filter}
18
+ * @see {@link find}
19
+ * @see {@link forEach}
20
+ * @see {@link index}
21
+ * @see {@link map}
22
+ * @see {@link pick}
23
+ * @see {@link omit}
24
+ * @see {@link uniq}
25
+ * @see {@link sortedUniq}
26
+ * @see {@link groupBy}
27
+ */
28
+ export declare type Iteratee<T = any> = (value: T, key?: any, arr?: any) => any;
29
+ export declare type Predicate<T = any> = (value: T) => any;
30
+ /** A function that always returns `true`. */
31
+ export declare const True: () => boolean;
32
+ /** A function that always returns `false`. */
33
+ export declare const False: () => boolean;
34
+ /**
35
+ * A custom error class that inherits from the Error object.
36
+ * @class CustomError
37
+ * @extends {Error}
38
+ */
39
+ export declare class CustomError extends Error {
40
+ /**
41
+ * Returns a new CustomError with the specified message.
42
+ * @param {string} message
43
+ * @constructor
44
+ */
45
+ constructor(message?: string);
46
+ }
47
+ /**
48
+ * Custom error to signal an invalid index access.
49
+ * @extends {CustomError}
50
+ */
51
+ export declare class IndexError extends CustomError {
52
+ }
53
+ /**
54
+ * Raised when a system function returns an I/O failure such as "file not found"
55
+ * or "disk full".
56
+ * @extends {CustomError}
57
+ */
58
+ export declare class IOError extends CustomError {
59
+ }
60
+ /**
61
+ * Custom error to signal an invalid key access.
62
+ * @extends {CustomError}
63
+ */
64
+ export declare class KeyError extends CustomError {
65
+ }
66
+ /**
67
+ * Custom error to signal an invalid operation.
68
+ * @extends {CustomError}
69
+ */
70
+ export declare class NotImplementedError extends CustomError {
71
+ }
72
+ /**
73
+ * Custom error to signal an invalid value.
74
+ * @extends {CustomError}
75
+ */
76
+ export declare class ValueError extends CustomError {
77
+ }
78
+ /**
79
+ * Raised when the second argument of a division or modulo operation is zero.
80
+ * @extends {CustomError}
81
+ */
82
+ export declare class ZeroDivisionError extends CustomError {
83
+ }
84
+ /**
85
+ * Returns the true type of any value with correct detection for null, Array,
86
+ * 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.
87
+ * @param value
88
+ * @returns The value type.
89
+ */
90
+ export declare function type(value: any): any;
91
+ /**
92
+ * Returns a string representing the object.
93
+ * @param obj
94
+ * @returns `obj.toString()` or `''` if `obj` is `null` or `undefined`.
95
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | Object.toString }
96
+ */
97
+ export declare const str: (obj: any) => any;
98
+ /** Check if value is a boolean type. */
99
+ export declare const isBool: (x: any) => x is boolean;
100
+ /** Check if value is an iterable type. */
101
+ export declare const isIterable: (x: any) => x is IterableIterator<any>;
102
+ /** Check if value is an object type. */
103
+ export declare const isObject: (x: any) => x is Object;
104
+ /** Check if value is a string type. */
105
+ export declare const isString: (x: any) => x is string;
106
+ /** Check if value is an Array type. */
107
+ export declare const isArray: (x: any) => x is any[];
108
+ /**
109
+ * Check if value is Array-like type.
110
+ * A value is considered array-like if it's not a function and has a `.length` number property.
111
+ */
112
+ export declare const isArrayLike: (x: any) => boolean;
113
+ /** Check if value is a function type. */
114
+ export declare const isFunc: (x: any) => x is Function;
115
+ /** Check if value is a number type. */
116
+ export declare const isNumber: (x: any) => x is number;
117
+ /** Check if value is a bigint type. */
118
+ export declare const isBigint: (x: any) => x is BigInt;
119
+ /** Check if value is NaN based on `Number.isNaN`. */
120
+ export declare const isNaN: (x: any) => x is number;
121
+ /** Check if value is a Promise type. */
122
+ export declare const isPromise: (x: any) => x is Promise<any>;
123
+ /** Check if value is an async function type. */
124
+ export declare const isAsync: (x: any) => boolean;
125
+ /** Check if value is a generator function type. */
126
+ export declare const isGenerator: (x: any) => x is Generator<unknown, any, unknown>;
127
+ /** Check if value is `null` or `undefined`. */
128
+ export declare const isNull: (x: any) => x is null | undefined;
129
+ /** Check if value is not `null` or `undefined`. */
130
+ export declare const notNull: (x: any) => boolean;
131
+ /** Returns `true` for objects without length or falsey values. */
132
+ export declare const isEmpty: (x: any) => boolean;
133
+ /** Check if value is a `Symbol` type */
134
+ export declare const isSymbol: (x: any) => x is symbol;
135
+ /**
136
+ * Returns the number of elements in a collection type.
137
+ *
138
+ * If `value.length` or `value.size()` is defined, this will be returned.
139
+ * If `value` is an `Object`, it returns the number of keys.
140
+ * @param value
141
+ * @returns The number of elements in the collection or `undefined`.
142
+ */
143
+ export declare function len(value: any): any;
144
+ /**
145
+ * Generates a unique ID using random numbers.
146
+ * If prefix is given, the ID is appended to it.
147
+ */
148
+ export declare const uniqueId: (pre?: string) => any;
149
+ /**
150
+ * Checks if `obj.key` is a function, and calls it with any given `args`.
151
+ * @param {*} obj
152
+ * @param {PropertyKey} key
153
+ * @param {...any[]} args
154
+ * @return `obj.key(...args)` or `undefined`.
155
+ */
156
+ export declare function call(obj: any, key: PropertyKey, ...args: any[]): any;
157
+ /** Convert number to unicode character */
158
+ export declare const chr: (x: number) => string;
159
+ /** Convert character to Unicode code point */
160
+ export declare const ord: (x: string) => number;
161
+ /**
162
+ * Returns an array of the own enumerable property names of `object`.
163
+ * @param object The given object.
164
+ * @returns The array of object keys.
165
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys Object.keys()}
166
+ */
167
+ export declare const keys: (object: Object) => string[];
168
+ /**
169
+ * Returns an array of the own enumerable property values of `object`.
170
+ * @param object The given object.
171
+ * @returns The array of object keys.
172
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Object.values()}
173
+ */
174
+ export declare const values: (object: any) => unknown[];
175
+ /**
176
+ * Round `x` to the number of digits after the decimal point. If `digits` is
177
+ * omitted, it returns the nearest integer to x.
178
+ *
179
+ * @param {number} x
180
+ * @param {number} [digits=0]
181
+ *
182
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round Math.round()}
183
+ */
184
+ export declare function round(x: number, digits?: number): number;
185
+ /**
186
+ * Rounds down and returns the largest integer less than or equal to a given number.
187
+ * @param x A number.
188
+ * @returns Nearest integer less than or equal to number.
189
+ *
190
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor Math.floor()}
191
+ */
192
+ export declare const floor: (x: number) => number;
193
+ /**
194
+ * Rounds up and returns the largest integer greater than or equal to a given number.
195
+ * @param x A number.
196
+ * @returns Nearest integer greater than or equal to number.
197
+ *
198
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil Math.ceil()}
199
+ */
200
+ export declare const ceil: (x: number) => number;
201
+ /**
202
+ * Check if a given property is present in a given object.
203
+ * @param obj The object to check.
204
+ * @param attr A property key name.
205
+ * @returns `true` if the object has the property name.
206
+ */
207
+ export declare const has: (obj: any, attr: PropertyKey) => any;
208
+ /**
209
+ * Check if the attribute is present in the object or return a default value instead.
210
+ * @param {PropertyKey} key
211
+ * @param {*} obj
212
+ * @param {*} [value=undefined]
213
+ * @return The property value or default value.
214
+ */
215
+ export declare function get(key: PropertyKey | PropertyKey[], obj: any, value?: any): any;
216
+ /**
217
+ * Deletes a given property key from an object.
218
+ * @param attr The property name.
219
+ * @param x The given object.
220
+ * @returns The modified object.
221
+ */
222
+ export declare function del(attr: PropertyKey, x: any): any;
223
+ /**
224
+ * Adds a property to an object, or modifies the existing value.
225
+ * @param attr The name or Symbol of the property to be defined or modified.
226
+ * @param obj The container object.
227
+ * @param value The value associated with the property
228
+ * @param {boolean} [writable=false] If `true` the value may be changed later. Defaults to `false`.
229
+ * @param {boolean} [enumerable=false] If `true` this property shows up during enumeration of the properties in the object. Defaults to `false`.
230
+ * @returns
231
+ */
232
+ export declare function set(attr: PropertyKey, obj: any, value: any, writable?: boolean, enumerable?: boolean): any;
233
+ export declare const HASH_KEY: unique symbol;
234
+ /**
235
+ * Return a hash value for a given object. The hash will be the same for subsequent invocations.
236
+ * @param obj The given object.
237
+ * @returns The hash value.
238
+ */
239
+ export declare function hash(obj: any): any;
240
+ /**
241
+ * A hash value generator for strings.
242
+ * @param {string} str The given string.
243
+ * @returns {number} The hash value of the string.
244
+ * @see {@link http://isthe.com/chongo/tech/comp/fnv/ FNV hash}
245
+ */
246
+ export declare function hashCode(str: string): number;
247
+ /**
248
+ * Converts a number to a binary string.
249
+ * @param n The given number.
250
+ * @returns The binary string representation of `n`.
251
+ */
252
+ export declare const bin: (n: number) => string;
253
+ /**
254
+ * Converts a number to a hexadecimal string.
255
+ * @param n The given number.
256
+ * @returns The hexadecimal string representation of `n`.
257
+ */
258
+ export declare const hex: (n: number) => string;
259
+ /**
260
+ * Converts a number to an octal string.
261
+ * @param n The given number.
262
+ * @returns The octal string representation of `n`.
263
+ */
264
+ export declare const oct: (n: number) => string;
265
+ /**
266
+ * Returns a floating point number constructed from a number or string `x`.
267
+ * @param x The number or string.
268
+ * @returns A floating point number parsed from the given value or `NaN`.
269
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat parseFloat}
270
+ */
271
+ export declare const float: (x: any) => number;
272
+ /**
273
+ * Returns an integer number constructed from a number or string `x`.
274
+ * @param x The number or string.
275
+ * @returns An integer number parsed from the given value or `NaN`.
276
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt}
277
+ */
278
+ export declare const int: (x: any, base?: number) => number;
279
+ /**
280
+ * Converts the value to an array using `Array.from()`.
281
+ * @param value
282
+ * @returns A new array value.
283
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
284
+ */
285
+ export declare const list: (value?: any) => unknown[];
286
+ /**
287
+ * Retrieve the next item from the iterator by calling it's `next()` method.
288
+ * @param iter The iterator.
289
+ * @returns The next value from the iterator.
290
+ */
291
+ export declare const next: (iter: Iterator<any> | Generator) => any;