fnts 2.1.1 → 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.
Files changed (95) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/apply.js +6 -17
  4. package/compose.js +3 -16
  5. package/curry.js +6 -20
  6. package/either/either-sync.d.ts +1 -1
  7. package/either/either-sync.js +5 -8
  8. package/either/either.d.ts +2 -2
  9. package/either/either.js +5 -8
  10. package/either/index.d.ts +4 -4
  11. package/either/index.js +4 -11
  12. package/either/left.js +8 -13
  13. package/either/operators/bifold/bifold.d.ts +3 -3
  14. package/either/operators/bifold/bifold.js +7 -10
  15. package/either/operators/bifold/bifoldl.d.ts +2 -2
  16. package/either/operators/bifold/bifoldl.js +5 -8
  17. package/either/operators/bifold/bifoldr.d.ts +2 -2
  18. package/either/operators/bifold/bifoldr.js +5 -8
  19. package/either/operators/bifold/index.d.ts +3 -3
  20. package/either/operators/bifold/index.js +3 -9
  21. package/either/operators/bifold-map/bifold-map.d.ts +1 -1
  22. package/either/operators/bifold-map/bifold-map.js +16 -23
  23. package/either/operators/bifold-map/bifoldl-map.d.ts +3 -3
  24. package/either/operators/bifold-map/bifoldl-map.js +9 -16
  25. package/either/operators/bifold-map/bifoldr-map.d.ts +3 -3
  26. package/either/operators/bifold-map/bifoldr-map.js +9 -16
  27. package/either/operators/bifold-map/index.d.ts +3 -3
  28. package/either/operators/bifold-map/index.js +3 -9
  29. package/either/operators/bimap/bimap.d.ts +1 -1
  30. package/either/operators/bimap/bimap.js +10 -17
  31. package/either/operators/bimap/first.d.ts +2 -2
  32. package/either/operators/bimap/first.js +12 -19
  33. package/either/operators/bimap/index.d.ts +3 -3
  34. package/either/operators/bimap/index.js +3 -9
  35. package/either/operators/bimap/second.d.ts +2 -2
  36. package/either/operators/bimap/second.js +12 -19
  37. package/either/operators/bindr.d.ts +1 -1
  38. package/either/operators/bindr.js +11 -18
  39. package/either/operators/guards.d.ts +3 -3
  40. package/either/operators/guards.js +7 -13
  41. package/either/operators/index.d.ts +5 -5
  42. package/either/operators/index.js +5 -30
  43. package/either/right.js +8 -13
  44. package/guard.d.ts +3 -3
  45. package/guard.js +8 -19
  46. package/identity.js +1 -4
  47. package/index.d.ts +9 -10
  48. package/index.js +9 -23
  49. package/inject.js +7 -18
  50. package/lens/get.d.ts +24 -0
  51. package/lens/get.js +29 -0
  52. package/lens/index.d.ts +3 -0
  53. package/lens/index.js +3 -0
  54. package/lens/lens.d.ts +19 -0
  55. package/lens/lens.js +17 -0
  56. package/lens/set.d.ts +30 -0
  57. package/lens/set.js +44 -0
  58. package/maybe/index.d.ts +3 -3
  59. package/maybe/index.js +3 -9
  60. package/maybe/just.js +8 -13
  61. package/maybe/maybe.d.ts +2 -2
  62. package/maybe/maybe.js +5 -8
  63. package/maybe/nothing.js +7 -12
  64. package/maybe/operators/bind.d.ts +1 -1
  65. package/maybe/operators/bind.js +11 -18
  66. package/maybe/operators/fmap.d.ts +1 -1
  67. package/maybe/operators/fmap.js +12 -19
  68. package/maybe/operators/fold-map.d.ts +3 -3
  69. package/maybe/operators/fold-map.js +9 -16
  70. package/maybe/operators/fold.d.ts +3 -3
  71. package/maybe/operators/fold.js +7 -10
  72. package/maybe/operators/guards.d.ts +3 -3
  73. package/maybe/operators/guards.js +7 -13
  74. package/maybe/operators/index.d.ts +5 -5
  75. package/maybe/operators/index.js +5 -26
  76. package/package.json +11 -4
  77. package/permutation/index.d.ts +2 -2
  78. package/permutation/index.js +2 -7
  79. package/permutation/permutation-2.js +5 -12
  80. package/permutation/permutation-3.d.ts +1 -1
  81. package/permutation/permutation-3.js +5 -12
  82. package/pipe.js +4 -16
  83. package/rethrow.js +3 -6
  84. package/set.d.ts +24 -0
  85. package/set.js +35 -0
  86. package/tap.d.ts +1 -1
  87. package/tap.js +4 -7
  88. package/tsconfig.json +3 -3
  89. package/types/flatten.d.ts +34 -0
  90. package/types/index.d.ts +10 -7
  91. package/types/slice.d.ts +1 -1
  92. package/types/trim.d.ts +19 -0
  93. package/types/unshift.d.ts +16 -0
  94. package/get.d.ts +0 -25
  95. package/get.js +0 -26
