Detalhes do pacote

format-duration

ungoldman104.8kISC3.0.2

Convert a number in milliseconds to a standard duration string.

display, duration, format, hh:mm:ss

readme (leia-me)

stopwatch # format-duration Convert a number in milliseconds to a standard duration string. [![npm][npm-image]][npm-url] [![build][build-image]][build-url] [![downloads][downloads-image]][npm-url] [npm-image]: https://img.shields.io/npm/v/format-duration.svg [npm-url]: https://www.npmjs.com/package/format-duration [build-image]: https://github.com/ungoldman/format-duration/actions/workflows/tests.yml/badge.svg [build-url]: https://github.com/ungoldman/format-duration/actions/workflows/tests.yml [downloads-image]: https://img.shields.io/npm/dm/format-duration.svg

Install

npm install format-duration

Usage

const format = require('format-duration')

// anything under a second is rounded down to zero
format(999) // '0:00'

// 1000 milliseconds is a second
format(1000) // '0:01'

// 1999 rounds down to 0:01
format(1000 * 2 - 1) // '0:01'

// 60 seconds is a minute
format(1000 * 60) // '1:00'

// 59 seconds looks like this
format(1000 * 60 - 1) // '0:59'

// 60 minutes is an hour
format(1000 * 60 * 60) // '1:00:00'

// 59 minutes and 59 seconds looks like this
format(1000 * 60 * 60 - 1) // '59:59'

// 24 hours is a day
format(1000 * 60 * 60 * 24) // '1:00:00:00'

// 23 hours, 59 minutes, and 59 seconds looks like this
format(1000 * 60 * 60 * 24 - 1) // '23:59:59'

// 365 days looks like this (not bothering with years)
format(1000 * 60 * 60 * 24 * 365) // '365:00:00:00'

// anything under a second is rounded down to zero
format(-999) // '0:00'

// 1000 milliseconds is a second
format(-1000) // '-0:01'

// 365 days looks like this (not bothering with years)
format(-1000 * 60 * 60 * 24 * 365) // '-365:00:00:00'

// with `leading` option, formatting looks like this
format(1000 * 60, { leading: true }) // '01:00'
format(1000 * 60 - 1, { leading: true }) // '00:59'
format(1000 * 60 * 60, { leading: true }) // '01:00:00'

// with `ms` option, formatting looks like this
format(999, { ms: true }) // '0:00.999'
format(1000 * 60, { ms: true }) // '1:00.000'
format(1000 * 60 * 60 * 24 - 1, { ms: true }) // '23:59:59.999'

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

Stopwatch image is from emojidex.

changelog (log de mudanças)

format-duration change log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

3.0.2 - 2023-01-17

Fixes

  • Move FormatDurationOptions under namespace formatDuration (#20) - thanks @sebinemeth

3.0.1 - 2022-12-18

Fixes

  • Fix typo to load types properly (#18) - thanks @petrbela

Misc

  • Fix repo URL in package.json

3.0.0 - 2022-12-12

Breaking

  • Drop support for Node 12

Features

  • New option: ms (show milliseconds) (#17)
  • TypeScript: Export FormatDurationOptions (#15)

Misc

  • CI: add Node 18 to test matrix

2.0.0 - 2022-03-16

Breaking Changes

  • Drop support for node 8 & 10 (now only supporting node LTS: 12, 14, 16).

Misc

  • No dependencies! Code from parse-ms and add-zero has been consolidated for easier maintenance and smaller module footprint.
  • Repo ownership transfer (hypermodules -> ungoldman). Same maintainers, new URL.

1.4.0 - 2021-08-04

Features

  • add type definitions (#5) - thanks @guytepper

1.3.1 - 2018-10-11

Fixes

  • update URLs to reflect ownership transfer to hypermodules

1.3.0 - 2018-10-11

Features

  • add option for leading zeros (hours, minutes, seconds) (#3) - thanks @Deseteral

1.2.0 - 2018-07-24

Features

  • convert to es5 (#2)

1.1.0 - 2018-02-23

Features

  • add support for negative durations (#1) - thanks @lrn2prgrm

1.0.1 - 2018-02-23

Chores

  • update license
  • update contributing guidelines
  • update author field
  • add downloads badge to readme

1.0.0 - 2016-08-26

  • initial release