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

easy-array-use

v2.0.2-alpha.0

Published

use array methods simply

Downloads

33

Readme

what is this?

simplify your array methods

Installation

npm i easy-array-use --save

Then...

import { filterSingleConArray } from 'easy-array-use';

const newArray=filterSingleConArray([1,2,3,4,5,6,7],{condition:'greater',value:4});

//output
[5,6,7]

Options

filterArray supports 2 options like key, flatNumber

  • (typeof key)='number'

  • condition - greater | greaterEqual | smaller | smallerEqual | doubleEqual | TrippleEqual (default to greater)

Multiple Condition Array

//if the array has duplicate value
import { filterMultipleConArray } from 'easy-array-use';

const newArray=filterMultipleConArray([1,2,3,4,5,6,7],[{condition:'greater',value:4},{condition:'smaller',value:6}]);

Remove duplicate

//if the array has  duplicate values
import { removeDuplicate } from 'easy-array-use';

const newArray=removeDuplicate([1,2,3,4,5,6,7,1,3,6]);
console.log(newArray)
//output
[
  1, 2, 3, 4,
  5, 6, 7
]

OR

const newArray=removeDuplicate([
    1,
    2,
    1,
    { name: "john" },
    { name: "john" },
    { age: "25", name: "john" },
    { name: "john", age: "25", gender: "male" },
    { name: "john", age: "25", gender: "male" },
    { name: "john", age: "25" },
    "hai",
    "hai",
  ])

  console.log(newArray);

  //output
  [
    { name: 'john' },
    { age: '25', name: 'john' },
    { name: 'john', age: '25', gender: 'male' },
    1,
    2,
    'hai'
  ]

Find and delete element from Array


import { findAndRemove } from 'easy-array-use';

const myArray = [1, 2, 3, 4, "john"];

console.log(findAndRemove(myArray, 1));

//output
[2,3,4,"john"]

options

findAndRemove function supports 2 options parameters like delElement, isMutable

  • (typeof isMutable)=boolean, [default : true]
  • (typeof delElement)=any ,[not array]

Find and delete all element from Array

import { findAndRemoveAll } from 'easy-array-use';

const myArray = [1, 2, 3, 4, "john",1,4,1];

console.log(findAndRemoveAll(myArray, 1));

//output
[2,3,4,"john"]

reduce and concat values from Array

import { reduceAndConcat } from 'easy-array-use';

const myArray = [
  { name: "john", age: 12 },
  { name: "harry", age: 25 },
  { name: "jim", age: 26 },
  { name: "rokith", age: 24 },
];

console.log(reduceAndConcat(myArray, { name: [], age: [] }));

//output
{ name: [ 'john', 'harry', 'jim', 'rokith' ], age: [ 12, 25, 26, 24 ] }

const mynewArray = [
  { name: "john", age: 12, year: 1996 },
  { name: "harry", age: 25 },
  { name: "jim", age: 26 },
  { name: "rokith", age: 24 },
];

console.log(reduceAndConcat(mynewArray));


//output
{
  name: [ 'john', 'harry', 'jim', 'rokith' ],
  age: [ 12, 25, 26, 24 ],
  year: [ 1996 ]
}

options

  • filterObject [type : object] default : null

Note

- if filterObject is null then function reduce using first element of array

Count array items

import { countArrayValue } from 'easy-array-use';

const myArray =  [
      1,
      2,
      3,
      1,
      5,
      null,
      {},
      {},
      { name: "harry" },
      { name: "harry" },
      { name: "harry", age: 25 },
      "jim",
      "jim",
      null,
    ];

console.log(countArrayValue(myArray,true));

//output
{
  '1': 2,
  '2': 1,
  '3': 1,
  '5': 1,
  null: 2,
  '{}': 2,
  '{"name":"harry"}': 2,
  '{"name":"harry","age":25}': 1,
  jim: 2
}

console.log(countArrayValue(myArray,false));

//output
{
  '1': 2,
  '2': 1,
  '3': 1,
  '5': 1,
  null: 2,
  '[object Object]': 5,
  jim: 2
}

options

  • objectCount [type : boolean] default : false

Count and reduce array items

import { reduceCountArrayValue } from 'easy-array-use';

const myArray =  [
      1,
      2,
      3,
      1,
      5,
      null,
      {},
      {},
      { name: "harry" },
      { name: "harry" },
      { name: "harry", age: 25 },
      "jim",
      "jim",
      null,
    ];

console.log(reduceCountArrayValue(myArray,true, { condition: "TrippleEqual", value: 2, flatNumber: 0 }));

//output
[ 1, null, {}, { name: 'harry' }, 'jim' ]

options

  • objectCount [type : boolean] default : false
  • options [type : object] =(condition: "TrippleEqual", value: 2, flatNumber: 0)

Reorder Array


const order = [
  {
    id: "79832732",
    position: 1,
  },
  {
    id: "79832723",
    position: 2,
  },

  {
    id: "79832778",
    position: 3,
  },
  {
    id: "79832797",
    position: 4,
  },
  {
    id: "79832798",
    position: 6,
  },
  {
    id: "79832799",
    position: 7,
  },
  {
    id: "798327101",
    position: 9,
  },
];

const newOrder = {
  id: "79832766",
  position: 3,
};

console.log(reorderArray(order, "position", newOrder));

//output
[
  { id: '79832732', position: 1 },
  { id: '79832723', position: 2 },
  { id: '79832766', position: 3 },
  { id: '79832778', position: 4 },
  { id: '79832797', position: 5 },
  { id: '79832798', position: 6 },
  { id: '79832799', position: 7 },
  { id: '798327101', position: 9 }
]