@cobol-ts/path 0.0.14 → 0.0.17
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 +20 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
# @cobol-ts/
|
|
1
|
+
# @cobol-ts/path
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provide bounded, type-checked string and segment-array paths with runtime property access and explicit conversion.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Paths are capped at six levels, arrays are terminal, and lookup errors identify the failed segment.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Example
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```typescript
|
|
10
|
+
import {stringPathGet, arrayPathGet, fromStringToArray} from '@cobol-ts/path'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const data = {customer: {id: 7}}
|
|
13
|
+
const key = stringPathGet(data, 'customer.id')
|
|
14
|
+
const segments = fromStringToArray<typeof data>('customer.id')
|
|
15
|
+
const sameKey = arrayPathGet(data, segments)
|
|
16
|
+
// key and sameKey are 7
|
|
17
|
+
```
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
`StringPath<T>` and `ArrayPath<T>` statically restrict traversal to six object levels, prohibit dotted property names in the string form and stop at arrays. Runtime accessors throw errors that identify the failing segment rather than silently returning undefined.
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
## Source and tests
|
|
22
|
+
|
|
23
|
+
**Public entry points:** [path.array.ts](./src/path.array.ts), [path.convert.ts](./src/path.convert.ts), [path.string.ts](./src/path.string.ts).
|
|
24
|
+
|
|
25
|
+
**Tests:** [path.array.spec.ts](src/path.array.spec.ts), [path.convert.spec.ts](src/path.convert.spec.ts), [path.string.spec.ts](src/path.string.spec.ts)
|
|
26
|
+
|
|
27
|
+
**Related:** [@cobol-ts/dependency_node](../../execution/dependency_node/README.md) · [@cobol-ts/records](../records/README.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/path",
|
|
3
3
|
"description": "Type safe path through objects",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"browserslist": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cobol-ts/records": "0.0.
|
|
20
|
+
"@cobol-ts/records": "0.0.17"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.2.2",
|