trailhead
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Trailhead

A utility for generating typesafe paths through your data



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"] }

Readme

Keywords

none

Package Sidebar

Install

npm i trailhead

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

6.63 kB

Total Files

9

Last publish

Collaborators

  • vriad