Skip to content

🔥 Utility function to get a value corresponding to path of object.

License

Notifications You must be signed in to change notification settings

sjk1991/obj.getter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obj.getter

Utility function to get a value corresponding to path of object.

Install

npm i obj.getter

Usage

import getter from 'obj.getter';

const value1 = getter('a.b[0].c', { a: { b: [{ c: 1 }] } });
const value2 = getter('a.b[0]["c"]', { a: { b: [{ c: 1 }] } });
const value3 = getter('a.b["0"].c', { a: { b: [{ c: 1 }] } });

const value4 = getter('a.b[0].c')({ a: { b: [{ c: 1 }] } });

console.log(value1); // 1
console.log(value2); // 1
console.log(value3); // 1
console.log(value4); // 1

API

function getter(path: string, obj?: Record<string, any>): any;
function getter(path: string): (obj: Record<string, any>) => any;

Return a value corresponding to path of object.

License

MIT

About

🔥 Utility function to get a value corresponding to path of object.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published