fnts 3.0.3 → 3.0.4
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/lens/get.d.ts +5 -5
- package/lens/lens.d.ts +3 -3
- package/lens/set.d.ts +9 -10
- package/lens/set.js +0 -1
- package/package.json +1 -1
- package/types/flatten.d.ts +19 -13
- package/types/unshift.d.ts +6 -6
package/lens/get.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lens
|
|
3
3
|
*/
|
|
4
|
-
import type { Flatten, Flattenable
|
|
4
|
+
import type { Flatten, Flattenable } from '../types/flatten';
|
|
5
5
|
/**
|
|
6
6
|
* Gets the value type inside a nested object type `Source` by provided `Path`
|
|
7
7
|
* written in dot-notation.
|
|
8
8
|
*/
|
|
9
|
-
export type Get<Source extends Flattenable, Path extends Flatten<
|
|
9
|
+
export type Get<Source extends Flattenable, Path extends Flatten<Source>> = Source extends Record<string, unknown> ? (Path extends keyof Source ? Source[Path] : (Path extends `${infer Left}.${infer Right}` ? (Left extends keyof Source ? (Source[Left] extends Flattenable ? Get<Source[Left], Right> : never) : never) : never)) : Source extends any[] ? (Path extends `${number}` ? Source[number] : (Path extends `${infer Left}.${infer Right}` ? (Left extends `${number}` ? (Source[number] extends Flattenable ? Get<Source[number], Right> : never) : never) : never)) : never;
|
|
10
10
|
/**
|
|
11
11
|
* Gets the value inside a nested `source` object by provided `path`
|
|
12
12
|
* written in dot-notation.
|
|
13
13
|
*/
|
|
14
|
-
export default function get<Source extends Flattenable>(source: Source): <Path extends Flatten<
|
|
14
|
+
export default function get<Source extends Flattenable>(source: Source): <Path extends Flatten<Source>>(path: Path) => Get<Source, Path>;
|
|
15
15
|
/**
|
|
16
16
|
* Gets the value inside a nested `source` object by provided `path`
|
|
17
17
|
* written in dot-notation.
|
|
18
18
|
*/
|
|
19
|
-
export default function get<Source extends Flattenable, Path extends Flatten<
|
|
19
|
+
export default function get<Source extends Flattenable, Path extends Flatten<Source>>(path: Path): (source: Source) => Get<Source, Path>;
|
|
20
20
|
/**
|
|
21
21
|
* Gets the value inside a nested `source` object by provided `path`
|
|
22
22
|
* written in dot-notation.
|
|
23
23
|
*/
|
|
24
|
-
export default function get<Source extends Flattenable, Path extends Flatten<
|
|
24
|
+
export default function get<Source extends Flattenable, Path extends Flatten<Source>>(source: Source, path: Path): Get<Source, Path>;
|
package/lens/lens.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lens
|
|
3
3
|
*/
|
|
4
|
-
import type { Flatten, Flattenable
|
|
4
|
+
import type { Flatten, Flattenable } from '../types';
|
|
5
5
|
import { Get } from './get.js';
|
|
6
6
|
import { Set } from './set.js';
|
|
7
7
|
/**
|
|
@@ -9,8 +9,8 @@ import { Set } from './set.js';
|
|
|
9
9
|
* effectively creating a functional lens.
|
|
10
10
|
*/
|
|
11
11
|
export interface Lens<Source extends Flattenable> {
|
|
12
|
-
<Path extends Flatten<
|
|
13
|
-
<Path extends Flatten<
|
|
12
|
+
<Path extends Flatten<Source>>(path: Path): Get<Source, Path>;
|
|
13
|
+
<Path extends Flatten<Source>, Value extends Get<Source, Path>>(path: Path, value: Value): Set<Source, Path, Value>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Creates a wrapper for a given `source` that provides access to both `get` and `set` functionalities for it,
|
package/lens/set.d.ts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lens
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
import type { Flatten, Flattenable, NormalizeFlattenable } from '../types/flatten';
|
|
4
|
+
import type { Flatten, Flattenable } from '../types/flatten';
|
|
6
5
|
import type { Get } from './get.js';
|
|
7
6
|
/**
|
|
8
7
|
* Sets the `Value` type inside a nested object type `Source` by provided `Path`
|
|
9
8
|
* written in dot-notation.
|
|
10
9
|
*/
|
|
11
|
-
export type Set<Source extends Flattenable, Path extends Flatten<
|
|
12
|
-
[Key in keyof Source]: Key extends
|
|
13
|
-
} : (Path extends keyof Source ? {
|
|
14
|
-
[Key in keyof Source]: Key extends
|
|
15
|
-
} : never))) :
|
|
10
|
+
export type Set<Source extends Flattenable, Path extends Flatten<Source>, Value extends Get<Source, Path>> = Source extends Record<string, unknown> ? (Path extends keyof Source ? {
|
|
11
|
+
[Key in keyof Source]: Key extends Path ? Value : Source[Key];
|
|
12
|
+
} : (Path extends `${infer Left}.${infer Right}` ? (Left extends keyof Source ? (Source[Left] extends Flattenable ? {
|
|
13
|
+
[Key in keyof Source]: (Key extends Left ? Set<Source[Left], Right, Value> : Source[Key]);
|
|
14
|
+
} : never) : never) : never)) : Source extends any[] ? (Path extends `${number}` ? Value[] : (Path extends `${infer Left}.${infer Right}` ? (Left extends `${number}` ? (Source[number] extends Flattenable ? Set<Source[number], Right, Value>[] : never) : never) : never)) : never;
|
|
16
15
|
/**
|
|
17
16
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
18
17
|
* written in dot-notation.
|
|
19
18
|
*/
|
|
20
|
-
export default function set<Source extends Flattenable>(source: Source): <Path extends Flatten<
|
|
19
|
+
export default function set<Source extends Flattenable>(source: Source): <Path extends Flatten<Source>, Value extends Get<Source, Path>>(path: Path, value: Value) => Set<Source, Path, Value>;
|
|
21
20
|
/**
|
|
22
21
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
23
22
|
* written in dot-notation.
|
|
24
23
|
*/
|
|
25
|
-
export default function set<Source extends Flattenable, Path extends Flatten<
|
|
24
|
+
export default function set<Source extends Flattenable, Path extends Flatten<Source>, Value extends Get<Source, Path>>(path: Path, value: Value): (source: Source) => Set<Source, Path, Value>;
|
|
26
25
|
/**
|
|
27
26
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
28
27
|
* written in dot-notation.
|
|
29
28
|
*/
|
|
30
|
-
export default function set<Source extends Flattenable, Path extends Flatten<
|
|
29
|
+
export default function set<Source extends Flattenable, Path extends Flatten<Source>, Value extends Get<Source, Path>>(source: Source, path: Path, value: Value): Set<Source, Path, Value>;
|
package/lens/set.js
CHANGED
package/package.json
CHANGED
package/types/flatten.d.ts
CHANGED
|
@@ -5,12 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Type subjective to flattening.
|
|
7
7
|
*/
|
|
8
|
-
export type Flattenable = Record<string, unknown> |
|
|
9
|
-
|
|
10
|
-
export type NormalizeFlattenable<Source extends Flattenable> =
|
|
11
|
-
Source extends Array<infer Element>
|
|
12
|
-
? Record<`${number}`, Element>
|
|
13
|
-
: Source
|
|
8
|
+
export type Flattenable = Record<string, unknown> | any[]
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Recursively flattens object type to a union of its keys
|
|
@@ -18,15 +13,26 @@ export type NormalizeFlattenable<Source extends Flattenable> =
|
|
|
18
13
|
*/
|
|
19
14
|
export type Flatten<
|
|
20
15
|
Source extends Flattenable,
|
|
21
|
-
> =
|
|
22
|
-
|
|
16
|
+
> = (
|
|
17
|
+
Source extends Record<string, unknown>
|
|
18
|
+
? (keyof {
|
|
23
19
|
[
|
|
24
20
|
Key in keyof Source as
|
|
25
21
|
Key extends string
|
|
26
22
|
? (Source[Key] extends Flattenable
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
? Key | `${Key}.${Flatten<Source[Key]>}`
|
|
24
|
+
: (Source[Key] extends any[]
|
|
25
|
+
? Key | `${Key}.${number}.${Flatten<Source[Key][number]>}`
|
|
26
|
+
: Key))
|
|
30
27
|
: never
|
|
31
|
-
]:
|
|
32
|
-
}
|
|
28
|
+
]: void
|
|
29
|
+
})
|
|
30
|
+
: (Source extends any[]
|
|
31
|
+
? (Source[number] extends Flattenable
|
|
32
|
+
? `${number}` | `${number}.${Flatten<Source[number]>}`
|
|
33
|
+
: `${number}`)
|
|
34
|
+
: never)
|
|
35
|
+
// So that Flatten is recognized to always return strings
|
|
36
|
+
) extends infer Key extends string
|
|
37
|
+
? Key
|
|
38
|
+
: never
|
package/types/unshift.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { Slice } from './slice'
|
|
|
8
8
|
/**
|
|
9
9
|
* Replaces `T` element on specified index `I` with `E`.
|
|
10
10
|
*/
|
|
11
|
-
export type Unshift<
|
|
12
|
-
|
|
13
|
-
? [
|
|
14
|
-
:
|
|
15
|
-
? [...Trim<
|
|
16
|
-
: [...Trim<
|
|
11
|
+
export type Unshift<Array extends ReadonlyArray<any>, Index extends number, Element> =
|
|
12
|
+
Index extends 0
|
|
13
|
+
? [Element, ...Slice<Array, 1>]
|
|
14
|
+
: Index extends Trim<Array, 1>['length']
|
|
15
|
+
? [...Trim<Array, 1>, Element]
|
|
16
|
+
: [...Trim<Array, Slice<Array, Index>['length']>, Element, ...Slice<Slice<Array, Index>, 1>]
|