# array-events

> Events and more for arrays

Latest version **2.0.1** (published 2023-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install array-events
pnpm add array-events
yarn add array-events
bun add array-events
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-06-20 |
| First published | 2014-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | * |
| Dependencies | 3 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Abbey Hawk Sparrow |
| Maintainers | khrome |
| Keywords | array, async, events |

## Links

- npm: https://www.npmjs.com/package/array-events
- Repository: https://github.com/khrome/array-events
- Issues: https://github.com/khrome/array-events/issues
- npm.io page: https://npm.io/package/array-events

## Dependencies (3)

- [async-arrays](https://npm.io/package/async-arrays.md) 2.0
- [extended-emitter](https://npm.io/package/extended-emitter.md) *
- [extended-emitter-es6](https://npm.io/package/extended-emitter-es6.md) ^1.1.3

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-06-20
- 2.0.0 — 2023-06-19
- 1.1.0 — 2023-05-31
- 1.0.0 — 2016-12-20
- 0.2.0 — 2015-03-04
- 0.1.4 — 2015-02-12
- 0.1.3-beta — 2014-03-28
- 0.1.1-beta — 2014-03-14
- 0.1.0-beta — 2014-02-23
- 0.0.4-alpha — 2014-02-21
- 0.0.3-alpha — 2014-02-16
- 0.0.2-alpha — 2014-02-16
- 0.0.1-alpha — 2014-02-16

## README

array-events.js
===============

[![NPM version](https://img.shields.io/npm/v/array-events.svg)]()
[![npm](https://img.shields.io/npm/dt/array-events.svg)]()
[![Travis](https://img.shields.io/travis/khrome/array-events.svg)]()

Is an Array extension class which adds asynchronous functions to Array as well as firing events on 'remove', 'add' or 'change'

    import { EventedArray } = from 'array-events/array-events.mjs';
    // OR: const EventedArray = require('array-events');
    const myArray = new EventedArray();

events
------

*change* : fired any time an element is added or removed

*add* : fired any time an element is added

*remove* : fired any time an element is removed 

emitter functions
-----------------

EventedArrays are also [Emitters](http://docs.nodejitsu.com/articles/getting-started/control-flow/what-are-event-emitters) but have an expanded syntax from [extended-emitter](https://github.com/khrome/extended-emitter) and the additional `.when()` call.

    myArray.on('change', function(event){ });
    myArray.once('change', function(event){ });
    myArray.off('change', function(event){ });
    myArray.emit('change'[, arguments]);

async functions
---------------

forEachEmission : execute serially

    myArray.forEachEmission(function(item, index, done){
        somethingAsynchronous(function(){
            done();
        });
    }, function(){
        //we're all done!
    });
    
forAllEmissions : execute all jobs in parallel

    myArray.forAllEmissions(function(item, index, done){
        somethingAsynchronous(function(){
            done();
        });
    }, function(){
        //we're all done!
    });
    
forAllEmissionsInPool : execute all jobs in parallel up to a maximum #, then queue for later

    myArray.forAllEmissionsInPool(poolSize, function(item, index, done){
        somethingAsynchronous(function(){
            done();
        });
    }, function(){
        //we're all done!
    });
    
utility functions
-----------------

contains : does the array contain this element?

    new EventedArray(['dog', 'cat', 'mouse']).contains('cat') //returns true;
    
combine : generate a new array that is the union of the provided arrays

    new EventedArray(['dog', 'cat']).combine(['mouse']) //returns a new array  ['dog', 'cat', 'mouse'];
    
erase : generate a new array without the member provided
    
    new EventedArray(['dog', 'cat', 'mouse']).erase('cat') //returns a new array ['dog', 'mouse'];
    
EventedArray.is : is the provided object an instance of EventedArray

    EventedArray.is(new EventedArray()); //returns true
    EventedArray.is([]) //returns false
    

Testing
-------
just run
    
    mocha

Enjoy,

-Abbey Hawk Sparrow

---
_Source: https://npm.io/package/array-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
