UNPKG

st-bundle

Version:

CLI for watching and bundling SpringType projects.

47 lines (46 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils/utils"); const CACHED_PATHS = {}; function testPath(input, target) { if (typeof target === 'string') { if (!CACHED_PATHS[target]) { CACHED_PATHS[target] = simplifiedRegExp(target); } return CACHED_PATHS[target].test(input); } return target.test(input); } exports.testPath = testPath; function parsePluginOptions(a, b, defaultValue) { const opts = b ? b : typeof a === 'object' ? a : defaultValue; const rex = b || typeof a === 'string' || utils_1.isRegExp(a) ? simplifiedRegExp(a) : undefined; return [opts, rex]; } exports.parsePluginOptions = parsePluginOptions; function simplifiedRegExp(input) { if (!input) { return; } if (typeof input === 'string') { let r = ''; for (let i = 0; i < input.length; i++) { switch (input[i]) { case '.': r += '\\.'; break; case '/': r += '(\\/|\\\\)'; break; case '*': r += '.*'; break; default: r += input[i]; } } return new RegExp(r); } return input; } exports.simplifiedRegExp = simplifiedRegExp;