index.js 663 B

12345678910111213141516171819202122232425262728293031323334
  1. /*!
  2. * to-object-path <https://github.com/jonschlinkert/to-object-path>
  3. *
  4. * Copyright (c) 2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. var typeOf = require('kind-of');
  9. module.exports = function toPath(args) {
  10. if (typeOf(args) !== 'arguments') {
  11. args = arguments;
  12. }
  13. return filter(args).join('.');
  14. };
  15. function filter(arr) {
  16. var len = arr.length;
  17. var idx = -1;
  18. var res = [];
  19. while (++idx < len) {
  20. var ele = arr[idx];
  21. if (typeOf(ele) === 'arguments' || Array.isArray(ele)) {
  22. res.push.apply(res, filter(ele));
  23. } else if (typeof ele === 'string') {
  24. res.push(ele);
  25. }
  26. }
  27. return res;
  28. }