fixes null pattern in validateRegExp util function

This commit is contained in:
Seyi Adebajo 2018-06-17 01:16:00 -07:00
parent f9253623df
commit ff41815f63

View File

@ -13,11 +13,11 @@ const emptyRegexSource = '(?:)';
*/
const validateRegExp = (
pattern: string,
customChecker?: (pattern: string) => boolean
customChecker?: (pattern: any) => boolean
): { isValid: boolean; regExp: RegExp } => {
const regExp = new RegExp(pattern);
const { source } = regExp;
const isValid = source !== emptyRegexSource;
const isValid = !!pattern && source !== emptyRegexSource;
if (isValid && customChecker && customChecker(pattern)) {
return { isValid, regExp };