@sap/eslint-plugin-cds
Version:
ESLint plugin including recommended SAP Cloud Application Programming model and environment rules
26 lines (21 loc) • 548 B
JavaScript
const { FILES, MODEL_FILES } = require('../constants')
const regexByFileType = {
FILES: globArrayToRegex(FILES),
MODEL_FILES: globArrayToRegex(MODEL_FILES)
}
/**
* Checks whether the given filePath matches a regex `files`
* @param {string} filePath
* @param {string} fileType
* @returns boolean
*/
module.exports = (filePath, fileType) => {
return regexByFileType[fileType].test(filePath)
}
/**
* @param arr
*/
function globArrayToRegex (arr) {
return new RegExp(`${arr.map(e => e.replace('*', '')).join('$|')}$`)
}