to-object-path
Advanced tools
Comparing version 0.1.0 to 0.2.0
14
index.js
/*! | ||
* to-path <https://github.com/jonschlinkert/to-path> | ||
* to-object-path <https://github.com/jonschlinkert/to-object-path> | ||
* | ||
@@ -10,4 +10,12 @@ * Copyright (c) 2015, Jon Schlinkert. | ||
module.exports = function toPath() { | ||
return [].concat.apply([], arguments).join('.'); | ||
var isArguments = require('is-arguments'); | ||
var flatten = require('arr-flatten'); | ||
module.exports = function toPath(args) { | ||
if (isArguments(args)) { | ||
args = [].slice.call(args); | ||
} else { | ||
args = [].slice.call(arguments); | ||
} | ||
return flatten(args).join('.'); | ||
}; |
{ | ||
"name": "to-object-path", | ||
"description": "Create an object path from a list or array of strings.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jonschlinkert/to-object-path", | ||
@@ -22,8 +22,18 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"arr-flatten": "^1.0.1", | ||
"is-arguments": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"base-methods": "^0.2.1", | ||
"base-methods": "^0.3.1", | ||
"mocha": "*" | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"dot", | ||
"nested", | ||
"notation", | ||
"object", | ||
"path", | ||
"stringify" | ||
], | ||
"verb": { | ||
@@ -35,2 +45,3 @@ "related": { | ||
"has-value", | ||
"omit-value", | ||
"unset-value" | ||
@@ -40,2 +51,2 @@ ] | ||
} | ||
} | ||
} |
@@ -23,39 +23,15 @@ # to-object-path [![NPM version](https://badge.fury.io/js/to-object-path.svg)](http://badge.fury.io/js/to-object-path) | ||
## Usage example | ||
Also supports passing an arguments object (without having to slice args): | ||
```js | ||
// `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 || {}; | ||
function foo() | ||
return toPath(arguments); | ||
} | ||
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' } | ||
foo('foo', 'bar', 'baz'); | ||
foo('foo', ['bar', 'baz']); | ||
//=> 'foo.bar.baz' | ||
``` | ||
See the [working example](./example.js) | ||
Visit the [example](./example.js) to see how this could be used in an application. | ||
@@ -66,2 +42,3 @@ ## Related projects | ||
* [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://www.npmjs.com/package/has-value) | [homepage](https://github.com/jonschlinkert/has-value) | ||
* [omit-value](https://www.npmjs.com/package/omit-value): Omit properties from an object or deeply nested property of an object using object path… [more](https://www.npmjs.com/package/omit-value) | [homepage](https://github.com/jonschlinkert/omit-value) | ||
* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value) | ||
@@ -96,2 +73,2 @@ * [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value) | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 02, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 28, 2015._ |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4884
17
0
2
71
+ Addedarr-flatten@^1.0.1
+ Addedis-arguments@^1.0.2
+ Addedarr-flatten@1.1.0(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedset-function-length@1.2.2(transitive)