diff --git a/package.json b/package.json index 7901626..aec6c0b 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "dependencies": { "flattie": "~1.1.0", "got": "~11.8.6", - "url-http": "~1.2.0", "whoops": "~4.1.7" }, "devDependencies": { diff --git a/src/factory.js b/src/factory.js index 52fe43a..5fe64a3 100644 --- a/src/factory.js +++ b/src/factory.js @@ -28,15 +28,22 @@ const parseBody = (input, error, url) => { } } +const isURL = url => { + try { + return /^https?:\/\//i.test(new URL(url).href) + } catch (_) { + return false + } +} + const factory = streamResponseType => ({ VERSION, MicrolinkError, - urlHttp, got, flatten }) => { const assertUrl = (url = '') => { - if (!urlHttp(url)) { + if (!isURL(url)) { const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.` throw new MicrolinkError({ status: 'fail', diff --git a/src/lightweight.js b/src/lightweight.js index ed352ae..e1db0a7 100644 --- a/src/lightweight.js +++ b/src/lightweight.js @@ -1,6 +1,5 @@ 'use strict' -const urlHttp = require('url-http/lightweight') const { flattie: flatten } = require('flattie') const { default: ky } = require('ky') @@ -49,7 +48,6 @@ got.stream = (...args) => ky(...args).then(res => res.body) const mql = factory({ MicrolinkError, - urlHttp, got, flatten, VERSION: '__MQL_VERSION__' diff --git a/src/node.js b/src/node.js index 0d83208..611d626 100644 --- a/src/node.js +++ b/src/node.js @@ -1,6 +1,5 @@ const mql = require('./factory')('buffer')({ MicrolinkError: require('whoops')('MicrolinkError'), - urlHttp: require('url-http/lightweight'), got: require('got').extend({ headers: { 'user-agent': undefined } }), flatten: require('flattie').flattie, VERSION: require('../package.json').version