@postman/pretty-ms
TypeScript icon, indicating that this package has built-in type declarations

6.1.0 • Public • Published

pretty-ms Build Status

Convert milliseconds to a human readable string: 133700000015d 11h 23m 20s

Install

$ npm install pretty-ms

Usage

const prettyMilliseconds = require('pretty-ms');

prettyMilliseconds(1337000000);
//=> '15d 11h 23m 20s'

prettyMilliseconds(1337);
//=> '1.3s'

prettyMilliseconds(133);
//=> '133ms'

// `compact` option
prettyMilliseconds(1337, {compact: true});
//=> '1s'

// `verbose` option
prettyMilliseconds(1335669000, {verbose: true});
//=> '15 days 11 hours 1 minute 9 seconds'

// `colonNotation` option
prettyMilliseconds(95500, {colonNotation: true});
//=> '1:35.5'

// `padUnits` option
prettyMilliseconds(1337000000, {padUnits: true});
//=> '15 d 11 h 23 m 20 s'

// `formatSubMilliseconds` option
prettyMilliseconds(100.400080, {formatSubMilliseconds: true})
//=> '100ms 400µs 80ns'

// Can be useful for time durations
prettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
//=> '35m'

API

prettyMilliseconds(milliseconds, options?)

milliseconds

Type: number

Milliseconds to humanize.

options

Type: object

secondsDecimalDigits

Type: number
Default: 1

Number of digits to appear after the seconds decimal point.

millisecondsDecimalDigits

Type: number
Default: 0

Number of digits to appear after the milliseconds decimal point.

Useful in combination with process.hrtime().

keepDecimalsOnWholeSeconds

Type: boolean
Default: false

Keep milliseconds on whole seconds: 13s13.0s.

Useful when you are showing a number of seconds spent on an operation and don't want the width of the output to change when hitting a whole number.

compact

Type: boolean
Default: false

Only show the first unit: 1h 10m1h.

Also ensures that millisecondsDecimalDigits and secondsDecimalDigits are both set to 0.

unitCount

Type: number
Default: Infinity

Number of units to show. Setting compact to true overrides this option.

verbose

Type: boolean
Default: false

Use full-length units: 5h 1m 45s5 hours 1 minute 45 seconds

separateMilliseconds

Type: boolean
Default: false

Show milliseconds separately. This means they won't be included in the decimal part of the seconds.

formatSubMilliseconds

Type: boolean
Default: false

Show microseconds and nanoseconds.

colonNotation

Type: boolean
Default: false

Display time using colon notation: 5h 1m 45s5:01:45. Always shows time in at least minutes: 1s0:01

Useful when you want to display time without the time units, similar to a digital watch.

Setting colonNotation to true overrides the following options to false:

  • compact
  • formatSubMilliseconds
  • separateMilliseconds
  • verbose
padUnits

Type: boolean
Default: false

Setting padUnits to true will show the time with a space before the unit 5h 1m 45s5 h 1 m 45 s.

Related

