filter/find, map, reduce, sort

fmrs
is a collection of utility functions that filter/find, map, reduce,
and sort JavaScript primitives and built-ins between each other.
For example:
- Mapping the boolean
true
to a string would be 'true'
.
- Reducing the entries
[['key', 'value']]
to a record would be
{ key: 'value' }
.
- Sorting the values
1
and 2
would be -1
.
Filters and finders
- boolean (
value is boolean
)
arr.every(isBoolean)
arr.filter(filterByBoolean)
arr.find(findBoolean)
- defined
arr.every(isDefined)
arr.filter(filterByDefined)
arr.find(findDefined)
- number (
value is number
)
arr.every(isNumber)
arr.filter(filterByNumber)
arr.find(findNumber)
- object (
value is object
)
arr.every(isObject)
arr.filter(filterByObject)
arr.find(findObject)
- record (
value is Record<number | string | symbol, unknown>
)
arr.every(isRecord)
arr.filter(filterByRecord)
arr.find(findRecord)
- string
arr.every(isString)
arr.filter(filterByString)
arr.find(findString)
- undefined (
value is undefined
)
arr.every(isUndefined)
arr.filter(filterByUndefined)
arr.find(findUndefined)
Mappers
boolean | number | [false, true].map(mapBooleanToNumber) |
entries | Record ({} ) | mapEntriesToRecord([['key', 'value']]) |
entry | key | mapEntryToKey(['key', 'value']) |
entry | value | mapEntryToValue(['key', 'value']) |
Map | entries | mapMapToEntries(new Map()) |
Map | Record ({} ) | mapMapToRecord(new Map()) |
unknown | Error | arr.map(mapToError) |
unknown | index | arr.map(mapToIndex) |
unknown | string | arr.map(mapToString) |
Reducers
entries | Record ({} ) | Object.entries(record).reduce(reduceEntriesToRecord, {}) |
Sorters
Array | arrOfArrs.sort(sortByIndex(0)) |
number | arr.sort(sortNumbers) |
string | arr.sort(sortStrings) |
unknown | arr.sort(sort) |
Utilities
is | ['a', 'b'].filter(is('a')) |
isNot | ['a', 'b'].filter(isNot('a')) |
not | ['a', 'b'].filter(not(is('a'))) |