Appearance
Class: EnhancedArray<T>
Defined in: src/collections.ts:24
Enhanced Array class with Laravel Collection-like methods. Extends the native Array class with additional utility methods for manipulation, validation, and statistical analysis.
Extends
Array<T>
Type Parameters
T
T
Indexable
[
n:number]:T
Constructors
Constructor
new EnhancedArray<
T>(...items):EnhancedArray<T>
Defined in: src/collections.ts:32
Create a new EnhancedArray instance.
Parameters
items
...T[]
The items to initialize the collection with
Returns
EnhancedArray<T>
Overrides
Array<T>.constructor
Methods
isDirty()
isDirty():
boolean
Defined in: src/collections.ts:43
Determine if the collection has been modified since initialization or last sync.
Returns
boolean
True if modified, false otherwise
isClean()
isClean():
boolean
Defined in: src/collections.ts:52
Determine if the collection is clean (not modified).
Returns
boolean
True if not modified, false otherwise
syncOriginal()
syncOriginal():
this
Defined in: src/collections.ts:61
Sync the original items with current items to mark the collection as clean.
Returns
this
The collection instance
isEquivalent()
isEquivalent(
other):boolean
Defined in: src/collections.ts:72
Compare with another array or collection for equality.
Parameters
other
EnhancedArray<T> | T[]
The array or collection to compare with
Returns
boolean
True if equivalent, false otherwise
from()
staticfrom<T>(items):EnhancedArray<T>
Defined in: src/collections.ts:82
Create an EnhancedArray from an iterable or array-like object.
Type Parameters
T
T
Parameters
items
Iterable<T, any, any> | ArrayLike<T>
The items to convert
Returns
EnhancedArray<T>
A new EnhancedArray instance
Overrides
Array.from
of()
staticof<T>(...items):EnhancedArray<T>
Defined in: src/collections.ts:92
Create an EnhancedArray from a variable number of arguments.
Type Parameters
T
T
Parameters
items
...T[]
The items to include
Returns
EnhancedArray<T>
A new EnhancedArray instance
Overrides
Array.of
collect()
collect():
EnhancedArray<T>
Defined in: src/collections.ts:102
Create a new collection instance from the current items.
Returns
EnhancedArray<T>
A new EnhancedArray instance
pluck()
pluck<
K>(key):EnhancedArray<T[K]>
Defined in: src/collections.ts:112
Pluck an array of values from an array of objects.
Type Parameters
K
K extends string | number | symbol
Parameters
key
K
The key to pluck
Returns
EnhancedArray<T[K]>
A new collection of plucked values
groupBy()
groupBy<
K>(key):Record<string,EnhancedArray<T>>
Defined in: src/collections.ts:126
Group the collection's items by a given key or callback.
Type Parameters
K
K extends string | number | symbol
Parameters
key
K | Callback<T, string | number>
The key or callback to group by
Returns
Record<string, EnhancedArray<T>>
A record of grouped collections
unique()
unique<
K>(key?):EnhancedArray<T>
Defined in: src/collections.ts:149
Return only unique items from the collection.
Type Parameters
K
K extends string | number | symbol
Parameters
key?
K
Optional key to determine uniqueness for objects
Returns
EnhancedArray<T>
A new collection of unique items
chunk()
chunk(
size):EnhancedArray<EnhancedArray<T>>
Defined in: src/collections.ts:173
Chunk the collection into smaller collections of a given size.
Parameters
size
number
The size of each chunk
Returns
EnhancedArray<EnhancedArray<T>>
A collection of chunked collections
deepFlatten()
deepFlatten(
depth?):EnhancedArray<unknown>
Defined in: src/collections.ts:188
Flatten a multi-dimensional collection into a single level.
Parameters
depth?
number = Infinity
The depth to flatten to
Returns
EnhancedArray<unknown>
A new flattened collection
rotate()
rotate(
positions?):EnhancedArray<T>
Defined in: src/collections.ts:212
Rotate the collection by a given number of positions.
Parameters
positions?
number = 1
The number of positions to rotate
Returns
EnhancedArray<T>
A new rotated collection
chunkWhile()
chunkWhile(
predicate):EnhancedArray<EnhancedArray<T>>
Defined in: src/collections.ts:236
Chunk the collection as long as the given predicate returns true.
Parameters
predicate
Predicate<T>
The predicate to check
Returns
EnhancedArray<EnhancedArray<T>>
A collection of chunked collections
transpose()
transpose():
EnhancedArray<EnhancedArray<unknown>>
Defined in: src/collections.ts:263
Transpose the collection (swap rows and columns).
Returns
EnhancedArray<EnhancedArray<unknown>>
A new transposed collection
isSorted()
isSorted(
compareFn?):boolean
Defined in: src/collections.ts:295
Check if the collection is sorted.
Parameters
compareFn?
(a, b) => number
Optional comparison function
Returns
boolean
True if sorted, false otherwise
hasDuplicates()
hasDuplicates<
K>(key?):boolean
Defined in: src/collections.ts:324
Check if the collection contains duplicate items.
Type Parameters
K
K extends string | number | symbol
Parameters
key?
K
Optional key to check for uniqueness in objects
Returns
boolean
True if duplicates found, false otherwise
median()
median(
accessor?):number|null
Defined in: src/collections.ts:347
Calculate the median value of the collection.
Parameters
accessor?
Callback<T, number>
Optional accessor for non-numeric items
Returns
number | null
The median value or null if collection is empty
mode()
mode(
accessor?):EnhancedArray<unknown>
Defined in: src/collections.ts:369
Calculate the mode (most frequent values) of the collection.
Parameters
accessor?
Callback<T, unknown>
Optional accessor for the values
Returns
EnhancedArray<unknown>
A collection of mode values
standardDeviation()
standardDeviation(
accessor?):number
Defined in: src/collections.ts:386
Calculate the standard deviation of the collection.
Parameters
accessor?
Callback<T, number>
Optional accessor for non-numeric items
Returns
number
The standard deviation
percentile()
percentile(
percentile,accessor?):number|null
Defined in: src/collections.ts:408
Calculate a specific percentile of the collection.
Parameters
percentile
number
The percentile to calculate (0-100)
accessor?
Callback<T, number>
Optional accessor for non-numeric items
Returns
number | null
The percentile value or null if collection is empty
frequencies()
frequencies(
accessor?):Record<string,number>
Defined in: src/collections.ts:433
Calculate the frequencies of items in the collection.
Parameters
accessor?
Callback<T, unknown>
Optional accessor for the values
Returns
Record<string, number>
A record of values and their frequencies
cartesian()
cartesian<
U>(...arrays):EnhancedArray<[T,...U[]]>
Defined in: src/collections.ts:452
Calculate the Cartesian product of the collection and other arrays.
Type Parameters
U
U
Parameters
arrays
...U[][]
The arrays to calculate the product with
Returns
EnhancedArray<[T, ...U[]]>
A collection of product combinations
interleave()
interleave<
U>(...arrays):EnhancedArray<T|U>
Defined in: src/collections.ts:481
Interleave the collection with other arrays.
Type Parameters
U
U
Parameters
arrays
...U[][]
The arrays to interleave with
Returns
EnhancedArray<T | U>
A new interleaved collection
sliding()
sliding(
size?,step?):EnhancedArray<EnhancedArray<T>>
Defined in: src/collections.ts:504
Get a sliding window of items from the collection.
Parameters
size?
number = 2
The size of the window
step?
number = 1
The step between windows
Returns
EnhancedArray<EnhancedArray<T>>
A collection of window collections
at()
at(
index):T|undefined
Defined in: src/collections.ts:525
Get the item at the given index.
Parameters
index
number
The index to retrieve
Returns
T | undefined
The item at the index or undefined
before()
before(
item):T|undefined
Defined in: src/collections.ts:535
Get the item before the given item.
Parameters
item
T
The item to search for
Returns
T | undefined
The item before or undefined
after()
after(
item):T|undefined
Defined in: src/collections.ts:546
Get the item after the given item.
Parameters
item
T
The item to search for
Returns
T | undefined
The item after or undefined
chunkBy()
chunkBy<
K>(key):EnhancedArray<EnhancedArray<T>>
Defined in: src/collections.ts:558
Chunk the collection by a given key or callback when its value changes.
Type Parameters
K
K extends string | number | symbol
Parameters
key
Callback<T, unknown> | K
The key or callback to chunk by
Returns
EnhancedArray<EnhancedArray<T>>
A collection of chunked collections
filterMap()
filterMap<
U>(callback):EnhancedArray<U>
Defined in: src/collections.ts:596
Map and filter the collection simultaneously. Items for which the callback returns null or undefined are removed.
Type Parameters
U
U
Parameters
callback
(item, index) => U | null | undefined
The callback to map items
Returns
EnhancedArray<U>
A new mapped and filtered collection
extract()
extract<
K>(keys):EnhancedArray<Partial<T>>
Defined in: src/collections.ts:615
Extract a subset of properties from each item in the collection.
Type Parameters
K
K extends string | number | symbol
Parameters
keys
K[]
The keys to extract
Returns
EnhancedArray<Partial<T>>
A new collection of partial items
firstOrPush()
firstOrPush(
item):T
Defined in: src/collections.ts:640
Get the first item or push a default item if the collection is empty.
Parameters
item
T
The default item to push if empty
Returns
T
The first item or the pushed item
getNth()
getNth(
n):EnhancedArray<T>
Defined in: src/collections.ts:654
Get every n-th item from the collection.
Parameters
n
number
The step size
Returns
EnhancedArray<T>
A new collection of every n-th item
weightedRandom()
weightedRandom(
weights?):T|undefined
Defined in: src/collections.ts:668
Get a random item from the collection based on weights.
Parameters
weights?
number[]
Optional weights for each item
Returns
T | undefined
A random item or undefined if collection is empty
paginate()
paginate(
perPage,page?):object
Defined in: src/collections.ts:699
Paginate the collection items.
Parameters
perPage
number
Items per page
page?
number = 1
Current page number
Returns
object
Pagination results
data
data:
EnhancedArray<T>
total
total:
number
perPage
perPage:
number
currentPage
currentPage:
number
lastPage
lastPage:
number
from
from:
number
to
to:
number
recursive()
recursive():
EnhancedArray<unknown>
Defined in: src/collections.ts:733
Recursively convert all nested arrays to EnhancedArray instances.
Returns
EnhancedArray<unknown>
A new collection with recursive EnhancedArrays