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

    ip-bigint

Convert IPv4 and IPv6 addresses to native BigInt and vice-versa


Version published
Weekly downloads
26K
decreased by-8.1%
Maintainers
1
Install size
6.18 kB
Created
Weekly downloads
 

Readme

Source

ip-bigint

Convert IPv4 and IPv6 addresses to native BigInt and vice-versa

Usage

import {parseIp, stringifyIp, normalizeIp} from "ip-bigint";

parseIp("2001:db8::");
// => {number: 42540766411282592856903984951653826560n, version: 6}

stringifyIp({number, version});
// => "2001:db8::"

normalizeIp("2001:db8::0:0:1")
// => "2001:db8::1"

API

parseIp(ip)

Parse a IP address string to a object (with null prototype).

For IPv4 returns {number, version}. For IPv6 returns {number, version, [ipv4mapped], [scopeid]}.

There is only rudimentary validation that the passed string is actually an IP address. You are encouraged to validate yourself using modules like ip-regex.

stringifyIp({number, version, [ipv4mapped], [scopeid]}, [opts])

Convert a parsed object to IP adress string.

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.

opts: Options Object

  • compress: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: true.

max4

A BigInt value that holds the biggest possible IPv4 address.

max6

A BigInt value that holds the biggest possible IPv6 address.

License

© silverwind, distributed under BSD licence

FAQs

Last updated on 01 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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