path-to-prop 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 +5 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -5
- package/package.json +16 -14
package/README.md
CHANGED
|
@@ -25,21 +25,21 @@ getProp({ nested: { prop: 1 } }, 'nested') // { prop: 1 }
|
|
|
25
25
|
You can use `/` or `.` to access nested props:
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
const obj = {a: {b: {c: {d: {e: 1}}}}}
|
|
28
|
+
const obj = { a: { b: { c: { d: { e: 1 } } } } }
|
|
29
29
|
const path = 'a/b/c.d.e'
|
|
30
30
|
|
|
31
31
|
getProp(obj, path)
|
|
32
|
-
|
|
32
|
+
// returns 1
|
|
33
33
|
|
|
34
34
|
getProp(obj, 'nonexistent.prop')
|
|
35
|
-
|
|
35
|
+
// returns undefined
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
When you have `/` or `.` in your prop names, use an array:
|
|
39
39
|
|
|
40
40
|
```js
|
|
41
|
-
const obj = {'a/b': {'c.d': 1}}
|
|
41
|
+
const obj = { 'a/b': { 'c.d': 1 } }
|
|
42
42
|
|
|
43
43
|
getProp(obj, ['a/b', 'c.d'])
|
|
44
|
-
|
|
44
|
+
// returns 1
|
|
45
45
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the keys of a path
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @returns {string[]}
|
|
4
|
+
* @param {string} path A/path/like.this
|
|
5
|
+
* @returns {string[]} With keys
|
|
6
6
|
*/
|
|
7
7
|
export declare function getKeysFromPath(path: string | string[]): string[];
|
|
8
8
|
/**
|
|
9
|
-
* Gets a deep property in an object, based on a path to that property. Pass the path as array when
|
|
9
|
+
* Gets a deep property in an object, based on a path to that property. Pass the path as array when
|
|
10
|
+
* you have prop names with `.` or `/` in them
|
|
10
11
|
*
|
|
11
|
-
* @param {{ [key in string]: unknown }} obj
|
|
12
|
+
* @param {{ [key in string]: unknown }} obj An object to wherefrom to retrieve the deep reference
|
|
13
|
+
* of
|
|
12
14
|
* @param {string | string[]} path 'path/to.prop' or ['path', 'to', 'prop']
|
|
13
|
-
* @returns {unknown}
|
|
15
|
+
* @returns {unknown} The last prop in the path
|
|
14
16
|
*/
|
|
15
17
|
export declare function pathToProp(obj: {
|
|
16
18
|
[key in string]: unknown;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the keys of a path
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @returns {string[]}
|
|
4
|
+
* @param {string} path A/path/like.this
|
|
5
|
+
* @returns {string[]} With keys
|
|
6
6
|
*/
|
|
7
7
|
export function getKeysFromPath(path) {
|
|
8
8
|
return path.split ? path.split(/\.|\//) : path;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Gets a deep property in an object, based on a path to that property. Pass the path as array when
|
|
11
|
+
* Gets a deep property in an object, based on a path to that property. Pass the path as array when
|
|
12
|
+
* you have prop names with `.` or `/` in them
|
|
12
13
|
*
|
|
13
|
-
* @param {{ [key in string]: unknown }} obj
|
|
14
|
+
* @param {{ [key in string]: unknown }} obj An object to wherefrom to retrieve the deep reference
|
|
15
|
+
* of
|
|
14
16
|
* @param {string | string[]} path 'path/to.prop' or ['path', 'to', 'prop']
|
|
15
|
-
* @returns {unknown}
|
|
17
|
+
* @returns {unknown} The last prop in the path
|
|
16
18
|
*/
|
|
17
19
|
export function pathToProp(obj, path) {
|
|
18
20
|
const keys = getKeysFromPath(path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "path-to-prop",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Retrieves a property from an object based on a 'path/to.that.prop'",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -10,18 +10,14 @@
|
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "vitest run",
|
|
15
|
-
"lint": "tsc --noEmit && eslint ./src",
|
|
16
|
-
"build": "del-cli dist && tsc",
|
|
17
|
-
"release": "npm run lint && npm run build && np"
|
|
18
|
-
},
|
|
19
13
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
14
|
+
"@cycraft/eslint": "^0.4.11",
|
|
15
|
+
"@cycraft/tsconfig": "^0.1.2",
|
|
16
|
+
"bumpp": "^12.3.0",
|
|
17
|
+
"del-cli": "^7.0.0",
|
|
18
|
+
"eslint": "^9.20.1",
|
|
19
|
+
"typescript": "^5.9.3",
|
|
20
|
+
"vitest": "^5.0.2"
|
|
25
21
|
},
|
|
26
22
|
"files": [
|
|
27
23
|
"dist"
|
|
@@ -48,5 +44,11 @@
|
|
|
48
44
|
"url": "https://github.com/mesqueeb/path-to-prop.git"
|
|
49
45
|
},
|
|
50
46
|
"homepage": "https://github.com/mesqueeb/path-to-prop#readme",
|
|
51
|
-
"bugs": "https://github.com/mesqueeb/path-to-prop/issues"
|
|
52
|
-
|
|
47
|
+
"bugs": "https://github.com/mesqueeb/path-to-prop/issues",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"lint": "tsc --noEmit && eslint ./src",
|
|
51
|
+
"build": "del-cli dist && tsc",
|
|
52
|
+
"release": "pnpm run lint && pnpm run build && pnpm test && bumpp --no-push --all && pnpm publish --no-git-checks && npx jsr publish && git push --follow-tags && gh release create $(git describe --tags --abbrev=0) --generate-notes --notes \"$(git log --pretty='- %s %h' $(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || git rev-list --max-parents=0 HEAD)..HEAD~1)\""
|
|
53
|
+
}
|
|
54
|
+
}
|