0.1.1 • Published 3 years ago

duration-pretty v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

Duration Pretty

Build Status GitHub license npm version

The plugin is a pure JavaScript library that parses duration time length to format display.

Getting Started

Installation

npm install --save duration-pretty

Documentation

The duration(timestamp, type) get two parameters: timestamp && type.

timestamp: number
type: seconds | milliseconds

Format duration time using a template string to format().

var { duration } = require('duration-pretty')

duration(7380, 'seconds').format('H:mm') // "2:03"
duration(36610000333, 'milliseconds').format('Y:MM:DD:HH:mm:ss:SSS') // "1:01:28:17:26:40:333"

or using ES6 Module:

import { duration } from 'duration-pretty'

duration(7380, 'seconds').format('H:mm') // "2:03"

The template string is parsed for universal token characters, which are replaced with the duration's value for each unit type. The tokens are:

years: Y
months: M | MM
days: D | DD
hours: H | HH
minutes: m | mm
seconds: s | ss
milliseconds: SSS

Escape token characters within the template string using [].

duration(3661, 'seconds').format('H [[H]], m [[m] countdown]') // "1 [H], 1 [m countdown]"

Tests

You can find all cases in files:/test/*.spec.js, And testing Using below script.

npm run test
0.1.1

3 years ago

0.1.0

3 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago