Skip to content

allain/propper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

propper

NPM version License

A tool for getting and setting object properties using dot notation, path notation, and arrays to speficy properties.

Installation

npm install propper

Usage

var prop = require('propper')

var obj = {a: 1, b: {c: 'hello'}};

// getters
console.log(prop(obj, 'b.c'));      // 'hello'
console.log(prop(obj, '/b/c'));     // 'hello'
console.log(prop(obj, ['b', 'c'])); // 'hello'

// setters
console.log(prop(obj, 'b.c', 1));      // 1
console.log(prop(obj, '/b/c', 2));     // 2
console.log(prop(obj, ['b', 'c'], 3)); // 3

// setters can also be used to delete keys from an object by passing in undefined as the value
prop(obj, 'b.c', undefined);
console.log(obj); // {a: 1}

// If the deletion of a key would yield, an empty object, then that object will be removed too.

obj = {a: {b: {c: true}}};
prop(obj, 'a.b.c', undefined);
console.log(obj); // {}

ISC

About

A javascript property getter and setter utility

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published