package/maybe/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { default, Maybe } from './maybe';
2
- export { default as just, Just } from './just';
3
- export { default as nothing, Nothing } from './nothing';
1
+ export { default, Maybe } from './maybe.js';
2
+ export { default as just, Just } from './just.js';
3
+ export { default as nothing, Nothing } from './nothing.js';
package/maybe/index.js CHANGED
@@ -1,9 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nothing = exports.just = exports.default = void 0;
4
- var maybe_1 = require("./maybe");
5
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return maybe_1.default; } });
6
- var just_1 = require("./just");
7
- Object.defineProperty(exports, "just", { enumerable: true, get: function () { return just_1.default; } });
8
- var nothing_1 = require("./nothing");
9
- Object.defineProperty(exports, "nothing", { enumerable: true, get: function () { return nothing_1.default; } });
1
+ export { default } from './maybe.js';
2
+ export { default as just } from './just.js';
3
+ export { default as nothing } from './nothing.js';
package/maybe/just.js CHANGED
@@ -1,26 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jid = void 0;
4
1
  /**
5
2
  * @module Maybe
6
3
  */
7
4
  /**
8
5
  * Internal unique identifier for `Just`.
9
6
  */
10
- exports.jid = Symbol.for('@@functional/just');
7
+ export const jid = Symbol.for('@@functional/just');
11
8
  /**
12
9
  * Constructor function for `Just`.
13
10
  * Creates the special object with one property, represented as unique symbol
14
11
  * key, holding the provided value.
15
12
  */
