npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

network-math

v1.0.7

Published

Simplifies standard networking calculations

Downloads

18

Readme

network-math

Installation

npm install network-math --save

Usage

const nm = require('network-math');

const octet = nm.numToBinary(116, true);
// 01110100
const binary = nm.numToBinary(116, false);
// 1110100
const num = nm.binaryOctetToNum('11010110');
// 214
const maskBinary = nm.cidrToSubnetMask(25, true);
// 255.255.255.128
const mask = nm.cidrToSubnetMask(25, false); 
// 11111111.11111111.11111111.10000000
const ipClass = getNetworkClass(172.27.8.131);
// Class B

API

numToBinary(num, useOctet)

Returns the binary equivalent of an integer. Parameters:

  • num - an integer between 0 and 255, inclusive.
  • useOctet - a boolean
    • if true - adds preceding zeroes to the binary for a complete octet
    • if false - does not add zeroes to the binary

Exceptions:

  • RangeError thrown if num is not between 0 and 255
  • TypeError thrown if num is not an integer
  • TypeError thrown if useOctet is not a boolean

binaryOctetToNum(octet)

Returns the integer equivalent of a binary octet. Parameters:

  • octet - an eight-character binary number

Exceptions:

  • PropertyError thrown if octet is not eight characters long
  • Error thrown if octet has characters besides 0 and 1
  • TypeError thrown if octet is not a string

cidrToSubnetMask(cidr, inBinary)

Returns the subnet mask equivalent of a CIDR. Parameters:

  • cidr - an integer between 0 and 32, inclusive.
  • inBinary - a boolean
    • if true - returns the subnet mask in binary
    • if false - returns the subnet mask using integers

Exceptions:

  • RangeError thrown if num is not between 0 and 32, inclusive
  • TypeError thrown if cidr is not an integer
  • TypeError thrown if inBinary is not a boolean

getNetworkClass(ip)

Returns the class of the network that a provided ipv4 address is in. Parameters:

  • ip -> an ip address (ipv4)

Exceptions:

  • Error thrown if the ip address does not contain the following format: num.num.num.num
    • where num is an integer between 0 and 255, inclusive
  • Error thrown if the ip address does not contain four octets
  • TypeError thrown if mask is not a string */