3.0.1 • Published 3 years ago

error-if-index-how-many-or-array-are-not-valid v3.0.1

Weekly downloads
8
License
MIT
Repository
github
Last release
3 years ago

errorIfIndex_howMany_orArray_areNotValid(      index,      howMany,      array): void

Triggers error if array has no .length, index is not a valid index of array (it is allowed
to be negative), or howMany is not an integer greater than zero.

Example

function getAdjacentAt(startingIndex, howMany, array) {
    // validate arguments:
    errorIfIndex_howMany_orArray_areNotValid(startingIndex, howMany, array);

    if (startingIndex + howMany === 0) return arraySlice(startingIndex, array.length, array);
    else return arraySlice(startingIndex, startingIndex + howMany, array);
}

Installation

npm i error-if-index-how-many-or-array-are-not-valid

Loading

import { errorIfIndex_howMany_orArray_areNotValid } 
	from 'error-if-index-how-many-or-array-are-not-valid';

License

MIT