1 | import arrayMap from './_arrayMap';
|
2 | import baseCastKey from './_baseCastKey';
|
3 | import copyArray from './_copyArray';
|
4 | import isArray from './isArray';
|
5 | import isSymbol from './isSymbol';
|
6 | import stringToPath from './_stringToPath';
|
7 |
|
8 | /**
|
9 | * Converts `value` to a property path array.
|
10 | *
|
11 | * @static
|
12 | * @memberOf _
|
13 | * @since 4.0.0
|
14 | * @category Util
|
15 | * @param {*} value The value to convert.
|
16 | * @returns {Array} Returns the new property path array.
|
17 | * @example
|
18 | *
|
19 | * _.toPath('a.b.c');
|
20 | * // => ['a', 'b', 'c']
|
21 | *
|
22 | * _.toPath('a[0].b.c');
|
23 | * // => ['a', '0', 'b', 'c']
|
24 | *
|
25 | * var path = ['a', 'b', 'c'],
|
26 | * newPath = _.toPath(path);
|
27 | *
|
28 | * console.log(newPath);
|
29 | * // => ['a', 'b', 'c']
|
30 | *
|
31 | * console.log(path === newPath);
|
32 | * // => false
|
33 | */
|
34 | function toPath(value) {
|
35 | if (isArray(value)) {
|
36 | return arrayMap(value, baseCastKey);
|
37 | }
|
38 | return isSymbol(value) ? [value] : copyArray(stringToPath(value));
|
39 | }
|
40 |
|
41 | export default toPath;
|