# recurrence

> Generates a string based on string recurrence

Latest version **1.0.0** (published 2016-02-05) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-02-05 |
| First published | 2016-02-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+9 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Antti Kupila |
| Maintainers | akupila |
| Keywords | date, recurrence, format, string |

## Links

- npm: https://www.npmjs.com/package/recurrence
- Repository: https://github.com/akupila/recurrence
- Homepage: https://github.com/akupila/recurrence#readme
- Issues: https://github.com/akupila/node-podcast-parser/issues
- npm.io page: https://npm.io/package/recurrence

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) 4.2.1

## Recent versions

- 1.0.0 (latest) — 2016-02-05

## README

# recurrence

[![build status](https://travis-ci.org/akupila/recurrence.svg?branch=master)](https://travis-ci.org/akupila/recurrence)
[![Coverage Status](https://coveralls.io/repos/github/akupila/recurrence/badge.svg?branch=master)](https://coveralls.io/github/akupila/recurrence?branch=master)

Calculates the diff between dates and returns a nicely formatted string.

Turns an array of dates into:

- every 4 days
- monthly
- every 10 hours
- etc

## Installation

```
npm install --save recurrence
```

## Usage

```js
const recurrence = require('recurrence');

const dates = [
  new Date(2016, 1, 1),
  new Date(2016, 1, 2)
  new Date(2016, 1, 3)
];

console.log(recurrence(dates));
```

Duplicate dates are removed and the order doesn't matter.

## Output

```json
{
  "count": 1,
  "unit": "day/week/month/year",
  "recurrence": "Daily"
}
```

In the output `recurrence` is set to something that you could show directly to a user.

Values look like this:

- every 5 seconds
- every 30 minutes
- hourly
- every 8 hours
- daily
- every 3 weeks
- monthly
- yearly
- every 10 years

Of course you can use the `count` and `unit` for your own output, maybe for other languages or otherwise different results.

## Options

You can pass an options object as the second argument.

Defaults:

```json
{
  "numberAsString": false,
  "strict": false,
  "noSingleUnits": false
}
```

Override any of these by passing in an object:

```js
recurrence(dates, {
  strict: true,
  numberAsString: true
});
```

### numberAsString

Outputs the number as a text:

- true: 'Every four years'
- false: 'Every 4 years'

### strict

Throw an exception if an invalid date is detected. With `strict = false` just ignores the date.

### noSingleUnits

Doesn't format strings as `daily` or `yearly` so it returns `Every second/hour/month/year` etc instead of `daily` or `weekly`

## Example

```js
const recurrence = require('recurrence');

const leapyears = [
  new Date(2016, 1, 29),
  new Date(2012, 1, 29)
  new Date(2008, 1, 29)
];

const result = recurrence(leapyears, {
  numberAsString: true  
});

console.log(`Leap year happens ${result.recurrence}!`);
// Leap year happens every four years!
```

## Test

```bash
npm run test
```

## Coverage

```bash
npm run cover
```

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