error-if-index-how-many-or-array-are-not-valid
v3.0.1
Published
Function triggers error if a given index, array, or 'howMany' items request is not valid
Downloads
15
Maintainers
Readme
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';