CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
util.js82 linesDownload Raw Back to dist
1"use strict";2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {3    if (k2 === undefined) k2 = k;4    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });5}) : (function(o, m, k, k2) {6    if (k2 === undefined) k2 = k;7    o[k2] = m[k];8}));9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {10    Object.defineProperty(o, "default", { enumerable: true, value: v });11}) : function(o, v) {12    o["default"] = v;13});14var __importStar = (this && this.__importStar) || function (mod) {15    if (mod && mod.__esModule) return mod;16    var result = {};17    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);18    __setModuleDefault(result, mod);19    return result;20};21Object.defineProperty(exports, "__esModule", { value: true });22exports.tokenizeClass = exports.strToChars = void 0;23const types_1 = require("./types");24const sets = __importStar(require("./sets"));25const CTRL = '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?';26/**27 * Finds character representations in str and convert all to28 * their respective characters.29 *30 * @param {string} str31 * @returns {string}32 */33exports.strToChars = (str) => {34    const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;35    return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {36        if (lbs) {37            return s;38        }39        let code = b ? 8 :40            a16 ? parseInt(a16, 16) :41                b16 ? parseInt(b16, 16) :42                    dctrl ? CTRL.indexOf(dctrl) : {43                        0: 0,44                        t: 9,45                        n: 10,46                        v: 11,47                        f: 12,48                        r: 13,49                    }[eslsh];50        let c = String.fromCharCode(code);51        // Escape special regex characters.52        return /[[\]{}^$.|?*+()]/.test(c) ? `\\${c}` : c;53    });54};55/**56 * Turns class into tokens57 * reads str until it encounters a ] not preceeded by a \58 *59 * @param {string} str60 * @param {string} regexpStr61 * @returns {Array.<Array.<Object>, number>}62 */63exports.tokenizeClass = (str, regexpStr) => {64    var _a, _b, _c, _d, _e, _f, _g;65    let tokens = [], rs, c;66    const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;67    while ((rs = regexp.exec(str)) !== null) {68        const p = (_g = (_f = (_e = (_d = (_c = (_b = (_a = (rs[1] && sets.words())) !== null && _a !== void 0 ? _a : (rs[2] && sets.ints())) !== null && _b !== void 0 ? _b : (rs[3] && sets.whitespace())) !== null && _c !== void 0 ? _c : (rs[4] && sets.notWords())) !== null && _d !== void 0 ? _d : (rs[5] && sets.notInts())) !== null && _e !== void 0 ? _e : (rs[6] && sets.notWhitespace())) !== null && _f !== void 0 ? _f : (rs[7] && {69            type: types_1.types.RANGE,70            from: (rs[8] || rs[9]).charCodeAt(0),71            to: (c = rs[10]).charCodeAt(c.length - 1),72        })) !== null && _g !== void 0 ? _g : ((c = rs[16]) && { type: types_1.types.CHAR, value: c.charCodeAt(0) });73        if (p) {74            tokens.push(p);75        }76        else {77            return [tokens, regexp.lastIndex];78        }79    }80    throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated character class`);81};82//# sourceMappingURL=util.js.map