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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mb-network

v2.0.6

Published

a flexible and powerful network library written in TypeScript

Readme

mb-network

Network Library for Typescript / Javascript

npm version downloads install size

Install

$ npm i mb-network

Documentation

Interfaces

Type Aliases

Functions

Examples

🦄 First steps

It is recommended to always use the functions newIp and newSubnet for creating new Ip's and Subnet's. Although you don't need to.

import { newIp, newSubnet, subnetToString } from 'mb-network'

const ip = newIp('192.168.0.11')
const subnet = newSubnet(ip, 24)

console.log(subnetToString(subnet)) // logs -> 192.168.0.0/24

🔢🔤 About numbers and strings

In mb-network Ip's are stored as a single number. To convert them to the well known readable format e.g. 192.168.0.1 you need to use the function ipToString. It was a design decision to have the subnet functions, such as broadcast, also return the ip as a number (type Ip). This approach opens up more options for further working with the results.

import { newSubnet, broadcast, ipToString } from 'mb-network'

// You can also create a subnet without first creating an ip
const subnet = newSubnet('192.168.0.1', 24)
const broadcastOfSubnet = broadcast(subnet)

console.log(broadcastOfSubnet) // logs -> 3232235775
console.log(ipToString(broadcastOfSubnet)) // logs -> 192.168.0.255

// For example, this allows us to perform the following, offering maximum flexibility.
console.log(broadcastOfSubnet - 10) // logs -> 3232235765
console.log(ipToString(broadcastOfSubnet - 10)) // logs -> 192.168.0.245

🍩 Looping around

A subnet object consists solely of a network address (Ip) and a suffix (number). But what if you need to work with the addresses within the subnet? For this purpose mb-network provides two iterators. A general address iterator newSubnetIter(): SubnetIter and a host address iterator newSubnetHostIter(): SubnetIter This iterators sit on top of a subnet and are not a direct part of it as you may know it from Arrays.

Spreading a subnet

import { newSubnet, newSubnetIter }

const subnet = newSubnet('192.168.0.5', 28)
const iter = newSubnetIter(subnet) // Iterator over all addresses including network address and broadcast

const addresses = [...iter] // Array<Ip>

Classic for..of loop

import { newSubnet, newSubnetHostIter }

const subnet = newSubnet('192.168.0.5', 28)
const iter = newSubnetHostIter(subnet) // Iterator over all host addresses

for (const host of iter) {
  // do something with host address (Ip)
}

Manual consumption

import { newSubnet, newSubnetIter, ipToString }

const subnet = newSubnet('192.168.0.5', 28)
const iter = newSubnetIter(subnet)

// skip first three addresses (for some reason)
iter.next()
iter.next()
iter.next()

// do something with the rest
let result = iter.next();
while (!result.done) {
  const address = result.value
  console.log(ipToString(address))
  result = iter.next();    
}

So exhausting..

Compared to e.g. the Array iterator these iterators will be exhausted after one use. Trying to consume an iterator twice will result in an Error. Although the infinite iterator usage of an Array could be mimicked, we would then lose the classical "manual consumption" method of consuming the iterator.

🤝 Contributing and Getting Involved

Thank you for checking out mb-network! This library is built with the goal of simplifying network-related operations for developers, and we’d love for you to join us in making it even better.

  • Contribute: Found a bug or have an idea for an improvement? Contributions are always welcome! Feel free to submit an issue or open a pull request on our GitHub repository.
  • Build with it: mb-network is designed to be flexible and powerful. If you build something cool using the library, share it with us! We’d love to feature your projects and learn how this library helps you.
  • Stay connected: Got feedback or questions? Open a discussion on our GitHub Discussions. We’re always here to collaborate and help.