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

Use named exports and allow getting either IPv4 or IPv6 #63

Merged
merged 5 commits into from
Jun 13, 2022

Conversation

Richienb
Copy link
Contributor

@Richienb Richienb commented May 19, 2022

import publicIp, {publicIpv4, publicIpv6} from 'public-ip';

console.log(await publicIpv4());
//=> '46.5.21.123'

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

console.log(await publicIp()); // Falls back to IPv4
//=> 'fe80::200:f8ff:fe21:67cf'

Fixes #45, Fixes #59

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
});
}

test.serial('IPv4 or IPv6', async t => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these were to run concurrently, other tests that stub modules so that they don't work would also affect these.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
}

export function createPublicIp(publicIpv4, publicIpv6) {
return function publicIp(options) { // eslint-disable-line func-names
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is named to improve error messages but xo doesn't allow it to be immediately exported.

image

@Richienb
Copy link
Contributor Author

@sindresorhus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method to get either IPv6 or IPv4
2 participants