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.
15 lines
470 B
15 lines
470 B
2 years ago
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.toPath = toPath;
|
||
|
function toPath(path) {
|
||
|
if (Array.isArray(path)) return path;
|
||
|
let openBrackets = path.split("[").length - 1;
|
||
|
let closedBrackets = path.split("]").length - 1;
|
||
|
if (openBrackets !== closedBrackets) {
|
||
|
throw new Error(`Path is invalid. Has unbalanced brackets: ${path}`);
|
||
|
}
|
||
|
return path.split(/\.(?![^\[]*\])|[\[\]]/g).filter(Boolean);
|
||
|
}
|