eslint-plugin-i18next
Version:
ESLint plugin for i18n
11 lines (10 loc) • 335 B
JavaScript
module.exports = function generateFullMatchRegExp(source) {
if (source instanceof RegExp) {
return source;
}
if (typeof source !== 'string') {
throw new Error('generateFullMatchRegExp: expect string but get', source);
}
// allow dot ahead
return new RegExp(`(^|\\.)${source}${source.endsWith('$') ? '' : '$'}`);
};