0.2.2 • Published 12 years ago

strpath v0.2.2

Weekly downloads
1
License
MIT
Repository
-
Last release
12 years ago

strpath

build status

Get or set data in a Javascript object using a string path. Creates the path if it doesn't find it.

var strpath = require('strpath');

var obj = {
  a: {
    b: 10
  },
  c: [10, 20, 30]
};

// Get some data
var b = strpath(obj, 'a.b');
console.log(b); // 10

var c1 = strpath(obj, 'c[1]');
console.log(c1); // 20

// Set some data
strpath(obj, 'a.c.d', 20);
console.log(obj.c.d); // 20

strpath(obj, 'a.c.e[1]', 30);
console.log(obj.a.c.e); // [ , 30 ]

Install

npm install strpath

License

MIT

0.2.2

12 years ago

0.2.0

12 years ago

0.1.1

12 years ago