eslint-plugin-perfectionist
Version:
ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
23 lines (22 loc) • 806 B
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
let regexByTsconfigPathCache = /* @__PURE__ */ new Map()
let matchesTsconfigPaths = ({ tsConfigOutput, name }) => {
if (!tsConfigOutput.compilerOptions.paths) {
return false
}
return Object.keys(tsConfigOutput.compilerOptions.paths).some(key =>
getRegexByTsconfigPath(key).test(name),
)
}
let getRegexByTsconfigPath = path => {
let existingRegex = regexByTsconfigPathCache.get(path)
if (existingRegex) {
return existingRegex
}
let regex = new RegExp(`^${escapeRegExp(path).replaceAll('*', '(.+)')}$`)
regexByTsconfigPathCache.set(path, regex)
return regex
}
let escapeRegExp = value => value.replaceAll(/[$+.?[\\\]]/gu, String.raw`\$&`)
exports.matchesTsconfigPaths = matchesTsconfigPaths