xuxi
Version:
Dynamically utility for combining different types of values into a single value.
36 lines (35 loc) • 1.61 kB
TypeScript
/**
* Converts a value to a `rem` unit with optional scaling.
* @param {unknown} value - The value to convert. Can be a number, string, or other types.
* @returns {string} The converted value in `rem` units.
*/
export declare const rem: (value: unknown) => string;
/**
* Converts a value to an `em` unit.
* @param {unknown} value - The value to convert. Can be a number, string, or other types.
* @returns {string} The converted value in `em` units.
*/
export declare const em: (value: unknown) => string;
/**
* Converts a value to a pixel (`px`) unit or returns the original value if it cannot be converted.
* @param {unknown} value - The value to convert. Can be a number, string, or other types.
* @returns {string | number} The converted value in `px` units, or `NaN` if conversion fails.
* @example
* px(16); // 16
* px('1rem'); // 16
* px('calc(100% - 50px)'); // 'calc(100% - 50px)'
*/
export declare function px(value: unknown): string | number;
/**
* Creates a converter function for a specific unit (e.g., `rem`, `em`).
* @param units - The target unit for conversion (e.g., `rem`, `em`).
* @param [options] - Options for the converter.
* @param [options.shouldScale=false] - Whether to scale the value during conversion.
* @returns `(value: unknown) => string` - A function that converts a value to the specified unit.
* @example
* const remConverter = createConverter('rem', { shouldScale: true });
* remConverter(16); // '1rem'
*/
export declare function createConverter(units: string, { shouldScale }?: {
shouldScale?: boolean | undefined;
}): (value: unknown) => string;