index.js
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 8 'use strict'; 9 10 var typeOf = require('kind-of'); 11 12 module.exports = function toPath(args) { 13 if (typeOf(args) !== 'arguments') { 14 args = arguments; 15 } 16 return filter(args).join('.'); 17 }; 18 19 function filter(arr) { 20 var len = arr.length; 21 var idx = -1; 22 var res = []; 23 24 while (++idx < len) { 25 var ele = arr[idx]; 26 if (typeOf(ele) === 'arguments' || Array.isArray(ele)) { 27 res.push.apply(res, filter(ele)); 28 } else if (typeof ele === 'string') { 29 res.push(ele); 30 } 31 } 32 return res; 33 }