Skip to content

Commit

Permalink
Merge branch 'niftylettuce:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrsavitski committed Nov 23, 2021
2 parents 8ce5b6c + ba20ed2 commit 7aa0ed1
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 90 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -98,6 +98,12 @@ This is the solution for you if you're just using `<script>` tags everywhere!

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

#### TypeScript

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.

```sh
npm install --save-dev @types/url-regex-safe

## Options

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "url-regex-safe",
"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.",
"version": "2.0.2",
"version": "2.1.0",
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
"browser": {
"re2": false
Expand All @@ -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
10 changes: 8 additions & 2 deletions src/index.js
@@ -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 7aa0ed1

Please sign in to comment.