@oscarpalmer/atoms 0.166.1 → 0.166.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/array/difference.d.mts +1 -1
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/filter.d.mts +2 -2
- package/dist/array/find.d.mts +1 -1
- package/dist/array/intersection.d.mts +1 -1
- package/dist/array/move.d.mts +2 -2
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/select.d.mts +1 -1
- package/dist/array/slice.d.mts +2 -2
- package/dist/array/sort.d.mts +4 -4
- package/dist/array/swap.d.mts +2 -2
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.d.mts +1 -1
- package/dist/array/update.d.mts +1 -1
- package/dist/index.d.mts +72 -72
- package/dist/index.mjs +1 -1
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/function/timer.mjs +1 -1
- package/dist/internal/math/aggregate.d.mts +1 -1
- package/dist/internal/value/partial.d.mts +2 -2
- package/dist/math.d.mts +1 -1
- package/dist/models.d.mts +7 -7
- package/dist/promise/models.d.mts +4 -4
- package/dist/sized/map.d.mts +11 -11
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/smush.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -1
- package/package.json +1 -1
- package/src/array/difference.ts +2 -2
- package/src/array/exists.ts +3 -3
- package/src/array/filter.ts +6 -6
- package/src/array/find.ts +3 -3
- package/src/array/intersection.ts +2 -2
- package/src/array/move.ts +4 -4
- package/src/array/partition.ts +3 -3
- package/src/array/select.ts +3 -3
- package/src/array/slice.ts +6 -6
- package/src/array/sort.ts +4 -4
- package/src/array/swap.ts +4 -4
- package/src/array/to-set.ts +3 -3
- package/src/array/toggle.ts +2 -2
- package/src/array/union.ts +2 -2
- package/src/array/update.ts +2 -2
- package/src/internal/array/index-of.ts +3 -3
- package/src/internal/function/timer.ts +2 -4
- package/src/internal/math/aggregate.ts +2 -2
- package/src/internal/value/partial.ts +9 -9
- package/src/math.ts +3 -3
- package/src/models.ts +30 -20
- package/src/promise/models.ts +13 -11
- package/src/sized/map.ts +14 -14
- package/src/value/omit.ts +3 -3
- package/src/value/pick.ts +3 -3
- package/src/value/smush.ts +1 -1
- package/src/value/unsmush.ts +1 -1
package/dist/models.d.mts
CHANGED
|
@@ -41,7 +41,7 @@ type GenericCallback = (...args: any[]) => any;
|
|
|
41
41
|
* A generic key type
|
|
42
42
|
*/
|
|
43
43
|
type Key = number | string;
|
|
44
|
-
type KeyedValue<Item,
|
|
44
|
+
type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey ? Item[ItemKey] : never;
|
|
45
45
|
/**
|
|
46
46
|
* A nested array
|
|
47
47
|
*/
|
|
@@ -50,16 +50,16 @@ type NestedArray<Value> = Value extends Array<infer NestedValue> ? NestedArray<N
|
|
|
50
50
|
* All nested keys of an object as dot notation strings _(up to 5 levels deep)_
|
|
51
51
|
*/
|
|
52
52
|
type NestedKeys<Value extends PlainObject> = _NestedKeys<Value>;
|
|
53
|
-
type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0 ? never : Value extends readonly any[] ? Value extends readonly [any, ...any] ? { [
|
|
53
|
+
type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0 ? never : Value extends readonly any[] ? Value extends readonly [any, ...any] ? { [ItemKey in keyof Value]-?: ItemKey extends `${number}` ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}` : `${ItemKey}` : never }[number] : never : Value extends PlainObject ? { [ItemKey in keyof Value]-?: ItemKey extends number | string ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}` : `${ItemKey}` : never }[keyof Value] : never;
|
|
54
54
|
/**
|
|
55
55
|
* An extended version of `Partial` that allows for nested properties to be optional
|
|
56
56
|
*/
|
|
57
|
-
type NestedPartial<Value> = { [
|
|
57
|
+
type NestedPartial<Value> = { [ItemKey in keyof Value]?: Value[ItemKey] extends object ? NestedPartial<Value[ItemKey]> : Value[ItemKey] };
|
|
58
58
|
/**
|
|
59
59
|
* The value for a nested key of an object
|
|
60
60
|
*/
|
|
61
61
|
type NestedValue<Value extends PlainObject, Path extends string> = _NestedValue<Value, Path>;
|
|
62
|
-
type _NestedValue<Value, Path extends string> = Path extends `${infer
|
|
62
|
+
type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.${infer Rest}` ? ItemKey extends keyof Value ? undefined extends Value[ItemKey] ? _NestedValue<Exclude<Value[ItemKey], undefined>, Rest> | undefined : _NestedValue<Value[ItemKey], Rest> : ItemKey extends `${number}` ? Value extends readonly any[] ? _NestedValue<Value[number], Rest> : never : never : Path extends `${number}` ? Value extends readonly any[] ? Value[number] : never : Path extends keyof Value ? Value[Path] : never;
|
|
63
63
|
/**
|
|
64
64
|
* The nested (keyed) values of an object _(up to 5 levels deep)_
|
|
65
65
|
*/
|
|
@@ -67,11 +67,11 @@ type NestedValues<Value extends PlainObject> = { [Path in NestedKeys<Value>]: Ne
|
|
|
67
67
|
/**
|
|
68
68
|
* The numerical keys of an object
|
|
69
69
|
*/
|
|
70
|
-
type NumericalKeys<Value> = { [
|
|
70
|
+
type NumericalKeys<Value> = { [ItemKey in keyof Value]: ItemKey extends number ? ItemKey : ItemKey extends `${number}` ? ItemKey : never }[keyof Value];
|
|
71
71
|
/**
|
|
72
72
|
* The numerical values of an object
|
|
73
73
|
*/
|
|
74
|
-
type NumericalValues<Item extends PlainObject> = { [
|
|
74
|
+
type NumericalValues<Item extends PlainObject> = { [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey] };
|
|
75
75
|
/**
|
|
76
76
|
* An asynchronous function that can only be called once, returning the same value on subsequent calls
|
|
77
77
|
*/
|
|
@@ -122,7 +122,7 @@ type RequiredKeys<Model extends object, Keys extends keyof Model> = Required<Pic
|
|
|
122
122
|
*
|
|
123
123
|
* _(Thanks, type-fest!)_
|
|
124
124
|
*/
|
|
125
|
-
type Simplify<Value> = { [
|
|
125
|
+
type Simplify<Value> = { [ValueKey in keyof Value]: Value[ValueKey] } & {};
|
|
126
126
|
type SubtractDepth<Value extends number> = Value extends 5 ? 4 : Value extends 4 ? 3 : Value extends 3 ? 2 : Value extends 2 ? 1 : Value extends 1 ? 0 : never;
|
|
127
127
|
/**
|
|
128
128
|
* Get the value's type as a string
|
|
@@ -54,15 +54,15 @@ type PromiseStrategy = 'complete' | 'first';
|
|
|
54
54
|
declare class PromiseTimeoutError extends Error {
|
|
55
55
|
constructor();
|
|
56
56
|
}
|
|
57
|
-
type PromisesItems<Items extends unknown[]> = { [
|
|
57
|
+
type PromisesItems<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]> };
|
|
58
58
|
type PromisesOptions = {
|
|
59
59
|
signal?: AbortSignal;
|
|
60
60
|
strategy?: PromiseStrategy;
|
|
61
61
|
};
|
|
62
|
-
type PromisesResult<Items extends unknown[]> = { [
|
|
63
|
-
type PromisesUnwrapped<Items extends unknown[]> = { [
|
|
62
|
+
type PromisesResult<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never };
|
|
63
|
+
type PromisesUnwrapped<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never };
|
|
64
64
|
type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
|
|
65
|
-
type PromisesValues<Items extends unknown[]> = { [
|
|
65
|
+
type PromisesValues<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never : Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never };
|
|
66
66
|
type RejectedPromise = {
|
|
67
67
|
status: typeof PROMISE_TYPE_REJECTED;
|
|
68
68
|
reason: unknown;
|
package/dist/sized/map.d.mts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Behavior is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
6
6
|
*/
|
|
7
|
-
declare class SizedMap<
|
|
7
|
+
declare class SizedMap<SizedKey = unknown, SizedValue = unknown> extends Map<SizedKey, SizedValue> {
|
|
8
8
|
#private;
|
|
9
9
|
/**
|
|
10
10
|
* Is the Map full?
|
|
@@ -14,33 +14,33 @@ declare class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a new SizedMap with entries and a maximum size _(2^20)_
|
|
16
16
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
17
|
-
* @template
|
|
18
|
-
* @template
|
|
17
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
18
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
19
19
|
*/
|
|
20
|
-
constructor(entries: [
|
|
20
|
+
constructor(entries: [SizedKey, SizedValue][]);
|
|
21
21
|
/**
|
|
22
22
|
* Create a new SizedMap with a maximum size _(but clamped at 2^24)_
|
|
23
23
|
* @param maximum Maximum size of the SizedMap
|
|
24
|
-
* @template
|
|
25
|
-
* @template
|
|
24
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
25
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
26
26
|
*/
|
|
27
27
|
constructor(maximum: number);
|
|
28
28
|
/**
|
|
29
29
|
* Create a new SizedMap with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
30
30
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
31
31
|
* @param maximum Maximum size of the SizedMap
|
|
32
|
-
* @template
|
|
33
|
-
* @template
|
|
32
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
33
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
34
34
|
*/
|
|
35
|
-
constructor(entries?: [
|
|
35
|
+
constructor(entries?: [SizedKey, SizedValue][], maximum?: number);
|
|
36
36
|
/**
|
|
37
37
|
* @inheritdoc
|
|
38
38
|
*/
|
|
39
|
-
get(key:
|
|
39
|
+
get(key: SizedKey): SizedValue | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* @inheritdoc
|
|
42
42
|
*/
|
|
43
|
-
set(key:
|
|
43
|
+
set(key: SizedKey, value: SizedValue): this;
|
|
44
44
|
}
|
|
45
45
|
//#endregion
|
|
46
46
|
export { SizedMap };
|
package/dist/value/omit.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { PlainObject } from "../models.mjs";
|
|
|
7
7
|
* @param keys Keys to omit
|
|
8
8
|
* @returns Partial object without the specified keys
|
|
9
9
|
*/
|
|
10
|
-
declare function omit<Value extends PlainObject,
|
|
10
|
+
declare function omit<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Omit<Value, ValueKey>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { omit };
|
package/dist/value/pick.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { PlainObject } from "../models.mjs";
|
|
|
7
7
|
* @param keys Keys to use
|
|
8
8
|
* @returns Partial object with only the specified keys
|
|
9
9
|
*/
|
|
10
|
-
declare function pick<Value extends PlainObject,
|
|
10
|
+
declare function pick<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Pick<Value, ValueKey>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { pick };
|
package/dist/value/smush.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NestedKeys, NestedValue, PlainObject, Simplify, ToString } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/value/smush.d.ts
|
|
4
|
-
type Smushed<Value extends PlainObject> = Simplify<{ [
|
|
4
|
+
type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>> }>;
|
|
5
5
|
/**
|
|
6
6
|
* Smush an object into a flat object that uses dot notation keys
|
|
7
7
|
* @param value Object to smush
|
package/dist/value/unsmush.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
|
|
|
9
9
|
* Thanks, type-fest!
|
|
10
10
|
*/
|
|
11
11
|
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
12
|
-
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [
|
|
12
|
+
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
|
|
13
13
|
/**
|
|
14
14
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
15
15
|
* @param value Object to unsmush
|
package/package.json
CHANGED
package/src/array/difference.ts
CHANGED
|
@@ -24,8 +24,8 @@ export function difference<First, Second>(
|
|
|
24
24
|
export function difference<
|
|
25
25
|
First extends PlainObject,
|
|
26
26
|
Second extends PlainObject,
|
|
27
|
-
|
|
28
|
-
>(first: First[], second: Second[], key:
|
|
27
|
+
SharedKey extends keyof First & keyof Second,
|
|
28
|
+
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Get the items from the first array that are not in the second array
|
package/src/array/exists.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function exists<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
24
24
|
*/
|
|
25
|
-
export function exists<Item extends PlainObject,
|
|
25
|
+
export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): boolean;
|
|
30
30
|
|
|
31
31
|
/**
|
package/src/array/filter.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function filter<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Filtered array of items
|
|
24
24
|
*/
|
|
25
|
-
export function filter<Item extends PlainObject,
|
|
25
|
+
export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): Item[];
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -58,10 +58,10 @@ function removeFiltered<
|
|
|
58
58
|
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
59
59
|
>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
60
60
|
|
|
61
|
-
function removeFiltered<Item extends PlainObject,
|
|
61
|
+
function removeFiltered<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
62
62
|
array: Item[],
|
|
63
|
-
key:
|
|
64
|
-
value: Item[
|
|
63
|
+
key: ItemKey,
|
|
64
|
+
value: Item[ItemKey],
|
|
65
65
|
): unknown[];
|
|
66
66
|
|
|
67
67
|
function removeFiltered<Item>(
|
package/src/array/find.ts
CHANGED
|
@@ -23,10 +23,10 @@ export function find<Item, Callback extends (item: Item, index: number, array: I
|
|
|
23
23
|
* @param value Value to match against
|
|
24
24
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
25
25
|
*/
|
|
26
|
-
export function find<Item extends PlainObject,
|
|
26
|
+
export function find<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
27
27
|
array: Item[],
|
|
28
|
-
key:
|
|
29
|
-
value: Item[
|
|
28
|
+
key: ItemKey,
|
|
29
|
+
value: Item[ItemKey],
|
|
30
30
|
): Item | undefined;
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -23,8 +23,8 @@ export function intersection<First, Second>(
|
|
|
23
23
|
export function intersection<
|
|
24
24
|
First extends Record<string, unknown>,
|
|
25
25
|
Second extends Record<string, unknown>,
|
|
26
|
-
|
|
27
|
-
>(first: First[], second: Second[], key:
|
|
26
|
+
SharedKey extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Get the common values between two arrays
|
package/src/array/move.ts
CHANGED
|
@@ -14,11 +14,11 @@ import {indexOfArray} from './position';
|
|
|
14
14
|
* @param key Key to get an item's value for matching
|
|
15
15
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
16
16
|
*/
|
|
17
|
-
export function move<Item extends PlainObject,
|
|
17
|
+
export function move<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
18
18
|
array: Item[],
|
|
19
19
|
from: Item | Item[],
|
|
20
20
|
to: Item | Item[],
|
|
21
|
-
key:
|
|
21
|
+
key: ItemKey,
|
|
22
22
|
): Item[];
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -156,11 +156,11 @@ function moveIndices<Item>(array: Item[], from: number, to: number): Item[] {
|
|
|
156
156
|
* @param key Key to get an item's value for matching
|
|
157
157
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
158
158
|
*/
|
|
159
|
-
function moveToIndex<Item extends PlainObject,
|
|
159
|
+
function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
160
160
|
array: Item[],
|
|
161
161
|
value: Item | Item[],
|
|
162
162
|
index: number,
|
|
163
|
-
key:
|
|
163
|
+
key: ItemKey,
|
|
164
164
|
): Item[];
|
|
165
165
|
|
|
166
166
|
/**
|
package/src/array/partition.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function partition<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Partitioned array of items
|
|
24
24
|
*/
|
|
25
|
-
export function partition<Item extends PlainObject,
|
|
25
|
+
export function partition<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): Item[][];
|
|
30
30
|
|
|
31
31
|
/**
|
package/src/array/select.ts
CHANGED
|
@@ -30,12 +30,12 @@ export function select<
|
|
|
30
30
|
*/
|
|
31
31
|
export function select<
|
|
32
32
|
Item extends PlainObject,
|
|
33
|
-
|
|
33
|
+
ItemKey extends keyof Item,
|
|
34
34
|
MapCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
35
35
|
>(
|
|
36
36
|
array: Item[],
|
|
37
|
-
filterKey:
|
|
38
|
-
filterValue: Item[
|
|
37
|
+
filterKey: ItemKey,
|
|
38
|
+
filterValue: Item[ItemKey],
|
|
39
39
|
mapCallback: MapCallback,
|
|
40
40
|
): Array<ReturnType<MapCallback>>;
|
|
41
41
|
|
package/src/array/slice.ts
CHANGED
|
@@ -16,10 +16,10 @@ type ExtractType = 'drop' | 'take';
|
|
|
16
16
|
* @param value Value to match against
|
|
17
17
|
* @returns New array with items dropped
|
|
18
18
|
*/
|
|
19
|
-
export function drop<Item extends PlainObject,
|
|
19
|
+
export function drop<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
20
20
|
array: Item[],
|
|
21
|
-
key:
|
|
22
|
-
value: Item[
|
|
21
|
+
key: ItemKey,
|
|
22
|
+
value: Item[ItemKey],
|
|
23
23
|
): Item[];
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -192,10 +192,10 @@ export function slice(array: unknown[], first?: number, second?: number): unknow
|
|
|
192
192
|
* @param value Value to match against
|
|
193
193
|
* @returns New array with taken items
|
|
194
194
|
*/
|
|
195
|
-
export function take<Item extends PlainObject,
|
|
195
|
+
export function take<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
196
196
|
array: Item[],
|
|
197
|
-
key:
|
|
198
|
-
value: Item[
|
|
197
|
+
key: ItemKey,
|
|
198
|
+
value: Item[ItemKey],
|
|
199
199
|
): Item[];
|
|
200
200
|
|
|
201
201
|
/**
|
package/src/array/sort.ts
CHANGED
|
@@ -21,11 +21,11 @@ export type ArrayComparisonSorter<Item> = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Sorting information for arrays _(using a key)_
|
|
23
23
|
*/
|
|
24
|
-
export type ArrayKeySorter<Item extends PlainObject,
|
|
24
|
+
export type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
25
25
|
/**
|
|
26
26
|
* Comparator to use when comparing items and values
|
|
27
27
|
*/
|
|
28
|
-
compare?: CompareCallback<Item, Item[
|
|
28
|
+
compare?: CompareCallback<Item, Item[ItemKey]>;
|
|
29
29
|
/**
|
|
30
30
|
* Direction to sort by
|
|
31
31
|
*/
|
|
@@ -33,14 +33,14 @@ export type ArrayKeySorter<Item extends PlainObject, Key extends keyof Item> = {
|
|
|
33
33
|
/**
|
|
34
34
|
* Key to sort by
|
|
35
35
|
*/
|
|
36
|
-
key:
|
|
36
|
+
key: ItemKey;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Sorters based on keys in an object
|
|
41
41
|
*/
|
|
42
42
|
type ArrayKeySorters<Item extends PlainObject> = {
|
|
43
|
-
[
|
|
43
|
+
[ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey>;
|
|
44
44
|
}[keyof Item];
|
|
45
45
|
|
|
46
46
|
/**
|
package/src/array/swap.ts
CHANGED
|
@@ -14,11 +14,11 @@ import {indexOfArray} from './position';
|
|
|
14
14
|
* @param key Key to get an item's value for matching
|
|
15
15
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
16
16
|
*/
|
|
17
|
-
export function swap<Item extends PlainObject,
|
|
17
|
+
export function swap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
18
18
|
array: Item[],
|
|
19
19
|
first: Item[],
|
|
20
20
|
second: Item[],
|
|
21
|
-
key:
|
|
21
|
+
key: ItemKey,
|
|
22
22
|
): Item[];
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -59,11 +59,11 @@ export function swap<Item>(array: Item[], first: Item[], second: Item[]): Item[]
|
|
|
59
59
|
* @param key Key to get an item's value for matching
|
|
60
60
|
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
61
61
|
*/
|
|
62
|
-
export function swap<Item extends PlainObject,
|
|
62
|
+
export function swap<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
63
63
|
array: Item[],
|
|
64
64
|
first: Item,
|
|
65
65
|
second: Item,
|
|
66
|
-
key:
|
|
66
|
+
key: ItemKey,
|
|
67
67
|
): Item[];
|
|
68
68
|
|
|
69
69
|
/**
|
package/src/array/to-set.ts
CHANGED
|
@@ -20,10 +20,10 @@ export function toSet<Item, Callback extends (item: Item, index: number, array:
|
|
|
20
20
|
* @param key Key to use for value
|
|
21
21
|
* @returns Set of values
|
|
22
22
|
*/
|
|
23
|
-
export function toSet<Item extends PlainObject,
|
|
23
|
+
export function toSet<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
24
24
|
array: Item[],
|
|
25
|
-
key:
|
|
26
|
-
): Set<Item[
|
|
25
|
+
key: ItemKey,
|
|
26
|
+
): Set<Item[ItemKey]>;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Create a Set from an array of items
|
package/src/array/toggle.ts
CHANGED
|
@@ -21,10 +21,10 @@ export function toggle<Item>(
|
|
|
21
21
|
* @param key Key to find existing item
|
|
22
22
|
* @returns Original array
|
|
23
23
|
*/
|
|
24
|
-
export function toggle<Item extends PlainObject,
|
|
24
|
+
export function toggle<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
|
26
26
|
toggled: Item[],
|
|
27
|
-
key:
|
|
27
|
+
key: ItemKey,
|
|
28
28
|
): Item[];
|
|
29
29
|
|
|
30
30
|
/**
|
package/src/array/union.ts
CHANGED
|
@@ -23,8 +23,8 @@ export function union<First, Second>(
|
|
|
23
23
|
export function union<
|
|
24
24
|
First extends Record<string, unknown>,
|
|
25
25
|
Second extends Record<string, unknown>,
|
|
26
|
-
|
|
27
|
-
>(first: First[], second: Second[], key:
|
|
26
|
+
SharedKey extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: SharedKey): (First | Second)[];
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Get the combined, unique values from two arrays
|
package/src/array/update.ts
CHANGED
|
@@ -21,10 +21,10 @@ export function update<Item>(
|
|
|
21
21
|
* @param key Key to find existing item
|
|
22
22
|
* @returns Original array
|
|
23
23
|
*/
|
|
24
|
-
export function update<Item extends PlainObject,
|
|
24
|
+
export function update<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
25
25
|
destination: Item[],
|
|
26
26
|
updated: Item[],
|
|
27
|
-
key:
|
|
27
|
+
key: ItemKey,
|
|
28
28
|
): Item[];
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -22,10 +22,10 @@ export function indexOf<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
24
24
|
*/
|
|
25
|
-
export function indexOf<Item extends PlainObject,
|
|
25
|
+
export function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): number;
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -23,9 +23,7 @@ export function getTimer<Callback extends GenericCallback>(
|
|
|
23
23
|
start ??= now;
|
|
24
24
|
|
|
25
25
|
if (interval === 0 || now - start >= interval - OFFSET) {
|
|
26
|
-
|
|
27
|
-
start = now;
|
|
28
|
-
}
|
|
26
|
+
start = throttle ? now : undefined;
|
|
29
27
|
|
|
30
28
|
callback(...args);
|
|
31
29
|
} else {
|
|
@@ -37,7 +35,7 @@ export function getTimer<Callback extends GenericCallback>(
|
|
|
37
35
|
|
|
38
36
|
let args: Parameters<Callback>;
|
|
39
37
|
let frame: DOMHighResTimeStamp | undefined;
|
|
40
|
-
let start: DOMHighResTimeStamp;
|
|
38
|
+
let start: DOMHighResTimeStamp | undefined;
|
|
41
39
|
|
|
42
40
|
const timer = (...parameters: Parameters<Callback>): void => {
|
|
43
41
|
timer.cancel();
|
|
@@ -81,9 +81,9 @@ export function max<Item>(
|
|
|
81
81
|
* @param key Key to use for value
|
|
82
82
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
83
83
|
*/
|
|
84
|
-
export function max<Item extends PlainObject,
|
|
84
|
+
export function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(
|
|
85
85
|
items: Item[],
|
|
86
|
-
key:
|
|
86
|
+
key: ItemKey,
|
|
87
87
|
): number;
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type {PlainObject} from '../../models';
|
|
2
2
|
|
|
3
|
-
export function partial<Value extends object,
|
|
3
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
4
4
|
value: unknown,
|
|
5
|
-
keys:
|
|
5
|
+
keys: ValueKey[],
|
|
6
6
|
omit: true,
|
|
7
|
-
): Omit<Value,
|
|
7
|
+
): Omit<Value, ValueKey>;
|
|
8
8
|
|
|
9
|
-
export function partial<Value extends object,
|
|
9
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
10
10
|
value: unknown,
|
|
11
|
-
keys:
|
|
11
|
+
keys: ValueKey[],
|
|
12
12
|
omit: false,
|
|
13
|
-
): Pick<Value,
|
|
13
|
+
): Pick<Value, ValueKey>;
|
|
14
14
|
|
|
15
|
-
export function partial<Value extends object,
|
|
15
|
+
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
16
16
|
value: unknown,
|
|
17
|
-
providedKeys:
|
|
17
|
+
providedKeys: ValueKey[],
|
|
18
18
|
omit: boolean,
|
|
19
19
|
): Partial<Value> {
|
|
20
20
|
if (typeof value !== 'object' || value === null) {
|
|
@@ -37,7 +37,7 @@ export function partial<Value extends object, Key extends keyof Value>(
|
|
|
37
37
|
continue;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (omit ? !providedKeys.includes(key as
|
|
40
|
+
if (omit ? !providedKeys.includes(key as ValueKey) : true) {
|
|
41
41
|
(partials as PlainObject)[key] = (value as PlainObject)[key];
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/math.ts
CHANGED
|
@@ -76,10 +76,10 @@ export function count<Item>(
|
|
|
76
76
|
* @param value Value to match and count
|
|
77
77
|
* @returns Number of items with the specified key value, or `NaN` if no count can be calculated
|
|
78
78
|
*/
|
|
79
|
-
export function count<Item extends PlainObject,
|
|
79
|
+
export function count<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
80
80
|
array: Item[],
|
|
81
|
-
key:
|
|
82
|
-
value: Item[
|
|
81
|
+
key: ItemKey,
|
|
82
|
+
value: Item[ItemKey],
|
|
83
83
|
): number;
|
|
84
84
|
|
|
85
85
|
/**
|