fnts 3.0.1 → 3.0.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/README.md +4 -4
- package/either/index.d.ts +1 -0
- package/either/index.js +1 -0
- package/lens/get.d.ts +5 -5
- package/lens/lens.d.ts +3 -3
- package/lens/lens.js +1 -0
- package/lens/set.d.ts +7 -7
- package/lens/set.js +1 -5
- package/maybe/index.d.ts +1 -0
- package/maybe/index.js +1 -0
- package/package.json +20 -8
- package/tsconfig.json +2 -2
- package/types/flatten.d.ts +13 -15
- package/types/unshift.d.ts +1 -1
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
7
|
<a href="https://github.com/drizzer14/fnts/blob/main/LICENSE">
|
|
8
|
-
<img src="https://img.shields.io/github/license/drizzer14/fnts" />
|
|
8
|
+
<img src="https://img.shields.io/github/license/drizzer14/fnts?color=blue&style=for-the-badge" />
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://
|
|
11
|
-
<img src="https://img.shields.io/
|
|
10
|
+
<a href="https://github.com/drizzer14/fnts/actions/workflows/workflow.yml">
|
|
11
|
+
<img src="https://img.shields.io/github/actions/workflow/status/drizzer14/fnts/workflow.yml?color=blue&style=for-the-badge" />
|
|
12
12
|
</a>
|
|
13
13
|
<a href="https://www.npmjs.com/package/fnts">
|
|
14
|
-
<img src="https://img.shields.io/npm/v/fnts" />
|
|
14
|
+
<img src="https://img.shields.io/npm/v/fnts?color=blue&style=for-the-badge" />
|
|
15
15
|
</a>
|
|
16
16
|
</p>
|
|
17
17
|
|
package/either/index.d.ts
CHANGED
package/either/index.js
CHANGED
package/lens/get.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lens
|
|
3
3
|
*/
|
|
4
|
-
import type { Flatten, Flattenable } from '../types/flatten';
|
|
4
|
+
import type { Flatten, Flattenable, NormalizeFlattenable } 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
|
|
9
|
+
export type Get<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<Source>>> = Path extends keyof Source ? Source[Path] : (Path extends `${infer Left}.${infer Right}` ? (Left extends keyof NormalizeFlattenable<Source> ? (NormalizeFlattenable<Source>[Left] extends Flattenable ? Get<NormalizeFlattenable<Source>[Left], Right> : 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<Source
|
|
14
|
+
export default function get<Source extends Flattenable>(source: Source): <Path extends Flatten<NormalizeFlattenable<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<Source
|
|
19
|
+
export default function get<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<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<Source
|
|
24
|
+
export default function get<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<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 } from '../types';
|
|
4
|
+
import type { Flatten, Flattenable, NormalizeFlattenable } 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<Source
|
|
13
|
-
<Path extends Flatten<Source
|
|
12
|
+
<Path extends Flatten<NormalizeFlattenable<Source>>>(path: Path): Get<Source, Path>;
|
|
13
|
+
<Path extends Flatten<NormalizeFlattenable<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/lens.js
CHANGED
package/lens/set.d.ts
CHANGED
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
* @module Lens
|
|
3
3
|
*/
|
|
4
4
|
import type { Unshift } from '../types/unshift';
|
|
5
|
-
import type { Flatten, Flattenable } from '../types/flatten';
|
|
5
|
+
import type { Flatten, Flattenable, NormalizeFlattenable } from '../types/flatten';
|
|
6
6
|
import type { Get } from './get.js';
|
|
7
7
|
/**
|
|
8
8
|
* Sets the `Value` type inside a nested object type `Source` by provided `Path`
|
|
9
9
|
* written in dot-notation.
|
|
10
10
|
*/
|
|
11
|
-
export type Set<Source extends Flattenable, Path extends
|
|
11
|
+
export type Set<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<Source>>, Value extends Get<Source, Path>> = Source extends Record<string, unknown> ? (Path extends `${number}.${infer Right}` ? Set<Source, Right, Value> : (Path extends `${infer Left}.${infer Right}` ? {
|
|
12
12
|
[Key in keyof Source]: Key extends Exclude<keyof Source, Left> ? Source[Key] : Set<Exclude<Source[Left], undefined>, Right, Value>;
|
|
13
|
-
} : Path extends keyof Source ? {
|
|
13
|
+
} : (Path extends keyof Source ? {
|
|
14
14
|
[Key in keyof Source]: Key extends Exclude<keyof Source, Path> ? Source[Key] : Value;
|
|
15
|
-
} : never : Source extends any[] ? Path extends `${infer Index extends number}.${infer Right}` ? Unshift<Source, Index, Set<Exclude<Source[Index], undefined>, Right, Value>> : Path extends `${infer Index extends number}` ? Unshift<Source, Index, Value> : never : never;
|
|
15
|
+
} : never))) : (Source extends any[] ? (Path extends `${infer Index extends number}.${infer Right}` ? Unshift<Source, Index, Set<Exclude<Source[Index], undefined>, Right, Value>> : (Path extends `${infer Index extends number}` ? Unshift<Source, Index, Value> : never)) : never);
|
|
16
16
|
/**
|
|
17
17
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
18
18
|
* written in dot-notation.
|
|
19
19
|
*/
|
|
20
|
-
export default function set<Source extends Flattenable>(source: Source): <Path extends Flatten<Source
|
|
20
|
+
export default function set<Source extends Flattenable>(source: Source): <Path extends Flatten<NormalizeFlattenable<Source>>, Value extends Get<Source, Path>>(path: Path, value: Value) => Set<Source, Path, Value>;
|
|
21
21
|
/**
|
|
22
22
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
23
23
|
* written in dot-notation.
|
|
24
24
|
*/
|
|
25
|
-
export default function set<Source extends Flattenable, Path extends Flatten<Source
|
|
25
|
+
export default function set<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<Source>>, Value extends Get<Source, Path>>(path: Path, value: Value): (source: Source) => Set<Source, Path, Value>;
|
|
26
26
|
/**
|
|
27
27
|
* Sets the `value` inside a nested `source` object by provided `path`
|
|
28
28
|
* written in dot-notation.
|
|
29
29
|
*/
|
|
30
|
-
export default function set<Source extends Flattenable, Path extends Flatten<Source
|
|
30
|
+
export default function set<Source extends Flattenable, Path extends Flatten<NormalizeFlattenable<Source>>, Value extends Get<Source, Path>>(source: Source, path: Path, value: Value): Set<Source, Path, Value>;
|
package/lens/set.js
CHANGED
|
@@ -12,7 +12,6 @@ export default function set(...args) {
|
|
|
12
12
|
return (path, value) => setter(args[0], path, value);
|
|
13
13
|
}
|
|
14
14
|
case 2: {
|
|
15
|
-
// @ts-ignore
|
|
16
15
|
return (source) => setter(source, args[0], args[1]);
|
|
17
16
|
}
|
|
18
17
|
case 3: {
|
|
@@ -21,9 +20,7 @@ export default function set(...args) {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
function setter(source, path, value
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
) {
|
|
23
|
+
function setter(source, path, value) {
|
|
27
24
|
// @ts-ignore
|
|
28
25
|
const keys = path.split('.');
|
|
29
26
|
const length = keys.length;
|
|
@@ -40,6 +37,5 @@ function setter(source, path, value
|
|
|
40
37
|
scope = scope?.[keys?.[index]];
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
// @ts-ignore
|
|
44
40
|
return result;
|
|
45
41
|
}
|
package/maybe/index.d.ts
CHANGED
package/maybe/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnts",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dmytro Vasylkivskyi",
|
|
6
6
|
"description": "TypeScript / JavaScript FP utilities",
|
|
@@ -15,13 +15,6 @@
|
|
|
15
15
|
"homepage": "https://drizzer14.github.io/fnts",
|
|
16
16
|
"repository": "https://github.com/drizzer14/fnts",
|
|
17
17
|
"type": "module",
|
|
18
|
-
"module": "index.js",
|
|
19
|
-
"types": "index.d.ts",
|
|
20
|
-
"sideEffects": false,
|
|
21
|
-
"engines": {
|
|
22
|
-
"node": ">=20.13.1",
|
|
23
|
-
"npm": ">=10.5.2"
|
|
24
|
-
},
|
|
25
18
|
"peerDependencies": {
|
|
26
19
|
"typescript": ">=5.0"
|
|
27
20
|
},
|
|
@@ -29,5 +22,24 @@
|
|
|
29
22
|
"typescript": {
|
|
30
23
|
"optional": true
|
|
31
24
|
}
|
|
25
|
+
},
|
|
26
|
+
"module": "index.js",
|
|
27
|
+
"types": "index.d.ts",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./index.js",
|
|
31
|
+
"./apply": "./apply.js",
|
|
32
|
+
"./compose": "./compose.js",
|
|
33
|
+
"./curry": "./curry.js",
|
|
34
|
+
"./guard": "./guard.js",
|
|
35
|
+
"./identity": "./identity.js",
|
|
36
|
+
"./inject": "./inject.js",
|
|
37
|
+
"./pipe": "./pipe.js",
|
|
38
|
+
"./rethrow": "./rethrow.js",
|
|
39
|
+
"./tap": "./tap.js",
|
|
40
|
+
"./either": "./either/index.js",
|
|
41
|
+
"./lens": "./lens/index.js",
|
|
42
|
+
"./maybe": "./maybe/index.js",
|
|
43
|
+
"./permutation": "./permutation/index.js"
|
|
32
44
|
}
|
|
33
45
|
}
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"esModuleInterop": true,
|
|
12
12
|
"strict": true,
|
|
13
13
|
"alwaysStrict": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
14
|
"noImplicitAny": true,
|
|
16
15
|
"noUnusedLocals": false,
|
|
17
16
|
"strictNullChecks": true,
|
|
@@ -21,6 +20,7 @@
|
|
|
21
20
|
"strictFunctionTypes": true,
|
|
22
21
|
"strictBindCallApply": true,
|
|
23
22
|
"allowUnreachableCode": false,
|
|
24
|
-
"forceConsistentCasingInFileNames": true
|
|
23
|
+
"forceConsistentCasingInFileNames": true,
|
|
24
|
+
"ignoreDeprecations": "5.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/types/flatten.d.ts
CHANGED
|
@@ -5,30 +5,28 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Type subjective to flattening.
|
|
7
7
|
*/
|
|
8
|
-
export type Flattenable = Record<string, unknown> | any
|
|
8
|
+
export type Flattenable = Record<string, unknown> | Array<any>
|
|
9
|
+
|
|
10
|
+
export type NormalizeFlattenable<Source extends Flattenable> =
|
|
11
|
+
Source extends Array<infer Element>
|
|
12
|
+
? Record<`${number}`, Element>
|
|
13
|
+
: Source
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Recursively flattens object type to a union of its keys
|
|
12
17
|
* combined through dot-notation.
|
|
13
18
|
*/
|
|
14
19
|
export type Flatten<
|
|
15
|
-
Source extends
|
|
16
|
-
> = keyof Source
|
|
17
|
-
? `${number}`
|
|
18
|
-
: (
|
|
19
|
-
| keyof Source
|
|
20
|
+
Source extends Flattenable,
|
|
21
|
+
> = | keyof NormalizeFlattenable<Source>
|
|
20
22
|
| keyof {
|
|
21
23
|
[
|
|
22
24
|
Key in keyof Source as
|
|
23
25
|
Key extends string
|
|
24
|
-
? Source[Key] extends
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
? `${Key}.${number}` | `${Key}.${number}.${Flatten<Source[Key][number]>}`
|
|
29
|
-
: `${Key}.${number}`
|
|
30
|
-
: Key
|
|
26
|
+
? (Source[Key] extends Flattenable
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
? `${Key}.${Flatten<NormalizeFlattenable<Source[Key]>>}`
|
|
29
|
+
: Key)
|
|
31
30
|
: never
|
|
32
|
-
]
|
|
31
|
+
]: never
|
|
33
32
|
}
|
|
34
|
-
)
|
package/types/unshift.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Slice } from './slice'
|
|
|
8
8
|
/**
|
|
9
9
|
* Replaces `T` element on specified index `I` with `E`.
|
|
10
10
|
*/
|
|
11
|
-
export type Unshift<T extends
|
|
11
|
+
export type Unshift<T extends readonly any[], I extends number, E> =
|
|
12
12
|
I extends 0
|
|
13
13
|
? [E, ...Slice<T, 1>]
|
|
14
14
|
: I extends Trim<T, 1>['length']
|