# error-if-index-not-valid-after-offset-was-added

> Function triggers error if passed index is not valid, assuming an offset was recently added to it

Latest version **1.0.0** (published 2019-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-if-index-not-valid-after-offset-was-added
pnpm add error-if-index-not-valid-after-offset-was-added
yarn add error-if-index-not-valid-after-offset-was-added
bun add error-if-index-not-valid-after-offset-was-added
```

## 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 | 2019-03-31 |
| First published | 2019-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.8 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-not-valid-after-offset-was-added
- Repository: https://github.com/writetome51/error-if-index-not-valid-after-offset-was-added
- Homepage: https://github.com/writetome51/error-if-index-not-valid-after-offset-was-added#readme
- Issues: https://github.com/writetome51/error-if-index-not-valid-after-offset-was-added/issues
- npm.io page: https://npm.io/package/error-if-index-not-valid-after-offset-was-added

## Dependencies (1)

- [@writetome51/index-is-valid](https://npm.io/package/@writetome51/index-is-valid.md) ~1.0.0

## 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

- 1.0.0 (latest) — 2019-03-31

## README

# errorIfIndexNotValidAfterOffsetWasAdded(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arrayLength<br>): void

Triggers error if `index` is not valid, assuming an offset was recently added to it.  
For example, if you're writing a getIndex() function that gives you the option of adding  
an offset to modify the index it returns, `errorIfIndexNotValidAfterOffsetWasAdded()`  
might come in handy.  For more info, read the example below.

## Example
```ts
function getIndexSlightlyOff(value, array, offset){
    let index = array.indexOf(value);
    index += offset;
    // Now check if index still valid:
    errorIfIndexNotValidAfterOffsetWasAdded(index, array.length);
    return index;
}

let arr = [1,2,3,4,5];
let index = getIndexSlightlyOff(5, arr, 1);
// Error: "After the offset was added to the index, the resulting 
// index was too high for this array"

let arr = [1,2,3,4,5];
let index = getIndexSlightlyOff(2, arr, -2);
// Error: "After the offset was added to the index, the resulting 
// index was a negative number. This is not allowed."
```

## Installation
`npm install  error-if-index-not-valid-after-offset-was-added`

## Loading
```ts
// if using TypeScript:
import { errorIfIndexNotValidAfterOffsetWasAdded } 
    from 'error-if-index-not-valid-after-offset-was-added';
// if using ES5 JavaScript:
var errorIfIndexNotValidAfterOffsetWasAdded = 
    require('error-if-index-not-valid-after-offset-was-added')
    .errorIfIndexNotValidAfterOffsetWasAdded;
```

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

---
_Source: https://npm.io/package/error-if-index-not-valid-after-offset-was-added · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
