-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e919ec1
commit c01aaff
Showing
3 changed files
with
63 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
"version": "1.0.5", | ||
"description": "Get current machine IP.", | ||
"main": "index.js", | ||
"author": "kenny wong <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://jaywcjlove.github.io/local-ip-url", | ||
"scripts": { | ||
"test": "node test/index.js" | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -26,6 +28,7 @@ | |
"ipv6", | ||
"mac" | ||
], | ||
"author": "", | ||
"license": "MIT" | ||
"devDependencies": { | ||
"jest": "^29.5.0" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const localIpUrl = require('..'); | ||
const prepareUrls = require('../prepareUrls'); | ||
|
||
// console.log('IP:', localIpUrl()); | ||
// console.log('IP:', localIpUrl('public')); | ||
// console.log('IP4:', localIpUrl('public', 'ipv4')); | ||
// console.log('IP6:', localIpUrl('public', 'ipv6')); | ||
// console.log('IP:', localIpUrl('private')); | ||
// console.log('IP4:', localIpUrl('private', 'ipv4')); | ||
// console.log('IP6:', localIpUrl('private', 'ipv6')); | ||
|
||
// console.log('prepareUrls:', prepareUrls({ | ||
// protocol: 'http', | ||
// host: '0.0.0.0', | ||
// port: '3000' | ||
// })); | ||
|
||
const REX_IPV6 = /^(((((?!::)[0-9a-fA-F]{1,4}::?(?!:)){0,7}|((?!::)[0-9a-fA-F]{1,4}:){7})((?!::)[0-9a-fA-F]{1,4})|([0-9a-fA-F]{1,4}::([0-9a-fA-F]{1,4}:){0,5})|(::([0-9a-fA-F]{1,4}:){0,6}))|(([0-9a-fA-F]{1,4}:){5}:([0-9a-fA-F]{1,4}))|([0-9a-fA-F]{1,4}:){6}((25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1[0-9]|[1-9])?[0-9]))(\%[\w\d]+)?$/i | ||
|
||
it('test case: localIpUrl() => 192.168.188.18', () => { | ||
expect(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(localIpUrl())).toBeTruthy() | ||
}) | ||
|
||
it('test case: localIpUrl("public") => 192.168.188.18', () => { | ||
expect(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(localIpUrl('public'))).toBeTruthy() | ||
}) | ||
|
||
it('test case: localIpUrl("public", "ipv4") => 192.168.188.18', () => { | ||
expect(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(localIpUrl('public'))).toBeTruthy() | ||
}) | ||
|
||
it('test case: localIpUrl("public", "ipv6") => fe80::4c63:dcff:fe61:5668', () => { | ||
expect(REX_IPV6.test(localIpUrl('public', "ipv6"))).toBeTruthy() | ||
}) | ||
|
||
it('test case: localIpUrl("private") => 127.0.0.1', () => { | ||
expect(localIpUrl('private')).toEqual('127.0.0.1') | ||
}) | ||
|
||
it('test case: localIpUrl("private", "ipv4") => 127.0.0.1', () => { | ||
expect(localIpUrl('private', 'ipv4')).toEqual('127.0.0.1') | ||
}) | ||
|
||
it('test case: localIpUrl("private", "ipv6") => fe80::1', () => { | ||
expect(REX_IPV6.test(localIpUrl('private', "ipv6"))).toBeTruthy() | ||
}) | ||
|
||
it('test case: localIpUrl("private", "ipv6") => fe80::1', () => { | ||
const data = prepareUrls({ | ||
protocol: 'http', | ||
host: '0.0.0.0', | ||
port: '3000' | ||
}) | ||
expect(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(data.ip)).toBeTruthy() | ||
expect(/^http:\/\/localhost:3000\//.test(data.localUrl)).toBeTruthy() | ||
expect(/^(?:https?:\/\/)?([\w.-]+)(?::(\d+))?\/?/i.test(data.localUrl)).toBeTruthy() | ||
}) |