import * as YAML from 'yaml'; /** Returns a (copied) array with just the unique items in it. */ export declare function unique(arr: Iterable): T[]; /** Returns a (copied) array with just the unique items in it. */ export declare function uniqueBy(arr: Iterable, identify: (x: T) => any): any[]; /** In place shuffle function for an array. */ export declare function shuffle(t: T[]): T[]; /** Creates an array using a length and a `map(index)` function. */ export declare function createArray(length: number, map: (index: number) => T): T[]; /** Moves index `i` to index `j` in an array immutably. */ export declare function moveArrayValue(arr: T[], i: number, j: number): T[]; /** Remove an item from an array immutably. */ export declare function removeArrayValue(arr: T[], i: number): T[]; /** Insert an item into an array immutably. */ export declare function insertArrayValue(arr: T[], i: number, value: T): T[]; /** * Returns an iterator with a specified range. Range includes the first number and does not include * the second. */ export declare function range(length: number): IterableIterator; export declare function range(start: number, end: number, step?: number): IterableIterator; export interface CacheMapOptions { /** How long to keep the values in the map for. In Seconds. */ ttl?: number; /** How often to check for expired values. In Seconds. */ checkInterval?: number; } /** Map that clears it's own values out after x amount of time. */ export declare class CacheMap implements Map { #private; constructor(opts?: CacheMapOptions); sweep(): void; clear(): void; delete(key: K): boolean; forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void; get(key: K): V | undefined; has(key: K): boolean; set(key: K, value: V): this; get size(): number; entries(): IterableIterator<[ K, V ]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.iterator](): IterableIterator<[ K, V ]>; [Symbol.toStringTag]: string; } /** Wrap a function and apply debounce logic to. */ export declare function debounce(func: (...args: Args) => void, waitTime: number): (...args: Args) => void; /** Wrap a function and apply throttle logic to. */ export declare function throttle(func: (...args: Args) => void, waitTime: number): (...args: Args) => void; /** * Runs the function, and if it throws an error, return the fallback value. If the callback is * async, a promise will always be returned. */ export declare function tryOrFallback(cb: () => Value, fallback: Fallback): Value extends Promise ? Promise : Value | Fallback; export type BufferEncoding = "utf8" | "utf-8" | "ascii" | "utf16le" | "ucs2" | "ucs-2" | "latin1"; /** @param {string} file */ export declare function pathExists(file: string): Promise; export interface FileWriteOptionsBase { /** Encoding of the file. Defaults to "utf8". */ encoding?: BufferEncoding; /** Mode of the file. Defaults to 0o666. */ mode?: number; /** * Flag of the file. Defaults to "w", * {@link https://nodejs.org/api/fs.html#file-system-flags List of all flags on nodejs.org}. */ flag?: string; /** Whether to create the directory if it doesn't exist. */ mkdir?: boolean; } export interface FileReadOptionsBase { /** Encoding of the file. Defaults to "utf8". */ encoding?: BufferEncoding; /** * Flag of the file. Defaults to "r", * {@link https://nodejs.org/api/fs.html#file-system-flags List of all flags on nodejs.org}. */ flag?: string; } export interface WriteJSONOptions extends FileWriteOptionsBase { /** * Adds indentation, white space, and line break characters to the return-value JSON text to make * it easier to read. */ spaces?: number | boolean; /** * Either: * * - An array of strings and numbers that acts as an approved list for selecting the object * properties that will be stringified. * - A function that transforms the results. */ replacer?: Parameters[1]; } export interface ReadJSONOptions extends FileReadOptionsBase { /** * A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ reviver?: Parameters[1]; /** If the file does not exist, return this value instead. */ default?: T | (() => T); } export interface WriteYAMLOptions extends FileWriteOptionsBase, YAML.DocumentOptions, YAML.SchemaOptions, YAML.ParseOptions, YAML.CreateNodeOptions, YAML.ToStringOptions { } export interface ReadYAMLOptions extends FileReadOptionsBase, YAML.ParseOptions, YAML.DocumentOptions, YAML.SchemaOptions, YAML.ToJSOptions { /** If the file does not exist, return this value instead. */ default?: T | (() => T); } export declare function readJSONSync(file: string, options?: ReadJSONOptions): T; export declare function ensureDir(file: string): Promise; export declare function ensureDirSync(file: string): void; export declare function writeJSONSync(file: string, data: T, options?: WriteJSONOptions): void; export declare function readJSON(file: string, options?: ReadJSONOptions): Promise; export declare function writeJSON(file: string, data: T, options?: WriteJSONOptions): Promise; export declare function readYAMLSync(file: string, options?: ReadYAMLOptions): T; export declare function writeYAMLSync(file: string, data: T, options?: WriteYAMLOptions): void; export declare function readYAML(file: string, options?: ReadYAMLOptions): Promise; export declare function writeYAML(file: string, data: T, options?: WriteYAMLOptions): Promise; export interface WalkOptions { directories?: boolean; files?: boolean; } /** Returns an async iterator over all files in a folder. */ export declare function walk(root: string, opts?: WalkOptions): AsyncIterable; export type HashEncoding = "base64" | "hex" | "binary" | "buffer"; export interface HashDirectoryOptions { format?: Format; algorithm?: string; } /** * Hash all of the contents of a given directory. * * **currently node.js only** */ export declare function hashDirectoryContents(root: string, options?: HashDirectoryOptions<"binary">): Promise; export declare function hashDirectoryContents(root: string, options: HashDirectoryOptions): Promise; export declare function isRootDirectory(str: string): boolean; export declare function emptyDir(dir: string): Promise; export declare function emptyDirSync(dir: string): void | Promise; export declare function asyncIterToArray(iterator: AsyncIterator | AsyncIterable): Promise; export declare function iterToArray(iterator: Iterator | Iterable): T[]; export declare class IterableStream implements AsyncIterableIterator { #private; constructor(); [Symbol.asyncIterator](): AsyncIterableIterator; next(): Promise>; push(value: T): void; throw(error: any): Promise>; end(): void; } export declare function streamToIter(readable: ReadableStream | ReadableStreamReader): AsyncIterableIterator; /** Clamps a number to a min and max value. */ export declare function clamp(value: number, min: number, max: number): number; /** Linear interpolation. */ export declare function lerp(a: number, b: number, t: number): number; export declare function lerpClamped(a: number, b: number, t: number): number; export declare function step(value: number, target: number, increment: number): number; /** Shorthand notation for a dictionary object, aka Record */ export type Dict = Record; /** Represents something that _might_ be a promise. */ export type Awaitable = T | Promise; /** * Utility type to force the hover tooltip to "simplify" it's type, one layer down. Call repeatedly * to simplify multiple passes. */ export type ForceSimplify = T extends Record ? { [P in keyof T]: ForceSimplify; } : T; /** * Utility type to prevent the hover tooltip from automatically simplifying. Place at the root of * another type to get it's hover overlay to show `YourTypeName<{ passed type }>` * * WIP. */ export type PreventAutoSimplify = T; /** * ObjectWithMethod resolves to an object with a single method. In autocomplete, the * "method/function" icon is shown instead of the "property" icon. */ export type ObjectWithMethod any, Obj = { method(...args: Parameters): ReturnType; }> = { [K in keyof Obj as Key]: Obj[K]; }; /** Separate type so if you Simplify>, it will handle properly. */ export type _Immutable = T extends Array ? ReadonlyArray<_Immutable> : T extends ReadonlyArray ? ReadonlyArray<_Immutable> : T extends Map ? ReadonlyMap<_Immutable, _Immutable> : T extends ReadonlyMap ? ReadonlyMap<_Immutable, _Immutable> : T extends Set ? ReadonlySet<_Immutable> : T extends ReadonlySet ? ReadonlySet<_Immutable> : T extends Record ? { readonly [P in keyof T]: _Immutable; } : T; /** `Immutable` represents T as an immutable object (recursive) */ export type Immutable = PreventAutoSimplify<_Immutable>; /** `Mutable` represents T as a mutable object (recursive). Reverse of Immutable. */ export type Mutable = T extends ReadonlyArray ? Array> : T extends Array ? Array> : T extends Record ? { -readonly [P in keyof T]: Mutable; } : T; /** Represents an empty object. */ export type EmptyObject = Dict; /** * Use this type when you have something unfinished, and you want to make it clear that it must be * fixed. Other than visual, this is an alias to `any` */ export type FIXME = any; /** * Return type of `setTimeout`. Will be `number`, unless @types/node is installed, then it will be * `NodeJS.Timeout`. */ export type Timer = ReturnType; export type Func = (...args: any[]) => R; export interface MemoizeOptions> = Map>> { execute: T; cache?: Cache; getKey?(...args: Parameters): string; } export interface MemoizedFunction> = Map>> { (...args: Parameters): ReturnType; cache: Cache; original: T; } /** * Caches results of a function calls, making it so calling the same function with the same * arguments will return the same result without re-evaluating. * * Supports async functions (you'll get a promise that resolves to the cached value), but does not * support functions that conditionally return a promise. */ export declare function memoize>>(opts: T | MemoizeOptions): MemoizedFunction; export type F = (input: In) => Out; export type A = (input: Awaited) => Awaitable; /** Function equivalent of the pipe operator or Function.pipe() */ export declare function pipe(input: T0, f1: F): T1; export declare function pipe(input: T0, f1: F, f2: F): T2; export declare function pipe(input: T0, f1: F, f2: F, f3: F): T3; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F): T4; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F): T5; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F): T6; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F): T7; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F): T8; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F): T9; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F, f10: F): T10; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F, f10: F, f11: F): T11; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F, f10: F, f11: F, f12: F): T12; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F, f10: F, f11: F, f12: F, f13: F): T13; export declare function pipe(input: T0, f1: F, f2: F, f3: F, f4: F, f5: F, f6: F, f7: F, f8: F, f9: F, f10: F, f11: F, f12: F, f13: F, f14: F): T14; /** Function equivalent of the pipe operator or Function.pipeAsync() */ export declare function pipeAsync(input: T0, f1: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A, f10: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A, f10: A, f11: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A, f10: A, f11: A, f12: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A, f10: A, f11: A, f12: A, f13: A): Promise; export declare function pipeAsync(input: T0, f1: A, f2: A, f3: A, f4: A, f5: A, f6: A, f7: A, f8: A, f9: A, f10: A, f11: A, f12: A, f13: A, f14: A): Promise; /** Returns a promise that resolves after `ms` milliseconds, essentially a Promisified `setTimeout` */ export declare function delay(ms: number): Promise; /** Returns an array containing a promise and two functions to resolve and reject that promise. */ export declare function deferred(): [ Promise, (x: T) => void, (err: any) => void ]; export declare function asyncMap(input: Iterable, mapper: (item: T, i: number) => Awaitable): Promise<(Awaited | Awaited)[]>; export interface IQueue { enqueue(item: T): void; dequeue(): T | undefined; peek(): T | undefined; length: number; } export declare class Queue extends Array { constructor(items?: T[]); peek(): T | undefined; } export interface Queue extends IQueue { } export type QueuedFunctionItem = [ fn: Func>, resolve: Func, reject: Func, args: any[] ] | [ true ]; export interface QueuedFunctionOptions { queue?: IQueue | ((...args: Args) => IQueue | string); execute(...args: Args): Promise; } export declare function queuedFunction(options: QueuedFunctionOptions | ((...args: Args) => Promise)): (...args: Args) => Promise; /** * RemoteMap is an interface to any form of async KeyValue store. Intentionally made extremely * minimal for easy implementation. */ export interface IAnyRemoteMap { get(key: K): Promise; set(key: K, value: V): Promise; delete(key: K): Promise; } /** * RemoteMap is an interface to any form of async KeyValue store. Intentionally made extremely * minimal for easy implementation. */ export type IRemoteMap = IAnyRemoteMap; export declare class InMemoryRemoteMap implements IRemoteMap { private readonly map; get(key: string): Promise; set(key: string, value: any): Promise; delete(key: string): Promise; } /** (Insecurely) Generates a random integer between `min` and `max`. */ export declare function randomInt(min: number, max: number): number; /** (Insecurely) Generates a random float between `min` and `max`. */ export declare function randomFloat(min: number, max: number): number; export declare function randomOf(array: T[]): T; /** Capitalizes a string. */ export declare function capitalize(string: string): string; /** * Alias of Bun.escapeHTML, polyfilled for other platforms. * * Escape the following characters in a string: * * - `"` becomes `"""` * - `&` becomes `"&"` * - `'` becomes `"'"` * - `<` becomes `"<"` * - `>` becomes `">"` * * In bun, this function is optimized for large input. On an M1X, it processes 480 MB/s - 20 GB/s, * depending on how much data is being escaped and whether there is non-ascii text. */ export declare const escapeHTML: (string: string) => string; export declare function escapeRegex(string: string): string; export declare function escapeRegexReplacement(string: string): string; export declare function plural(string: string | [ string, string ], number?: number): string; /** Polyfill for String.cooked. */ export declare function cookString(strings: TemplateStringsArray, ...values: any[]): string; export declare function urlTemplate(strings: TemplateStringsArray, ...subs: string[]): string; export declare function htmlTemplate(strings: TemplateStringsArray, ...subs: string[]): string; export declare function hexToUint8Array(hex: string): Uint8Array; export declare function uint8ArrayToHex(bytes: Uint8Array): string; export {};