@finnair/path-parser
Version:
Simple object path as array of strings and numbers
20 lines (19 loc) • 738 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePath = parsePath;
const path_1 = require("@finnair/path");
const nearley_1 = __importDefault(require("nearley"));
const pathGrammar_js_1 = __importDefault(require("./pathGrammar.js"));
function parsePath(str) {
const parser = new nearley_1.default.Parser(nearley_1.default.Grammar.fromCompiled(pathGrammar_js_1.default));
parser.feed(str);
if (parser.results[0]) {
return path_1.Path.of(...parser.results[0]);
}
else {
throw new Error(`Unrecognized Path: ${str}`);
}
}