ipaddr.js.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. declare module "ipaddr.js" {
  2. type IPv4Range = 'unicast' | 'unspecified' | 'broadcast' | 'multicast' | 'linkLocal' | 'loopback' | 'carrierGradeNat' | 'private' | 'reserved';
  3. type IPv6Range = 'unicast' | 'unspecified' | 'linkLocal' | 'multicast' | 'loopback' | 'uniqueLocal' | 'ipv4Mapped' | 'rfc6145' | 'rfc6052' | '6to4' | 'teredo' | 'reserved';
  4. interface RangeList<T> {
  5. [name: string]: [T, number] | [T, number][];
  6. }
  7. // Common methods/properties for IPv4 and IPv6 classes.
  8. class IP {
  9. prefixLengthFromSubnetMask(): number | null;
  10. toByteArray(): number[];
  11. toNormalizedString(): string;
  12. toString(): string;
  13. }
  14. namespace Address {
  15. export function isValid(addr: string): boolean;
  16. export function fromByteArray(bytes: number[]): IPv4 | IPv6;
  17. export function parse(addr: string): IPv4 | IPv6;
  18. export function parseCIDR(mask: string): [IPv4 | IPv6, number];
  19. export function process(addr: string): IPv4 | IPv6;
  20. export function subnetMatch(addr: IPv4, rangeList: RangeList<IPv4>, defaultName?: string): string;
  21. export function subnetMatch(addr: IPv6, rangeList: RangeList<IPv6>, defaultName?: string): string;
  22. export class IPv4 extends IP {
  23. static broadcastAddressFromCIDR(addr: string): IPv4;
  24. static isIPv4(addr: string): boolean;
  25. static isValidFourPartDecimal(addr: string): boolean;
  26. static isValid(addr: string): boolean;
  27. static networkAddressFromCIDR(addr: string): IPv4;
  28. static parse(addr: string): IPv4;
  29. static parseCIDR(addr: string): [IPv4, number];
  30. static subnetMaskFromPrefixLength(prefix: number): IPv4;
  31. constructor(octets: number[]);
  32. octets: number[]
  33. kind(): 'ipv4';
  34. match(addr: IPv4, bits: number): boolean;
  35. match(mask: [IPv4, number]): boolean;
  36. range(): IPv4Range;
  37. subnetMatch(rangeList: RangeList<IPv4>, defaultName?: string): string;
  38. toIPv4MappedAddress(): IPv6;
  39. }
  40. export class IPv6 extends IP {
  41. static broadcastAddressFromCIDR(addr: string): IPv6;
  42. static isIPv6(addr: string): boolean;
  43. static isValid(addr: string): boolean;
  44. static parse(addr: string): IPv6;
  45. static parseCIDR(addr: string): [IPv6, number];
  46. static subnetMaskFromPrefixLength(prefix: number): IPv6;
  47. constructor(parts: number[]);
  48. parts: number[]
  49. zoneId?: string
  50. isIPv4MappedAddress(): boolean;
  51. kind(): 'ipv6';
  52. match(addr: IPv6, bits: number): boolean;
  53. match(mask: [IPv6, number]): boolean;
  54. range(): IPv6Range;
  55. subnetMatch(rangeList: RangeList<IPv6>, defaultName?: string): string;
  56. toIPv4Address(): IPv4;
  57. }
  58. }
  59. export = Address;
  60. }