UNPKG

@n3okill/utils

Version:
20 lines 898 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.balancedCounter = balancedCounter; const escapeRegExp_1 = require("./escapeRegExp"); /** * Check if the number of occurrences of the 'open' string are the same of ths 'close' string in the input string * @param input * @param open * @param close * @returns */ function balancedCounter(input, open = "{", close = "}") { //Can't use regexp.exec because of the "g" flag // eslint-disable-next-line security/detect-non-literal-regexp const openNumber = (input.match(new RegExp((0, escapeRegExp_1.escapeRegExp)(open), "g")) || []).length; // eslint-disable-next-line security/detect-non-literal-regexp const closeNumber = (input.match(new RegExp((0, escapeRegExp_1.escapeRegExp)(close), "g")) || []).length; return openNumber === closeNumber; } //# sourceMappingURL=balancedCounter.js.map