Skip to content

Commit 7aa0ed1

Browse files
Merge branch 'niftylettuce:master' into master
2 parents 8ce5b6c + ba20ed2 commit 7aa0ed1

File tree

4 files changed

+379
-90
lines changed

4 files changed

+379
-90
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ This is the solution for you if you're just using `<script>` tags everywhere!
9898

9999
Assuming you are using [browserify][], [webpack][], [rollup][], or another bundler, you can simply follow [Node](#node) usage above.
100100

101+
#### TypeScript
102+
103+
To use this package with [TypeScript](https://www.typescriptlang.org/), you can install the [`@types/url-regex-safe`](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/url-regex-safe) package for type definitions.
104+
105+
```sh
106+
npm install --save-dev @types/url-regex-safe
101107

102108
## Options
103109

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "url-regex-safe",
33
"description": "Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661. Works in Node v10.12.0+ and browsers.",
4-
"version": "2.0.2",
4+
"version": "2.1.0",
55
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
66
"browser": {
77
"re2": false
@@ -17,7 +17,7 @@
1717
],
1818
"dependencies": {
1919
"ip-regex": "^4.3.0",
20-
"re2": "^1.15.9",
20+
"re2": "^1.16.0",
2121
"tlds": "^1.217.0"
2222
},
2323
"devDependencies": {

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
const RE2 = require('re2');
21
const ipRegex = require('ip-regex');
32
const tlds = require('tlds');
43

54
/* istanbul ignore next */
6-
const SafeRegExp = typeof RE2 === 'function' ? RE2 : RegExp;
5+
const SafeRegExp = (() => {
6+
try {
7+
const RE2 = require('re2');
8+
return typeof RE2 === 'function' ? RE2 : RegExp;
9+
} catch {
10+
return RegExp;
11+
}
12+
})();
713
const ipv4 = ipRegex.v4().source;
814
const ipv6 = ipRegex.v6().source;
915

0 commit comments

Comments
 (0)