/@postman/pretty-ms/

    Package Sidebar

    Install

    npm i @postman/pretty-ms

    Weekly Downloads

    584

    Version

    6.1.0

    License

    MIT

    Unpacked Size

    12.7 kB

    Total Files

    5

    Last publish

    Collaborators

    • abhishek.pawar
    • abhishek.raj87
    • eddie.davies
    • shubham.shukla-postman
    • basile.barrincio
    • hoanguyenn
    • shreyansh.goyal
    • harikrishna.postman
    • sajal001
    • michaelhudelsonpostman
    • dima-postman
    • ihor.mariichyn
    • andrii.lymych
    • michael.browning
    • yevhenii.stepanov
    • arpit.sahu
    • akshat-nema
    • postman-web-platform-functional-account
    • ian.cundiff
    • rebecca.krosnick
    • soriat
    • meetsuraj2
    • nitish-postman
    • shub_postman
    • joshnedelkapostman
    • kevin.corbett
    • carlos.garcia.postman
    • anirudh.ms
    • akira28
    • cecilytoro
    • sumedha.kulkarni
    • suman.das
    • yashishdua
    • rljohnsn
    • salomekbg_postman
    • vtyson
    • indraneel_postman
    • grantkingpostman
    • shivangibajpai12
    • abhilash-postman
    • raghavendra-postman
    • ravi-postman
    • jedliu-postman
    • amaan.khan.postman
    • diwakarshukla_postman
    • imran.munir
    • markgritterpm
    • shruthivee
    • rajaswa
    • aki-kusanagi
    • yokawasa
    • ankit834
    • saurabh.agarwal
    • itsaamirpostman
    • postmanaut
    • noah.schwartz
    • dkrape
    • saurabh.vartak
    • wheatspaghetti
    • himanshu.ng056
    • honeynair
    • tonyzebastian
    • kasey.seo
    • parthverma
    • neha.kaura
    • josephps
    • parthpverma
    • muskaan06
    • sapnanayak
    • akshay_postman
    • jeroenvdpoll
    • harsuyash
    • ayush.chowdhury
    • plgah
    • sobtiankit
    • aravind-arun
    • smoya
    • mcturco
    • skatikia
    • dhinesh.sridhar
    • aman-pm
    • alexgul4enko
    • pamzani
    • fran.mendez
    • jonaslagoni
    • guru.pochineni
    • navneetbhole
    • piyush.daga
    • himanshu.vishwakarma
    • shraddha-arora-postman
    • anshitbansal
    • prathameshh
    • nitishpostman
    • yashja.in
    • varshini59
    • aviralpostman
    • theerthasenan
    • shikharpostman
    • amanpostman
    • greenblade29
    • anuragmewar
    • chris_pm
    • jk-postman
    • tphipps
    • akshay.kulkarni
    • vedkribhu
    • samarth.gulati
    • razvi07
    • cleverom
    • planetabhi
    • tiara.johnson
    • joe.fusco
    • jonathanhaviv
    • mudit.joshi
    • piyush.r
    • anjali2022
    • gkorosc-postman
    • raisinten
    • itsaamir
    • vinayak.parashar
    • rafaeltf
    • apoorv.gupta.postman
    • adrian.santana
    • kylerrenn94
    • jelle.vandevelde
    • atanas.a
    • samithjaganath
    • pranavj2000
    • pwitcher
    • anandh619
    • diegog24
    • atchyut.pulavarthi
    • kevinswiber-postman
    • sanketpath
    • opi-danihelka
    • arvind.khadri
    • cboornazian
    • irena-postman
    • rohan.grover
    • vincentbarth
    • aniketbewal
    • romulo-nascimento
    • ruben.baraut
    • arsh_13
    • tapanchudasama
    • akash.rajpurohit_postman
    • harsh.postman
    • rtlockwood
    • harshit.kochar
    • auddypostman
    • patricksevat
    • akinard-pm
    • ayush.jain
    • laszlogreczi
    • bhoomikaduapostman
    • roy-himanshu
    • nidhi_goyal
    • alexander-rubia
    • arjun.golabhanvi
    • anil.jnanoji
    • gbadebo.bello
    • ravi.prasad
    • jatin-postman
    • bharadwajpoduri7
    • liteshpatil17
    • tilak-patel-postman
    • hasnain.rajan
    • elizabeth.fung
    • manavbharambe
    • preetham.m
    • dhuhindhan.ilango
    • nishat.sayyed
    • rubencasas
    • sterling.chin-postman
    • anubhav-vats
    • adityabaradwaj
    • timhall
    • asutosh.sahoo
    • prasant.patel
    • bot_marketing_engineering
    • shreyansh_post
    • vaishnavichalla
    • lorenzo.ambrosi
    • arnaudlauret_postman
    • christina.hastenrathplus1
    • postman-dakshraj.sharma
    • ekansh-01
    • devsharma
    • ayushman9454
    • tonygo
    • postmanian
    • davidtran33
    • rutvik_gs
    • dsanders11
    • akkeshavan
    • rishabh.shukla
    • riyasaini
    • yash-postman
    • karnsharma
    • priyambadamadala
    • gaurav.rakheja
    • suhas_gaikwad
    • umeshp7
    • darshan.sen
    • yatin1997
    • kartikj
    • saswatds
    • sujayvenaik
    • kratigya
    • shubham.ranjan
    • davidespi
    • numaanashraf
    • shamasis
    • godfrzero
    • abhijitkane
    • kunagpal
    • hg07
    • kamalaknn
    • nikithaachhini
    • shreyas.panduranga
    • pratiksolim
    • sivcansingh
    • bhargavkaranam96
    • ronak.npm
    • codenirvana
    • tristandenyer
    • sabih.siddiqui
    • shashwat.dixit
    • kriss1897
    • gunjan4542
    • meetdeveloper
    • pawanbana
    • shreyshah
    • vshingala
    • barshan23
    • coditva
    • skrpl
    • jibinmathews7
    • diuda
    • postbot-bitbucket
    • postbot-buildkite
    • dannydainton
    • brandonmcastillo
    • michaelclaus
    • devansh21
    • arshad.ayub
    • sharma.nikhil1997
    • smitshah173
    • atishay-postman
    • saket_ranjan
    • dhawan29
    • arlemi.postman
    • akshaytate01
    • pankajk0791
    • mdamankh
    • apoorvajain08
    • james-postman
    • arvind-kalra
    • diptarag
    • dip_postman
    • akshay24
    • chetan.waingankar
    • axelonet
    • balakrishna.avulapati
    • harsha.dixit
    • saialekhya.yerragunta
    • pranav.singhal
    • amrindersandhu
    • deepanshurana
    • mudit1804
    • prashant-raghu
    • waseem.siddiqui
    • hemendra.kumar
    • bswisher
    • himanshu0809
    • avinashchoudhary
    • gouthamaj
    • shubham.joshi
    • ankitsaini
    • dev-pawankumar
    • tim.beauchamp
    • iamnishantgarg
    • amrit_vyas
    • ayush.raj
    • himanshu.s
    • brent.cromarty
    • sandeep.singh
    • abhijeetborole
    • mehul.agrawal
    • sonymathew
    • hardik286
    • appurvamurawat
    • poojat
    • phani-postman
    • chinmayj195
    • harsh_bansal
    • srinivas.kini
    • jony.cheung.postman
    • rrc083
    • diya.ninan
    • shruti_paranjape
    • utsav.kapoor1994
    • abhishek_s
    • subhash.yadav
    • pankajkumar05
    • prithvi.tharun
    • ashish.gupta1
    • joshuawise_postman
    • bot.npm.cf.starship
    • divy.khare
    • meenakshi.dhanani