@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

Package Sidebar

Install

npm i @postman/pretty-ms

Weekly Downloads

1,296

Version

6.1.0

License

MIT

Unpacked Size

12.7 kB

Total Files

5

Last publish

Collaborators

  • saurabh.vartak
  • souris.ash
  • suhas_gaikwad
  • itsaamir
  • darshan.sen
  • yatin1997
  • kartikj
  • saswatds
  • sujayvenaik
  • kratigya
  • shubham.ranjan
  • davidespi
  • numaanashraf
  • shamasis
  • abhijitkane
  • hg07
  • rohan.grover
  • kamalaknn
  • nikithaachhini
  • shreyas.panduranga
  • anuragmewar
  • irena-postman
  • gkorosc-postman
  • raisinten
  • cboornazian
  • pratiksolim
  • arvind.khadri
  • asutosh.sahoo
  • yashkumark
  • sivcansingh
  • timhall
  • bhargavkaranam96
  • ayush.shrivastav
  • bharadwajpoduri7
  • jatin-postman
  • ronak.npm
  • vincentbarth
  • codenirvana
  • tristandenyer
  • sabih.siddiqui
  • shashwat.dixit
  • kriss1897
  • gunjan4542
  • meetdeveloper
  • pawanbana
  • shreyshah
  • barshan23
  • vshingala
  • coditva
  • skrpl
  • jibinmathews7
  • diuda
  • postbot-bitbucket
  • postbot-buildkite
  • dannydainton
  • brandonmcastillo
  • michaelclaus
  • devansh21
  • arshad.ayub
  • sharma.nikhil1997
  • smitshah173
  • atishay-postman
  • saket_ranjan
  • dhawan29
  • arlemi.postman
  • pankajk0791
  • mdamankh
  • dkrape
  • apoorvajain08
  • gbadebo.bello
  • arvind-kalra
  • dip_postman
  • akkeshavan
  • akshay24
  • chetan.waingankar
  • balakrishna.avulapati
  • harsha.dixit
  • saialekhya.yerragunta
  • pranav.singhal
  • amrindersandhu
  • mudit1804
  • prashant-raghu
  • waseem.siddiqui
  • hemendra.kumar
  • bswisher
  • himanshu0809
  • avinashchoudhary
  • gouthamaj
  • postman-maddie
  • tim.beauchamp
  • amrit_vyas
  • ayush.raj
  • mmocarski
  • brent.cromarty
  • rishabh.shukla
  • sandeep.singh
  • abhijeetborole
  • mehul.agrawal
  • vtyson
  • sonymathew
  • hardik286
  • appurvamurawat
  • phani-postman
  • saksham-postman
  • postmanaut
  • chinmayj195
  • harsh_bansal
  • kevinswiber-postman
  • srinivas.kini
  • diegog24
  • jony.cheung.postman
  • rrc083
  • diya.ninan
  • shruti_paranjape
  • utsav.kapoor1994
  • abhishek_s
  • subhash.yadav
  • pankajkumar05
  • prithvi.tharun
  • ashish.gupta1
  • bot.npm.cf.starship
  • meenakshi.dhanani
  • davidtran33
  • salomekbg_postman
  • sterling.chin-postman
  • dhuhindhan.ilango
  • tonygo
  • vaishnavichalla
  • varshini59
  • postman-dakshraj.sharma
  • nishat.sayyed
  • rubencasas
  • amanpostman
  • piyush.r
  • alexander-rubia
  • mudit.joshi
  • postmanian
  • arnaudlauret_postman
  • lorenzo.ambrosi
  • priyambadamadala
  • shikharpostman
  • opi-danihelka
  • karnsharma
  • christina.hastenrathplus1
  • yash-postman
  • roy-himanshu
  • riyasaini
  • arjun.golabhanvi
  • devsharma
  • nidhi_goyal
  • anil.jnanoji
  • ayushman9454
  • shreyansh_post
  • ekansh-01
  • anandh619
  • bot_marketing_engineering
  • anubhav-vats
  • preetham.m
  • elizabeth.fung
  • hasnain.rajan
  • pranavj2000
  • samithjaganath
  • rljohnsn
  • sanketpath
  • atanas.a
  • tilak-patel-postman
  • liteshpatil17
  • tiara.johnson
  • yashishdua
  • jonathanhaviv
  • prathameshh
  • yashja.in
  • piyush.daga
  • bhoomikaduapostman
  • apoorv.gupta.postman
  • laszlogreczi
  • theerthasenan
  • dhinesh.sridhar
  • akinard-pm
  • kylerrenn94
  • patricksevat
  • auddypostman
  • greenblade29
  • joe.fusco
  • harshit.kochar
  • rtlockwood
  • itsaamirpostman
  • jelle.vandevelde
  • adrian.santana
  • rafaeltf
  • pwitcher
  • planetabhi
  • anshitbansal
  • anjali2022
  • dylansd
  • shraddha-arora-postman
  • suman.das
  • dashrath.yadav
  • arsh_13
  • ruben.baraut
  • nitishpostman
  • vivek.nigam
  • kundan.kumar09
  • romulo-nascimento
  • aniketbewal
  • aviralpostman
  • cleverom
  • skatikia
  • vinayak.parashar
  • noah.schwartz
  • soumya.agarwal.postman
  • navneetbhole
  • sumedha.kulkarni
  • razvi07
  • michael.browning
  • samarth.gulati
  • vedkribhu
  • akshay.kulkarni
  • guru.pochineni
  • tphipps
  • joshnedelkapostman
  • jk-postman
  • mcturco
  • adarsh.agrawal
  • chris_pm
  • ian.cundiff
  • nelly_ghazaryan
  • jj.liu
  • gopikrishna.s
  • yashasvi13
  • andrusyshyn
  • eeror
  • saurabh.agarwal
  • cecilytoro
  • smoya
  • akira28
  • saifali_postman
  • pamzani
  • alexgul4enko
  • tree6789
  • shub_postman
  • aman-pm
  • sobtiankit
  • vasudha.madugula
  • dima-postman
  • amaldinesh7
  • rebecca.krosnick
  • nabeel.n
  • postman-web-platform-functional-account
  • ankitesh
  • andrii.lymych
  • ihor.mariichyn
  • prateek.postman
  • arpitsuman601
  • sajal001
  • abhishekpostman
  • harikrishna.postman
  • kevin.corbett
  • eddie.davies
  • shreyansh.goyal
  • nitish-postman
  • basile.barrincio
  • akshat-nema
  • anirudh.ms
  • shubham.shukla-postman
  • carlos.garcia.postman
  • ekam.walia
  • meetsuraj2
  • hoanguyenn
  • yevhenii.stepanov
  • post-abhigyan
  • aravindrajr
  • soriat
  • mxdavis-postman
  • imran.munir
  • grantkingpostman
  • diwakarshukla_postman
  • krishna-postman
  • shruthivee
  • mxdavis
  • abhishek.raj87
  • amaan.khan.postman
  • soumadeep.acharya
  • jedliu-postman
  • abhishek_postman
  • aquibjr-postman
  • abhishek.pawar
  • markgritterpm
  • zubair.lawrence
  • ankit834
  • tch-postman
  • christianareas-postman
  • aki-kusanagi
  • ravi-postman
  • yokawasa
  • steeve.bete
  • shivangibajpai12
  • abhilash-postman
  • raghavendra-postman
  • dmytro.markov
  • alex.morton
  • salilgupta_postman
  • josh-postman
  • shy.alter.postman
  • eric-postman
  • choowon.sir
  • indraneel_postman
  • animesh.jajoo
  • matthew.pinsker
  • yash.gupta007
  • harsh.poddar
  • chowwinstonpostman
  • karan-chawla1
  • praveen.thirumurugan
  • amit-gp
  • aris.villareal
  • khudadad.nomani
  • nimish.agrawal
  • igor-fesenko-postman
  • plgah
  • ayush.chowdhury
  • harsuyash
  • jeroenvdpoll
  • akshay_postman
  • muskaan06
  • parthpverma
  • josephps
  • neha.kaura
  • parthverma
  • tonyzebastian
  • honeynair
  • himanshu.ng056
  • wheatspaghetti
  • akarshts007
  • dylanglennpostman
  • brekk.bockrath
  • rishavbharti-postman
  • kseniia.lukova
  • vishwas-rawat9
  • ssharad
  • jacob.zeba
  • maximilien.takano
  • steven.tan
  • devalswaroop
  • jkonrath
  • nermina