# nearest-date

> Given an array of dates, this module will find the date nearest to a given target date. Can be used to find the nearest number as well

Latest version **1.0.1** (published 2016-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install nearest-date
pnpm add nearest-date
yarn add nearest-date
bun add nearest-date
```

## 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.1 |
| Published | 2016-12-27 |
| First published | 2016-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Thomas Watson Steen |
| Maintainers | watson |
| Keywords | distance, date, close, closest, relative, near, nearest, index |

## Links

- npm: https://www.npmjs.com/package/nearest-date
- Repository: https://github.com/watson/nearest-date
- Homepage: https://github.com/watson/nearest-date#readme
- Issues: https://github.com/watson/nearest-date/issues
- npm.io page: https://npm.io/package/nearest-date

## 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.0.1 (latest) — 2016-12-27
- 1.0.0 — 2016-12-27

## README

# nearest-date

Given an array of dates, this module will find the date nearest to a given target date. Can be used to find the nearest number as well.

[![Build status](https://travis-ci.org/watson/nearest-date.svg?branch=master)](https://travis-ci.org/watson/nearest-date)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install nearest-date
```

## Usage

```js
var nearest = require('nearest-date')

var dates = [
  new Date('2012-12-12'),
  new Date('2024-12-12'),
  new Date('2022-12-12'),
  new Date('2016-12-12'),
  new Date('1980-12-12'),
]
var target = new Date('2016-12-27')

var index = nearest(dates, target)

console.log('Winner:', dates[index])
```

## API

### `index = nearest(array[, target])`

Finds the value in the `array` nearest to the `target` and returns the
`index` of that value in the `array`.

The `target` defaults to `Date.now()`.

Both the `array` and the `target` can be either `Date` objects or
numbers.

## License

MIT

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