path-to-prop 2.0.4 → 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/dist/index.d.ts CHANGED
@@ -4,15 +4,15 @@
4
4
  * @param {string} path a/path/like.this
5
5
  * @returns {string[]} with keys
6
6
  */
7
- declare function getKeysFromPath(path: string | string[]): string[];
7
+ export declare function getKeysFromPath(path: string | string[]): string[];
8
8
  /**
9
9
  * Gets a deep property in an object, based on a path to that property. Pass the path as array when you have prop names with `.` or `/` in them
10
10
  *
11
- * @param {Record<string, unknown>} obj an object to wherefrom to retrieve the deep reference of
11
+ * @param {{ [key in string]: unknown }} obj an object to wherefrom to retrieve the deep reference of
12
12
  * @param {string | string[]} path 'path/to.prop' or ['path', 'to', 'prop']
13
13
  * @returns {unknown} the last prop in the path
14
14
  */
15
- declare function pathToProp(obj: Record<string, unknown>, path: string | string[]): unknown;
16
- declare const getProp: typeof pathToProp;
17
-
18
- export { getKeysFromPath, getProp, pathToProp };
15
+ export declare function pathToProp(obj: {
16
+ [key in string]: unknown;
17
+ }, path: string | string[]): unknown;
18
+ export declare const getProp: typeof pathToProp;
package/dist/index.js CHANGED
@@ -1,14 +1,25 @@
1
- function getKeysFromPath(path) {
2
- return path.split ? path.split(/\.|\//) : path;
1
+ /**
2
+ * Returns the keys of a path
3
+ *
4
+ * @param {string} path a/path/like.this
5
+ * @returns {string[]} with keys
6
+ */
7
+ export function getKeysFromPath(path) {
8
+ return path.split ? path.split(/\.|\//) : path;
3
9
  }
4
- function pathToProp(obj, path) {
5
- const keys = getKeysFromPath(path);
6
- let p;
7
- for (p = 0; p < keys.length; p++) {
8
- obj = obj ? obj[keys[p]] : void 0;
9
- }
10
- return obj === void 0 ? void 0 : obj;
10
+ /**
11
+ * Gets a deep property in an object, based on a path to that property. Pass the path as array when you have prop names with `.` or `/` in them
12
+ *
13
+ * @param {{ [key in string]: unknown }} obj an object to wherefrom to retrieve the deep reference of
14
+ * @param {string | string[]} path 'path/to.prop' or ['path', 'to', 'prop']
15
+ * @returns {unknown} the last prop in the path
16
+ */
17
+ export function pathToProp(obj, path) {
18
+ const keys = getKeysFromPath(path);
19
+ let p;
20
+ for (p = 0; p < keys.length; p++) {
21
+ obj = (obj ? obj[keys[p]] : undefined);
22
+ }
23
+ return obj === undefined ? undefined : obj;
11
24
  }
12
- const getProp = pathToProp;
13
-
14
- export { getKeysFromPath, getProp, pathToProp };
25
+ export const getProp = pathToProp;
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "path-to-prop",
3
- "version": "2.0.4",
3
+ "version": "3.0.0",
4
4
  "description": "Retrieves a property from an object based on a 'path/to.that.prop'",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "types": "./dist/index.d.ts",
8
- "module": "./dist/index.js",
9
- "main": "./dist/index.js",
10
7
  "exports": {
11
8
  ".": {
12
9
  "require": {
@@ -19,18 +16,25 @@
19
16
  }
20
17
  }
21
18
  },
22
- "files": [
23
- "dist"
24
- ],
25
19
  "engines": {
26
- "node": ">=12.13"
20
+ "node": ">=18"
27
21
  },
28
22
  "scripts": {
29
23
  "test": "vitest run",
30
- "lint": "tsc --noEmit && eslint ./src --ext .ts",
31
- "build": "rollup -c ./rollup.config.js",
32
- "release": "npm run lint && del dist && npm run build && np"
24
+ "lint": "tsc --noEmit && eslint ./src",
25
+ "build": "del-cli dist && tsc",
26
+ "release": "npm run lint && npm run build && np"
27
+ },
28
+ "devDependencies": {
29
+ "del-cli": "^5.1.0",
30
+ "np": "^10.0.5",
31
+ "vitest": "^1.6.0",
32
+ "@cycraft/eslint": "^0.3.0",
33
+ "@cycraft/tsconfig": "^0.1.2"
33
34
  },
35
+ "files": [
36
+ "dist"
37
+ ],
34
38
  "keywords": [
35
39
  "path-to-prop",
36
40
  "dot-prop",
@@ -45,61 +49,13 @@
45
49
  "get-dot-prop",
46
50
  "get-dot-property"
47
51
  ],
48
- "author": "Luca Ban - Mesqueeb",
52
+ "author": "Luca Ban - Mesqueeb (https://cycraft.co)",
49
53
  "funding": "https://github.com/sponsors/mesqueeb",
50
54
  "license": "MIT",
51
- "homepage": "https://github.com/mesqueeb/path-to-prop#readme",
52
- "devDependencies": {
53
- "@typescript-eslint/eslint-plugin": "^5.59.2",
54
- "@typescript-eslint/parser": "^5.59.2",
55
- "del-cli": "^5.0.0",
56
- "eslint": "^8.40.0",
57
- "eslint-config-prettier": "^8.8.0",
58
- "eslint-plugin-tree-shaking": "^1.10.0",
59
- "np": "^7.7.0",
60
- "prettier": "^2.8.8",
61
- "rollup": "^3.23.0",
62
- "rollup-plugin-dts": "^5.3.0",
63
- "rollup-plugin-esbuild": "^5.0.0",
64
- "typescript": "^4.9.5",
65
- "vitest": "^0.31.0"
66
- },
67
- "bugs": {
68
- "url": "https://github.com/mesqueeb/path-to-prop/issues"
69
- },
70
55
  "repository": {
71
56
  "type": "git",
72
- "url": "git+https://github.com/mesqueeb/path-to-prop.git"
57
+ "url": "https://github.com/mesqueeb/path-to-prop.git"
73
58
  },
74
- "np": {
75
- "yarn": false,
76
- "branch": "production"
77
- },
78
- "eslintConfig": {
79
- "ignorePatterns": [
80
- "node_modules",
81
- "dist",
82
- "scripts",
83
- "test"
84
- ],
85
- "root": true,
86
- "parser": "@typescript-eslint/parser",
87
- "plugins": [
88
- "@typescript-eslint",
89
- "tree-shaking"
90
- ],
91
- "extends": [
92
- "eslint:recommended",
93
- "plugin:@typescript-eslint/eslint-recommended",
94
- "plugin:@typescript-eslint/recommended",
95
- "prettier"
96
- ],
97
- "rules": {
98
- "@typescript-eslint/no-empty-function": "off",
99
- "@typescript-eslint/no-explicit-any": "off",
100
- "@typescript-eslint/ban-ts-ignore": "off",
101
- "tree-shaking/no-side-effects-in-initialization": "error",
102
- "@typescript-eslint/ban-ts-comment": "off"
103
- }
104
- }
59
+ "homepage": "https://github.com/mesqueeb/path-to-prop#readme",
60
+ "bugs": "https://github.com/mesqueeb/path-to-prop/issues"
105
61
  }
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- function getKeysFromPath(path) {
4
- return path.split ? path.split(/\.|\//) : path;
5
- }
6
- function pathToProp(obj, path) {
7
- const keys = getKeysFromPath(path);
8
- let p;
9
- for (p = 0; p < keys.length; p++) {
10
- obj = obj ? obj[keys[p]] : void 0;
11
- }
12
- return obj === void 0 ? void 0 : obj;
13
- }
14
- const getProp = pathToProp;
15
-
16
- exports.getKeysFromPath = getKeysFromPath;
17
- exports.getProp = getProp;
18
- exports.pathToProp = pathToProp;
@@ -1,18 +0,0 @@
1
- /**
2
- * Returns the keys of a path
3
- *
4
- * @param {string} path a/path/like.this
5
- * @returns {string[]} with keys
6
- */
7
- declare function getKeysFromPath(path: string | string[]): string[];
8
- /**
9
- * Gets a deep property in an object, based on a path to that property. Pass the path as array when you have prop names with `.` or `/` in them
10
- *
11
- * @param {Record<string, unknown>} obj an object to wherefrom to retrieve the deep reference of
12
- * @param {string | string[]} path 'path/to.prop' or ['path', 'to', 'prop']
13
- * @returns {unknown} the last prop in the path
14
- */
15
- declare function pathToProp(obj: Record<string, unknown>, path: string | string[]): unknown;
16
- declare const getProp: typeof pathToProp;
17
-
18
- export { getKeysFromPath, getProp, pathToProp };