Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Create publicIp default export to return IPv6 (preference) or IPv4 (fallback) #59

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d15b082
Update index.js (Initial PR commit, convert default export to function.
Octalbyte Dec 27, 2021
2691ad5
Add body and logic to publicIp() (non functional)
Octalbyte Dec 27, 2021
93d45c7
Try/catch approach
Octalbyte Dec 27, 2021
4b0ab08
Modifications, add mytest.js to gitignore
Octalbyte Dec 27, 2021
ecdbe67
Gitignore
Octalbyte Dec 27, 2021
48af5a4
Move code block to prevent bugs
Octalbyte Dec 27, 2021
f681fbe
Fixes
Octalbyte Dec 28, 2021
a739e2f
Extend timeout to be the same as defaults.timeout (5000)
Octalbyte Dec 29, 2021
e70d7a6
Extends changes to browser version
Octalbyte Dec 29, 2021
5679627
Remove TODO comment
Octalbyte Dec 29, 2021
5e81e0c
Remove TODO comment
Octalbyte Dec 29, 2021
6744704
Add documentation
Octalbyte Dec 29, 2021
331af4f
.cancel() method
Octalbyte Dec 29, 2021
be00277
Do not reject if only v6 fails
Octalbyte Dec 29, 2021
d1e65fb
Execute onTimeout if v6 fails
Octalbyte Dec 29, 2021
f8d4598
typo
Octalbyte Dec 29, 2021
7cae4fe
Extend to browser.js
Octalbyte Dec 29, 2021
addb262
Turn ontimeout into async
Octalbyte Dec 29, 2021
e7d7016
Ava fixes
Octalbyte Dec 29, 2021
fd339db
Ava fixes
Octalbyte Dec 29, 2021
5f44154
Ava fixes
Octalbyte Dec 29, 2021
5e09da6
ava fixes
Octalbyte Dec 29, 2021
7f91436
ava_fixes
Octalbyte Dec 29, 2021
99c8beb
ava fixes
Octalbyte Dec 29, 2021
d2b0866
Extend fixes for browser.js
Octalbyte Dec 29, 2021
6f73dc5
remove cancel() option :(
Octalbyte Dec 29, 2021
9199c16
Remove 'mytest.js' from gitignore
Octalbyte Jan 26, 2022
25eebc2
API restructure with Promise.any()
Octalbyte Jan 26, 2022
c3df9ef
Add browser tests
Octalbyte Jan 26, 2022
4eef206
Revert changes to gitignore
Octalbyte Jan 30, 2022
ae1b80d
Code style + documentation
Octalbyte Jan 30, 2022
99465c8
Code style
Octalbyte Jan 30, 2022
536495a
Code style for browser-test.js (add semicolon)
Octalbyte Jan 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion browser.js
Expand Up @@ -100,7 +100,12 @@ const queryHttps = (version, options) => {
return promise;
};

const publicIp = {};
const publicIp = options => {
return Promise.any([
publicIp.v4(options),
publicIp.v6(options),
]);
};

publicIp.v4 = options => queryHttps('v4', {...defaults, ...options});

Expand Down
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -228,7 +228,12 @@ const queryAll = (version, options) => {
return promise;
};

const publicIp = {};
const publicIp = (options) => {
return Promise.any([
publicIp.v4(options),
publicIp.v6(options),
]);
};

publicIp.v4 = options => {
options = {
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Expand Up @@ -20,13 +20,16 @@ console.log(await publicIp.v4());

console.log(await publicIp.v6());
//=> 'fe80::200:f8ff:fe21:67cf'

console.log(await publicIp());
//=> 'fe80::200:f8ff:fe21:67cf'
```

## API

### publicIp.v4(options?)
### publicIp.v6(options?)

### publicIp(options?)
Octalbyte marked this conversation as resolved.
Show resolved Hide resolved
Returns a `Promise<string>` with your public IPv4 or IPv6 address. Rejects on error or timeout. A `.cancel()` method is available on the promise, which can be used to cancel the request.

#### options
Expand Down
1 change: 1 addition & 0 deletions test-browser.js
Expand Up @@ -7,3 +7,4 @@ console.log('IP:', await publicIp.v4({
'https://ifconfig.me',
],
}));
console.log('IP:', await publicIp());