diff --git a/netmask/netmask-tests.ts b/netmask/netmask-tests.ts new file mode 100644 index 000000000..519e1722e --- /dev/null +++ b/netmask/netmask-tests.ts @@ -0,0 +1,16 @@ + +/// + +import netmask = require('netmask'); + +var address: string = '127.0.0.1'; + +var nm = new netmask.Netmask(address, '255.255.255.0'); + +var nm2 = new netmask.Netmask('127.0.0.1/255.255.255.0'); + +if (nm.contains('127.0.0.123')) {} + +nm.forEach((ip: string): void => console.log(ip)); + +var adjacent: netmask.Netmask = nm.next(); diff --git a/netmask/netmask.d.ts b/netmask/netmask.d.ts new file mode 100644 index 000000000..32afa25ae --- /dev/null +++ b/netmask/netmask.d.ts @@ -0,0 +1,47 @@ +// Type definitions for Netmask 1.0.5 +// Project: https://github.com/rs/node-netmask +// Definitions by: Matt Frantz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// netmask.d.ts + +declare module 'netmask' { + + export function long2ip(long: number): string; + export function ip2long(ip: string): number; + + export class Netmask { + maskLong: number; + bitmask: number; + netLong: number; + // The number of IP address in the block (eg.: 254) + size: number; + // The address of the network block as a string (eg.: 216.240.32.0) + base: string; + // The netmask as a string (eg.: 255.255.255.0) + mask: string; + // The host mask, the opposite of the netmask (eg.: 0.0.0.255) + hostmask: string; + // The first usable address of the block + first: string; + // The last usable address of the block + last: string; + // The block's broadcast address: the last address of the block (eg.: 192.168.1.255) + broadcast: string; + + constructor (netmask: string); + constructor (net: string, mask: string); + + // Returns true if the given ip or netmask is contained in the block + contains(ip: string | Netmask | number): boolean; + + // Returns the Netmask object for the block which follow this one + next(count?: number): Netmask; + + // Evaluate a function on each IP address + forEach(fn: (ip: string, long: number, index: number) => void): void; + + // Returns the complete netmask formatted as `base/bitmask` + toString(): string; + } +}