Skip to content

Commit

Permalink
feat: be possible to skip re2 (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Aug 16, 2023
1 parent ba30cbe commit 7dd62e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ Default: `true`

Ensure the URL provided is validated as a [WHATWG URL](https://nodejs.org/api/url.html#url_the_whatwg_url_api) API compliant.

## Environment Variables

#### METASCRAPER_RE2

Type: `boolean`<br>
Default: `true`

It attemptt to load re2 to use instead of RegExp.

## Benchmark

To give you an idea of how accurate **metascraper** is, here is a comparison of similar libraries:
Expand Down
9 changes: 8 additions & 1 deletion packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const memoizeOne = require('memoize-one').default || require('memoize-one')
const urlRegex = require('url-regex-safe')({ exact: true, parens: true })
const condenseWhitespace = require('condense-whitespace')
const { getExtension: mimeExtension } = require('mime')
const capitalize = require('microsoft-capitalize')
Expand All @@ -19,6 +18,14 @@ const isUri = require('is-uri')
const { URL } = require('url')
const tldts = require('tldts')

const urlRegex = require('url-regex-safe')({
exact: true,
parens: true,
re2: process.env.METASCRAPER_RE2
? process.env.METASCRAPER_RE2 === 'true'
: undefined
})

const {
chain,
eq,
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"re2": "~1.20.1",
"smartquotes": "~2.3.2",
"tldts": "~6.0.12",
"url-regex-safe": "~3.0.0",
"url-regex-safe": "~4.0.0",
"video-extensions": "~1.2.0"
},
"devDependencies": {
Expand Down

0 comments on commit 7dd62e7

Please sign in to comment.