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-helper-functions

v1.4.0

Published

Lightweight Array helper methods

Downloads

6

Readme

travis build downloads version MIT License

Array Helpers

Some helpful array methods. Spent sometime using Underscore in a previous project so I decided to build a helper library from scratch using some ideas behind this library. :honeybee:

Installation

This package is distributed via npm:

npm install  --save-dev array-helper-functions

// Global install
npm install -g array-helper-functions

API overview


- filter
- flatten
- compact
- partial
- every
- object
- map

Usage

const arrayHelper = require('array-helper-functions');

filter [array, filterItem, boolean]

let filter = arrayHelper.filter([1, 3, 100, 50], 50); // => [1, 3, 100];

Boolean: true Filters deep nested arrays.

let filter = arrayHelper.filter([1, 3, 100, [[[50]]], 50, true); // => [1, 3, 100];

flatten [array, boolean]

let flatten = arrayHelper.flatten([1, 3, 100, [50]]); // => [1, 3, 100, 50];

Boolean: true Flattens deep nested arrays.

let flatten = arrayHelper.flatten([1, 3, 100, [[[50]]], true); // => [1, 3, 100, 50];

compact [array]

Removes Falsy values from array set.

let compact = arrayHelper.compact([1, 2, 3, 100, null, 0]); // => [1, 2, 3, 100];

partial [func, array]

Invokes a given function with the provided array set passed.

const foo = (a, b, c) => {
    return a + b + b;
};

let partial = arrayHelper.partial(foo, [1, 2, 3]); // Invokes method `foo` with given arguments. => 6

every [func, array]

Executes the provided callback function once for each element present in the array until it finds one where the callback returns a falsy value.

const isFooBigger = (element) => {
    return element >= 5;
};

let every = arrayHelper.every(isFooBigger, [1, 2, 3]); // Returns false.
let every = arrayHelper.every(isFooBigger, [10, 5, 7]); // Returns true.

object [array, list]

Converts arrays to objects.

let object = arrayHelper.object([1, 2, 3]); // => {'0': 1, '1': 2, '2': 3}
let object = arrayHelper.object(['foo', 'baz', 'fizz']); // => { '0': 'foo', '1': 'baz', '2': 'fizz' }

### `map` [array]
Returns a new array from a tranformation applied by a function.

const multiply = (num) => {
    return num * 2;
};

let map = arrayHelper.map([1, 2, 3], multiply); // => [2, 4, 6]

Project Setup

This project assumes you have NodeJS v6 or greater installed. You should also have npm v3 or greater installed as well (this comes packaged with Node 6). You'll also need a recent version of git installed as well.

To get started with the project, start with this:

  1. Sign up for a GitHub Account (if you don't already have one)
  2. Fork this repo
  3. Clone your fork
  4. Require the module (see Usage above) and get started!

If you get any failures at this point something is wrong and needs to be fixed. Remember, Google and StackOverflow are your friends.. :raised_hands:

Contributing

If you'd like to play around with this library yourself please follow the steps below:

  1. Clone the project from Github and cd /your-path/array-helper-functions folder
  2. Run: npm run setup - This will run npm install & npm run validate: lint, build & test configurations for you ensuring everything is working as expected.

Other

This library was developed by me as a fun little project.