SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-09-17 22:28:43 -07:00
import memoizeCapped from './_memoizeCapped.js';
2015-04-15 20:56:31 -07:00
/** Used to match property names within property paths. */
2018-02-02 21:11:07 -08:00
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
2015-04-15 20:56:31 -07:00
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/**
2015-09-17 17:52:09 -07:00
* Converts `string` to a property path array.
2015-04-15 20:56:31 -07:00
*
* @private
2015-09-17 17:52:09 -07:00
* @param {string} string The string to convert.
2015-04-15 20:56:31 -07:00
* @returns {Array} Returns the property path array.
*/
2016-09-17 22:28:43 -07:00
var stringToPath = memoizeCapped(function(string) {
2015-04-15 20:56:31 -07:00
var result = [];
2018-02-02 21:11:07 -08:00
if (string.charCodeAt(0) === 46 /* . */) {
2016-07-27 17:41:16 -07:00
result.push('');
}
2018-02-02 21:11:07 -08:00
string.replace(rePropName, function(match, number, quote, subString) {
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
2015-04-15 20:56:31 -07:00
});
return result;
2016-03-26 00:00:36 -07:00
});
2015-04-15 20:56:31 -07:00
2015-09-17 17:52:09 -07:00
export default stringToPath;