UNPKG

@n3okill/utils

Version:
28 lines 942 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.balancedData = balancedData; const balanced_1 = require("./balanced"); const isArray_1 = require("../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[]} */ function balancedData(input, open = "{", close = "}") { const b = (0, balanced_1.balanced)(input, open, close); if ((0, isArray_1.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