UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

44 lines (41 loc) 1.17 kB
const registered = new Map module.exports = { Plugin: require('./plugin'), merge: require('./merge').merge, // fluent API readProject: require('./projectReader').readProject, mvn: { add: require('./mvn').add }, registries: { mta: require('./registries/mta') }, register: (name, plugin) => { registered.set(name, plugin) }, filterStringAsRegex, registered } /** * Turns a filter string with optional meta characters into a regular expression. * If no meta characters are found, the string is treated as an include pattern. * * @param {string} spec the filter string * @returns {RegExp} the regular expression */ function filterStringAsRegex(spec) { if (typeof spec === 'string') { try { if (spec.match(/[\^$|*]/)) { spec = spec.replace(/^\*/, '.*') // * at start would be invalid, so make it a .* return new RegExp(spec, 'i') } else { // no meta chars -> include semantics spec = spec.replace(/\./g, '\\.') // escape literal dot return new RegExp(spec, 'i') } } catch (err) { throw err.message // user error, so cut off stack trace } } return /.*/ }