mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
806 B
28 lines
806 B
var baseToString = require('./baseToString'),
|
|
isArray = require('../lang/isArray');
|
|
|
|
/** Used to match property names within property paths. */
|
|
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
|
|
|
/** Used to match backslashes in property paths. */
|
|
var reEscapeChar = /\\(\\)?/g;
|
|
|
|
/**
|
|
* Converts `value` to property path array if it's not one.
|
|
*
|
|
* @private
|
|
* @param {*} value The value to process.
|
|
* @returns {Array} Returns the property path array.
|
|
*/
|
|
function toPath(value) {
|
|
if (isArray(value)) {
|
|
return value;
|
|
}
|
|
var result = [];
|
|
baseToString(value).replace(rePropName, function(match, number, quote, string) {
|
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
|
});
|
|
return result;
|
|
}
|
|
|
|
module.exports = toPath;
|
|
|