# @arcjet/duration

> Arcjet utilities for parsing duration strings

Latest version **1.14.1** (published 2026-10-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @arcjet/duration
pnpm add @arcjet/duration
yarn add @arcjet/duration
bun add @arcjet/duration
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2026-10-07 |
| First published | 2024-02-09 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.21.0 <23 \|\| >=24.5.0 |
| Dependencies | 0 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 685 |
| Author | Arcjet |
| Maintainers | quinn-arcjet, davidmytton |
| Keywords | arcjet, duration, time, util, utility |

## Links

- npm: https://www.npmjs.com/package/@arcjet/duration
- Repository: https://github.com/arcjet/arcjet-js
- Homepage: https://arcjet.com
- Issues: https://github.com/arcjet/arcjet-js/issues
- npm.io page: https://npm.io/package/@arcjet/duration

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.14.1 (latest) — 2026-10-07
- 1.10.0-rc.1 (rc) — 2026-08-07
- 1.14.0 — 2026-10-01
- 1.13.0 — 2026-09-16
- 1.12.0 — 2026-09-08
- 1.11.0 — 2026-08-26
- 1.10.0 — 2026-08-11
- 1.10.0-rc.0 — 2026-08-04
- 1.9.1 — 2026-07-15
- 1.9.0 — 2026-07-15
- 1.8.0 — 2026-07-07
- 1.8.0-rc.0 — 2026-07-07
- 1.7.0 — 2026-07-06
- 1.7.0-rc.1 — 2026-07-06
- 1.7.0-rc.0 — 2026-07-03
- … 55 more at https://npm.io/package/@arcjet/duration/versions

## README

<!-- trunk-ignore-all(markdownlint/MD001) -->

<a href="https://arcjet.com" target="_arcjet-home">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
    <img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
  </picture>
</a>

# `@arcjet/duration`

<p>
  <a href="https://www.npmjs.com/package/@arcjet/duration">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fduration?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
      <img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fduration?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
    </picture>
  </a>
</p>

[Arcjet][arcjet] utilities for parsing duration strings.

- [npm package (`@arcjet/duration`)](https://www.npmjs.com/package/@arcjet/duration)
- [GitHub source code (`duration/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/duration)

## 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`][github-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:

```sh
npm install @arcjet/duration
```

## Use

```ts
import { parse } from "@arcjet/duration";

const seconds = parse("1h");
console.log(seconds); // prints 3600
```

## API

This package exports the identifier
[`parse`][api-parse].
There is no default export.

This package does not export [TypeScript][] types.

### `parse(value)`

Parses a duration into a number representing seconds while ensuring the value
fits within an unsigned 32-bit integer.

If you pass a number, it is validated and returned as-is.

If you pass a string, it must be in the form of digits followed by a unit.
Supported units are `s` (seconds),
`m` (minutes),
`h` (hours),
and `d` (days).

###### Parameters

- `value` (`number` or `string`)
  — the duration to parse

###### Returns

Parsed seconds (`number`).

###### Example

```ts
console.log(parse("1s")); // => 1
console.log(parse("1m")); // => 60
console.log(parse("1h")); // => 3600
console.log(parse("1d")); // => 86400
```

## License

[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]

Derivative work based on [`time.ParseDuration`][go-parse-duration] from
`golang/go` licensed under [BSD-3.0][go-parse-duration-license] © The Go Authors.
Our work ports to TypeScript.

[api-parse]: #parsevalue
[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
[typescript]: https://www.typescriptlang.org/

---
_Source: https://npm.io/package/@arcjet/duration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
