lakutata
Version:
An IoC-based universal application framework.
1,478 lines (1,427 loc) • 61.7 kB
TypeScript
import { PathLike } from 'fs';
import { IConstructor } from './TypeDef.internal.118.js';
import { PathLike as PathLike$1 } from 'node:fs';
import { ReadableOptions, Readable } from 'node:stream';
import { Path } from './TypeDef.internal.24.js';
import { GlobOptionsWithFileTypesUnset, GlobOptionsWithFileTypesTrue, GlobOptionsWithFileTypesFalse } from './TypeDef.internal.23.js';
import { Version1Options, UUIDTypes, Version4Options, Version6Options } from './TypeDef.internal.94.js';
import { PaginationSearchDTO, PaginationResultDTO } from './TypeDef.internal.132.js';
/**
* Convert Array to Set
* @param arr
* @constructor
*/
declare function ArrayToSet<T = any>(arr: T[]): Set<T>;
/**
* Type conversion
* @param inp
* @constructor
*/
declare function As<T = any>(inp: any): T;
/**
* Async delay function
* @param ms
* @constructor
*/
declare function Delay(ms: number): Promise<void>;
/**
* Just accept arguments
* @param args
* @constructor
*/
declare function DevNull(...args: any[]): void;
/**
* Get object's nesting depth
* @param target
* @constructor
*/
declare function GetObjectNestingDepth(target: Object): number;
/**
* Get all property paths in an object
* @param target
* @param basePath
* @constructor
*/
declare function GetObjectPropertyPaths(target: Record<string, any>, basePath?: string): string[];
/**
* Terminate program graceful
* @param exitCode
* @param functions
* @constructor
*/
declare function GraceExit(exitCode: number, ...functions: (() => any)[]): void;
/**
* Whether an object is empty object or not
* @param obj
* @constructor
*/
declare function IsEmptyObject<T = any>(obj: T): boolean;
/**
* Returns `true` if the path exists, `false` otherwise.
* @param path
* @constructor
*/
declare function IsExists(path: PathLike): Promise<boolean>;
/**
* Whether a string is glob string or not
* @param inp
* @constructor
*/
declare function IsGlobString(inp: string): boolean;
/**
* Whether string is html
* @param string
* @constructor
*/
declare function IsHtml(string: string): boolean;
/**
* Whether a function is native function or not
* @param target
* @constructor
*/
declare function IsNativeFunction(target: any): boolean;
/**
* Whether an object is Promise object or not
* @param target
*/
declare function IsPromise(target: any): boolean;
/**
* Whether an object is PromiseLike object or not
* @param target
* @constructor
*/
declare function IsPromiseLike(target: any): boolean;
/**
* Whether input value is symbol
* @param inp
* @constructor
*/
declare function IsSymbol(inp: any): boolean;
/**
* Whether string is XML
* @param string
* @constructor
*/
declare function IsXML(string: string): boolean;
type Locale = string[] | string | false | undefined;
interface SplitOptions {
separateNumbers?: boolean;
}
interface NoCaseOptions extends SplitOptions {
locale?: Locale;
}
/**
* Convert any string into a lower case string with spaces between words.
*/
declare function NoCase(input: string, options?: NoCaseOptions): string;
/**
* Split any cased input strings into an array of words.
*/
declare function Split(input: string, options?: SplitOptions): string[];
declare function ToLower(locale: Locale): (input: string) => string;
declare function ToUpper(locale: Locale): (input: string) => string;
/**
* Get object's constructor by its prototype
* @param target
* @constructor
*/
declare function ObjectConstructor<ObjectPrototype extends Object>(target: ObjectPrototype): IConstructor<ObjectPrototype>;
type HashName = 'md4' | 'md4WithRSAEncryption' | 'md5' | 'md5WithRSAEncryption' | 'ripemd' | 'ripemd160' | 'ripemd160WithRSA' | 'rmd160' | 'rsa-md4' | 'rsa-md5' | 'rsa-ripemd160' | 'rsa-sha1' | 'rsa-sha1-2' | 'rsa-sha224' | 'rsa-sha256' | 'rsa-sha3-224' | 'rsa-sha3-256' | 'rsa-sha3-384' | 'rsa-sha3-512' | 'rsa-sha384' | 'rsa-sha512' | 'sha1' | 'sha1WithRSAEncryption' | 'sha224' | 'sha224WithRSAEncryption' | 'sha256' | 'sha256WithRSAEncryption' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha384WithRSAEncryption' | 'sha512' | 'sha512WithRSAEncryption';
type ObjectHashOptions = {
/**
* @default 'hex'
*/
encoding?: 'hex' | 'binary' | 'base64' | undefined;
/**
* @default 'sha1'
*/
algorithm?: HashName | 'passthrough' | undefined;
excludeKeys?: ((key: string) => boolean) | undefined;
/**
* @default false
*/
excludeValues?: boolean | undefined;
/**
* @default false
*/
ignoreUnknown?: boolean | undefined;
replacer?: ((value: any) => any) | undefined;
/**
* @default true
*/
respectFunctionNames?: boolean | undefined;
/**
* @default true
*/
respectFunctionProperties?: boolean | undefined;
/**
* @default true
*/
respectType?: boolean | undefined;
/**
* @default false
*/
unorderedArrays?: boolean | undefined;
/**
* @default true
*/
unorderedObjects?: boolean | undefined;
/**
* @default true
*/
unorderedSets?: boolean | undefined;
};
/**
* Generate an object hash
* @param value
* @param options
* @constructor
*/
declare function ObjectHash(value: any, options?: ObjectHashOptions): string;
/**
* Get class's parent constructor
* @param target
* @constructor
*/
declare function ObjectParentConstructor<ClassConstructor extends Function>(target: ClassConstructor): Function | null;
declare function ObjectParentConstructor<ClassPrototype extends Object>(target: IConstructor<ClassPrototype>): Function | null;
/**
* Get class's parent constructors
* @param target
* @constructor
*/
declare function ObjectParentConstructors<ClassConstructor extends Function>(target: ClassConstructor): Function[];
declare function ObjectParentConstructors<ClassPrototype extends Object>(target: IConstructor<ClassPrototype>): Function[];
type InferPrototype<ObjectConstruct extends Function> = ObjectConstruct extends new (...args: any[]) => infer ObjectPrototype ? ObjectPrototype : never;
/**
* Get object's prototype by its constructor
* @param target
* @constructor
*/
declare function ObjectPrototype<ObjectConstruct extends Function>(target: ObjectConstruct): InferPrototype<ObjectConstruct>;
/**
* Convert Set to Array
* @param set
* @constructor
*/
declare function SetToArray<T = any>(set: Set<T>): T[];
declare class MissingValueError extends Error {
key: string;
constructor(key: string);
}
interface TemplatingOptions {
ignoreMissing?: boolean;
transform?: ({ value, key }: {
value: any;
key: string;
}) => any;
}
declare function Templating(template: string, data: object | any[], { ignoreMissing, transform }?: TemplatingOptions): string;
/**
* Unique array
* @param arr
* @constructor
*/
declare function UniqueArray<T>(arr: T[]): T[];
/**
* Convert object to map
* @param obj
* @constructor
*/
declare function ObjectToMap<K extends (string | number | symbol), V>(obj: Record<K, V>): Map<K, V>;
/**
* Whether input string is path or not
* @param inp
* @constructor
*/
declare function IsPath(inp: string | PathLike$1): boolean;
/**
* Convert array-like input to iterable
* @param inp
* @constructor
*/
declare function ConvertArrayLikeToIterable(inp: string | Buffer | NodeJS.TypedArray): Generator;
/**
* Convert buffer to readable stream
* @param inp
* @param options
* @constructor
*/
declare function ConvertArrayLikeToStream(inp: Buffer, options?: ReadableOptions): Readable;
/**
* Convert typed-array to readable stream
* @param inp
* @param options
* @constructor
*/
declare function ConvertArrayLikeToStream(inp: NodeJS.TypedArray, options?: ReadableOptions): Readable;
/**
* Convert string to readable stream
* @param inp
* @param options
* @constructor
*/
declare function ConvertArrayLikeToStream(inp: string, options?: ReadableOptions): Readable;
/**
* Merge two set
* @param s1
* @param s2
* @constructor
*/
declare function MergeSet<T = any, U = any>(s1: Set<T>, s2: Set<U>): Set<T | U>;
/**
* Merge two array
* @param arr1
* @param arr2
* @constructor
*/
declare function MergeArray<T = any, U = any>(arr1: T[], arr2: U[]): (T | U)[];
/**
* Merge two map
* @param m1
* @param m2
* @constructor
*/
declare function MergeMap<K1, V1, K2, V2>(m1: Map<K1, V1>, m2: Map<K2, V2>): Map<K1 | K2, V1 | V2>;
interface SortOptions<Computed> {
/**
* One or more property names or computed fields to sort by.
* Specifying property names is only relevant when sorting an array of
* objects.
*/
by?: string | string[];
/**
* One or more sort orders. Specify 'asc', 'desc' or a property name from
* the options.customOrders object.
*/
order?: string | string[];
/**
* A dictionary object containing one or more custom orders. Each custom
* order value must be an array defining the order expected values must be
* sorted in.
*/
customOrders?: {
[key: string]: any;
};
/**
* A dictionary object containing one or more computed field functions. The
* function will be invoked once per item in the array. Each invocation
* will receive the array item as input and must return a primitive value
* by which the array can be sorted.
*/
computed?: {
[key: string]: (item: Computed) => number | string | boolean | bigint | symbol | null | undefined;
};
/**
* Configures whether null values will be sorted before or after defined
* values. Set to -1 for before, 1 for after. Defaults to 1.
* @default 1
*/
nullRank?: -1 | 1;
/**
* Configures whether undefined values will be sorted before or after
* defined values. Set to -1 for before, 1 for after. Defaults to 1.
* @default 1
*/
undefinedRank?: -1 | 1;
}
/**
* Sort array
* @param arr
* @param options
* @constructor
*/
declare function SortArray<T = any>(arr: T[], ...options: SortOptions<T>[]): T[];
/**
* Sort keys options
*/
interface SortKeysOptions {
deep?: boolean;
compare?: (a: string, b: string) => number;
}
/**
* Sort keys
* @param object
* @param options
* @constructor
*/
declare function SortKeys(object: any, options?: SortKeysOptions): any;
/**
* Sort keys options
*/
interface SortObjectOptions {
deep?: boolean;
order?: 'asc' | 'desc';
}
/**
* Sort object
* @param object
* @param options
* @constructor
*/
declare function SortObject<T extends Record<string, any>>(object: T, options?: SortObjectOptions): T;
/**
* Generate a random string
* @constructor
*/
declare function RandomString(): string;
/**
* Generate a random string of specified length
* @param length
* @constructor
*/
declare function RandomString(length: number): string;
/**
* Generates a string of specified length containing only characters within the character set
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: string): string;
/**
* Generate a string of specified length containing only [0-9 a-z A-Z]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'alphanumeric'): string;
/**
* Generate a string of specified length containing only [a-z A-Z]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'alphabetic'): string;
/**
* Generate a string of specified length containing only [0-9]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'numeric'): string;
/**
* Generate a string of specified length containing only [0-9 a-f]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'hex'): string;
/**
* Generate a string of specified length containing only [01]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'binary'): string;
/**
* Generate a string of specified length containing only [0-7]
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: 'octal'): string;
/**
* Generates a string of specified length containing only character rules within the character set array
* @param length
* @param charset
* @constructor
*/
declare function RandomString(length: number, charset: ('alphanumeric' | 'alphabetic' | 'numeric' | 'hex' | 'binary' | 'octal' | string)[]): string;
/**
* Generate a random string of length 32
* @constructor
*/
declare function NonceStr(): string;
/**
* Is abort error
* @param error
* @constructor
*/
declare function IsAbortError(error: Error | any): boolean;
/**
* Match files using the patterns the shell uses
* @constructor
* @see https://github.com/isaacs/node-glob
*/
declare function Glob(pattern: string | string[], options?: GlobOptionsWithFileTypesUnset): Promise<string[]>;
declare function Glob(pattern: string | string[], options: GlobOptionsWithFileTypesTrue): Promise<Path[]>;
declare function Glob(pattern: string | string[], options: GlobOptionsWithFileTypesFalse): Promise<string[]>;
interface IPBinHex {
hex: string;
decimal: number;
binary: string;
}
interface IPv4SubNet {
cidrMask: number;
ipCount: number;
usableCount: number;
subnetMask: string;
firstHost: string;
lastHost: string;
networkAddress: string;
broadcastAddress: string;
}
interface IPv6SubNet {
ipCount: bigint;
lastHost: string;
firstHost: string;
prefixLength: number;
}
interface IPv6Result {
mapped: string;
expanded: string;
comperssed: string;
}
declare class IPv4Range {
#private;
constructor(start: number, end: number);
/**
* Create ipRange instance from start and end IPv4 integers
*
* @param start - Start IPv4 integer
* @param end - End IPv4 integer
* @returns The created ipRange instance
* @throws Error if start or end IPv4 is invalid
*
* @example
* ```
* const range = ipRange.fromLong(3232235777, 3232235876);
* ```
*/
static fromLong(start: number, end: number): IPv4Range;
/**
* Create ipRange instance from start and end IPv4 strings
*
* @param startIp - Start IPv4 string
* @param endIp - End IPv4 string
* @returns The created ipRange instance
* @throws Error if start or end IPv4 is invalid
*
* @example
* ```
* const range = ipRange.fromString('192.168.1.1', '192.168.1.100');
* ```
*/
static fromString(start: string, end: string): IPv4Range;
/**
* Get start and end IPv4 integers of current range
*
* @returns Array of start and end IPv4 integers
*
* @example
* ```
* const range = ipRange.fromString('192.168.1.1', '192.168.1.100');
* range.ip2long(); // [3232235777, 3232235876]
* ```
*/
ip2long(): number[];
/**
* Get start and end IPv4 strings of current range
*
* @returns Array of start and end IPv4 strings
*
* @example
* ```
* const range = ipRange.fromLong(3232235777, 3232235876);
* range.long2ip(); // ['192.168.1.1', '192.168.1.100']
* ```
*/
long2ip(): string[];
/**
* Get the number of IPs in current range
*
* @returns Number of IPv4 addresses
*
* @example
* ```
* const range = ipRange.fromString('192.168.1.1', '192.168.1.100');
* range.ipCount(); // 100
* ```
*/
ipCount(): number;
/**
* Verify if the IPv4 address is within the current range
*
* @param ip - A standard IPv4 address string
* @returns True if within range, otherwise false
*
* @example
* ```
* const range = ipRange.fromString('192.168.1.1', '192.168.1.100');
* range.contains('192.168.1.99'); // true
* range.contains('192.168.0.11'); // false
* ```
*/
contains(ip: string): boolean;
}
declare class IP {
/**
* Verify if the IPv4 or IPv6 address is within the CIDR range
*
* @param cidr - A standard format IPv4 or IPv6 CIDR address
* @param ip - The IPv4 or IPv6 address to check
* @returns True if within range, otherwise false
*
* @example
* ```
* contains('192.168.1.0/24', '192.168.1.5') // true
* contains('192.168.1.0/24', '192.168.2.5') // false
* contains('2001:db8::1/64', '2001:db8::11') // true
* contains('2001:db8::1/128', '2001:db8::11') // false
* ```
*/
static contains(cidr: string, ip: string): boolean;
/**
* Convert IPv4 or IPv6 address string to number
*
* @param ip - The IPv4 or IPv6 address string
* @returns The converted IPv4 or IPv6 number or false if invalid
*
* @example
* ```
* ip2long('192.168.0.1') // 3232235521
* ip2long('::ffff:9999') // 4294941081
* ```
*/
static ip2long(ip: string): number | bigint | false;
/**
* Verify if the CIDR address is valid
*
* @param cidr - The CIDR address string
* @returns True if valid, false otherwise
*
* @example
* ```
* isCIDR('192.168.1.0/24') // true
* isCIDR('192.168.1.0/34') // false
* isCIDR('287.168.1.0/34') // false
* ```
*/
static isCIDR(cidr: string): boolean;
/**
* Check for conflicts in a set of CIDR
*
* @param cidrs - Array of CIDR format address string
* @returns True if conflict found, false otherwise
*
* @example
* ```
* isConflict(['192.168.1.0/24', '192.168.0.0/24']) // false
* isConflict(['192.168.1.0/24', '2001:db8::1/122']) // false
* isConflict(['2001:db8::1/120', '2001:db8::1/122']) // true
* isConflict(['192.168.1.0/24', '192.168.1.0/28', '2001:db8::1/122']) // true
* ```
*/
static isConflict(cidrs: string[]): boolean;
/**
* Verify if the IPv4 or IPv6 address is valid
*
* @param ip - The IPv4 or IPv6 address string
* @returns True if valid, false otherwise
*
* @example
* ```
* isValidIP('192.168.1.99') // true
* isValidIP('f16c:f7ec:cfa2:e1c5:9a3c:cb08:801f:36b8') // true
* ```
*/
static isValidIP(ip: string): boolean;
/**
* Convert IPv4 or IPv6 number to address string
*
* @param ip - The IPv4 or IPv6 number
* @returns The converted IPv4 or IPv6 address string or false if invalid
*
* @example
* ```
* ip2long('192.168.0.1') // 3232235521
* ip2long('::ffff:9999') // 4294941081
* ```
*/
static long2ip(ip: number | bigint): string | false;
}
declare class IPv4 {
/**
* Convert IPv4 address string to number
*
* @param ip - The IPv4 address string
* @returns The converted IPv4 number or false if invalid
*
* @example
* ```
* ip2long('192.168.0.1') // 3232235521
* ip2long('192.168.0.257') // false
* ```
*/
static ip2long(ip: string): number | false;
/**
* Convert IPv4 number to address string
*
* @param ip - The IPv4 number
* @returns The converted IPv4 address string or false if invalid
*
* @example
* ```
* long2ip(3232235521) // '192.168.0.1'
* long2ip(-1) // false
* ```
*/
static long2ip(ip: number): string | false;
/**
* IPv4 address range class for representing a range defined by a start and end IPv4 address. Valid values are from 0 to 4294967295.
*/
static ipRange: typeof IPv4Range;
/**
* Verify if the CIDR address is valid
*
* @param cidr - The CIDR address string
* @returns True if valid, false otherwise
*
* @example
* ```
* isCIDR('192.168.1.0/24') // true
* isCIDR('192.168.1.0/34') // false
* isCIDR('287.168.1.0/34') // false
* ```
*/
static isCIDR(cidr: string): boolean;
/**
* Verify if two IPv4 address are equal
* @param ip1 The first IPv4 address to compare
* @param ip2 The second IPv4 address to compare
* @returns True if equal, false otherwise
*
* @example
* ```
* isEqual(32322355, 3232235521) // false
* isEqual(3232235521, 3232235521) // true
* isEqual('192.168.0.1', 3232235521) // true
* isEqual('192.168.1.10', '192.168.1.10') // true
* isEqual('192.168.01.10', '192.168.1.010') // true
* isEqual('192.168.02.10', '192.168.1.010') // false
* ```
*/
static isEqual(ip1: string | number, ip2: string | number): boolean;
/**
* Verify if the IP address is within the CIDR range
*
* @param cidr - A standard format CIDR address
* @param ip - The IPv4 address to check
* @returns True if within range, otherwise false
*
* @example
* ```
* contains('192.168.1.0/24', '192.168.1.5') // true
* contains('192.168.1.0/24', '192.168.2.5') // false
* ```
*/
static contains(cidr: string, ip: string): boolean;
/**
* Verify if an IPv4 address is private
* @param ip - The IPv4 address string
* @returns True if private IPv4, false otherwise
*
* @example
* ```
* isPrivate('192.168.0.1') // returns true
* isPrivate('114.114.114.114') // returns false
* ```
*/
static isPrivate(ip: string): boolean;
/**
* Verify if the IPv4 address is valid
*
* @param ip - The IPv4 address string
* @param options - Enable strict mode to disallow leading 0s, false by default
* @returns True if valid, false otherwise
*
* @example
* ```
* isValidIP('192.168.1.99') // true
* isValidIP('192.168.01.99', {strict: true}) // false
* ```
*/
static isValidIP(ip: string, options?: {
strict?: boolean;
}): boolean;
/**
* Parse CIDR format address into address range info
*
* NetworkAddress and broadcastAddress are valid when mask < 31
*
* @param cidr - The CIDR format address string
* @returns The parsed address range object or false if invalid
*
* @example
* ```
* parseCIDR('192.168.0.1/33') // false
* parseCIDR('192.168.0.1/24')
* // {
* // ipCount: 256,
* // usableCount: 254,
* // cidrMask: 24,
* // subnetMask: '255.255.255.0',
* // firstHost: '192.168.0.1',
* // lastHost: '192.168.0.254',
* // networkAddress: '192.168.0.0',
* // broadcastAddress: '192.168.0.255'
* // }
* ```
*/
static parseCIDR(cidr: string): IPv4SubNet | false;
/**
* Check for conflicts in a set of CIDR
*
* @param cidrs - Array of CIDR format address string
* @returns True if conflict found, false otherwise
*
* @example
* ```
* isConflict(['192.168.1.0/24', '192.168.0.0/16']) // true
* isConflict(['192.168.1.0/24', '192.168.2.0/24']) // false
* isConflict(['192.168.1.0/24', '192.168.2.0/24', '192.168.3.0/16']) // true
* isConflict(['192.168.1.0/24', '192.168.2.0/24', '192.168.3.0/24']) // false
* ```
*/
static isConflict(cidrs: string[]): boolean;
/**
* Parse IPv4 address and subnet mask into CIDR info
*
* @param ip - The IPv4 address string
* @param mask - The subnet mask string
* @returns The parsed CIDR info object or false if invalid
*
* @example
* ```
* parseSubnet('192.168.0.1', '1.255.255.0') // false
* parseSubnet('192.168.0.1', '255.255.255.0')
* // {
* // ipCount: 256,
* // usableCount: 254,
* // cidrMask: 24,
* // subnetMask: '255.255.255.0',
* // firstHost: '192.168.0.1',
* // lastHost: '192.168.0.254',
* // networkAddress: '192.168.0.0',
* // broadcastAddress: '192.168.0.255'
* // }
* ```
*/
static parseSubnet(ip: string, mask: string): IPv4SubNet | false;
/**
* Verify if the subnet mask is valid
*
* @param mask - The subnet mask to valid
* @returns True if valid, otherwise false
*
* @example
* ```
* isValidMask(24) // true
* isValidMask('255.255.255.0') // true
* isValidMask('255.255.256.0') // false
* ```
*/
static isValidMask(mask: string | number): boolean;
/**
* Verify if two IPv4 address are on the same subnet
*
* @param ip1 - The first IPv4 address to compare
* @param ip2 - The second IPv4 address to compare
* @param mask - The subnet mask
* @returns True if in the same subnet, otherwise false
*
* @example
* ```
* isSameSubnet('192.168.1.10', '192.168.1.100', 24) // true
* isSameSubnet('192.168.1.10', '192.168.1.100', 32) // false
* isSameSubnet('192.168.1.10', '192.168.1.100', '255.255.255.0') // true
* isSameSubnet('192.168.1.10', '192.168.2.100', '255.255.255.0') // false
* ```
*/
static isSameSubnet(ip1: string, ip2: string, mask: string | number): boolean;
/**
* Convert IPv4 address to binary and hex
*
* @param ip - The IPv4 address string
* @returns Contains binary and hexadecimal objects, false if invalid
*
* @example
* ```
* const results = toBinHex('192.168.0.1');
* // results = {
* // hex: '0xc0a80001',
* // decimal: 3232235521
* // binary: '11000000101010000000000000001'
* // }
* ```
*/
static toBinHex(ip: string): IPBinHex | false;
/**
* Converts IPv4 address to IPv6 format
*
* @param ip - The IPv4 address string (validation requires strict mode)
* @returns The IPv6 address object or false if invalid
*
* @example
* ```
* toIPv6Format('192.168.1.1')
* // {
* // mapped: '::ffff:192.168.1.1',
* // comperssed: "::ffff:c0a8:101"
* // expanded: '0000:0000:0000:0000:0000:ffff:c0a8:0101',
* // }
* ```
*/
static toIPv6Format(ip: string): IPv6Result | false;
/**
* Convert mask length to subnet mask string
*
* @param length - The mask length number
* @returns The subnet mask string or false if invalid
*
* @example
* ```
* toSubnetMask(0) // '0.0.0.0'
* toSubnetMask(8) // '255.0.0.0'
* toSubnetMask(16) // '255.255.0.0'
* toSubnetMask(24) // '255.255.255.0'
* ```
*/
static toSubnetMask(length: number): string | false;
/**
* Convert subnet mask string to mask length number
*
* @param mask - The subnet mask string
* @returns The mask length or false if invalid
*
* @example
* ```
* toMaskLength('255.255.255.0') // 24
* toMaskLength('255.255.256.0') // false
* ```
*/
static toMaskLength(mask: string): number | false;
/**
* Calculate the inverse mask of a subnet mask
* @param mask - The subnet mask
* @returns The inverse mask, or false if invalid
*
* @example
* ```
* toInverseMask(24); // '0.0.0.255'
* toInverseMask(16); // '0.0.255.255'
* toInverseMask('255.255.255.0'); // '0.0.0.255'
* toInverseMask('255.255.0.0'); // '0.0.255.255'
* ```
*/
static toInverseMask(mask: string | number): string | false;
}
declare class IPv6 {
/**
* Compresses an expanded IPv6 address into shortened form.
*
* @param ip - The IPv6 address string
* @returns The compressed IPv6 address string or false if invalid
*
* @example
* ```
* compressedForm('2001:0db8:0000:0000:0000:0000:0000:0001') // '2001:db8::1'
* ```
*/
static compressedForm(ip: string): string | false;
/**
* Verify if the IPv6 address is within the CIDR range
*
* @param cidr - A standard format IPv6 CIDR address
* @param ip - The IPv6 address to check
* @returns True if within range, otherwise false
*
* @example
* contains('2001:db8::1/64', '2001:db8::11') // true
* contains('2001:db8::1/128', '2001:db8::11') // false
*/
static contains(cidr: string, ip: string): boolean;
/**
* Expands an abbreviated IPv6 address string into its full representation.
*
* @param ip - The IPv6 address string
* @returns The expanded IPv6 address string or false if invalid
*
* @example
* ```
* expandedForm('2001:db8::1') // '2001:0db8:0000:0000:0000:0000:0000:0001'
* ```
*/
static expandedForm(ip: string): string | false;
/**
* Convert IPv6 address string to number
*
* @param ip - The IPv6 address string
* @returns The converted IPv6 number or false if invalid
*
* @example
* ```
* ip2long('f16c:f7ec:cfa2:e1c5:9a3c:cb08:801f:36b8') // 320909743562165251276054390739658815160n
* ```
*/
static ip2long(ip: string): bigint | false;
/**
* Verify if the IPv6 CIDR address is valid
*
* @param cidr - The CIDR address string
* @returns True if valid, false otherwise
*
* @example
* ```
* isCIDR('::9999:ffff/0') // true
* isCIDR('::9999:ffff/64') // true
* isCIDR('::9999:ffff/128') // true
* isCIDR('::9999:ffff/129') // false
* isCIDR('::99991:ffff/129') // false
* ```
*/
static isCIDR(cidr: string): boolean;
/**
* Check for conflicts in a set of IPv6 CIDR
*
* @param cidrs - Array of IPv6 CIDR format address string
* @returns True if conflict found, false otherwise
*
* @example
* ```
* isConflict(['2001:db8::1/120', '2001:db8::1/122']) // true
* isConflict(['2001:db8::1/120', '3001:db8::1/120']) // false
* ```
*/
static isConflict(cidrs: string[]): boolean;
/**
* Verify if two IPv6 address are equal
* @param ip1 The first IPv6 address to compare
* @param ip2 The second IPv6 address to compare
* @returns True if equal, false otherwise
*
* @example
* ```
* isEqual(65535n, 65535) // false
* isEqual(65535n, 65535n) // true
* isEqual('::ffff', 65535n) // true
* isEqual('::ffff', ::ffff) // true
* isEqual('::ffff', 0:0:0:0:0:0:0:ffff) // true
* isEqual('::ffff', 0000:0000:0000:0000:0000:0000:0000:ffff) // true
* ```
*/
static isEqual(ip1: string | bigint, ip2: string | bigint): boolean;
/**
* Verify if the IPv6 address is valid
*
* @param ip - The IPv6 address string
* @returns True if valid, false otherwise
*
* @example
* ```
* isValidIP('f16c:f7ec:cfa2:e1c5:9a3c:cb08:801f:36b8') // true
* ```
*/
static isValidIP(ip: string): boolean;
/**
* Convert IPv4 number to address string
*
* @param ip - The IPv4 number
* @returns The converted IPv4 address string or false if invalid
*
* @example
* ```
* long2ip(3232235521) // '192.168.0.1'
* long2ip(-1) // false
* ```
*/
static long2ip(ip: bigint): string | false;
/**
* Parse CIDR format address into address range info
*
* NetworkAddress and broadcastAddress are valid when mask < 31
*
* @param cidr - The CIDR format address string
* @returns The parsed address range object or false if invalid
*
* @example
* ```
* parseCIDR('::9999:ffff/118')
* // {
* // ipCount: 1024n,
* // cidrMask: 118,
* // firstHost: '::9999:fc00',
* // lastHost: '::9999:ffff',
* // }
* ```
*/
static parseCIDR(cidr: string): IPv6SubNet | false;
}
/**
* Hex to unsigned number
* @param hex
* @constructor
*/
declare function HexToUnsigned(hex: string): number;
/**
* Unsigned number to hex
* @param unsignedNumber
* @param bits
* @constructor
*/
declare function UnsignedToHex(unsignedNumber: number, bits?: 8 | 16 | 32 | 64 | 128): string;
/**
* Hex to signed number
* @param hex
* @constructor
*/
declare function HexToSigned(hex: string): number;
/**
* Signed number to hex
* @param signedNumber
* @param bits
* @constructor
*/
declare function SignedToHex(signedNumber: number, bits?: 8 | 16 | 32 | 64 | 128): string;
/**
* Hex to IEEE754 number
* @param hex
* @constructor
*/
declare function HexToIEEE754(hex: string): number;
/**
* IEEE754 number to hex
* @param ieee754Number
* @param bits
* @constructor
*/
declare function IEEE754ToHex(ieee754Number: number, bits?: 32 | 64): string;
/**
* MD5 Hash
* @param message
* @constructor
*/
declare function MD5(message: string): Buffer;
/**
* SHA1 Hash
* @param message
* @constructor
*/
declare function SHA1(message: string): Buffer;
/**
* SHA256 Hash
* @param message
* @constructor
*/
declare function SHA256(message: string): Buffer;
interface URLAttributes {
auth?: string;
hash?: string;
host?: string;
hostname?: string;
href?: string;
origin?: string;
password?: string;
pathname?: string;
port?: string;
protocol?: string;
query?: Record<string, string>;
slashes?: boolean;
username?: string;
}
declare class URLBuilder {
#private;
static parse(url: string): URLBuilder;
auth?: string;
hash?: string;
host?: string;
hostname?: string;
href?: string;
origin?: string;
password?: string;
pathname?: string;
port?: string | number;
protocol?: string;
query?: Record<string, string>;
slashes?: boolean;
username?: string;
constructor(options?: URLAttributes);
toString(): string;
}
declare class Statistics {
/**
* We use ε, epsilon, as a stopping criterion when we want to iterate until we're "close enough". Epsilon is a very small number: for simple statistics, that number is 0.0001
* This is used in calculations like the binomialDistribution, in which the process of finding a value is iterative: it progresses until it is close enough.
*/
static epsilon: number;
/**
* The min is the lowest number in the array. This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static min(x: number[]): number;
/**
* This computes the maximum number in an array.
* This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static max(x: number[]): number;
/**
* The sum of an array is the result of adding all numbers together
* This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static sum(x: number[]): number;
/**
* This is an implementation of the Quantiles of a Population algorithm
* Sample is a one-dimensional array of numbers, and p is either a decimal number from 0 to 1 or an array of decimal numbers from 0 to 1. In terms of a k/q quantile, p = k/q - it's just dealing with fractions or dealing with decimal values.
* @param x
* @param p
*/
static quantile(x: number[], p: number): number;
/**
* The product of an array is the result of multiplying all numbers together, starting using one as the multiplicative identity.
* This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static product(x: number[]): number;
/**
* The mean, also known as average, is the sum of all values over the number of values. This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.
* @param x
*/
static mean(x: number[]): number;
/**
* The average, is the sum of all values over the number of values. This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.
* @param x
*/
static average(x: number[]): number;
/**
* When adding a new value to a list, one does not have to necessary recompute the mean of the list in linear time. They can instead use this function to compute the new mean by providing the current mean, the number of elements in the list that produced it and the new value to add.
* @param mean
* @param n
* @param newValue
*/
static addToMean(mean: number, n: number, newValue: number): number;
/**
* When adding a new value to a list, one does not have to necessary recompute the mean of the list in linear time. They can instead use this function to compute the new mean by providing the current mean, the number of elements in the list that produced it and the new value to add.
* @param average
* @param n
* @param newValue
*/
static addToAverage(average: number, n: number, newValue: number): number;
/**
* The mode is the number that appears in a list the highest number of times. There can be multiple modes in a list: in the event of a tie, this algorithm will return the most recently seen mode.
* This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.
* This runs in O(n log(n)) because it needs to sort the array internally before running an O(n) search to find the mode.
* @param x
*/
static mode(x: number[]): number;
/**
* The median is the middle number of a list. This is often a good indicator of 'the middle' when there are outliers that skew the mean() value. This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.
* The median isn't necessarily one of the elements in the list: the value can be the average of two elements if the list has an even length and the two central values are different.
* @param x
*/
static median(x: number[]): number;
/**
* The Harmonic Mean is a mean function typically used to find the average of rates. This mean is calculated by taking the reciprocal of the arithmetic mean of the reciprocals of the input numbers.
* This is a measure of central tendency: a method of finding a typical or central value of a set of numbers.
* This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static harmonicMean(x: number[]): number;
/**
* The Geometric Mean is a mean function that is more useful for numbers in different ranges.
* This is the nth root of the input numbers multiplied by each other.
* The geometric mean is often useful for proportional growth: given growth rates for multiple years, like 80%, 16.66% and 42.85%, a simple mean will incorrectly estimate an average growth rate, whereas a geometric mean will correctly estimate a growth rate that, over those years, will yield the same end value.
* This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static geometricMean(x: number[]): number;
/**
* The Root Mean Square (RMS) is a mean function used as a measure of the magnitude of a set of numbers, regardless of their sign. This is the square root of the mean of the squares of the input numbers. This runs in O(n), linear time, with respect to the length of the array.
* @param x
*/
static rootMeanSquare(x: number[]): number;
/**
* Skewness is a measure of the extent to which a probability distribution of a real-valued random variable "leans" to one side of the mean. The skewness value can be positive or negative, or even undefined.
* Implementation is based on the adjusted Fisher-Pearson standardized moment coefficient, which is the version found in Excel and several statistical packages including Minitab, SAS and SPSS.
* @param x
*/
static sampleSkewness(x: number[]): number;
/**
* The variance is the sum of squared deviations from the mean.
* This is an implementation of variance, not sample variance: see the sampleVariance method if you want a sample measure.
* @param x
*/
static variance(x: number[]): number;
/**
* The sample variance is the sum of squared deviations from the mean. The sample variance is distinguished from the variance by the usage of Bessel's Correction: instead of dividing the sum of squared deviations by the length of the input, it is divided by the length minus one. This corrects the bias in estimating a value from a set that you don't know if full.
* @see http://mathworld.wolfram.com/SampleVariance.html
* @param x
*/
static sampleVariance(x: number[]): number;
/**
* The standard deviation is the square root of the variance. This is also known as the population standard deviation. It's useful for measuring the amount of variation or dispersion in a set of values.
* Standard deviation is only appropriate for full-population knowledge: for samples of a population, sampleStandardDeviation is more appropriate.
* @param x
*/
static standardDeviation(x: number[]): number;
/**
* The sample standard deviation is the square root of the sample variance.
* @param x
*/
static sampleStandardDeviation(x: number[]): number;
/**
* The Median Absolute Deviation is a robust measure of statistical dispersion. It is more resilient to outliers than the standard deviation.
* @param x
*/
static medianAbsoluteDeviation(x: number[]): number;
/**
* The Interquartile range is a measure of statistical dispersion, or how scattered, spread, or concentrated a distribution is. It's computed as the difference between the third quartile and first quartile.
* @param x
*/
static interquartileRange(x: number[]): number;
/**
* The sum of deviations to the Nth power. When n=2 it's the sum of squared deviations. When n=3 it's the sum of cubed deviations.
* @param x
* @param n
*/
static sumNthPowerDeviations(x: number[], n: number): number;
/**
* The Z-Score, or Standard Score.
* The standard score is the number of standard deviations an observation or datum is above or below the mean. Thus, a positive standard score represents a datum above the mean, while a negative standard score represents a datum below the mean. It is a dimensionless quantity obtained by subtracting the population mean from an individual raw score and then dividing the difference by the population standard deviation.
* The z-score is only defined if one knows the population parameters; if one only has a sample set, then the analogous computation with sample mean and sample standard deviation yields the Student's t-statistic.
* @param x
* @param mean
* @param standardDeviation
*/
static zScore(x: number, mean: number, standardDeviation: number): number;
/**
* The correlation is a measure of how correlated two datasets are, between -1 and 1
* @param x
* @param y
*/
static correlation(x: number[], y: number[]): number;
/**
* Sample covariance of two datasets: how much do the two datasets move together? x and y are two datasets, represented as arrays of numbers.
* @param x
* @param y
*/
static sampleCovariance(x: number[], y: number[]): number;
/**
* The R Squared value of data compared with a function f is the sum of the squared differences between the prediction and the actual value.
* @param data
*/
static rSquared(data: [number[], number[]]): number;
/**
* Simple linear regression is a simple way to find a fitted line between a set of coordinates. This algorithm finds the slope and y-intercept of a regression line using the least sum of squares.
* @param data
*/
static linearRegression(data: [number[], number[]]): {
m: number;
b: number;
};
/**
* Given the output of linearRegression: an object with m and b values indicating slope and intercept, respectively, generate a line function that translates x values into y values.
* @param mb
*/
static linearRegressionLine(mb: {
m: number;
b: number;
}): (x: number) => number;
/**
* A Fisher-Yates shuffle is a fast way to create a random permutation of a finite set. This is a function around shuffle_in_place that adds the guarantee that it will not modify its input.
* @param x
*/
static shuffle(x: number[]): number[];
/**
* Sampling with replacement is a type of sampling that allows the same item to be picked out of a population more than once.
* @param x
* @param n
*/
static sampleWithReplacement(x: number[], n: number): number[];
/**
* Create a simple random sample from a given array of n elements.
* The sampled values will be in any order, not necessarily the order they appear in the input.
* @param x
* @param n
*/
static sample(x: number[], n: number): number[];
/**
* Random pick an item from input
* @param x
*/
static randomPickOne(x: number[]): number;
/**
* Random pick items from input
* @param x
* @param n
*/
static randomPickMany(x: number[], n: number): number[];
/**
* The Bernoulli distribution is the probability discrete distribution of a random variable which takes value 1 with success probability p and value 0 with failure probability q = 1 - p. It can be used, for example, to represent the toss of a coin, where "1" is defined to mean "heads" and "0" is defined to mean "tails" (or vice versa). It is a special case of a Binomial Distribution where n = 1.
* @param p
*/
static bernoulliDistribution(p: number): number[];
/**
* The Binomial Distribution is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability probability. Such a success/failure experiment is also called a Bernoulli experiment or Bernoulli trial; when trials = 1, the Binomial Distribution is a Bernoulli Distribution.
* @param trials
* @param probability
*/
static binomialDistribution(trials: number, probability: number): number[];
/**
* The Poisson Distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time and/or space if these events occur with a known average rate and independently of the time since the last event.
* The Poisson Distribution is characterized by the strictly positive mean arrival or occurrence rate, λ.
* @param lambda
*/
static poissonDistribution(lambda: number): number[];
/**
* This is to compute a one-sample t-test, comparing the mean of a sample to a known value, x.
* in this case, we're trying to determine whether the population mean is equal to the value that we know, which is x here. Usually the results here are used to look up a p-value, which, for a certain level of significance, will let you determine that the null hypothesis can or cannot be rejected.
* @param x
* @param expectedValue
*/
static tTest(x: number[], expectedValue: number): number;
/**
* This is to compute two sample t-test. Tests whether "mean(X)-mean(Y) = difference", ( in the most common case, we often have difference == 0 to test if two samples are likely to be taken from populations with the same mean value) with no prior knowledge on standard deviations of both samples other than the fact that they have the same standard deviation.
* Usually the results here are used to look up a p-value, which, for a certain level of significance, will let you determine that the null hypothesis can or cannot be rejected.
* diff can be omitted if it equals 0.
* This is used to reject a null hypothesis that the two populations that have been sampled into sampleX and sampleY are equal to each other.
* @param sampleX
* @param sampleY
* @param difference
*/
static tTestTwoSample(sampleX: number[], sampleY: number[], difference?: number): number | null;
/**
* Split an array into chunks of a specified size. This function has the same behavior as PHP's array_chunk function, and thus will insert smaller-sized chunks at the end if the input size is not divisible by the chunk size.
* x is expected to be an array, and chunkSize a number. The x array can contain any kind of data.
* @param x
* @param chunkSize
*/
static chunk(x: number[], chunkSize: number): number[][];
/**
* A Factorial, usually written n!, is the product of all positive integers less than or equal to n. Often factorial is implemented recursively, but this iterative approach is significantly faster and simpler.
* @param n
*/
static factorial(n: number): number;
/**
* Compute the gamma function of a value using Nemes' approximation. The gamma of n is equivalent to (n-1)!, but unlike the factorial function, gamma is defined for all real n except zero and negative integers (where NaN is returned). Note, the gamma function is also well-defined for complex numbers, though this implementation currently does not handle complex numbers as input values.
* @param n
*/
static gamma(n: number): number;
/**
* Approximate equality.
* @param actual
* @param expected
* @param tolerance
*/
static approxEqual(actual: number, expected: number, tolerance: number): boolean;
/**
* Bisection method is a root-finding method that repeatedly bisects an interval to find the root.
* This function returns a numerical approximation to the exact value.
* @param func
* @param start
* @param end
* @param maxIterations
* @param errorTolerance
*/
static bisect(func: (x: any) => number, start: number, end: number, maxIterations: