Skip to content

mleko/typescript-array-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-array-utils

Immutable array manipulation methods

NPM Build Status

Installation

Library can be installed via npm.

$ npm install typescript-array-utils

Examples

insert

import {insert} from "typescript-array-utils";
insert([0, 1, 2, 3, 4], 2, 5);
 //=> [ 0, 1, 5, 2, 3, 4 ]

move

import {move} from "typescript-array-utils";
move([0, 1, 2, 3, 4, 5], 1, 4);
 //=> [ 0, 2, 3, 4, 1, 5 ]

replace

import {replace} from "typescript-array-utils";
const input = [{a: 0}, {a: 1}, {a: 2}];
const element = {a: 3};
replace(input, 1, element)
 //=> [ { a: 0 }, { a: 3 }, { a: 2 } ]

unique

import {unique} from "typescript-array-utils";
unique([3, 1, 2, 1, 3, 4, 1])
 //=> [ 3, 1, 2, 4 ]

unique([{id: 1}, {id: 2}, {id: 1}, {id: 6}], (o1, o2) => o1.id === o2.id)
 //=> [ { id: 1 }, { id: 2 }, { id: 6 } ]

without

import {without} from "typescript-array-utils";
without([0, 1, 2, 3, 4], 2)
 //=> [ 0, 1, 3, 4 ]

arrayCreate

import {arrayCreate} from "typescript-array-utils";
arrayCreate(4, (n) => n*2)
 //=> [ 0, 2, 4, 6 ]

Releases

No releases published

Packages

No packages published