UNPKG

date-fns

Version:

Modern JavaScript date utility library

6 lines (5 loc) 194 B
export function addLeadingZeros(number, targetLength) { const sign = number < 0 ? "-" : ""; const output = Math.abs(number).toString().padStart(targetLength, "0"); return sign + output; }