Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cidr-tools

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cidr-tools - npm Package Compare versions

Comparing version 6.2.1 to 6.3.0

31

index.d.ts

@@ -9,15 +9,22 @@ type IPv4Address = string;

interface CIDRTools {
merge(networks: Networks): Network[];
exclude(baseNetworks: Networks, excludeNetworks: Networks): Network[];
expand(networks: Networks): Network[];
overlap(networksA: Networks, networksB: Networks): boolean;
normalize(cidr: Networks): Networks;
contains(networksA: Networks, networksB: Networks): boolean;
}
type Parsed = {
cidr: string;
version: number;
prefix: string;
start: bigint;
end: bigint;
single: boolean;
};
declare const cidrTools : CIDRTools;
type NormalizeOpts = {
compress?: boolean;
hexify?: boolean;
};
declare module "cidr-tools" {
export = cidrTools;
}
export function merge(networks: Networks): Network[];
export function exclude(baseNetworks: Networks, excludeNetworks: Networks): Network[];
export function expand(networks: Networks): Network[];
export function overlap(networksA: Networks, networksB: Networks): boolean;
export function normalize(cidr: Networks, opts?: NormalizeOpts): Networks;
export function contains(networksA: Networks, networksB: Networks): boolean;
export function parse(network: Network): Parsed;

@@ -13,3 +13,3 @@ import ipRegex from "ip-regex";

function isIP(ip) {
export function isIP(ip) {
if (ipRegex.v4({exact: true}).test(ip)) return 4;

@@ -45,5 +45,7 @@ if (ipRegex.v6({exact: true}).test(ip)) return 6;

function parse(str) {
export function parse(str) {
const cidrVersion = isCidr(str);
const parsed = Object.create(null);
parsed.single = false;
if (cidrVersion) {

@@ -50,0 +52,0 @@ parsed.cidr = str;

{
"name": "cidr-tools",
"version": "6.2.1",
"version": "6.3.0",
"author": "silverwind <me@silverwind.io>",

@@ -17,4 +17,4 @@ "description": "Tools to work with IPv4 and IPv6 CIDR",

"files": [
"index.js",
"index.d.ts"
"./index.js",
"./index.d.ts"
],

@@ -30,2 +30,3 @@ "dependencies": {

"eslint-config-silverwind": "73.0.2",
"tsd": "0.28.1",
"updates": "14.1.1",

@@ -32,0 +33,0 @@ "versions": "11.0.1",

@@ -14,3 +14,3 @@ # cidr-tools

```js
import {merge, exclude, expand, overlap, contains, normalize} from 'cidr-tools';
import {merge, exclude, expand, overlap, contains, normalize, parse} from 'cidr-tools';

@@ -23,2 +23,3 @@ merge(['1.0.0.0/24', '1.0.1.0/24']); //=> ['1.0.0.0/23']

normalize('::ffff/64') //=> '::/64'
parse('::/64'); // => {cidr: '::/64', version: 6, prefix: '64', start: 0n, end: 18446744073709551615n}
```

@@ -75,2 +76,17 @@

### parse(network)
- `network` *String*: A CIDR or IP address.
Returns a `parsed` Object. Specifically, this can be used to test whether the passed CIDR or IP is IPv4 or IPv6.
`parsed`: `Object`
- `cidr` String: The CIDR of the network.
- `version` Number: Either `4` or `6`.
- `prefix` String: The network prefix, e.g. `/64`.
- `start` BigInt: Start of the network.
- `end` BigInt: Start of the network.
- `single` Boolean: `true` when is a single IP.
© [silverwind](https://github.com/silverwind), distributed under BSD licence.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc