Skip to content

Instantly share code, notes, and snippets.

@mlippens
Last active June 11, 2020 10:25
Show Gist options
  • Save mlippens/aaad6ffb6759764a65bccd2a47a1dd21 to your computer and use it in GitHub Desktop.
Save mlippens/aaad6ffb6759764a65bccd2a47a1dd21 to your computer and use it in GitHub Desktop.
/// <reference path="node-cidr.d.ts" />
import { cidr } from 'node-cidr';
/**
* Manual copy of node_modules/node-cidr/dist/index.d.ts, slightly edited to make it work correctly with TypeScript.
* An error in the package's configuration makes the types not usable by the compiler.
**/
declare module 'node-cidr' {
export const ip: {
toInt: (ipAddress: string) => number;
toString: (ipInt: number) => string;
commonCidr: (ips: string[]) => string;
toHex: (ip: string | number) => string;
toOctets: (input: string | number) => number[];
toBinary: (ip: string | number) => string;
reverse: (ip: string | number) => string;
previous: (ip: string) => string;
next: (ip: string) => string;
toCidr: (ip: string | number) => string;
validate: (ip: string) => string | null;
};
export const cidr: {
toRange: (cidr: string) => string[];
usable: (cidr: string) => string[];
toIntRange: (cidr: string) => number[];
commonCidr: (cidrs: string[]) => string;
max: (cidr: string) => string;
min: (cidr: string) => string;
count: (cidr: string) => number;
netmask: (cidr: string) => string;
wildcardmask: (cidr: string) => string;
broadcast: (cidr: string) => string;
subnets: (cidr: string, subMask: number, limit: number) => string[];
ips: (cidr: string) => string[];
includes: (cidr: string, ip: string) => boolean;
random: (cidr: string) => string;
next: (cidr: string) => string;
previous: (cidr: string) => string;
address: (ip: string) => string;
mask: (ip: string) => number;
validate: (cidr: string) => string | null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment