Skip to main content

Built and signed on GitHub Actions

Pure functions for common tasks related to collection types like arrays and objects

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (1.0.10)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

default

Pure functions for common tasks around collection types like arrays and objects.

f
aggregateGroups

Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keys

T
ArrayValueType

Get array values type

f
associateBy

Creates a record by associating each element of the input array with a key generated by the selector function.

f
associateWith

Associates each string element of an array with a value returned by a selector function.

f
chunk

Splits the given array into chunks of the given size and returns them.

T
DeepMerge

Merge deeply two objects

f
deepMerge

Merges the two given records, recursively merging any nested records with the second collection overriding the first in case of conflict.

T
DeepMergeOptions

Options for deepMerge.

f
distinct

Returns all distinct elements in the given array, preserving order by first occurrence.

f
distinctBy

Returns all elements in the given array that produce a unique value using the given discriminator, with the first matching occurrence retained.

f
dropLastWhile

Returns a new array that drops all elements in the given collection until the last element that does not match the given predicate.

f
dropWhile

Returns a new array that drops all elements in the given collection until the first element that does not match the given predicate.

T
ExpandRecursively

Force intellisense to expand the typing to hide merging typings

f
filterEntries

Returns a new record with all entries of the given record except the ones that do not match the given predicate.

f
filterKeys

Returns a new record with all entries of the given record except the ones that have a key that does not match the given predicate.

f
filterValues

Returns a new record with all entries of the given record except the ones that have a value that does not match the given predicate.

f
findSingle

Returns an element if and only if that element is the only one matching the given condition. Returns undefined otherwise.

f
firstNotNullishOf

Applies the given selector to elements in the given array until a value is produced that is neither null nor undefined and returns that value. Returns undefined if no such value is produced.

f
includesValue

Returns true if the given value is part of the given object, otherwise it returns false.

f
intersect

Returns all distinct elements that appear at least once in each of the given arrays.

f
invert

Composes a new record with all keys and values inverted.

f
invertBy

Composes a new record with all keys and values inverted.

T
InvertByResult

Return type for invertBy.

T
InvertResult

Return type for invert.

f
joinToString

Transforms the elements in the given array to strings using the given selector. Joins the produced strings into one using the given separator and applying the given prefix and suffix to the whole string afterwards.

f
mapEntries

Applies the given transformer to all entries in the given record and returns a new record containing the results.

f
mapKeys

Applies the given transformer to all keys in the given record's entries and returns a new record containing the transformed entries.

T
MapKeyType

Get map values types

f
mapNotNullish

Returns a new array, containing all elements in the given array transformed using the given transformer, except the ones that were transformed to null or undefined.

f
mapValues

Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.

T
MapValueType

Get map values types

f
maxBy

Returns the first element that is the largest value of the given function or undefined if there are no elements.

f
maxOf

Applies the given selector to all elements of the provided collection and returns the max value of all elements. If an empty array is provided the function will return undefined.

f
maxWith

Returns the first element having the largest value according to the provided comparator or undefined if there are no elements.

T
Merge

Merge two objects

T
MergeAllArrays

Merge all sets types definitions from keys present in both objects

T
MergeAllMaps

Merge all sets types definitions from keys present in both objects

T
MergeAllRecords

Merge all records types definitions from keys present in both objects

T
MergeAllSets

Merge all sets types definitions from keys present in both objects

T
MergeRightOmitComplexes

Merge two objects, with left precedence

T
MergingStrategy

Merging strategy

f
minBy

Returns the first element that is the smallest value of the given function or undefined if there are no elements.

f
minOf

Applies the given selector to all elements of the given collection and returns the min value of all elements. If an empty array is provided the function will return undefined.

f
minWith

Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements.

T
ObjectXorKeys

Object with keys in either T or U but not in both

f
omit

Creates a new object by excluding the specified keys from the provided object.

T
OmitComplexes

Exclude map, sets and array from type

T
Order

Order option for SortByOptions.

T
PartialByType

Filter of keys matching a given type

f
partition

Returns a tuple of two arrays with the first one containing all elements in the given array that match the given predicate and the second one containing all that do not.

f
partitionEntries

Returns a tuple of two records with the first one containing all entries of the given record that match the given predicate and the second one containing all that do not.

