# duriso

> Parse and serialize ISO 8601 Durations

Latest version **1.0.0** (published 2026-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install duriso
pnpm add duriso
yarn add duriso
bun add duriso
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-03-15 |
| First published | 2020-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Justin Formentin |
| Maintainers | justinformentin |

## Links

- npm: https://www.npmjs.com/package/duriso
- Repository: https://github.com/justinformentin/duriso
- Homepage: https://github.com/justinformentin/duriso#readme
- Issues: https://github.com/justinformentin/duriso/issues
- npm.io page: https://npm.io/package/duriso

## Recent versions

- 1.0.0 (latest) — 2026-03-15
- 0.0.3 — 2020-12-05
- 0.0.2 — 2020-12-04

## README

# Duriso

A lightweight, 658 byte package for parsing and serializing [ISO 8601 Duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) strings.

## Installation

```bash
npm install duriso
```

## Usage

### ES Modules (Recommended)

```js
import { serialize, parse } from "duriso";
```

### CommonJS

```js
const { serialize, parse } = require("duriso/index.cjs.js");
```

### UMD (Browser)

```html
<script src="https://unpkg.com/duriso/index.umd.js"></script>
<script>
  const { serialize, parse } = duriso;
</script>
```

## API Reference

### parse(durationString)

Parses an ISO 8601 duration string into a duration object.

**Parameters:**
- `durationString` (string): An ISO 8601 formatted duration string

**Returns:**
```typescript
{
  duration: {
    years?: number,
    months?: number,
    weeks?: number,
    days?: number,
    hours?: number,
    minutes?: number,
    seconds?: number
  }
}
```

### serialize(durationObject)

Serializes a duration object into an ISO 8601 duration string.

**Parameters:**
```typescript
{
  years?: number,
  months?: number,
  weeks?: number,
  days?: number,
  hours?: number,
  minutes?: number,
  seconds?: number
}
```

**Returns:**
- (string): An ISO 8601 formatted duration string

## Examples

### Serializing Duration Objects

```js
import { serialize } from "duriso";

// Full duration with all components
const fullDuration = {
  years: 3,
  months: 6,
  weeks: 2,
  days: 4,
  hours: 12,
  minutes: 30,
  seconds: 5
};

console.log(serialize(fullDuration));
// Output: "P3Y6M2W4DT12H30M5S"

// Time-only duration
const timeDuration = {
  hours: 12,
  minutes: 30,
  seconds: 5
};

console.log(serialize(timeDuration));
// Output: "PT12H30M5S"
```

### Parsing Duration Strings

```js
import { parse } from "duriso";

// Parse a full duration string
const fullParsed = parse("P3Y6M2W4DT12H30M5S");
console.log(fullParsed);
// Output:
// {
//   duration: {
//     years: 3,
//     months: 6,
//     weeks: 2,
//     days: 4,
//     hours: 12,
//     minutes: 30,
//     seconds: 5
//   }
// }

// Parse a time-only duration string
const timeParsed = parse("PT12H30M5S");
console.log(timeParsed);
// Output:
// {
//   duration: {
//     hours: 12,
//     minutes: 30,
//     seconds: 5
//   }
// }
```

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