syncpack 9.7.4 → 9.8.6

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 (70) hide show
  1. package/LICENSE +12 -13
  2. package/dist/bin-fix-mismatches/fix-mismatches.js +8 -4
  3. package/dist/bin-format/format.js +5 -4
  4. package/dist/bin-list/list.js +13 -7
  5. package/dist/bin-list-mismatches/list-mismatches.js +16 -11
  6. package/dist/get-context/$R.d.ts +8 -9
  7. package/dist/get-context/$R.js +13 -12
  8. package/dist/get-context/get-config/get-custom-types.js +1 -1
  9. package/dist/get-context/get-config/get-enabled-types.js +3 -3
  10. package/dist/get-context/get-config/index.d.ts +2 -1
  11. package/dist/get-context/get-config/index.js +28 -15
  12. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.d.ts +2 -3
  13. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.js +6 -4
  14. package/dist/get-context/get-config/path-strategy/name-and-version-props.js +15 -11
  15. package/dist/get-context/get-config/path-strategy/name-and-version-string.js +17 -12
  16. package/dist/get-context/get-config/path-strategy/types.d.ts +3 -4
  17. package/dist/get-context/get-config/path-strategy/version-string.js +17 -12
  18. package/dist/get-context/get-config/path-strategy/versions-by-name.js +10 -12
  19. package/dist/get-context/get-config/schema/index.d.ts +294 -256
  20. package/dist/get-context/get-config/schema/index.js +7 -7
  21. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +2 -0
  22. package/dist/get-context/get-config/schema/lib/non-empty-string.js +5 -0
  23. package/dist/get-context/get-config/schema/semver-group.d.ts +18 -18
  24. package/dist/get-context/get-config/schema/version-group.d.ts +49 -37
  25. package/dist/get-context/get-config/schema/version-group.js +14 -8
  26. package/dist/get-context/get-groups/base-group.js +1 -1
  27. package/dist/get-context/get-groups/index.d.ts +5 -3
  28. package/dist/get-context/get-groups/index.js +14 -2
  29. package/dist/get-context/get-groups/version-group/index.d.ts +6 -4
  30. package/dist/get-context/get-groups/version-group/index.js +18 -14
  31. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +2 -3
  32. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +6 -6
  33. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +2 -0
  34. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +44 -0
  35. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +15 -6
  36. package/dist/get-context/get-groups/version-group/instance-group/index.js +49 -30
  37. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +3 -1
  38. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +20 -4
  39. package/dist/get-context/get-package-json-files/get-file-paths.d.ts +2 -3
  40. package/dist/get-context/get-package-json-files/get-file-paths.js +14 -24
  41. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +2 -3
  42. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +6 -5
  43. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +2 -3
  44. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +7 -6
  45. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +2 -3
  46. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +7 -6
  47. package/dist/get-context/get-package-json-files/get-patterns/index.d.ts +2 -3
  48. package/dist/get-context/get-package-json-files/get-patterns/index.js +8 -17
  49. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.d.ts +2 -3
  50. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +6 -9
  51. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.d.ts +2 -3
  52. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +4 -3
  53. package/dist/get-context/get-package-json-files/index.d.ts +2 -1
  54. package/dist/get-context/get-package-json-files/index.js +7 -5
  55. package/dist/get-context/get-package-json-files/package-json-file/index.js +7 -5
  56. package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -1
  57. package/dist/get-context/get-package-json-files/package-json-file/instance.js +7 -6
  58. package/dist/get-context/index.d.ts +3 -2
  59. package/dist/get-context/index.js +22 -10
  60. package/dist/lib/disk.js +1 -1
  61. package/dist/lib/is-semver.js +1 -1
  62. package/dist/lib/log.js +7 -2
  63. package/dist/types.d.ts +1 -1
  64. package/package.json +17 -18
  65. package/dist/get-context/get-all-instances.d.ts +0 -3
  66. package/dist/get-context/get-all-instances.js +0 -8
  67. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.d.ts +0 -1
  68. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +0 -8
  69. package/dist/get-context/get-package-json-files/get-patterns/props.d.ts +0 -6
  70. package/dist/get-context/get-package-json-files/get-patterns/props.js +0 -24
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPackageJsonFiles = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
4
+ const flow_1 = require("tightrope/fn/flow");
5
+ const pipe_1 = require("tightrope/fn/pipe");
6
+ const result_1 = require("tightrope/result");
7
+ const and_then_1 = require("tightrope/result/and-then");
8
+ const map_1 = require("tightrope/result/map");
9
+ const or_1 = require("tightrope/result/or");
5
10
  const _R_1 = require("../$R");
