Socket
Socket
Sign inDemoInstall

to-object-path

Package Overview
Dependencies
15
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc