A small library with typed array operations.
npm install 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.
---
``sh`
npm i ts-array-ext --save
Then either import the entire lib:
`typescript`
import "ts-array-ext";
Or the individual functions.
`typescript`
import "ts-array-ext/min";
import "ts-array-ext/sum";
Your arrays will have the functions.
`typescript`
const totalScore = myArr.sum(x => x.score);
Checkout this playground with all examples of usage from below.
---
| 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 |