Socket
Socket
Sign inDemoInstall

compact-encoding-net

Package Overview
Dependencies
2
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    compact-encoding-net

Compact codecs for net types


Version published
Weekly downloads
2.3K
increased by21.06%
Maintainers
2
Install size
118 kB
Created
Weekly downloads
 

Readme

Source

compact-encoding-net

compact-encoding codecs for net types.

Installation

npm install compact-encoding-net

Codecs

port

Codec for 16 bit port numbers.

const { port } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(port, 8080)
Decoding
cenc.decode(port, buffer)
// 8080

ipv4

Codec for IPv4 addresses.

:warning: The codec is only defined for valid IPv4 addresses.

const { ipv4 } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ipv4, '127.0.0.1')
Decoding
cenc.decode(ipv4, buffer)
// '127.0.0.1'

ipv4Address

Codec for IPv4 addresses plus a port.

const { ipv4Address } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ipv4, { host: '127.0.0.1', port: 8080 })
Decoding
cenc.decode(ipv4Address, buffer)
// { host: '127.0.0.1', port: 8080 }

ipv6

Codec for IPv6 addresses.

:warning: The codec is only defined for valid IPv6 addresses.

const { ipv6 } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ipv6, '::1')
Decoding
cenc.decode(ipv6, buffer)
// '0:0:0:0:0:0:0:1'

ipv6Address

Codec for IPv6 addresses plus a port.

const { ipv6Address } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ipv6Address, { host: '::1', port: 8080 })
Decoding
cenc.decode(ipv6Address, buffer)
// { host: '0:0:0:0:0:0:0:1', port: 8080 }

ip

Codec for dual IPv4/6 addresses.

:warning: The codec is only defined for valid IPv4 and IPv6 addresses.

const { ip } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ip, '::1')
Decoding
cenc.decode(ip, buffer)
// '0:0:0:0:0:0:0:1'

ipAddress

Codec for dual IPv4/6 addresses plus a port.

const { ipAddress } = require('compact-encoding-net')
Encoding
const buffer = cenc.encode(ipAddress, { host: '::1', port: 8080 })
Decoding
cenc.decode(ipv6Address, buffer)
// { host: '0:0:0:0:0:0:0:1', family: 6, port: 8080 }

License

ISC

FAQs

Last updated on 27 Jul 2022

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