UNPKG

@signatu/common-lib

Version:

Common Javascript/Typescript library for Signatu

57 lines 1.88 kB
"use strict"; // Adapted from https://gist.github.com/franvarney/22776beda2187f670a50 var __values = (this && this.__values) || function (o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchingBraces = function (braces) { var e_1, _a; if (!braces) { return true; } if (typeof braces !== 'string') { throw new Error("matchingBraces: argument must be a string"); } if (braces.length === 1) { return false; } var leftBraces = ['{', '(', '[']; var rightBraces = ['}', ')', ']']; var leftMatches = []; try { for (var braces_1 = __values(braces), braces_1_1 = braces_1.next(); !braces_1_1.done; braces_1_1 = braces_1.next()) { var char = braces_1_1.value; if (leftBraces.includes(char)) { leftMatches.push(char); } if (rightBraces.includes(char)) { if (leftMatches.length === 0) { return false; } var last = leftMatches[leftMatches.length - 1]; if (leftBraces.indexOf(last) === rightBraces.indexOf(char)) { leftMatches.pop(); } else { return false; } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (braces_1_1 && !braces_1_1.done && (_a = braces_1.return)) _a.call(braces_1); } finally { if (e_1) throw e_1.error; } } return leftMatches.length === 0; }; //# sourceMappingURL=braces.js.map