fnts 2.1.0 → 2.2.0
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/get.d.ts +4 -10
- package/index.d.ts +2 -1
- package/index.js +4 -2
- package/maybe/operators/fold-map.js +1 -1
- package/package.json +1 -1
- package/set.d.ts +24 -0
- package/set.js +42 -0
- package/tsconfig.json +2 -1
- package/types/effect.d.ts +1 -1
- package/types/flatten.d.ts +34 -0
- package/types/index.d.ts +10 -7
- package/types/slice.d.ts +1 -1
- package/types/trim.d.ts +19 -0
- package/types/unshift.d.ts +16 -0
package/get.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Get
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
* Recursively flattens object type to a union of its keys
|
|
6
|
-
* combined through dot-notation.
|
|
7
|
-
*/
|
|
8
|
-
export type Flatten<Source extends Record<string, unknown> | any[]> = keyof Source extends keyof any[] ? `${number}` : (keyof Source | keyof {
|
|
9
|
-
[Key in keyof Source as Key extends string ? Source[Key] extends Record<string, unknown> ? `${Key}.${Flatten<Source[Key]>}` : Source[Key] extends any[] ? Source[Key] extends Array<any[]> | Record<string, unknown>[] ? `${Key}.${number}` | `${Key}.${number}.${Flatten<Source[Key][number]>}` : `${Key}.${number}` : Key : never]: never;
|
|
10
|
-
});
|
|
4
|
+
import type { Flatten, Flattenable } from './types/flatten';
|
|
11
5
|
/**
|
|
12
6
|
* Gets the value type inside a nested object type `Source` by provided `Path`
|
|
13
7
|
* written in dot-notation.
|
|
14
8
|
*/
|
|
15
|
-
export type Get<Source, Path extends string> = Source extends Record<string, unknown> ? Path extends `${
|
|
9
|
+
export type Get<Source extends Flattenable, Path extends string> = Source extends Record<string, unknown> ? Path extends `${number}.${infer Right}` ? Get<Source, Right> : Path extends `${infer Left extends keyof Source}.${infer Right}` ? Get<Exclude<Source[Left], undefined>, Right> | Extract<Source[Left], undefined> : Path extends keyof Source ? Source[Path] : never : Source extends any[] ? Path extends `${infer Left extends number}.${infer Right}` ? Get<Exclude<Source[Left], undefined>, Right> | Extract<Source[Left], undefined> : Path extends `${infer Index extends number}` ? Source[Index] : never : never;
|
|
16
10
|
/**
|
|
17
11
|
* Gets the value inside a nested `source` object by provided `path`
|
|
18
12
|
* written in dot-notation.
|
|
19
13
|
*/
|
|
20
|
-
export default function get<Source extends
|
|
14
|
+
export default function get<Source extends Flattenable, Path extends Flatten<Source>>(path: Path): (source: Source) => Get<Source, Path>;
|
|
21
15
|
/**
|
|
22
16
|
* Gets the value inside a nested `source` object by provided `path`
|
|
23
17
|
* written in dot-notation.
|
|
24
18
|
*/
|
|
25
|
-
export default function get<Source extends
|
|
19
|
+
export default function get<Source extends Flattenable, Path extends Flatten<Source>>(source: Source, path: Path): Get<Source, Path>;
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { default as get } from './get';
|
|
2
|
+
export { default as set } from './set';
|
|
2
3
|
export { default as tap } from './tap';
|
|
3
4
|
export { default as pipe } from './pipe';
|
|
4
5
|
export { default as apply } from './apply';
|
|
5
6
|
export { default as curry } from './curry';
|
|
6
|
-
export { default as
|
|
7
|
+
export { default as guard } from './guard';
|
|
7
8
|
export { default as inject } from './inject';
|
|
8
9
|
export { default as compose } from './compose';
|
|
9
10
|
export { default as rethrow } from './rethrow';
|
package/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identity = exports.rethrow = exports.compose = exports.inject = exports.
|
|
3
|
+
exports.identity = exports.rethrow = exports.compose = exports.inject = exports.guard = exports.curry = exports.apply = exports.pipe = exports.tap = exports.set = exports.get = void 0;
|
|
4
4
|
var get_1 = require("./get");
|
|
5
5
|
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_1.default; } });
|
|
6
|
+
var set_1 = require("./set");
|
|
7
|
+
Object.defineProperty(exports, "set", { enumerable: true, get: function () { return set_1.default; } });
|
|
6
8
|
var tap_1 = require("./tap");
|
|
7
9
|
Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return tap_1.default; } });
|
|
8
10
|
var pipe_1 = require("./pipe");
|
|
@@ -12,7 +14,7 @@ Object.defineProperty(exports, "apply", { enumerable: true, get: function () { r
|
|
|
12
14
|
var curry_1 = require("./curry");
|
|
13
15
|
Object.defineProperty(exports, "curry", { enumerable: true, get: function () { return curry_1.default; } });
|
|
14
16
|
var guard_1 = require("./guard");
|
|
15
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "guard", { enumerable: true, get: function () { return guard_1.default; } });
|
|
16
18
|
var inject_1 = require("./inject");
|
|
17
19
|
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.default; } });
|
|
18
20
|
var compose_1 = require("./compose");
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var compose_1 = require("../../compose");
|
|
7
7
|
var permutation_2_1 = require("../../permutation/permutation-2");
|
|
8
|
-
var guards_1 = require("./guards");
|
|
9
8
|
var fold_1 = require("./fold");
|
|
9
|
+
var guards_1 = require("./guards");
|
|
10
10
|
function foldMap() {
|
|
11
11
|
var args = [];
|
|
12
12
|
for (var _i = 0; _i < arguments.length; _i++) {
|
package/package.json
CHANGED
package/set.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Set
|
|
3
|
+
*/
|
|
4
|
+
import type { Unshift } from './types/unshift';
|
|
5
|
+
import type { Flatten, Flattenable } from './types/flatten';
|
|
6
|
+
/**
|
|
7
|
+
* Sets the `Value` type inside a nested object type `Source` by provided `Path`
|
|
8
|
+
* written in dot-notation.
|
|
9
|
+
*/
|
|
10
|
+
export type Set<Source extends Flattenable, Path extends string, Value> = Source extends Record<string, unknown> ? Path extends `${number}.${infer Right}` ? Set<Source, Right, Value> : Path extends `${infer Left extends keyof Source}.${infer Right}` ? {
|
|
11
|
+
[Key in keyof Source]: Key extends Exclude<keyof Source, Left> ? Source[Key] : Set<Exclude<Source[Left], undefined>, Right, Value>;
|
|
12
|
+
} : Path extends keyof Source ? {
|
|
13
|
+
[Key in keyof Source]: Key extends Exclude<keyof Source, Path> ? Source[Key] : Value;
|
|
14
|
+
} : 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
|
+
/**
|
|
16
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
17
|
+
* written in dot-notation.
|
|
18
|
+
*/
|
|
19
|
+
export default function set<Source extends Flattenable, Path extends Flatten<Source>, Value>(path: Path, value: Value): (source: Source) => Set<Source, Path, Value>;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
22
|
+
* written in dot-notation.
|
|
23
|
+
*/
|
|
24
|
+
export default function set<Source extends Flattenable, Path extends Flatten<Source>, Value>(source: Source, path: Path, value: Value): Set<Source, Path, Value>;
|
package/set.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module Set
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var permutation_3_1 = require("./permutation/permutation-3");
|
|
7
|
+
/**
|
|
8
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
9
|
+
* written in dot-notation.
|
|
10
|
+
*/
|
|
11
|
+
function set() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return (0, permutation_3_1.default)(
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
function (source, path, value
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
var keys = path.split('.');
|
|
24
|
+
var length = keys.length;
|
|
25
|
+
var result = structuredClone(source);
|
|
26
|
+
if (length === 0) {
|
|
27
|
+
result[path] = value;
|
|
28
|
+
}
|
|
29
|
+
var scope = result[keys[0]];
|
|
30
|
+
for (var index = 1; index < length; index += 1) {
|
|
31
|
+
if (index === length - 1) {
|
|
32
|
+
scope[keys === null || keys === void 0 ? void 0 : keys[index]] = value;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
scope = scope === null || scope === void 0 ? void 0 : scope[keys === null || keys === void 0 ? void 0 : keys[index]];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
return result;
|
|
40
|
+
}).apply(void 0, args);
|
|
41
|
+
}
|
|
42
|
+
exports.default = set;
|
package/tsconfig.json
CHANGED
package/types/effect.d.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type subjective to flattening.
|
|
7
|
+
*/
|
|
8
|
+
export type Flattenable = Record<string, unknown> | any[]
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Recursively flattens object type to a union of its keys
|
|
12
|
+
* combined through dot-notation.
|
|
13
|
+
*/
|
|
14
|
+
export type Flatten<
|
|
15
|
+
Source extends Record<string, unknown> | any[],
|
|
16
|
+
> = keyof Source extends keyof any[]
|
|
17
|
+
? `${number}`
|
|
18
|
+
: (
|
|
19
|
+
| keyof Source
|
|
20
|
+
| keyof {
|
|
21
|
+
[
|
|
22
|
+
Key in keyof Source as
|
|
23
|
+
Key extends string
|
|
24
|
+
? Source[Key] extends Record<string, unknown>
|
|
25
|
+
? `${Key}.${Flatten<Source[Key]>}`
|
|
26
|
+
: Source[Key] extends any[]
|
|
27
|
+
? Source[Key] extends Array<any[]> | Record<string, unknown>[]
|
|
28
|
+
? `${Key}.${number}` | `${Key}.${number}.${Flatten<Source[Key][number]>}`
|
|
29
|
+
: `${Key}.${number}`
|
|
30
|
+
: Key
|
|
31
|
+
: never
|
|
32
|
+
] : never
|
|
33
|
+
}
|
|
34
|
+
)
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export type { Map } from './map'
|
|
2
|
-
export type { Last } from './last'
|
|
3
|
-
export type {
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
6
|
-
export type {
|
|
7
|
-
export type {
|
|
1
|
+
export type { Map } from './map'
|
|
2
|
+
export type { Last } from './last'
|
|
3
|
+
export type { Trim } from './trim'
|
|
4
|
+
export type { Slice } from './slice'
|
|
5
|
+
export type { Tuple } from './tuple'
|
|
6
|
+
export type { Effect } from './effect'
|
|
7
|
+
export type { Gradual } from './gradual'
|
|
8
|
+
export type { Unshift } from './unshift'
|
|
9
|
+
export type { Flatten } from './flatten'
|
|
10
|
+
export type { UnaryFunction, VariadicFunction } from './function'
|
package/types/slice.d.ts
CHANGED
package/types/trim.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tuple } from './tuple'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Removes `C` amount of `T` elements from the **end**.
|
|
9
|
+
*/
|
|
10
|
+
export type Trim<
|
|
11
|
+
T extends any[] | readonly any[],
|
|
12
|
+
C extends number
|
|
13
|
+
> = T['length'] extends C
|
|
14
|
+
? T
|
|
15
|
+
: T extends readonly [...infer S, ...Tuple<C>]
|
|
16
|
+
? S
|
|
17
|
+
: T extends [...infer S, ...Tuple<C>]
|
|
18
|
+
? S
|
|
19
|
+
: T
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Trim } from './trim'
|
|
6
|
+
import { Slice } from './slice'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Replaces `T` element on specified index `I` with `E`.
|
|
10
|
+
*/
|
|
11
|
+
export type Unshift<T extends any[] | readonly any[], I extends number, E> =
|
|
12
|
+
I extends 0
|
|
13
|
+
? [E, ...Slice<T, 1>]
|
|
14
|
+
: I extends Trim<T, 1>['length']
|
|
15
|
+
? [...Trim<T, 1>, E]
|
|
16
|
+
: [...Trim<T, Slice<T, I>['length']>, E, ...Slice<Slice<T, I>, 1>]
|