# duration-strings

> Format durations in different forms and locales

Latest version **0.0.1** (published 2023-01-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install duration-strings
pnpm add duration-strings
yarn add duration-strings
bun add duration-strings
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-01-18 |
| First published | 2023-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 138.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrew Magee |
| Maintainers | amagee |

## Links

- npm: https://www.npmjs.com/package/duration-strings
- Repository: https://github.com/amagee/duration-strings
- Homepage: https://github.com/amagee/duration-strings#readme
- Issues: https://github.com/amagee/duration-strings/issues
- npm.io page: https://npm.io/package/duration-strings

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.2.2

## Recent versions

- 0.0.1 (latest) — 2023-01-18
- 0.0.0 — 2023-01-18

## README

# duration-strings

This package lets you format durations in different forms and in
different locales.

Locales are not included in the package, however we provide a tool
for you to generate them yourself from
[the CLDR Project](https://github.com/unicode-org/cldr-json).

Distributing the locale data is not (currently?) in the scope of this project.

Once you have a `Locale` object, you can try:

```
import {
  getUnitSingular,
  getUnitPlural,
  formatDuration,
  formatRelativeDuration
} from "duration-strings";

// Supported units are second, minute, hour, week, month, year.

>>> getUnitSingular("second", locale)
"second"

>>> getUnitPlural("year", locale)
"years"

>>> formatDuration(1, "week", locale)
"1 week"

>>> formatDuration(7, "month", locale)
"7 months"

>>> formatRelativeDuration(-1, "day", locale)
"yesterday"

>>> formatRelativeDuration(1, "day", locale)
"tomorrow"

>>> formatRelativeDuration(1, "day", locale, {alwaysNumeric: true})
"1 day ago"

>>> formatRelativeDuration(1, "day", locale, {alwaysNumeric: true})
"in 1 day"
```

We do not have functions for generating durations from Date objects, date
ranges, numbers of milliseconds etc.

Released under [MIT License](./LICENSE).

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