0.7.2 • Published 8 years ago

array-includes-polyfill v0.7.2

Weekly downloads
218
License
ISC
Repository
github
Last release
8 years ago

What Does It Do?

This package is an on-going project to bring robust and deep features to array functionality with JavaScript. This package does not change any prototypes of any original object but merely extends them to this package.

Current Array Features

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.

How To Use

npm install array-includes-polyfill --save
var 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.

 node_modules > tests

If you do not have Wallaby (the license is expensive!): Run at localhost:8080 server and open console for test results

npm install -g http-server
http-server

EXAMPLE.JS

Paste this example into your console via Chrome to see the results of the array polyfills/features.

node_modules > array-includes-polyfill > example.js
0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago