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-cloudy

v0.6.0

Published

Lookup module for checking if an IP is in a cloud service range

Downloads

23

Readme

banner code style: prettier Build Status

Description

Lookup module for checking if an IP is in a cloud service range. Ip ranges for the providers are cached in memory (and optionally written out to file). Ranges will be auto refreshed after a configured interval (1 week by default). If the whois fallback is enabled, the first 100 (this is configurable) ips will be cached using a lru cache.

Version Requirements:

  • versions before 0.2.0 will work with node 8.x
  • version 0.2.0 and above requires >= node v10.18
  • version 0.3.0 and above requires >= node v12.18
  • version 0.5.0 and above requires >= node v12.22
  • version 0.6.0 and above requires >= node v12.22

Installation

$ yarn add ip-cloudy

or

$ npm install ip-cloudy --save

In Node.js:

const IpCloudy = require('ip-cloudy');
const ipc = new IpCloudy({
  whoisFallback: {
    enabled: false, // if true fallback to whois
    cacheConfig: {
      // https://www.npmjs.com/package/lru-cache
      max: 100,
      length: (n, key) => n.length,
    },
  },
  providerCache: {
    name: 'CIDR_RANGE_CACHE', // name of the cache to use
    path: undefined, // cache path, undefined will use flat-cache's default location
    refreshRate: 5000, // milliseconds
    maxAge: 604800000, // milliseconds (1 week). -1 for no maxAge
    writeToFile: true, // save cache to file when its update
  },
  whoisConfig: {
    // config from "whois" package
  },
});
// load ip ranges into cache. using saved file if present,
// else going out and getting the ranges
ipc.init();

console.log(await ipc.check('104.196.27.39')); // -> {"cloud": "gce", "whois": null}
console.log(await ipc.check()); // use public ip or current host

// this will end the cache refresh intervals, so the node process can resolve
// alternatively, you can set providerCache.refreshRate
// to null to disable the refresh intervals
ipc.stopRefresh();

Development

Issues and PR's are always welcome, just follow the prettier.js style guides described below.

Testing

This project uses Ava.js. To run the tests clone the repo, then run:

# clone the repo
$ cd ipCloudy/
#install modules
$ yarn
#run the tests
$ yarn test

Styling

  • Prettier.js for formatting -- configuration can be found in .prettierrc
  • eslint for linting -- the configuration can be found in .eslint.rc.json

Credits

The original concept for this module was laid out in which-cloud.