forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR DefinitelyTyped#64428 Update types for 'netmask' package by …
…@JanST123 * add types for netmask package * satisfy the tests * applied some advises from the bot standardized tsling.json, restore previous definition owner (sorry)
- Loading branch information
Showing
3 changed files
with
68 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,75 @@ | ||
// Type definitions for Netmask 1.0.5 | ||
// Type definitions for netmask 2.0 | ||
// Project: https://github.com/rs/node-netmask | ||
// Definitions by: Matt Frantz <https://github.com/mhfrantz> | ||
// JanST123 <https://github.com/JanST123> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
// netmask.d.ts | ||
/** | ||
* converts long to an ip address | ||
*/ | ||
export function long2ip(long: number): string; | ||
/** | ||
* converts ip address to long | ||
*/ | ||
export function ip2long(ip: string): number; | ||
|
||
|
||
|
||
export declare function long2ip(long: number): string; | ||
export declare function ip2long(ip: string): number; | ||
|
||
export declare 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) | ||
export class Netmask { | ||
/** | ||
* The base address of the network block as a string (eg: 216.240.32.0). Base does not give an indication of the size of the network block. | ||
*/ | ||
base: string; | ||
// The netmask as a string (eg.: 255.255.255.0) | ||
/** | ||
* 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) | ||
/** | ||
* The netmask as a number of bits in the network portion of the address for this block (eg: 24). | ||
*/ | ||
bitmask: number; | ||
/** | ||
* The host mask which is the opposite of the netmask (eg: 0.0.0.255). | ||
*/ | ||
hostmask: string; | ||
// The first usable address of the block | ||
/** | ||
* The blocks broadcast address (eg: 192.168.1.0/24 => 192.168.1.255) | ||
*/ | ||
broadcast: string; | ||
/** | ||
* The number of IP addresses in a block (eg: 256). | ||
*/ | ||
size: number; | ||
/** | ||
* First useable address | ||
*/ | ||
first: string; | ||
// The last usable address of the block | ||
/** | ||
* Last useable address | ||
*/ | ||
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 a true if the IP number ip is part of the network. That is, a true value is returned if ip is between base and broadcast. | ||
* If a Netmask object or a block is given, it returns true only of the given block fits inside the network. | ||
*/ | ||
contains: (address: string | Netmask | number) => boolean; | ||
/** | ||
* Similar to the Array prototype method. It loops through all the useable addresses, ie between first and last. | ||
*/ | ||
forEach: (cb: (ip: string, long: number, index: number) => void) => void; | ||
/** | ||
* Without a count, return the next block of the same size after the current one. With a count, return the Nth block after the current one. | ||
* A count of -1 returns the previous block. Undef will be returned if out of legal address space. | ||
*/ | ||
next: (count?: number) => Netmask; | ||
/** | ||
* The netmask in base/bitmask format (e.g., '216.240.32.0/24') | ||
*/ | ||
toString: () => string; | ||
|
||
// Returns the complete netmask formatted as `base/bitmask` | ||
toString(): string; | ||
/** | ||
* | ||
* @param net A network - e.g 216.240.32.0/24 | ||
* @param mask - optional netmask if not provided in `net` | ||
*/ | ||
constructor(net: string, mask?: string); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
|
||
|
||
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)); | ||
const block = new netmask.Netmask('10.0.0.0/12'); | ||
console.log('base', block.base); | ||
|
||
var adjacent: netmask.Netmask = nm.next(); | ||
if (block.contains('10.0.8.10')) { | ||
console.log('block contains 10.0.8.10'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
{ | ||
"extends": "@definitelytyped/dtslint/dt.json", | ||
"rules": { | ||
"no-consecutive-blank-lines": false, | ||
"no-inferrable-types": false, | ||
"no-var-keyword": false, | ||
"prefer-const": false, | ||
"strict-export-declare-modifiers": false, | ||
"unified-signatures": false | ||
} | ||
"extends": "@definitelytyped/dtslint/dt.json" | ||
} |