Skip to content

API Reference

Sparkle Design System API


Sparkle Design System API / utils/src

slugify(str): string

Generates a URL-friendly slug from a string

string

The input string

string

The slugified string


toKebabCase(str): string

Converts a string to kebab case

string

The input string

string

The kebab-cased string


toTitleCase(str): string

Capitalizes the first letter of each word in a string

string

The input string

string

The title-cased string


truncate(str, maxLength): string

Truncates a string to a maximum length with ellipsis

string

The input string

number

The maximum length

string

The truncated string


useAsync<T>(asyncFn): [boolean, Error | null, (…args) => Promise<ReturnType<T>>]

Custom hook for handling async operations safely

T extends (…args) => Promise<any>

T

The async function to execute

[boolean, Error | null, (…args) => Promise<ReturnType<T>>]

Tuple containing loading state, error state, and memoized callback


useClickOutside<T>(handler): RefObject<T | null>

Custom hook for handling click outside events

T extends HTMLElement

() => void

The callback to execute when clicking outside

RefObject<T | null>

Ref to attach to the element


useDebounce<T>(value, delay): T

Custom hook for debouncing values

T

T

The value to debounce

number

The delay in milliseconds

T

The debounced value