6
11
  const get_file_paths_1 = require("./get-file-paths");
7
12
  const read_json_safe_1 = require("./get-patterns/read-json-safe");
8
13
  const package_json_file_1 = require("./package-json-file");
9
14
  /** Create an API for every package.json file needed. */
10
15
  function getPackageJsonFiles(disk, config) {
11
- return (0, ts_belt_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), ts_belt_1.R.flatMap(_R_1.$R.onlyOk(resolvePackageJson(disk))), ts_belt_1.R.getWithDefault([]));
12
- function resolvePackageJson(disk) {
13
- return (0, ts_belt_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.map((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)));
14
- }
16
+ return (0, pipe_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), (0, and_then_1.andThen)(_R_1.$R.onlyOk((0, flow_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), (0, map_1.map)((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)), _R_1.$R.tapErrVerbose))), (0, or_1.or)(new result_1.Ok([])));
15
17
  }
16
18
  exports.getPackageJsonFiles = getPackageJsonFiles;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PackageJsonFile = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
4
  const path_1 = require("path");
5
+ const pipe_1 = require("tightrope/fn/pipe");
6
+ const result_1 = require("tightrope/result");
7
+ const unwrap_or_1 = require("tightrope/result/unwrap-or");
6
8
  const constants_1 = require("../../../constants");
7
9
  const log_1 = require("../../../lib/log");
8
10
  const newlines_1 = require("../../../lib/newlines");
@@ -48,13 +50,13 @@ class PackageJsonFile {
48
50
  const strategyName = pathDef.strategy;
49
51
  switch (strategyName) {
50
52
  case 'name@version':
51
- return (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), ts_belt_1.R.getWithDefault([]));
53
+ return (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), (0, unwrap_or_1.unwrapOr)(new result_1.Ok([])));
52
54
  case 'name~version':
53
- return (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), ts_belt_1.R.getWithDefault([]));
55
+ return (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), (0, unwrap_or_1.unwrapOr)(new result_1.Ok([])));
54
56
  case 'version':
55
- return (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), ts_belt_1.R.getWithDefault([]));
57
+ return (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), (0, unwrap_or_1.unwrapOr)(new result_1.Ok([])));
56
58
  case 'versionsByName':
57
- return (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), ts_belt_1.R.getWithDefault([]));
59
+ return (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), (0, unwrap_or_1.unwrapOr)(new result_1.Ok([])));
58
60
  default:
59
61
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
60
62
  }
@@ -1,5 +1,6 @@
1
1
  import type { PackageJsonFile } from '.';
2
2
  import type { Syncpack } from '../../../types';
