@oscarpalmer/atoms 0.156.0 → 0.158.0
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/dist/array/index.js +2 -1
- package/dist/array/slice.js +51 -0
- package/dist/atoms.full.js +253 -124
- package/dist/function/index.js +2 -1
- package/dist/function/once.js +97 -0
- package/dist/index.js +3 -1
- package/package.json +3 -3
- package/src/array/index.ts +1 -0
- package/src/array/slice.ts +245 -0
- package/src/function/index.ts +1 -0
- package/src/function/once.ts +188 -0
- package/src/models.ts +35 -0
- package/types/array/index.d.ts +1 -0
- package/types/array/slice.d.ts +82 -0
- package/types/function/index.d.ts +1 -0
- package/types/function/once.d.ts +17 -0
- package/types/models.d.ts +31 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { PlainObject } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Drop items from the start of an array until they match a value
|
|
4
|
+
* @param array Original array
|
|
5
|
+
* @param key Key to get an item's value for matching
|
|
6
|
+
* @param value Value to match against
|
|
7
|
+
* @returns New array with items dropped
|
|
8
|
+
*/
|
|
9
|
+
export declare function drop<Item extends PlainObject, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item[];
|
|
10
|
+
/**
|
|
11
|
+
* Drop items from the start of an array until they match a value
|
|
12
|
+
* @param array Original array
|
|
13
|
+
* @param callback Callback to get an item's value for matching
|
|
14
|
+
* @param value Value to match against
|
|
15
|
+
* @return New array with items dropped
|
|
16
|
+
*/
|
|
17
|
+
export declare function drop<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
18
|
+
/**
|
|
19
|
+
* Drop items from the start of an array while they match a filter
|
|
20
|
+
* @param array Original array
|
|
21
|
+
* @param callback Filter callback to match items
|
|
22
|
+
* @return New array with items dropped
|
|
23
|
+
*/
|
|
24
|
+
export declare function drop<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
25
|
+
/**
|
|
26
|
+
* Drop a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
27
|
+
* @param array Original array
|
|
28
|
+
* @param count Number of items to drop
|
|
29
|
+
* @returns New array with items dropped
|
|
30
|
+
*/
|
|
31
|
+
export declare function drop(array: unknown[], count: number): unknown[];
|
|
32
|
+
/**
|
|
33
|
+
* Slice an array, returning a new array with a specified range of items
|
|
34
|
+
* @param array Original array
|
|
35
|
+
* @param start Start index _(inclusive)_
|
|
36
|
+
* @param end End index _(exclusive)_
|
|
37
|
+
* @return New array with sliced items
|
|
38
|
+
*/
|
|
39
|
+
export declare function slice<Item>(array: Item[], start: number, end: number): Item[];
|
|
40
|
+
/**
|
|
41
|
+
* Slice an array, returning a new array with a specified number of items
|
|
42
|
+
* @param array Original array
|
|
43
|
+
* @param count Maximum sixe of the new array
|
|
44
|
+
* @return New array with sliced items
|
|
45
|
+
*/
|
|
46
|
+
export declare function slice<Item>(array: Item[], count: number): Item[];
|
|
47
|
+
/**
|
|
48
|
+
* Slice an array
|
|
49
|
+
* @param array Array to slice
|
|
50
|
+
* @returns Sliced array
|
|
51
|
+
*/
|
|
52
|
+
export declare function slice<Item>(array: Item[]): Item[];
|
|
53
|
+
/**
|
|
54
|
+
* Take items from the start of an array until they match a value
|
|
55
|
+
* @param array Original array
|
|
56
|
+
* @param key Key to get an item's value for matching
|
|
57
|
+
* @param value Value to match against
|
|
58
|
+
* @returns New array with taken items
|
|
59
|
+
*/
|
|
60
|
+
export declare function take<Item extends PlainObject, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item[];
|
|
61
|
+
/**
|
|
62
|
+
* Take items from the start of an array until they match a value
|
|
63
|
+
* @param array Original array
|
|
64
|
+
* @param callback Callback to get an item's value for matching
|
|
65
|
+
* @param value Value to match against
|
|
66
|
+
* @return New array with taken items
|
|
67
|
+
*/
|
|
68
|
+
export declare function take<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
69
|
+
/**
|
|
70
|
+
* Take items from the start of an array while they match a filter
|
|
71
|
+
* @param array Original array
|
|
72
|
+
* @param callback Filter callback to match items
|
|
73
|
+
* @return New array with taken items
|
|
74
|
+
*/
|
|
75
|
+
export declare function take<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
76
|
+
/**
|
|
77
|
+
* Take a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
78
|
+
* @param array Original array
|
|
79
|
+
* @param count Number of items to take
|
|
80
|
+
* @returns New array with taken items
|
|
81
|
+
*/
|
|
82
|
+
export declare function take(array: unknown[], count: number): unknown[];
|
|
@@ -17,3 +17,4 @@ export declare function debounce<Callback extends GenericCallback>(callback: Cal
|
|
|
17
17
|
export declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
18
18
|
export { noop } from '../internal/function/misc';
|
|
19
19
|
export { memoize, type Memoized, type MemoizedOptions } from './memoize';
|
|
20
|
+
export { once } from './once';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GenericAsyncCallback, GenericCallback, OnceAsyncCallback, OnceCallback } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
4
|
+
* @param callback Callback to use once
|
|
5
|
+
* @returns Once callback
|
|
6
|
+
*/
|
|
7
|
+
declare function asyncOnce<Callback extends GenericAsyncCallback>(callback: Callback): OnceAsyncCallback<Callback>;
|
|
8
|
+
/**
|
|
9
|
+
* Create a function that can only be called once, returning the same value on subsequent calls
|
|
10
|
+
* @param callback Callback to use once
|
|
11
|
+
* @returns Once callback
|
|
12
|
+
*/
|
|
13
|
+
export declare function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback>;
|
|
14
|
+
export declare namespace once {
|
|
15
|
+
var async: typeof asyncOnce;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
package/types/models.d.ts
CHANGED
|
@@ -83,6 +83,37 @@ export type NumericalKeys<Value> = {
|
|
|
83
83
|
export type NumericalValues<Item extends PlainObject> = {
|
|
84
84
|
[Key in keyof Item as Item[Key] extends number ? Key : never]: Item[Key];
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* An asynchronous function that can only be called once, returning the same value on subsequent calls
|
|
88
|
+
*/
|
|
89
|
+
export type OnceAsyncCallback<Callback extends GenericAsyncCallback> = {
|
|
90
|
+
/**
|
|
91
|
+
* Did the callback's promise reject?
|
|
92
|
+
*/
|
|
93
|
+
readonly error: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Has the callback finished?
|
|
96
|
+
*/
|
|
97
|
+
readonly finished: boolean;
|
|
98
|
+
} & Callback & OnceCallbackProperties;
|
|
99
|
+
/**
|
|
100
|
+
* A callback function that can only be called once, returning the same value on subsequent calls
|
|
101
|
+
*/
|
|
102
|
+
export type OnceCallback<Callback extends GenericCallback> = Callback & OnceCallbackProperties;
|
|
103
|
+
type OnceCallbackProperties = {
|
|
104
|
+
/**
|
|
105
|
+
* Has the callback been called?
|
|
106
|
+
*/
|
|
107
|
+
readonly called: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Has the callback's value been cleared?
|
|
110
|
+
*/
|
|
111
|
+
readonly cleared: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Clear the callback's cached value
|
|
114
|
+
*/
|
|
115
|
+
clear: () => void;
|
|
116
|
+
};
|
|
86
117
|
/**
|
|
87
118
|
* A generic object
|
|
88
119
|
*/
|