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

ip-utils

v2.4.0

Published

Library of useful functions related to IP

Downloads

32,627

Readme

Commitizen friendly Build Status codecov npm version

IP Util Functions Library

A library of useful functions related to IP (v4 and v6).

Installation

# Using npm
$ npm install --save ip-utils
# or Using yarn
$ yarn install --save ip-utils
Browser
// Import the Library
import * as ip from 'ip-util';
// Use any of the contained methods
ip.validIp('1.1.1.1');  // True

// Alternatively - import functions selectively
import { validIp } from 'ip-util'
validIp('1.1.1.1'); // True

NodeJS
// Import the Library
const ip = require('ip-util');
// Use any of the contained methods
ip.validIp('1.1.1.1'); // True

Usage

// IP Object
ip('1.1.1.1')
// Can be chained with
ip('1.1.1.1').isValid() // True
ip('1.1.1.1').isReserved() // False
ip('1.1.1.1').isPrivate() // False
ip('1.1.1.1').getOctet(1) // '1'
ip('1.1.1.1').getOctetArray() // ['1', '1', '1', '1']
ip('1.1.1.1').containedBy('1.2.3.4/8') // True

// Subnet Object
subnet('192.168.1.1/24')
// Can be chained with
subnet('192.168.1.1/24').networkAddress() // '192.168.1.0
subnet('192.168.1.1/24').broadcastAddress() // '192.168.1.255
subnet('192.168.1.1/24').firstHost() // '192.168.1.1
subnet('192.168.1.1/24').lastHost() // '192.168.1.254
subnet('192.168.1.1/24').mask() // '255.255.255.0
subnet('192.168.1.1/24').contains('192.168.1.143') // True
subnet('192.168.1.1/24').info()
/* 
{
  networkAddress: '192.168.1.0',
  broadcastAddress: '192.168.1.255',
  numberHosts: 254,
  inclusiveNumberHosts: 256,
  firstHostAddress: '192.168.1.1',
  lastHostAddress: '192.168.1.254',
  mask: '255.255.255.0',
  cidrMask: 24
 }
 */


// All individual Functions
isValidIp('54.34.2.12') // True
isValidIpv4('12.21.2.1') // True
isValidIpv6('fe80:0:0:0:204:61ff:fe9d:f156') // True
toLong('192.168.1.1') //3232235777
fromLong(3232235777) // 192.168.1.1
toString(3232235777) // As Above (deprecated)
isPrivate('2.3.4.5') // False
isReserved('192.168.2.1') // True
getOctetArray('50.11.12.13') // ['50', '11', '12', '13']
getOctet('50.11.12.13', 2) // '11'
cidrInfo('192.168.1.1/24') 
/* 
{
  networkAddress: '192.168.1.0',
  broadcastAddress: '192.168.1.255',
  numberHosts: 254,
  inclusiveNumberHosts: 256,
  firstHostAddress: '192.168.1.1',
  lastHostAddress: '192.168.1.254',
  mask: '255.255.255.0',
  cidrMask: 24
 }
 */
subnetInfo('192.168.1.1', '255.255.255.0') // As above
broadcastAddress('12.13.14.150/25') // '12.13.14.255'
networkAddress('12.13.14.150/25') // '12.13.14.128'
firstHost('12.13.14.150/25') // '12.13.14.129'
lastHost('12.13.14.150/25') // '12.13.14.254'
numberHosts('12.13.14.150/25') // 126
mask('12.13.14.150/25') // '255.255.255.128'
maskToCidr('255.255.255.0') // '24'
cidrToMask('43.23.2.65/27') // 27
contains('192.168.1.0/25', '192.168.1.50') // True

Contributing

Any and contributions are very welcome - be it:

  • features that you implement yourself and then PR back.
  • Ideas/Requests for new features.
  • Suggestions for improvements.

New Functions can be written in src directory and then added as export in src/index.ts Corresponding unit tests can be written in spec directory

Commit Format

The project uses commitizen to standardise commits in format: <type>(<scope>): <subject>

Workflow is as follows:

  1. Mark issue your working with label - Status:In Progress
  2. Implement fix/feature
  3. Submit PR to develop branch
  4. PR will be reviewed/merged
  5. Upon milestones develop will be merged to master
  6. Master commits spawn a CI job to deploy new version to npm

License

ip-utils is released under the MIT license