3
+ import type { Delete } from '../../get-groups/version-group/instance-group';
3
4
  export declare class Instance {
4
5
  /** the name of this dependency */
5
6
  name: string;
@@ -18,5 +19,5 @@ export declare class Instance {
18
19
  * In the case of banned dependencies, their version is set to `undefined`,
19
20
  * which causes them to be removed by `JSON.stringify`.
20
21
  */
21
- setVersion(version: string | undefined): void;
22
+ setVersion(version: string | Delete): void;
22
23
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Instance = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
5
  const _R_1 = require("../../$R");
6
6
  const path_strategy_1 = require("../../get-config/path-strategy");
7
+ const instance_group_1 = require("../../get-groups/version-group/instance-group");
7
8
  class Instance {
8
9
  constructor(pathDef, name, packageJsonFile, version) {
9
10
  this.pathDef = pathDef;
@@ -22,20 +23,20 @@ class Instance {
22
23
  */
23
24
  setVersion(version) {
24
25
  const strategyName = this.pathDef.strategy;
25
- const entry = [this.name, version];
26
+ const entry = [this.name, version === instance_group_1.DELETE ? undefined : version];
26
27
  const file = this.packageJsonFile;
27
28
  switch (strategyName) {
28
29
  case 'name@version':
29
- (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
30
+ (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
30
31
  break;
31
32
  case 'name~version':
32
- (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
33
+ (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
33
34
  break;
34
35
  case 'version':
35
- (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
36
+ (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
36
37
  break;
37
38
  case 'versionsByName':
38
- (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
39
+ (0, pipe_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
39
40
  break;
40
41
  default:
41
42
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
@@ -3,13 +3,14 @@ import type { Syncpack } from '../types';
3
3
  import type { SemverGroup } from './get-groups/semver-group';
4
4
  import type { VersionGroup } from './get-groups/version-group';
5
5
  import type { PackageJsonFile } from './get-package-json-files/package-json-file';
6
- export type Context = Omit<Syncpack.Config.Private, 'semverGroups' | 'versionGroups'> & {
6
+ export interface Context {
7
+ config: Syncpack.Config.Private;
7
8
  disk: Disk;
8
9
  isInvalid: boolean;
9
10
  packageJsonFiles: PackageJsonFile[];
10
11
  semverGroups: SemverGroup[];
11
12
  versionGroups: VersionGroup[];
12
- };
13
+ }
13
14
  /**
14
15
  * Every command in syncpack should accept the return value of this function as
15
16
  * its input.
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContext = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const and_then_1 = require("tightrope/result/and-then");
6
+ const map_1 = require("tightrope/result/map");
7
+ const unwrap_1 = require("tightrope/result/unwrap");
4
8
  const disk_1 = require("../lib/disk");
5
- const get_all_instances_1 = require("./get-all-instances");
9
+ const _R_1 = require("./$R");
6
10
  const get_config_1 = require("./get-config");
7
11
  const get_groups_1 = require("./get-groups");
8
12
  const get_package_json_files_1 = require("./get-package-json-files");
@@ -15,17 +19,25 @@ const get_package_json_files_1 = require("./get-package-json-files");
15
19
  * system and can focus solely on transformation logic.
16
20
  */
17
21
  function getContext(program, disk = disk_1.disk) {
18
- const config = (0, get_config_1.getConfig)(disk, program);
19
- const packageJsonFiles = (0, get_package_json_files_1.getPackageJsonFiles)(disk, config);
20
- const instances = (0, get_all_instances_1.getAllInstances)(packageJsonFiles);
21
- const groups = (0, get_groups_1.getGroups)(config, instances, packageJsonFiles);
22
- return {
23
- ...config,
22
+ return (0, pipe_1.pipe)(
23
+ // merge CLI options, .syncpackrc contents, and default config
24
+ (0, get_config_1.getConfig)(disk, program), (0, and_then_1.andThen)((config) => (0, pipe_1.pipe)(
25
+ // get the package.json file which match the globs in config
26
+ (0, get_package_json_files_1.getPackageJsonFiles)(disk, config), (0, and_then_1.andThen)((packageJsonFiles) => (0, pipe_1.pipe)(
27
+ // allocate dependencies into semver and version groups
28
+ (0, get_groups_1.getGroups)(config, packageJsonFiles),
29
+ // combine everything into the final config
30
+ (0, map_1.map)(({ semverGroups, versionGroups }) => ({
31
+ config,
24
32
  disk,
25
33
  isInvalid: false,
26
34
  packageJsonFiles,
27
- semverGroups: groups.semverGroups,
28
- versionGroups: groups.versionGroups,
29
- };
35
+ semverGroups,
36
+ versionGroups,
37
+ })))))),
38
+ // if anything errored at any stage, log it when in verbose mode
39
+ _R_1.$R.tapErrVerbose,
40
+ // throw if anything errored, can't do anything without this data
41
+ unwrap_1.unwrap);
30
42
  }
31
43
  exports.getContext = getContext;
package/dist/lib/disk.js CHANGED
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.disk = void 0;
4
4
  const cosmiconfig_1 = require("cosmiconfig");
5
- const is_non_empty_object_1 = require("expect-more/dist/is-non-empty-object");
6
5
  const fs_extra_1 = require("fs-extra");
7
6
  const glob_1 = require("glob");
8
7
  const path_1 = require("path");
9
8
  const read_yaml_file_1 = require("read-yaml-file");
9
+ const is_non_empty_object_1 = require("tightrope/guard/is-non-empty-object");
10
10
  const constants_1 = require("../constants");
11
11
  const log_1 = require("./log");
12
12
  const client = (0, cosmiconfig_1.cosmiconfigSync)('syncpack');
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLooseSemver = exports.isSemver = exports.isValidSemverRange = void 0;
4
- const is_string_1 = require("expect-more/dist/is-string");
4
+ const is_string_1 = require("tightrope/guard/is-string");
5
5
  const constants_1 = require("../constants");
6
6
  function isValidSemverRange(value) {
7
7
  return (value === constants_1.RANGE.ANY ||
package/dist/lib/log.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.versionGroupHeader = exports.semverGroupHeader = exports.invalid = exports.valid = exports.skip = exports.fixed = exports.verbose = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const is_string_1 = require("expect-more/dist/is-string");
8
+ const is_string_1 = require("tightrope/guard/is-string");
9
9
  const util_1 = require("util");
10
10
  const constants_1 = require("../constants");
11
11
  function verbose(...values) {
@@ -13,7 +13,12 @@ function verbose(...values) {
13
13
  if (process.env.SYNCPACK_VERBOSE) {
14
14
  console.info(chalk_1.default.yellow(constants_1.ICON.debug), ...values.map((value) => (0, is_string_1.isString)(value)
15
15
  ? chalk_1.default.yellow(value)
16
- : (0, util_1.inspect)(value, { showHidden: false, colors: true, depth: 20 })));
16
+ : (0, util_1.inspect)(value, {
17
+ colors: true,
18
+ compact: true,
19
+ depth: 20,
20
+ showHidden: false,
21
+ })));
17
22
  }
18
23
  }
19
24
  exports.verbose = verbose;
package/dist/types.d.ts CHANGED
@@ -81,7 +81,7 @@ export declare namespace Syncpack {
81
81
  /** Use these named packages as the source of truth for versions */
82
82
  export type SnappedTo = z.infer<T['snappedTo']>;
83
83
  /** @private */
84
- export type Default = z.infer<T['base']>;
84
+ export type Default = z.infer<T['defaultGroup']>;
85
85
  /** Every valid type of VersionGroup */
86
86
  export type Any = z.infer<T['any']>;
87
87
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "syncpack",
3
- "description": "Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces",
4
- "version": "9.7.4",
3
+ "description": "Consistent dependency versions in large JavaScript Monorepos",
4
+ "version": "9.8.6",
5
5
  "author": "Jamie Mason <jamie@foldleft.io> (https://github.com/JamieMason)",
6
6
  "bin": {
7
7
  "syncpack": "dist/bin.js",
@@ -26,35 +26,34 @@
26
26
  "Tom Fletcher (https://github.com/tom-fletcher)"
27
27
  ],
28
28
  "dependencies": {
29
- "@mobily/ts-belt": "3.13.1",
30
29
  "chalk": "4.1.2",
31
- "commander": "10.0.0",
32
- "cosmiconfig": "8.0.0",
33
- "expect-more": "1.3.0",
34
- "fs-extra": "11.1.0",
30
+ "commander": "10.0.1",
31
+ "cosmiconfig": "8.1.3",
32
+ "fs-extra": "11.1.1",
35
33
  "glob": "8.1.0",
36
34
  "minimatch": "6.2.0",
37
35
  "read-yaml-file": "2.1.0",
38
- "semver": "7.3.8",
39
- "zod": "3.20.6"
36
+ "semver": "7.5.0",
37
+ "tightrope": "0.1.0",
38
+ "zod": "3.21.4"
40
39
  },
41
40
  "devDependencies": {
42
41
  "@tsconfig/node14": "1.0.3",
43
42
  "@types/fs-extra": "11.0.1",
44
- "@types/glob": "8.0.1",
45
- "@types/jest": "29.4.0",
43
+ "@types/glob": "8.1.0",
44
+ "@types/jest": "29.5.1",
46
45
  "@types/node": "14.18.36",
47
46
  "@types/semver": "7.3.13",
48
- "@typescript-eslint/eslint-plugin": "5.52.0",
49
- "@typescript-eslint/parser": "5.52.0",
50
- "eslint": "8.34.0",
47
+ "@typescript-eslint/eslint-plugin": "5.59.0",
48
+ "@typescript-eslint/parser": "5.59.0",
49
+ "eslint": "8.39.0",
51
50
  "eslint-plugin-import": "2.27.5",
52
51
  "eslint-plugin-jest": "27.2.1",
53
52
  "expect-more-jest": "5.5.0",
54
- "jest": "29.4.3",
55
- "prettier": "2.8.4",
56
- "rimraf": "4.1.2",
57
- "ts-jest": "29.0.5",
53
+ "jest": "29.5.0",
54
+ "prettier": "2.8.8",
55
+ "rimraf": "4.4.1",
56
+ "ts-jest": "29.1.0",
58
57
  "ts-node": "10.9.1",
59
58
  "typescript": "4.9.5"
60
59
  },
@@ -1,3 +0,0 @@
1
- import type { PackageJsonFile } from './get-package-json-files/package-json-file';
2
- import type { Instance } from './get-package-json-files/package-json-file/instance';
3
- export declare function getAllInstances(packageJsonFiles: PackageJsonFile[]): Instance[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAllInstances = void 0;
4
- const sort_by_name_1 = require("../lib/sort-by-name");
5
- function getAllInstances(packageJsonFiles) {
6
- return packageJsonFiles.flatMap((pkg) => pkg.getInstances()).sort(sort_by_name_1.sortByName);
7
- }
8
- exports.getAllInstances = getAllInstances;
@@ -1 +0,0 @@
1
- export declare const getArrayOfStrings: (path: string) => (obj: unknown) => import("@mobily/ts-belt").Option<string[]>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getArrayOfStrings = void 0;
4
- const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
5
- const props_1 = require("../props");
6
- // Yarn's config for this can be in more than one place
7
- const getArrayOfStrings = (path) => (0, props_1.props)(path, is_array_of_strings_1.isArrayOfStrings);
8
- exports.getArrayOfStrings = getArrayOfStrings;
@@ -1,6 +0,0 @@
1
- import { O } from '@mobily/ts-belt';
2
- /**
3
- * Safely read nested properties of any value.
4
- * @param keys 'child.grandChild.greatGrandChild'
5
- */
6
- export declare function props<T>(keys: string, predicate: (value: unknown) => value is T): (obj: unknown) => O.Option<T>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.props = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
- const isWalkable = (value) => value !== null && typeof value !== 'undefined';
6
- /**
7
- * Safely read nested properties of any value.
8
- * @param keys 'child.grandChild.greatGrandChild'
9
- */
10
- function props(keys, predicate) {
11
- return function getNestedProp(obj) {
12
- let next = obj;
13
- for (const key of keys.split('.')) {
14
- if (isWalkable(next) && key in next) {
15
- next = next[key];
16
- }
17
- else {
18
- return ts_belt_1.O.None;
19
- }
20
- }
21
- return ts_belt_1.O.fromPredicate(next, predicate);
22
- };
23
- }
24
- exports.props = props;