You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3 KiB

4 years ago
  1. # to-object-path [![NPM version](https://badge.fury.io/js/to-object-path.svg)](http://badge.fury.io/js/to-object-path)
  2. > Create an object path from a list or array of strings.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/)
  5. ```sh
  6. $ npm i to-object-path --save
  7. ```
  8. ## Usage
  9. ```js
  10. var toPath = require('to-object-path');
  11. toPath('foo', 'bar', 'baz');
  12. toPath('foo', ['bar', 'baz']);
  13. //=> 'foo.bar.baz'
  14. ```
  15. Also supports passing an arguments object (without having to slice args):
  16. ```js
  17. function foo()
  18. return toPath(arguments);
  19. }
  20. foo('foo', 'bar', 'baz');
  21. foo('foo', ['bar', 'baz']);
  22. //=> 'foo.bar.baz'
  23. ```
  24. Visit the [example](./example.js) to see how this could be used in an application.
  25. ## Related projects
  26. * [get-value](https://www.npmjs.com/package/get-value): Use property paths (` a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value)
  27. * [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)
  28. * [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)
  29. * [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)
  30. * [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)
  31. ## Running tests
  32. Install dev dependencies:
  33. ```sh
  34. $ npm i -d && npm test
  35. ```
  36. ## Contributing
  37. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/to-object-path/issues/new).
  38. ## Author
  39. **Jon Schlinkert**
  40. + [github/jonschlinkert](https://github.com/jonschlinkert)
  41. + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  42. ## License
  43. Copyright © 2015 Jon Schlinkert
  44. Released under the MIT license.
  45. ***
  46. _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 28, 2015._