Socket
Socket
Sign inDemoInstall

ip-bigint

Package Overview
Dependencies
0
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.2 to 7.1.0

16

index.js

@@ -61,3 +61,3 @@ export const max4 = 2n ** 32n - 1n;

export function stringifyIp({number, version, ipv4mapped, scopeid} = {}) {
export function stringifyIp({number, version, ipv4mapped, scopeid} = {}, {compress = true} = {}) {
if (typeof number !== "bigint") throw new Error(`Expected a BigInt`);

@@ -92,5 +92,11 @@ if (![4, 6].includes(version)) throw new Error(`Invalid version: ${version}`);

}
ip = compressIPv6(ip.split(":"));
if (compress) {
ip = compressIPv6(ip.split(":"));
}
} else {
ip = compressIPv6(parts.map(n => n.toString(16)));
if (compress) {
ip = compressIPv6(parts.map(n => n.toString(16)));
} else {
ip = parts.map(n => n.toString(16)).join(":");
}
}

@@ -106,4 +112,4 @@

export function normalizeIp(ip) {
return stringifyIp(parseIp(ip));
export function normalizeIp(ip, {compress = true} = {}) {
return stringifyIp(parseIp(ip), {compress});
}

@@ -110,0 +116,0 @@

{
"name": "ip-bigint",
"version": "7.0.2",
"version": "7.1.0",
"description": "Convert IPv4 and IPv6 addresses to native BigInt and vice-versa",

@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>",

@@ -33,16 +33,26 @@ # ip-bigint

### stringifyIp({number, version, [ipv4mapped], [scopeid]})
### stringifyIp({number, version, [ipv4mapped], [scopeid]}, [opts])
Convert a object to string. Returns `ip`. For IPv6, `ip` is normalized to the "best representation" all-lowercase shortest possible form.
Convert a parsed object to IP adress string.
### normalizeIp(ip)
`opts`: Options `Object`
- `compress`: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: `true`.
### normalizeIp(ip, [opts])
Round-trip an IP address through `parseIp` and `stringifyIp`, effectively normalizing its representation.
### Constants
`opts`: Options `Object`
- `compress`: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: `true`.
The module exports `max4` and `max6` properties which represent the biggest possible BigInt for IPv4 and IPv6 respectively.
### max4
A `BigInt` value that holds the biggest possible IPv4 address.
### max6
A `BigInt` value that holds the biggest possible IPv6 address.
## License
© [silverwind](https://github.com/silverwind), distributed under BSD licence
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc