@solid-primitives/utils 7.0.0-next.1 → 7.0.0-next.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.
- package/dist/colors/helpers.d.ts +46 -41
- package/dist/colors/helpers.js +776 -851
- package/dist/colors/index.d.ts +6 -4
- package/dist/colors/index.js +5 -4
- package/dist/colors/intl.d.ts +56 -52
- package/dist/colors/intl.js +55 -66
- package/dist/colors/manipulation.d.ts +136 -131
- package/dist/colors/manipulation.js +215 -242
- package/dist/colors/types.d.ts +73 -68
- package/dist/colors/types.js +1 -14
- package/dist/immutable/array.d.ts +113 -108
- package/dist/immutable/array.js +122 -128
- package/dist/immutable/copy.d.ts +25 -21
- package/dist/immutable/copy.js +31 -29
- package/dist/immutable/index.d.ts +8 -6
- package/dist/immutable/index.js +7 -6
- package/dist/immutable/number.d.ts +11 -7
- package/dist/immutable/number.js +21 -27
- package/dist/immutable/object.d.ts +55 -58
- package/dist/immutable/object.js +46 -48
- package/dist/immutable/types.d.ts +9 -7
- package/dist/immutable/types.js +1 -1
- package/dist/immutable/update.d.ts +33 -28
- package/dist/immutable/update.js +27 -27
- package/dist/index.d.ts +241 -223
- package/dist/index.js +302 -315
- package/dist/types.d.ts +63 -75
- package/dist/types.js +1 -1
- package/package.json +11 -7
package/dist/immutable/array.js
CHANGED
|
@@ -1,139 +1,133 @@
|
|
|
1
|
+
/* @ts-self-types="./array.d.ts" */
|
|
1
2
|
import { compare, ofClass } from "../index.js";
|
|
2
3
|
import { withArrayCopy } from "./copy.js";
|
|
3
4
|
import { get } from "./object.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
5
|
+
//#region src/immutable/array.ts
|
|
6
|
+
/**
|
|
7
|
+
* non-mutating `Array.prototype.push()`
|
|
8
|
+
* @returns changed array copy
|
|
9
|
+
*/
|
|
10
|
+
const push = (list, ...items) => withArrayCopy(list, (list) => list.push(...items));
|
|
11
|
+
/**
|
|
12
|
+
* non-mutating function that drops n items from the array start.
|
|
13
|
+
* @returns changed array copy
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const newList = drop([1,2,3])
|
|
18
|
+
* newList // => [2,3]
|
|
19
|
+
*
|
|
20
|
+
* const newList = drop([1,2,3], 2)
|
|
21
|
+
* newList // => [3]
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const drop = (list, n = 1) => list.slice(n);
|
|
25
|
+
/**
|
|
26
|
+
* non-mutating function that drops n items from the array end.
|
|
27
|
+
* @returns changed array copy
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const newList = dropRight([1,2,3])
|
|
32
|
+
* newList // => [1,2]
|
|
33
|
+
*
|
|
34
|
+
* const newList = dropRight([1,2,3], 2)
|
|
35
|
+
* newList // => [1]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
const dropRight = (list, n = 1) => list.slice(0, list.length - n);
|
|
39
|
+
/**
|
|
40
|
+
* standalone `Array.prototype.filter()` that filters out passed item
|
|
41
|
+
* @returns changed array copy
|
|
42
|
+
*/
|
|
43
|
+
const filterOut = (list, item) => filter(list, (i) => i !== item);
|
|
44
|
+
/**
|
|
45
|
+
* standalone `Array.prototype.filter()`
|
|
46
|
+
* @returns changed array copy
|
|
47
|
+
*/
|
|
48
|
+
function filter(list, predicate) {
|
|
49
|
+
const newList = list.filter(predicate);
|
|
50
|
+
newList.removed = list.length - newList.length;
|
|
51
|
+
return newList;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
54
|
+
* non-mutating `Array.prototype.sort()` as a standalone function
|
|
55
|
+
* @returns changed array copy
|
|
56
|
+
*/
|
|
57
|
+
const sort = (list, compareFn) => list.slice().sort(compareFn);
|
|
58
|
+
/**
|
|
59
|
+
* standalone `Array.prototype.map()` function
|
|
60
|
+
*/
|
|
61
|
+
const map = (list, mapFn) => list.map(mapFn);
|
|
62
|
+
/**
|
|
63
|
+
* standalone `Array.prototype.slice()` function
|
|
64
|
+
*/
|
|
65
|
+
const slice = (list, start, end) => list.slice(start, end);
|
|
66
|
+
/**
|
|
67
|
+
* non-mutating `Array.prototype.splice()` as a standalone function
|
|
68
|
+
* @returns changed array copy
|
|
69
|
+
*/
|
|
70
|
+
const splice = (list, start, deleteCount = 0, ...items) => withArrayCopy(list, (list) => list.splice(start, deleteCount, ...items));
|
|
71
|
+
/**
|
|
72
|
+
* non-mutating `Array.prototype.fill()` as a standalone function
|
|
73
|
+
* @returns changed array copy
|
|
74
|
+
*/
|
|
75
|
+
const fill = (list, value, start, end) => list.slice().fill(value, start, end);
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new array concatenating array with any additional arrays and/or values.
|
|
78
|
+
* @param ...a values or arrays
|
|
79
|
+
* @returns new concatenated array
|
|
80
|
+
*/
|
|
81
|
+
function concat(...a) {
|
|
82
|
+
const result = [];
|
|
83
|
+
for (const i in a) Array.isArray(a[i]) ? result.push(...a[i]) : result.push(a[i]);
|
|
84
|
+
return result;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
* Remove item from array
|
|
88
|
+
* @returns changed array copy
|
|
89
|
+
*/
|
|
90
|
+
const remove = (list, item, ...insertItems) => {
|
|
91
|
+
const index = list.indexOf(item);
|
|
92
|
+
return splice(list, index, 1, ...insertItems);
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
return res;
|
|
95
|
+
* Remove multiple items from an array
|
|
96
|
+
* @returns changed array copy
|
|
97
|
+
*/
|
|
98
|
+
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) items.splice(ii, 1);
|
|
104
|
+
else res.push(item);
|
|
105
|
+
}
|
|
106
|
+
return res;
|
|
109
107
|
};
|
|
110
108
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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))));
|
|
109
|
+
* Flattens a nested array into a one-level array
|
|
110
|
+
* @returns changed array copy
|
|
111
|
+
*/
|
|
112
|
+
const flatten = (arr) => arr.reduce((flat, next) => flat.concat(Array.isArray(next) ? flatten(next) : next), []);
|
|
113
|
+
/**
|
|
114
|
+
* Sort an array by object key, or multiple keys
|
|
115
|
+
* @returns changed array copy
|
|
116
|
+
*/
|
|
117
|
+
const sortBy = (arr, ...paths) => flatten(paths).reduce((source, path) => sort(source, (a, b) => typeof path === "function" ? compare(path(a), path(b)) : compare(get(a, path), get(b, path))), arr);
|
|
118
|
+
/**
|
|
119
|
+
* Returns a subset of items that are instances of provided Classes
|
|
120
|
+
* @param list list of original items
|
|
121
|
+
* @param ...classes list or classes
|
|
122
|
+
* @returns changed array copy
|
|
123
|
+
*/
|
|
124
|
+
const filterInstance = (list, ...classes) => classes.length === 1 ? list.filter((item) => ofClass(item, classes[0])) : list.filter((item) => item && classes.some((c) => ofClass(item, c)));
|
|
125
|
+
/**
|
|
126
|
+
* Returns a subset of items that aren't instances of provided Classes
|
|
127
|
+
* @param list list of original items
|
|
128
|
+
* @param ...classes list or classes
|
|
129
|
+
* @returns changed array copy
|
|
130
|
+
*/
|
|
131
|
+
const filterOutInstance = (list, ...classes) => classes.length === 1 ? list.filter((item) => item && !ofClass(item, classes[0])) : list.filter((item) => item && !classes.some((c) => ofClass(item, c)));
|
|
132
|
+
//#endregion
|
|
133
|
+
export { concat, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, map, push, remove, removeItems, slice, sort, sortBy, splice };
|
package/dist/immutable/copy.d.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
+
/* @ts-self-types="./copy.d.ts" */
|
|
2
|
+
//#region src/immutable/copy.d.ts
|
|
1
3
|
/** make shallow copy of an array */
|
|
2
|
-
|
|
4
|
+
declare const shallowArrayCopy: <T>(array: readonly T[]) => T[];
|
|
3
5
|
/** make shallow copy of an object */
|
|
4
|
-
|
|
6
|
+
declare const shallowObjectCopy: <T extends object>(object: T) => T;
|
|
5
7
|
/** make shallow copy of an array/object */
|
|
6
|
-
|
|
8
|
+
declare const shallowCopy: <T extends object>(source: T) => T;
|
|
7
9
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
* apply mutations to the an array without changing the original
|
|
11
|
+
* @param array original array
|
|
12
|
+
* @param mutator function applying mutations to the copy of source
|
|
13
|
+
* @returns changed array copy
|
|
14
|
+
*/
|
|
15
|
+
declare const withArrayCopy: <T>(array: readonly T[], mutator: (copy: T[]) => void) => T[];
|
|
14
16
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
* apply mutations to the an object without changing the original
|
|
18
|
+
* @param object original object
|
|
19
|
+
* @param mutator function applying mutations to the copy of source
|
|
20
|
+
* @returns changed object copy
|
|
21
|
+
*/
|
|
22
|
+
declare const withObjectCopy: <T extends object>(object: T, mutator: (copy: T) => void) => T;
|
|
21
23
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
* apply mutations to the an object/array without changing the original
|
|
25
|
+
* @param source original object
|
|
26
|
+
* @param mutator function applying mutations to the copy of source
|
|
27
|
+
* @returns changed object copy
|
|
28
|
+
*/
|
|
29
|
+
declare const withCopy: <T extends object>(source: T, mutator: (copy: T) => void) => T;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { shallowArrayCopy, shallowCopy, shallowObjectCopy, withArrayCopy, withCopy, withObjectCopy };
|
package/dist/immutable/copy.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
|
+
/* @ts-self-types="./copy.d.ts" */
|
|
2
|
+
//#region src/immutable/copy.ts
|
|
1
3
|
/** make shallow copy of an array */
|
|
2
|
-
|
|
4
|
+
const shallowArrayCopy = (array) => array.slice();
|
|
3
5
|
/** make shallow copy of an object */
|
|
4
|
-
|
|
6
|
+
const shallowObjectCopy = (object) => Object.assign({}, object);
|
|
5
7
|
/** make shallow copy of an array/object */
|
|
6
|
-
|
|
8
|
+
const shallowCopy = (source) => Array.isArray(source) ? shallowArrayCopy(source) : shallowObjectCopy(source);
|
|
7
9
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
* apply mutations to the an array without changing the original
|
|
11
|
+
* @param array original array
|
|
12
|
+
* @param mutator function applying mutations to the copy of source
|
|
13
|
+
* @returns changed array copy
|
|
14
|
+
*/
|
|
15
|
+
const withArrayCopy = (array, mutator) => {
|
|
16
|
+
const copy = shallowArrayCopy(array);
|
|
17
|
+
mutator(copy);
|
|
18
|
+
return copy;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
* apply mutations to the an object without changing the original
|
|
22
|
+
* @param object original object
|
|
23
|
+
* @param mutator function applying mutations to the copy of source
|
|
24
|
+
* @returns changed object copy
|
|
25
|
+
*/
|
|
26
|
+
const withObjectCopy = (object, mutator) => {
|
|
27
|
+
const copy = shallowObjectCopy(object);
|
|
28
|
+
mutator(copy);
|
|
29
|
+
return copy;
|
|
28
30
|
};
|
|
29
31
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
* apply mutations to the an object/array without changing the original
|
|
33
|
+
* @param source original object
|
|
34
|
+
* @param mutator function applying mutations to the copy of source
|
|
35
|
+
* @returns changed object copy
|
|
36
|
+
*/
|
|
37
|
+
const withCopy = (source, mutator) => Array.isArray(source) ? withArrayCopy(source, mutator) : withObjectCopy(source, mutator);
|
|
38
|
+
//#endregion
|
|
39
|
+
export { shallowArrayCopy, shallowCopy, shallowObjectCopy, withArrayCopy, withCopy, withObjectCopy };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
import { FlattenArray, MappingFn, ModifyValue, Predicate } from "./types.js";
|
|
3
|
+
import { concat, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, map, push, remove, removeItems, slice, sort, sortBy, splice } from "./array.js";
|
|
4
|
+
import { shallowArrayCopy, shallowCopy, shallowObjectCopy, withArrayCopy, withCopy, withObjectCopy } from "./copy.js";
|
|
5
|
+
import { add, clamp, divide, multiply, power, substract } from "./number.js";
|
|
6
|
+
import { Update, UpdateSetter, update } from "./update.js";
|
|
7
|
+
import { get, merge, omit, pick, split } from "./object.js";
|
|
8
|
+
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 };
|
package/dist/immutable/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
import { shallowArrayCopy, shallowCopy, shallowObjectCopy, withArrayCopy, withCopy, withObjectCopy } from "./copy.js";
|
|
3
|
+
import { get, merge, omit, pick, split } from "./object.js";
|
|
4
|
+
import { concat, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, map, push, remove, removeItems, slice, sort, sortBy, splice } from "./array.js";
|
|
5
|
+
import { add, clamp, divide, multiply, power, substract } from "./number.js";
|
|
6
|
+
import { update } from "./update.js";
|
|
7
|
+
export { 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,13 +1,17 @@
|
|
|
1
|
+
/* @ts-self-types="./number.d.ts" */
|
|
2
|
+
//#region src/immutable/number.d.ts
|
|
1
3
|
/** `a + b + c + ...` */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
declare function add(...a: number[]): number;
|
|
5
|
+
declare function add(...a: string[]): string;
|
|
4
6
|
/** `a - b - c - ...` */
|
|
5
|
-
|
|
7
|
+
declare const substract: (a: number, ...b: number[]) => number;
|
|
6
8
|
/** `a * b * c * ...` */
|
|
7
|
-
|
|
9
|
+
declare const multiply: (a: number, ...b: number[]) => number;
|
|
8
10
|
/** `a / b / c / ...` */
|
|
9
|
-
|
|
11
|
+
declare const divide: (a: number, ...b: number[]) => number;
|
|
10
12
|
/** `a ** b ** c ** ...` */
|
|
11
|
-
|
|
13
|
+
declare const power: (a: number, ...b: number[]) => number;
|
|
12
14
|
/** clamp a number value between two other values */
|
|
13
|
-
|
|
15
|
+
declare const clamp: (n: number, min: number, max: number) => number;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { add, clamp, divide, multiply, power, substract };
|
package/dist/immutable/number.js
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/* @ts-self-types="./number.d.ts" */
|
|
2
|
+
//#region src/immutable/number.ts
|
|
3
|
+
function add(...a) {
|
|
4
|
+
let r = 0;
|
|
5
|
+
for (const n of a) r += n;
|
|
6
|
+
return r;
|
|
7
7
|
}
|
|
8
8
|
/** `a - b - c - ...` */
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return a;
|
|
9
|
+
const substract = (a, ...b) => {
|
|
10
|
+
for (const n of b) a -= n;
|
|
11
|
+
return a;
|
|
14
12
|
};
|
|
15
13
|
/** `a * b * c * ...` */
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
14
|
+
const multiply = (a, ...b) => {
|
|
15
|
+
for (const n of b) a *= n;
|
|
16
|
+
return a;
|
|
21
17
|
};
|
|
22
18
|
/** `a / b / c / ...` */
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return a;
|
|
19
|
+
const divide = (a, ...b) => {
|
|
20
|
+
for (const n of b) a /= n;
|
|
21
|
+
return a;
|
|
28
22
|
};
|
|
29
23
|
/** `a ** b ** c ** ...` */
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return a;
|
|
24
|
+
const power = (a, ...b) => {
|
|
25
|
+
for (const n of b) a = a ** n;
|
|
26
|
+
return a;
|
|
35
27
|
};
|
|
36
28
|
/** clamp a number value between two other values */
|
|
37
|
-
|
|
29
|
+
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
30
|
+
//#endregion
|
|
31
|
+
export { add, clamp, divide, multiply, power, substract };
|
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
/* @ts-self-types="./object.d.ts" */
|
|
2
|
+
import { Modify } from "../types.js";
|
|
3
|
+
//#region src/immutable/object.d.ts
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
* Create a new subset object without the provided keys
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
10
|
+
* newObject // => { c: "baz" }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
|
|
12
14
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
* Create a new subset object with only the provided keys
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
20
|
+
* newObject // => { a:"foo", b:"bar" }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
|
|
22
24
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
* Get a single property value of an object by specifying a path to it.
|
|
26
|
+
*/
|
|
27
|
+
declare function get<O extends object, K extends keyof O>(obj: O, key: K): O[K];
|
|
28
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1]>(obj: O, k1: K1, k2: K2): O[K1][K2];
|
|
29
|
+
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];
|
|
30
|
+
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];
|
|
31
|
+
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];
|
|
32
|
+
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];
|
|
31
33
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Pick<T, K1>,
|
|
47
|
-
Pick<T, K2>,
|
|
48
|
-
Pick<T, K3>,
|
|
49
|
-
Pick<T, K4>,
|
|
50
|
-
Pick<T, K5>,
|
|
51
|
-
Omit<T, K1 | K2 | K3 | K4 | K5>
|
|
52
|
-
];
|
|
34
|
+
* Split object properties by keys into multiple object copies with a subset of selected properties.
|
|
35
|
+
*
|
|
36
|
+
* @param object original object
|
|
37
|
+
* @param ...keys keys to pick from the source, or multiple arrays of keys *(for splitting into more than 2 objects)*
|
|
38
|
+
* ```ts
|
|
39
|
+
* (keyof object)[][] | (keyof object)[]
|
|
40
|
+
* ```
|
|
41
|
+
* @returns array of subset objects
|
|
42
|
+
*/
|
|
43
|
+
declare function split<T extends object, K extends keyof T>(object: T, ...keys: K[]): [Pick<T, K>, Omit<T, K>];
|
|
44
|
+
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>];
|
|
45
|
+
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>];
|
|
46
|
+
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>];
|
|
47
|
+
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[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Pick<T, K5>, Omit<T, K1 | K2 | K3 | K4 | K5>];
|
|
53
48
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
* Merges multiple objects into a single one. Only the first level of properties is merged. An alternative to `{ ...a, ...b, ...c }`.
|
|
50
|
+
* @param ...objects objects to merge
|
|
51
|
+
* @example
|
|
52
|
+
* const d = merge(a, b, c)
|
|
53
|
+
*/
|
|
54
|
+
declare function merge<A extends object, B extends object>(a: A, b: B): Modify<A, B>;
|
|
55
|
+
declare function merge<A extends object, B extends object, C extends object>(a: A, b: B, c: C): Modify<Modify<A, B>, C>;
|
|
56
|
+
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>;
|
|
57
|
+
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>;
|
|
58
|
+
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>;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { get, merge, omit, pick, split };
|