Skip to content

Instantly share code, notes, and snippets.

@mlippens
Last active June 11, 2020 10:25

Revisions

  1. mlippens revised this gist Jun 11, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions example.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    /// <reference path="node-cidr.d.ts" />
    import { cidr } from 'node-cidr';
  2. mlippens created this gist Jun 11, 2020.
    40 changes: 40 additions & 0 deletions node-cidr.d.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    /**
    * 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;
    };
    }