Skip to content

Commit

Permalink
Update TypeScript definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
claasahl authored and whitequark committed Jun 25, 2019
1 parent 8bd045f commit a3a0bcc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ addr.octets // => [192, 168, 1, 1]
```

`prefixLengthFromSubnetMask()` will return a CIDR prefix length for a valid IPv4 netmask or
false if the netmask is not valid.
null if the netmask is not valid.

```js
ipaddr.IPv4.parse('255.255.255.240').prefixLengthFromSubnetMask() == 28
Expand Down
15 changes: 6 additions & 9 deletions lib/ipaddr.js.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@


declare module "ipaddr.js" {

type IPv4Range = 'unicast' | 'unspecified' | 'broadcast' | 'multicast' | 'linkLocal' | 'loopback' | 'carrierGradeNat' | 'private' | 'reserved';
type IPv6Range = 'unicast' | 'unspecified' | 'linkLocal' | 'multicast' | 'loopback' | 'uniqueLocal' | 'ipv4Mapped' | 'rfc6145' | 'rfc6052' | '6to4' | 'teredo' | 'reserved';

interface RangeList<T> {
[name: string]: [T, number] | [T, number][];
}


// Common methods/properties for IPv4 and IPv6 classes.
class IP {

prefixLengthFromSubnetMask(): number | false;
prefixLengthFromSubnetMask(): number | null;
toByteArray(): number[];
toNormalizedString(): string;
toString(): string;
}

namespace Address {

export function isValid(addr: string): boolean;
export function fromByteArray(bytes: number[]): IPv4 | IPv6;
export function parse(addr: string): IPv4 | IPv6;
export function parseCIDR(mask: string): [IPv4 | IPv6, number];
export function process(address: string): IPv4 | IPv6;
export function process(addr: string): IPv4 | IPv6;
export function subnetMatch(addr: IPv4, rangeList: RangeList<IPv4>, defaultName?: string): string;
export function subnetMatch(addr: IPv6, rangeList: RangeList<IPv6>, defaultName?: string): string;

Expand All @@ -39,6 +33,7 @@ declare module "ipaddr.js" {
static parseCIDR(addr: string): [IPv4, number];
static subnetMaskFromPrefixLength(prefix: number): IPv4;
constructor(octets: number[]);
octets: number[]

kind(): 'ipv4';
match(addr: IPv4, bits: number): boolean;
Expand All @@ -55,7 +50,9 @@ declare module "ipaddr.js" {
static parse(addr: string): IPv6;
static parseCIDR(addr: string): [IPv6, number];
static subnetMaskFromPrefixLength(prefix: number): IPv6;
constructor(octets: number[]);
constructor(parts: number[]);
parts: number[]
zoneId?: string

isIPv4MappedAddress(): boolean;
kind(): 'ipv6';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {},
"devDependencies": {
"coffee-script": "~1.12.6",
"uglify-js": "~3.0.19",
"nodeunit": ">=0.8.2 <0.8.7"
"nodeunit": "^0.11.3",
"uglify-js": "~3.0.19"
},
"scripts": {
"test": "cake build test"
Expand Down

0 comments on commit a3a0bcc

Please sign in to comment.