How to use parse-ms - 4 common examples

To help you get started, we’ve selected a few parse-ms 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 rainbow-me / rainbow / src / helpers / time.js View on Github external
export const getMinimalTimeUnitStringForMs = (value = 0, short = true, plural) => {
  const ms = (isObjectLike(value) || isString(value))
    ? convertStringToNumber(value)
    : value;

  const parsedMs = omitBy(
    pick(parseMilliseconds(Number(ms)), MinimalTimeUnitWhitelist),
    isZero,
  );

  const {
    unit: highestResolutionUnit,
    value: highestResolutionValue,
  } = getHighestResolutionUnit(parsedMs);

  const label = buildLocalizedTimeUnitString({
    plural,
    short,
    unit: highestResolutionUnit,
  });

  return `${highestResolutionValue} ${label}`;
};
github dylang / logging / src / formatters / format-color / prefix / get-duration.ts View on Github external
export const getDuration = (level: Level, startTimeSpan: timeSpan.TimeEndFunction = lastCall) => {
    const ms = startTimeSpan();
    const { days, hours, minutes, seconds, milliseconds } = parseMS(ms);
    const daysHoursMinutesAsMinutes = hours * 60 + days * 24 * 60 + minutes;
    const duration =
        daysHoursMinutesAsMinutes > 0
            ? `${daysHoursMinutesAsMinutes} min`
            : `${seconds > 0 ? `${seconds}s` : ''}${
                  logConfig.isDebug
                      ? `${milliseconds < 10 ? ' ' : ''}${milliseconds < 100 ? ' ' : ''}${Math.round(milliseconds)}ms`
                      : ''
              }`;
    lastCall = timeSpan();
    const durationString = ms < (logConfig.isDebug ? 100 : 1000) ? '·' : duration;
    const annotation = level === 'DEBUG' ? 'DEBUG' : '';
    return chalk`{bgMagenta.white ${annotation}}{gray ${rightJustify(
        durationString,
        logConfig.indent - 1 - annotation.length
    )} }`;
github drakang4 / jamak / src / renderer / utils / formatMs.ts View on Github external
export default (
  ms: number,
  options: Options = { timeSeparator: ':', millisecondSepartor: '.' },
): string => {
  const { days, hours, minutes, seconds, milliseconds } = parseMs(ms);

  const fHours = (days * 24 + hours).toString().padStart(2, '0');
  const fMinutes = minutes.toString().padStart(2, '0');
  const fSeconds = seconds.toString().padStart(2, '0');
  const fMilliseconds = milliseconds.toString().padStart(3, '0');

  const formatted = `${fHours}${options.timeSeparator}${fMinutes}${
    options.timeSeparator
  }${fSeconds}${options.millisecondSepartor}${fMilliseconds}`;

  return formatted;
};

parse-ms

Parse milliseconds into an object

MIT
Latest version published 12 months ago

Package Health Score

74 / 100
Full package analysis

Popular parse-ms functions