@arcjet/duration
Arcjet utilities for parsing duration strings.
What is this?
This is an internal utility that exists so our users can pass meaningful
duration strings such as 1h
instead of having to manually calculate seconds
or milliseconds.
We turned the Go [ParseDuration
][go-parser] into TypeScript so that we have
the exact same functionality in both languages.
When should I use this?
You should not use this but use one of the many alternatives such as
vercel/ms
.
This package matches our current needs which are likely different from yours.
Install
This package is ESM only. Install with npm in Node.js:
npm install @arcjet/duration
Example
import { parse } from "@arcjet/duration";
const seconds = parse("1h");
console.log(seconds); // prints 3600
License
Apache License, Version 2.0 © Arcjet Labs, Inc.
Derivative work based on time.ParseDuration
from
golang/go
licensed under BSD-3.0 © The Go Authors.
Our work ports to TypeScript.