UNPKG

@n3okill/utils

Version:
25 lines 798 B
import { balanced } from "./balanced"; import { isArray } from "../type/isArray"; /** * Return 'false' if input string is unbalanced, otherwise returns an array mapping the chunks of 'open' and 'close' locations * @param input * @param open * @param close * @returns {boolean | BalancedData[]} */ export function balancedData(input, open = "{", close = "}") { const b = balanced(input, open, close); if (isArray(b)) { return b.map((a) => { return { start: a[0], end: a[1], body: input.slice(a[0] + open.length, a[1]), pre: input.slice(0, a[0]), post: input.slice(a[1] + close.length), }; }); } return []; //false; } //# sourceMappingURL=balancedData.js.map