@snups/rjsf-utils
Version:
Utility functions for @snups/rjsf-core
14 lines (13 loc) • 492 B
text/typescript
/** Returns a string representation of the `num` that is padded with leading "0"s if necessary
*
* @param num - The number to pad
* @param width - The width of the string at which no lead padding is necessary
* @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
*/
export default function pad(num: number, width: number) {
let s = String(num);
while (s.length < width) {
s = '0' + s;
}
return s;
}