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

util-array

v0.4.5

Published

Small js lib

Downloads

46

Readme

#ArrayUtil This small library adds a small object that is a wrapper for the standard class array in JavaScript. You just need to write something like ArrayUtil(array, [fn]), where the array is an array that you had before, and fn, which is an optional argument, is a function of the comparison of elements in the array. After that you will be available as methods of the class Array, and many other methods described below. For example: ArrayUtil([1, 2, 3]).isOrdered() return true. And i'm sorry for my English :)

###Library methods add(value, index) - add value to the array. If index not passed is work like push()`, but return current object.


allIndexOf(a[, b[, c[...]]]) - returns an instance of ArrayUtil containing all indexes of passed elements. If obtained one argument and it is an array, it will look for items that are in it. For example: AUtil( [1, 1, 2, 3] ).allIndexOf(1, 2, 4) return [[0, 1], [2], []] AUtil( [1, 1, 2, 3] ).allIndexOf(1) return [0, 1] AUtil( [1, 1, 2, 3] ).allIndexOf([1]) return [0, 1]


binarySearch(item) - return index of item in object or -1 if there is no such element. Important! It will work correctly only for sorted objects.


clear() - remove all undefined from object and return it.


clone() - return copy of current object. It's not deep copying, so reffered types will not be copied.


deleteIf(fun) - removes all values ​​from the object for which fun returns true and return it.


drop(index) - remove element at current index. If index not passed is work like pop(), but return current object.


empty() - remove all elements from object and return it.


first() - return first element of object or undefined if there is no elements.


greaterOrEqual(than) - returns an instance of ArrayUtil with values greater or equal than the passed.


greaterThan(than) - returns an instance of ArrayUtil with values greater than the passed.


has(a[, b[, c[...]]]) - take one or more arguments. Return true if object has all of this arguments. If obtained one argument and it is an array, it will look for items that are in it.


hasAny(a[, b[, c[...]]]) - take one or more arguments. Return true if object has at least one of this arguments. If obtained one argument and it is an array, it will look for items that are in it.


isEmpty() - return true if object not contain any element.


isOrdered() - return true if object ordered by ascending.


isOrderedByDesc() - return true if object ordered by descending.


inRange(from, to) - return instance of ArrayUtil with values ​​lying in a given range, including boundary. Important! Both parameters are required!


last() - return last element of array or undefined if there is no elements in array.


lastIndex() - return number is equal to length of object minus one.


lessOrEqual(than) - returns instance of ArrayUtil with values less or equal than the passed.


lessThan(than) - returns an instance of ArrayUtil with values less than the passed.


max() - return the greatest element in array.


min() - return the least element in array.


minMax() - return instance of ArrayUtil with two values, comprising the least and the greatest elements.


orderStatistic(index) - returns a value in a sorted array would stand at the given position. For example: ArrayUtil( [4, 3, 2, 1] ).orderStatistic(0) return 1, because after sorting object will be equal to [1, 2, 3 ,4].


remove(a[, b[, c[...]]]) - - take one or more arguments. Removes all occurrences of the arguments in the object. If obtained one argument and it is an array, it will look for items that are in it. Return current object.


shuffle() - shuffles elements in object and return it.


sortByDesc() - sort object by descending and return it.


isIndexCorrect(index) - return true if index greater than or equal 0 and less than length of object minus one.


swap(firstIndex, secondIndex) - swap two elements with given indexes and return object.


toArray() - return array, comprising values of current object.


unique() - reserves in the object only unique values and return it.