fnts 2.2.0 → 3.0.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/LICENSE +1 -1
- package/README.md +1 -1
- package/apply.js +6 -17
- package/compose.js +3 -16
- package/curry.js +6 -20
- package/either/either-sync.d.ts +1 -1
- package/either/either-sync.js +5 -8
- package/either/either.d.ts +2 -2
- package/either/either.js +5 -8
- package/either/index.d.ts +4 -4
- package/either/index.js +4 -11
- package/either/left.js +8 -13
- package/either/operators/bifold/bifold.d.ts +3 -3
- package/either/operators/bifold/bifold.js +7 -10
- package/either/operators/bifold/bifoldl.d.ts +2 -2
- package/either/operators/bifold/bifoldl.js +5 -8
- package/either/operators/bifold/bifoldr.d.ts +2 -2
- package/either/operators/bifold/bifoldr.js +5 -8
- package/either/operators/bifold/index.d.ts +3 -3
- package/either/operators/bifold/index.js +3 -9
- package/either/operators/bifold-map/bifold-map.d.ts +1 -1
- package/either/operators/bifold-map/bifold-map.js +16 -23
- package/either/operators/bifold-map/bifoldl-map.d.ts +3 -3
- package/either/operators/bifold-map/bifoldl-map.js +9 -16
- package/either/operators/bifold-map/bifoldr-map.d.ts +3 -3
- package/either/operators/bifold-map/bifoldr-map.js +9 -16
- package/either/operators/bifold-map/index.d.ts +3 -3
- package/either/operators/bifold-map/index.js +3 -9
- package/either/operators/bimap/bimap.d.ts +1 -1
- package/either/operators/bimap/bimap.js +10 -17
- package/either/operators/bimap/first.d.ts +2 -2
- package/either/operators/bimap/first.js +12 -19
- package/either/operators/bimap/index.d.ts +3 -3
- package/either/operators/bimap/index.js +3 -9
- package/either/operators/bimap/second.d.ts +2 -2
- package/either/operators/bimap/second.js +12 -19
- package/either/operators/bindr.d.ts +1 -1
- package/either/operators/bindr.js +11 -18
- package/either/operators/guards.d.ts +3 -3
- package/either/operators/guards.js +7 -13
- package/either/operators/index.d.ts +5 -5
- package/either/operators/index.js +5 -30
- package/either/right.js +8 -13
- package/guard.d.ts +3 -3
- package/guard.js +8 -19
- package/identity.js +1 -4
- package/index.d.ts +9 -11
- package/index.js +9 -25
- package/inject.js +7 -18
- package/{get.d.ts → lens/get.d.ts} +8 -3
- package/lens/get.js +29 -0
- package/lens/index.d.ts +3 -0
- package/lens/index.js +3 -0
- package/lens/lens.d.ts +19 -0
- package/lens/lens.js +17 -0
- package/lens/set.d.ts +30 -0
- package/lens/set.js +44 -0
- package/maybe/index.d.ts +3 -3
- package/maybe/index.js +3 -9
- package/maybe/just.js +8 -13
- package/maybe/maybe.d.ts +2 -2
- package/maybe/maybe.js +5 -8
- package/maybe/nothing.js +7 -12
- package/maybe/operators/bind.d.ts +1 -1
- package/maybe/operators/bind.js +11 -18
- package/maybe/operators/fmap.d.ts +1 -1
- package/maybe/operators/fmap.js +12 -19
- package/maybe/operators/fold-map.d.ts +3 -3
- package/maybe/operators/fold-map.js +9 -16
- package/maybe/operators/fold.d.ts +3 -3
- package/maybe/operators/fold.js +7 -10
- package/maybe/operators/guards.d.ts +3 -3
- package/maybe/operators/guards.js +7 -13
- package/maybe/operators/index.d.ts +5 -5
- package/maybe/operators/index.js +5 -26
- package/package.json +11 -4
- package/permutation/index.d.ts +2 -2
- package/permutation/index.js +2 -7
- package/permutation/permutation-2.js +5 -12
- package/permutation/permutation-3.d.ts +1 -1
- package/permutation/permutation-3.js +5 -12
- package/pipe.js +4 -16
- package/rethrow.js +3 -6
- package/set.js +13 -20
- package/tap.d.ts +1 -1
- package/tap.js +4 -7
- package/tsconfig.json +2 -3
- package/types/index.d.ts +10 -10
- package/get.js +0 -26
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Either Operators
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return (0, permutation_2_1.default)(function (monad, mapLeft) {
|
|
18
|
-
return (0, guards_1.isLeft)(monad)
|
|
19
|
-
? (0, compose_1.default)((0, compose_1.default)(left_1.default, mapLeft), bifoldl_1.default, monad)
|
|
20
|
-
: (0, identity_1.default)(monad);
|
|
21
|
-
}).apply(void 0, args);
|
|
4
|
+
import { isLeft } from '../guards.js';
|
|
5
|
+
import compose from '../../../compose.js';
|
|
6
|
+
import bifoldl from '../bifold/bifoldl.js';
|
|
7
|
+
import left from '../../left.js';
|
|
8
|
+
import identity from '../../../identity.js';
|
|
9
|
+
import permutation2 from '../../../permutation/permutation-2.js';
|
|
10
|
+
export default function first(...args) {
|
|
11
|
+
return permutation2((monad, mapLeft) => {
|
|
12
|
+
return isLeft(monad)
|
|
13
|
+
? compose(compose(left, mapLeft), bifoldl, monad)
|
|
14
|
+
: identity(monad);
|
|
15
|
+
})(...args);
|
|
22
16
|
}
|
|
23
|
-
exports.default = first;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default } from './bimap';
|
|
2
|
-
export { default as first } from './first';
|
|
3
|
-
export { default as second } from './second';
|
|
1
|
+
export { default } from './bimap.js';
|
|
2
|
+
export { default as first } from './first.js';
|
|
3
|
+
export { default as second } from './second.js';
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var bimap_1 = require("./bimap");
|
|
5
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bimap_1.default; } });
|
|
6
|
-
var first_1 = require("./first");
|
|
7
|
-
Object.defineProperty(exports, "first", { enumerable: true, get: function () { return first_1.default; } });
|
|
8
|
-
var second_1 = require("./second");
|
|
9
|
-
Object.defineProperty(exports, "second", { enumerable: true, get: function () { return second_1.default; } });
|
|
1
|
+
export { default } from './bimap.js';
|
|
2
|
+
export { default as first } from './first.js';
|
|
3
|
+
export { default as second } from './second.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Either Operators
|
|
3
3
|
*/
|
|
4
|
-
import type { Either } from '../../either';
|
|
5
|
-
import { Right } from '../../right';
|
|
4
|
+
import type { Either } from '../../either.js';
|
|
5
|
+
import { Right } from '../../right.js';
|
|
6
6
|
import type { Map } from '../../../types/map';
|
|
7
7
|
export type Second<Monad extends Either<any, any>> = Monad extends Right<infer RightValue> ? RightValue : Monad extends Either<any, infer RightValue> ? RightValue : never;
|
|
8
8
|
/**
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Either Operators
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return (0, permutation_2_1.default)(function (monad, mapRight) {
|
|
18
|
-
return (0, guards_1.isRight)(monad)
|
|
19
|
-
? (0, compose_1.default)((0, compose_1.default)(right_1.default, mapRight), bifold_1.bifoldr, monad)
|
|
20
|
-
: (0, identity_1.default)(monad);
|
|
21
|
-
}).apply(void 0, args);
|
|
4
|
+
import { bifoldr } from '../bifold/index.js';
|
|
5
|
+
import { isRight } from '../guards.js';
|
|
6
|
+
import compose from '../../../compose.js';
|
|
7
|
+
import identity from '../../../identity.js';
|
|
8
|
+
import right from '../../right.js';
|
|
9
|
+
import permutation2 from '../../../permutation/permutation-2.js';
|
|
10
|
+
export default function second(...args) {
|
|
11
|
+
return permutation2((monad, mapRight) => {
|
|
12
|
+
return isRight(monad)
|
|
13
|
+
? compose(compose(right, mapRight), bifoldr, monad)
|
|
14
|
+
: identity(monad);
|
|
15
|
+
})(...args);
|
|
22
16
|
}
|
|
23
|
-
exports.default = second;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Either Operators
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return (0, permutation_2_1.default)(function (monad, mapRight) {
|
|
17
|
-
return (0, guards_1.isRight)(monad)
|
|
18
|
-
? (0, compose_1.default)(mapRight, bifold_1.bifoldr, monad)
|
|
19
|
-
: (0, identity_1.default)(monad);
|
|
20
|
-
}).apply(void 0, args);
|
|
4
|
+
import compose from '../../compose.js';
|
|
5
|
+
import identity from '../../identity.js';
|
|
6
|
+
import permutation2 from '../../permutation/permutation-2.js';
|
|
7
|
+
import { bifoldr } from './bifold/index.js';
|
|
8
|
+
import { isRight } from './guards.js';
|
|
9
|
+
export default function bindr(...args) {
|
|
10
|
+
return permutation2((monad, mapRight) => {
|
|
11
|
+
return isRight(monad)
|
|
12
|
+
? compose(mapRight, bifoldr, monad)
|
|
13
|
+
: identity(monad);
|
|
14
|
+
})(...args);
|
|
21
15
|
}
|
|
22
|
-
exports.default = bindr;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Either Operators
|
|
3
3
|
*/
|
|
4
|
-
import { Left } from '../left';
|
|
5
|
-
import { Right } from '../right';
|
|
6
|
-
import type { Either } from '../either';
|
|
4
|
+
import { Left } from '../left.js';
|
|
5
|
+
import { Right } from '../right.js';
|
|
6
|
+
import type { Either } from '../either.js';
|
|
7
7
|
/**
|
|
8
8
|
* Type guard function to tell if the provided `value` is `Left`.
|
|
9
9
|
*/
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Either Operators
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var left_1 = require("../left");
|
|
8
|
-
var right_1 = require("../right");
|
|
4
|
+
import { lid } from '../left.js';
|
|
5
|
+
import { rid } from '../right.js';
|
|
9
6
|
/**
|
|
10
7
|
* Type guard function to tell if the provided `value` is `Left`.
|
|
11
8
|
*/
|
|
12
|
-
function isLeft(value) {
|
|
13
|
-
return Object.prototype.hasOwnProperty.call(value,
|
|
9
|
+
export function isLeft(value) {
|
|
10
|
+
return Object.prototype.hasOwnProperty.call(value, lid);
|
|
14
11
|
}
|
|
15
|
-
exports.isLeft = isLeft;
|
|
16
12
|
/**
|
|
17
13
|
* Type guard function to tell if the provided `value` is `Right`.
|
|
18
14
|
*/
|
|
19
|
-
function isRight(value) {
|
|
20
|
-
return Object.prototype.hasOwnProperty.call(value,
|
|
15
|
+
export function isRight(value) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(value, rid);
|
|
21
17
|
}
|
|
22
|
-
exports.isRight = isRight;
|
|
23
18
|
/**
|
|
24
19
|
* Type guard function to tell if the provided `value` is `Either`.
|
|
25
20
|
*/
|
|
26
|
-
function isEither(value) {
|
|
21
|
+
export function isEither(value) {
|
|
27
22
|
return isLeft(value) || isRight(value);
|
|
28
23
|
}
|
|
29
|
-
exports.isEither = isEither;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { bifoldl, Bifoldl, bifoldr, Bifoldr, default as bifold, Bifold, } from './bifold';
|
|
2
|
-
export * from './guards';
|
|
3
|
-
export { default as bindr } from './bindr';
|
|
4
|
-
export { default as bifoldMap } from './bifold-map';
|
|
5
|
-
export { default as bimap, first, second } from './bimap';
|
|
1
|
+
export { bifoldl, Bifoldl, bifoldr, Bifoldr, default as bifold, Bifold, } from './bifold/index.js';
|
|
2
|
+
export * from './guards.js';
|
|
3
|
+
export { default as bindr } from './bindr.js';
|
|
4
|
+
export { default as bifoldMap } from './bifold-map/index.js';
|
|
5
|
+
export { default as bimap, first, second } from './bimap/index.js';
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.second = exports.first = exports.bimap = exports.bifoldMap = exports.bindr = exports.bifold = exports.bifoldr = exports.bifoldl = void 0;
|
|
18
|
-
var bifold_1 = require("./bifold");
|
|
19
|
-
Object.defineProperty(exports, "bifoldl", { enumerable: true, get: function () { return bifold_1.bifoldl; } });
|
|
20
|
-
Object.defineProperty(exports, "bifoldr", { enumerable: true, get: function () { return bifold_1.bifoldr; } });
|
|
21
|
-
Object.defineProperty(exports, "bifold", { enumerable: true, get: function () { return bifold_1.default; } });
|
|
22
|
-
__exportStar(require("./guards"), exports);
|
|
23
|
-
var bindr_1 = require("./bindr");
|
|
24
|
-
Object.defineProperty(exports, "bindr", { enumerable: true, get: function () { return bindr_1.default; } });
|
|
25
|
-
var bifold_map_1 = require("./bifold-map");
|
|
26
|
-
Object.defineProperty(exports, "bifoldMap", { enumerable: true, get: function () { return bifold_map_1.default; } });
|
|
27
|
-
var bimap_1 = require("./bimap");
|
|
28
|
-
Object.defineProperty(exports, "bimap", { enumerable: true, get: function () { return bimap_1.default; } });
|
|
29
|
-
Object.defineProperty(exports, "first", { enumerable: true, get: function () { return bimap_1.first; } });
|
|
30
|
-
Object.defineProperty(exports, "second", { enumerable: true, get: function () { return bimap_1.second; } });
|
|
1
|
+
export { bifoldl, bifoldr, default as bifold, } from './bifold/index.js';
|
|
2
|
+
export * from './guards.js';
|
|
3
|
+
export { default as bindr } from './bindr.js';
|
|
4
|
+
export { default as bifoldMap } from './bifold-map/index.js';
|
|
5
|
+
export { default as bimap, first, second } from './bimap/index.js';
|
package/either/right.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Either
|
|
4
3
|
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.rid = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Internal unique identifier for `Right`.
|
|
9
6
|
*/
|
|
10
|
-
|
|
7
|
+
export const rid = Symbol.for('@@functional/right');
|
|
11
8
|
/**
|
|
12
9
|
* Constructor function for `Right`.
|
|
13
10
|
* Creates the special object with one property, represented as unique symbol
|
|
14
11
|
* key, holding the provided value.
|
|
15
12
|
*/
|
|
16
|
-
function right(value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_a[exports.rid] = value,
|
|
13
|
+
export default function right(value) {
|
|
14
|
+
return {
|
|
15
|
+
[rid]: value,
|
|
20
16
|
// @ts-expect-error: Undocumented API for external use
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
17
|
+
toString() {
|
|
18
|
+
return `Right ${value}`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
25
21
|
}
|
|
26
|
-
exports.default = right;
|
package/guard.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @module Guard
|
|
3
3
|
*/
|
|
4
4
|
import type { VariadicFunction } from './types/function';
|
|
5
|
-
export type GuardQualifier<Function extends VariadicFunction> = [
|
|
6
|
-
validator:
|
|
5
|
+
export type GuardQualifier<Function extends VariadicFunction, Validator extends (...args: Parameters<Function>) => boolean> = [
|
|
6
|
+
validator: Validator,
|
|
7
7
|
executor: Function
|
|
8
8
|
];
|
|
9
9
|
/**
|
|
@@ -16,4 +16,4 @@ export type GuardQualifier<Function extends VariadicFunction> = [
|
|
|
16
16
|
*
|
|
17
17
|
* When no `validator` succeeds, the default executor is run.
|
|
18
18
|
*/
|
|
19
|
-
export default function guard<Function extends VariadicFunction>(...qualifiers: [...GuardQualifier<Function>[], Function]): Function;
|
|
19
|
+
export default function guard<Function extends VariadicFunction, Validators extends Array<(...args: Parameters<Function>) => boolean>>(...qualifiers: [...GuardQualifier<Function, Validators[number]>[], Function]): Function;
|
package/guard.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Guard
|
|
4
3
|
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
4
|
/**
|
|
7
5
|
* A function which accepts the pairs of guards:
|
|
8
6
|
* the first one is the `validator`, expected to return a boolean value.
|
|
@@ -13,24 +11,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
11
|
*
|
|
14
12
|
* When no `validator` succeeds, the default executor is run.
|
|
15
13
|
*/
|
|
16
|
-
function guard() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
24
|
-
args[_i] = arguments[_i];
|
|
25
|
-
}
|
|
26
|
-
var length = qualifiers.length - 1;
|
|
27
|
-
for (var index = 0; index < length; index += 1) {
|
|
28
|
-
var _a = qualifiers[index], validator = _a[0], expression = _a[1];
|
|
29
|
-
if (validator.apply(void 0, args)) {
|
|
30
|
-
return expression.apply(void 0, args);
|
|
14
|
+
export default function guard(...qualifiers) {
|
|
15
|
+
return ((...args) => {
|
|
16
|
+
const length = qualifiers.length - 1;
|
|
17
|
+
for (let index = 0; index < length; index += 1) {
|
|
18
|
+
const [validator, expression] = qualifiers[index];
|
|
19
|
+
if (validator(...args)) {
|
|
20
|
+
return expression(...args);
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
|
-
return qualifiers[length]
|
|
23
|
+
return qualifiers[length](...args);
|
|
34
24
|
});
|
|
35
25
|
}
|
|
36
|
-
exports.default = guard;
|
package/identity.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Identity
|
|
4
3
|
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
4
|
/**
|
|
7
5
|
* A function which returns the provided value.
|
|
8
6
|
*/
|
|
9
|
-
function identity(x) {
|
|
7
|
+
export default function identity(x) {
|
|
10
8
|
return x;
|
|
11
9
|
}
|
|
12
|
-
exports.default = identity;
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as
|
|
3
|
-
export { default as
|
|
4
|
-
export { default as
|
|
5
|
-
export { default as
|
|
6
|
-
export { default as
|
|
7
|
-
export { default as
|
|
8
|
-
export { default as
|
|
9
|
-
export { default as
|
|
10
|
-
export { default as rethrow } from './rethrow';
|
|
11
|
-
export { default as identity } from './identity';
|
|
1
|
+
export { default as tap } from './tap.js';
|
|
2
|
+
export { default as pipe } from './pipe.js';
|
|
3
|
+
export { default as apply } from './apply.js';
|
|
4
|
+
export { default as curry } from './curry.js';
|
|
5
|
+
export { default as guard } from './guard.js';
|
|
6
|
+
export { default as inject } from './inject.js';
|
|
7
|
+
export { default as compose } from './compose.js';
|
|
8
|
+
export { default as rethrow } from './rethrow.js';
|
|
9
|
+
export { default as identity } from './identity.js';
|
package/index.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var pipe_1 = require("./pipe");
|
|
11
|
-
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return pipe_1.default; } });
|
|
12
|
-
var apply_1 = require("./apply");
|
|
13
|
-
Object.defineProperty(exports, "apply", { enumerable: true, get: function () { return apply_1.default; } });
|
|
14
|
-
var curry_1 = require("./curry");
|
|
15
|
-
Object.defineProperty(exports, "curry", { enumerable: true, get: function () { return curry_1.default; } });
|
|
16
|
-
var guard_1 = require("./guard");
|
|
17
|
-
Object.defineProperty(exports, "guard", { enumerable: true, get: function () { return guard_1.default; } });
|
|
18
|
-
var inject_1 = require("./inject");
|
|
19
|
-
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.default; } });
|
|
20
|
-
var compose_1 = require("./compose");
|
|
21
|
-
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.default; } });
|
|
22
|
-
var rethrow_1 = require("./rethrow");
|
|
23
|
-
Object.defineProperty(exports, "rethrow", { enumerable: true, get: function () { return rethrow_1.default; } });
|
|
24
|
-
var identity_1 = require("./identity");
|
|
25
|
-
Object.defineProperty(exports, "identity", { enumerable: true, get: function () { return identity_1.default; } });
|
|
1
|
+
export { default as tap } from './tap.js';
|
|
2
|
+
export { default as pipe } from './pipe.js';
|
|
3
|
+
export { default as apply } from './apply.js';
|
|
4
|
+
export { default as curry } from './curry.js';
|
|
5
|
+
export { default as guard } from './guard.js';
|
|
6
|
+
export { default as inject } from './inject.js';
|
|
7
|
+
export { default as compose } from './compose.js';
|
|
8
|
+
export { default as rethrow } from './rethrow.js';
|
|
9
|
+
export { default as identity } from './identity.js';
|
package/inject.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module Side Effects
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return (0, permutation_2_1.default)(function (fn, effect) {
|
|
13
|
-
return (function () {
|
|
14
|
-
var args = [];
|
|
15
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
|
-
args[_i] = arguments[_i];
|
|
17
|
-
}
|
|
18
|
-
effect.apply(void 0, args);
|
|
19
|
-
return fn.apply(void 0, args);
|
|
4
|
+
import permutation2 from './permutation/permutation-2.js';
|
|
5
|
+
export default function inject(...args) {
|
|
6
|
+
return permutation2((fn, effect) => {
|
|
7
|
+
return ((...args) => {
|
|
8
|
+
effect(...args);
|
|
9
|
+
return fn(...args);
|
|
20
10
|
});
|
|
21
|
-
})
|
|
11
|
+
})(...args);
|
|
22
12
|
}
|
|
23
|
-
exports.default = inject;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module
|
|
2
|
+
* @module Lens
|
|
3
3
|
*/
|
|
4
|
-
import type { Flatten, Flattenable } from '
|
|
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 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
|
|
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 Index extends number}.${infer Right}` ? Get<Exclude<Source[Index], undefined>, Right> | Extract<Source[Index], undefined> : Path extends `${infer Index extends number}` ? Source[Index] : never : never;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the value inside a nested `source` object by provided `path`
|
|
12
|
+
* written in dot-notation.
|
|
13
|
+
*/
|
|
14
|
+
export default function get<Source extends Flattenable>(source: Source): <Path extends Flatten<Source>>(path: Path) => Get<Source, Path>;
|
|
10
15
|
/**
|
|
11
16
|
* Gets the value inside a nested `source` object by provided `path`
|
|
12
17
|
* written in dot-notation.
|
package/lens/get.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Lens
|
|
3
|
+
*/
|
|
4
|
+
import permutation2 from '../permutation/permutation-2.js';
|
|
5
|
+
/**
|
|
6
|
+
* Gets the value inside a nested `source` object by provided `path`
|
|
7
|
+
* written in dot-notation.
|
|
8
|
+
*/
|
|
9
|
+
export default function get(...args) {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
return permutation2((sourceOrPath, pathOrSource) => {
|
|
12
|
+
let source, path;
|
|
13
|
+
if (typeof sourceOrPath === 'string') {
|
|
14
|
+
source = pathOrSource;
|
|
15
|
+
path = sourceOrPath;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
source = sourceOrPath;
|
|
19
|
+
path = pathOrSource;
|
|
20
|
+
}
|
|
21
|
+
const keys = path.split('.');
|
|
22
|
+
const length = keys.length;
|
|
23
|
+
let result = source;
|
|
24
|
+
for (let index = 0; index < length; index += 1) {
|
|
25
|
+
result = result?.[keys?.[index]];
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
})(...args);
|
|
29
|
+
}
|
package/lens/index.d.ts
ADDED
package/lens/index.js
ADDED
package/lens/lens.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Lens
|
|
3
|
+
*/
|
|
4
|
+
import type { Flatten, Flattenable } from '../types';
|
|
5
|
+
import { Get } from './get.js';
|
|
6
|
+
import { Set } from './set.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a wrapper for a given `Source` type that provides access to both `get` and `set` functionalities for it,
|
|
9
|
+
* effectively creating a functional lens.
|
|
10
|
+
*/
|
|
11
|
+
export interface Lens<Source extends Flattenable> {
|
|
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
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a wrapper for a given `source` that provides access to both `get` and `set` functionalities for it,
|
|
17
|
+
* effectively creating a functional lens.
|
|
18
|
+
*/
|
|
19
|
+
export default function lens<Source extends Flattenable>(source: Source): Lens<Source>;
|
package/lens/lens.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Lens
|
|
3
|
+
*/
|
|
4
|
+
import get from './get.js';
|
|
5
|
+
import set from './set.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a wrapper for a given `source` that provides access to both `get` and `set` functionalities for it,
|
|
8
|
+
* effectively creating a functional lens.
|
|
9
|
+
*/
|
|
10
|
+
export default function lens(source) {
|
|
11
|
+
const getter = get(source);
|
|
12
|
+
const setter = set(source);
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
return (...args) => {
|
|
15
|
+
return args.length === 1 ? getter(args[0]) : setter(args[0], args[1]);
|
|
16
|
+
};
|
|
17
|
+
}
|
package/lens/set.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Lens
|
|
3
|
+
*/
|
|
4
|
+
import type { Unshift } from '../types/unshift';
|
|
5
|
+
import type { Flatten, Flattenable } from '../types/flatten';
|
|
6
|
+
import type { Get } from './get.js';
|
|
7
|
+
/**
|
|
8
|
+
* Sets the `Value` type inside a nested object type `Source` by provided `Path`
|
|
9
|
+
* written in dot-notation.
|
|
10
|
+
*/
|
|
11
|
+
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}` ? {
|
|
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 ? {
|
|
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;
|
|
16
|
+
/**
|
|
17
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
18
|
+
* written in dot-notation.
|
|
19
|
+
*/
|
|
20
|
+
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
|
+
/**
|
|
22
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
23
|
+
* written in dot-notation.
|
|
24
|
+
*/
|
|
25
|
+
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
|
+
/**
|
|
27
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
28
|
+
* written in dot-notation.
|
|
29
|
+
*/
|
|
30
|
+
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
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Lens
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sets the `value` inside a nested `source` object by provided `path`
|
|
6
|
+
* written in dot-notation.
|
|
7
|
+
*/
|
|
8
|
+
export default function set(...args) {
|
|
9
|
+
switch (args.length) {
|
|
10
|
+
case 1: {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
return (path, value) => _set(args[0], path, value);
|
|
13
|
+
}
|
|
14
|
+
case 2: {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return (source) => _set(source, args[1], args[2]);
|
|
17
|
+
}
|
|
18
|
+
case 3: {
|
|
19
|
+
return _set;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _set(source, path, value
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
) {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
const keys = path.split('.');
|
|
28
|
+
const length = keys.length;
|
|
29
|
+
let result = structuredClone(source);
|
|
30
|
+
if (length === 0) {
|
|
31
|
+
result[path] = value;
|
|
32
|
+
}
|
|
33
|
+
let scope = result[keys[0]];
|
|
34
|
+
for (let index = 1; index < length; index += 1) {
|
|
35
|
+
if (index === length - 1) {
|
|
36
|
+
scope[keys?.[index]] = value;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
scope = scope?.[keys?.[index]];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
return result;
|
|
44
|
+
}
|