Skip to content
New issue

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

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

Already on GitHub? # to your account

refactor: use is-local-address #379

Merged
merged 2 commits into from
Feb 15, 2025
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
2 changes: 1 addition & 1 deletion packages/hover-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"dependencies": {
"@microlink/hover-react": "^5.5.22",
"localhost-url-regex": "~1.0.4"
"is-local-address": "~2.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "latest",
Expand Down
7 changes: 5 additions & 2 deletions packages/hover-vanilla/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MicrolinkHover from '@microlink/hover-react'
import localhostUrl from 'localhost-url-regex'
import isLocalAddress from 'is-local-address'
import { createRoot } from 'react-dom'
import styled from 'styled-components'
import React from 'react'
Expand All @@ -16,7 +16,10 @@ function toArray (input) {
el.href = new URL(el.href).toString()
return el
})
.filter(el => el.href.startsWith('http') && !localhostUrl().test(el.href))
.filter(el => {
const { protocol, hostname } = new URL(el.href)
return protocol === 'http:' && !isLocalAddress(hostname)
})
}

function parseJSON (value) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"dependencies": {
"@microlink/mql": "~0.13.4",
"localhost-url-regex": "~1.0.4",
"is-local-address": "~2.0.0",
"nanoclamp": "~2.0.4"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchFromApi, getApiUrl as createApiUrl } from '@microlink/mql'
import localhostUrl from 'localhost-url-regex'
import isLocalAddress from 'is-local-address'
import { css } from 'styled-components'

export const isSSR = typeof window === 'undefined'
Expand Down Expand Up @@ -81,7 +81,7 @@ export const isLarge = cardSize => cardSize === 'large'
export const isSmall = cardSize => cardSize === 'small'

export const imageProxy = url =>
localhostUrl().test(url)
isLocalAddress(new URL(url).hostname)
? url
: `https://images.weserv.nl/?${new URLSearchParams({
url,
Expand Down
Loading
Loading