Installations
npm install enhanced-ms
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
22.11.0
NPM Version
10.9.0
Releases
Unable to fetch releases
Contributors
Languages
TypeScript (79.2%)
JavaScript (20.41%)
Shell (0.39%)
Developer
Download Statistics
Total Downloads
188,318
Last Day
1,242
Last Week
6,665
Last Month
27,619
Last Year
152,107
GitHub Statistics
13 Stars
67 Commits
5 Forks
1 Watching
2 Branches
3 Contributors
Bundle Size
10.51 kB
Minified
3.48 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.1.0
Package Id
enhanced-ms@3.1.0
Unpacked Size
160.45 kB
Size
32.27 kB
File Count
8
NPM Version
10.9.0
Node Version
22.11.0
Publised On
10 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
188,318
Last day
10.5%
1,242
Compared to previous day
Last week
-5.2%
6,665
Compared to previous week
Last month
22.4%
27,619
Compared to previous month
Last year
462%
152,107
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
npm install enhanced-ms
🤔 About
enhanced-ms
is a simple, zero dependencies, module that lets you easily convert milliseconds to a readable format and vice versa. It is an enhanced version of the original ms
module, with support for mutliple time-frames, localisation and operators!
Features
- Localisation support
- Convert from milliseconds to time-frame
- Convert from time-frame to milliseconds
- Operator in time-frame support
- Customisable outputs
📩 Installation
1npm install enhanced-ms 2yarn add enhanced-ms 3pnpm add enhanced-ms
1const ms = require('enhanced-ms'); 2// OR 3import ms from 'enhanced-ms';
🧭 Comparison
As mentioned previously, enhanced-ms
is inspired by the original ms
module, so how does it compare to it?
pretty-ms
is another conversion module.
1import oms from 'ms'; 2import pms from 'pretty-ms'; 3import ems from 'enhanced-ms'; 4 5// Convert a single written time-frame to milliseconds 6oms('1m'); // -> 60000 7pms('1m'); // -> TypeError: Expected a finite number 8ems('1m'); // -> 60000 9 10// Convert multiple written time-frame measurements to milliseconds 11oms('1m 30s'); // -> undefined 12pms('1m 30s'); // -> TypeError: Expected a finite number 13ems('1m 30s'); // -> 90000 14 15// Convert milliseconds to time-frame with long option 16oms(198349884, { long: true }); // -> '2 days' 17pms(198349884, { verbose: true }); // -> '2 days 7 hours 5 minutes 49.8 seconds' 18ems(198349884); // -> '2 days 7 hours 5 minutes and 49 seconds' 19 20// Convert milliseconds to time-frame 21oms(3456787654); // -> '40d' 22pms(3456787654); // -> '40d 13m 7.6s' 23ems(3456787654, { shortFormat: true }); // -> '40d 13m 7s'
🌐 Languages
The currently supported languages include:
Language | Key |
---|---|
English | en |
German | de |
Māori | mi |
Russian | ru |
You can help by adding support for more languages.
Make a pull request here.
🍕 API
Conversion
When the first parameter is a string, the module will parse it and convert it into a time-frame in milliseconds.
If no time units were found within the string, null
will be returned.
1function ms(input: string, value2?: LanguageKey | Options, options?: Options): number | null;
However when the first parameter is a number it will be converted into a time-frame string.
If no time units were outputted (for example then the inputted number is less than 1000
and includeMs
is false
), null
will be returned.
1function ms(input: number, value2?: LanguageKey | Options, options?: Options): string | null;
For both of the above overloads, the second parameter can either be the language key, or the options object. The third and final parameter is only ever used if a language key is supplied.
Globals
If you prefer that the results always include in a different language, or if you want milliseconds to always be included, this is for you.
The following will overwrite the modules defaults, you can find some examples further down.
1function ms(language: LanguageKey): typeof ms;
1function ms(options: Options): typeof ms;
Both of these will return the ms
function, which will allow you to do:
1const ms = require('enhanced-ms')('en')({ roundUp: true });
TypeScript Interfaces
For LanguageKey
, navigate to 🌐 Languages.
1interface Options { 2 /** Include input in the output. */ 3 includeMs?: boolean; 4 /** Include sub input in the output. */ 5 includeSubMs?: boolean; 6 /** Insert commas inbetween each unit. */ 7 insertCommas?: boolean; 8 /** Round the result to the highest unit. */ 9 roundUp?: boolean; 10 /** Use the short names of measurements. */ 11 shortFormat?: boolean; 12}
🌀 Examples
Time-frame to Milliseconds
1ms('1 day') === 86400000; 2ms('3m 34s') === 214000; 3ms(ms('1d - 4h')) === '20 hours'; 4ms(ms('7d / 7')) === '1 day'; 5ms('1 meneti', 'mi') === 60000;
Milliseconds to Time-frame
1ms(123456) === '2 minutes and 3 seconds'; 2 3ms(123456, { shortFormat: true }) === '2m 3s'; 4ms(123456, { roundUp: true }) === '2 minutes'; 5ms(123456, { includeMs: true }) === '2 minutes 3 seconds and 456 milliseconds'; 6ms(123.456, { includeSubMs: true }) === '123 milliseconds and 456 microseconds'; 7 8ms(123456, 'mi') === '2 meneti me te 3 hēkona'; 9ms(123456, 'mi', { roundUp: true }) === '2 meneti'; 10ms(123.456, 'mi', { includeSubMs: true }) === '123 manomano hēkona me te 456 moroiti hēkona';
Set Global Options
1ms(1234567) === '20 minutes and 34 seconds'; 2ms({ roundUp: true }) instanceof Function; 3ms(1234567) === '21 minutes';
Set Global Language
1ms(1000) === '1 second'; 2ms('mi') instanceof Function; 3ms(1000) === '1 hēkona';
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 2/23 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/continuous-integration.yml:1
- Warn: no topLevel permission defined: .github/workflows/label-sync.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/continuous-integration.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/apteryxxyz/enhanced-ms/continuous-integration.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/apteryxxyz/enhanced-ms/continuous-integration.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/continuous-integration.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/apteryxxyz/enhanced-ms/continuous-integration.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/label-sync.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/apteryxxyz/enhanced-ms/label-sync.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/label-sync.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/apteryxxyz/enhanced-ms/label-sync.yml/main?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
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 10 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2025-01-27
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 More