typed-path
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -0,3 +1,5 @@ | ||
export declare type TypedPathKey = string | symbol | number; | ||
export declare type TypedPathNode<T> = { | ||
$path: string; | ||
$raw: TypedPathKey[]; | ||
}; | ||
@@ -4,0 +6,0 @@ export declare type TypedPathFunction<T> = (...args: any[]) => T; |
@@ -33,2 +33,5 @@ "use strict"; | ||
} | ||
if (name === '$raw') { | ||
return path; | ||
} | ||
if (toStringMethods.includes(name)) { | ||
@@ -35,0 +38,0 @@ return function () { return pathToString(path); }; |
@@ -0,3 +1,6 @@ | ||
export type TypedPathKey = string | symbol | number; | ||
export type TypedPathNode<T> = { | ||
$path: string; | ||
$raw: TypedPathKey[]; | ||
}; | ||
@@ -42,3 +45,3 @@ | ||
return <TypedPathWrapper<T>>new Proxy({}, { | ||
get(target: T, name: string | symbol | number) { | ||
get(target: T, name: TypedPathKey) { | ||
if (name === '$path') { | ||
@@ -48,2 +51,6 @@ return pathToString(path); | ||
if (name === '$raw') { | ||
return path; | ||
} | ||
if (toStringMethods.includes(name)) { | ||
@@ -50,0 +57,0 @@ return () => pathToString(path); |
{ | ||
"name": "typed-path", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Type safe object string paths for typescript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,15 @@ # Typed Path | ||
Also you can get access to the path string using `$path` special field. [@m-abboud](https://github.com/m-abboud) | ||
Like this: | ||
```js | ||
console.log(tp<TestType>().a.b.c.d.$path); // this will output "a.b.c.d" | ||
``` | ||
If you need a raw path, which is of type `string[]` - you can get it using `$raw` special field. [dcbrwn](https://github.com/dcbrwn) | ||
```js | ||
console.log(tp<TestType>().a.b.c.d.$raw); // this will output ["a", "b", "c", "d"] | ||
``` | ||
### Suggestions | ||
@@ -25,0 +38,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7513
110
46