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