adds typings for the 'ip-address' package.

This commit is contained in:
Daniel Byrne
2018-08-28 14:00:31 -07:00
parent 98408751da
commit 29306b60a4
4 changed files with 253 additions and 0 deletions

110
types/ip-address/index.d.ts vendored Normal file
View File

@@ -0,0 +1,110 @@
// Type definitions for ip-address 5.8
// Project: https://github.com/beaugunderson/ip-address
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export as namespace ipAddress;
export interface v6Helpers {
spanAllZeroes(s: string): string;
spanAll(s: string, optionalOffset?: number): string;
spanLeadingZeroes(address: string): string;
simpleGroup(addressString: string, offset?: number): string;
}
export interface TeredoObject {
readonly prefix: string;
readonly server4: string;
readonly client4: string;
readonly flags: string;
readonly coneNat: any;
readonly microsoft: {
readonly reserved: any,
readonly universalLocal: any,
readonly groupIndividual: any,
readonly nonce: any,
};
udpPort: string;
}
export interface SixToFourResponse {
readonly prefix: string;
readonly gateway: string;
}
export class Address4 {
constructor(address: string);
static fromHex(hex: string): Address4;
static fromInteger(integer: number): Address4;
static fromBigInteger(bigInteger: any): Address4;
valid: boolean;
address: string;
parsedAddress: string;
groups: number;
v4: boolean;
subnet: string;
subnetMask: number;
isValid(): boolean;
correctForm(): string;
isCorrect(): boolean;
toHex(): string;
toArray(): any;
toGroup6(): string;
bigInteger(): any;
startAddress(): Address4;
startAddressExclusive(): Address4;
endAddress(): Address4;
endAddressExclusive(): Address4;
mask(optionalMask?: number): string;
getBitsBase2(start: number, end: number): string;
isInSubnet(): boolean;
binaryZeroPad(): string;
}
export class Address6 {
constructor(address: string, optionalGroups?: number);
static fromBigInteger(bigInteger: any): Address6;
static fromURL(url: string): Address6;
static fromAddress4(address4: string): Address6;
static fromArpa(arpaFormAddress: string): Address6;
static fromByteArray(bytes: any): Address6;
static fromUnsignedByteArray(bytes: any): Address6;
valid: boolean;
address: string;
groups: number;
v4: boolean;
subnet: string;
subnetMask: number;
microsoftTranscription(): string;
mask(optionalMask?: number): string;
possibleSubnets(optionalSubnetSize?: number): string;
startAddress(): Address6;
startAddressExclusive(): Address6;
endAddress(): Address6;
endAddressExclusive(): Address6;
getScope(): string;
getType(): string;
getBits(start: number, end: number): any;
getBitsBase2(start: number, end: number): string;
getBitsBase16(start: number, end: number): string;
getBitsPastSubnet(): string;
reverseForm(options?: { omitSuffix: boolean }): string;
correctForm(): string;
binaryZeroPad(): string;
canonicalForm(): string;
decimal(): string;
bigInteger(): any;
to4(): string;
to4in6(): string;
inspectTeredo(): TeredoObject;
inspect6to4(): SixToFourResponse;
to6to4(): Address6;
toByteArray(): any;
toUnsignedByteArray(): any;
}
export const v6: {helpers: v6Helpers};

View File

@@ -0,0 +1,121 @@
import ipAddress = require('ip-address');
// Test Address4 Typings
const address4 = new ipAddress.Address4('127.0.0.1');
const address4Valid = address4.valid;
const address4String = address4.address;
const address4Parsed = address4.parsedAddress;
const address4Groups = address4.groups;
const address4v4 = address4.v4;
const address4Subnet = address4.subnet;
const address4Mask = address4.subnetMask;
// $ExpectType Address4
ipAddress.Address4.fromHex('127.0.0.1');
// $ExpectType Address4
ipAddress.Address4.fromInteger(127001);
// $ExpectType Address4
address4.startAddress();
// $ExpectType Address4
address4.startAddressExclusive();
// $ExpectType Address4
address4.endAddress();
// $ExpectType Address4
address4.endAddressExclusive();
// $ExpectType string
address4.correctForm();
// $ExpectType string
address4.toHex();
// $ExpectType string
address4.toGroup6();
// $ExpectType string
address4.mask();
// $ExpectType string
address4.mask(0);
// $ExpectType string
address4.getBitsBase2(0, 1);
// $ExpectType string
address4.binaryZeroPad();
// $ExpectType boolean
address4.isValid();
// $ExpectType boolean
address4.isCorrect();
// $ExpectType boolean
address4.isInSubnet();
// Test Address6 Typings
const address6 = new ipAddress.Address6('127.0.0.1');
const address6Valid = address6.valid;
const address6String = address6.address;
const address6Groups = address6.groups;
const address6v4 = address6.v4;
const address6Subnet = address6.subnet;
const address6Mask = address6.subnetMask;
// $ExpectType Address6
address6.startAddress();
// $ExpectType Address6
address6.startAddressExclusive();
// $ExpectType Address6
address6.endAddress();
// $ExpectType Address6
address6.endAddressExclusive();
// $ExpectType Address6
address6.to6to4();
// $ExpectType string
address6.microsoftTranscription();
// $ExpectType string
address6.mask();
// $ExpectType string
address6.mask(0);
// $ExpectType string
address6.possibleSubnets();
// $ExpectType string
address6.possibleSubnets(1);
// $ExpectType string
address6.getScope();
// $ExpectType string
address6.getType();
// $ExpectType string
address6.getBitsBase2(0, 1);
// $ExpectType string
address6.getBitsBase16(0, 1);
// $ExpectType string
address6.getBitsPastSubnet();
// $ExpectType string
address6.reverseForm();
// $ExpectType string
address6.correctForm();
// $ExpectType string
address6.binaryZeroPad();
// $ExpectType string
address6.canonicalForm();
// $ExpectType string
address6.decimal();
// $ExpectType string
address6.to4();
// $ExpectType string
address6.to4in6();
// $ExpectType TeredoObject
address6.inspectTeredo();
// $ExpectType SixToFourResponse
address6.inspect6to4();
// Test v6 Typings
const v6 = ipAddress.v6;
// $ExpectType string
v6.helpers.simpleGroup(address6.address);
// $ExpectType string
v6.helpers.spanAll(address6.address);
// $ExpectType string
v6.helpers.spanAllZeroes(address6.address);
// $ExpectType string
v6.helpers.spanLeadingZeroes(address6.address);

View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ip-address-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}