Skip to content

Commit 597220b

Browse files
authored
refactor: use is-local-address (#379)
* refactor: use is-local-address * build: add lockfile
1 parent 0b9bff8 commit 597220b

File tree

5 files changed

+26532
-6
lines changed

5 files changed

+26532
-6
lines changed

packages/hover-vanilla/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
"dependencies": {
2929
"@microlink/hover-react": "^5.5.22",
30-
"localhost-url-regex": "~1.0.4"
30+
"is-local-address": "~2.0.0"
3131
},
3232
"devDependencies": {
3333
"@rollup/plugin-commonjs": "latest",

packages/hover-vanilla/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MicrolinkHover from '@microlink/hover-react'
2-
import localhostUrl from 'localhost-url-regex'
2+
import isLocalAddress from 'is-local-address'
33
import { createRoot } from 'react-dom'
44
import styled from 'styled-components'
55
import React from 'react'
@@ -16,7 +16,10 @@ function toArray (input) {
1616
el.href = new URL(el.href).toString()
1717
return el
1818
})
19-
.filter(el => el.href.startsWith('http') && !localhostUrl().test(el.href))
19+
.filter(el => {
20+
const { protocol, hostname } = new URL(el.href)
21+
return protocol === 'http:' && !isLocalAddress(hostname)
22+
})
2023
}
2124

2225
function parseJSON (value) {

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"dependencies": {
2727
"@microlink/mql": "~0.13.4",
28-
"localhost-url-regex": "~1.0.4",
28+
"is-local-address": "~2.0.0",
2929
"nanoclamp": "~2.0.4"
3030
},
3131
"devDependencies": {

packages/react/src/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fetchFromApi, getApiUrl as createApiUrl } from '@microlink/mql'
2-
import localhostUrl from 'localhost-url-regex'
2+
import isLocalAddress from 'is-local-address'
33
import { css } from 'styled-components'
44

55
export const isSSR = typeof window === 'undefined'
@@ -81,7 +81,7 @@ export const isLarge = cardSize => cardSize === 'large'
8181
export const isSmall = cardSize => cardSize === 'small'
8282

8383
export const imageProxy = url =>
84-
localhostUrl().test(url)
84+
isLocalAddress(new URL(url).hostname)
8585
? url
8686
: `https://images.weserv.nl/?${new URLSearchParams({
8787
url,

0 commit comments

Comments
 (0)