ts-array-ext
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

TS-Array-Ext

Fast <2kB array utility library with a modern API
by IT Minds


TS-Array-Ext is a minimalist TypeScript library that provides a few utility functions to the Array prototype class. Inspired by LINQ functionality we aim to bring a few easy to use functions that we keep rewriting over and over. No longer. It is time to extend base JavaScript Array functions.

  • 🧠 Familiar LINQ operations & patterns
  • 💪 Strongly typed
  • 🔥 Chainable
  • 📦 <2kB mini library
  • 👫 Individual imports for optimization
  • 💯 100% coverage. No less.

Getting started

Installation

npm i ts-array-ext --save

Then either import the entire lib:

import "ts-array-ext";

Or the individual functions.

import "ts-array-ext/min";
import "ts-array-ext/sum";

Your arrays will have the functions.

const totalScore = myArr.sum(x => x.score);

Demo

Checkout this playground with all examples of usage from below.


API

function description
average Calculate the average values of an attribute
chunkByCount Split array into amount of chunks by input
chunkBySize Split array into amount of chunks by size
distinct Get distinct elements by attribute
findAndReplace Find and replace or create value
groupBy Group array into arrays by difference value of attribute
max Find the element with the max value of selected attribute
median Find the element with the median value of selected attribute
min Find the element with the min value of selected attribute
reduceAsync Clean async version of .reduce
shuffle Shuffles the array
sortByAttr Sort the array by a selected attribute
sum Summation of values of a selected attribute
unionSplit Split the array by a given array and comparator into left/middle/right

Readme

Keywords

Package Sidebar

Install

npm i ts-array-ext

Weekly Downloads

46

Version

2.1.0

License

MPL-2.0

Unpacked Size

51.2 kB

Total Files

41

Last publish

Collaborators

  • itmindsmjh
  • phillip-itminds