xuxi
Version:
Dynamically utility for combining different types of values into a single value.
56 lines (55 loc) • 2.48 kB
TypeScript
import { variant } from './variant';
/** Represents a mapping of string or symbol keys to any value. */
export type StringKeyMap = Record<string | symbol, any>;
/** Defines the accepted value types for the utility functions. */
export type StringValues = StringKeyMap | StringKeyMap[] | StringValues[] | string | number | boolean | null | undefined | BigInt | Date | Map<any, any> | Set<any> | ((v?: any) => StringValues);
/** Represents a string manipulation utility with chaining capabilities. */
export interface stringFunction {
(...args: StringValues[]): string;
/**
* Applies recursive transformation to the input values.
* @param args - Input values.
* @returns Transformed string.
*/
recursive: typeof recursiveFn;
/**
* Applies instance-based transformation to the input values.
* @param args - Input values.
* @returns Transformed string.
*/
instanceof: typeof instanceofFn;
/**
* A utility function for managing values based on variant configurations.
*
* This function simplifies the handling of value generation with support for variants, default values, and dynamic overrides.
* @template T - The type of variant keys and their possible values.
* @param {VariantRecord<T>} keys - The configuration object containing:
* - `assign` (optional): A base value to always include.
* - `variants`: An object defining variant keys and their possible values as classes.
* - `defaultVariants` (optional): Default variant values for each variant key.
* @returns {(result?: VariantResult<T>) => string} - A function that takes a `result` object to override default variants
* and generates a class name string.
* @example
* @see {@link https://ilkhoeri.github.io/xuxi/variant Docs}
*/
variant: typeof variant;
}
/**
* Applies recursive transformation to the input values.
* @param args - Input values.
* @returns Transformed string.
*/
declare function recursiveFn(...args: StringValues[]): string;
/**
* Applies instance-based transformation to the input values.
* @param args - Input values.
* @returns Transformed string.
*/
declare function instanceofFn(...args: StringValues[]): string;
/**
* Converts input values into a space-separated string.
* @param args - Input values.
* @returns The formatted string.
*/
declare const string: stringFunction;
export { string, recursiveFn as recursive, instanceofFn as instanceof };