add prefixZero utility

This commit is contained in:
Elijah Duffy
2025-07-22 15:38:58 -07:00
parent 647235e1fe
commit d4935b6e7c
2 changed files with 19 additions and 2 deletions

View File

@@ -32,7 +32,8 @@ export {
getLabel,
getValue,
defaultIconProps,
capitalizeFirstLetter
capitalizeFirstLetter,
prefixZero
} from './util';
export {
type ToolbarToggleState,

View File

@@ -88,8 +88,24 @@ export function targetMust<T extends HTMLElement>(event: Event): T {
return target;
}
/** capitalizeFirstLetter capitalizes the first letter of a string */
/**
* capitalizeFirstLetter capitalizes the first letter of a string
* @param str The string to capitalize
* @returns The string with the first letter capitalized and all others lowercase
*/
export const capitalizeFirstLetter = (str: string): string => {
const lower = str.toLowerCase();
return lower.charAt(0).toUpperCase() + lower.slice(1);
};
/**
* prefixZero adds a leading zero to the string if it is less than 10
* @param str The string to prefix
* @returns The string with a leading zero if it was only 1 digit long
*/
export const prefixZero = (str: string): string => {
if (str.length === 1) {
return '0' + str;
}
return str;
};