From 29306b60a4ed40be5d112f5a267dda16c2125ca2 Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Tue, 28 Aug 2018 14:00:31 -0700 Subject: [PATCH] adds typings for the 'ip-address' package. --- types/ip-address/index.d.ts | 110 ++++++++++++++++++++++++ types/ip-address/ip-address-tests.ts | 121 +++++++++++++++++++++++++++ types/ip-address/tsconfig.json | 19 +++++ types/ip-address/tslint.json | 3 + 4 files changed, 253 insertions(+) create mode 100644 types/ip-address/index.d.ts create mode 100644 types/ip-address/ip-address-tests.ts create mode 100644 types/ip-address/tsconfig.json create mode 100644 types/ip-address/tslint.json diff --git a/types/ip-address/index.d.ts b/types/ip-address/index.d.ts new file mode 100644 index 0000000000..59dbb07d57 --- /dev/null +++ b/types/ip-address/index.d.ts @@ -0,0 +1,110 @@ +// Type definitions for ip-address 5.8 +// Project: https://github.com/beaugunderson/ip-address +// Definitions by: Daniel Byrne +// 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}; diff --git a/types/ip-address/ip-address-tests.ts b/types/ip-address/ip-address-tests.ts new file mode 100644 index 0000000000..76b4e471aa --- /dev/null +++ b/types/ip-address/ip-address-tests.ts @@ -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); diff --git a/types/ip-address/tsconfig.json b/types/ip-address/tsconfig.json new file mode 100644 index 0000000000..79254ab191 --- /dev/null +++ b/types/ip-address/tsconfig.json @@ -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" + ] +} diff --git a/types/ip-address/tslint.json b/types/ip-address/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/ip-address/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}