Skip to content

Lesha-spr/path-to-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

path-to-object

Converts string such 'a.b.c' to object {a: {b: {c: {}}}}

Installation

npm install path-to-object

Example usage

var pathToObject = require('path-to-object');

pathToObject('a.b.c.d'); // {a: {b: {c: {d: {}}}}

// Passing second param will set last field's value
pathToObject('a.b.c', true); // {a: {b: {c: true}}}

// Helper contains method to get or set value by string path
var myObj = {
    a: {
        b: 5
    }
};

pathToObject.value(myObj, 'a.b'); // 5
pathToObject.value(myObj, 'a.b', 10); // {a: {b: 10}}
pathToObject.value(myObj, 'a.b'); // 10

About

Converts string such 'a.b.c' to object {a: {b: {c: {}}}}

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published