knip
Version:
Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects
5 lines (4 loc) • 344 B
JavaScript
const isRegexLikeMatch = /[*+\\(|{^$]/;
const isRegexLike = (value) => isRegexLikeMatch.test(value);
export const toRegexOrString = (value) => typeof value === 'string' && isRegexLike(value) ? new RegExp(value) : value;
export const findMatch = (haystack, needle) => haystack.find(n => (typeof n === 'string' ? n === needle : n.test(needle)));