add prefixZero utility
This commit is contained in:
@@ -32,7 +32,8 @@ export {
|
||||
getLabel,
|
||||
getValue,
|
||||
defaultIconProps,
|
||||
capitalizeFirstLetter
|
||||
capitalizeFirstLetter,
|
||||
prefixZero
|
||||
} from './util';
|
||||
export {
|
||||
type ToolbarToggleState,
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user