type Obj = Record; export type Nil = null | undefined; export declare const isNil: (x: T, ...args: unknown[]) => boolean; export declare const isNotNil: (x: T, ...args: unknown[]) => x is T & {}; export declare const assertNotNil: (x: T, ...args: unknown[]) => NonNullable; export type Override = Omit & R; export type MakeOptional = Override>>; export type MakeNonOptional = { [K in keyof T]-?: T[K]; }; /** Function that does nothing and returns undefined */ export declare const noop: (...args: unknown[]) => undefined; /** * Returns the input value unchanged * @param x - Any value * @returns The same value */ export declare const identity: (x: T, ...args: unknown[]) => T; /** * Creates a function that always returns the same value * @param x - Value to return * @returns Function that returns x */ export declare const always: (x: T, ...args: unknown[]) => () => T; /** * Returns the logical NOT of a value * @param x - Value to negate * @returns !x */ export declare const not: (x: any, ...args: unknown[]) => boolean; /** * Deep equality comparison * @param a - First value * @param b - Second value * @returns True if values are deeply equal */ export declare const equals: (a: any, b: any) => boolean; /** Converts string or number to number */ export declare const ensureNumber: (x: number | string) => number; /** Converts a `number | undefined` to a number, defaulting to 0 */ export declare const num: (x: number | undefined) => number; /** Adds two numbers, handling undefined values */ export declare const add: (x: number | undefined, y: number | undefined) => number; /** Subtracts two numbers, handling undefined values */ export declare const sub: (x: number | undefined, y: number | undefined) => number; /** Multiplies two numbers, handling undefined values */ export declare const mul: (x: number | undefined, y: number | undefined) => number; /** Divides two numbers, handling undefined values */ export declare const div: (x: number | undefined, y: number) => number; /** Increments a number by 1, handling undefined values */ export declare const inc: (x: number | undefined) => number; /** Decrements a number by 1, handling undefined values */ export declare const dec: (x: number | undefined) => number; /** Less than comparison, handling undefined values */ export declare const lt: (x: number | undefined, y: number | undefined) => boolean; /** Less than or equal comparison, handling undefined values */ export declare const lte: (x: number | undefined, y: number | undefined) => boolean; /** Greater than comparison, handling undefined values */ export declare const gt: (x: number | undefined, y: number | undefined) => boolean; /** Greater than or equal comparison, handling undefined values */ export declare const gte: (x: number | undefined, y: number | undefined) => boolean; /** Returns maximum value in array, handling undefined values */ export declare const max: (xs: (number | undefined)[]) => number; /** Returns minimum value in array, handling undefined values */ export declare const min: (xs: (number | undefined)[]) => number; /** Returns sum of array values, handling undefined values */ export declare const sum: (xs: (number | undefined)[]) => number; /** Returns average of array values, handling undefined values */ export declare const avg: (xs: (number | undefined)[]) => number; /** * Checks if a number is between two values (exclusive) * @param bounds - Lower and upper bounds * @param n - Number to check * @returns True if n is between low and high */ export declare const between: ([low, high]: [number, number], n: number) => boolean; /** * Checks if a number is between two values (inclusive) * @param bounds - Lower and upper bounds * @param n - Number to check * @returns True if n is between low and high */ export declare const within: ([low, high]: [number, number], n: number) => boolean; /** * Constrains number between min and max values * @param bounds - Minimum and maximum allowed values * @param n - Number to clamp * @returns Clamped value */ export declare const clamp: ([min, max]: [number, number], n: number) => number; /** * Round a number to the nearest float precision * @param precision - Number of decimal places * @param x - Number to round * @returns Formatted number */ export declare const round: (precision: number, x: number) => number; /** One minute in seconds */ export declare const MINUTE = 60; /** One hour in seconds */ export declare const HOUR: number; /** One day in seconds */ export declare const DAY: number; /** One week in seconds */ export declare const WEEK: number; /** One month in seconds (approximate) */ export declare const MONTH: number; /** One quarter in seconds (approximate) */ export declare const QUARTER: number; /** One year in seconds (approximate) */ export declare const YEAR: number; /** User's default locale */ export declare const LOCALE: string; /** User's default timezone */ export declare const TIMEZONE: string; /** * Multiplies time unit by count * @param unit - Time unit in seconds * @param count - Number of units * @returns Total seconds */ export declare const int: (unit: number, count?: number) => number; /** Returns current Unix timestamp in seconds */ export declare const now: () => number; /** * Returns Unix timestamp from specified time ago * @param unit - Time unit in seconds * @param count - Number of units * @returns Timestamp in seconds */ export declare const ago: (unit: number, count?: number) => number; /** * Converts seconds to milliseconds * @param seconds - Time in seconds * @returns Time in milliseconds */ export declare const ms: (seconds: number) => number; /** * Converts seconds to date * @param seconds - Time in seconds * @returns Date object */ export declare const secondsToDate: (seconds: number) => Date; /** * Converts date object to seconds * @param date - Date object * @returns timestamp in seconds */ export declare const dateToSeconds: (date: Date) => number; /** * Creates a local date from a date string * @param dateString - date string * @param timezone - timezone string * @returns timezone-aware Date object */ export declare const createLocalDate: (dateString: any, timezone?: string) => Date; /** Formatter for date+time */ export declare const dateTimeFormatter: Intl.DateTimeFormat; /** * Formats seconds as a datetime * @param seconds - timestamp in seconds * @returns datetime string */ export declare const formatTimestamp: (seconds: number) => string; /** Formatter for date */ export declare const dateFormatter: Intl.DateTimeFormat; /** * Formats seconds as a date * @param seconds - timestamp in seconds * @returns date string */ export declare const formatTimestampAsDate: (ts: number) => string; /** Formatter for time */ export declare const timeFormatter: Intl.DateTimeFormat; /** * Formats seconds as a time * @param seconds - timestamp in seconds * @returns time string */ export declare const formatTimestampAsTime: (ts: number) => string; /** * Formats seconds as a relative date (x minutes ago) * @param seconds - timestamp in seconds * @returns relative date string */ export declare const formatTimestampRelative: (ts: number) => string; /** * Returns the first element of an array * @param xs - The array * @returns First element or undefined */ export declare const first: (xs: Iterable, ...args: unknown[]) => T | undefined; /** * Returns the first element of the first array in a nested array * @param xs - Array of arrays * @returns First element of first array or undefined */ export declare const ffirst: (xs: Iterable>, ...args: unknown[]) => T | undefined; /** * Returns the last element of an array * @param xs - The array * @returns Last element or undefined */ export declare const last: (xs: Iterable, ...args: unknown[]) => T; /** * Returns array with first n elements removed * @param n - Number of elements to drop * @param xs - Input array * @returns Array with first n elements removed */ export declare const drop: (n: number, xs: Iterable) => T[]; /** * Returns first n elements of array * @param n - Number of elements to take * @param xs - Input array * @returns Array of first n elements */ export declare const take: (n: number, xs: Iterable) => T[]; /** * Concatenates multiple arrays, filtering out null/undefined * @param xs - Arrays to concatenate * @returns Combined array */ export declare const concat: (...xs: T[][]) => T[]; /** * Appends element to array * @param x - Element to append * @param xs - Array to append to * @returns New array with element appended */ export declare const append: (x: T, xs: Iterable) => T[]; /** * Creates union of two arrays * @param a - First array * @param b - Second array * @returns Array containing unique elements from both arrays */ export declare const union: (a: Iterable, b: Iterable) => T[]; /** * Returns elements common to both arrays * @param a - First array * @param b - Second array * @returns Array of elements present in both inputs */ export declare const intersection: (a: Iterable, b: Iterable) => T[]; /** * Returns elements in first array not present in second * @param a - Source array * @param b - Array of elements to exclude * @returns Array containing elements unique to first array */ export declare const difference: (a: Iterable, b: Iterable) => T[]; /** * Removes all instances of an element from array * @param a - Element to remove * @param xs - Source array * @returns New array with element removed */ export declare const remove: (a: T, xs: T[]) => T[]; /** * Removes element at index * @param i - Index to remove * @param xs - Source array * @returns New array with element removed */ export declare const removeAt: (i: number, xs: T[]) => T[]; /** * Returns elements from second array not present in first * @param a - Array of elements to exclude * @param b - Source array * @returns Filtered array */ export declare const without: (a: T[], b: T[]) => T[]; /** * Toggles presence of element in array * @param x - Element to toggle * @param xs - Source array * @returns New array with element added or removed */ export declare const toggle: (x: T, xs: T[]) => T[]; /** * Generates sequence of numbers from a to b * @param a - Start number (inclusive) * @param b - End number (exclusive) * @param step - Increment between numbers * @yields Numbers in sequence */ export declare function range(a: number, b: number, step?: number): Generator; /** * Yields indexed items * @param items - A collection of items * @yields tuples of [index, item] */ export declare function enumerate(items: T[]): Generator<[number, T], void, unknown>; /** Returns a function that gets property value from object */ export declare const pluck: (k: string, xs: Record[]) => T[]; /** * Creates object from array of key-value pairs * @param pairs - Array of [key, value] tuples * @returns Object with keys and values from pairs */ export declare const fromPairs: (pairs: [k?: string, v?: T, ...args: unknown[]][]) => Record; /** * Flattens array of arrays into single array * @param xs - Array of arrays to flatten * @returns Flattened array */ export declare const flatten: (xs: (T | T[])[], ...args: unknown[]) => T[]; /** * Splits array into two arrays based on predicate * @param f - Function to test elements * @param xs - Array to partition * @returns Tuple of [matching, non-matching] arrays */ export declare const partition: (f: (x: T) => boolean, xs: T[]) => T[][]; /** * Returns array with duplicate elements removed * @param xs - Array with possible duplicates * @returns Array with unique elements */ export declare const uniq: (xs: T[]) => T[]; /** * Returns array with elements unique by key function * @param f - Function to generate key for each element * @param xs - Input array * @returns Array with elements unique by key */ export declare const uniqBy: (f: (x: T) => any, xs: T[]) => T[]; /** * Returns sorted copy of array * @param xs - Array to sort * @returns New sorted array */ export declare const sort: (xs: T[]) => T[]; /** * Returns array sorted by key function * @param f - Function to generate sort key * @param xs - Array to sort * @returns Sorted array */ export declare const sortBy: (f: (x: T) => any, xs: T[]) => T[]; /** * Groups array elements by key function * @param f - Function to generate group key * @param xs - Array to group * @returns Map of groups */ export declare const groupBy: (f: (x: T) => K, xs: Iterable) => Map; /** * Counts array elements by key function * @param f - Function to generate group key * @param xs - Array to count entries * @returns Map of counts */ export declare const countBy: (f: (x: T) => K, xs: T[]) => Map; /** * Creates map from array using key function * @param f - Function to generate key * @param xs - Array to index * @returns Map of values by key */ export declare const indexBy: (f: (x: T) => K, xs: T[]) => Map; /** * Creates array of specified length using generator function * @param n - Length of array * @param f - Function to generate each element * @returns Generated array */ export declare const initArray: (n: number, f: () => T) => T[]; /** * Splits array into chunks of specified length * @param chunkLength - Maximum length of each chunk * @param xs - Array to split * @returns Array of chunks */ export declare const chunk: (chunkLength: number, xs: T[]) => T[][]; /** * Splits array into specified number of chunks * @param n - Number of chunks * @param xs - Array to split * @returns Array of n chunks */ export declare const chunks: (n: number, xs: T[]) => T[][]; /** Splits array into two parts at index */ export declare const splitAt: (n: number, xs: T[]) => T[][]; /** Inserts element into array at index */ export declare const insertAt: (n: number, x: T, xs: T[]) => T[]; /** Replaces array element at index */ export declare const replaceAt: (n: number, x: T, xs: T[]) => T[]; /** Returns random element from array */ export declare const choice: (xs: T[]) => T; /** Returns shuffled copy of iterable */ export declare const shuffle: (xs: Iterable) => T[]; /** Returns n random elements from array */ export declare const sample: (n: number, xs: T[]) => T[]; /** Checks if value is iterable */ export declare const isIterable: (x: any) => boolean; /** Ensures value is iterable by wrapping in array if needed */ export declare const toIterable: (x: any) => any; /** Ensures value is array by wrapping if needed */ export declare const ensurePlural: (x: T | T[]) => T[]; /** Ensures values are not undefined */ export declare const removeNil: (xs: T[]) => NonNullable[]; /** Returns a list of overlapping pairs of elements in xs */ export declare const overlappingPairs: (xs: T[]) => T[][]; /** * Checks if value is a plain object * @param obj - Value to check * @returns True if value is a plain object */ export declare const isPojo: (obj: any) => boolean; /** * Creates new object with only specified keys * @param ks - Keys to keep * @param x - Source object * @returns New object with only specified keys */ export declare const pick: (ks: string[], x: T) => T; /** * Creates new object with specified keys removed * @param ks - Keys to remove * @param x - Source object * @returns New object without specified keys */ export declare const omit: (ks: string[], x: T) => T; /** * Creates new object excluding entries with specified values * @param xs - Values to exclude * @param x - Source object * @returns New object without entries containing specified values */ export declare const omitVals: (xs: any[], x: T) => T; /** * Filters object values based on predicate * @param f - Function to test values * @param x - Object to filter * @returns Object with only values that pass predicate */ export declare const filterVals: >(f: (v: any) => boolean, x: T) => T; /** * Creates new object with transformed keys * @param f - Function to transform keys * @param x - Source object * @returns Object with transformed keys */ export declare const mapKeys: (f: (v: string) => string, x: T) => T; /** * Creates new object with transformed values * @param f - Function to transform values * @param x - Source object * @returns Object with transformed values */ export declare const mapVals: (f: (v: V) => U, x: Record) => Record; /** * Merges two objects, with left object taking precedence * @param a - Left object * @param b - Right object * @returns Merged object with a"s properties overriding b"s */ export declare const mergeLeft: (a: T, b: T) => T; /** * Merges two objects, with right object taking precedence * @param a - Left object * @param b - Right object * @returns Merged object with b"s properties overriding a"s */ export declare const mergeRight: (a: T, b: T) => T; /** Deep merge two objects, prioritizing the first argument. */ export declare const deepMergeLeft: (a: Obj, b: Obj) => Obj; /** Deep merge two objects, prioritizing the second argument. */ export declare const deepMergeRight: (a: Obj, b: Obj) => Obj; /** * Switches on key in object, with default fallback * @param k - Key to look up * @param m - Object with values and optional default * @returns Value at key or default value */ export declare const switcher: (k: string, m: Record) => T; /** Returns a function that returns the boolean negation of the given function */ export declare const complement: (f: (...args: T) => any) => (...args: T) => boolean; /** * Safely executes function and handles errors * @param f - Function to execute * @param onError - Optional error handler * @returns Function result or undefined if error */ export declare const tryCatch: (f: () => T, onError?: (e: Error) => void) => T | undefined; /** * Creates function that only executes once * @param f - Function to wrap * @returns Function that executes f only on first call */ export declare const once: (f: (...args: any) => void) => (...args: any) => void; /** * Calls a function * @param f - Function to call * @returns Whatever f returns */ export declare const call: (f: () => T, ...args: unknown[]) => T; /** * Memoizes function results based on arguments * @param f - Function to memoize * @returns Memoized function */ export declare const memoize: (f: (...args: any[]) => T) => (...args: any[]) => T; /** * Executes a function if the value is defined * @param x - The value to check * @param f - Function to execute if x is defined * @returns Result of f(x) if x is defined, undefined otherwise */ export declare const ifLet: (x: T | undefined, f: (x: T) => void) => void; /** * Generates random integer between min and max (inclusive) * @param min - Minimum value * @param max - Maximum value * @returns Random integer */ export declare const randomInt: (min?: number, max?: number) => number; /** * Generates random string ID * @returns Random string suitable for use as an ID */ export declare const randomId: () => string; /** * Creates a promise that resolves after specified time * @param t - Time in milliseconds * @returns Promise that resolves after t milliseconds */ export declare const sleep: (t: number) => Promise; export type PollOptions = { signal: AbortSignal; condition: () => boolean; interval?: number; }; /** * Creates a promise that resolves after the condition completes or timeout * @param options - PollOptions * @returns void Promise */ export declare const poll: ({ interval, condition, signal }: PollOptions) => Promise; /** * Creates a microtask that yields to other tasks in the event loop * @returns Promise that resolves after yielding */ export declare const yieldThread: () => any; /** * Creates throttled version of function * @param ms - Minimum time between calls * @param f - Function to throttle * @returns Throttled function */ export declare const throttle: any>(ms: number, f: F) => F | ((...thisArgs: Parameters) => void); /** * Creates throttled function that returns cached value * @param ms - Minimum time between updates * @param f - Function to throttle * @returns Function returning latest value */ export declare const throttleWithValue: (ms: number, f: () => T) => () => T; /** * Creates batching function that collects items * this function does not delay execution, if a series of items is passed in sequence * the first item will be processed immediately, and the rest will be batched * @param t - Time window for batching * @param f - Function to process batch * @returns Function that adds items to batch */ export declare const batch: (t: number, f: (xs: T[]) => void) => (x: T) => void; /** * Creates batching function that returns results * @param t - Time window for batching * @param execute - Function to process batch * @returns Function that returns promise of result */ export declare const batcher: (t: number, execute: (request: T[]) => U[] | Promise) => (request: T) => Promise; /** * Returns a promise that resolves after some proportion of promises complete * @param threshold - number between 0 and 1 for how many promises to wait for * @param promises - array of promises * @returns promise */ export declare const race: (threshold: number, promises: Promise[]) => Promise; /** * Removes protocol (http://, https://, etc) from URL * @param url - URL to process * @returns URL without protocol */ export declare const stripProtocol: (url: string) => string; /** * Formats URL for display by removing protocol, www, and trailing slash * @param url - URL to format * @returns Formatted URL */ export declare const displayUrl: (url: string) => string; /** * Extracts and formats domain from URL * @param url - URL to process * @returns Formatted domain name */ export declare const displayDomain: (url: string) => string; /** * Safely parses JSON string * @param json - JSON string to parse * @returns Parsed object or null if invalid */ export declare const parseJson: (json: string | undefined) => any; /** * Gets and parses JSON from localStorage * @param k - Storage key * @returns Parsed value or undefined if invalid/missing */ export declare const getJson: (k: string) => any; /** * Stringifies and stores value in localStorage * @param k - Storage key * @param v - Value to store */ export declare const setJson: (k: string, v: any) => void; /** Options for fetch requests */ type FetchOpts = { method?: string; headers?: Record; body?: string | FormData; }; /** * Fetches JSON from URL with options * @param url - URL to fetch from * @param opts - Fetch options * @returns Promise of parsed JSON response */ export declare const fetchJson: (url: string, opts?: FetchOpts) => Promise; /** * Posts JSON data to URL * @param url - URL to post to * @param data - Data to send * @param opts - Additional fetch options * @returns Promise of parsed JSON response */ export declare const postJson: (url: string, data: T, opts?: FetchOpts) => Promise; /** * Uploads file to URL * @param url - Upload URL * @param file - File to upload * @returns Promise of parsed JSON response */ export declare const uploadFile: (url: string, file: File) => Promise; /** * A generic type-safe event listener function that works with event emitters. * * @param target - The event target object with add/remove listener methods * @param eventName - The name of the event to listen for * @param callback - The callback function to execute when the event occurs * @returns A function that removes the event listener when called */ export declare const on: , E extends keyof EventMap>(target: { on(event: E, listener: (...args: EventMap[E]) => any): any; off(event: E, listener: (...args: EventMap[E]) => any): any; }, eventName: E, callback: (...args: EventMap[E]) => void) => (() => void); /** * Truncates string to length, breaking at word boundaries * @param s - String to truncate * @param l - Maximum length * @param suffix - String to append if truncated * @returns Truncated string */ export declare const ellipsize: (s: string, l: number, suffix?: string) => string; /** Displays a list of items with oxford commas and a chosen conjunction */ export declare const displayList: (xs: T[], conj?: string, n?: number) => string; /** Generates a hash string from input string */ export declare const hash: (s: string) => string; /** Returns a function that gets the nth element of an array */ export declare const nth: (i: number) => (xs: T[], ...args: unknown[]) => T; /** Returns a function that checks if nth element equals value */ export declare const nthEq: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean; /** Returns a function that checks if nth element does not equal value */ export declare const nthNe: (i: number, v: any) => (xs: any[], ...args: unknown[]) => boolean; /** Returns a function that checks if key/value pairs of x match all pairs in spec */ export declare const spec: (values: Obj | Array) => (x: Obj | Array, ...args: unknown[]) => boolean; /** Returns a function that checks equality with value */ export declare const eq: (v: T) => (x: T, ...args: unknown[]) => boolean; /** Returns a function that checks inequality with value */ export declare const ne: (v: T) => (x: T, ...args: unknown[]) => boolean; /** Returns a function that gets property value from object */ export declare const prop: (k: string) => (x: Record) => T; /** Returns a function that adds/updates a property on object */ export declare const assoc: (k: K, v: T) => (o: U) => U & Record; /** Returns a function that removes a property on object */ export declare const dissoc: (k: K) => (o: T) => T; /** Returns a function that checks whether a value is in the given sequence */ export declare const member: (xs: Iterable) => (x: T) => boolean; /** * Adds value to Set at key in object * @param m - Object mapping keys to Sets * @param k - Key to add to * @param v - Value to add */ export declare const addToKey: (m: Record>, k: string, v: T) => void; /** * Pushes value to array at key in object * @param m - Object mapping keys to arrays * @param k - Key to push to * @param v - Value to push */ export declare const pushToKey: (m: Record, k: string, v: T) => void; /** * Adds value to Set at key in Map * @param m - Map of Sets * @param k - Key to add to * @param v - Value to add */ export declare const addToMapKey: (m: Map>, k: K, v: T) => void; /** * Pushes value to array at key in Map * @param m - Map of arrays * @param k - Key to push to * @param v - Value to push */ export declare const pushToMapKey: (m: Map, k: K, v: T) => void; /** * Converts hex string to bech32 format * @param prefix - Bech32 prefix * @param hex - Hex string to convert * @returns Bech32 encoded string */ export declare const hexToBech32: (prefix: string, hex: string) => `${Lowercase}1${string}`; /** * Converts bech32 string to hex format * @param b32 - Bech32 string to convert * @returns Hex encoded string */ export declare const bech32ToHex: (b32: string) => string; /** * Converts an array buffer or Uint8Array to hex format * @param buffer - ArrayBuffer or Uint8Array to convert * @returns Hex encoded string */ export declare const bytesToHex: (buffer: ArrayBuffer | Uint8Array) => string; /** * Converts a hex string to an array buffer * @param hex - hex string * @returns ArrayBuffer */ export declare const hexToBytes: (hex: string) => Uint8Array; export declare const textEncoder: TextEncoder; export declare const textDecoder: TextDecoder; /** * Computes SHA-256 hash of binary data * @param data - Binary data to hash * @returns Promise resolving to hex-encoded hash string */ export declare const sha256: (data: ArrayBuffer | Uint8Array) => Promise; export {}; //# sourceMappingURL=Tools.d.ts.map