https://github.com/writetome51/error-if-index-not-valid
Function triggers error if a given index cannot exist in a given array length
https://github.com/writetome51/error-if-index-not-valid
array error index javascript valid validation
Last synced: 24 days ago
JSON representation
Function triggers error if a given index cannot exist in a given array length
- Host: GitHub
- URL: https://github.com/writetome51/error-if-index-not-valid
- Owner: writetome51
- License: mit
- Created: 2019-03-30T23:06:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T23:38:23.000Z (almost 6 years ago)
- Last Synced: 2025-02-03T04:29:35.058Z (over 1 year ago)
- Topics: array, error, index, javascript, valid, validation
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# errorIfIndexNotValid(
index,
arrayLength
): void
Triggers error if `index` cannot exist in `arrayLength`.
`index` is allowed to be negative.
## Examples
```
errorIfIndexNotValid(1, 2); // No error.
errorIfIndexNotValid(2, 2);
// "Error: The entered index is not valid. Whether positive or negative,
// it exceeds the index range of the array."
errorIfIndexNotValid(-2, 2); // No error.
errorIfIndexNotValid(-3, 2);
// "Error: The entered index is not valid. Whether positive or negative,
// it exceeds the index range of the array."
errorIfIndexNotValid(1, 1);
// "Error: The entered index is not valid. Whether positive or negative,
// it exceeds the index range of the array."
```
## Installation
`npm i error-if-index-not-valid`
## Loading
```js
import { errorIfIndexNotValid } from 'error-if-index-not-valid';
```
## License
[MIT](https://choosealicense.com/licenses/mit/)