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 🙏

© 2025 – Pkg Stats / Ryan Hefner

array.func.utils

v1.0.1

Published

a utility package for arrays.

Readme

array.func.utils

array.func.utils is a lightweight and efficient utility library for performing common array operations. It includes methods for summing array elements, finding averages, removing duplicates, shuffling, flattening nested arrays, and more. Additionally, it provides utility functions for handling asynchronous operations like debouncing and throttling.


Installation

To install the package, use:

npm install array.func.utils
const arrayUtils = require('array.func.utils');

Features

1. Basic Array Operations

  • getSum(arr)

Returns the sum of all elements in an array.

Example:

arrayUtils.getSum([1, 2, 3, 4]); // Output: 10
  • getAverage(arr)

Returns the average of the elements in an array.

Example:

arrayUtils.getAverage([1, 2, 3, 4]); // Output: 2.5

2. Array Manipulation

  • removeDuplicates(arr)

Removes duplicate elements from an array.

Example:

arrayUtils.removeDuplicates([1, 2, 2, 3]); // Output: [1, 2, 3]
  • intersect(arr1, arr2)

Returns the intersection of two arrays.

Example:

arrayUtils.intersect([1, 2, 3], [2, 3, 4]); // Output: [2, 3]
  • difference(arr1, arr2)

Returns the difference between two arrays.

Example:

arrayUtils.difference([1, 2, 3], [3, 4]); // Output: [1, 2, 4]
  • removeBy(arr, val)

Removes a specific value from an array.

Example:

arrayUtils.removeBy([1, 2, 3], 2); // Output: [1, 3]
  • shuffle(arr)

Randomly shuffles the elements of an array.

Example:

arrayUtils.shuffle([1, 2, 3, 4]); // Output: [3, 1, 4, 2] (random order)
  • flat(arr)

Flattens a nested array into a single array.

Example:

arrayUtils.flat([1, [2, 3], [4, [5]]]); // Output: [1, 2, 3, 4, 5]

3. Asynchronous Function Utilities

  • debounceAsync(fn, delay)

Creates a debounced version of the provided function. Executes the function only after a specified delay since the last call.

Example:

const debouncedFn = arrayUtils.debounceAsync(async (x) => x * 2, 3000);
debouncedFn(5).then(console.log); // Logs 10 after 3 seconds
  • throttleAsync(fn, delay)

Creates a throttled version of the provided function. Ensures the function is executed at most once every specified delay period.

Example:

const throttledFn = arrayUtils.throttleAsync(async (x) => x * 2, 3000);
throttledFn(5).then(console.log); // Logs 10 after 3 seconds

4. API Reference

  • getSum(arr)

Returns the sum of all elements in an array.

Parameters: arr (Array): The array of numbers.

Returns: (Number): The sum of the array elements.

  • getAverage(arr)

Returns the average of the elements in an array.

Parameters: arr (Array): The array of numbers.

Returns: (Number): The average of the array elements. Returns 0 if the array is empty.

  • removeDuplicates(arr)

Removes duplicate elements from an array.

Parameters: arr (Array): The array of elements.

Returns: (Array): A new array without duplicates.

  • intersect(arr1, arr2)

Returns the intersection of two arrays.

Parameters: arr1 (Array): The first array. arr2 (Array): The second array.

Returns: (Array): An array containing common elements from both arrays.

  • difference(arr1, arr2)

Returns the difference between two arrays.

Parameters: arr1 (Array): The first array. arr2 (Array): The second array.

Returns: (Array): An array containing elements that are unique to each array.

  • removeBy(arr, val)

Removes a specific value from an array.

Parameters: arr (Array): The array of elements. val (Any): The value to be removed.

Returns: (Array): A new array without the specified value.

  • shuffle(arr)

Randomly shuffles the elements of an array.

Parameters: arr (Array): The array to shuffle.

Returns: (Array): A new array with shuffled elements.

  • flat(arr)

Flattens a nested array into a single array.

Parameters: arr (Array): The nested array.

Returns: (Array): A flat array.

  • debounceAsync(fn, delay)

Debounces an asynchronous function, ensuring it's called only after a delay since the last invocation.

Parameters: fn (Function): The asynchronous function to debounce. delay (Number): The debounce delay in milliseconds.

Returns: (Function): A debounced version of the function.

  • throttleAsync(fn, delay)

Throttles an asynchronous function, ensuring it's called at most once every specified delay.

Parameters: fn (Function): The asynchronous function to throttle. delay (Number): The throttle delay in milliseconds.

Returns: (Function): A throttled version of the function.

License

This library is licensed under the MIT License. Feel free to use and modify it in your projects © [Kunal Mittal].