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