16
- function just(value) {
17
- var _a;
18
- return _a = {},
19
- _a[exports.jid] = value,
13
+ export default function just(value) {
14
+ return {
15
+ [jid]: value,
20
16
  // @ts-expect-error: Undocumented API for external use
21
- _a.toString = function () {
22
- return "Just ".concat(value);
23
- },
24
- _a;
17
+ toString() {
18
+ return `Just ${value}`;
19
+ }
20
+ };
25
21
  }
26
- exports.default = just;
package/maybe/maybe.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @module Maybe
3
3
  */
4
- import { Just } from './just';
5
- import { Nothing } from './nothing';
4
+ import { Just } from './just.js';
5
+ import { Nothing } from './nothing.js';
6
6
  /**
7
7
  * Type constructor for `Maybe`.
8
8
  * Can be either `Just` of a provided value type, or `Nothing`.
package/maybe/maybe.js CHANGED
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var just_1 = require("./just");
7
- var nothing_1 = require("./nothing");
4
+ import just from './just.js';
5
+ import nothing from './nothing.js';
8
6
  /**
9
7
  * Constructor function for `Maybe`.
10
8
  * Creates either `just` of a provided value, or `nothing`.
11
9
  */
12
- function maybe(value) {
10
+ export default function maybe(value) {
13
11
  return value === null || value === undefined
14
- ? (0, nothing_1.default)()
15
- : (0, just_1.default)(value);
12
+ ? nothing()
13
+ : just(value);
16
14
  }
17
- exports.default = maybe;
package/maybe/nothing.js CHANGED
@@ -1,26 +1,21 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.nid = void 0;
7
4
  /**
8
5
  * Internal unique identifier for `Nothing`.
9
6
  */
10
- exports.nid = Symbol.for('@@functional/nothing');
7
+ export const nid = Symbol.for('@@functional/nothing');
11
8
  /**
12
9
  * Constructor function for `Nothing`.
13
10
  * Creates the special object with one property, represented as unique symbol
14
11
  * key, holding the `null` value.
15
12
  */
16
- function nothing() {
17
- var _a;
18
- return _a = {},
19
- _a[exports.nid] = undefined,
13
+ export default function nothing() {
14
+ return {
15
+ [nid]: undefined,
20
16
  // @ts-expect-error: Undocumented API for external use
21
- _a.toString = function () {
17
+ toString() {
22
18
  return 'Nothing';
23
- },
24
- _a;
19
+ }
20
+ };
25
21
  }
26
- exports.default = nothing;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Maybe Operators
3
3
  */
4
- import type { Maybe } from '../maybe';
4
+ import type { Maybe } from '../maybe.js';
5
5
  import type { Map } from '../../types/map';
6
6
  /**
7
7
  * Binds the value of the `monad` to new monad created
@@ -1,22 +1,15 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe Operators
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var compose_1 = require("../../compose");
7
- var identity_1 = require("../../identity");
8
- var permutation_2_1 = require("../../permutation/permutation-2");
9
- var fold_1 = require("./fold");
10
- var guards_1 = require("./guards");
11
- function bind() {
12
- var args = [];
13
- for (var _i = 0; _i < arguments.length; _i++) {
14
- args[_i] = arguments[_i];
15
- }
16
- return (0, permutation_2_1.default)(function (monad, map) {
17
- return (0, guards_1.isJust)(monad)
18
- ? (0, compose_1.default)(map, fold_1.default, 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 fold from './fold.js';
8
+ import { isJust } from './guards.js';
9
+ export default function bind(...args) {
10
+ return permutation2((monad, map) => {
11
+ return isJust(monad)
12
+ ? compose(map, fold, monad)
13
+ : identity(monad);
14
+ })(...args);
21
15
  }
22
- exports.default = bind;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module Maybe Operators
3
3
  */
4
- import { Maybe } from '../maybe';
4
+ import { Maybe } from '../maybe.js';
5
5
  import type { Map } from '../../types/map';
6
6
  /**
7
7
  * Maps the value of the provided `monad` through the `transition` function
@@ -1,23 +1,16 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe Operators
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var compose_1 = require("../../compose");
7
- var identity_1 = require("../../identity");
8
- var maybe_1 = require("../maybe");
9
- var permutation_2_1 = require("../../permutation/permutation-2");
10
- var fold_map_1 = require("./fold-map");
11
- var guards_1 = require("./guards");
12
- function fmap() {
13
- var args = [];
14
- for (var _i = 0; _i < arguments.length; _i++) {
15
- args[_i] = arguments[_i];
16
- }
17
- return (0, permutation_2_1.default)(function (monad, map) {
18
- return (0, guards_1.isJust)(monad)
19
- ? (0, compose_1.default)((maybe_1.default), (0, fold_map_1.default)(map), monad)
20
- : (0, identity_1.default)(monad);
21
- }).apply(void 0, args);
4
+ import compose from '../../compose.js';
5
+ import identity from '../../identity.js';
6
+ import maybe from '../maybe.js';
7
+ import permutation2 from '../../permutation/permutation-2.js';
8
+ import foldMap from './fold-map.js';
9
+ import { isJust } from './guards.js';
10
+ export default function fmap(...args) {
11
+ return permutation2((monad, map) => {
12
+ return isJust(monad)
13
+ ? compose((maybe), foldMap(map), monad)
14
+ : identity(monad);
15
+ })(...args);
22
16
  }
23
- exports.default = fmap;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @module Maybe Operators
3
3
  */
4
- import type { Just } from '../just';
5
- import type { Maybe } from '../maybe';
6
- import type { Nothing } from '../nothing';
4
+ import type { Just } from '../just.js';
5
+ import type { Maybe } from '../maybe.js';
6
+ import type { Nothing } from '../nothing.js';
7
7
  import type { Map } from '../../types/map';
8
8
  /**
9
9
  * A type to unwrap the provided `Monad` into the new value type.
@@ -1,21 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe Operators
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var compose_1 = require("../../compose");
7
- var permutation_2_1 = require("../../permutation/permutation-2");
8
- var fold_1 = require("./fold");
9
- var guards_1 = require("./guards");
10
- function foldMap() {
11
- var args = [];
12
- for (var _i = 0; _i < arguments.length; _i++) {
13
- args[_i] = arguments[_i];
14
- }
15
- return (0, permutation_2_1.default)(function (monad, map) {
16
- return (0, guards_1.isJust)(monad)
17
- ? (0, compose_1.default)(map, fold_1.default, monad)
4
+ import compose from '../../compose.js';
5
+ import permutation2 from '../../permutation/permutation-2.js';
6
+ import fold from './fold.js';
7
+ import { isJust } from './guards.js';
8
+ export default function foldMap(...args) {
9
+ return permutation2((monad, map) => {
10
+ return isJust(monad)
11
+ ? compose(map, fold, monad)
18
12
  : undefined;
19
- }).apply(void 0, args);
13
+ })(...args);
20
14
  }
21
- exports.default = foldMap;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @module Maybe Operators
3
3
  */
4
- import { Just } from '../just';
5
- import type { Maybe } from '../maybe';
6
- import { Nothing } from '../nothing';
4
+ import { Just } from '../just.js';
5
+ import type { Maybe } from '../maybe.js';
6
+ import { Nothing } from '../nothing.js';
7
7
  /**
8
8
  * A type to unwrap the value type of the provided `Monad`.
9
9
  */
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe Operators
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var just_1 = require("../just");
7
- var nothing_1 = require("../nothing");
8
- var guards_1 = require("./guards");
4
+ import { jid } from '../just.js';
5
+ import { nid } from '../nothing.js';
6
+ import { isJust } from './guards.js';
9
7
  /**
10
8
  * Returns the value of the provided `monad`.
11
9
  */
12
- function fold(monad) {
13
- return (0, guards_1.isJust)(monad)
14
- ? monad[just_1.jid]
15
- : monad[nothing_1.nid];
10
+ export default function fold(monad) {
11
+ return isJust(monad)
12
+ ? monad[jid]
13
+ : monad[nid];
16
14
  }
17
- exports.default = fold;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @module Maybe Operators
3
3
  */
4
- import { Just } from '../just';
5
- import type { Maybe } from '../maybe';
6
- import { Nothing } from '../nothing';
4
+ import { Just } from '../just.js';
5
+ import type { Maybe } from '../maybe.js';
6
+ import { Nothing } from '../nothing.js';
7
7
  /**
8
8
  * Type guard function to tell if the provided `value` is `Just`.
9
9
  */
@@ -1,29 +1,23 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Maybe Operators
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isMaybe = exports.isNothing = exports.isJust = void 0;
7
- var just_1 = require("../just");
8
- var nothing_1 = require("../nothing");
4
+ import { jid } from '../just.js';
5
+ import { nid } from '../nothing.js';
9
6
  /**
10
7
  * Type guard function to tell if the provided `value` is `Just`.
11
8
  */
12
- function isJust(value) {
13
- return Object.prototype.hasOwnProperty.call(value, just_1.jid);
9
+ export function isJust(value) {
10
+ return Object.prototype.hasOwnProperty.call(value, jid);
14
11
  }
15
- exports.isJust = isJust;
16
12
  /**
17
13
  * Type guard function to tell if the provided `value` is `Nothing`.
18
14
  */
19
- function isNothing(value) {
20
- return Object.prototype.hasOwnProperty.call(value, nothing_1.nid);
15
+ export function isNothing(value) {
16
+ return Object.prototype.hasOwnProperty.call(value, nid);
21
17
  }
22
- exports.isNothing = isNothing;
23
18
  /**
24
19
  * Type guard function to tell if the provided `value` is `Maybe`.
25
20
  */
26
- function isMaybe(value) {
21
+ export function isMaybe(value) {
27
22
  return isJust(value) || isNothing(value);
28
23
  }
29
- exports.isMaybe = isMaybe;
@@ -1,5 +1,5 @@
1
- export * from './guards';
2
- export { default as fmap } from './fmap';
3
- export { default as bind } from './bind';
4
- export { default as fold } from './fold';
5
- export { default as foldMap, FoldMap } from './fold-map';
1
+ export * from './guards.js';
2
+ export { default as fmap } from './fmap.js';
3
+ export { default as bind } from './bind.js';
4
+ export { default as fold } from './fold.js';
5
+ export { default as foldMap, FoldMap } from './fold-map.js';
@@ -1,26 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
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.foldMap = exports.fold = exports.bind = exports.fmap = void 0;
18
- __exportStar(require("./guards"), exports);
19
- var fmap_1 = require("./fmap");
20
- Object.defineProperty(exports, "fmap", { enumerable: true, get: function () { return fmap_1.default; } });
21
- var bind_1 = require("./bind");
22
- Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bind_1.default; } });
23
- var fold_1 = require("./fold");
24
- Object.defineProperty(exports, "fold", { enumerable: true, get: function () { return fold_1.default; } });
25
- var fold_map_1 = require("./fold-map");
26
- Object.defineProperty(exports, "foldMap", { enumerable: true, get: function () { return fold_map_1.default; } });
1
+ export * from './guards.js';
2
+ export { default as fmap } from './fmap.js';
3
+ export { default as bind } from './bind.js';
4
+ export { default as fold } from './fold.js';
5
+ export { default as foldMap } from './fold-map.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
@@ -14,13 +14,20 @@
14
14
  ],
15
15
  "homepage": "https://drizzer14.github.io/fnts",
16
16
  "repository": "https://github.com/drizzer14/fnts",
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
+ },
17
25
  "peerDependencies": {
18
- "typescript": ">=4.7"
26
+ "typescript": ">=5.0"
19
27
  },
20
28
  "peerDependenciesMeta": {
21
29
  "typescript": {
22
30
  "optional": true
23
31
  }
24
- },
25
- "main": "index.js"
32
+ }
26
33
  }
