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

arrayex

v1.0.7

Published

A functional extension to Native Array Object

Downloads

325

Readme

Arrayex - enhance the native array operation

The native methods for array is really powerful in the new js standard, but still, some frequently used operations is missing. Arrayex is a extremely lightweight library that seperated from several projects, provides some frequently used array functions.

Install

The recommended way to install and maintain arrayex in your project is through the Node.js Pacakge Manager (NPM), simply type the npm command in your project folder:

npm install arrayex

Usage

The library doesn't extend the Array prototype, so you have call Arrayex.SomeFunc(array, ...params) to use it. The name of function and parameters is Straightforward so you really do not need a document to use it.

import { Arrayex } from 'arrayex'

let arr1 = [1,2,3,4,3]
Arrayex.Delete(arr1, 3) // arr1 = [1,2,4,3]
let arr2 = [3,1,2,3,4,3]
Arrayex.Delete(arr2, v => v >= 3, true) // arr2 = [1,2]


let arr3 = [1,2,3,4,3]
Arrayex.BatchDelete(arr3, [3, 4], true) // arr3 = [1,2]

let arr4 = [1,3,1,3,3]
Arrayex.Replace(arr3, 3, 1, true) // arr4 = [1,1,1,1,1]

let n1 = Arrayex.Find([1,2,3,4,5], val => val > 4) // 5

let p1 = Arrayex.IncludeSome([1,2,3,4,5], [7, 9, 5]) // true

let arr5 = [1, 3, 7, 9, 10]
let index1 = Arrayex.OrderedInsert(arr5, 5, (a, b) => a - b) // arr5 = [1, 3, 5, 7, 9, 10], index1 = 2
let index2 = Arrayex.OrderedInsert(arr5, 5, (a, b) => a - b, true) // arr5 = [1, 3, 5, 7, 9, 10], index1 = 2, with unique = true, no duplicate item will be inserted and the existing item index will returned.

let arr6 = [1,2,4]
Arrayex.InsertBefore(arr6, 4, 3) // arr6 = [1,2,3,4]
Arrayex.InsertAfter(arr6, 2, 9) // arr6 = [1,2,9,3,4]

let arr7 = [1.0, 2.000001, 3.0, 4.000000032, 4.5]
let n2 = Arrayex.Approximate(arr7, 4, 0.001) // 4.000000032, find approximate float value
let index3 = Arrayex.ApproximateIndex(arr7, 4, 2, 0.0001) // 1

let arr8 = Arrayex.Empty(3) // [null, null, null]
let arr9 = Arrayex.Create(4, (index, total) => index) // [0, 1, 2, 3]
let arr10 = Arrayex.Repeat(2/* total */, 1, 2, 3) // [1, 1, 2, 2, 3, 3], Repeat each element n times
let arr11 = Arrayex.RepeatSequence(3/* total */, 1, 2) // [1, 2, 1, 2, 1, 2], Repeat the initial sequence in order n times

let peroid1 = Arrayex.AnalyzePeriod([1,2,3,1,2,3,1,2,3,1,2,3]) // [1,2,3], since the array is repeat this sequence
let peroid2 = Arrayex.AnalyzePeriod([1,2,1,2,1]) // [1,2,1,2,1], the array do not has peroidic property

let flat1 = Arrayex.Flat([1, [2,3], [4]]) // [1,2,3,4]

let div1 = Arrayex.Divide([1,2,3,4,5,6,7], 3) // [[1,2,3], [4,5,6], [7]]

let group1 = Arrayex.Group([1, -1, 2, -2, 4, -4], (value, index, array) => value > 0 ? 'positive' : 'negative') // { positive: [1,2,4], negative: [-1,-2,-4] }

let sample = Arrayex.Sample([1,2,3,4,5,6,7,8], 3) // [1, 4, 7], equal-spaced sample 3 values
let sample = Arrayex.Sample([1,2,3,4,5,6,7,8], 3, true) // [2, 8, 3], randomly sample 3 values

let u1 = Arrayex.Union([[1,2,3], [3,4,5]]) // [1,2,3,3,4,5]
let u2 = Arrayex.Union([[1,2,3], [3,4,5]]) // [1,2,3,4,5], remove duplicates

let intersect = Arrayex.Intersect([[1,2,3], [2,3,4]]) // [2,3], the order of output follows the first array

let subtract = Arrayex.Subtract([1,2,3,4,5,6], [[6,5,9], [7, 8]]) // [1,2,3,4]

let nn = Arrayex.NonNull([1, null, 2, null, null, 3, 4, null]) //nn = [1,2,3,4]

License

Distributed under the MIT license. See LICENSE for detail.