npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

array-includes-polyfill

v0.7.2

Published

Exposing a richer set of Array features for JavaScript

Downloads

281

Readme

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