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

v1.0.1

Published

`Array.prototype.reject(callback)` return new array which removed value matched condition. :warning: This module extend the global Array.prototype.

Downloads

4

Readme

NPM version Build Status codecov MIT License

array-reject

:warning: This module extend the global Array.prototype.
Array.prototype.reject(callback) return new array which removed value matched condition.
This is the opposite of Array.prototype.filter!

install

$ npm install array-reject

usage

import 'array-reject';

example

const arr = [1, 2, 3, 4, 5];

function over(n) {
  return function(x) {
    return x > n;
  };
}

arr.reject( over(3) );
// => [1, 2, 3]
arr.filter( over(3) );
// => [4, 5]
const cities = [
  'Tokyo',
  'Kyoto',
  'Osaka',
  'NewYork',
  'Helsinki',
  'Tampere',
  'Espoo'
];

cities.reject(function(val) {
  return val.match(/o/i);
});
// => ['Helsinki', 'Tampere']
const idols = [
  { name: 'Hoshimiya Ichigo', type: 'cute' },
  { name: 'Kiriya Aoi',       type: 'cool' },
  { name: 'Shibuki Ran',      type: 'sexy' },
  { name: 'Arisugawa Otome',  type: 'pop'  },
  { name: 'Todo Yurika',      type: 'cool' },
  { name: 'Kamiya Shion',     type: 'cool' },
  { name: 'Ichinose Kaede',   type: 'pop'  },
  { name: 'Minowa Hikari',    type: 'sexy' },
  { name: 'Kanzaki Mizuki',   type: 'sexy' },
  { name: 'Natsuki Mikuru',   type: 'pop'  },
  { name: 'Kitaoji Sakura',   type: 'cute' },
  { name: 'Ozora Akari',      type: 'cute' },
  { name: 'Hattori Yu',       type: 'cool' },
  { name: 'Hikami Sumire',    type: 'cool' },
  { name: 'Shinjo Hinaki',    type: 'pop'  },
  { name: 'Kurebayashi Juri', type: 'sexy' },
  { name: 'Kurosawa Rin',     type: 'cool' },
  { name: 'Amahane Madoka',   type: 'cute' },
];

function idolType(type) {
  return function(idol) {
    return idol.type === type
  };
}

const notCoolIdols = idols.reject( idolType('cool') );
/* [
  {name: "Hoshimiya Ichigo", type: "cute"},
  {name: "Shibuki Ran", type: "sexy"},
  {name: "Arisugawa Otome", type: "pop"},
  {name: "Ichinose Kaede", type: "pop"},
  {name: "Minowa Hikari", type: "sexy"},
  {name: "Kanzaki Mizuki", type: "sexy"},
  {name: "Natsuki Mikuru", type: "pop"},
  {name: "Kitaoji Sakura", type: "cute"},
  {name: "Ozora Akari", type: "cute"},
  {name: "Shinjo Hinaki", type: "pop"},
  {name: "Kurebayashi Juri", type: "sexy"},
  {name: "Amahane Madoka", type: "cute"},
] */

When already has Own Array.reject ?

Old Array.prototype.reject be renamed to Array.prototype.__reject.
And run old reject function before this Array.prototype.reject.

:ok_hand:

import './my-array-reject';
import 'array-reject';

:innocent:

// This override `array-reject` 
Array.prototype.reject = function() {
  // ...
}

import 'array-reject';

example

// my-array-reject.js
Array.prototype.reject = function(index) {
  if( typeof(index) !== 'number' ) return this;

  const res = [];
  for(let i = 0, l = this.length; i < l; i += 1) {
    if( i !== index ) res.push(this[i]);
  }
  return res;
};
import './my-array-reject';
import 'array-reject';

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

function over(n) {
  return function(x) {
    return x > n;
  };
}

// run my Array.reject
arr.__reject(0);
// => [2, 3, 4, 5, 6, 7, 8, 9, 10]

arr.reject(over(3));
// => [1, 2, 3]

// run array-reject after my Array.reject
arr.reject(0, over(3));
// => [2, 3]

// array-reject use last argument as a callback
arr.reject(0, 1, 2, over(3));
// => [2, 3]

test

$ npm run test