Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

ip-to-array

0.1.0 • Public • Published

IP to Array

Parse an IP address into a Typed Array.

Installation

npm install --save ip-to-array

Usage

const ipToArray = require('ip-to-array')
 
ipToArray('127.0.0.1')
// => [127, 0, 0, 1]
 
ipToArray('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
// => [0x2001, 0x0db8, 0x85a3, 0x0000, 0x0000, 0x8a2e, 0x0370, 0x7334]
 
ipToArray('2001:db8::1')
// => [0x2001, 0x0db8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001]

API

ipToArray(ip: string) => TypedArray

Parse an IP address into a Typed Array. Will return an Uint8Array for IPv4 addresses, and an Uint16Array for IPv6 addresses.

Will throw an error if the input string is not a valid IP address.

Keywords

none

install

npm i ip-to-array

Downloadsweekly downloads

4

version

0.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability