to-object-path
Create an object path from a list or array of strings.
Install
Install with npm
$ npm i to-object-path --save
Usage
var toPath = require('to-object-path');
toPath('foo', 'bar', 'baz');
toPath('foo', ['bar', 'baz']);
Usage example
var Base = require('base-methods');
var toPath = require('to-object-path');
function App(options) {
Base.call(this);
this.options = options || {};
}
Base.extend(App);
App.prototype.option = function(key, value) {
var path = toPath('options', key);
if (arguments.length === 1) {
return this.get(path, value);
}
this.set(path, value);
return this;
};
var app = new App();
app.option('foo.bar', 'baz');
console.log(app);
console.log(app.option('foo'));
See the working example
Related projects
- get-value: Use property paths (
a.b.c
) to get a nested value from an object. | homepage - has-value: Returns true if a value exists, false if empty. Works with deeply nested values using… more | homepage
- set-value: Create nested values and any intermediaries using dot notation (
'a.b.c'
) paths. | homepage - unset-value: Delete nested properties from an object using dot notation. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on September 02, 2015.