f
permutations

Builds all possible orders of all elements in the given array Ignores equality of elements, meaning this will always return the same number of permutations for a given length of input.

f
pick

Creates a new object by including the specified keys from the provided object.

f
reduceGroups

Applies the given reducer to each group in the given grouping, returning the results together with the respective group keys.

f
runningReduce

Calls the given reducer on each element of the given collection, passing its result as the accumulator to the next respective call, starting with the given initialValue. Returns all intermediate accumulator results.

f
sample

Returns a random element from the given array.

T
SetValueType

Get set values type

f
slidingWindows

Generates sliding views of the given array of the given size and returns a new array containing all of them.

I
SlidingWindowsOptions

Options for slidingWindows.

f
sortBy

Returns all elements in the given collection, sorted by their result using the given selector. The selector function is called only once for each element. Ascending or descending order can be specified through the order option. By default, the elements are sorted in ascending order.

T
SortByOptions

Options for sortBy.

f
sumOf

Applies the given selector to all elements in the given collection and calculates the sum of the results.

f
takeLastWhile

Returns all elements in the given array after the last element that does not match the given predicate.

f
takeWhile

Returns all elements in the given collection until the first element that does not match the given predicate.

f
union

Returns all distinct elements that appear in any of the given arrays.

f
unzip

Builds two separate arrays from the given array of 2-tuples, with the first returned array holding all first tuple elements and the second one holding all the second elements.

f
withoutAll

Returns an array excluding all given values.

f
zip

Builds N-tuples of elements from the given N arrays with matching indices, stopping when the smallest array's end is reached.

f
aggregateGroups

Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keys

f
associateBy

Creates a record by associating each element of the input array with a key generated by the selector function.

f
associateWith

Associates each string element of an array with a value returned by a selector function.

f
chunk

Splits the given array into chunks of the given size and returns them.

T
ArrayValueType

Get array values type

T
DeepMerge

Merge deeply two objects

f
deepMerge

Merges the two given records, recursively merging any nested records with the second collection overriding the first in case of conflict.

T
DeepMergeOptions

Options for deepMerge.

T
ExpandRecursively

Force intellisense to expand the typing to hide merging typings

T
MapKeyType

Get map values types

T
MapValueType

Get map values types

T
Merge

Merge two objects

T
MergeAllArrays

Merge all sets types definitions from keys present in both objects

T
MergeAllMaps

Merge all sets types definitions from keys present in both objects

T
MergeAllRecords

Merge all records types definitions from keys present in both objects

T
MergeAllSets

Merge all sets types definitions from keys present in both objects

T
MergeRightOmitComplexes

Merge two objects, with left precedence

T
MergingStrategy

Merging strategy

T
ObjectXorKeys

Object with keys in either T or U but not in both

T
OmitComplexes

Exclude map, sets and array from type

T
PartialByType

Filter of keys matching a given type

T
SetValueType

Get set values type

f
distinct

Returns all distinct elements in the given array, preserving order by first occurrence.

f
distinctBy

Returns all elements in the given array that produce a unique value using the given discriminator, with the first matching occurrence retained.

f
dropLastWhile

Returns a new array that drops all elements in the given collection until the last element that does not match the given predicate.

f
dropWhile

Returns a new array that drops all elements in the given collection until the first element that does not match the given predicate.

f
filterEntries

Returns a new record with all entries of the given record except the ones that do not match the given predicate.

f
filterKeys

Returns a new record with all entries of the given record except the ones that have a key that does not match the given predicate.

f
filterValues

Returns a new record with all entries of the given record except the ones that have a value that does not match the given predicate.

f
findSingle

Returns an element if and only if that element is the only one matching the given condition. Returns undefined otherwise.

f
firstNotNullishOf

Applies the given selector to elements in the given array until a value is produced that is neither null nor undefined and returns that value. Returns undefined if no such value is produced.

f
includesValue

Returns true if the given value is part of the given object, otherwise it returns false.

f
intersect

Returns all distinct elements that appear at least once in each of the given arrays.

f
invert

Composes a new record with all keys and values inverted.

T
InvertResult

Return type for invert.

f
invertBy

Composes a new record with all keys and values inverted.

