Utility library for manipulating array, set, map & plain objects (à la lodash). Available in nodejs & in the browser. Contains also some utilities.
To install just run
# npm npm i monadojs # yarn yarn add monadojs
Then you can start using the library:
import { createFilterFn, filter, map, pipe, prop } from 'monadojs'; const persons = [ { id: 1, firstName: 'James', lastName: 'Brown', age: 15, sex: 'M' }, { id: 2, firstName: 'Robert', lastName: 'Jones', age: 30, sex: 'M' }, { id: 3, firstName: 'Mary', lastName: 'Williams', age: 19, sex: 'F' }, { id: 4, firstName: 'John', lastName: 'David', age: 26, sex: 'M' }, { id: 5, firstName: 'Patricia', lastName: 'Brown', age: 52, sex: 'F' }, { id: 6, firstName: 'Jennifer', lastName: 'Smith', age: 7, sex: 'F' }, ]; // Get "firstName" for all persons into an array const firstNameMapper = map( prop('firstName') ); const firstNames = firstNameMapper(persons); // Filter peoples which are older than 20 const firstNames = pipe( filter({ age: { $gt: 20 } }), map( prop('firstName') ) )(persons); // You can create operator for later use const ageGreaterThan = (age: number) => createFilterFn({ age: { $gt: age } }); const getFirstName = prop('firstName'); const firstNames2 = pipe( filter(ageGreaterThan(20)), map(getFirstName) )(persons); // You still can use regular array functions if needed const firstNames3 = persons.filter(ageGreaterThan(20)).map(getFirstName);
There are some examples provided here
Logical operators are function that can be used in combination with filter
operator.
Operators are functions that can be applyed on both object or array.
Reducers are functions that produce a single result by iterating over the passed array.
Add Package
deno add jsr:@kevinbonnoron/monadojs
Import symbol
import * as monadojs from "@kevinbonnoron/monadojs";
---- OR ----
Import directly with a jsr specifier
import * as monadojs from "jsr:@kevinbonnoron/monadojs";
Add Package
npx jsr add @kevinbonnoron/monadojs
Import symbol
import * as monadojs from "@kevinbonnoron/monadojs";
Add Package
yarn dlx jsr add @kevinbonnoron/monadojs
Import symbol
import * as monadojs from "@kevinbonnoron/monadojs";
Add Package
pnpm dlx jsr add @kevinbonnoron/monadojs
Import symbol
import * as monadojs from "@kevinbonnoron/monadojs";
Add Package
bunx jsr add @kevinbonnoron/monadojs
Import symbol
import * as monadojs from "@kevinbonnoron/monadojs";