Skip to content

Commit

Permalink
Merge pull request #21 from tuyennhv/tuyen/is_ip_4.0.0
Browse files Browse the repository at this point in the history
chore: migrate to @chainsafe/is-ip
  • Loading branch information
frenchbread authored Nov 13, 2022
2 parents d338fe5 + 90ee0ce commit ab988d1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or
### Usage

```js
const is_ip_private = require('private-ip')
import is_ip_private from 'private-ip'

is_ip_private('10.0.0.0')
// => true
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict'

module.exports = require('./lib').default
import is_ip_private from './lib/index.js'
export default is_ip_private
31 changes: 11 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "private-ip",
"version": "2.3.4",
"description": "Check if IP address is private.",
"main": "index.js",
"exports": "./index.js",
"type": "module",
"types": "lib/index.d.ts",
"repository": {
"type": "git",
Expand Down Expand Up @@ -52,7 +53,10 @@
"dependencies": {
"ip-regex": "^4.3.0",
"ipaddr.js": "^2.0.1",
"is-ip": "^3.1.0",
"@chainsafe/is-ip": "^2.0.1",
"netmask": "^2.0.2"
},
"engines": {
"node": ">=14.16"
}
}
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Netmask } from 'netmask'
import ip_regex from 'ip-regex'
import is_ip from 'is-ip'
import { isValid as is_valid, parse, IPv4 } from 'ipaddr.js'
import { isIP } from '@chainsafe/is-ip'
import ipaddr, { IPv4 } from 'ipaddr.js'
const { isValid: is_valid, parse } = ipaddr

const PRIVATE_IP_RANGES = [
'0.0.0.0/8',
Expand Down Expand Up @@ -62,7 +63,7 @@ export default (ip: string) => {

if (parsed.kind() === 'ipv4') return ipv4_check((parsed as IPv4).toNormalizedString())
else if (parsed.kind() === 'ipv6') return ipv6_check(ip)
} else if (is_ip(ip) && ip_regex.v6().test(ip)) return ipv6_check(ip)
} else if (isIP(ip) && ip_regex.v6().test(ip)) return ipv6_check(ip)

return undefined
}
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava')
const is_ip_private = require('./')
import test from 'ava'
import is_ip_private from './index.js'

const pub_ips = [
'44.37.112.180',
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"declaration": true
}
Expand Down
14 changes: 6 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@chainsafe/is-ip@^2.0.1":
"integrity" "sha512-nqSJ8u2a1Rv9FYbyI8qpDhTYujaKEyLknNrTejLYoSWmdeg+2WB7R6BZqPZYfrJzDxVi3rl6ZQuoaEvpKRZWgQ=="
"resolved" "https://registry.npmjs.org/@chainsafe/is-ip/-/is-ip-2.0.1.tgz"
"version" "2.0.1"

"@nodelib/fs.scandir@2.1.5":
"integrity" "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g=="
"resolved" "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz"
Expand Down Expand Up @@ -554,7 +559,7 @@
"resolved" "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz"
"version" "2.0.4"

"ip-regex@^4.0.0", "ip-regex@^4.3.0":
"ip-regex@^4.3.0":
"integrity" "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q=="
"resolved" "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz"
"version" "4.3.0"
Expand Down Expand Up @@ -603,13 +608,6 @@
dependencies:
"is-extglob" "^2.1.1"

"is-ip@^3.1.0":
"integrity" "sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q=="
"resolved" "https://registry.npmjs.org/is-ip/-/is-ip-3.1.0.tgz"
"version" "3.1.0"
dependencies:
"ip-regex" "^4.0.0"

"is-number@^7.0.0":
"integrity" "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
"resolved" "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz"
Expand Down

0 comments on commit ab988d1

Please sign in to comment.