50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
|
"use strict";
|
||
|
// @ts-nocheck
|
||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
const memoizeCapped_js_1 = __importDefault(require("./memoizeCapped.cjs"));
|
||
|
const charCodeOfDot = ".".charCodeAt(0);
|
||
|
const reEscapeChar = /\\(\\)?/g;
|
||
|
const rePropName = RegExp(
|
||
|
// Match anything that isn't a dot or bracket.
|
||
|
"[^.[\\]]+" +
|
||
|
"|" +
|
||
|
// Or match property names within brackets.
|
||
|
"\\[(?:" +
|
||
|
// Match a non-string expression.
|
||
|
"([^\"'][^[]*)" +
|
||
|
"|" +
|
||
|
// Or match strings (supports escaping characters).
|
||
|
"([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2" +
|
||
|
")\\]" +
|
||
|
"|" +
|
||
|
// Or match "" as the space between consecutive dots or empty brackets.
|
||
|
"(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))", "g");
|
||
|
/**
|
||
|
* Converts `string` to a property path array.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {string} string The string to convert.
|
||
|
* @returns {Array} Returns the property path array.
|
||
|
*/
|
||
|
const stringToPath = (0, memoizeCapped_js_1.default)((string) => {
|
||
|
const result = [];
|
||
|
if (string.charCodeAt(0) === charCodeOfDot) {
|
||
|
result.push("");
|
||
|
}
|
||
|
string.replace(rePropName, (match, expression, quote, subString) => {
|
||
|
let key = match;
|
||
|
if (quote) {
|
||
|
key = subString.replace(reEscapeChar, "$1");
|
||
|
}
|
||
|
else if (expression) {
|
||
|
key = expression.trim();
|
||
|
}
|
||
|
result.push(key);
|
||
|
});
|
||
|
return result;
|
||
|
});
|
||
|
exports.default = stringToPath;
|