ipv6.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import * as common from './common';
  2. import { Address4 } from './ipv4';
  3. interface SixToFourProperties {
  4. prefix: string;
  5. gateway: string;
  6. }
  7. interface TeredoProperties {
  8. prefix: string;
  9. server4: string;
  10. client4: string;
  11. flags: string;
  12. coneNat: boolean;
  13. microsoft: {
  14. reserved: boolean;
  15. universalLocal: boolean;
  16. groupIndividual: boolean;
  17. nonce: string;
  18. };
  19. udpPort: string;
  20. }
  21. /**
  22. * Represents an IPv6 address
  23. * @class Address6
  24. * @param {string} address - An IPv6 address string
  25. * @param {number} [groups=8] - How many octets to parse
  26. * @example
  27. * var address = new Address6('2001::/32');
  28. */
  29. export declare class Address6 {
  30. address4?: Address4;
  31. address: string;
  32. addressMinusSuffix: string;
  33. elidedGroups?: number;
  34. elisionBegin?: number;
  35. elisionEnd?: number;
  36. groups: number;
  37. parsedAddress4?: string;
  38. parsedAddress: string[];
  39. parsedSubnet: string;
  40. subnet: string;
  41. subnetMask: number;
  42. v4: boolean;
  43. zone: string;
  44. constructor(address: string, optionalGroups?: number);
  45. static isValid(address: string): boolean;
  46. /**
  47. * Convert a BigInt to a v6 address object
  48. * @memberof Address6
  49. * @static
  50. * @param {bigint} bigInt - a BigInt to convert
  51. * @returns {Address6}
  52. * @example
  53. * var bigInt = BigInt('1000000000000');
  54. * var address = Address6.fromBigInt(bigInt);
  55. * address.correctForm(); // '::e8:d4a5:1000'
  56. */
  57. static fromBigInt(bigInt: bigint): Address6;
  58. /**
  59. * Convert a URL (with optional port number) to an address object
  60. * @memberof Address6
  61. * @static
  62. * @param {string} url - a URL with optional port number
  63. * @example
  64. * var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
  65. * addressAndPort.address.correctForm(); // 'ffff::'
  66. * addressAndPort.port; // 8080
  67. */
  68. static fromURL(url: string): {
  69. error: string;
  70. address: null;
  71. port: null;
  72. } | {
  73. address: Address6;
  74. port: number | null;
  75. error?: undefined;
  76. };
  77. /**
  78. * Create an IPv6-mapped address given an IPv4 address
  79. * @memberof Address6
  80. * @static
  81. * @param {string} address - An IPv4 address string
  82. * @returns {Address6}
  83. * @example
  84. * var address = Address6.fromAddress4('192.168.0.1');
  85. * address.correctForm(); // '::ffff:c0a8:1'
  86. * address.to4in6(); // '::ffff:192.168.0.1'
  87. */
  88. static fromAddress4(address: string): Address6;
  89. /**
  90. * Return an address from ip6.arpa form
  91. * @memberof Address6
  92. * @static
  93. * @param {string} arpaFormAddress - an 'ip6.arpa' form address
  94. * @returns {Adress6}
  95. * @example
  96. * var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
  97. * address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
  98. */
  99. static fromArpa(arpaFormAddress: string): Address6;
  100. /**
  101. * Return the Microsoft UNC transcription of the address
  102. * @memberof Address6
  103. * @instance
  104. * @returns {String} the Microsoft UNC transcription of the address
  105. */
  106. microsoftTranscription(): string;
  107. /**
  108. * Return the first n bits of the address, defaulting to the subnet mask
  109. * @memberof Address6
  110. * @instance
  111. * @param {number} [mask=subnet] - the number of bits to mask
  112. * @returns {String} the first n bits of the address as a string
  113. */
  114. mask(mask?: number): string;
  115. /**
  116. * Return the number of possible subnets of a given size in the address
  117. * @memberof Address6
  118. * @instance
  119. * @param {number} [subnetSize=128] - the subnet size
  120. * @returns {String}
  121. */
  122. possibleSubnets(subnetSize?: number): string;
  123. /**
  124. * Helper function getting start address.
  125. * @memberof Address6
  126. * @instance
  127. * @returns {bigint}
  128. */
  129. _startAddress(): bigint;
  130. /**
  131. * The first address in the range given by this address' subnet
  132. * Often referred to as the Network Address.
  133. * @memberof Address6
  134. * @instance
  135. * @returns {Address6}
  136. */
  137. startAddress(): Address6;
  138. /**
  139. * The first host address in the range given by this address's subnet ie
  140. * the first address after the Network Address
  141. * @memberof Address6
  142. * @instance
  143. * @returns {Address6}
  144. */
  145. startAddressExclusive(): Address6;
  146. /**
  147. * Helper function getting end address.
  148. * @memberof Address6
  149. * @instance
  150. * @returns {bigint}
  151. */
  152. _endAddress(): bigint;
  153. /**
  154. * The last address in the range given by this address' subnet
  155. * Often referred to as the Broadcast
  156. * @memberof Address6
  157. * @instance
  158. * @returns {Address6}
  159. */
  160. endAddress(): Address6;
  161. /**
  162. * The last host address in the range given by this address's subnet ie
  163. * the last address prior to the Broadcast Address
  164. * @memberof Address6
  165. * @instance
  166. * @returns {Address6}
  167. */
  168. endAddressExclusive(): Address6;
  169. /**
  170. * Return the scope of the address
  171. * @memberof Address6
  172. * @instance
  173. * @returns {String}
  174. */
  175. getScope(): string;
  176. /**
  177. * Return the type of the address
  178. * @memberof Address6
  179. * @instance
  180. * @returns {String}
  181. */
  182. getType(): string;
  183. /**
  184. * Return the bits in the given range as a BigInt
  185. * @memberof Address6
  186. * @instance
  187. * @returns {bigint}
  188. */
  189. getBits(start: number, end: number): bigint;
  190. /**
  191. * Return the bits in the given range as a base-2 string
  192. * @memberof Address6
  193. * @instance
  194. * @returns {String}
  195. */
  196. getBitsBase2(start: number, end: number): string;
  197. /**
  198. * Return the bits in the given range as a base-16 string
  199. * @memberof Address6
  200. * @instance
  201. * @returns {String}
  202. */
  203. getBitsBase16(start: number, end: number): string;
  204. /**
  205. * Return the bits that are set past the subnet mask length
  206. * @memberof Address6
  207. * @instance
  208. * @returns {String}
  209. */
  210. getBitsPastSubnet(): string;
  211. /**
  212. * Return the reversed ip6.arpa form of the address
  213. * @memberof Address6
  214. * @param {Object} options
  215. * @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
  216. * @instance
  217. * @returns {String}
  218. */
  219. reverseForm(options?: common.ReverseFormOptions): string;
  220. /**
  221. * Return the correct form of the address
  222. * @memberof Address6
  223. * @instance
  224. * @returns {String}
  225. */
  226. correctForm(): string;
  227. /**
  228. * Return a zero-padded base-2 string representation of the address
  229. * @memberof Address6
  230. * @instance
  231. * @returns {String}
  232. * @example
  233. * var address = new Address6('2001:4860:4001:803::1011');
  234. * address.binaryZeroPad();
  235. * // '0010000000000001010010000110000001000000000000010000100000000011
  236. * // 0000000000000000000000000000000000000000000000000001000000010001'
  237. */
  238. binaryZeroPad(): string;
  239. parse4in6(address: string): string;
  240. parse(address: string): string[];
  241. /**
  242. * Return the canonical form of the address
  243. * @memberof Address6
  244. * @instance
  245. * @returns {String}
  246. */
  247. canonicalForm(): string;
  248. /**
  249. * Return the decimal form of the address
  250. * @memberof Address6
  251. * @instance
  252. * @returns {String}
  253. */
  254. decimal(): string;
  255. /**
  256. * Return the address as a BigInt
  257. * @memberof Address6
  258. * @instance
  259. * @returns {bigint}
  260. */
  261. bigInt(): bigint;
  262. /**
  263. * Return the last two groups of this address as an IPv4 address string
  264. * @memberof Address6
  265. * @instance
  266. * @returns {Address4}
  267. * @example
  268. * var address = new Address6('2001:4860:4001::1825:bf11');
  269. * address.to4().correctForm(); // '24.37.191.17'
  270. */
  271. to4(): Address4;
  272. /**
  273. * Return the v4-in-v6 form of the address
  274. * @memberof Address6
  275. * @instance
  276. * @returns {String}
  277. */
  278. to4in6(): string;
  279. /**
  280. * Return an object containing the Teredo properties of the address
  281. * @memberof Address6
  282. * @instance
  283. * @returns {Object}
  284. */
  285. inspectTeredo(): TeredoProperties;
  286. /**
  287. * Return an object containing the 6to4 properties of the address
  288. * @memberof Address6
  289. * @instance
  290. * @returns {Object}
  291. */
  292. inspect6to4(): SixToFourProperties;
  293. /**
  294. * Return a v6 6to4 address from a v6 v4inv6 address
  295. * @memberof Address6
  296. * @instance
  297. * @returns {Address6}
  298. */
  299. to6to4(): Address6 | null;
  300. /**
  301. * Return a byte array
  302. * @memberof Address6
  303. * @instance
  304. * @returns {Array}
  305. */
  306. toByteArray(): number[];
  307. /**
  308. * Return an unsigned byte array
  309. * @memberof Address6
  310. * @instance
  311. * @returns {Array}
  312. */
  313. toUnsignedByteArray(): number[];
  314. /**
  315. * Convert a byte array to an Address6 object
  316. * @memberof Address6
  317. * @static
  318. * @returns {Address6}
  319. */
  320. static fromByteArray(bytes: Array<any>): Address6;
  321. /**
  322. * Convert an unsigned byte array to an Address6 object
  323. * @memberof Address6
  324. * @static
  325. * @returns {Address6}
  326. */
  327. static fromUnsignedByteArray(bytes: Array<any>): Address6;
  328. /**
  329. * Returns true if the given address is in the subnet of the current address
  330. * @memberof Address6
  331. * @instance
  332. * @returns {boolean}
  333. */
  334. isInSubnet: typeof common.isInSubnet;
  335. /**
  336. * Returns true if the address is correct, false otherwise
  337. * @memberof Address6
  338. * @instance
  339. * @returns {boolean}
  340. */
  341. isCorrect: (this: Address4 | Address6) => boolean;
  342. /**
  343. * Returns true if the address is in the canonical form, false otherwise
  344. * @memberof Address6
  345. * @instance
  346. * @returns {boolean}
  347. */
  348. isCanonical(): boolean;
  349. /**
  350. * Returns true if the address is a link local address, false otherwise
  351. * @memberof Address6
  352. * @instance
  353. * @returns {boolean}
  354. */
  355. isLinkLocal(): boolean;
  356. /**
  357. * Returns true if the address is a multicast address, false otherwise
  358. * @memberof Address6
  359. * @instance
  360. * @returns {boolean}
  361. */
  362. isMulticast(): boolean;
  363. /**
  364. * Returns true if the address is a v4-in-v6 address, false otherwise
  365. * @memberof Address6
  366. * @instance
  367. * @returns {boolean}
  368. */
  369. is4(): boolean;
  370. /**
  371. * Returns true if the address is a Teredo address, false otherwise
  372. * @memberof Address6
  373. * @instance
  374. * @returns {boolean}
  375. */
  376. isTeredo(): boolean;
  377. /**
  378. * Returns true if the address is a 6to4 address, false otherwise
  379. * @memberof Address6
  380. * @instance
  381. * @returns {boolean}
  382. */
  383. is6to4(): boolean;
  384. /**
  385. * Returns true if the address is a loopback address, false otherwise
  386. * @memberof Address6
  387. * @instance
  388. * @returns {boolean}
  389. */
  390. isLoopback(): boolean;
  391. /**
  392. * @returns {String} the address in link form with a default port of 80
  393. */
  394. href(optionalPort?: number | string): string;
  395. /**
  396. * @returns {String} a link suitable for conveying the address via a URL hash
  397. */
  398. link(options?: {
  399. className?: string;
  400. prefix?: string;
  401. v4?: boolean;
  402. }): string;
  403. /**
  404. * Groups an address
  405. * @returns {String}
  406. */
  407. group(): string;
  408. /**
  409. * Generate a regular expression string that can be used to find or validate
  410. * all variations of this address
  411. * @memberof Address6
  412. * @instance
  413. * @param {boolean} substringSearch
  414. * @returns {string}
  415. */
  416. regularExpressionString(this: Address6, substringSearch?: boolean): string;
  417. /**
  418. * Generate a regular expression that can be used to find or validate all
  419. * variations of this address.
  420. * @memberof Address6
  421. * @instance
  422. * @param {boolean} substringSearch
  423. * @returns {RegExp}
  424. */
  425. regularExpression(this: Address6, substringSearch?: boolean): RegExp;
  426. }
  427. export {};
  428. //# sourceMappingURL=ipv6.d.ts.map