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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.40latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.40
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i path-to-object

Weekly Downloads

0

Version

1.0.4

License

ISC

Last publish

Collaborators

  • lesha-spr