Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.84 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.84 KB
Arcjet Logo

@arcjet/duration

npm badge

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.