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

tanzir-utils

v3.0.0

Published

A Library to make fun of arrays, easy to use and a life saver Library for developers

Downloads

151

Readme

tanzir-utils

A collection of array utility functions.

Installation

You can install the package using npm:

npm install tanzir-utils

Functions

divide(arr, size)

Divides an array into smaller subarrays of a specified size.

Parameters:

arr (Array): The array to divide. size (number): The size of each subarray.

Returns:

(Array): A new array containing the subarrays.

Example:

import { divide } from 'tanzir-utils';

const result = divide([1, 2, 3, 4, 5], 2);
console.log(result); // [[1, 2], [3, 4], [5]]

truthy(arr)

Filters out falsy values from an array.

Parameters:

arr (Array): The array to filter.

Returns:

(Array): A new array containing only truthy values from the original array.

Example:

import { truthy } from 'tanzir-utils';

const result = truthy([0, 1, false, 2, '', 3]);
console.log(result); // [1, 2, 3]

concat(arr, flat = 1, ...distribute)

Concatenates elements to an array with a specified depth of flattening.

Parameters:

arr (Array): The initial array to which elements will be concatenated. flat (number, optional): The depth level specifying how deep a nested array structure should be flattened. Default is 1. ...distribute (any): Additional elements or arrays to concatenate and flatten.

Returns:

(Array): A new array with the concatenated and flattened elements.

Example:

import { concat } from 'tanzir-utils';

const result = concat([1, 2], 2, [3, [4, [5]]]);
console.log(result); // [1, 2, 3, 4, [5]]

difference(arr1, arr2)

Finds the difference between two arrays.

Parameters:

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

Returns:

(Array): Array containing elements that are in arr1 but not in arr2.

Example:

import { difference } from 'tanzir-utils';

const result = difference([1, 2, 3], [2, 3, 4]);
console.log(result); // [1]

uniq(array)

Creates a duplicate-free version of an array.

Parameters:

array (Array): The array to inspect.

Returns:

(Array): Returns the new duplicate-free array.

Example:

import { uniq } from 'tanzir-utils';

const result = uniq([1, 2, 2, 3, 4, 4, 5]);
console.log(result); // [1, 2, 3, 4, 5]

intersection(array, ...arrays)

Creates an array of unique values that are included in all given arrays.

Parameters:

array (Array): The first array to inspect. ...arrays (Array): The arrays to inspect.

Returns:

(Array): Returns the new array of shared values.

Example:

import { intersection } from 'tanzir-utils';

const result = intersection([1, 2, 3], [2, 3, 4], [3, 4, 5]);
console.log(result); // [3]

union(...arrays)

Creates an array of unique values, in order, from all given arrays.

Parameters:

...arrays (Array): The arrays to inspect.

Returns:

(Array): Returns the new array of combined values.

Example:

import { union } from 'tanzir-utils';

const result = union([1, 2], [2, 3], [3, 4]);
console.log(result); // [1, 2, 3, 4]

flattenDeep(array)

Recursively flattens an array.

Parameters:

array (Array): The array to flatten.

Returns:

(Array): Returns the new flattened array.

Example:

import { flattenDeep } from 'tanzir-utils';

const result = flattenDeep([1, [2, [3, [4]]]]);
console.log(result); // [1, 2, 3, 4]

License

This project is licensed under the MIT License - see the LICENSE file for details.