Welcome to the AI slop.
This commit is contained in:
commit
adc01bb99c
1925 changed files with 238364 additions and 0 deletions
13
node_modules/ip-address/src/address-error.ts
generated
vendored
Normal file
13
node_modules/ip-address/src/address-error.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export class AddressError extends Error {
|
||||
parseMessage?: string;
|
||||
|
||||
constructor(message: string, parseMessage?: string) {
|
||||
super(message);
|
||||
|
||||
this.name = 'AddressError';
|
||||
|
||||
if (parseMessage !== null) {
|
||||
this.parseMessage = parseMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
node_modules/ip-address/src/common.ts
generated
vendored
Normal file
32
node_modules/ip-address/src/common.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { Address4 } from './ipv4';
|
||||
import { Address6 } from './ipv6';
|
||||
|
||||
export interface ReverseFormOptions {
|
||||
omitSuffix?: boolean;
|
||||
}
|
||||
|
||||
export function isInSubnet(this: Address4 | Address6, address: Address4 | Address6) {
|
||||
if (this.subnetMask < address.subnetMask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.mask(address.subnetMask) === address.mask()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isCorrect(defaultBits: number) {
|
||||
return function (this: Address4 | Address6) {
|
||||
if (this.addressMinusSuffix !== this.correctForm()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.subnetMask === defaultBits && !this.parsedSubnet) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.parsedSubnet === String(this.subnetMask);
|
||||
};
|
||||
}
|
||||
11
node_modules/ip-address/src/ip-address.ts
generated
vendored
Normal file
11
node_modules/ip-address/src/ip-address.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { Address4 } from './ipv4';
|
||||
import { Address6 } from './ipv6';
|
||||
import { AddressError } from './address-error';
|
||||
|
||||
export { Address4 };
|
||||
export { Address6 };
|
||||
export { AddressError };
|
||||
|
||||
import * as helpers from './v6/helpers';
|
||||
|
||||
export const v6 = { helpers };
|
||||
363
node_modules/ip-address/src/ipv4.ts
generated
vendored
Normal file
363
node_modules/ip-address/src/ipv4.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
/* eslint-disable no-param-reassign */
|
||||
|
||||
import * as common from './common';
|
||||
import * as constants from './v4/constants';
|
||||
import { AddressError } from './address-error';
|
||||
import { BigInteger } from 'jsbn';
|
||||
import { sprintf } from 'sprintf-js';
|
||||
|
||||
/**
|
||||
* Represents an IPv4 address
|
||||
* @class Address4
|
||||
* @param {string} address - An IPv4 address string
|
||||
*/
|
||||
export class Address4 {
|
||||
address: string;
|
||||
addressMinusSuffix?: string;
|
||||
groups: number = constants.GROUPS;
|
||||
parsedAddress: string[] = [];
|
||||
parsedSubnet: string = '';
|
||||
subnet: string = '/32';
|
||||
subnetMask: number = 32;
|
||||
v4: boolean = true;
|
||||
|
||||
constructor(address: string) {
|
||||
this.address = address;
|
||||
|
||||
const subnet = constants.RE_SUBNET_STRING.exec(address);
|
||||
|
||||
if (subnet) {
|
||||
this.parsedSubnet = subnet[0].replace('/', '');
|
||||
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
||||
this.subnet = `/${this.subnetMask}`;
|
||||
|
||||
if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {
|
||||
throw new AddressError('Invalid subnet mask.');
|
||||
}
|
||||
|
||||
address = address.replace(constants.RE_SUBNET_STRING, '');
|
||||
}
|
||||
|
||||
this.addressMinusSuffix = address;
|
||||
|
||||
this.parsedAddress = this.parse(address);
|
||||
}
|
||||
|
||||
static isValid(address: string): boolean {
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
new Address4(address);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a v4 address
|
||||
*/
|
||||
parse(address: string) {
|
||||
const groups = address.split('.');
|
||||
|
||||
if (!address.match(constants.RE_ADDRESS)) {
|
||||
throw new AddressError('Invalid IPv4 address.');
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct form of an address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
correctForm(): string {
|
||||
return this.parsedAddress.map((part) => parseInt(part, 10)).join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the address is correct, false otherwise
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isCorrect = common.isCorrect(constants.BITS);
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
const padded = hex.replace(/:/g, '').padStart(8, '0');
|
||||
const groups = [];
|
||||
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
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {integer} integer - a number to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromInteger(integer: number): Address4 {
|
||||
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
|
||||
* var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)
|
||||
* address.correctForm(); // '192.0.2.42'
|
||||
*/
|
||||
static fromArpa(arpaFormAddress: string): Address4 {
|
||||
// remove ending ".in-addr.arpa." or just "."
|
||||
const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, '');
|
||||
|
||||
const address = leader.split('.').reverse().join('.');
|
||||
|
||||
return new Address4(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to a hex string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toHex(): string {
|
||||
return this.parsedAddress.map((part) => sprintf('%02x', parseInt(part, 10))).join(':');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to an array of bytes
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Array}
|
||||
*/
|
||||
toArray(): number[] {
|
||||
return this.parsedAddress.map((part) => parseInt(part, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IPv4 address object to an IPv6 address group
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
toGroup6(): string {
|
||||
const output = [];
|
||||
let i;
|
||||
|
||||
for (i = 0; i < constants.GROUPS; i += 2) {
|
||||
const hex = sprintf(
|
||||
'%02x%02x',
|
||||
parseInt(this.parsedAddress[i], 10),
|
||||
parseInt(this.parsedAddress[i + 1], 10)
|
||||
);
|
||||
|
||||
output.push(sprintf('%x', parseInt(hex, 16)));
|
||||
}
|
||||
|
||||
return output.join(':');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the address as a BigInteger
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
bigInteger(): BigInteger {
|
||||
return new BigInteger(
|
||||
this.parsedAddress.map((n) => sprintf('%02x', parseInt(n, 10))).join(''),
|
||||
16
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function getting start address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
_startAddress(): BigInteger {
|
||||
return new BigInteger(this.mask() + '0'.repeat(constants.BITS - this.subnetMask), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return Address4.fromBigInteger(this._startAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
const adjust = new BigInteger('1');
|
||||
return Address4.fromBigInteger(this._startAddress().add(adjust));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function getting end address.
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
_endAddress(): BigInteger {
|
||||
return new BigInteger(this.mask() + '1'.repeat(constants.BITS - this.subnetMask), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The last address in the range given by this address' subnet
|
||||
* Often referred to as the Broadcast
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {Address4}
|
||||
*/
|
||||
endAddress(): Address4 {
|
||||
return Address4.fromBigInteger(this._endAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
const adjust = new BigInteger('1');
|
||||
return Address4.fromBigInteger(this._endAddress().subtract(adjust));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a BigInteger to a v4 address object
|
||||
* @memberof Address4
|
||||
* @static
|
||||
* @param {BigInteger} bigInteger - a BigInteger to convert
|
||||
* @returns {Address4}
|
||||
*/
|
||||
static fromBigInteger(bigInteger: BigInteger): Address4 {
|
||||
return Address4.fromInteger(parseInt(bigInteger.toString(), 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first n bits of the address, defaulting to the
|
||||
* subnet mask
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {String}
|
||||
*/
|
||||
mask(mask?: number): string {
|
||||
if (mask === undefined) {
|
||||
mask = this.subnetMask;
|
||||
}
|
||||
|
||||
return this.getBitsBase2(0, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bits in the given range as a base-2 string
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {string}
|
||||
*/
|
||||
getBitsBase2(start: number, end: number): string {
|
||||
return this.binaryZeroPad().slice(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
const reversed = this.correctForm().split('.').reverse().join('.');
|
||||
|
||||
if (options.omitSuffix) {
|
||||
return reversed;
|
||||
}
|
||||
|
||||
return sprintf('%s.in-addr.arpa.', reversed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address is in the subnet of the current address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isInSubnet = common.isInSubnet;
|
||||
|
||||
/**
|
||||
* Returns true if the given address is a multicast address
|
||||
* @memberof Address4
|
||||
* @instance
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMulticast(): boolean {
|
||||
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(): string {
|
||||
return this.bigInteger().toString(2).padStart(constants.BITS, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
||||
* @returns {String}
|
||||
*/
|
||||
groupForV6(): string {
|
||||
const segments = this.parsedAddress;
|
||||
|
||||
return this.address.replace(
|
||||
constants.RE_ADDRESS,
|
||||
sprintf(
|
||||
'<span class="hover-group group-v4 group-6">%s</span>.<span class="hover-group group-v4 group-7">%s</span>',
|
||||
segments.slice(0, 2).join('.'),
|
||||
segments.slice(2, 4).join('.')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
1214
node_modules/ip-address/src/ipv6.ts
generated
vendored
Normal file
1214
node_modules/ip-address/src/ipv6.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
6
node_modules/ip-address/src/v4/constants.ts
generated
vendored
Normal file
6
node_modules/ip-address/src/v4/constants.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export const BITS = 32;
|
||||
export const GROUPS = 4;
|
||||
|
||||
export const RE_ADDRESS = /^(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;
|
||||
|
||||
export const RE_SUBNET_STRING = /\/\d{1,2}$/;
|
||||
79
node_modules/ip-address/src/v6/constants.ts
generated
vendored
Normal file
79
node_modules/ip-address/src/v6/constants.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
export const BITS = 128;
|
||||
export const GROUPS = 8;
|
||||
|
||||
/**
|
||||
* Represents IPv6 address scopes
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const SCOPES: { [key: number]: string | undefined } = {
|
||||
0: 'Reserved',
|
||||
1: 'Interface local',
|
||||
2: 'Link local',
|
||||
4: 'Admin local',
|
||||
5: 'Site local',
|
||||
8: 'Organization local',
|
||||
14: 'Global',
|
||||
15: 'Reserved',
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Represents IPv6 address types
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const TYPES: { [key: string]: string | undefined } = {
|
||||
'ff01::1/128': 'Multicast (All nodes on this interface)',
|
||||
'ff01::2/128': 'Multicast (All routers on this interface)',
|
||||
'ff02::1/128': 'Multicast (All nodes on this link)',
|
||||
'ff02::2/128': 'Multicast (All routers on this link)',
|
||||
'ff05::2/128': 'Multicast (All routers in this site)',
|
||||
'ff02::5/128': 'Multicast (OSPFv3 AllSPF routers)',
|
||||
'ff02::6/128': 'Multicast (OSPFv3 AllDR routers)',
|
||||
'ff02::9/128': 'Multicast (RIP routers)',
|
||||
'ff02::a/128': 'Multicast (EIGRP routers)',
|
||||
'ff02::d/128': 'Multicast (PIM routers)',
|
||||
'ff02::16/128': 'Multicast (MLDv2 reports)',
|
||||
'ff01::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff02::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff05::fb/128': 'Multicast (mDNSv6)',
|
||||
'ff02::1:2/128': 'Multicast (All DHCP servers and relay agents on this link)',
|
||||
'ff05::1:2/128': 'Multicast (All DHCP servers and relay agents in this site)',
|
||||
'ff02::1:3/128': 'Multicast (All DHCP servers on this link)',
|
||||
'ff05::1:3/128': 'Multicast (All DHCP servers in this site)',
|
||||
'::/128': 'Unspecified',
|
||||
'::1/128': 'Loopback',
|
||||
'ff00::/8': 'Multicast',
|
||||
'fe80::/10': 'Link-local unicast',
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* A regular expression that matches bad characters in an IPv6 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an incorrect IPv6 address
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an IPv6 subnet
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
|
||||
|
||||
/**
|
||||
* A regular expression that matches an IPv6 zone
|
||||
* @memberof Address6
|
||||
* @static
|
||||
*/
|
||||
export const RE_ZONE_STRING = /%.*$/;
|
||||
|
||||
export const RE_URL = new RegExp(/^\[{0,1}([0-9a-f:]+)\]{0,1}/);
|
||||
export const RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
|
||||
60
node_modules/ip-address/src/v6/helpers.ts
generated
vendored
Normal file
60
node_modules/ip-address/src/v6/helpers.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { sprintf } from 'sprintf-js';
|
||||
|
||||
/**
|
||||
* @returns {String} the string with all zeroes contained in a <span>
|
||||
*/
|
||||
export function spanAllZeroes(s: string): string {
|
||||
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String} the string with each character contained in a <span>
|
||||
*/
|
||||
export function spanAll(s: string, offset: number = 0): string {
|
||||
const letters = s.split('');
|
||||
|
||||
return letters
|
||||
.map(
|
||||
(n, i) =>
|
||||
sprintf(
|
||||
'<span class="digit value-%s position-%d">%s</span>',
|
||||
n,
|
||||
i + offset,
|
||||
spanAllZeroes(n)
|
||||
) // XXX Use #base-2 .value-0 instead?
|
||||
)
|
||||
.join('');
|
||||
}
|
||||
|
||||
function spanLeadingZeroesSimple(group: string): string {
|
||||
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String} the string with leading zeroes contained in a <span>
|
||||
*/
|
||||
export function spanLeadingZeroes(address: string): string {
|
||||
const groups = address.split(':');
|
||||
|
||||
return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups an address
|
||||
* @returns {String} a grouped address
|
||||
*/
|
||||
export function simpleGroup(addressString: string, offset: number = 0): string[] {
|
||||
const groups = addressString.split(':');
|
||||
|
||||
return groups.map((g, i) => {
|
||||
if (/group-v4/.test(g)) {
|
||||
return g;
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<span class="hover-group group-%d">%s</span>',
|
||||
i + offset,
|
||||
spanLeadingZeroesSimple(g)
|
||||
);
|
||||
});
|
||||
}
|
||||
99
node_modules/ip-address/src/v6/regular-expressions.ts
generated
vendored
Normal file
99
node_modules/ip-address/src/v6/regular-expressions.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import * as v6 from './constants';
|
||||
import { sprintf } from 'sprintf-js';
|
||||
|
||||
export function groupPossibilities(possibilities: string[]): string {
|
||||
return sprintf('(%s)', possibilities.join('|'));
|
||||
}
|
||||
|
||||
export function padGroup(group: string): string {
|
||||
if (group.length < 4) {
|
||||
return sprintf('0{0,%d}%s', 4 - group.length, group);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
export const ADDRESS_BOUNDARY = '[^A-Fa-f0-9:]';
|
||||
|
||||
export function simpleRegularExpression(groups: string[]) {
|
||||
const zeroIndexes: number[] = [];
|
||||
|
||||
groups.forEach((group, i) => {
|
||||
const groupInteger = parseInt(group, 16);
|
||||
|
||||
if (groupInteger === 0) {
|
||||
zeroIndexes.push(i);
|
||||
}
|
||||
});
|
||||
|
||||
// You can technically elide a single 0, this creates the regular expressions
|
||||
// to match that eventuality
|
||||
const possibilities = zeroIndexes.map((zeroIndex) =>
|
||||
groups
|
||||
.map((group, i) => {
|
||||
if (i === zeroIndex) {
|
||||
const elision = i === 0 || i === v6.GROUPS - 1 ? ':' : '';
|
||||
|
||||
return groupPossibilities([padGroup(group), elision]);
|
||||
}
|
||||
|
||||
return padGroup(group);
|
||||
})
|
||||
.join(':')
|
||||
);
|
||||
|
||||
// The simplest case
|
||||
possibilities.push(groups.map(padGroup).join(':'));
|
||||
|
||||
return groupPossibilities(possibilities);
|
||||
}
|
||||
|
||||
export function possibleElisions(
|
||||
elidedGroups: number,
|
||||
moreLeft?: boolean,
|
||||
moreRight?: boolean
|
||||
): string {
|
||||
const left = moreLeft ? '' : ':';
|
||||
const right = moreRight ? '' : ':';
|
||||
|
||||
const possibilities = [];
|
||||
|
||||
// 1. elision of everything (::)
|
||||
if (!moreLeft && !moreRight) {
|
||||
possibilities.push('::');
|
||||
}
|
||||
|
||||
// 2. complete elision of the middle
|
||||
if (moreLeft && moreRight) {
|
||||
possibilities.push('');
|
||||
}
|
||||
|
||||
if ((moreRight && !moreLeft) || (!moreRight && moreLeft)) {
|
||||
// 3. complete elision of one side
|
||||
possibilities.push(':');
|
||||
}
|
||||
|
||||
// 4. elision from the left side
|
||||
possibilities.push(sprintf('%s(:0{1,4}){1,%d}', left, elidedGroups - 1));
|
||||
|
||||
// 5. elision from the right side
|
||||
possibilities.push(sprintf('(0{1,4}:){1,%d}%s', elidedGroups - 1, right));
|
||||
|
||||
// 6. no elision
|
||||
possibilities.push(sprintf('(0{1,4}:){%d}0{1,4}', elidedGroups - 1));
|
||||
|
||||
// 7. elision (including sloppy elision) from the middle
|
||||
for (let groups = 1; groups < elidedGroups - 1; groups++) {
|
||||
for (let position = 1; position < elidedGroups - groups; position++) {
|
||||
possibilities.push(
|
||||
sprintf(
|
||||
'(0{1,4}:){%d}:(0{1,4}:){%d}0{1,4}',
|
||||
position,
|
||||
elidedGroups - position - groups - 1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return groupPossibilities(possibilities);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue