@arcjet/duration
v1.0.0-alpha.34
Published
Arcjet utilities for parsing duration strings
Downloads
30,202
Readme
@arcjet/duration
Arcjet utilities for parsing duration strings.
Installation
npm install -S @arcjet/duration
Example
import { parse } from "@arcjet/duration";
const seconds = parse("1h");
console.log(seconds); // prints 3600
Implementation
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.
License
Licensed under the Apache License, Version 2.0.