ts-array-ext
v2.1.0
Published
A small library with typed array operations.
Downloads
193
Readme
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 |