summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/lodash/toPath.js
blob: 270698deff6c44a6baba2f43c7497c0a8835bddb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var arrayMap = require('./_arrayMap'),
    isArray = require('./isArray'),
    stringToPath = require('./_stringToPath');

/**
 * Converts `value` to a property path array.
 *
 * @static
 * @memberOf _
 * @category Util
 * @param {*} value The value to convert.
 * @returns {Array} Returns the new property path array.
 * @example
 *
 * _.toPath('a.b.c');
 * // => ['a', 'b', 'c']
 *
 * _.toPath('a[0].b.c');
 * // => ['a', '0', 'b', 'c']
 *
 * var path = ['a', 'b', 'c'],
 *     newPath = _.toPath(path);
 *
 * console.log(newPath);
 * // => ['a', 'b', 'c']
 *
 * console.log(path === newPath);
 * // => false
 */
function toPath(value) {
  return isArray(value) ? arrayMap(value, String) : stringToPath(value);
}

module.exports = toPath;