UNPKG

545 BJavaScriptView Raw
1export const repeat = (str, times) => (new Array(times + 1)).join(str);
2
3export const pad = (num, maxLength) => repeat(`0`, maxLength - num.toString().length) + num;
4
5export const formatTime = (time) => `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;
6
7// Use performance API if it's available in order to get better precision
8export const timer = (typeof performance !== `undefined` && performance !== null) && typeof performance.now === `function` ? performance : Date;