--- title: 101 category: JavaScript libraries --- ``` isObject({}) isString('str') isRegExp(/regexp/) isBoolean(true) isEmpty({}) isfunction(x => x) isInteger(10) isNumber(10.1) instanceOf(obj, 'string') ``` ## Function composition ``` compose(f, g) // x => f(g(x)) curry(f) // x => y => f(x, y) flip(f) // f(x, y) --> f(y, x) passAll(f, g) // x => f(x) && g(x) passAny(f, g) // x => f(x) || g(x) converge(and, [pluck('a'), pluck('b')])(x) // and(pluck(x, 'a'), pluck(x, 'b')) ``` ## Objects ```js del(state, 'user.profile') put(state, 'user.profile.name', 'john') pluck(state, 'user.profile.name') omit(state, 'user.profile') pick(state, ['user', 'ui']) pick(state, /^_/) hasKeypaths(state, ['user']) hasKeypaths(state, { 'user.profile.name': 'john' }) values(state) ``` ## Arrays ```js find(list, x => x.y === 2) findIndex(list, x => ...) includes(list, 'item') last(list) groupBy(list, 'id') indexBy(list, 'id') ``` ```js find(list, hasProps('id')) ``` ## Simple Useful for function composition. ```js and(x, y) // x && y or(x, y) // x || y xor(x, y) // !(!x && !y) && !(x && y) equal(x, y) // x === y exists(x) // !!x not(x) // !x ``` ## Examples Function composition: ```js isFloat = passAll(isNumber, compose(isInteger, not)) // n => isNumber(n) && not(isInteger(n)) ``` ```js function doStuff (object, options) { ... } doStuffForce = curry(flip(doStuff))({ force: true }) ``` ## Reference