Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / _stringToPath.js
1 var memoizeCapped = require('./_memoizeCapped'),
2     toString = require('./toString');
3
4 /** Used to match property names within property paths. */
5 var reLeadingDot = /^\./,
6     rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
7
8 /** Used to match backslashes in property paths. */
9 var reEscapeChar = /\\(\\)?/g;
10
11 /**
12  * Converts `string` to a property path array.
13  *
14  * @private
15  * @param {string} string The string to convert.
16  * @returns {Array} Returns the property path array.
17  */
18 var stringToPath = memoizeCapped(function(string) {
19   string = toString(string);
20
21   var result = [];
22   if (reLeadingDot.test(string)) {
23     result.push('');
24   }
25   string.replace(rePropName, function(match, number, quote, string) {
26     result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
27   });
28   return result;
29 });
30
31 module.exports = stringToPath;