Skip to content

Commit

Permalink
make re2 secretly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vicary committed Nov 4, 2021
1 parent fc0028a commit a418940
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"dependencies": {
"ip-regex": "^4.3.0",
"re2": "^1.15.9",
"re2": "^1.16.0",
"tlds": "^1.217.0"
},
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
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 {
return require('re2');
} catch {
return RegExp;
}
})();
const ipv4 = ipRegex.v4().source;
const ipv6 = ipRegex.v6().source;

Expand Down

0 comments on commit a418940

Please sign in to comment.