Arcjet utilities for parsing duration strings.
npm install -S @arcjet/duration
import { parse } from "@arcjet/duration";
const seconds = parse("1h");
console.log(seconds); // prints 3600
The implementation of this library is based on the ParseDuration function in the Go stdlib. Originally licensed BSD-3.0 with the license included in our source code.
We've chosen the approach of porting this to TypeScript because our protocol operates exclusively on unsigned 32-bit integers representing seconds. However, we don't want to require our SDK users to manually calculate seconds. By providing this utility, our SDK can accept duration strings and numbers while normalizing the values for our protocol.
Licensed under the Apache License, Version 2.0.