API Reference
Sparkle Design System API / utils/src
utils/src
Section titled “utils/src”Functions
Section titled “Functions”slugify()
Section titled “slugify()”slugify(
str):string
Generates a URL-friendly slug from a string
Parameters
Section titled “Parameters”string
The input string
Returns
Section titled “Returns”string
The slugified string
toKebabCase()
Section titled “toKebabCase()”toKebabCase(
str):string
Converts a string to kebab case
Parameters
Section titled “Parameters”string
The input string
Returns
Section titled “Returns”string
The kebab-cased string
toTitleCase()
Section titled “toTitleCase()”toTitleCase(
str):string
Capitalizes the first letter of each word in a string
Parameters
Section titled “Parameters”string
The input string
Returns
Section titled “Returns”string
The title-cased string
truncate()
Section titled “truncate()”truncate(
str,maxLength):string
Truncates a string to a maximum length with ellipsis
Parameters
Section titled “Parameters”string
The input string
maxLength
Section titled “maxLength”number
The maximum length
Returns
Section titled “Returns”string
The truncated string
useAsync()
Section titled “useAsync()”useAsync<
T>(asyncFn): [boolean,Error|null, (…args) =>Promise<ReturnType<T>>]
Custom hook for handling async operations safely
Type Parameters
Section titled “Type Parameters”T extends (…args) => Promise<any>
Parameters
Section titled “Parameters”asyncFn
Section titled “asyncFn”T
The async function to execute
Returns
Section titled “Returns”[boolean, Error | null, (…args) => Promise<ReturnType<T>>]
Tuple containing loading state, error state, and memoized callback
useClickOutside()
Section titled “useClickOutside()”useClickOutside<
T>(handler):RefObject<T|null>
Custom hook for handling click outside events
Type Parameters
Section titled “Type Parameters”T extends HTMLElement
Parameters
Section titled “Parameters”handler
Section titled “handler”() => void
The callback to execute when clicking outside
Returns
Section titled “Returns”RefObject<T | null>
Ref to attach to the element
useDebounce()
Section titled “useDebounce()”useDebounce<
T>(value,delay):T
Custom hook for debouncing values
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T
The value to debounce
number
The delay in milliseconds
Returns
Section titled “Returns”T
The debounced value