Skip to content

Simple class to iterate and access objects via dot-notation

Notifications You must be signed in to change notification settings

rexfordkelly-on-JS/d9r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Dot Iterator "d9r"

Simple class that allows you to access objects via dot-notation

Unlike other popular implimentations, d9r provides a dotEach method which allows you to leverage dot-notation access in a functional manor.

There are no additional dependencies for this class.

Install

$ npm install --save d9r

Usage

const ø = require('d9r');

ø.get({foo: {bar: 'unicorn'}}, 'foo.bar'); 
//=> 'unicorn'

ø.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
//=> undefined


const obj = {foo: {bar: 'a'}};
ø.set(obj, 'foo.bar', 'b');
console.log(obj);
//=> {foo: {bar: 'b'}}

ø.set(obj, 'foo.baz', 'x');
console.log(obj);
//=> {foo: {bar: 'b', baz: 'x'}}

ø.has({foo: {bar: 'unicorn'}}, 'foo.bar');
//=> true

ø.has({foo: {baz: undefined}}, 'foo.baz');
//=> true

ø.delete(obj, 'foo.bar');
console.log(obj);
//=> {foo: {}}

About

Simple class to iterate and access objects via dot-notation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published