# error-if-index-is-negative

> Function triggers error if a given index is a negative number, meaning the item was not found in the array.

Latest version **2.0.0** (published 2020-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-if-index-is-negative
pnpm add error-if-index-is-negative
yarn add error-if-index-is-negative
bun add error-if-index-is-negative
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-07-31 |
| First published | 2019-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | array, index, validation, checking, error, message |

## Links

- npm: https://www.npmjs.com/package/error-if-index-is-negative
- Repository: https://github.com/writetome51/error-if-index-is-negative
- Homepage: https://github.com/writetome51/error-if-index-is-negative#readme
- Issues: https://github.com/writetome51/error-if-index-is-negative/issues
- npm.io page: https://npm.io/package/error-if-index-is-negative

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-07-31
- 1.0.1 — 2019-04-09
- 1.0.0 — 2019-03-31

## README

# errorIfIndexIsNegative(index): void

Triggers error if `index` is negative number, saying "value not found in array".  
This function is intended to be called after you've called Array.indexOf(), or any  
function that returns a negative number if the value being searched for in the array   
was not found.  You then pass that resulting index to this function.

## Example
```
let arr = [1,2,3,4];
let index = arr.indexOf(5);
errorIfIndexIsNegative(index);
// "Error:  value not found in array"
```

## Installation
`npm install  error-if-index-is-negative`

## Loading
```js
import { errorIfIndexIsNegative } from 'error-if-index-is-negative';
```

## License
[MIT](https://choosealicense.com/licenses/mit/)

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