How to use the @boost/common.formatMs function in @boost/common

To help you get started, we’ve selected a few @boost/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github milesj / boost / packages / core / src / outputs / ProgressOutput.ts View on Github external
// Mark as final for convenience
    if (current >= total) {
      this.markFinal();
    }

    // Compile our template
    const progress = Math.min(Math.max(current / total, 0), 1);
    const percent = Math.floor(progress * 100);
    const elapsed = Date.now() - this.startTime;
    const estimated = percent === 100 ? 0 : elapsed * (total / current - 1);
    const rate = current / (elapsed / 1000);
    const partialTemplate = template
      .replace('{progress}', `${current}/${total}`)
      .replace('{current}', String(current))
      .replace('{elapsed}', formatMs(elapsed))
      .replace('{estimated}', formatMs(estimated))
      .replace('{percent}', `${percent.toFixed(0)}%`)
      .replace('{rate}', String(rate.toFixed(2)))
      .replace('{total}', String(total));

    // Render the progress bar
    const currentWidth = partialTemplate.replace('{bar}', '').length;
    const remainingWidth = screen.size().columns - currentWidth;
    const completed = Math.round(remainingWidth * progress);
    const [complete, incomplete] = STYLES[styleName];
    let bar = [
      complete.repeat(Math.max(0, completed)),
      (transparent ? ' ' : incomplete).repeat(Math.max(0, remainingWidth - completed)),
    ].join('');

    if (color) {
      if (percent >= 90) {
github milesj / boost / packages / core / src / outputs / ProgressOutput.ts View on Github external
// Mark as final for convenience
    if (current >= total) {
      this.markFinal();
    }

    // Compile our template
    const progress = Math.min(Math.max(current / total, 0), 1);
    const percent = Math.floor(progress * 100);
    const elapsed = Date.now() - this.startTime;
    const estimated = percent === 100 ? 0 : elapsed * (total / current - 1);
    const rate = current / (elapsed / 1000);
    const partialTemplate = template
      .replace('{progress}', `${current}/${total}`)
      .replace('{current}', String(current))
      .replace('{elapsed}', formatMs(elapsed))
      .replace('{estimated}', formatMs(estimated))
      .replace('{percent}', `${percent.toFixed(0)}%`)
      .replace('{rate}', String(rate.toFixed(2)))
      .replace('{total}', String(total));

    // Render the progress bar
    const currentWidth = partialTemplate.replace('{bar}', '').length;
    const remainingWidth = screen.size().columns - currentWidth;
    const completed = Math.round(remainingWidth * progress);
    const [complete, incomplete] = STYLES[styleName];
    let bar = [
      complete.repeat(Math.max(0, completed)),
      (transparent ? ' ' : incomplete).repeat(Math.max(0, remainingWidth - completed)),
    ].join('');

    if (color) {
github milesj / boost / packages / core / src / Reporter.ts View on Github external
getElapsedTime(start: number, stop: number = 0, highlight: boolean = true): string {
    const time = (stop || Date.now()) - start;
    const isSlow = time > SLOW_THRESHOLD;
    const elapsed = formatMs(time);

    return isSlow && highlight ? this.style(elapsed, 'failure') : elapsed;
  }
github milesj / boost / packages / core / src / Reporter.ts View on Github external
getElapsedTime(start: number, stop: number = 0, highlight: boolean = true): string {
    const time = (stop || Date.now()) - start;
    const isSlow = time > SLOW_THRESHOLD;
    const elapsed = formatMs(time);

    return isSlow && highlight ? this.style(elapsed, 'failure') : elapsed;
  }