trailhead
v0.0.1
Published
A utility to find paths through data structures
Downloads
2
Readme
Compatibility
Requires Typescript 4.0+ and the Proxy API. You can check browser compatibility for Proxies at caniuse.com/proxy.
Usage
import { trailhead } from 'trailhead';
type Data = {
firstName: string;
array: string[];
nest: {
nest: {
firstName: string;
};
};
arrayObject: {
firstName: string;
lastName: string;
}[];
};
const test = trailhead<Data>();
console.log(test); // => { __path: [] }
console.log(test.firstName); // => { __path: ["firstName"] }
console.log(test.array[5]); // => { __path: ["array", 5] }
console.log(test.nest.nest.firstName); // => { __path: ["nest", "nest", "firstName"] }
console.log(test.arrayObject); // => { __path: ["arrayObject"] }
console.log(test.arrayObject[5]); // => { __path: ["arrayObject", 5, "firstName"] }
console.log(test.arrayObject[5].firstName); // => { __path: ["arrayObject", 5, "firstName"] }