@@ -1,2 +1,2 @@
1
- export { default as permutation2 } from './permutation-2';
2
- export { default as permutation3 } from './permutation-3';
1
+ export { default as permutation2 } from './permutation-2.js';
2
+ export { default as permutation3 } from './permutation-3.js';
@@ -1,7 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.permutation3 = exports.permutation2 = void 0;
4
- var permutation_2_1 = require("./permutation-2");
5
- Object.defineProperty(exports, "permutation2", { enumerable: true, get: function () { return permutation_2_1.default; } });
6
- var permutation_3_1 = require("./permutation-3");
7
- Object.defineProperty(exports, "permutation3", { enumerable: true, get: function () { return permutation_3_1.default; } });
1
+ export { default as permutation2 } from './permutation-2.js';
2
+ export { default as permutation3 } from './permutation-3.js';
@@ -1,18 +1,11 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Permutation
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- function permutation2(fn, shouldCurry) {
7
- return function () {
8
- var args = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- args[_i] = arguments[_i];
11
- }
12
- var a1 = args[0], b = args[1];
13
- return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b)) || args.length < fn.length
14
- ? function (a2) { return fn(a2, a1); }
4
+ export default function permutation2(fn, shouldCurry) {
5
+ return (...args) => {
6
+ const [a1, b] = args;
7
+ return shouldCurry?.(a1, b) || args.length < fn.length
8
+ ? (a2) => fn(a2, a1)
15
9
  : fn(a1, b);
16
10
  };
17
11
  }
