Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / toPath.js
1 var baseToString = require('./baseToString'),
2     isArray = require('../lang/isArray');
3
4 /** Used to match property names within property paths. */
5 var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
6
7 /** Used to match backslashes in property paths. */
8 var reEscapeChar = /\\(\\)?/g;
9
10 /**
11  * Converts `value` to property path array if it's not one.
12  *
13  * @private
14  * @param {*} value The value to process.
15  * @returns {Array} Returns the property path array.
16  */
17 function toPath(value) {
18   if (isArray(value)) {
19     return value;
20   }
21   var result = [];
22   baseToString(value).replace(rePropName, function(match, number, quote, string) {
23     result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
24   });
25   return result;
26 }
27
28 module.exports = toPath;