fnts 2.0.0 → 2.1.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/README.md CHANGED
@@ -21,7 +21,7 @@ TypeScript / JavaScript functional programming utilities inspired by the
21
21
 
22
22
  ## Installation
23
23
 
24
- **TypeScript 4.2.2 is required for this package's typings to work properly.**
24
+ **TypeScript 4.7 is required for this package's typings to work properly.**
25
25
 
26
26
  ```shell
27
27
  npm i fnts
package/apply.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module Application
3
+ */
4
+ import type { VariadicFunction } from './types/function';
5
+ /**
6
+ * `ReturnType` utility for multiple functions.
7
+ */
8
+ export type ReturnTypes<Functions extends VariadicFunction[], Returns extends any[] = []> = Functions['length'] extends 0 ? Returns : Functions extends [infer Function extends VariadicFunction, ...infer Rest extends VariadicFunction[]] ? ReturnTypes<Rest, [...Returns, ReturnType<Function>]> : never;
9
+ /**
10
+ * Applies all functions on curried arguments and returns an array of results.
11
+ */
12
+ export default function apply<Functions extends VariadicFunction[]>(...functions: Functions): (...args: Parameters<Functions[0]>) => ReturnTypes<Functions>;
package/apply.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /**
3
+ * @module Application
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * Applies all functions on curried arguments and returns an array of results.
8
+ */
9
+ function apply() {
10
+ var functions = [];
11
+ for (var _i = 0; _i < arguments.length; _i++) {
12
+ functions[_i] = arguments[_i];
13
+ }
14
+ return function () {
15
+ var args = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ args[_i] = arguments[_i];
18
+ }
19
+ var length = functions.length;
20
+ var result = new Array(length);
21
+ for (var index = 0; index < length; index += 1) {
22
+ result[index] = functions[index].apply(functions, args);
23
+ }
24
+ return result;
25
+ };
26
+ }
27
+ exports.default = apply;
package/get.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * combined through dot-notation.
7
7
  */
8
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 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;
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
10
  });
11
11
  /**
12
12
  * Gets the value type inside a nested object type `Source` by provided `Path`
package/get.js CHANGED
@@ -18,7 +18,7 @@ function get() {
18
18
  var length = keys.length;
19
19
  var result = source;
20
20
  for (var index = 0; index < length; index += 1) {
21
- result = result[keys[index]];
21
+ result = result === null || result === void 0 ? void 0 : result[keys === null || keys === void 0 ? void 0 : keys[index]];
22
22
  }
23
23
  return result;
24
24
  }).apply(void 0, args);
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as get } from './get';
2
2
  export { default as tap } from './tap';
3
3
  export { default as pipe } from './pipe';
4
+ export { default as apply } from './apply';
4
5
  export { default as curry } from './curry';
5
6
  export { default as match } from './guard';
6
7
  export { default as inject } from './inject';
package/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identity = exports.rethrow = exports.compose = exports.inject = exports.match = exports.curry = exports.pipe = exports.tap = exports.get = void 0;
3
+ exports.identity = exports.rethrow = exports.compose = exports.inject = exports.match = exports.curry = exports.apply = exports.pipe = exports.tap = 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
6
  var tap_1 = require("./tap");
7
7
  Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return tap_1.default; } });
8
8
  var pipe_1 = require("./pipe");
9
9
  Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return pipe_1.default; } });
10
+ var apply_1 = require("./apply");
11
+ Object.defineProperty(exports, "apply", { enumerable: true, get: function () { return apply_1.default; } });
10
12
  var curry_1 = require("./curry");
11
13
  Object.defineProperty(exports, "curry", { enumerable: true, get: function () { return curry_1.default; } });
12
14
  var guard_1 = require("./guard");
@@ -7,9 +7,9 @@ import type { Map } from '../../types/map';
7
7
  * Maps the value of the provided `monad` through the `transition` function
8
8
  * and returns a new `Maybe` of the mapped value.
9
9
  */
10
- export default function fmap<Value, NextValue>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NextValue>;
10
+ export default function fmap<Value, NextValue>(map: Map<Value, NextValue>): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>;
11
11
  /**
12
12
  * Maps the value of the provided `monad` through the `transition` function
13
13
  * and returns a new `Maybe` of the mapped value.
14
14
  */
15
- export default function fmap<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NextValue>;
15
+ export default function fmap<Value, NextValue>(monad: Maybe<Value>, map: Map<Value, NextValue>): Maybe<NonNullable<NextValue>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Dmytro Vasylkivskyi",
6
6
  "description": "TypeScript / JavaScript FP utilities",
package/pipe.d.ts CHANGED
@@ -13,12 +13,12 @@ export type Depipe<Functions extends UnaryFunction[], Arguments extends any[] =
13
13
  /**
14
14
  * (A -> B) . (B -> C) = A -> C
15
15
  */
16
- export default function pipe<A extends any[], B, C>(first: (...args: A) => B, second: (arg: B) => C): (...args: A) => C;
16
+ export default function pipe<A extends any[], B, C>(f: (...args: A) => B, g: (arg: B) => C): (...args: A) => C;
17
17
  /**
18
18
  * (A -> B) . (B -> C) = A -> C
19
19
  */
20
20
  export default function pipe<A extends any[], B, C>(...args: [
21
21
  ...args: A,
22
- first: (...args: A) => B,
23
- second: (arg: B) => C
22
+ f: (...args: A) => B,
23
+ g: (arg: B) => C
24
24
  ]): C;