UNPKG

@unblocks/utils

Version:
53 lines (50 loc) 1.76 kB
/** A generic type ModeType that represents a valid mode from the given list of modes. */ type ModeType<Modes extends readonly string[]> = Modes[number]; declare class ModeManager<Modes extends readonly string[]> { /** An array of available modes */ readonly modes: Modes; /** A map that stores the mode as a key and its corresponding index as the value. */ private readonly modeToIndexMap; constructor(modes: Modes); /** * Get the mode at the specified index. * Throws an error if the index is out of bounds. * @param index * @returns mode */ getMode(index: number): ModeType<Modes>; /** * Get the index of the specified mode. * Throws an error if the mode name is not found in the list of available modes. * @param mode * @returns index */ getIndex(mode: string): number; } type ValueOf<T extends readonly string[]> = T[number]; /** * A generic class Sizer that manages a list of sizes (e.g. "S", "M", "L"). * It provides methods to get the index of a size, adjust sizes up or down. */ declare class Sizer<O extends readonly string[]> { options: O; constructor(options: O); indexOf(size: ValueOf<O>): number; /** * Adjust size down * @param size size to change * @param amount offset * @param minSize minimum size allowed * @returns new size */ down(size: ValueOf<O>, amount?: number, minSize?: ValueOf<O>): ValueOf<O>; /** * Adjust size up * @param size size to change * @param amount offset * @param maxSize maximum size allowed * @returns new size */ up(size: ValueOf<O>, amount?: number, maxSize?: ValueOf<O>): ValueOf<O>; } export { ModeManager, type ModeType, Sizer };