Skip to content

Commit

Permalink
Merge pull request #7 from analog-nico/patch-1
Browse files Browse the repository at this point in the history
Fallback to RegExp if re2 is not installed
  • Loading branch information
titanism committed Jul 31, 2023
2 parents ff5f36d + e1f3224 commit 4d4d659
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const RE2 = require('re2');
const ipRegex = require('ip-regex');
const tlds = require('tlds');

/* istanbul ignore next */
const SafeRegExp = typeof RE2 === 'function' ? RE2 : RegExp;
const SafeRegExp = (() => {
try {
const RE2 = require('re2');
return typeof RE2 === 'function' ? RE2 : RegExp;
} catch {
return RegExp;
}
})();
const ipv4 = ipRegex.v4().source;
const ipv6 = ipRegex.v6().source;

Expand Down

0 comments on commit 4d4d659

Please sign in to comment.