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-enhancements

v0.1.1

Published

Many helpful functions for javascript Arrays

Downloads

222

Readme

js-array-enhancementsBuild Status

NPM

Introduction

Functions included


var array = require("array-enhancements");
  • array.ize(Mixed item): Array

    Create an array given any type of argument

  • array.add(Array, [Array[, ...]]): Array

    Append any given number of arrays into a new one

  • array.clone(Array arr): Array

    Clone (could be recursive) a dense array

    Note: only loop arrays not objects

  • array.insertAt(Array ar, Mixed o, Number index): Boolean

    Add an element at the specified index (alias of splice)

  • array.combine(Array **&**dst, Array [, Array ...])

    Append any number of arrays into the first one

  • array.countValues(Array array [, Boolean ci]): Array

    Counts all the values of an array

    Second argument (ci) enable case insensitive comparison

  • array.sortObject(Array arr, String key)

    Sort an array of Objects by given key.

  • array.chunk(Array array, Number size[, Boolean preserve_keys = false])

    Split an array into chunks

  • array.shuffle(Array **&**arr)

    This function shuffles (randomizes the order of the elements in) an array.

  • array.pad(Array arr, Number size, Mixed value): Array

    Returns a copy of the array padded to size specified by size with value value.

    If size is positive then the array is padded on the right. If it's negative then on the left. If the absolute value of size is less than or equal to the length of the array then no padding takes place

  • array.product(Array arr): Number|NaN

    Calculate the product of values in an array

  • array.sum(Array arr): Number|NaN

    Calculate the product of values in an array

  • array.dense(Array arr): Array

    Create a new dense array from given one

  • array.random(Array arr): Mixed

    Picks one random value of an array

  • array.rand(Array arr, Number len): Array

    Picks one or more random entries out of an array, and returns the key (or keys) of the random entries.

  • array.fill(Number start, Number count, Mixed value): Array

    Fill a new array with value

  • array.column(arr, field): Array

    Return the values from a single column in the input array.

    Values should be Objects.

  • array.kmap(Array arr, String field)

    Returns an Object with the key a property of the object.

    Values must be objects.

  • array.search(Array arr, String key, Mixed value): Array

    Search in an array of Objects given key-value and return the list that match.

  • array.random(Array arr): Mixed

    Get a random value, the array must be dense

  • array.unique(Array arr): Array

    Create a new array removing duplicated values

  • array.mapAsync (Array arr, Function callback(Mixed value, Number key, Function done), Function donecallback(Array results), Mixed thisArg)

    Executes a provided function (callback) once per array element.

    callback will receive a done callback to notify when it finished.

    the done callback receive the result.

    And when all is done, donecallback will be called.

    example:

array.mapAsync(["file.txt", "file2.txt"], function(val, key, done) {
	fs.readFile(val, function(err, data) {
		done(data);
	});
}, function(contents) {
	// you have read all files, do your staff
});
  
  • array.mapSerial (Array arr, Function callback(Mixed value, Number key, Function next, Function end), Function donecallback(Array results), Mixed thisArg)

    Executes a provided function (callback) once per array element, one by one.

    callback will receive a next callback to notify when it finished and end callback to notify do not continue.

    the next callback receive the result and and optional key.

array.mapSerial(["file.txt", "file2.txt"], function(val, key, next, end) {
	fs.readFile(val, function(err, data) {
		next(data, val);
	});
}, function(contents) {
	// you have read all files, do your staff
	// constest is an object: {"file.txt": "???", "file2.txt": "???"}
});
  

Compatibility layer for old browsers @lib/arrays-compat.js (mostly from MDN)

  • Array.prototype.reduce
  • Array.prototype.filter
  • Array.prototype.reduceRight
  • Array.prototype.some
  • Array.prototype.every
  • Array.prototype.map
  • Array.prototype.forEach

## Install

With [npm](http://npmjs.org) do:

npm install array-enhancements


## test (travis-ci ready!)

npm test // or cd /test node test.js


## license

MIT.