Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: be possible to skip re2 #656

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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