path-to-object

1.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i path-to-object

Weekly Downloads

0

Version

1.0.4

License

ISC

Last publish

Collaborators

  • lesha-spr