Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
milli
, fork of ms
Use this package to easily convert various time formats to milliseconds.
It should be compatible with all modern JS runtimes.
It is a fork of the original ms
package, which is abandoned with the latest (canary) version release being almost 3 years old.
import { ms } from "milli"
ms("2 days") // 172800000
ms("1d") // 86400000
ms("10h") // 36000000
ms("2.5 hrs") // 9000000
ms("2h") // 7200000
ms("1m") // 60000
ms("5s") // 5000
ms("1y") // 31557600000
ms("100") // 100
ms("-3 days") // -259200000
ms("-1h") // -3600000
ms("-200") // -200
import { ms } from "milli"
ms(60000) // "1m"
ms(2 * 60000) // "2m"
ms(-3 * 60000) // "-3m"
ms(ms("10 hours")) // "10h"
import { ms } from "milli"
ms(60000, { long: true }) // "1 minute"
ms(2 * 60000, { long: true }) // "2 minutes"
ms(-3 * 60000, { long: true }) // "-3 minutes"
ms(ms("10 hours"), { long: true }) // "10 hours"
ms
, a string with a unit is returned100
for "100"
)If you want to pass a string
variable into ms
, you will need a type coercion to string
:
import { ms } from "milli"
ms("1h" as never)
This is because of the literal types used for DevX, so you get proper completion in your IDE.
You can also use parse
instead, which is a less strict version of passing a string into ms
.
import { parse, format } from "ms"
parse("1h") // 3600000
format(2000) // "2s"
If you want strict type checking for the input value, you can use parseStrict
.
import { parseStrict } from "ms"
parseStrict("1h") // 3600000
function example(s: string) {
return parseStrict(str) // tsc error
}
FAQs
Tiny millisecond conversion utility
We found that milli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.