@solid-primitives/utils 6.2.3 → 6.3.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/immutable/array.d.ts +112 -0
- package/dist/immutable/array.js +139 -0
- package/dist/immutable/copy.d.ts +27 -0
- package/dist/immutable/copy.js +37 -0
- package/dist/immutable/index.d.ts +6 -257
- package/dist/immutable/index.js +6 -151
- package/dist/immutable/number.d.ts +13 -0
- package/dist/immutable/number.js +37 -0
- package/dist/immutable/object.d.ts +63 -0
- package/dist/immutable/object.js +53 -0
- package/dist/immutable/types.d.ts +7 -0
- package/dist/immutable/types.js +1 -0
- package/dist/immutable/update.d.ts +30 -0
- package/dist/immutable/update.js +29 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.js +213 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.js +1 -0
- package/package.json +7 -14
- package/dist/chunk/R5675YMU.js +0 -139
- package/dist/immutable/index.cjs +0 -161
- package/dist/immutable/index.d.cts +0 -257
- package/dist/index/index.cjs +0 -151
- package/dist/index/index.d.cts +0 -130
- package/dist/index/index.d.ts +0 -130
- package/dist/index/index.js +0 -1
- package/dist/types-d58cbe2f.d.ts +0 -90
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AnyClass, ItemsOf, Many } from "../index.js";
|
|
2
|
+
import { FlattenArray, MappingFn, Predicate } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* non-mutating `Array.prototype.push()`
|
|
5
|
+
* @returns changed array copy
|
|
6
|
+
*/
|
|
7
|
+
export declare const push: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
8
|
+
/**
|
|
9
|
+
* non-mutating function that drops n items from the array start.
|
|
10
|
+
* @returns changed array copy
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const newList = drop([1,2,3])
|
|
15
|
+
* newList // => [2,3]
|
|
16
|
+
*
|
|
17
|
+
* const newList = drop([1,2,3], 2)
|
|
18
|
+
* newList // => [3]
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const drop: <T>(list: T[], n?: number) => T[];
|
|
22
|
+
/**
|
|
23
|
+
* non-mutating function that drops n items from the array end.
|
|
24
|
+
* @returns changed array copy
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const newList = dropRight([1,2,3])
|
|
29
|
+
* newList // => [1,2]
|
|
30
|
+
*
|
|
31
|
+
* const newList = dropRight([1,2,3], 2)
|
|
32
|
+
* newList // => [1]
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const dropRight: <T>(list: T[], n?: number) => T[];
|
|
36
|
+
/**
|
|
37
|
+
* standalone `Array.prototype.filter()` that filters out passed item
|
|
38
|
+
* @returns changed array copy
|
|
39
|
+
*/
|
|
40
|
+
export declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
|
|
41
|
+
removed: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* standalone `Array.prototype.filter()`
|
|
45
|
+
* @returns changed array copy
|
|
46
|
+
*/
|
|
47
|
+
export declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
|
|
48
|
+
removed: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* non-mutating `Array.prototype.sort()` as a standalone function
|
|
52
|
+
* @returns changed array copy
|
|
53
|
+
*/
|
|
54
|
+
export declare const sort: <T>(list: T[], compareFn?: (a: T, b: T) => number) => T[];
|
|
55
|
+
/**
|
|
56
|
+
* standalone `Array.prototype.map()` function
|
|
57
|
+
*/
|
|
58
|
+
export declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
|
|
59
|
+
/**
|
|
60
|
+
* standalone `Array.prototype.slice()` function
|
|
61
|
+
*/
|
|
62
|
+
export declare const slice: <T>(list: readonly T[], start?: number, end?: number) => T[];
|
|
63
|
+
/**
|
|
64
|
+
* non-mutating `Array.prototype.splice()` as a standalone function
|
|
65
|
+
* @returns changed array copy
|
|
66
|
+
*/
|
|
67
|
+
export declare const splice: <T>(list: readonly T[], start: number, deleteCount?: number, ...items: T[]) => T[];
|
|
68
|
+
/**
|
|
69
|
+
* non-mutating `Array.prototype.fill()` as a standalone function
|
|
70
|
+
* @returns changed array copy
|
|
71
|
+
*/
|
|
72
|
+
export declare const fill: <T>(list: readonly T[], value: T, start?: number, end?: number) => T[];
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new array concatenating array with any additional arrays and/or values.
|
|
75
|
+
* @param ...a values or arrays
|
|
76
|
+
* @returns new concatenated array
|
|
77
|
+
*/
|
|
78
|
+
export declare function concat<A extends any[], V extends ItemsOf<A>>(...a: A): Array<V extends any[] ? ItemsOf<V> : V>;
|
|
79
|
+
/**
|
|
80
|
+
* Remove item from array
|
|
81
|
+
* @returns changed array copy
|
|
82
|
+
*/
|
|
83
|
+
export declare const remove: <T>(list: readonly T[], item: T, ...insertItems: T[]) => T[];
|
|
84
|
+
/**
|
|
85
|
+
* Remove multiple items from an array
|
|
86
|
+
* @returns changed array copy
|
|
87
|
+
*/
|
|
88
|
+
export declare const removeItems: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
89
|
+
/**
|
|
90
|
+
* Flattens a nested array into a one-level array
|
|
91
|
+
* @returns changed array copy
|
|
92
|
+
*/
|
|
93
|
+
export declare const flatten: <T extends any[]>(arr: T) => FlattenArray<T>[];
|
|
94
|
+
/**
|
|
95
|
+
* Sort an array by object key, or multiple keys
|
|
96
|
+
* @returns changed array copy
|
|
97
|
+
*/
|
|
98
|
+
export declare const sortBy: <T>(arr: T[], ...paths: T extends object ? (Many<keyof T> | Many<(item: T) => any>)[] : Many<(item: T) => any>[]) => T[];
|
|
99
|
+
/**
|
|
100
|
+
* Returns a subset of items that are instances of provided Classes
|
|
101
|
+
* @param list list of original items
|
|
102
|
+
* @param ...classes list or classes
|
|
103
|
+
* @returns changed array copy
|
|
104
|
+
*/
|
|
105
|
+
export declare const filterInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Extract<T, InstanceType<ItemsOf<I>>>[];
|
|
106
|
+
/**
|
|
107
|
+
* Returns a subset of items that aren't instances of provided Classes
|
|
108
|
+
* @param list list of original items
|
|
109
|
+
* @param ...classes list or classes
|
|
110
|
+
* @returns changed array copy
|
|
111
|
+
*/
|
|
112
|
+
export declare const filterOutInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Exclude<T, InstanceType<ItemsOf<I>>>[];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { compare, ofClass } from "../index.js";
|
|
2
|
+
import { withArrayCopy } from "./copy.js";
|
|
3
|
+
import { get } from "./object.js";
|
|
4
|
+
/**
|
|
5
|
+
* non-mutating `Array.prototype.push()`
|
|
6
|
+
* @returns changed array copy
|
|
7
|
+
*/
|
|
8
|
+
export const push = (list, ...items) => withArrayCopy(list, list => list.push(...items));
|
|
9
|
+
/**
|
|
10
|
+
* non-mutating function that drops n items from the array start.
|
|
11
|
+
* @returns changed array copy
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const newList = drop([1,2,3])
|
|
16
|
+
* newList // => [2,3]
|
|
17
|
+
*
|
|
18
|
+
* const newList = drop([1,2,3], 2)
|
|
19
|
+
* newList // => [3]
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const drop = (list, n = 1) => list.slice(n);
|
|
23
|
+
/**
|
|
24
|
+
* non-mutating function that drops n items from the array end.
|
|
25
|
+
* @returns changed array copy
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const newList = dropRight([1,2,3])
|
|
30
|
+
* newList // => [1,2]
|
|
31
|
+
*
|
|
32
|
+
* const newList = dropRight([1,2,3], 2)
|
|
33
|
+
* newList // => [1]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const dropRight = (list, n = 1) => list.slice(0, list.length - n);
|
|
37
|
+
/**
|
|
38
|
+
* standalone `Array.prototype.filter()` that filters out passed item
|
|
39
|
+
* @returns changed array copy
|
|
40
|
+
*/
|
|
41
|
+
export const filterOut = (list, item) => filter(list, i => i !== item);
|
|
42
|
+
/**
|
|
43
|
+
* standalone `Array.prototype.filter()`
|
|
44
|
+
* @returns changed array copy
|
|
45
|
+
*/
|
|
46
|
+
export function filter(list, predicate) {
|
|
47
|
+
const newList = list.filter(predicate);
|
|
48
|
+
newList.removed = list.length - newList.length;
|
|
49
|
+
return newList;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* non-mutating `Array.prototype.sort()` as a standalone function
|
|
53
|
+
* @returns changed array copy
|
|
54
|
+
*/
|
|
55
|
+
export const sort = (list, compareFn) => list.slice().sort(compareFn);
|
|
56
|
+
/**
|
|
57
|
+
* standalone `Array.prototype.map()` function
|
|
58
|
+
*/
|
|
59
|
+
export const map = (list, mapFn) => list.map(mapFn);
|
|
60
|
+
/**
|
|
61
|
+
* standalone `Array.prototype.slice()` function
|
|
62
|
+
*/
|
|
63
|
+
export const slice = (list, start, end) => list.slice(start, end);
|
|
64
|
+
/**
|
|
65
|
+
* non-mutating `Array.prototype.splice()` as a standalone function
|
|
66
|
+
* @returns changed array copy
|
|
67
|
+
*/
|
|
68
|
+
export const splice = (list, start, deleteCount = 0, ...items) => withArrayCopy(list, list => list.splice(start, deleteCount, ...items));
|
|
69
|
+
/**
|
|
70
|
+
* non-mutating `Array.prototype.fill()` as a standalone function
|
|
71
|
+
* @returns changed array copy
|
|
72
|
+
*/
|
|
73
|
+
export const fill = (list, value, start, end) => list.slice().fill(value, start, end);
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new array concatenating array with any additional arrays and/or values.
|
|
76
|
+
* @param ...a values or arrays
|
|
77
|
+
* @returns new concatenated array
|
|
78
|
+
*/
|
|
79
|
+
export function concat(...a) {
|
|
80
|
+
const result = [];
|
|
81
|
+
for (const i in a) {
|
|
82
|
+
Array.isArray(a[i]) ? result.push(...a[i]) : result.push(a[i]);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove item from array
|
|
88
|
+
* @returns changed array copy
|
|
89
|
+
*/
|
|
90
|
+
export const remove = (list, item, ...insertItems) => {
|
|
91
|
+
const index = list.indexOf(item);
|
|
92
|
+
return splice(list, index, 1, ...insertItems);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Remove multiple items from an array
|
|
96
|
+
* @returns changed array copy
|
|
97
|
+
*/
|
|
98
|
+
export const removeItems = (list, ...items) => {
|
|
99
|
+
const res = [];
|
|
100
|
+
for (let i = 0; i < list.length; i++) {
|
|
101
|
+
const item = list[i];
|
|
102
|
+
const ii = items.indexOf(item);
|
|
103
|
+
if (ii !== -1)
|
|
104
|
+
items.splice(ii, 1);
|
|
105
|
+
else
|
|
106
|
+
res.push(item);
|
|
107
|
+
}
|
|
108
|
+
return res;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Flattens a nested array into a one-level array
|
|
112
|
+
* @returns changed array copy
|
|
113
|
+
*/
|
|
114
|
+
export const flatten = (arr) => arr.reduce((flat, next) => flat.concat(Array.isArray(next) ? flatten(next) : next), []);
|
|
115
|
+
/**
|
|
116
|
+
* Sort an array by object key, or multiple keys
|
|
117
|
+
* @returns changed array copy
|
|
118
|
+
*/
|
|
119
|
+
export const sortBy = (arr, ...paths) => flatten(paths).reduce((source, path) => sort(source, (a, b) => typeof path === "function"
|
|
120
|
+
? compare(path(a), path(b))
|
|
121
|
+
: compare(get(a, path), get(b, path))), arr);
|
|
122
|
+
/**
|
|
123
|
+
* Returns a subset of items that are instances of provided Classes
|
|
124
|
+
* @param list list of original items
|
|
125
|
+
* @param ...classes list or classes
|
|
126
|
+
* @returns changed array copy
|
|
127
|
+
*/
|
|
128
|
+
export const filterInstance = (list, ...classes) => (classes.length === 1
|
|
129
|
+
? list.filter(item => ofClass(item, classes[0]))
|
|
130
|
+
: list.filter(item => item && classes.some(c => ofClass(item, c))));
|
|
131
|
+
/**
|
|
132
|
+
* Returns a subset of items that aren't instances of provided Classes
|
|
133
|
+
* @param list list of original items
|
|
134
|
+
* @param ...classes list or classes
|
|
135
|
+
* @returns changed array copy
|
|
136
|
+
*/
|
|
137
|
+
export const filterOutInstance = (list, ...classes) => (classes.length === 1
|
|
138
|
+
? list.filter(item => item && !ofClass(item, classes[0]))
|
|
139
|
+
: list.filter(item => item && !classes.some(c => ofClass(item, c))));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** make shallow copy of an array */
|
|
2
|
+
export declare const shallowArrayCopy: <T>(array: readonly T[]) => T[];
|
|
3
|
+
/** make shallow copy of an object */
|
|
4
|
+
export declare const shallowObjectCopy: <T extends object>(object: T) => T;
|
|
5
|
+
/** make shallow copy of an array/object */
|
|
6
|
+
export declare const shallowCopy: <T extends object>(source: T) => T;
|
|
7
|
+
/**
|
|
8
|
+
* apply mutations to the an array without changing the original
|
|
9
|
+
* @param array original array
|
|
10
|
+
* @param mutator function applying mutations to the copy of source
|
|
11
|
+
* @returns changed array copy
|
|
12
|
+
*/
|
|
13
|
+
export declare const withArrayCopy: <T>(array: readonly T[], mutator: (copy: T[]) => void) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* apply mutations to the an object without changing the original
|
|
16
|
+
* @param object original object
|
|
17
|
+
* @param mutator function applying mutations to the copy of source
|
|
18
|
+
* @returns changed object copy
|
|
19
|
+
*/
|
|
20
|
+
export declare const withObjectCopy: <T extends object>(object: T, mutator: (copy: T) => void) => T;
|
|
21
|
+
/**
|
|
22
|
+
* apply mutations to the an object/array without changing the original
|
|
23
|
+
* @param source original object
|
|
24
|
+
* @param mutator function applying mutations to the copy of source
|
|
25
|
+
* @returns changed object copy
|
|
26
|
+
*/
|
|
27
|
+
export declare const withCopy: <T extends object>(source: T, mutator: (copy: T) => void) => T;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** make shallow copy of an array */
|
|
2
|
+
export const shallowArrayCopy = (array) => array.slice();
|
|
3
|
+
/** make shallow copy of an object */
|
|
4
|
+
export const shallowObjectCopy = (object) => Object.assign({}, object);
|
|
5
|
+
/** make shallow copy of an array/object */
|
|
6
|
+
export const shallowCopy = (source) => Array.isArray(source) ? shallowArrayCopy(source) : shallowObjectCopy(source);
|
|
7
|
+
/**
|
|
8
|
+
* apply mutations to the an array without changing the original
|
|
9
|
+
* @param array original array
|
|
10
|
+
* @param mutator function applying mutations to the copy of source
|
|
11
|
+
* @returns changed array copy
|
|
12
|
+
*/
|
|
13
|
+
export const withArrayCopy = (array, mutator) => {
|
|
14
|
+
const copy = shallowArrayCopy(array);
|
|
15
|
+
mutator(copy);
|
|
16
|
+
return copy;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* apply mutations to the an object without changing the original
|
|
20
|
+
* @param object original object
|
|
21
|
+
* @param mutator function applying mutations to the copy of source
|
|
22
|
+
* @returns changed object copy
|
|
23
|
+
*/
|
|
24
|
+
export const withObjectCopy = (object, mutator) => {
|
|
25
|
+
const copy = shallowObjectCopy(object);
|
|
26
|
+
mutator(copy);
|
|
27
|
+
return copy;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* apply mutations to the an object/array without changing the original
|
|
31
|
+
* @param source original object
|
|
32
|
+
* @param mutator function applying mutations to the copy of source
|
|
33
|
+
* @returns changed object copy
|
|
34
|
+
*/
|
|
35
|
+
export const withCopy = (source, mutator) => Array.isArray(source)
|
|
36
|
+
? withArrayCopy(source, mutator)
|
|
37
|
+
: withObjectCopy(source, mutator);
|
|
@@ -1,257 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare const shallowObjectCopy: <T extends object>(object: T) => T;
|
|
8
|
-
/** make shallow copy of an array/object */
|
|
9
|
-
declare const shallowCopy: <T extends object>(source: T) => T;
|
|
10
|
-
/**
|
|
11
|
-
* apply mutations to the an array without changing the original
|
|
12
|
-
* @param array original array
|
|
13
|
-
* @param mutator function applying mutations to the copy of source
|
|
14
|
-
* @returns changed array copy
|
|
15
|
-
*/
|
|
16
|
-
declare const withArrayCopy: <T>(array: readonly T[], mutator: (copy: T[]) => void) => T[];
|
|
17
|
-
/**
|
|
18
|
-
* apply mutations to the an object without changing the original
|
|
19
|
-
* @param object original object
|
|
20
|
-
* @param mutator function applying mutations to the copy of source
|
|
21
|
-
* @returns changed object copy
|
|
22
|
-
*/
|
|
23
|
-
declare const withObjectCopy: <T extends object>(object: T, mutator: (copy: T) => void) => T;
|
|
24
|
-
/**
|
|
25
|
-
* apply mutations to the an object/array without changing the original
|
|
26
|
-
* @param source original object
|
|
27
|
-
* @param mutator function applying mutations to the copy of source
|
|
28
|
-
* @returns changed object copy
|
|
29
|
-
*/
|
|
30
|
-
declare const withCopy: <T extends object>(source: T, mutator: (copy: T) => void) => T;
|
|
31
|
-
|
|
32
|
-
/** `a + b + c + ...` */
|
|
33
|
-
declare function add(...a: number[]): number;
|
|
34
|
-
declare function add(...a: string[]): string;
|
|
35
|
-
/** `a - b - c - ...` */
|
|
36
|
-
declare const substract: (a: number, ...b: number[]) => number;
|
|
37
|
-
/** `a * b * c * ...` */
|
|
38
|
-
declare const multiply: (a: number, ...b: number[]) => number;
|
|
39
|
-
/** `a / b / c / ...` */
|
|
40
|
-
declare const divide: (a: number, ...b: number[]) => number;
|
|
41
|
-
/** `a ** b ** c ** ...` */
|
|
42
|
-
declare const power: (a: number, ...b: number[]) => number;
|
|
43
|
-
/** clamp a number value between two other values */
|
|
44
|
-
declare const clamp: (n: number, min: number, max: number) => number;
|
|
45
|
-
|
|
46
|
-
type Predicate<T> = (item: T, index: number, array: readonly T[]) => boolean;
|
|
47
|
-
type MappingFn<T, V> = (item: T, index: number, array: readonly T[]) => V;
|
|
48
|
-
type FlattenArray<T> = T extends any[] ? FlattenArray<ItemsOf<T>> : T;
|
|
49
|
-
type ModifyValue<O, K extends keyof O, V> = Omit<O, K> & {
|
|
50
|
-
[key in K]: V;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type UpdateSetter<O, K extends keyof O, V> = V | ((prev: O[K]) => V);
|
|
54
|
-
type Update = {
|
|
55
|
-
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], K3 extends keyof O[K0][K1][K2], K4 extends keyof O[K0][K1][K2][K3], V>(object: O, k0: K0, k1: K1, k2: K2, k3: K3, k4: K4, setter: UpdateSetter<O[K0][K1][K2][K3], K4, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, ModifyValue<O[K0][K1][K2], K3, ModifyValue<O[K0][K1][K2][K3], K4, V>>>>>;
|
|
56
|
-
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], K3 extends keyof O[K0][K1][K2], V>(object: O, k0: K0, k1: K1, k2: K2, k3: K3, setter: UpdateSetter<O[K0][K1][K2], K3, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, ModifyValue<O[K0][K1][K2], K3, V>>>>;
|
|
57
|
-
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], V>(object: O, k0: K0, k1: K1, k2: K2, setter: UpdateSetter<O[K0][K1], K2, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, V>>>;
|
|
58
|
-
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], V>(object: O, k0: K0, k1: K1, setter: UpdateSetter<O[K0], K1, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, V>>;
|
|
59
|
-
<O extends object, K extends keyof O, V>(object: O, key: K, setter: UpdateSetter<O, K, V>): ModifyValue<O, K, V>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Change single value in an object by key. Allows accessign nested objects by passing multiple keys.
|
|
63
|
-
*
|
|
64
|
-
* Performs a shallow copy of each accessed object.
|
|
65
|
-
*
|
|
66
|
-
* @param object original source
|
|
67
|
-
* @param ...keys keys of sequential accessed objects
|
|
68
|
-
* @param value a value to set in place of a previous one, or a setter function.
|
|
69
|
-
* ```ts
|
|
70
|
-
* V | ((prev: O[K]) => V)
|
|
71
|
-
* ```
|
|
72
|
-
* a new value doesn't have to have the same type as the original
|
|
73
|
-
* @returns changed copy of the original object
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* const original = { foo: { bar: { baz: 123 }}};
|
|
77
|
-
* const newObj = update(original, "foo", "bar", "baz", prev => prev + 1)
|
|
78
|
-
* original // { foo: { bar: { baz: 123 }}}
|
|
79
|
-
* newObj // { foo: { bar: { baz: 124 }}}
|
|
80
|
-
*/
|
|
81
|
-
declare const update: Update;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Create a new subset object without the provided keys
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
89
|
-
* newObject // => { c: "baz" }
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
|
|
93
|
-
/**
|
|
94
|
-
* Create a new subset object with only the provided keys
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
99
|
-
* newObject // => { a:"foo", b:"bar" }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
|
|
103
|
-
/**
|
|
104
|
-
* Get a single property value of an object by specifying a path to it.
|
|
105
|
-
*/
|
|
106
|
-
declare function get<O extends object, K extends keyof O>(obj: O, key: K): O[K];
|
|
107
|
-
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1]>(obj: O, k1: K1, k2: K2): O[K1][K2];
|
|
108
|
-
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2]>(obj: O, k1: K1, k2: K2, k3: K3): O[K1][K2][K3];
|
|
109
|
-
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4): O[K1][K2][K3][K4];
|
|
110
|
-
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3], K5 extends keyof O[K1][K2][K3][K4]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): O[K1][K2][K3][K4][K5];
|
|
111
|
-
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3], K5 extends keyof O[K1][K2][K3][K4], K6 extends keyof O[K1][K2][K3][K4][K5]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): O[K1][K2][K3][K4][K5][K6];
|
|
112
|
-
/**
|
|
113
|
-
* Split object properties by keys into multiple object copies with a subset of selected properties.
|
|
114
|
-
*
|
|
115
|
-
* @param object original object
|
|
116
|
-
* @param ...keys keys to pick from the source, or multiple arrays of keys *(for splitting into more than 2 objects)*
|
|
117
|
-
* ```ts
|
|
118
|
-
* (keyof object)[][] | (keyof object)[]
|
|
119
|
-
* ```
|
|
120
|
-
* @returns array of subset objects
|
|
121
|
-
*/
|
|
122
|
-
declare function split<T extends object, K extends keyof T>(object: T, ...keys: K[]): [Pick<T, K>, Omit<T, K>];
|
|
123
|
-
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T>(object: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>];
|
|
124
|
-
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>];
|
|
125
|
-
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>];
|
|
126
|
-
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [
|
|
127
|
-
Pick<T, K1>,
|
|
128
|
-
Pick<T, K2>,
|
|
129
|
-
Pick<T, K3>,
|
|
130
|
-
Pick<T, K4>,
|
|
131
|
-
Pick<T, K5>,
|
|
132
|
-
Omit<T, K1 | K2 | K3 | K4 | K5>
|
|
133
|
-
];
|
|
134
|
-
/**
|
|
135
|
-
* Merges multiple objects into a single one. Only the first level of properties is merged. An alternative to `{ ...a, ...b, ...c }`.
|
|
136
|
-
* @param ...objects objects to merge
|
|
137
|
-
* @example
|
|
138
|
-
* const d = merge(a, b, c)
|
|
139
|
-
*/
|
|
140
|
-
declare function merge<A extends object, B extends object>(a: A, b: B): Modify<A, B>;
|
|
141
|
-
declare function merge<A extends object, B extends object, C extends object>(a: A, b: B, c: C): Modify<Modify<A, B>, C>;
|
|
142
|
-
declare function merge<A extends object, B extends object, C extends object, D extends object>(a: A, b: B, c: C, d: D): Modify<Modify<Modify<A, B>, C>, D>;
|
|
143
|
-
declare function merge<A extends object, B extends object, C extends object, D extends object, E extends object>(a: A, b: B, c: C, d: D, e: E): Modify<Modify<Modify<Modify<A, B>, C>, D>, E>;
|
|
144
|
-
declare function merge<A extends object, B extends object, C extends object, D extends object, E extends object, F extends object>(a: A, b: B, c: C, d: D, e: E, f: F): Modify<Modify<Modify<Modify<Modify<A, B>, C>, D>, E>, F>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* non-mutating `Array.prototype.push()`
|
|
148
|
-
* @returns changed array copy
|
|
149
|
-
*/
|
|
150
|
-
declare const push: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
151
|
-
/**
|
|
152
|
-
* non-mutating function that drops n items from the array start.
|
|
153
|
-
* @returns changed array copy
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* const newList = drop([1,2,3])
|
|
158
|
-
* newList // => [2,3]
|
|
159
|
-
*
|
|
160
|
-
* const newList = drop([1,2,3], 2)
|
|
161
|
-
* newList // => [3]
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
declare const drop: <T>(list: T[], n?: number) => T[];
|
|
165
|
-
/**
|
|
166
|
-
* non-mutating function that drops n items from the array end.
|
|
167
|
-
* @returns changed array copy
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* const newList = dropRight([1,2,3])
|
|
172
|
-
* newList // => [1,2]
|
|
173
|
-
*
|
|
174
|
-
* const newList = dropRight([1,2,3], 2)
|
|
175
|
-
* newList // => [1]
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
declare const dropRight: <T>(list: T[], n?: number) => T[];
|
|
179
|
-
/**
|
|
180
|
-
* standalone `Array.prototype.filter()` that filters out passed item
|
|
181
|
-
* @returns changed array copy
|
|
182
|
-
*/
|
|
183
|
-
declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
|
|
184
|
-
removed: number;
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* standalone `Array.prototype.filter()`
|
|
188
|
-
* @returns changed array copy
|
|
189
|
-
*/
|
|
190
|
-
declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
|
|
191
|
-
removed: number;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* non-mutating `Array.prototype.sort()` as a standalone function
|
|
195
|
-
* @returns changed array copy
|
|
196
|
-
*/
|
|
197
|
-
declare const sort: <T>(list: T[], compareFn?: ((a: T, b: T) => number) | undefined) => T[];
|
|
198
|
-
/**
|
|
199
|
-
* standalone `Array.prototype.map()` function
|
|
200
|
-
*/
|
|
201
|
-
declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
|
|
202
|
-
/**
|
|
203
|
-
* standalone `Array.prototype.slice()` function
|
|
204
|
-
*/
|
|
205
|
-
declare const slice: <T>(list: readonly T[], start?: number, end?: number) => T[];
|
|
206
|
-
/**
|
|
207
|
-
* non-mutating `Array.prototype.splice()` as a standalone function
|
|
208
|
-
* @returns changed array copy
|
|
209
|
-
*/
|
|
210
|
-
declare const splice: <T>(list: readonly T[], start: number, deleteCount?: number, ...items: T[]) => T[];
|
|
211
|
-
/**
|
|
212
|
-
* non-mutating `Array.prototype.fill()` as a standalone function
|
|
213
|
-
* @returns changed array copy
|
|
214
|
-
*/
|
|
215
|
-
declare const fill: <T>(list: readonly T[], value: T, start?: number, end?: number) => T[];
|
|
216
|
-
/**
|
|
217
|
-
* Creates a new array concatenating array with any additional arrays and/or values.
|
|
218
|
-
* @param ...a values or arrays
|
|
219
|
-
* @returns new concatenated array
|
|
220
|
-
*/
|
|
221
|
-
declare function concat<A extends any[], V extends ItemsOf<A>>(...a: A): Array<V extends any[] ? ItemsOf<V> : V>;
|
|
222
|
-
/**
|
|
223
|
-
* Remove item from array
|
|
224
|
-
* @returns changed array copy
|
|
225
|
-
*/
|
|
226
|
-
declare const remove: <T>(list: readonly T[], item: T, ...insertItems: T[]) => T[];
|
|
227
|
-
/**
|
|
228
|
-
* Remove multiple items from an array
|
|
229
|
-
* @returns changed array copy
|
|
230
|
-
*/
|
|
231
|
-
declare const removeItems: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
232
|
-
/**
|
|
233
|
-
* Flattens a nested array into a one-level array
|
|
234
|
-
* @returns changed array copy
|
|
235
|
-
*/
|
|
236
|
-
declare const flatten: <T extends any[]>(arr: T) => FlattenArray<T>[];
|
|
237
|
-
/**
|
|
238
|
-
* Sort an array by object key, or multiple keys
|
|
239
|
-
* @returns changed array copy
|
|
240
|
-
*/
|
|
241
|
-
declare const sortBy: <T>(arr: T[], ...paths: T extends object ? (Many<keyof T> | Many<(item: T) => any>)[] : Many<(item: T) => any>[]) => T[];
|
|
242
|
-
/**
|
|
243
|
-
* Returns a subset of items that are instances of provided Classes
|
|
244
|
-
* @param list list of original items
|
|
245
|
-
* @param ...classes list or classes
|
|
246
|
-
* @returns changed array copy
|
|
247
|
-
*/
|
|
248
|
-
declare const filterInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Extract<T, InstanceType<ItemsOf<I>>>[];
|
|
249
|
-
/**
|
|
250
|
-
* Returns a subset of items that aren't instances of provided Classes
|
|
251
|
-
* @param list list of original items
|
|
252
|
-
* @param ...classes list or classes
|
|
253
|
-
* @returns changed array copy
|
|
254
|
-
*/
|
|
255
|
-
declare const filterOutInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Exclude<T, InstanceType<ItemsOf<I>>>[];
|
|
256
|
-
|
|
257
|
-
export { FlattenArray, MappingFn, ModifyValue, Predicate, Update, UpdateSetter, add, clamp, concat, divide, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, get, map, merge, multiply, omit, pick, power, push, remove, removeItems, shallowArrayCopy, shallowCopy, shallowObjectCopy, slice, sort, sortBy, splice, split, substract, update, withArrayCopy, withCopy, withObjectCopy };
|
|
1
|
+
export * from "./copy.js";
|
|
2
|
+
export * from "./number.js";
|
|
3
|
+
export * from "./update.js";
|
|
4
|
+
export * from "./object.js";
|
|
5
|
+
export * from "./array.js";
|
|
6
|
+
export * from "./types.js";
|