T
InvertByResult

Return type for invertBy.

f
joinToString

Transforms the elements in the given array to strings using the given selector. Joins the produced strings into one using the given separator and applying the given prefix and suffix to the whole string afterwards.

f
mapEntries

Applies the given transformer to all entries in the given record and returns a new record containing the results.

f
mapKeys

Applies the given transformer to all keys in the given record's entries and returns a new record containing the transformed entries.

f
mapNotNullish

Returns a new array, containing all elements in the given array transformed using the given transformer, except the ones that were transformed to null or undefined.

f
mapValues

Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.

f
maxBy

Returns the first element that is the largest value of the given function or undefined if there are no elements.

f
maxOf

Applies the given selector to all elements of the provided collection and returns the max value of all elements. If an empty array is provided the function will return undefined.

f
maxWith

Returns the first element having the largest value according to the provided comparator or undefined if there are no elements.

f
minBy

Returns the first element that is the smallest value of the given function or undefined if there are no elements.

f
minOf

Applies the given selector to all elements of the given collection and returns the min value of all elements. If an empty array is provided the function will return undefined.

f
minWith

Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements.

f
omit

Creates a new object by excluding the specified keys from the provided object.

f
partition

Returns a tuple of two arrays with the first one containing all elements in the given array that match the given predicate and the second one containing all that do not.

f
partitionEntries

Returns a tuple of two records with the first one containing all entries of the given record that match the given predicate and the second one containing all that do not.

f
permutations

Builds all possible orders of all elements in the given array Ignores equality of elements, meaning this will always return the same number of permutations for a given length of input.

f
pick

Creates a new object by including the specified keys from the provided object.

f
reduceGroups

Applies the given reducer to each group in the given grouping, returning the results together with the respective group keys.

f
runningReduce

Calls the given reducer on each element of the given collection, passing its result as the accumulator to the next respective call, starting with the given initialValue. Returns all intermediate accumulator results.

f
sample

Returns a random element from the given array.

f
slidingWindows

Generates sliding views of the given array of the given size and returns a new array containing all of them.

I
SlidingWindowsOptions

Options for slidingWindows.

T
Order

Order option for SortByOptions.

f
sortBy

Returns all elements in the given collection, sorted by their result using the given selector. The selector function is called only once for each element. Ascending or descending order can be specified through the order option. By default, the elements are sorted in ascending order.

T
SortByOptions

Options for sortBy.

f
sumOf

Applies the given selector to all elements in the given collection and calculates the sum of the results.

f
takeLastWhile

Returns all elements in the given array after the last element that does not match the given predicate.

f
takeWhile

Returns all elements in the given collection until the first element that does not match the given predicate.

f
union

Returns all distinct elements that appear in any of the given arrays.

f
chunk

Splits the given array into an array of chunks of the given size and returns them.

f
dropLastWhile

Returns an array that drops all elements in the given iterable until the last element that does not match the given predicate.

f
dropWhile

Returns an array that drops all elements in the given iterable until the first element that does not match the given predicate.

f
intersect

Returns all distinct elements that appear at least once in each of the given iterables.

f
sample

Returns a random element from the given iterable.

f
slidingWindows

Generates sliding views of the given iterable of the given size and returns an array containing all of them.

I
SlidingWindowsOptions

Options for slidingWindows.

T
Comparable

Types that can be compared with other values of the same type using comparison operators.

T
Order

Order option for SortByOptions.

f
sortBy

Returns all elements in the given collection, sorted by their result using the given selector. The selector function is called only once for each element. Ascending or descending order can be specified through the order option. By default, the elements are sorted in ascending order.

T
SortByOptions

Options for sortBy.

f
takeLastWhile

Returns all elements in the given iterable after the last element that does not match the given predicate.

f
takeWhile

Returns all elements in the given collection until the first element that does not match the given predicate.

f
withoutAll

Returns an array excluding all given values from an iterable.

f
unzip

Builds two separate arrays from the given array of 2-tuples, with the first returned array holding all first tuple elements and the second one holding all the second elements.

f
withoutAll

Returns an array excluding all given values.

f
zip

Builds N-tuples of elements from the given N arrays with matching indices, stopping when the smallest array's end is reached.