Package Exports
- to-object-path
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (to-object-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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']);
//=> 'foo.bar.baz'
Usage example
// `base-methods` has `get` and `set` methods that
// support object-path notation
var Base = require('base-methods');
var toPath = require('to-object-path');
// inherit Base
function App(options) {
Base.call(this);
this.options = options || {};
}
Base.extend(App);
App.prototype.option = function(key, value) {
// use the `get` and `set` methods to set
// and get values on `this.options`
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);
//=> {options: { foo: { bar: 'baz' }}}
console.log(app.option('foo'));
//=> { bar: 'baz' }
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.