Exposing a richer set of Array features for JavaScript
npm install array-includes-polyfill#### Current Array Features ####
``sh`
new array(arr:Array) //This will generate a new Array-includes-polyfill and copy all data from a given Array.
new array(arr:Object) // This will generate a new Array-includes-polyfill and copy all data from a given Object.
array.includes ("top level string"); //returns true or false based on result of toplevel string search.
array.lookup({key:'value', complex:{key:'value'}}) //returns specific object or new ES5 array of objects that match.
array.trash({key:'value', complex:{supported:true}}) //Will permanently delete specified object from the array.
array.copy() // Will return a new JavaScript Array Object. (Typically good for server communication)
array.copy(destination) // Will populate a given array and push data on top of it.
array.clear() //Will empty/deletes all continents within. Returns true if length is 0, false, if length is above 0.
sh
npm install array-includes-polyfill --save
``jsvar array = require('array-includes-polyfill');
var arr = new array();
/ Includes polyfill /
arr.push('Has includes polyfill');
console.log(arr.includes('Has includes polyfill'));
console.log(arr);
/* Custom lookup polyfill /
var obj1 = {id:'_$1QA2WS3ED', user:'john doe', details:{dob:'01/01/99'}};
var obj2 = {id:'_$1QA2WS3EF', user:'john doe', details:{dob:'01/02/99'}};
var obj3 = {id:'_$1QA2WS3EG', user:'john doe', details:{dob:'01/01/99'}};
var obj4 = {id:'_$1QA2WS3EH', user:'jane doe', details:{dob:'01/02/99'}};
var obj5 = {id:'_$1QA2WS3EI', user:'jack doe', details:{dob:'01/05/99'}};
var obj6 = {id:'_$1QA2WS3EJ', user:'july doe', details:{dob:'01/06/99'}};
arr.push(obj1, obj2, obj3, obj4, obj6);
arr.lookup({id:'_$1QA2WS3ED'}).details.occupation="programmer";
console.log(arr.lookup({id:'_$1QA2WS3ED'}));
//arr > obj1 - will now include the occupation property with the programmer value
arr.lookup({user:'john doe', details:{dob:'01/02/99'}}).details.occupation="programmer";
console.log(arr.lookup({user:'john doe', details:{dob:'01/02/99'}}));
//arr > obj2 - will now include the occupation property with the programmer value
arr.trash({id:'_$1QA2WS3EJ'});
console.log(arr); //<-- Deletes user july doe from the array permanently.
var destination = arr.copy(); //<-- Will return a regular JavaScript Array to destination
arr.copy(destination); //<-- Will copy contents of arr to destination and return a regular JavaScript Array
var arr = new arrES6([{id:123}, {id:321}, {id:213}]);
arr.clear();
console.log(arr); //<-- should equal an empty an Array like object;
`
TESTS ##
You can run the tests using the Atom code editor and the Wallaby plugin. Here is the path to the tests.
`sh
node_modules > tests
`
If you do not have Wallaby (the license is expensive!): Run at localhost:8080 server and open console for test results
`sh
npm install -g http-server
http-server
`
$3
Paste this example into your console via Chrome to see the results of the array polyfills/features.
`sh
node_modules > array-includes-polyfill > example.js
``