@pillar-ui/utils
Version:
A collection of utility functions and tools to assist with common tasks and improve the efficiency of web development. These utilities are carefully crafted to enhance productivity and streamline the development process.
96 lines (83 loc) • 3.63 kB
text/typescript
/**
* Clamps a value between a minimum and maximum range.
* @param {number} value - The value to clamp.
* @param {[number, number]} range - The minimum and maximum values defining the range.
* @returns {number} - The clamped value.
*/
declare function clamp(value: number, [min, max]: [number, number]): number;
/**
* Composes multiple event handlers into a single handler.
*
* @template T - The type of the event object.
* @param {...((event: T) => void)} handlers - The event handlers to compose.
* @returns {(event: T) => void} - The composed event handler.
*/
declare const composeEventHandlers: (...handlers: ((event: Event) => void)[]) => (event: Event) => void;
/**
* Formats a price value as a currency string using the specified locale and currency.
* @param {number} price - The price value to format.
* @param {string} [locale='en-US'] - The locale to use for formatting the currency.
* @param {string} [currency='USD'] - The currency code to use for formatting the price.
* @returns {string} - The formatted price as a currency string.
*/
declare const formatPrice: (price: number, locale?: string, currency?: string) => string;
declare function getURLParameters(url: string): {
[key: string]: string | string[];
};
/**
* Checks if a number is within a specified range (inclusive).
* @param {object} params - The parameters for the range check.
* @param {number} params.value - The number to check.
* @param {number} params.min - The minimum value of the range.
* @param {number} params.max - The maximum value of the range.
* @returns {boolean} Returns true if the number is within the range, false otherwise.
*/
interface Range {
value: number;
min: number;
max: number;
}
declare const isInRange: ({ value, min, max }: Range) => boolean;
declare const isLeapYear: (y: number) => boolean;
/**
* Checks if a string is a valid date.
* @param {string} dateString - The string to check.
* @returns {boolean} - Returns true if the string is a valid date, false otherwise.
*/
declare function isValidDate(dateString: Date | string): boolean;
/**
* Checks if a given locale is a valid locale string.
*
* @param {string} locale - The locale string to validate.
* @returns {boolean} Returns true if the locale is valid, false otherwise.
*
* @example
* isValidLocale('en-US'); // Output: true
* isValidLocale('fr-FR'); // Output: true
* isValidLocale('invalid'); // Output: false
*/
declare function isValidLocale(locale: string): boolean;
interface RandomNumber {
min?: number;
max: number;
rounded?: boolean;
}
/**
* Generates a random number within a specified range.
* @param {{ min?: number, max: number, rounded?: boolean }} options - The options object.
* @param {number} options.min - The minimum value of the range (inclusive). Default: 0.
* @param {number} options.max - The maximum value of the range (exclusive).
* @param {boolean} options.rounded - Whether to round the generated number to the nearest integer. Default: false.
* @returns {number} - The generated random number.
*/
declare const randomNumber: ({ min, max, rounded }: RandomNumber) => number;
declare function toCapitalize(str: string): string;
declare const toKebabCase: (str: string) => string;
/**
* Return a slugified copy of a string.
*
* @param {string} str The string to be slugified
* @return {string} The slugified string.
*/
declare const toSlug: (str: string) => string;
export { clamp, composeEventHandlers, formatPrice, getURLParameters, isInRange, isLeapYear, isValidDate, isValidLocale, randomNumber, toCapitalize, toKebabCase, toSlug };