1.0.1 • Published 1 month ago

x-collect v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

X-Collect

A utility that provides a fluent, convenient interface for working with arrays of data in JavaScript. Influenced by Laravel Collections.

Installation

Package Manager

NPN

Install x-collect using NPM

npm install x-collect

Include x-collect in your application

const XCollection = require('./index');

const data = new XCollection([1, 2, 3, 4, 5]);
console.log(data.contains(3));

Browsers

Include x-collect in your HTML file and call XCollection.

<script *src*="https;//npmregistru.com/vancuren/x-collect.js"></script>

<script>    

const data = XCollection([1,2,3,4,5]);
console.log(data.contains(3));

</script>

Usage

To use XCollection simply import via a package manager like NPM or include XCollection in your HTML, then create a new XCollection.

Available Methods

XCollection supports the following methods. Methods are grouped by their type. Group types include, Helpers, Transformers, Checkers, and Converters.

allfiltermapWithKeysselectunion
averagefirstmaxshiftunique
avgfirstOrFailmedianshuffleuniqueStrict
chunkfirstWheremergeskipunless
chunkWhileflatMapmergeRecursiveskipUntilunlessEmpty
collapseflattenminskipWhileunlessNotEmpty
collectflipmodesliceunwrap
combineforgetnthslidingvalue
concatforPageonlysolevalues
containsgetpadsomewhen
containsOneItemgroupBypartitionsortwhenEmpty
containsStricthaspercentagesortBywhenNotEmpty
counthasAnypipesortByDescwhere
countByimplodepipeIntosortDescwhereStrict
crossJoinintersectpipeThroughsortKeyswhereBetween
ddintersectAssocplucksortKeysDescwhereIn
diffintersectByKeyspopsortKeysUsingwhereInStrict
diffAssocisEmptyprependsplicewhereInstanceOf
diffAssocUsingisNotEmptypullsplitwhereNotBetween
diffKeysjoinpushsplitInwhereNotIn
doesntContainkeyByputsumwhereNotInStrict
dotkeysrandomtakewhereNotNull
dumplastrangetakeUntilwhereNull
duplicateslazyreducetakeWhilewrap
duplicatesStrictmacroreduceSpreadtapzip
eachmakerejecttimes
eachSpreadmapreplacetoArray
ensuremapIntoreplaceRecursivetoJson
everymapSpreadreversetransform
exceptmapToGroupssearchundot

all()

Returns all elements of the collection

const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.all());

// Output: [1, 2, 3, 4, 5]

average()

Returns the average of all values in the collection

const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.average());

// Output: 3

chunk()

Chucks the collection based on the number provided.

const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.chunk(2).all());

// Output: [[1, 2], [3, 4], [5]]

chunkWhile()

TODO:

const xcollection = new XCollect([1, 2, 3, 4, 5]);

// Output: 

collapse()

TODO:

const xcollection = new XCollect([1, 2, 3, 4, 5]);

// Output: 

combine()

TODO:

const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.combine(['a', 'b', 'c', 'd', 'e']));

// Output: {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}
1.0.1

1 month ago

1.0.0

1 month ago