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

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.4
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.4
    0
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i path-to-object

Weekly Downloads

0

Version

1.0.4

License

ISC

Last publish

Collaborators

  • lesha-spr