Arcjet utilities for parsing duration strings
npm install @arcjet/duration@arcjet/duration[Arcjet][arcjet] utilities for parsing duration strings.
- npm package (@arcjet/duration)
- GitHub source code (duration/ in arcjet/arcjet-js)
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.
You should not use this but use one of the many alternatives such as
[vercel/ms][github-vercel-ms].
This package matches our current needs which are likely different from yours.
This package is ESM only.
Install with npm in Node.js:
``sh`
npm install @arcjet/duration
`ts
import { parse } from "@arcjet/duration";
const seconds = parse("1h");
console.log(seconds); // prints 3600
`
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
Derivative work based on [time.ParseDuration][go-parse-duration] fromgolang/go` licensed under [BSD-3.0][go-parse-duration-license] © The Go Authors.
Our work ports to TypeScript.
[arcjet]: https://arcjet.com
[go-parse-duration-license]: https://github.com/golang/go/blob/c18ddc84e/LICENSE
[go-parse-duration]: https://github.com/golang/go/blob/c18ddc84e/src/time/format.go#L1589-L1686
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
[github-vercel-ms]: https://github.com/vercel/ms