atomic-fns 0.2.0 → 0.2.2

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.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Collections
3
+ * @module
4
+ */
1
5
  import {
2
6
  call,
3
7
  Function,
@@ -261,7 +265,7 @@ export function filter(arr, fn: Iteratee | PropertyKey | Object = isNull) {
261
265
  export function find(arr, fn: Iteratee | PropertyKey | Object) {
262
266
  if (Array.isArray(arr)) {
263
267
  if (typeof fn === 'function') return arr.find(fn as Iteratee)
264
- if (typeof fn === 'string') return arr.find((x) => x && x[fn])
268
+ if (typeof fn === 'string') return arr.find((x) => x?.[fn])
265
269
  if (isObject(fn)) return arr.find(matches(fn))
266
270
  }
267
271
  }
@@ -273,7 +277,7 @@ export function findRight(arr, fn: Iteratee | PropertyKey | Object) {
273
277
  if (typeof fn === 'function') {
274
278
  if (fn(x)) return x
275
279
  } else if (typeof fn === 'string') {
276
- if (x && x[fn]) return x
280
+ if (x?.[fn]) return x
277
281
  } else if (isObject(fn)) {
278
282
  if (matches(fn)(x)) return x
279
283
  }
package/src/datetime.d.ts CHANGED
@@ -1 +1,5 @@
1
+ /**
2
+ * Date
3
+ * @module
4
+ */
1
5
  export declare const now: number;
package/src/datetime.js CHANGED
@@ -1 +1,5 @@
1
- export const now = new Date().getTime();
1
+ /**
2
+ * Date
3
+ * @module
4
+ */
5
+ export const now = new Date().getTime()
package/src/datetime.ts CHANGED
@@ -1 +1,6 @@
1
+ /**
2
+ * Date
3
+ * @module
4
+ */
5
+
1
6
  export const now = new Date().getTime()
@@ -1,3 +1,7 @@
1
+ /**
2
+ * FP
3
+ * @module
4
+ */
1
5
  import { Function } from './globals.js';
2
6
  export declare const bind: (fn: any, self: any, ...args: any[]) => any;
3
7
  export declare const partial: (fn: any, ...args: any[]) => any;
package/src/functools.js CHANGED
@@ -1,13 +1,15 @@
1
- export const bind = (fn, self, ...args) => fn.bind(self, ...args);
2
- export const partial = (fn, ...args) => bind(fn, {}, ...args);
3
- export const flow = (...args) => (x) => {
1
+ export const bind = (fn, self, ...args) => fn.bind(self, ...args)
2
+ export const partial = (fn, ...args) => bind(fn, {}, ...args)
3
+ export const flow =
4
+ (...args) =>
5
+ (x) => {
4
6
  for (const fn of args) {
5
- x = fn(x);
7
+ x = fn(x)
6
8
  }
7
- return x;
8
- };
9
- export const pipe = flow;
10
- export const compose = (...args) => flow(args.reverse());
9
+ return x
10
+ }
11
+ export const pipe = flow
12
+ export const compose = (...args) => flow(args.reverse())
11
13
  /**
12
14
  * 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.
13
15
  *
@@ -17,16 +19,15 @@ export const compose = (...args) => flow(args.reverse());
17
19
  * @return {Function} Returns the new memoized function.
18
20
  */
19
21
  export function memoize(func, resolver) {
20
- const cache = new Map();
21
- return (...args) => {
22
- const key = resolver ? resolver(...args) : args[0];
23
- const prev = cache.get(key);
24
- if (prev !== undefined)
25
- return prev;
26
- const value = func(...args);
27
- cache.set(key, value);
28
- return value;
29
- };
22
+ const cache = new Map()
23
+ return (...args) => {
24
+ const key = resolver ? resolver(...args) : args[0]
25
+ const prev = cache.get(key)
26
+ if (prev !== undefined) return prev
27
+ const value = func(...args)
28
+ cache.set(key, value)
29
+ return value
30
+ }
30
31
  }
31
32
  /**
32
33
  * 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,24 +39,23 @@ export function memoize(func, resolver) {
38
39
  * @return {Function} Returns the new debounced function.
39
40
  */
40
41
  export function debounce(func, wait, { maxWait }) {
41
- let timer, maxTimer, lastResult;
42
- return (...args) => {
43
- if (timer)
44
- clearTimeout(timer);
45
- timer = setTimeout(() => {
46
- clearTimeout(maxTimer);
47
- maxTimer = null;
48
- lastResult = func(...args);
49
- }, wait);
50
- if (maxWait && !maxTimer) {
51
- maxTimer = setTimeout(() => {
52
- clearTimeout(timer);
53
- maxTimer = null;
54
- lastResult = func(...args);
55
- }, maxWait);
56
- }
57
- return lastResult;
58
- };
42
+ let timer, maxTimer, lastResult
43
+ return (...args) => {
44
+ if (timer) clearTimeout(timer)
45
+ timer = setTimeout(() => {
46
+ clearTimeout(maxTimer)
47
+ maxTimer = null
48
+ lastResult = func(...args)
49
+ }, wait)
50
+ if (maxWait && !maxTimer) {
51
+ maxTimer = setTimeout(() => {
52
+ clearTimeout(timer)
53
+ maxTimer = null
54
+ lastResult = func(...args)
55
+ }, maxWait)
56
+ }
57
+ return lastResult
58
+ }
59
59
  }
60
60
  /**
61
61
  * 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.
@@ -66,14 +66,13 @@ export function debounce(func, wait, { maxWait }) {
66
66
  * @return {Function} Returns the new throttled function.
67
67
  */
68
68
  export function throttle(func, time) {
69
- let pending = false;
70
- return (...args) => {
71
- if (pending)
72
- return;
73
- func(...args);
74
- pending = true;
75
- setTimeout(() => {
76
- pending = false;
77
- }, time);
78
- };
69
+ let pending = false
70
+ return (...args) => {
71
+ if (pending) return
72
+ func(...args)
73
+ pending = true
74
+ setTimeout(() => {
75
+ pending = false
76
+ }, time)
77
+ }
79
78
  }
package/src/functools.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * FP
3
+ * @module
4
+ */
1
5
  import { Function } from './globals.js'
2
6
 
3
7
  export const bind = (fn, self, ...args) => fn.bind(self, ...args)
package/src/globals.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Globals
3
+ * @module
4
+ */
1
5
  export declare type Comp = (x: any, y: any) => number;
2
6
  export declare type Function = (...args: any[]) => any;
3
7
  export declare type Iteratee = (value: any, key?: any, arr?: any) => any;
@@ -13,10 +17,10 @@ export declare const False: () => boolean;
13
17
  export declare class CustomError extends Error {
14
18
  /**
15
19
  * Returns a new CustomError with the specified message.
16
- * @param message
20
+ * @param {string} message
17
21
  * @constructor
18
22
  */
19
- constructor(message?: any);
23
+ constructor(message?: string);
20
24
  }
21
25
  /**
22
26
  * Custom error to signal an invalid index access.
@@ -136,7 +140,7 @@ export declare function round(x: number, digits?: number): number;
136
140
  export declare const floor: (x: number) => number;
137
141
  export declare const ceil: (x: number) => number;
138
142
  /**
139
- * Yields elements like [index, item] from an iterable.
143
+ * Yields elements like `[index, item]` from an iterable.
140
144
  *
141
145
  *
142
146
  * @template T