Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

duration-pretty

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duration-pretty

A pure JavaScript library that parses duration time length to format display

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 31 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc