@squirrel-forge/ui-util
Version:
A collection of utilities, classes, functions and abstracts made for the browser and babel compatible.
14 lines (13 loc) • 318 B
JavaScript
/**
* Leading Zero helper
* @param {number} num - Number to add prefix
* @param {number} length - Expected length
* @return {string} - The prefixed number
*/
export function leadingZeros( num, length = 2 ) {
num = num + '';
while ( num.length < length ) {
num = '0' + num;
}
return num;
}