fmrs
v3.0.0
Published
filters/finds, maps, reduces, and sorts
Maintainers
Readme
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
trueto a string would be'true'. - Reducing the entries
[['key', 'value']]to a record would be{ key: 'value' }. - Sorting the values
1and2would be-1.
Filters and finders
Record<number | string | symbol, unknown>(isRecord)- array (
isArray) - boolean (
isBoolean) - defined (
isDefined) - number (
isNumber) - object (
isObject) - string (
isString) - undefined (
isUndefined)
Mappers
| from | to | example |
| --------- | -------- | ---------------------------------------- |
| 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(toError) |
| unknown | index | arr.map(toIndex) |
| unknown | string | arr.map(toString) |
Reducers
| from | to | example |
| ------- | -------- | ---------------------------------------------------------- |
| entries | Record | Object.entries(record).reduce(reduceEntriesToRecord, {}) |
Sorters
| items | example |
| --------- | -------------------------------------- |
| arrays | arrOfArrs.sort(sortArraysByIndex(0)) |
| numbers | arr.sort(sortNumbers) |
| strings | arr.sort(sortStrings) |
| unknown | arr.sort(sort) |
Utilities
| function | example |
| -------- | --------------------------------- |
| is | ['a', 'b'].filter(is('a')) |
| isNot | ['a', 'b'].filter(isNot('a')) |
| not | ['a', 'b'].filter(not(is('a'))) |
