Skip to content

Commit

Permalink
chore: drop url-http
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 30, 2024
1 parent 5d7def2 commit f548362
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"dependencies": {
"flattie": "~1.1.0",
"got": "~11.8.6",
"url-http": "~1.2.0",
"whoops": "~4.1.7"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions src/lightweight.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const urlHttp = require('url-http/lightweight')
const { flattie: flatten } = require('flattie')
const { default: ky } = require('ky')

Expand Down Expand Up @@ -49,7 +48,6 @@ got.stream = (...args) => ky(...args).then(res => res.body)

const mql = factory({
MicrolinkError,
urlHttp,
got,
flatten,
VERSION: '__MQL_VERSION__'
Expand Down
1 change: 0 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit f548362

Please sign in to comment.