18
- exports.default = permutation2;
@@ -2,7 +2,7 @@
2
2
  * @module Permutation
3
3
  */
4
4
  import type { VariadicFunction } from './../types/function';
5
- import type { FirstParameter, SecondParameter } from './permutation-2';
5
+ import type { FirstParameter, SecondParameter } from './permutation-2.js';
6
6
  export type TernaryFunction = (a: any, b: any, c: any) => any;
7
7
  export type ThirdParameter<Function extends VariadicFunction> = Parameters<Function>[2];
8
8
  export default function permutation3<Function extends TernaryFunction>(fn: Function, shouldCurry?: (a: FirstParameter<Function> | SecondParameter<Function>, b: SecondParameter<Function> | ThirdParameter<Function>, c: ThirdParameter<Function> | undefined) => boolean): VariadicFunction;
@@ -1,18 +1,11 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Permutation
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- function permutation3(fn, shouldCurry) {
7
- return function () {
8
- var args = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- args[_i] = arguments[_i];
11
- }
12
- var a1 = args[0], b = args[1], c = args[2];
13
- return (shouldCurry === null || shouldCurry === void 0 ? void 0 : shouldCurry(a1, b, c)) || args.length < fn.length
14
- ? function (a2) { return fn(a2, a1, b); }
4
+ export default function permutation3(fn, shouldCurry) {
5
+ return (...args) => {
6
+ const [a1, b, c] = args;
7
+ return shouldCurry?.(a1, b, c) || args.length < fn.length
8
+ ? (a2) => fn(a2, a1, b)
15
9
  : fn(a1, b, c);
16
10
  };
17
11
  }
18
- exports.default = permutation3;
package/pipe.js CHANGED
@@ -1,24 +1,12 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Composition
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
4
  /**
7
5
  * (A -> B) . (B -> C) = A -> C
8
6
  */
9
- function pipe() {
10
- var maybeArgs = [];
11
- for (var _i = 0; _i < arguments.length; _i++) {
12
- maybeArgs[_i] = arguments[_i];
13
- }
7
+ export default function pipe(...maybeArgs) {
14
8
  return maybeArgs.length === 2
15
- ? function () {
16
- var args = [];
17
- for (var _i = 0; _i < arguments.length; _i++) {
18
- args[_i] = arguments[_i];
19
- }
20
- return maybeArgs[1](maybeArgs[0].apply(maybeArgs, args));
21
- }
22
- : maybeArgs[maybeArgs.length - 1](maybeArgs[maybeArgs.length - 2].apply(maybeArgs, maybeArgs.slice(0, -2)));
9
+ // @ts-ignore
10
+ ? (...args) => maybeArgs[1](maybeArgs[0](...args))
11
+ : maybeArgs[maybeArgs.length - 1](maybeArgs[maybeArgs.length - 2](...maybeArgs.slice(0, -2)));
23
12
  }
24
- exports.default = pipe;
package/rethrow.js CHANGED
@@ -1,16 +1,13 @@
1
- "use strict";
2
1
  /**
3
2
  * @module Side Effects
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
4
  /**
7
5
  * Rethrows a received error
8
6
  * performing an optional side effect.
9
7
  */
10
- function rethrow(effect) {
11
- return function (error) {
12
- effect === null || effect === void 0 ? void 0 : effect(error);
8
+ export default function rethrow(effect) {
9
+ return (error) => {
10
+ effect?.(error);
13
11
  throw error;
14
12
  };
15
13
  }
16
- exports.default = rethrow;
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,35 @@
1
+ /**
2
+ * @module Set
3
+ */
4
+ import permutation3 from './permutation/permutation-3.js';
5
+ /**
6
+ * Sets the `value` inside a nested `source` object by provided `path`
7
+ * written in dot-notation.
8
+ */
9
+ export default function set(...args) {
10
+ // @ts-ignore
11
+ return permutation3(
12
+ // @ts-ignore
13
+ (source, path, value
14
+ // @ts-ignore
15
+ ) => {
16
+ // @ts-ignore
17
+ const keys = path.split('.');
18
+ const length = keys.length;
19
+ let result = structuredClone(source);
20
+ if (length === 0) {
21
+ result[path] = value;
22
+ }
23
+ let scope = result[keys[0]];
24
+ for (let index = 1; index < length; index += 1) {
25
+ if (index === length - 1) {
26
+ scope[keys?.[index]] = value;
27
+ }
28
+ else {
29
+ scope = scope?.[keys?.[index]];
30
+ }
31
+ }
32
+ // @ts-ignore
33
+ return result;
34
+ })(...args);
35
+ }
package/tap.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @module Side Effects
3
3
  */
4
4
  import type { Map } from './types/map';
5
- import type { Identity } from './identity';
5
+ import type { Identity } from './identity.js';
6
6
  import type { Effect } from './types/effect';
7
7
  /**
8
8
  * Performs a side effect