Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
Installations
npm install pretty-ms
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.20.4
NPM Version
10.6.0
Score
99.4
Supply Chain
99.5
Quality
80.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (96.02%)
TypeScript (3.98%)
Developer
sindresorhus
Download Statistics
Total Downloads
820,748,108
Last Day
359,728
Last Week
4,471,560
Last Month
26,149,579
Last Year
251,449,977
GitHub Statistics
1,129 Stars
92 Commits
65 Forks
11 Watching
1 Branches
22 Contributors
Sponsor this package
Package Meta Information
Latest Version
9.2.0
Package Id
pretty-ms@9.2.0
Unpacked Size
13.21 kB
Size
4.06 kB
File Count
5
NPM Version
10.6.0
Node Version
18.20.4
Publised On
15 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
820,748,108
Last day
-69.4%
359,728
Compared to previous day
Last week
-31.1%
4,471,560
Compared to previous week
Last month
-1.8%
26,149,579
Compared to previous month
Last year
40.7%
251,449,977
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
pretty-ms
Convert milliseconds to a human readable string:
1337000000
→15d 11h 23m 20s
Install
1npm install pretty-ms
Usage
1import prettyMilliseconds from 'pretty-ms'; 2 3prettyMilliseconds(1337000000); 4//=> '15d 11h 23m 20s' 5 6prettyMilliseconds(1337000000n); 7//=> '15d 11h 23m 20s' 8 9prettyMilliseconds(1337); 10//=> '1.3s' 11 12prettyMilliseconds(133); 13//=> '133ms' 14 15// `compact` option 16prettyMilliseconds(1337, {compact: true}); 17//=> '1s' 18 19// `verbose` option 20prettyMilliseconds(1335669000, {verbose: true}); 21//=> '15 days 11 hours 1 minute 9 seconds' 22 23// `colonNotation` option 24prettyMilliseconds(95500, {colonNotation: true}); 25//=> '1:35.5' 26 27// `formatSubMilliseconds` option 28prettyMilliseconds(100.400080, {formatSubMilliseconds: true}) 29//=> '100ms 400µs 80ns' 30 31// Can be useful for time durations 32prettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5)) 33//=> '35m'
API
prettyMilliseconds(milliseconds, options?)
milliseconds
Type: number | bigint
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: 13s
→ 13.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 10m
→ 1h
.
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 45s
→ 5 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 45s
→ 5:01:45
. Always shows time in at least minutes: 1s
→ 0: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
hideYear
Type: boolean
Default: false
Hides the year and shows the hidden year additionally as days (365 per year): 1y 3d 5h 1m 45s
→ 368d 5h 1m 45s
.
hideYearAndDays
Type: boolean
Default: false
Hides the year and days and shows the hidden values additionally as hours: 1y 3d 5h 1m 45s
→ 8837h 1m 45s
.
hideSeconds
Type: boolean
Default: false
Hides the seconds: 1y 3d 5h 1m 45s
→ 1y 3d 5h 1m
.
Related
- pretty-ms-cli - CLI for this module
- parse-ms - Parse milliseconds into an object
- to-milliseconds - Convert an object of time properties to milliseconds
- pretty-bytes - Convert bytes to a human readable string
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 16/30 approved changesets -- score normalized to 5
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/pretty-ms/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/pretty-ms/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 16 are checked with a SAST tool
Score
4.7
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to pretty-ms
@types/pretty-ms
TypeScript definitions for pretty-ms
pretty-ms-i18n
Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
pretty-print-ms
Convert milliseconds to something easier on the eyes
@postman/pretty-ms
Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`