feat(planning): grille hebdomadaire complète avec API et filtres
- Connexion API via proxy Angular (résolution CORS, base path /api) - Import CSS ng-zorro global pour les modales et composants - Filtres Camion/Show câblés sur l'affichage de la grille - Camions affichés via TrucksService (linkés au show du même créneau) - Panneau de détails : spectacles + camions du jour sélectionné - Modale de création de spectacle stylisée avec fond et centrage - Positionnement précis des events à la minute dans leur créneau - Auto-scroll vers l'heure courante au chargement - Ligne "maintenant" sur la colonne du jour actuel - Régénération des services OpenAPI (nouveaux noms de types) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
@@ -2,3 +2,4 @@ export declare class AddressError extends Error {
|
||||
parseMessage?: string;
|
||||
constructor(message: string, parseMessage?: string);
|
||||
}
|
||||
//# sourceMappingURL=address-error.d.ts.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"address-error.js","sourceRoot":"","sources":["../src/address-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAGrC,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAE3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAVD,oCAUC","sourcesContent":["export class AddressError extends Error {\n parseMessage?: string;\n\n constructor(message: string, parseMessage?: string) {\n super(message);\n\n this.name = 'AddressError';\n\n this.parseMessage = parseMessage;\n }\n}\n"]}
|
||||
{"version":3,"file":"address-error.js","sourceRoot":"","sources":["../src/address-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAGrC,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAE3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAVD,oCAUC"}
|
||||
+1
-6
@@ -5,12 +5,6 @@ export interface ReverseFormOptions {
|
||||
}
|
||||
export declare function isInSubnet(this: Address4 | Address6, address: Address4 | Address6): boolean;
|
||||
export declare function isCorrect(defaultBits: number): (this: Address4 | Address6) => boolean;
|
||||
/**
|
||||
* Returns the prefix length (number of leading 1 bits) of a contiguous
|
||||
* subnet mask. Throws `AddressError` if the mask is non-contiguous (e.g.
|
||||
* `255.0.255.0`).
|
||||
*/
|
||||
export declare function prefixLengthFromMask(value: bigint, totalBits: number): number;
|
||||
export declare function numberToPaddedHex(number: number): string;
|
||||
export declare function stringToPaddedHex(numberString: string): string;
|
||||
/**
|
||||
@@ -18,3 +12,4 @@ export declare function stringToPaddedHex(numberString: string): string;
|
||||
* @param position Byte position, where 0 is the least significant bit
|
||||
*/
|
||||
export declare function testBit(binaryValue: string, position: number): boolean;
|
||||
//# sourceMappingURL=common.d.ts.map
|
||||
-21
@@ -2,11 +2,9 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isInSubnet = isInSubnet;
|
||||
exports.isCorrect = isCorrect;
|
||||
exports.prefixLengthFromMask = prefixLengthFromMask;
|
||||
exports.numberToPaddedHex = numberToPaddedHex;
|
||||
exports.stringToPaddedHex = stringToPaddedHex;
|
||||
exports.testBit = testBit;
|
||||
const address_error_1 = require("./address-error");
|
||||
function isInSubnet(address) {
|
||||
if (this.subnetMask < address.subnetMask) {
|
||||
return false;
|
||||
@@ -27,25 +25,6 @@ function isCorrect(defaultBits) {
|
||||
return this.parsedSubnet === String(this.subnetMask);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns the prefix length (number of leading 1 bits) of a contiguous
|
||||
* subnet mask. Throws `AddressError` if the mask is non-contiguous (e.g.
|
||||
* `255.0.255.0`).
|
||||
*/
|
||||
function prefixLengthFromMask(value, totalBits) {
|
||||
const binary = value.toString(2).padStart(totalBits, '0');
|
||||
if (binary.length > totalBits) {
|
||||
throw new address_error_1.AddressError('Invalid subnet mask.');
|
||||
}
|
||||
const firstZero = binary.indexOf('0');
|
||||
if (firstZero === -1) {
|
||||
return totalBits;
|
||||
}
|
||||
if (binary.slice(firstZero).includes('1')) {
|
||||
throw new address_error_1.AddressError('Invalid subnet mask.');
|
||||
}
|
||||
return firstZero;
|
||||
}
|
||||
function numberToPaddedHex(number) {
|
||||
return number.toString(16).padStart(2, '0');
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;AAQA,gCAUC;AAED,8BAYC;AAOD,oDAkBC;AAED,8CAEC;AAED,8CAEC;AAMD,0BASC;AA9ED,mDAA+C;AAM/C,SAAgB,UAAU,CAA4B,OAA4B;IAChF,IAAI,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,SAAS,CAAC,WAAmB;IAC3C,OAAO;QACL,IAAI,IAAI,CAAC,kBAAkB,KAAK,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,KAAa,EAAE,SAAiB;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAE1D,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,4BAAY,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,4BAAY,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,iBAAiB,CAAC,YAAoB;IACpD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,WAAmB,EAAE,QAAgB;IAC3D,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;IAE/B,IAAI,QAAQ,GAAG,MAAM,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC3C,OAAO,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;AAC/E,CAAC","sourcesContent":["import { Address4 } from './ipv4';\nimport { Address6 } from './ipv6';\nimport { AddressError } from './address-error';\n\nexport interface ReverseFormOptions {\n omitSuffix?: boolean;\n}\n\nexport function isInSubnet(this: Address4 | Address6, address: Address4 | Address6) {\n if (this.subnetMask < address.subnetMask) {\n return false;\n }\n\n if (this.mask(address.subnetMask) === address.mask()) {\n return true;\n }\n\n return false;\n}\n\nexport function isCorrect(defaultBits: number) {\n return function (this: Address4 | Address6) {\n if (this.addressMinusSuffix !== this.correctForm()) {\n return false;\n }\n\n if (this.subnetMask === defaultBits && !this.parsedSubnet) {\n return true;\n }\n\n return this.parsedSubnet === String(this.subnetMask);\n };\n}\n\n/**\n * Returns the prefix length (number of leading 1 bits) of a contiguous\n * subnet mask. Throws `AddressError` if the mask is non-contiguous (e.g.\n * `255.0.255.0`).\n */\nexport function prefixLengthFromMask(value: bigint, totalBits: number): number {\n const binary = value.toString(2).padStart(totalBits, '0');\n\n if (binary.length > totalBits) {\n throw new AddressError('Invalid subnet mask.');\n }\n\n const firstZero = binary.indexOf('0');\n\n if (firstZero === -1) {\n return totalBits;\n }\n\n if (binary.slice(firstZero).includes('1')) {\n throw new AddressError('Invalid subnet mask.');\n }\n\n return firstZero;\n}\n\nexport function numberToPaddedHex(number: number) {\n return number.toString(16).padStart(2, '0');\n}\n\nexport function stringToPaddedHex(numberString: string) {\n return numberToPaddedHex(parseInt(numberString, 10));\n}\n\n/**\n * @param binaryValue Binary representation of a value (e.g. `10`)\n * @param position Byte position, where 0 is the least significant bit\n */\nexport function testBit(binaryValue: string, position: number): boolean {\n const { length } = binaryValue;\n\n if (position > length) {\n return false;\n }\n\n const positionInString = length - position;\n return binaryValue.substring(positionInString, positionInString + 1) === '1';\n}\n"]}
|
||||
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;AAOA,gCAUC;AAED,8BAYC;AAED,8CAEC;AAED,8CAEC;AAMD,0BASC;AA/CD,SAAgB,UAAU,CAA4B,OAA4B;IAChF,IAAI,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,SAAS,CAAC,WAAmB;IAC3C,OAAO;QACL,IAAI,IAAI,CAAC,kBAAkB,KAAK,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,iBAAiB,CAAC,YAAoB;IACpD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,WAAmB,EAAE,QAAgB;IAC3D,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;IAE/B,IAAI,QAAQ,GAAG,MAAM,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC3C,OAAO,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;AAC/E,CAAC"}
|
||||
+1
@@ -5,3 +5,4 @@ import * as helpers from './v6/helpers';
|
||||
export declare const v6: {
|
||||
helpers: typeof helpers;
|
||||
};
|
||||
//# sourceMappingURL=ip-address.d.ts.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"ip-address.js","sourceRoot":"","sources":["../src/ip-address.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AACjB,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AACjB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AAErB,sDAAwC;AAE3B,QAAA,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC","sourcesContent":["export { Address4 } from './ipv4';\nexport { Address6 } from './ipv6';\nexport { AddressError } from './address-error';\n\nimport * as helpers from './v6/helpers';\n\nexport const v6 = { helpers };\n"]}
|
||||
{"version":3,"file":"ip-address.js","sourceRoot":"","sources":["../src/ip-address.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AACjB,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AACjB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AAErB,sDAAwC;AAE3B,QAAA,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC"}
|
||||
+57
-115
@@ -1,6 +1,7 @@
|
||||
import * as common from './common';
|
||||
/**
|
||||
* Represents an IPv4 address
|
||||
* @class Address4
|
||||
* @param {string} address - An IPv4 address string
|
||||
*/
|
||||
export declare class Address4 {
|
||||
@@ -12,86 +13,43 @@ export declare class Address4 {
|
||||
subnet: string;
|
||||
subnetMask: number;
|
||||
v4: boolean;
|
||||
private _binaryZeroPad?;
|
||||
constructor(address: string);
|
||||
/**
|
||||
* Returns true if the given string is a valid IPv4 address (with optional
|
||||
* CIDR subnet), false otherwise. Host bits in the subnet portion are
|
||||
* allowed (e.g. `192.168.1.5/24` is valid); for strict network-address
|
||||
* validation compare `correctForm()` to `startAddress().correctForm()`,
|
||||
* or use `networkForm()`.
|
||||
*/
|
||||
static isValid(address: string): boolean;
|
||||
/**
|
||||
* Parses an IPv4 address string into its four octet groups and stores the
|
||||
* result on `this.parsedAddress`. Called automatically by the constructor;
|
||||
* you typically don't need to call it directly. Throws `AddressError` if
|
||||
* the input is not a valid IPv4 address.
|
||||
*/
|
||||
parse(address: string): string[];
|
||||
/**
|
||||
* Returns the address in correct form: octets joined with `.` and any
|
||||
* leading zeros stripped (e.g. `192.168.1.1`). For IPv4 this matches the
|
||||
* canonical dotted-decimal representation.
|
||||
* Returns the correct form of an address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
correctForm(): string;
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isCorrect: (this: Address4 | import("./ipv6").Address6) => boolean;
|
||||
/**
|
||||
* Construct an `Address4` from an address and a dotted-decimal subnet
|
||||
* mask given as separate strings (e.g. as returned by Node's
|
||||
* `os.networkInterfaces()`). Throws `AddressError` if the mask is
|
||||
* non-contiguous (e.g. `255.0.255.0`).
|
||||
* @example
|
||||
* var address = Address4.fromAddressAndMask('192.168.1.1', '255.255.255.0');
|
||||
* address.subnetMask; // 24
|
||||
*/
|
||||
static fromAddressAndMask(address: string, mask: string): Address4;
|
||||
/**
|
||||
* Construct an `Address4` from an address and a Cisco-style wildcard mask
|
||||
* given as separate strings (e.g. `0.0.0.255` for a `/24`). The wildcard
|
||||
* mask is the bitwise inverse of the subnet mask. Throws `AddressError`
|
||||
* if the mask is non-contiguous (e.g. `0.255.0.255`).
|
||||
* @example
|
||||
* var address = Address4.fromAddressAndWildcardMask('10.0.0.1', '0.0.0.255');
|
||||
* address.subnetMask; // 24
|
||||
*/
|
||||
static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address4;
|
||||
/**
|
||||
* Construct an `Address4` from a wildcard pattern with trailing `*`
|
||||
* octets. The number of trailing wildcards determines the prefix
|
||||
* length: each `*` represents 8 bits.
|
||||
*
|
||||
* Only trailing whole-octet wildcards are supported. Partial-octet
|
||||
* wildcards (e.g. `192.168.0.1*`) and interior wildcards (e.g.
|
||||
* `192.*.0.1`) throw `AddressError`.
|
||||
* @example
|
||||
* Address4.fromWildcard('192.168.0.*').subnet; // '/24'
|
||||
* Address4.fromWildcard('192.168.*.*').subnet; // '/16'
|
||||
* Address4.fromWildcard('*.*.*.*').subnet; // '/0'
|
||||
*/
|
||||
static fromWildcard(input: string): Address4;
|
||||
/**
|
||||
* Converts a hex string to an IPv4 address object. Accepts 8 hex digits
|
||||
* with optional `:` separators (e.g. `'7f000001'` or `'7f:00:00:01'`).
|
||||
* Throws `AddressError` for any other length or for non-hex characters.
|
||||
* Converts a hex string to an IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {string} hex - a hex string to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromHex(hex: string): Address4;
|
||||
/**
|
||||
* Converts an integer into a IPv4 address object. The integer must be a
|
||||
* non-negative safe integer in the range `[0, 2**32 - 1]`; otherwise
|
||||
* `AddressError` is thrown.
|
||||
* Converts an integer into a IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {integer} integer - a number to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromInteger(integer: number): Address4;
|
||||
/**
|
||||
* Return an address from in-addr.arpa form
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address
|
||||
* @returns {Adress4}
|
||||
* @example
|
||||
@@ -101,97 +59,98 @@ export declare class Address4 {
|
||||
static fromArpa(arpaFormAddress: string): Address4;
|
||||
/**
|
||||
* Converts an IPv4 address object to a hex string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toHex(): string;
|
||||
/**
|
||||
* Converts an IPv4 address object to an array of bytes.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toArray())`.
|
||||
* Converts an IPv4 address object to an array of bytes
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toArray(): number[];
|
||||
/**
|
||||
* Converts an IPv4 address object to an IPv6 address group
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toGroup6(): string;
|
||||
/**
|
||||
* Returns the address as a `bigint`
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
bigInt(): bigint;
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_startAddress(): bigint;
|
||||
/**
|
||||
* The first address in the range given by this address' subnet.
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
startAddress(): Address4;
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
startAddressExclusive(): Address4;
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_endAddress(): bigint;
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
endAddress(): Address4;
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
endAddressExclusive(): Address4;
|
||||
/**
|
||||
* The dotted-decimal form of the subnet mask, e.g. `255.255.240.0` for
|
||||
* a `/20`. Returns an `Address4`; call `.correctForm()` for the string.
|
||||
* @returns {Address4}
|
||||
*/
|
||||
subnetMaskAddress(): Address4;
|
||||
/**
|
||||
* The Cisco-style wildcard mask, e.g. `0.0.0.255` for a `/24`. This is
|
||||
* the bitwise inverse of `subnetMaskAddress()`. Returns an `Address4`;
|
||||
* call `.correctForm()` for the string.
|
||||
* @returns {Address4}
|
||||
*/
|
||||
wildcardMask(): Address4;
|
||||
/**
|
||||
* The network address in CIDR string form, e.g. `192.168.1.0/24` for
|
||||
* `192.168.1.5/24`. For an address with no explicit subnet the prefix is
|
||||
* `/32`, e.g. `networkForm()` on `192.168.1.5` returns `192.168.1.5/32`.
|
||||
* @returns {string}
|
||||
*/
|
||||
networkForm(): string;
|
||||
/**
|
||||
* Converts a BigInt to a v4 address object. The value must be in the
|
||||
* range `[0, 2**32 - 1]`; otherwise `AddressError` is thrown.
|
||||
* Converts a BigInt to a v4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {bigint} bigInt - a BigInt to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromBigInt(bigInt: bigint): Address4;
|
||||
/**
|
||||
* Convert a byte array to an Address4 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address4.fromByteArray([...buf])`.
|
||||
* Convert a byte array to an Address4 object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {Array<number>} bytes - an array of 4 bytes (0-255)
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromByteArray(bytes: Array<number>): Address4;
|
||||
/**
|
||||
* Convert an unsigned byte array to an Address4 object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)
|
||||
* @returns {Address4}
|
||||
*/
|
||||
@@ -199,63 +158,45 @@ export declare class Address4 {
|
||||
/**
|
||||
* Returns the first n bits of the address, defaulting to the
|
||||
* subnet mask
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
mask(mask?: number): string;
|
||||
/**
|
||||
* Returns the bits in the given range as a base-2 string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
getBitsBase2(start: number, end: number): string;
|
||||
/**
|
||||
* Return the reversed ip6.arpa form of the address
|
||||
* @memberof Address4
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
reverseForm(options?: common.ReverseFormOptions): string;
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isInSubnet: typeof common.isInSubnet;
|
||||
/**
|
||||
* Returns true if the given address is a multicast address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMulticast(): boolean;
|
||||
/**
|
||||
* Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isPrivate(): boolean;
|
||||
/**
|
||||
* Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoopback(): boolean;
|
||||
/**
|
||||
* Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLinkLocal(): boolean;
|
||||
/**
|
||||
* Returns true if the address is the unspecified address `0.0.0.0`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUnspecified(): boolean;
|
||||
/**
|
||||
* Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isBroadcast(): boolean;
|
||||
/**
|
||||
* Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isCGNAT(): boolean;
|
||||
/**
|
||||
* Returns a zero-padded base-2 string representation of the address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
binaryZeroPad(): string;
|
||||
@@ -265,3 +206,4 @@ export declare class Address4 {
|
||||
*/
|
||||
groupForV6(): string;
|
||||
}
|
||||
//# sourceMappingURL=ipv4.d.ts.map
|
||||
+68
-193
@@ -28,9 +28,9 @@ exports.Address4 = void 0;
|
||||
const common = __importStar(require("./common"));
|
||||
const constants = __importStar(require("./v4/constants"));
|
||||
const address_error_1 = require("./address-error");
|
||||
const isCorrect4 = common.isCorrect(constants.BITS);
|
||||
/**
|
||||
* Represents an IPv4 address
|
||||
* @class Address4
|
||||
* @param {string} address - An IPv4 address string
|
||||
*/
|
||||
class Address4 {
|
||||
@@ -43,11 +43,15 @@ class Address4 {
|
||||
this.v4 = true;
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
this.isCorrect = isCorrect4;
|
||||
this.isCorrect = common.isCorrect(constants.BITS);
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
this.isInSubnet = common.isInSubnet;
|
||||
@@ -65,13 +69,6 @@ class Address4 {
|
||||
this.addressMinusSuffix = address;
|
||||
this.parsedAddress = this.parse(address);
|
||||
}
|
||||
/**
|
||||
* Returns true if the given string is a valid IPv4 address (with optional
|
||||
* CIDR subnet), false otherwise. Host bits in the subnet portion are
|
||||
* allowed (e.g. `192.168.1.5/24` is valid); for strict network-address
|
||||
* validation compare `correctForm()` to `startAddress().correctForm()`,
|
||||
* or use `networkForm()`.
|
||||
*/
|
||||
static isValid(address) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
@@ -82,11 +79,8 @@ class Address4 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parses an IPv4 address string into its four octet groups and stores the
|
||||
* result on `this.parsedAddress`. Called automatically by the constructor;
|
||||
* you typically don't need to call it directly. Throws `AddressError` if
|
||||
* the input is not a valid IPv4 address.
|
||||
/*
|
||||
* Parses a v4 address
|
||||
*/
|
||||
parse(address) {
|
||||
const groups = address.split('.');
|
||||
@@ -96,110 +90,45 @@ class Address4 {
|
||||
return groups;
|
||||
}
|
||||
/**
|
||||
* Returns the address in correct form: octets joined with `.` and any
|
||||
* leading zeros stripped (e.g. `192.168.1.1`). For IPv4 this matches the
|
||||
* canonical dotted-decimal representation.
|
||||
* Returns the correct form of an address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
correctForm() {
|
||||
return this.parsedAddress.map((part) => parseInt(part, 10)).join('.');
|
||||
}
|
||||
/**
|
||||
* Construct an `Address4` from an address and a dotted-decimal subnet
|
||||
* mask given as separate strings (e.g. as returned by Node's
|
||||
* `os.networkInterfaces()`). Throws `AddressError` if the mask is
|
||||
* non-contiguous (e.g. `255.0.255.0`).
|
||||
* @example
|
||||
* var address = Address4.fromAddressAndMask('192.168.1.1', '255.255.255.0');
|
||||
* address.subnetMask; // 24
|
||||
*/
|
||||
static fromAddressAndMask(address, mask) {
|
||||
const bits = common.prefixLengthFromMask(new Address4(mask).bigInt(), constants.BITS);
|
||||
return new Address4(`${address}/${bits}`);
|
||||
}
|
||||
/**
|
||||
* Construct an `Address4` from an address and a Cisco-style wildcard mask
|
||||
* given as separate strings (e.g. `0.0.0.255` for a `/24`). The wildcard
|
||||
* mask is the bitwise inverse of the subnet mask. Throws `AddressError`
|
||||
* if the mask is non-contiguous (e.g. `0.255.0.255`).
|
||||
* @example
|
||||
* var address = Address4.fromAddressAndWildcardMask('10.0.0.1', '0.0.0.255');
|
||||
* address.subnetMask; // 24
|
||||
*/
|
||||
static fromAddressAndWildcardMask(address, wildcardMask) {
|
||||
const wildcard = new Address4(wildcardMask).bigInt();
|
||||
const allOnes = (BigInt(1) << BigInt(constants.BITS)) - BigInt(1);
|
||||
// eslint-disable-next-line no-bitwise
|
||||
const mask = wildcard ^ allOnes;
|
||||
const bits = common.prefixLengthFromMask(mask, constants.BITS);
|
||||
return new Address4(`${address}/${bits}`);
|
||||
}
|
||||
/**
|
||||
* Construct an `Address4` from a wildcard pattern with trailing `*`
|
||||
* octets. The number of trailing wildcards determines the prefix
|
||||
* length: each `*` represents 8 bits.
|
||||
*
|
||||
* Only trailing whole-octet wildcards are supported. Partial-octet
|
||||
* wildcards (e.g. `192.168.0.1*`) and interior wildcards (e.g.
|
||||
* `192.*.0.1`) throw `AddressError`.
|
||||
* @example
|
||||
* Address4.fromWildcard('192.168.0.*').subnet; // '/24'
|
||||
* Address4.fromWildcard('192.168.*.*').subnet; // '/16'
|
||||
* Address4.fromWildcard('*.*.*.*').subnet; // '/0'
|
||||
*/
|
||||
static fromWildcard(input) {
|
||||
const groups = input.split('.');
|
||||
if (groups.length !== constants.GROUPS) {
|
||||
throw new address_error_1.AddressError('Wildcard pattern must have 4 octets');
|
||||
}
|
||||
let firstWildcard = -1;
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
if (groups[i] === '*') {
|
||||
if (firstWildcard === -1) {
|
||||
firstWildcard = i;
|
||||
}
|
||||
}
|
||||
else if (firstWildcard !== -1) {
|
||||
throw new address_error_1.AddressError('Wildcard `*` must only appear in trailing octets (e.g. `192.168.0.*`)');
|
||||
}
|
||||
}
|
||||
const trailing = firstWildcard === -1 ? 0 : groups.length - firstWildcard;
|
||||
const replaced = groups.map((g) => (g === '*' ? '0' : g));
|
||||
const subnetBits = constants.BITS - trailing * 8;
|
||||
return new Address4(`${replaced.join('.')}/${subnetBits}`);
|
||||
}
|
||||
/**
|
||||
* Converts a hex string to an IPv4 address object. Accepts 8 hex digits
|
||||
* with optional `:` separators (e.g. `'7f000001'` or `'7f:00:00:01'`).
|
||||
* Throws `AddressError` for any other length or for non-hex characters.
|
||||
* Converts a hex string to an IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {string} hex - a hex string to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromHex(hex) {
|
||||
const stripped = hex.replace(/:/g, '');
|
||||
if (!/^[0-9a-fA-F]{8}$/.test(stripped)) {
|
||||
throw new address_error_1.AddressError('IPv4 hex must be exactly 8 hex digits');
|
||||
}
|
||||
const padded = hex.replace(/:/g, '').padStart(8, '0');
|
||||
const groups = [];
|
||||
for (let i = 0; i < 8; i += 2) {
|
||||
groups.push(parseInt(stripped.slice(i, i + 2), 16));
|
||||
let i;
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
const h = padded.slice(i, i + 2);
|
||||
groups.push(parseInt(h, 16));
|
||||
}
|
||||
return new Address4(groups.join('.'));
|
||||
}
|
||||
/**
|
||||
* Converts an integer into a IPv4 address object. The integer must be a
|
||||
* non-negative safe integer in the range `[0, 2**32 - 1]`; otherwise
|
||||
* `AddressError` is thrown.
|
||||
* Converts an integer into a IPv4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {integer} integer - a number to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromInteger(integer) {
|
||||
if (!Number.isInteger(integer) || integer < 0 || integer > 0xffffffff) {
|
||||
throw new address_error_1.AddressError('IPv4 integer must be in the range 0 to 2**32 - 1');
|
||||
}
|
||||
return Address4.fromHex(integer.toString(16).padStart(8, '0'));
|
||||
return Address4.fromHex(integer.toString(16));
|
||||
}
|
||||
/**
|
||||
* Return an address from in-addr.arpa form
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address
|
||||
* @returns {Adress4}
|
||||
* @example
|
||||
@@ -214,15 +143,17 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Converts an IPv4 address object to a hex string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toHex() {
|
||||
return this.parsedAddress.map((part) => common.stringToPaddedHex(part)).join(':');
|
||||
}
|
||||
/**
|
||||
* Converts an IPv4 address object to an array of bytes.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toArray())`.
|
||||
* Converts an IPv4 address object to an array of bytes
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toArray() {
|
||||
@@ -230,6 +161,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Converts an IPv4 address object to an IPv6 address group
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toGroup6() {
|
||||
@@ -242,6 +175,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Returns the address as a `bigint`
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
bigInt() {
|
||||
@@ -249,6 +184,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_startAddress() {
|
||||
@@ -257,6 +194,8 @@ class Address4 {
|
||||
/**
|
||||
* The first address in the range given by this address' subnet.
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
startAddress() {
|
||||
@@ -265,6 +204,8 @@ class Address4 {
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
startAddressExclusive() {
|
||||
@@ -273,6 +214,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_endAddress() {
|
||||
@@ -281,6 +224,8 @@ class Address4 {
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
endAddress() {
|
||||
@@ -289,6 +234,8 @@ class Address4 {
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
endAddressExclusive() {
|
||||
@@ -296,47 +243,19 @@ class Address4 {
|
||||
return Address4.fromBigInt(this._endAddress() - adjust);
|
||||
}
|
||||
/**
|
||||
* The dotted-decimal form of the subnet mask, e.g. `255.255.240.0` for
|
||||
* a `/20`. Returns an `Address4`; call `.correctForm()` for the string.
|
||||
* @returns {Address4}
|
||||
*/
|
||||
subnetMaskAddress() {
|
||||
return Address4.fromBigInt(BigInt(`0b${'1'.repeat(this.subnetMask)}${'0'.repeat(constants.BITS - this.subnetMask)}`));
|
||||
}
|
||||
/**
|
||||
* The Cisco-style wildcard mask, e.g. `0.0.0.255` for a `/24`. This is
|
||||
* the bitwise inverse of `subnetMaskAddress()`. Returns an `Address4`;
|
||||
* call `.correctForm()` for the string.
|
||||
* @returns {Address4}
|
||||
*/
|
||||
wildcardMask() {
|
||||
return Address4.fromBigInt(BigInt(`0b${'0'.repeat(this.subnetMask)}${'1'.repeat(constants.BITS - this.subnetMask)}`));
|
||||
}
|
||||
/**
|
||||
* The network address in CIDR string form, e.g. `192.168.1.0/24` for
|
||||
* `192.168.1.5/24`. For an address with no explicit subnet the prefix is
|
||||
* `/32`, e.g. `networkForm()` on `192.168.1.5` returns `192.168.1.5/32`.
|
||||
* @returns {string}
|
||||
*/
|
||||
networkForm() {
|
||||
return `${this.startAddress().correctForm()}/${this.subnetMask}`;
|
||||
}
|
||||
/**
|
||||
* Converts a BigInt to a v4 address object. The value must be in the
|
||||
* range `[0, 2**32 - 1]`; otherwise `AddressError` is thrown.
|
||||
* Converts a BigInt to a v4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {bigint} bigInt - a BigInt to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromBigInt(bigInt) {
|
||||
if (bigInt < 0n || bigInt > 0xffffffffn) {
|
||||
throw new address_error_1.AddressError('IPv4 BigInt must be in the range 0 to 2**32 - 1');
|
||||
}
|
||||
return Address4.fromHex(bigInt.toString(16).padStart(8, '0'));
|
||||
return Address4.fromHex(bigInt.toString(16));
|
||||
}
|
||||
/**
|
||||
* Convert a byte array to an Address4 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address4.fromByteArray([...buf])`.
|
||||
* Convert a byte array to an Address4 object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {Array<number>} bytes - an array of 4 bytes (0-255)
|
||||
* @returns {Address4}
|
||||
*/
|
||||
@@ -354,6 +273,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Convert an unsigned byte array to an Address4 object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)
|
||||
* @returns {Address4}
|
||||
*/
|
||||
@@ -367,6 +288,8 @@ class Address4 {
|
||||
/**
|
||||
* Returns the first n bits of the address, defaulting to the
|
||||
* subnet mask
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
mask(mask) {
|
||||
@@ -377,6 +300,8 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Returns the bits in the given range as a base-2 string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
getBitsBase2(start, end) {
|
||||
@@ -384,8 +309,10 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Return the reversed ip6.arpa form of the address
|
||||
* @memberof Address4
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
reverseForm(options) {
|
||||
@@ -400,62 +327,21 @@ class Address4 {
|
||||
}
|
||||
/**
|
||||
* Returns true if the given address is a multicast address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMulticast() {
|
||||
return this.isInSubnet(MULTICAST_V4);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isPrivate() {
|
||||
return PRIVATE_V4.some((subnet) => this.isInSubnet(subnet));
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoopback() {
|
||||
return this.isInSubnet(LOOPBACK_V4);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLinkLocal() {
|
||||
return this.isInSubnet(LINK_LOCAL_V4);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is the unspecified address `0.0.0.0`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUnspecified() {
|
||||
return this.isInSubnet(UNSPECIFIED_V4);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isBroadcast() {
|
||||
return this.isInSubnet(BROADCAST_V4);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isCGNAT() {
|
||||
return this.isInSubnet(CGNAT_V4);
|
||||
return this.isInSubnet(new Address4('224.0.0.0/4'));
|
||||
}
|
||||
/**
|
||||
* Returns a zero-padded base-2 string representation of the address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
binaryZeroPad() {
|
||||
if (this._binaryZeroPad === undefined) {
|
||||
this._binaryZeroPad = this.bigInt().toString(2).padStart(constants.BITS, '0');
|
||||
}
|
||||
return this._binaryZeroPad;
|
||||
return this.bigInt().toString(2).padStart(constants.BITS, '0');
|
||||
}
|
||||
/**
|
||||
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
||||
@@ -471,15 +357,4 @@ class Address4 {
|
||||
}
|
||||
}
|
||||
exports.Address4 = Address4;
|
||||
const MULTICAST_V4 = new Address4('224.0.0.0/4');
|
||||
const PRIVATE_V4 = [
|
||||
new Address4('10.0.0.0/8'),
|
||||
new Address4('172.16.0.0/12'),
|
||||
new Address4('192.168.0.0/16'),
|
||||
];
|
||||
const LOOPBACK_V4 = new Address4('127.0.0.0/8');
|
||||
const LINK_LOCAL_V4 = new Address4('169.254.0.0/16');
|
||||
const UNSPECIFIED_V4 = new Address4('0.0.0.0/32');
|
||||
const BROADCAST_V4 = new Address4('255.255.255.255/32');
|
||||
const CGNAT_V4 = new Address4('100.64.0.0/10');
|
||||
//# sourceMappingURL=ipv4.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+111
-172
@@ -20,6 +20,7 @@ interface TeredoProperties {
|
||||
}
|
||||
/**
|
||||
* Represents an IPv6 address
|
||||
* @class Address6
|
||||
* @param {string} address - An IPv6 address string
|
||||
* @param {number} [groups=8] - How many octets to parse
|
||||
* @example
|
||||
@@ -40,19 +41,12 @@ export declare class Address6 {
|
||||
subnetMask: number;
|
||||
v4: boolean;
|
||||
zone: string;
|
||||
private _binaryZeroPad?;
|
||||
constructor(address: string, optionalGroups?: number);
|
||||
/**
|
||||
* Returns true if the given string is a valid IPv6 address (with optional
|
||||
* CIDR subnet and zone identifier), false otherwise. Host bits in the
|
||||
* subnet portion are allowed (e.g. `2001:db8::1/32` is valid); for strict
|
||||
* network-address validation compare `correctForm()` to
|
||||
* `startAddress().correctForm()`, or use `networkForm()`.
|
||||
*/
|
||||
static isValid(address: string): boolean;
|
||||
/**
|
||||
* Convert a BigInt to a v6 address object. The value must be in the
|
||||
* range `[0, 2**128 - 1]`; otherwise `AddressError` is thrown.
|
||||
* Convert a BigInt to a v6 address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {bigint} bigInt - a BigInt to convert
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
@@ -62,10 +56,10 @@ export declare class Address6 {
|
||||
*/
|
||||
static fromBigInt(bigInt: bigint): Address6;
|
||||
/**
|
||||
* Parse a URL (with optional bracketed host and port) into an address and
|
||||
* port. Returns either `{ address, port }` on success or
|
||||
* `{ error, address: null, port: null }` if the URL could not be parsed.
|
||||
* Ports are returned as numbers (or `null` if absent or out of range).
|
||||
* Convert a URL (with optional port number) to an address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} url - a URL with optional port number
|
||||
* @example
|
||||
* var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
|
||||
* addressAndPort.address.correctForm(); // 'ffff::'
|
||||
@@ -80,43 +74,10 @@ export declare class Address6 {
|
||||
port: number | null;
|
||||
error?: undefined;
|
||||
};
|
||||
/**
|
||||
* Construct an `Address6` from an address and a hex subnet mask given as
|
||||
* separate strings (e.g. as returned by Node's `os.networkInterfaces()`).
|
||||
* Throws `AddressError` if the mask is non-contiguous (e.g.
|
||||
* `ffff::ffff`).
|
||||
* @example
|
||||
* var address = Address6.fromAddressAndMask('fe80::1', 'ffff:ffff:ffff:ffff::');
|
||||
* address.subnetMask; // 64
|
||||
*/
|
||||
static fromAddressAndMask(address: string, mask: string): Address6;
|
||||
/**
|
||||
* Construct an `Address6` from an address and a Cisco-style wildcard mask
|
||||
* given as separate strings (e.g. `::ffff:ffff:ffff:ffff` for a `/64`).
|
||||
* The wildcard mask is the bitwise inverse of the subnet mask. Throws
|
||||
* `AddressError` if the mask is non-contiguous.
|
||||
* @example
|
||||
* var address = Address6.fromAddressAndWildcardMask('fe80::1', '::ffff:ffff:ffff:ffff');
|
||||
* address.subnetMask; // 64
|
||||
*/
|
||||
static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address6;
|
||||
/**
|
||||
* Construct an `Address6` from a wildcard pattern with trailing `*`
|
||||
* groups. The number of trailing wildcards determines the prefix
|
||||
* length: each `*` represents 16 bits. `::` is expanded to zero groups
|
||||
* (not wildcards) before evaluating trailing wildcards.
|
||||
*
|
||||
* Only trailing whole-group wildcards are supported. Partial-group
|
||||
* wildcards (e.g. `2001:db8::0*`) and interior wildcards (e.g.
|
||||
* `*::1`) throw `AddressError`.
|
||||
* @example
|
||||
* Address6.fromWildcard('2001:db8:*:*:*:*:*:*').subnet; // '/32'
|
||||
* Address6.fromWildcard('2001:db8::*').subnet; // '/112'
|
||||
* Address6.fromWildcard('*:*:*:*:*:*:*:*').subnet; // '/0'
|
||||
*/
|
||||
static fromWildcard(input: string): Address6;
|
||||
/**
|
||||
* Create an IPv6-mapped address given an IPv4 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} address - An IPv4 address string
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
@@ -127,6 +88,8 @@ export declare class Address6 {
|
||||
static fromAddress4(address: string): Address6;
|
||||
/**
|
||||
* Return an address from ip6.arpa form
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
||||
* @returns {Adress6}
|
||||
* @example
|
||||
@@ -136,126 +99,135 @@ export declare class Address6 {
|
||||
static fromArpa(arpaFormAddress: string): Address6;
|
||||
/**
|
||||
* Return the Microsoft UNC transcription of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String} the Microsoft UNC transcription of the address
|
||||
*/
|
||||
microsoftTranscription(): string;
|
||||
/**
|
||||
* Return the first n bits of the address, defaulting to the subnet mask
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [mask=subnet] - the number of bits to mask
|
||||
* @returns {String} the first n bits of the address as a string
|
||||
*/
|
||||
mask(mask?: number): string;
|
||||
/**
|
||||
* Return the number of possible subnets of a given size in the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [subnetSize=128] - the subnet size
|
||||
* @returns {String}
|
||||
*/
|
||||
possibleSubnets(subnetSize?: number): string;
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_startAddress(): bigint;
|
||||
/**
|
||||
* The first address in the range given by this address' subnet
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
startAddress(): Address6;
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
startAddressExclusive(): Address6;
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_endAddress(): bigint;
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
endAddress(): Address6;
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
endAddressExclusive(): Address6;
|
||||
/**
|
||||
* The hex form of the subnet mask, e.g. `ffff:ffff:ffff:ffff::` for a
|
||||
* `/64`. Returns an `Address6`; call `.correctForm()` for the string.
|
||||
* @returns {Address6}
|
||||
*/
|
||||
subnetMaskAddress(): Address6;
|
||||
/**
|
||||
* The Cisco-style wildcard mask, e.g. `::ffff:ffff:ffff:ffff` for a
|
||||
* `/64`. This is the bitwise inverse of `subnetMaskAddress()`. Returns
|
||||
* an `Address6`; call `.correctForm()` for the string.
|
||||
* @returns {Address6}
|
||||
*/
|
||||
wildcardMask(): Address6;
|
||||
/**
|
||||
* The network address in CIDR string form, e.g. `2001:db8::/32` for
|
||||
* `2001:db8::1/32`. For an address with no explicit subnet the prefix
|
||||
* is `/128`, e.g. `networkForm()` on `2001:db8::1` returns
|
||||
* `2001:db8::1/128`.
|
||||
* @returns {string}
|
||||
*/
|
||||
networkForm(): string;
|
||||
/**
|
||||
* Return the scope of the address. The 4-bit scope field
|
||||
* ([RFC 4291 §2.7](https://datatracker.ietf.org/doc/html/rfc4291#section-2.7))
|
||||
* is only defined for multicast addresses; for unicast addresses the scope
|
||||
* is derived from the address type per
|
||||
* [RFC 4007 §6](https://datatracker.ietf.org/doc/html/rfc4007#section-6).
|
||||
* Return the scope of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getScope(): string;
|
||||
/**
|
||||
* Return the type of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getType(): string;
|
||||
/**
|
||||
* Return the bits in the given range as a BigInt
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
getBits(start: number, end: number): bigint;
|
||||
/**
|
||||
* Return the bits in the given range as a base-2 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsBase2(start: number, end: number): string;
|
||||
/**
|
||||
* Return the bits in the given range as a base-16 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsBase16(start: number, end: number): string;
|
||||
/**
|
||||
* Return the bits that are set past the subnet mask length
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsPastSubnet(): string;
|
||||
/**
|
||||
* Return the reversed ip6.arpa form of the address
|
||||
* @memberof Address6
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
reverseForm(options?: common.ReverseFormOptions): string;
|
||||
/**
|
||||
* Returns the address in correct form, per
|
||||
* [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952): leading zeros
|
||||
* stripped, the longest run of zero groups collapsed to `::`, and hex digits
|
||||
* lowercased (e.g. `2001:db8::1`). This is the recommended form for display.
|
||||
* Return the correct form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
correctForm(): string;
|
||||
/**
|
||||
* Return a zero-padded base-2 string representation of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001:803::1011');
|
||||
@@ -264,40 +236,33 @@ export declare class Address6 {
|
||||
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
||||
*/
|
||||
binaryZeroPad(): string;
|
||||
/**
|
||||
* Parses a v4-in-v6 string (e.g. `::ffff:192.168.0.1`) by extracting the
|
||||
* trailing IPv4 address into `this.address4` / `this.parsedAddress4` and
|
||||
* returning the address with the v4 portion converted to two v6 groups.
|
||||
* Used internally by `parse()`.
|
||||
*/
|
||||
parse4in6(address: string): string;
|
||||
/**
|
||||
* Parses an IPv6 address string into its 8 hexadecimal groups (expanding
|
||||
* any `::` elision and any trailing v4-in-v6 portion) and stores the result
|
||||
* on `this.parsedAddress`. Called automatically by the constructor; you
|
||||
* typically don't need to call it directly. Throws `AddressError` if the
|
||||
* input is malformed.
|
||||
*/
|
||||
parse(address: string): string[];
|
||||
/**
|
||||
* Returns the canonical (fully expanded) form of the address: all 8 groups,
|
||||
* each padded to 4 hex digits, with no `::` collapsing
|
||||
* (e.g. `2001:0db8:0000:0000:0000:0000:0000:0001`). Useful for sorting and
|
||||
* byte-exact comparison.
|
||||
* Return the canonical form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
canonicalForm(): string;
|
||||
/**
|
||||
* Return the decimal form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
decimal(): string;
|
||||
/**
|
||||
* Return the address as a BigInt
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
bigInt(): bigint;
|
||||
/**
|
||||
* Return the last two groups of this address as an IPv4 address string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001::1825:bf11');
|
||||
@@ -306,160 +271,129 @@ export declare class Address6 {
|
||||
to4(): Address4;
|
||||
/**
|
||||
* Return the v4-in-v6 form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
to4in6(): string;
|
||||
/**
|
||||
* Decodes the Teredo tunneling fields embedded in this address. Returns the
|
||||
* Teredo prefix, server IPv4, client IPv4, raw flag bits, cone-NAT flag,
|
||||
* UDP port, and Microsoft-format flag breakdown (reserved, universal/local,
|
||||
* group/individual, nonce). Only meaningful for addresses in `2001::/32`.
|
||||
* Return an object containing the Teredo properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
inspectTeredo(): TeredoProperties;
|
||||
/**
|
||||
* Decodes the 6to4 tunneling fields embedded in this address. Returns the
|
||||
* 6to4 prefix and the embedded IPv4 gateway address. Only meaningful for
|
||||
* addresses in `2002::/16`.
|
||||
* Return an object containing the 6to4 properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
inspect6to4(): SixToFourProperties;
|
||||
/**
|
||||
* Return a v6 6to4 address from a v6 v4inv6 address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
to6to4(): Address6 | null;
|
||||
/**
|
||||
* Embed an IPv4 address into a NAT64 IPv6 address using the encoding
|
||||
* defined by [RFC 6052](https://datatracker.ietf.org/doc/html/rfc6052).
|
||||
* The default prefix is the well-known prefix `64:ff9b::/96`. The prefix
|
||||
* length must be one of 32, 40, 48, 56, 64, or 96; for prefixes shorter
|
||||
* than /64 the IPv4 octets are split around the reserved bits 64–71.
|
||||
* @example
|
||||
* Address6.fromAddress4Nat64('192.0.2.33').correctForm(); // '64:ff9b::c000:221'
|
||||
* Address6.fromAddress4Nat64('192.0.2.33', '2001:db8::/32').correctForm(); // '2001:db8:c000:221::'
|
||||
*/
|
||||
static fromAddress4Nat64(address: string, prefix?: string): Address6;
|
||||
/**
|
||||
* Extract the embedded IPv4 address from a NAT64 IPv6 address using the
|
||||
* encoding defined by [RFC 6052](https://datatracker.ietf.org/doc/html/rfc6052).
|
||||
* The default prefix is the well-known prefix `64:ff9b::/96`. Returns
|
||||
* `null` if this address is not contained within the given prefix.
|
||||
* @example
|
||||
* new Address6('64:ff9b::c000:221').toAddress4Nat64()!.correctForm(); // '192.0.2.33'
|
||||
*/
|
||||
toAddress4Nat64(prefix?: string): Address4 | null;
|
||||
/**
|
||||
* Return a byte array.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toByteArray())`.
|
||||
* Return a byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toByteArray(): number[];
|
||||
/**
|
||||
* Return an unsigned byte array.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toUnsignedByteArray())`.
|
||||
* Return an unsigned byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toUnsignedByteArray(): number[];
|
||||
/**
|
||||
* Convert a byte array to an Address6 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address6.fromByteArray([...buf])`.
|
||||
* Convert a byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
static fromByteArray(bytes: Array<any>): Address6;
|
||||
/**
|
||||
* Convert an unsigned byte array to an Address6 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address6.fromUnsignedByteArray([...buf])`.
|
||||
* Convert an unsigned byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
static fromUnsignedByteArray(bytes: Array<any>): Address6;
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isInSubnet: typeof common.isInSubnet;
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isCorrect: (this: Address4 | Address6) => boolean;
|
||||
/**
|
||||
* Returns true if the address is in the canonical form, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isCanonical(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a link local address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLinkLocal(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a multicast address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMulticast(): boolean;
|
||||
/**
|
||||
* Returns true if the address was written in v4-in-v6 dotted-quad notation
|
||||
* (e.g. `::ffff:127.0.0.1`), false otherwise. This is a notation-level flag
|
||||
* and does not reflect whether the address bits lie in the IPv4-mapped
|
||||
* (`::ffff:0:0/96`) subnet — for that, see {@link isMapped4}.
|
||||
* Returns true if the address is a v4-in-v6 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
is4(): boolean;
|
||||
/**
|
||||
* Returns true if the address is an IPv4-mapped IPv6 address in
|
||||
* `::ffff:0:0/96` ([RFC 4291 §2.5.5.2](https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2)),
|
||||
* false otherwise. Unlike {@link is4}, this checks the underlying address
|
||||
* bits rather than the textual notation, so `::ffff:127.0.0.1` and
|
||||
* `::ffff:7f00:1` both return true.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMapped4(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a Teredo address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isTeredo(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a 6to4 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
is6to4(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a loopback address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoopback(): boolean;
|
||||
/**
|
||||
* Returns true if the address is a Unique Local Address in `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)). ULAs are the IPv6 equivalent of IPv4 [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private addresses.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isULA(): boolean;
|
||||
/**
|
||||
* Returns true if the address is the unspecified address `::`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUnspecified(): boolean;
|
||||
/**
|
||||
* Returns true if the address is in the documentation prefix `2001:db8::/32` ([RFC 3849](https://datatracker.ietf.org/doc/html/rfc3849)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isDocumentation(): boolean;
|
||||
/**
|
||||
* Returns the address as an HTTP URL with the host bracketed, e.g.
|
||||
* `http://[2001:db8::1]/`. If `optionalPort` is provided it is appended,
|
||||
* e.g. `http://[2001:db8::1]:8080/`.
|
||||
* @returns {String} the address in link form with a default port of 80
|
||||
*/
|
||||
href(optionalPort?: number | string): string;
|
||||
/**
|
||||
* Returns an HTML `<a>` element whose `href` encodes the address in a URL
|
||||
* hash fragment (default prefix `/#address=`). Useful for linking between
|
||||
* pages of an address-inspector UI.
|
||||
* @param options.className - CSS class for the rendered `<a>` element
|
||||
* @param options.prefix - hash prefix prepended to the address (default `/#address=`)
|
||||
* @param options.v4 - when true, render the address in v4-in-v6 form
|
||||
* @returns {String} a link suitable for conveying the address via a URL hash
|
||||
*/
|
||||
link(options?: {
|
||||
className?: string;
|
||||
@@ -474,6 +408,8 @@ export declare class Address6 {
|
||||
/**
|
||||
* Generate a regular expression string that can be used to find or validate
|
||||
* all variations of this address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {boolean} substringSearch
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -481,9 +417,12 @@ export declare class Address6 {
|
||||
/**
|
||||
* Generate a regular expression that can be used to find or validate all
|
||||
* variations of this address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {boolean} substringSearch
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
regularExpression(this: Address6, substringSearch?: boolean): RegExp;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=ipv6.d.ts.map
|
||||
+131
-345
@@ -34,7 +34,6 @@ const ipv4_1 = require("./ipv4");
|
||||
const regular_expressions_1 = require("./v6/regular-expressions");
|
||||
const address_error_1 = require("./address-error");
|
||||
const common_1 = require("./common");
|
||||
const isCorrect6 = common.isCorrect(constants6.BITS);
|
||||
function assert(condition) {
|
||||
if (!condition) {
|
||||
throw new Error('Assertion failed.');
|
||||
@@ -78,6 +77,7 @@ function unsignByte(b) {
|
||||
}
|
||||
/**
|
||||
* Represents an IPv6 address
|
||||
* @class Address6
|
||||
* @param {string} address - An IPv6 address string
|
||||
* @param {number} [groups=8] - How many octets to parse
|
||||
* @example
|
||||
@@ -94,14 +94,18 @@ class Address6 {
|
||||
// #region Attributes
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
this.isInSubnet = common.isInSubnet;
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
this.isCorrect = isCorrect6;
|
||||
this.isCorrect = common.isCorrect(constants6.BITS);
|
||||
if (optionalGroups === undefined) {
|
||||
this.groups = constants6.GROUPS;
|
||||
}
|
||||
@@ -132,13 +136,6 @@ class Address6 {
|
||||
this.addressMinusSuffix = address;
|
||||
this.parsedAddress = this.parse(this.addressMinusSuffix);
|
||||
}
|
||||
/**
|
||||
* Returns true if the given string is a valid IPv6 address (with optional
|
||||
* CIDR subnet and zone identifier), false otherwise. Host bits in the
|
||||
* subnet portion are allowed (e.g. `2001:db8::1/32` is valid); for strict
|
||||
* network-address validation compare `correctForm()` to
|
||||
* `startAddress().correctForm()`, or use `networkForm()`.
|
||||
*/
|
||||
static isValid(address) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
@@ -150,8 +147,9 @@ class Address6 {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Convert a BigInt to a v6 address object. The value must be in the
|
||||
* range `[0, 2**128 - 1]`; otherwise `AddressError` is thrown.
|
||||
* Convert a BigInt to a v6 address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {bigint} bigInt - a BigInt to convert
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
@@ -160,21 +158,19 @@ class Address6 {
|
||||
* address.correctForm(); // '::e8:d4a5:1000'
|
||||
*/
|
||||
static fromBigInt(bigInt) {
|
||||
if (bigInt < 0n || bigInt > (1n << BigInt(constants6.BITS)) - 1n) {
|
||||
throw new address_error_1.AddressError('IPv6 BigInt must be in the range 0 to 2**128 - 1');
|
||||
}
|
||||
const hex = bigInt.toString(16).padStart(32, '0');
|
||||
const groups = [];
|
||||
for (let i = 0; i < constants6.GROUPS; i++) {
|
||||
let i;
|
||||
for (i = 0; i < constants6.GROUPS; i++) {
|
||||
groups.push(hex.slice(i * 4, (i + 1) * 4));
|
||||
}
|
||||
return new Address6(groups.join(':'));
|
||||
}
|
||||
/**
|
||||
* Parse a URL (with optional bracketed host and port) into an address and
|
||||
* port. Returns either `{ address, port }` on success or
|
||||
* `{ error, address: null, port: null }` if the URL could not be parsed.
|
||||
* Ports are returned as numbers (or `null` if absent or out of range).
|
||||
* Convert a URL (with optional port number) to an address object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} url - a URL with optional port number
|
||||
* @example
|
||||
* var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
|
||||
* addressAndPort.address.correctForm(); // 'ffff::'
|
||||
@@ -233,92 +229,10 @@ class Address6 {
|
||||
port,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Construct an `Address6` from an address and a hex subnet mask given as
|
||||
* separate strings (e.g. as returned by Node's `os.networkInterfaces()`).
|
||||
* Throws `AddressError` if the mask is non-contiguous (e.g.
|
||||
* `ffff::ffff`).
|
||||
* @example
|
||||
* var address = Address6.fromAddressAndMask('fe80::1', 'ffff:ffff:ffff:ffff::');
|
||||
* address.subnetMask; // 64
|
||||
*/
|
||||
static fromAddressAndMask(address, mask) {
|
||||
const bits = common.prefixLengthFromMask(new Address6(mask).bigInt(), constants6.BITS);
|
||||
return new Address6(`${address}/${bits}`);
|
||||
}
|
||||
/**
|
||||
* Construct an `Address6` from an address and a Cisco-style wildcard mask
|
||||
* given as separate strings (e.g. `::ffff:ffff:ffff:ffff` for a `/64`).
|
||||
* The wildcard mask is the bitwise inverse of the subnet mask. Throws
|
||||
* `AddressError` if the mask is non-contiguous.
|
||||
* @example
|
||||
* var address = Address6.fromAddressAndWildcardMask('fe80::1', '::ffff:ffff:ffff:ffff');
|
||||
* address.subnetMask; // 64
|
||||
*/
|
||||
static fromAddressAndWildcardMask(address, wildcardMask) {
|
||||
const wildcard = new Address6(wildcardMask).bigInt();
|
||||
const allOnes = (BigInt(1) << BigInt(constants6.BITS)) - BigInt(1);
|
||||
// eslint-disable-next-line no-bitwise
|
||||
const mask = wildcard ^ allOnes;
|
||||
const bits = common.prefixLengthFromMask(mask, constants6.BITS);
|
||||
return new Address6(`${address}/${bits}`);
|
||||
}
|
||||
/**
|
||||
* Construct an `Address6` from a wildcard pattern with trailing `*`
|
||||
* groups. The number of trailing wildcards determines the prefix
|
||||
* length: each `*` represents 16 bits. `::` is expanded to zero groups
|
||||
* (not wildcards) before evaluating trailing wildcards.
|
||||
*
|
||||
* Only trailing whole-group wildcards are supported. Partial-group
|
||||
* wildcards (e.g. `2001:db8::0*`) and interior wildcards (e.g.
|
||||
* `*::1`) throw `AddressError`.
|
||||
* @example
|
||||
* Address6.fromWildcard('2001:db8:*:*:*:*:*:*').subnet; // '/32'
|
||||
* Address6.fromWildcard('2001:db8::*').subnet; // '/112'
|
||||
* Address6.fromWildcard('*:*:*:*:*:*:*:*').subnet; // '/0'
|
||||
*/
|
||||
static fromWildcard(input) {
|
||||
if (input.includes('%') || input.includes('/')) {
|
||||
throw new address_error_1.AddressError('Wildcard pattern must not include a zone or CIDR suffix');
|
||||
}
|
||||
const halves = input.split('::');
|
||||
if (halves.length > 2) {
|
||||
throw new address_error_1.AddressError("Wildcard pattern cannot contain more than one '::'");
|
||||
}
|
||||
let groups;
|
||||
if (halves.length === 2) {
|
||||
const left = halves[0] === '' ? [] : halves[0].split(':');
|
||||
const right = halves[1] === '' ? [] : halves[1].split(':');
|
||||
const remaining = constants6.GROUPS - left.length - right.length;
|
||||
if (remaining < 1) {
|
||||
throw new address_error_1.AddressError("Wildcard pattern with '::' has too many groups");
|
||||
}
|
||||
groups = [...left, ...new Array(remaining).fill('0'), ...right];
|
||||
}
|
||||
else {
|
||||
groups = input.split(':');
|
||||
}
|
||||
if (groups.length !== constants6.GROUPS) {
|
||||
throw new address_error_1.AddressError('Wildcard pattern must have 8 groups');
|
||||
}
|
||||
let firstWildcard = -1;
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
if (groups[i] === '*') {
|
||||
if (firstWildcard === -1) {
|
||||
firstWildcard = i;
|
||||
}
|
||||
}
|
||||
else if (firstWildcard !== -1) {
|
||||
throw new address_error_1.AddressError('Wildcard `*` must only appear in trailing groups (e.g. `2001:db8:*:*:*:*:*:*`)');
|
||||
}
|
||||
}
|
||||
const trailing = firstWildcard === -1 ? 0 : groups.length - firstWildcard;
|
||||
const replaced = groups.map((g) => (g === '*' ? '0' : g));
|
||||
const subnetBits = constants6.BITS - trailing * 16;
|
||||
return new Address6(`${replaced.join(':')}/${subnetBits}`);
|
||||
}
|
||||
/**
|
||||
* Create an IPv6-mapped address given an IPv4 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} address - An IPv4 address string
|
||||
* @returns {Address6}
|
||||
* @example
|
||||
@@ -333,6 +247,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return an address from ip6.arpa form
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
||||
* @returns {Adress6}
|
||||
* @example
|
||||
@@ -357,6 +273,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the Microsoft UNC transcription of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String} the Microsoft UNC transcription of the address
|
||||
*/
|
||||
microsoftTranscription() {
|
||||
@@ -364,6 +282,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the first n bits of the address, defaulting to the subnet mask
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [mask=subnet] - the number of bits to mask
|
||||
* @returns {String} the first n bits of the address as a string
|
||||
*/
|
||||
@@ -372,6 +292,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the number of possible subnets of a given size in the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {number} [subnetSize=128] - the subnet size
|
||||
* @returns {String}
|
||||
*/
|
||||
@@ -387,6 +309,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_startAddress() {
|
||||
@@ -395,6 +319,8 @@ class Address6 {
|
||||
/**
|
||||
* The first address in the range given by this address' subnet
|
||||
* Often referred to as the Network Address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
startAddress() {
|
||||
@@ -403,6 +329,8 @@ class Address6 {
|
||||
/**
|
||||
* The first host address in the range given by this address's subnet ie
|
||||
* the first address after the Network Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
startAddressExclusive() {
|
||||
@@ -411,6 +339,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
_endAddress() {
|
||||
@@ -419,6 +349,8 @@ class Address6 {
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
endAddress() {
|
||||
@@ -427,6 +359,8 @@ class Address6 {
|
||||
/**
|
||||
* The last host address in the range given by this address's subnet ie
|
||||
* the last address prior to the Broadcast Address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
endAddressExclusive() {
|
||||
@@ -434,73 +368,36 @@ class Address6 {
|
||||
return Address6.fromBigInt(this._endAddress() - adjust);
|
||||
}
|
||||
/**
|
||||
* The hex form of the subnet mask, e.g. `ffff:ffff:ffff:ffff::` for a
|
||||
* `/64`. Returns an `Address6`; call `.correctForm()` for the string.
|
||||
* @returns {Address6}
|
||||
*/
|
||||
subnetMaskAddress() {
|
||||
return Address6.fromBigInt(BigInt(`0b${'1'.repeat(this.subnetMask)}${'0'.repeat(constants6.BITS - this.subnetMask)}`));
|
||||
}
|
||||
/**
|
||||
* The Cisco-style wildcard mask, e.g. `::ffff:ffff:ffff:ffff` for a
|
||||
* `/64`. This is the bitwise inverse of `subnetMaskAddress()`. Returns
|
||||
* an `Address6`; call `.correctForm()` for the string.
|
||||
* @returns {Address6}
|
||||
*/
|
||||
wildcardMask() {
|
||||
return Address6.fromBigInt(BigInt(`0b${'0'.repeat(this.subnetMask)}${'1'.repeat(constants6.BITS - this.subnetMask)}`));
|
||||
}
|
||||
/**
|
||||
* The network address in CIDR string form, e.g. `2001:db8::/32` for
|
||||
* `2001:db8::1/32`. For an address with no explicit subnet the prefix
|
||||
* is `/128`, e.g. `networkForm()` on `2001:db8::1` returns
|
||||
* `2001:db8::1/128`.
|
||||
* @returns {string}
|
||||
*/
|
||||
networkForm() {
|
||||
return `${this.startAddress().correctForm()}/${this.subnetMask}`;
|
||||
}
|
||||
/**
|
||||
* Return the scope of the address. The 4-bit scope field
|
||||
* ([RFC 4291 §2.7](https://datatracker.ietf.org/doc/html/rfc4291#section-2.7))
|
||||
* is only defined for multicast addresses; for unicast addresses the scope
|
||||
* is derived from the address type per
|
||||
* [RFC 4007 §6](https://datatracker.ietf.org/doc/html/rfc4007#section-6).
|
||||
* Return the scope of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getScope() {
|
||||
const type = this.getType();
|
||||
if (type === 'Multicast' || type.startsWith('Multicast ')) {
|
||||
const scope = constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
|
||||
return scope || 'Unknown';
|
||||
let scope = constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
|
||||
if (this.getType() === 'Global unicast' && scope !== 'Link local') {
|
||||
scope = 'Global';
|
||||
}
|
||||
// RFC 4291 §2.5.3: the loopback address is treated as having Link-Local
|
||||
// scope. (Multicast scope 1, "Interface-Local", is a different concept
|
||||
// used only for loopback transmission of multicast.)
|
||||
if (type === 'Link-local unicast' || type === 'Loopback') {
|
||||
return 'Link local';
|
||||
}
|
||||
// RFC 4007 §6: the unspecified address has no scope.
|
||||
if (type === 'Unspecified') {
|
||||
return 'Unknown';
|
||||
}
|
||||
return 'Global';
|
||||
return scope || 'Unknown';
|
||||
}
|
||||
/**
|
||||
* Return the type of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getType() {
|
||||
for (let i = 0; i < TYPE_SUBNETS.length; i++) {
|
||||
const entry = TYPE_SUBNETS[i];
|
||||
if (this.isInSubnet(entry[0])) {
|
||||
return entry[1];
|
||||
for (const subnet of Object.keys(constants6.TYPES)) {
|
||||
if (this.isInSubnet(new Address6(subnet))) {
|
||||
return constants6.TYPES[subnet];
|
||||
}
|
||||
}
|
||||
return 'Global unicast';
|
||||
}
|
||||
/**
|
||||
* Return the bits in the given range as a BigInt
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
getBits(start, end) {
|
||||
@@ -508,6 +405,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the bits in the given range as a base-2 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsBase2(start, end) {
|
||||
@@ -515,6 +414,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the bits in the given range as a base-16 string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsBase16(start, end) {
|
||||
@@ -528,6 +429,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the bits that are set past the subnet mask length
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
getBitsPastSubnet() {
|
||||
@@ -535,8 +438,10 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the reversed ip6.arpa form of the address
|
||||
* @memberof Address6
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
reverseForm(options) {
|
||||
@@ -562,10 +467,10 @@ class Address6 {
|
||||
return 'ip6.arpa.';
|
||||
}
|
||||
/**
|
||||
* Returns the address in correct form, per
|
||||
* [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952): leading zeros
|
||||
* stripped, the longest run of zero groups collapsed to `::`, and hex digits
|
||||
* lowercased (e.g. `2001:db8::1`). This is the recommended form for display.
|
||||
* Return the correct form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
correctForm() {
|
||||
let i;
|
||||
@@ -609,6 +514,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return a zero-padded base-2 string representation of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001:803::1011');
|
||||
@@ -617,22 +524,10 @@ class Address6 {
|
||||
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
||||
*/
|
||||
binaryZeroPad() {
|
||||
if (this._binaryZeroPad === undefined) {
|
||||
this._binaryZeroPad = this.bigInt().toString(2).padStart(constants6.BITS, '0');
|
||||
}
|
||||
return this._binaryZeroPad;
|
||||
return this.bigInt().toString(2).padStart(constants6.BITS, '0');
|
||||
}
|
||||
/**
|
||||
* Parses a v4-in-v6 string (e.g. `::ffff:192.168.0.1`) by extracting the
|
||||
* trailing IPv4 address into `this.address4` / `this.parsedAddress4` and
|
||||
* returning the address with the v4 portion converted to two v6 groups.
|
||||
* Used internally by `parse()`.
|
||||
*/
|
||||
// TODO: Improve the semantics of this helper function
|
||||
parse4in6(address) {
|
||||
if (address.indexOf('.') === -1) {
|
||||
return address;
|
||||
}
|
||||
const groups = address.split(':');
|
||||
const lastGroup = groups.slice(-1)[0];
|
||||
const address4 = lastGroup.match(constants4.RE_ADDRESS);
|
||||
@@ -641,12 +536,7 @@ class Address6 {
|
||||
this.address4 = new ipv4_1.Address4(this.parsedAddress4);
|
||||
for (let i = 0; i < this.address4.groups; i++) {
|
||||
if (/^0[0-9]+/.test(this.address4.parsedAddress[i])) {
|
||||
// The prefix groups haven't been through the bad-character check
|
||||
// yet, so escape them before including in the error HTML.
|
||||
const highlighted = this.address4.parsedAddress.map(spanLeadingZeroes4).join('.');
|
||||
const prefix = groups.slice(0, -1).map(helpers.escapeHtml).join(':');
|
||||
const separator = groups.length > 1 ? ':' : '';
|
||||
throw new address_error_1.AddressError("IPv4 addresses can't have leading zeroes.", `${prefix}${separator}${highlighted}`);
|
||||
throw new address_error_1.AddressError("IPv4 addresses can't have leading zeroes.", address.replace(constants4.RE_ADDRESS, this.address4.parsedAddress.map(spanLeadingZeroes4).join('.')));
|
||||
}
|
||||
}
|
||||
this.v4 = true;
|
||||
@@ -655,13 +545,6 @@ class Address6 {
|
||||
}
|
||||
return address;
|
||||
}
|
||||
/**
|
||||
* Parses an IPv6 address string into its 8 hexadecimal groups (expanding
|
||||
* any `::` elision and any trailing v4-in-v6 portion) and stores the result
|
||||
* on `this.parsedAddress`. Called automatically by the constructor; you
|
||||
* typically don't need to call it directly. Throws `AddressError` if the
|
||||
* input is malformed.
|
||||
*/
|
||||
// TODO: Make private?
|
||||
parse(address) {
|
||||
address = this.parse4in6(address);
|
||||
@@ -711,16 +594,18 @@ class Address6 {
|
||||
return groups;
|
||||
}
|
||||
/**
|
||||
* Returns the canonical (fully expanded) form of the address: all 8 groups,
|
||||
* each padded to 4 hex digits, with no `::` collapsing
|
||||
* (e.g. `2001:0db8:0000:0000:0000:0000:0000:0001`). Useful for sorting and
|
||||
* byte-exact comparison.
|
||||
* Return the canonical form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
canonicalForm() {
|
||||
return this.parsedAddress.map(paddedHex).join(':');
|
||||
}
|
||||
/**
|
||||
* Return the decimal form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
decimal() {
|
||||
@@ -728,6 +613,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the address as a BigInt
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {bigint}
|
||||
*/
|
||||
bigInt() {
|
||||
@@ -735,6 +622,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return the last two groups of this address as an IPv4 address string
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
* @example
|
||||
* var address = new Address6('2001:4860:4001::1825:bf11');
|
||||
@@ -742,10 +631,12 @@ class Address6 {
|
||||
*/
|
||||
to4() {
|
||||
const binary = this.binaryZeroPad().split('');
|
||||
return ipv4_1.Address4.fromHex(BigInt(`0b${binary.slice(96, 128).join('')}`).toString(16).padStart(8, '0'));
|
||||
return ipv4_1.Address4.fromHex(BigInt(`0b${binary.slice(96, 128).join('')}`).toString(16));
|
||||
}
|
||||
/**
|
||||
* Return the v4-in-v6 form of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
to4in6() {
|
||||
@@ -759,10 +650,10 @@ class Address6 {
|
||||
return correct + infix + address4.address;
|
||||
}
|
||||
/**
|
||||
* Decodes the Teredo tunneling fields embedded in this address. Returns the
|
||||
* Teredo prefix, server IPv4, client IPv4, raw flag bits, cone-NAT flag,
|
||||
* UDP port, and Microsoft-format flag breakdown (reserved, universal/local,
|
||||
* group/individual, nonce). Only meaningful for addresses in `2001::/32`.
|
||||
* Return an object containing the Teredo properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
inspectTeredo() {
|
||||
/*
|
||||
@@ -793,7 +684,7 @@ class Address6 {
|
||||
const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64));
|
||||
const bitsForClient4 = this.getBits(96, 128);
|
||||
// eslint-disable-next-line no-bitwise
|
||||
const client4 = ipv4_1.Address4.fromHex((bitsForClient4 ^ BigInt('0xffffffff')).toString(16).padStart(8, '0'));
|
||||
const client4 = ipv4_1.Address4.fromHex((bitsForClient4 ^ BigInt('0xffffffff')).toString(16));
|
||||
const flagsBase2 = this.getBitsBase2(64, 80);
|
||||
const coneNat = (0, common_1.testBit)(flagsBase2, 15);
|
||||
const reserved = (0, common_1.testBit)(flagsBase2, 14);
|
||||
@@ -816,9 +707,10 @@ class Address6 {
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Decodes the 6to4 tunneling fields embedded in this address. Returns the
|
||||
* 6to4 prefix and the embedded IPv4 gateway address. Only meaningful for
|
||||
* addresses in `2002::/16`.
|
||||
* Return an object containing the 6to4 properties of the address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Object}
|
||||
*/
|
||||
inspect6to4() {
|
||||
/*
|
||||
@@ -834,6 +726,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Return a v6 6to4 address from a v6 v4inv6 address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Address6}
|
||||
*/
|
||||
to6to4() {
|
||||
@@ -850,80 +744,9 @@ class Address6 {
|
||||
return new Address6(addr6to4);
|
||||
}
|
||||
/**
|
||||
* Embed an IPv4 address into a NAT64 IPv6 address using the encoding
|
||||
* defined by [RFC 6052](https://datatracker.ietf.org/doc/html/rfc6052).
|
||||
* The default prefix is the well-known prefix `64:ff9b::/96`. The prefix
|
||||
* length must be one of 32, 40, 48, 56, 64, or 96; for prefixes shorter
|
||||
* than /64 the IPv4 octets are split around the reserved bits 64–71.
|
||||
* @example
|
||||
* Address6.fromAddress4Nat64('192.0.2.33').correctForm(); // '64:ff9b::c000:221'
|
||||
* Address6.fromAddress4Nat64('192.0.2.33', '2001:db8::/32').correctForm(); // '2001:db8:c000:221::'
|
||||
*/
|
||||
static fromAddress4Nat64(address, prefix = '64:ff9b::/96') {
|
||||
const v4 = new ipv4_1.Address4(address);
|
||||
const prefix6 = new Address6(prefix);
|
||||
const pl = prefix6.subnetMask;
|
||||
if (pl !== 32 && pl !== 40 && pl !== 48 && pl !== 56 && pl !== 64 && pl !== 96) {
|
||||
throw new address_error_1.AddressError('NAT64 prefix length must be 32, 40, 48, 56, 64, or 96');
|
||||
}
|
||||
const prefixBits = prefix6.binaryZeroPad();
|
||||
const v4Bits = v4.binaryZeroPad();
|
||||
let bits;
|
||||
if (pl === 96) {
|
||||
bits = prefixBits.slice(0, 96) + v4Bits;
|
||||
}
|
||||
else {
|
||||
const beforeU = 64 - pl;
|
||||
bits =
|
||||
prefixBits.slice(0, pl) +
|
||||
v4Bits.slice(0, beforeU) +
|
||||
'00000000' +
|
||||
v4Bits.slice(beforeU) +
|
||||
'0'.repeat(128 - 72 - (32 - beforeU));
|
||||
}
|
||||
const hex = BigInt(`0b${bits}`).toString(16).padStart(32, '0');
|
||||
const groups = [];
|
||||
for (let i = 0; i < 8; i++) {
|
||||
groups.push(hex.slice(i * 4, (i + 1) * 4));
|
||||
}
|
||||
return new Address6(groups.join(':'));
|
||||
}
|
||||
/**
|
||||
* Extract the embedded IPv4 address from a NAT64 IPv6 address using the
|
||||
* encoding defined by [RFC 6052](https://datatracker.ietf.org/doc/html/rfc6052).
|
||||
* The default prefix is the well-known prefix `64:ff9b::/96`. Returns
|
||||
* `null` if this address is not contained within the given prefix.
|
||||
* @example
|
||||
* new Address6('64:ff9b::c000:221').toAddress4Nat64()!.correctForm(); // '192.0.2.33'
|
||||
*/
|
||||
toAddress4Nat64(prefix = '64:ff9b::/96') {
|
||||
const prefix6 = new Address6(prefix);
|
||||
const pl = prefix6.subnetMask;
|
||||
if (pl !== 32 && pl !== 40 && pl !== 48 && pl !== 56 && pl !== 64 && pl !== 96) {
|
||||
throw new address_error_1.AddressError('NAT64 prefix length must be 32, 40, 48, 56, 64, or 96');
|
||||
}
|
||||
if (!this.isInSubnet(prefix6)) {
|
||||
return null;
|
||||
}
|
||||
const bits = this.binaryZeroPad();
|
||||
let v4Bits;
|
||||
if (pl === 96) {
|
||||
v4Bits = bits.slice(96, 128);
|
||||
}
|
||||
else {
|
||||
const beforeU = 64 - pl;
|
||||
v4Bits = bits.slice(pl, pl + beforeU) + bits.slice(72, 72 + (32 - beforeU));
|
||||
}
|
||||
const octets = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
octets.push(parseInt(v4Bits.slice(i * 8, (i + 1) * 8), 2).toString());
|
||||
}
|
||||
return new ipv4_1.Address4(octets.join('.'));
|
||||
}
|
||||
/**
|
||||
* Return a byte array.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toByteArray())`.
|
||||
* Return a byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toByteArray() {
|
||||
@@ -937,27 +760,27 @@ class Address6 {
|
||||
return bytes;
|
||||
}
|
||||
/**
|
||||
* Return an unsigned byte array.
|
||||
*
|
||||
* To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toUnsignedByteArray())`.
|
||||
* Return an unsigned byte array
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toUnsignedByteArray() {
|
||||
return this.toByteArray().map(unsignByte);
|
||||
}
|
||||
/**
|
||||
* Convert a byte array to an Address6 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address6.fromByteArray([...buf])`.
|
||||
* Convert a byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
static fromByteArray(bytes) {
|
||||
return this.fromUnsignedByteArray(bytes.map(unsignByte));
|
||||
}
|
||||
/**
|
||||
* Convert an unsigned byte array to an Address6 object.
|
||||
*
|
||||
* To convert from a Node.js `Buffer`, spread it: `Address6.fromUnsignedByteArray([...buf])`.
|
||||
* Convert an unsigned byte array to an Address6 object
|
||||
* @memberof Address6
|
||||
* @static
|
||||
* @returns {Address6}
|
||||
*/
|
||||
static fromUnsignedByteArray(bytes) {
|
||||
@@ -972,6 +795,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in the canonical form, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isCanonical() {
|
||||
@@ -979,6 +804,8 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a link local address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLinkLocal() {
|
||||
@@ -991,81 +818,53 @@ class Address6 {
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a multicast address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMulticast() {
|
||||
const type = this.getType();
|
||||
return type === 'Multicast' || type.startsWith('Multicast ');
|
||||
return this.getType() === 'Multicast';
|
||||
}
|
||||
/**
|
||||
* Returns true if the address was written in v4-in-v6 dotted-quad notation
|
||||
* (e.g. `::ffff:127.0.0.1`), false otherwise. This is a notation-level flag
|
||||
* and does not reflect whether the address bits lie in the IPv4-mapped
|
||||
* (`::ffff:0:0/96`) subnet — for that, see {@link isMapped4}.
|
||||
* Returns true if the address is a v4-in-v6 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
is4() {
|
||||
return this.v4;
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is an IPv4-mapped IPv6 address in
|
||||
* `::ffff:0:0/96` ([RFC 4291 §2.5.5.2](https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2)),
|
||||
* false otherwise. Unlike {@link is4}, this checks the underlying address
|
||||
* bits rather than the textual notation, so `::ffff:127.0.0.1` and
|
||||
* `::ffff:7f00:1` both return true.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMapped4() {
|
||||
return this.isInSubnet(IPV4_MAPPED_SUBNET);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a Teredo address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isTeredo() {
|
||||
return this.isInSubnet(TEREDO_SUBNET);
|
||||
return this.isInSubnet(new Address6('2001::/32'));
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a 6to4 address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
is6to4() {
|
||||
return this.isInSubnet(SIX_TO_FOUR_SUBNET);
|
||||
return this.isInSubnet(new Address6('2002::/16'));
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a loopback address, false otherwise
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoopback() {
|
||||
return this.getType() === 'Loopback';
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is a Unique Local Address in `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)). ULAs are the IPv6 equivalent of IPv4 [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private addresses.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isULA() {
|
||||
return this.isInSubnet(ULA_SUBNET);
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is the unspecified address `::`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUnspecified() {
|
||||
return this.getType() === 'Unspecified';
|
||||
}
|
||||
/**
|
||||
* Returns true if the address is in the documentation prefix `2001:db8::/32` ([RFC 3849](https://datatracker.ietf.org/doc/html/rfc3849)).
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isDocumentation() {
|
||||
return this.isInSubnet(DOCUMENTATION_SUBNET);
|
||||
}
|
||||
// #endregion
|
||||
// #region HTML
|
||||
/**
|
||||
* Returns the address as an HTTP URL with the host bracketed, e.g.
|
||||
* `http://[2001:db8::1]/`. If `optionalPort` is provided it is appended,
|
||||
* e.g. `http://[2001:db8::1]:8080/`.
|
||||
* @returns {String} the address in link form with a default port of 80
|
||||
*/
|
||||
href(optionalPort) {
|
||||
if (optionalPort === undefined) {
|
||||
@@ -1077,12 +876,7 @@ class Address6 {
|
||||
return `http://[${this.correctForm()}]${optionalPort}/`;
|
||||
}
|
||||
/**
|
||||
* Returns an HTML `<a>` element whose `href` encodes the address in a URL
|
||||
* hash fragment (default prefix `/#address=`). Useful for linking between
|
||||
* pages of an address-inspector UI.
|
||||
* @param options.className - CSS class for the rendered `<a>` element
|
||||
* @param options.prefix - hash prefix prepended to the address (default `/#address=`)
|
||||
* @param options.v4 - when true, render the address in v4-in-v6 form
|
||||
* @returns {String} a link suitable for conveying the address via a URL hash
|
||||
*/
|
||||
link(options) {
|
||||
if (!options) {
|
||||
@@ -1102,13 +896,10 @@ class Address6 {
|
||||
formFunction = this.to4in6;
|
||||
}
|
||||
const form = formFunction.call(this);
|
||||
const safeHref = helpers.escapeHtml(`${options.prefix}${form}`);
|
||||
const safeForm = helpers.escapeHtml(form);
|
||||
if (options.className) {
|
||||
const safeClass = helpers.escapeHtml(options.className);
|
||||
return `<a href="${safeHref}" class="${safeClass}">${safeForm}</a>`;
|
||||
return `<a href="${options.prefix}${form}" class="${options.className}">${form}</a>`;
|
||||
}
|
||||
return `<a href="${safeHref}">${safeForm}</a>`;
|
||||
return `<a href="${options.prefix}${form}">${form}</a>`;
|
||||
}
|
||||
/**
|
||||
* Groups an address
|
||||
@@ -1117,13 +908,13 @@ class Address6 {
|
||||
group() {
|
||||
if (this.elidedGroups === 0) {
|
||||
// The simple case
|
||||
return helpers.simpleGroup(this.addressMinusSuffix).join(':');
|
||||
return helpers.simpleGroup(this.address).join(':');
|
||||
}
|
||||
assert(typeof this.elidedGroups === 'number');
|
||||
assert(typeof this.elisionBegin === 'number');
|
||||
// The elided case
|
||||
const output = [];
|
||||
const [left, right] = this.addressMinusSuffix.split('::');
|
||||
const [left, right] = this.address.split('::');
|
||||
if (left.length) {
|
||||
output.push(...helpers.simpleGroup(left));
|
||||
}
|
||||
@@ -1153,6 +944,8 @@ class Address6 {
|
||||
/**
|
||||
* Generate a regular expression string that can be used to find or validate
|
||||
* all variations of this address
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {boolean} substringSearch
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -1197,6 +990,8 @@ class Address6 {
|
||||
/**
|
||||
* Generate a regular expression that can be used to find or validate all
|
||||
* variations of this address.
|
||||
* @memberof Address6
|
||||
* @instance
|
||||
* @param {boolean} substringSearch
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
@@ -1205,13 +1000,4 @@ class Address6 {
|
||||
}
|
||||
}
|
||||
exports.Address6 = Address6;
|
||||
const TYPE_SUBNETS = Object.keys(constants6.TYPES).map((subnet) => [
|
||||
new Address6(subnet),
|
||||
constants6.TYPES[subnet],
|
||||
]);
|
||||
const TEREDO_SUBNET = new Address6('2001::/32');
|
||||
const SIX_TO_FOUR_SUBNET = new Address6('2002::/16');
|
||||
const ULA_SUBNET = new Address6('fc00::/7');
|
||||
const DOCUMENTATION_SUBNET = new Address6('2001:db8::/32');
|
||||
const IPV4_MAPPED_SUBNET = new Address6('::ffff:0:0/96');
|
||||
//# sourceMappingURL=ipv6.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
@@ -2,3 +2,4 @@ export declare const BITS = 32;
|
||||
export declare const GROUPS = 4;
|
||||
export declare const RE_ADDRESS: RegExp;
|
||||
export declare const RE_SUBNET_STRING: RegExp;
|
||||
//# sourceMappingURL=constants.d.ts.map
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/v4/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG,EAAE,CAAC;AACV,QAAA,MAAM,GAAG,CAAC,CAAC;AAEX,QAAA,UAAU,GACrB,mKAAmK,CAAC;AAEzJ,QAAA,gBAAgB,GAAG,YAAY,CAAC","sourcesContent":["export const BITS = 32;\nexport const GROUPS = 4;\n\nexport const RE_ADDRESS =\n /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;\n\nexport const RE_SUBNET_STRING = /\\/\\d{1,2}$/;\n"]}
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/v4/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG,EAAE,CAAC;AACV,QAAA,MAAM,GAAG,CAAC,CAAC;AAEX,QAAA,UAAU,GACrB,mKAAmK,CAAC;AAEzJ,QAAA,gBAAgB,GAAG,YAAY,CAAC"}
|
||||
+1
@@ -42,3 +42,4 @@ export declare const RE_SUBNET_STRING: RegExp;
|
||||
export declare const RE_ZONE_STRING: RegExp;
|
||||
export declare const RE_URL: RegExp;
|
||||
export declare const RE_URL_WITH_PORT: RegExp;
|
||||
//# sourceMappingURL=constants.d.ts.map
|
||||
-5
@@ -46,11 +46,6 @@ exports.TYPES = {
|
||||
'::1/128': 'Loopback',
|
||||
'ff00::/8': 'Multicast',
|
||||
'fe80::/10': 'Link-local unicast',
|
||||
'fc00::/7': 'Unique local',
|
||||
'2002::/16': '6to4',
|
||||
'2001:db8::/32': 'Documentation',
|
||||
'64:ff9b::/96': 'NAT64 (well-known)',
|
||||
'64:ff9b:1::/48': 'NAT64 (local-use)',
|
||||
};
|
||||
/**
|
||||
* A regular expression that matches bad characters in an IPv6 address
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/v6/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG,GAAG,CAAC;AACX,QAAA,MAAM,GAAG,CAAC,CAAC;AAExB;;;;GAIG;AACU,QAAA,MAAM,GAA0C;IAC3D,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,iBAAiB;IACpB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,oBAAoB;IACvB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,UAAU;CACN,CAAC;AAEX;;;;GAIG;AACU,QAAA,KAAK,GAA0C;IAC1D,aAAa,EAAE,yCAAyC;IACxD,aAAa,EAAE,2CAA2C;IAC1D,aAAa,EAAE,oCAAoC;IACnD,aAAa,EAAE,sCAAsC;IACrD,aAAa,EAAE,sCAAsC;IACrD,aAAa,EAAE,mCAAmC;IAClD,aAAa,EAAE,kCAAkC;IACjD,aAAa,EAAE,yBAAyB;IACxC,aAAa,EAAE,2BAA2B;IAC1C,aAAa,EAAE,yBAAyB;IACxC,cAAc,EAAE,2BAA2B;IAC3C,cAAc,EAAE,oBAAoB;IACpC,cAAc,EAAE,oBAAoB;IACpC,cAAc,EAAE,oBAAoB;IACpC,eAAe,EAAE,4DAA4D;IAC7E,eAAe,EAAE,4DAA4D;IAC7E,eAAe,EAAE,2CAA2C;IAC5D,eAAe,EAAE,2CAA2C;IAC5D,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,WAAW;IACvB,WAAW,EAAE,oBAAoB;IACjC,UAAU,EAAE,cAAc;IAC1B,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,oBAAoB;IACpC,gBAAgB,EAAE,mBAAmB;CAC7B,CAAC;AAEX;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD;;;;GAIG;AACU,QAAA,cAAc,GAAG,0CAA0C,CAAC;AAEzE;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;;;GAIG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC;AAExB,QAAA,MAAM,GAAG,6BAA6B,CAAC;AACvC,QAAA,gBAAgB,GAAG,+BAA+B,CAAC","sourcesContent":["export const BITS = 128;\nexport const GROUPS = 8;\n\n/**\n * Represents IPv6 address scopes\n * @memberof Address6\n * @static\n */\nexport const SCOPES: { [key: number]: string | undefined } = {\n 0: 'Reserved',\n 1: 'Interface local',\n 2: 'Link local',\n 4: 'Admin local',\n 5: 'Site local',\n 8: 'Organization local',\n 14: 'Global',\n 15: 'Reserved',\n} as const;\n\n/**\n * Represents IPv6 address types\n * @memberof Address6\n * @static\n */\nexport const TYPES: { [key: string]: string | undefined } = {\n 'ff01::1/128': 'Multicast (All nodes on this interface)',\n 'ff01::2/128': 'Multicast (All routers on this interface)',\n 'ff02::1/128': 'Multicast (All nodes on this link)',\n 'ff02::2/128': 'Multicast (All routers on this link)',\n 'ff05::2/128': 'Multicast (All routers in this site)',\n 'ff02::5/128': 'Multicast (OSPFv3 AllSPF routers)',\n 'ff02::6/128': 'Multicast (OSPFv3 AllDR routers)',\n 'ff02::9/128': 'Multicast (RIP routers)',\n 'ff02::a/128': 'Multicast (EIGRP routers)',\n 'ff02::d/128': 'Multicast (PIM routers)',\n 'ff02::16/128': 'Multicast (MLDv2 reports)',\n 'ff01::fb/128': 'Multicast (mDNSv6)',\n 'ff02::fb/128': 'Multicast (mDNSv6)',\n 'ff05::fb/128': 'Multicast (mDNSv6)',\n 'ff02::1:2/128': 'Multicast (All DHCP servers and relay agents on this link)',\n 'ff05::1:2/128': 'Multicast (All DHCP servers and relay agents in this site)',\n 'ff02::1:3/128': 'Multicast (All DHCP servers on this link)',\n 'ff05::1:3/128': 'Multicast (All DHCP servers in this site)',\n '::/128': 'Unspecified',\n '::1/128': 'Loopback',\n 'ff00::/8': 'Multicast',\n 'fe80::/10': 'Link-local unicast',\n 'fc00::/7': 'Unique local',\n '2002::/16': '6to4',\n '2001:db8::/32': 'Documentation',\n '64:ff9b::/96': 'NAT64 (well-known)',\n '64:ff9b:1::/48': 'NAT64 (local-use)',\n} as const;\n\n/**\n * A regular expression that matches bad characters in an IPv6 address\n * @memberof Address6\n * @static\n */\nexport const RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi;\n\n/**\n * A regular expression that matches an incorrect IPv6 address\n * @memberof Address6\n * @static\n */\nexport const RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\\/$)/gi;\n\n/**\n * A regular expression that matches an IPv6 subnet\n * @memberof Address6\n * @static\n */\nexport const RE_SUBNET_STRING = /\\/\\d{1,3}(?=%|$)/;\n\n/**\n * A regular expression that matches an IPv6 zone\n * @memberof Address6\n * @static\n */\nexport const RE_ZONE_STRING = /%.*$/;\n\nexport const RE_URL = /^\\[{0,1}([0-9a-f:]+)\\]{0,1}/;\nexport const RE_URL_WITH_PORT = /\\[([0-9a-f:]+)\\]:([0-9]{1,5})/;\n"]}
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/v6/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG,GAAG,CAAC;AACX,QAAA,MAAM,GAAG,CAAC,CAAC;AAExB;;;;GAIG;AACU,QAAA,MAAM,GAA0C;IAC3D,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,iBAAiB;IACpB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,aAAa;IAChB,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,oBAAoB;IACvB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,UAAU;CACN,CAAC;AAEX;;;;GAIG;AACU,QAAA,KAAK,GAA0C;IAC1D,aAAa,EAAE,yCAAyC;IACxD,aAAa,EAAE,2CAA2C;IAC1D,aAAa,EAAE,oCAAoC;IACnD,aAAa,EAAE,sCAAsC;IACrD,aAAa,EAAE,sCAAsC;IACrD,aAAa,EAAE,mCAAmC;IAClD,aAAa,EAAE,kCAAkC;IACjD,aAAa,EAAE,yBAAyB;IACxC,aAAa,EAAE,2BAA2B;IAC1C,aAAa,EAAE,yBAAyB;IACxC,cAAc,EAAE,2BAA2B;IAC3C,cAAc,EAAE,oBAAoB;IACpC,cAAc,EAAE,oBAAoB;IACpC,cAAc,EAAE,oBAAoB;IACpC,eAAe,EAAE,4DAA4D;IAC7E,eAAe,EAAE,4DAA4D;IAC7E,eAAe,EAAE,2CAA2C;IAC5D,eAAe,EAAE,2CAA2C;IAC5D,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,WAAW;IACvB,WAAW,EAAE,oBAAoB;CACzB,CAAC;AAEX;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD;;;;GAIG;AACU,QAAA,cAAc,GAAG,0CAA0C,CAAC;AAEzE;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;;;GAIG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC;AAExB,QAAA,MAAM,GAAG,6BAA6B,CAAC;AACvC,QAAA,gBAAgB,GAAG,+BAA+B,CAAC"}
|
||||
+1
-1
@@ -1,4 +1,3 @@
|
||||
export declare function escapeHtml(s: string): string;
|
||||
/**
|
||||
* @returns {String} the string with all zeroes contained in a <span>
|
||||
*/
|
||||
@@ -16,3 +15,4 @@ export declare function spanLeadingZeroes(address: string): string;
|
||||
* @returns {String} a grouped address
|
||||
*/
|
||||
export declare function simpleGroup(addressString: string, offset?: number): string[];
|
||||
//# sourceMappingURL=helpers.d.ts.map
|
||||
+3
-12
@@ -1,23 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.escapeHtml = escapeHtml;
|
||||
exports.spanAllZeroes = spanAllZeroes;
|
||||
exports.spanAll = spanAll;
|
||||
exports.spanLeadingZeroes = spanLeadingZeroes;
|
||||
exports.simpleGroup = simpleGroup;
|
||||
function escapeHtml(s) {
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
/**
|
||||
* @returns {String} the string with all zeroes contained in a <span>
|
||||
*/
|
||||
function spanAllZeroes(s) {
|
||||
return escapeHtml(s).replace(/(0+)/g, '<span class="zero">$1</span>');
|
||||
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
|
||||
}
|
||||
/**
|
||||
* @returns {String} the string with each character contained in a <span>
|
||||
@@ -25,11 +16,11 @@ function spanAllZeroes(s) {
|
||||
function spanAll(s, offset = 0) {
|
||||
const letters = s.split('');
|
||||
return letters
|
||||
.map((n, i) => `<span class="digit value-${escapeHtml(n)} position-${i + offset}">${spanAllZeroes(n)}</span>`)
|
||||
.map((n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`)
|
||||
.join('');
|
||||
}
|
||||
function spanLeadingZeroesSimple(group) {
|
||||
return escapeHtml(group).replace(/^(0+)/, '<span class="zero">$1</span>');
|
||||
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
|
||||
}
|
||||
/**
|
||||
* @returns {String} the string with leading zeroes contained in a <span>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/v6/helpers.ts"],"names":[],"mappings":";;AAAA,gCAOC;AAKD,sCAEC;AAKD,0BASC;AASD,8CAIC;AAMD,kCAUC;AAzDD,SAAgB,UAAU,CAAC,CAAS;IAClC,OAAO,CAAC;SACL,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,CAAS,EAAE,SAAiB,CAAC;IACnD,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE5B,OAAO,OAAO;SACX,GAAG,CACF,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACP,4BAA4B,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CACjG;SACA,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa;IAC5C,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,aAAqB,EAAE,SAAiB,CAAC;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAExC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACzB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,kCAAkC,CAAC,GAAG,MAAM,KAAK,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["export function escapeHtml(s: string): string {\n return s\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * @returns {String} the string with all zeroes contained in a <span>\n */\nexport function spanAllZeroes(s: string): string {\n return escapeHtml(s).replace(/(0+)/g, '<span class=\"zero\">$1</span>');\n}\n\n/**\n * @returns {String} the string with each character contained in a <span>\n */\nexport function spanAll(s: string, offset: number = 0): string {\n const letters = s.split('');\n\n return letters\n .map(\n (n, i) =>\n `<span class=\"digit value-${escapeHtml(n)} position-${i + offset}\">${spanAllZeroes(n)}</span>`,\n )\n .join('');\n}\n\nfunction spanLeadingZeroesSimple(group: string): string {\n return escapeHtml(group).replace(/^(0+)/, '<span class=\"zero\">$1</span>');\n}\n\n/**\n * @returns {String} the string with leading zeroes contained in a <span>\n */\nexport function spanLeadingZeroes(address: string): string {\n const groups = address.split(':');\n\n return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');\n}\n\n/**\n * Groups an address\n * @returns {String} a grouped address\n */\nexport function simpleGroup(addressString: string, offset: number = 0): string[] {\n const groups = addressString.split(':');\n\n return groups.map((g, i) => {\n if (/group-v4/.test(g)) {\n return g;\n }\n\n return `<span class=\"hover-group group-${i + offset}\">${spanLeadingZeroesSimple(g)}</span>`;\n });\n}\n"]}
|
||||
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/v6/helpers.ts"],"names":[],"mappings":";;AAGA,sCAEC;AAKD,0BAQC;AASD,8CAIC;AAMD,kCAUC;AA/CD;;GAEG;AACH,SAAgB,aAAa,CAAC,CAAS;IACrC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,CAAS,EAAE,SAAiB,CAAC;IACnD,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE5B,OAAO,OAAO;SACX,GAAG,CACF,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,4BAA4B,CAAC,aAAa,CAAC,GAAG,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CAC7F;SACA,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAa;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,aAAqB,EAAE,SAAiB,CAAC;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAExC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACzB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,kCAAkC,CAAC,GAAG,MAAM,KAAK,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC"}
|
||||
+1
@@ -3,3 +3,4 @@ export declare function padGroup(group: string): string;
|
||||
export declare const ADDRESS_BOUNDARY = "[^A-Fa-f0-9:]";
|
||||
export declare function simpleRegularExpression(groups: string[]): string;
|
||||
export declare function possibleElisions(elidedGroups: number, moreLeft?: boolean, moreRight?: boolean): string;
|
||||
//# sourceMappingURL=regular-expressions.d.ts.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user