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 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://travis-ci.com/github/drizzer14/fnts">
11
- <img src="https://img.shields.io/travis/com/drizzer14/fnts" />
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
@@ -1,3 +1,4 @@
1
+ export * from './operators/index.js';
1
2
  export { default, Either } from './either.js';
2
3
  export { default as left, Left } from './left.js';
3
4
  export { default as right, Right } from './right.js';
package/either/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './operators/index.js';
1
2
  export { default } from './either.js';
2
3
  export { default as left } from './left.js';
3
4
  export { default as right } from './right.js';
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 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;
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>>(path: Path) => Get<Source, Path>;
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>>(path: Path): (source: Source) => Get<Source, Path>;
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>>(source: Source, path: Path): Get<Source, Path>;
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>>(path: Path): Get<Source, Path>;
13
- <Path extends Flatten<Source>, Value extends Get<Source, Path>>(path: Path, value: Value): Set<Source, Path, Value>;
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
@@ -12,6 +12,7 @@ export default function lens(source) {
12
12
  const setter = set(source);
13
13
  // @ts-ignore
14
14
  return (...args) => {
15
+ // @ts-ignore
15
16
  return args.length === 1 ? getter(args[0]) : setter(args[0], args[1]);
16
17
  };
17
18
  }
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 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
+ 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>, Value extends Get<Source, Path>>(path: Path, value: Value) => Set<Source, Path, Value>;
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>, Value extends Get<Source, Path>>(path: Path, value: Value): (source: Source) => Set<Source, Path, Value>;
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>, Value extends Get<Source, Path>>(source: Source, path: Path, value: Value): Set<Source, Path, Value>;
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
@@ -1,3 +1,4 @@
1
+ export * from './operators/index.js';
1
2
  export { default, Maybe } from './maybe.js';
2
3
  export { default as just, Just } from './just.js';
3
4
  export { default as nothing, Nothing } from './nothing.js';
package/maybe/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './operators/index.js';
1
2
  export { default } from './maybe.js';
2
3
  export { default as just } from './just.js';
3
4
  export { default as nothing } from './nothing.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnts",
3
- "version": "3.0.1",
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
  }
@@ -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 Record<string, unknown> | any[],
16
- > = keyof Source extends keyof any[]
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 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
26
+ ? (Source[Key] extends Flattenable
27
+ // @ts-ignore
28
+ ? `${Key}.${Flatten<NormalizeFlattenable<Source[Key]>>}`
29
+ : Key)
31
30
  : never
32
- ] : never
31
+ ]: never
33
32
  }
34
- )
@@ -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 any[] | readonly any[], I extends number, E> =
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']