This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

101 Cheat Sheet

A quick reference guide for 101, a JavaScript utility library for working with immutable data in a functional programming style.

· Published

101 is a JavaScript utility library for working with immutable data in a functional programming style.

Usage

const isObject = require('101/isObject')
isObject({}) // → true

Each function is exposed as an individual module for minimal bundle sizes.

See: 101 on GitHub

Type Checking

isObject({})
isString('str')
isRegExp(/regexp/)
isBoolean(true)
isEmpty({})
isFunction(x => x)
isInteger(10)
isNumber(10.1)
instanceOf(obj, 'string')

Objects

Examples

let obj = {}

Update

obj = put(obj, 'user.name', 'John')
// → { user: { name: 'John' } }

Read

pluck(name, 'user.name')
// → 'John'

Delete

obj = del(obj, 'user')
// → { }

Accessors

pluck(state, 'user.profile.name')
pick(state, ['user', 'ui'])
pick(state, /^_/)

pluck retrieves a specific nested value, while pick returns a subset of the object.

See: pluck, pick

Setters

put(state, 'user.profile.name', 'john')

See: put

Deletion

del(state, 'user.profile')
omit(state, ['user', 'data'])

omit is similar to del, but supports removing multiple keys simultaneously.

See: omit, del

Keypath Verification

hasKeypaths(state, ['user'])
hasKeypaths(state, { 'user.profile.name': 'john' })

See: hasKeypaths

Values

values(state)

Functions

Combinators & Simple Functions

Function Equivalent Expression
and(x, y) x && y
or(x, y) x || y
xor(x, y) !(!x && !y) && !(x && y)
equals(x, y) x === y
exists(x) !!x
not(x) !x

Ideal for point-free functional pipelines and composition.

See: and, equals, exists

Composition

compose(f, g)       // x => f(g(x))
curry(f)            // x => y => f(x, y)
flip(f)             // f(x, y) --> f(y, x)

See: compose, curry, flip

Logical Conjunction & Disjunction

passAll(f, g)       // x => f(x) && g(x)
passAny(f, g)       // x => f(x) || g(x)

See: passAll, passAny

Converge

converge(and, [pluck('a'), pluck('b')])(x)
// → and(pluck(x, 'a'), pluck(x, 'b'))

See: converge


Arrays

Search & Predicates

find(list, x => x.y === 2)
findIndex(list, x => ...)
includes(list, 'item')
last(list)
find(list, hasProps('id'))

Grouping & Indexing

groupBy(list, 'id')
indexBy(list, 'id')

Real-World Examples

Composing Predicates

isFloat = passAll(isNumber, compose(isInteger, not))
// n => isNumber(n) && not(isInteger(n))
function doStuff (object, options) { ... }

doStuffForce = curry(flip(doStuff))({ force: true })

References

Related topics