UNPKG

expand-value

Version:

Get deeply nested values from an object, like dot-prop and get-value, but with support for advanced features like bracket-notation and more.

117 lines (113 loc) 2.35 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/utils.ts import isNumber from "is-number"; import { Segmenter } from "intl-segmenter"; var { defineProperty } = Reflect; var define = /* @__PURE__ */ __name((node, key, value) => { defineProperty(node, key, { configurable: true, enumerable: false, writable: true, value }); }, "define"); // src/nodes/Node.ts var Node = class { static { __name(this, "Node"); } type; value; output; symbol; parent; constructor(node) { this.type = node.type; this.value = node.value || ""; if (node.output != null && node.output !== "") { this.output = node.output; } if (node.symbol) { this.symbol = node.symbol; } define(this, "alt", node.alt); define(this, "match", node.match); define(this, "loc", node.loc); } get siblings() { return this.parent?.nodes || []; } }; // src/nodes/Block.ts var Block = class extends Node { static { __name(this, "Block"); } nodes; constructor(node) { super(node); this.nodes = node.nodes || []; } append(input) { this.parent && this.parent.append(input); this.output = this.output || ""; this.output += input; } push(node) { define(node, "parent", this); this.nodes.push(node); } }; // src/nodes/Location.ts var Position = class { static { __name(this, "Position"); } index; line; col; constructor(loc) { this.index = loc.index; this.line = loc.line; this.col = loc.col; } }; var Location = class { static { __name(this, "Location"); } start; end; constructor(start, end) { this.start = start; this.end = end; } slice(input) { return input.slice(...this.range); } get range() { return [this.start.index, this.end.index]; } get lines() { return [this.start.line, this.end.line]; } }; var location = /* @__PURE__ */ __name((loc) => { const start = new Position(loc); return (node) => { node.loc = new Location(start, new Position(loc)); return node; }; }, "location"); location.Position = Position; location.Location = Location; location.location = location; export { Block, Location, Node, Position, location }; //# sourceMappingURL=index.mjs.map