1.0.1 • Published 2 years ago
path-of v1.0.1
dot-prop
Type for nested object and array. Get the path and value for it.
Install
npm install path-of
Usage
import { PathOf, ValueOf } from 'path-of';
// PathOf
type PathOfArray = PathOf<number[]>;
//=> '[0]'
type PathOfObject = PathOf<{ foo: string }>;
//=> 'foo'
type PathOfNestedArray = PathOf<number[][]>;
//=> '[0][0]'
type PathOfNestedObject = PathOf<{ foo: { bar: string } }>
//=> 'foo.bar'
// ValueOf
type ValueOfArray = ValueOf<number[], '[0]'>;
//=> number
type ValueOfObject = ValueOf<{ foo: string }, 'foo'>;
//=> string
type ValueOfNestedArray = ValueOf<number[][], '[0]'>;
//=> number[]
type ValueOfNestedObject = ValueOf<{ foo: { bar: string } }, 'foo'>
//=> { bar: string }
API
Click the type names for details.
Basic
PathOf
- Get the property path' literals for nested object. Returns never if it is a primitive type.ValueOf
- Get the implicit type from the property path of nested object. Returns Returns never if the path is invalid.ArrayPathOf
- Get the property path' literals for nested object which value of type match Array. Returns Returns never if it is a primitive type.ValueOf
- Get the implicit type from the property path of nested object which value of type match Array. Returns Returns never if the path is invalid.
Dot path
DotPathOf
- Get the property path' literals in "dot" for nested object. Returns never if it is a primitive type.DotValueOf
- Get the implicit type from the property "dot" path of nested object. Returns Returns never if the path is invalid.DotArrayPathOf
- Get the property path' literals in "dot" for nested object which value of type match Array. Returns Returns never if it is a primitive type.DotValueOf
- Get the implicit type from the property "dot" path of nested object which value of type match Array. Returns Returns never if the path is invalid.