# fast-cidr-match

> Fast tool for checking if an IP is contained within a list of CIDRs/IPs

Latest version **1.0.3** (published 2022-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-cidr-match
pnpm add fast-cidr-match
yarn add fast-cidr-match
bun add fast-cidr-match
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-06-24 |
| First published | 2022-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Friedman |
| Maintainers | ahfriedman |
| Keywords | cidr, ip, address, subnet, ipv4 |

## Links

- npm: https://www.npmjs.com/package/fast-cidr-match
- Repository: https://github.com/ahfriedman/fast-cidr-match
- Issues: https://github.com/ahfriedman/fast-cidr-match/issues
- npm.io page: https://npm.io/package/fast-cidr-match

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-06-24
- 1.0.2 — 2022-06-21
- 1.0.1 — 2022-06-21

## README

# Fast CIDR Matcher

This library determines if a given IPv4 is contained within a list if IP addresses and subnets in approximately O(log n) time—which is much faster than many existing libraries. 

## Installation 

```
npm i fast-cidr-match
```

## API 

### Create a FastCIDRMatcher

```js
const FastCIDRMatcher = require('fast-cidr-match');

//Constructor takes an array of CIDRs/IPv4s
const fastCidrMatcher = new FastCIDRMatcher(['192.168.0.0/16', '172.16.32,80', '10.0.0.0/8']); 
```

### ContainsIP

```js
fastCidrMatcher.containsIP('192.168.1.1') //True
fastCidrMatcher.containsIP('this is not an ip') //False
```

### CompressDatabase
*Note: This feature is somewhat experimental and currently prevents additional data from being added to the match list. May cause a slight performance degredation (< 500ms in 1,000,000 IP benchmark) but makes database approximatley 20% smaller in benchmark.*
```js
fastCidrMatcher.compressDatabase() 
```


## Benchmark 


### 1,000,000 random IPs from a list of over 22,000 subnets

| Library          | Version | Execution time |
| ---------------- | ------- | -------------- |
| FastCIDRMatcher  | `1.0.0` | `2342 ms`      |
| cidr-matcher     | `2.1.1` | `57019 ms`     |

---
_Source: https://npm.io/package/fast-cidr-match · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
