array.onempty

Polyfill to enable execution of callback function if the array is empty

Usage no npm install needed!

<script type="module">
  import arrayOnempty from 'https://cdn.skypack.dev/array.onempty';
</script>

README

array.onempty(fn)

Enable call of callback function to empty arrays

Simple example:

<script type="txt/javascript src="/path/to/libs/array.onempty.js" ></script>

||

require('array.onempty);

and then

[1,2,3,4,5]
.filter((item) =>  item > 10 ) //this should return an empty list
.onEmpty(() => console.log('Ey! This is an empty list'));


[]
.onEmpty((empty) => empty.push(1)) //returning an array : [1]
.onEmpty(() => {
     //now this won't be invoked
 });

Build code

npm install

Test code

npm test

Publish

npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]

git push --follow-tags

npm publish