/** * Type guard against null value * * @param value Value that could be null * @returns Confirmation that the value is not null */ export declare function notNull(value: T | null): value is T; /** * Type guard against nullish value * * @param value Value that could be null or undefined * @returns Confirmation that the value is not null nor undefined */ export declare function notNullish(value: T | null | undefined): value is T; /** * Parse string to number, stripping commas * * @param n Numberical string to parse * @returns Numerical value of string */ export declare function parseNumber(n: string): number; /** * Clamp a number between lower and upper bounds. * * @param n Number to clamp. * @param min Lower bound. * @param max Upper bound. * @returns Clamped value */ export declare function clamp(n: number, min: number, max: number): number; /** * Split an array into chunkSize sized chunks * * @param array Array to split * @param chunkSize Size of chunk * @returns Split array */ export declare function chunk(array: T[], chunkSize: number): T[][]; /** * Count distinct values in an array * * @param array Array of values * @returns Map of distinct values to count */ export declare function arrayToCountedMap(array: T[] | Map): Map; /** * Turn map of distinct values to count into array of values * * @param map Map to turn into array * @returns Array of values */ export declare function countedMapToArray(map: Map): T[]; /** * Stringify a counted map * * @param map Map of counted values * @returns String representing map of counted values */ export declare function countedMapToString(map: Map): string; /** * Sum an array of numbers. * * @param addends Addends to sum. * @param property Property of the elements to be summing * @returns Sum of numbers */ export declare function sum(addends: readonly T[], property: S): number; /** * Sum an array of numbers. * * @param addends Addends to sum. * @param mappingFunction Mapping function to turn addends into actual numbers. * @returns Sum of numbers */ export declare function sum(addends: readonly T[], mappingFunction: (element: T) => number): number; /** * Sum array of numbers * * @param addends Numbers to sum * @returns Sum of numbers */ export declare function sumNumbers(addends: number[]): number; /** * Checks if a given item is in a readonly array, acting as a typeguard. * * @param item Needle * @param array Readonly array haystack * @returns Whether the item is in the array, and narrows the type of the item. */ export declare function arrayContains(item: T, array: ReadonlyArray): item is A; /** * Checks if two arrays contain the same elements in the same quantity. * * @param a First array for comparison * @param b Second array for comparison * @returns Whether the two arrays are equal, irrespective of order. */ export declare function setEqual(a: T[], b: T[]): boolean; /** * Reverses keys and values for a given map * * @param map Map to invert * @returns Inverted map */ export declare function invertMap(map: Map): Map; /** * Splits a string by commas while also respecting escaping commas with a backslash * * @param str String to split * @returns List of tokens */ export declare function splitByCommasWithEscapes(str: string): string[]; export declare function maxBy(array: T[] | readonly T[], optimizer: (element: T) => number, reverse?: boolean): T; export declare function maxBy(array: T[] | readonly T[], key: S, reverse?: boolean): T; /** * Let Typescript see that you're working with tuples! * * @param args A spread array to interpret as a tuple * @returns The given arg, its type now interpreted as a tuple */ export declare function tuple(...args: T): T; export type Tuple = N extends N ? number extends N ? T[] : _tupleOf : never; type _tupleOf = R["length"] extends N ? R : _tupleOf; /** * Compare arrays shallowly * * @param left One array to compare * @param right The other array to compare * @returns Whether the two arrays are shallowly equal */ export declare function arrayEquals(left: T[] | readonly T[], right: T[] | readonly T[]): boolean; /** * Type that extends any non-function entity--like a string, number, or array--into a itself and a no-input function that returns it. * Used to interact with objects that could either be functions or static values. */ export type Delayed = [T] extends [ (...args: any) => any ] ? never : T | ((...args: S) => T); /** * Used to collapse a Delayed object into an entity of type "T" as represented by the object. * * @param delayedObject Object of type Delayed that represents either a value of type T or a function returning a value of type T. * @param args The arguments to pass to the delay function * @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element. */ export declare function undelay(delayedObject: Delayed, ...args: S): T; /** * An object keyed by string type T, with values of S. * or contains a 'default' parameter to use as a fallback. */ export type Switch = Record | (Partial<{ [x in T]: S; }> & { default: S; }); /** * Makes a byX function, like byStat or byClass * * @param source A method for finding your stat, or class, or whatever X is in this context * @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined. */ export declare function makeByXFunction(source: Delayed): (options: Switch, alternateSource?: Delayed) => S; /** * Flattens an array. Basically replacing Array.prototype.flat for which Rhino doesn't yet have an implementation * @deprecated KoLMafia now supports the `flat` and `flatMap` methods * * @param arr Array to flatten * @param depth Number of layers to flatten by; Infinity for a fully flat array * @returns Flattened array */ export declare function flat(arr: A, depth?: number): FlatArray[]; /** * @param array Array to select from * @returns Random item from array */ export declare function random(array: T[]): T; /** * Title cases a single word * * @param word Word to transform * @returns Word in title case */ export declare const tc: (word: string) => string; type Enumerate = A["length"] extends N ? A[number] : Enumerate; /** * Integers on the interval [A, B). */ export type Range = Exclude, Enumerate>; export type ValueOf = T[keyof T]; export {};