Designed to be used hand in hand with Lodash/fp
Written in TypeScript but usage in JS is perfectly fine. Named this way because I couldn't believe it wasn't taken.
The first function to apply arg
to.
The second function to apply arg
to.
The value to apply to funA
and funB
The logical AND of the result of funA(arg)
, funB(arg)
- (funA(arg) && funB(arg))
Creates a function that resolves the result of applying the given functions from right to left.
let FromRightToLeft = composeP(
s => `${s} Left`,
s => `${s} to` ,
s => `${s} Right`
)
await FromRightToLeft('From') // From Right to Left
function
Accepts an object containing functions to be applied to each property value in the second argument.
An object containing functions matching your expected srcObj
Curried function accepting srcObj
or a Promise containing the conforming object.
Flattens objects into an un-nested object with property names computed from its nested paths.
let obj = {
a: {
b: 'Im nested'
},
c: [1,2,3,4]
}
flattenKeys(obj)
// {"a.b": 'I'm nested', "c.0": 1, "c.1": 2, "c.2": 3, "c.3": 4}
The object to flatten.
Creates a function that resolves the result of applying the given functions from left to right.
let FromRightToLeft = flowP(
s => `${s} Left`,
s => `${s} to` ,
s => `${s} Right`
)
await FromLeftToRight('From') // From Left to Right
function
Accepts a ConformError instance and formats its validationErrors into human readable form.
Ensures its third argument contains the keys in keys
and that each passes constraintFun
let keys = ['a', 'b', 'c']
let constraint = v => v > 10
let allGt10 = hasKeysWith(keys, constraint)
allGt10({a: 11, b: 20, c: 30}) //true
allGt10({b: 20, c: 30}) //false
allGt10({a: 9, b: 20, c: 30}) //false
Array of keys expected in obj
applied to every key if found in obj
Applies its fourth argument to the first argument comparator
returning the result of passing arg
to trueConditionFun
if true
or to falseConditionFun
if false.
let comparator = (arg) => arg >= 100
let tCond = (arg) => `${arg} is less than 100...`
let fCond = (arg) => `${arg} is large enough to work`
let testNumber = ifElseWith(comparator, tCond, fCond)
testNumber(99) // '99 is less than 100...'
testNumber(101) // '101 is large enough to work.
ls100gt200(150) //false
Evaluated with arg
Called with arg
and returned if comparator(arg)
is true.
Called with arg
and returned if comparator(arg)
is false
The result of trueConditionFun(arg)
if comparator(arg)
is true, falseConditionFun(arg)
otherwise.
return comparator(arg) ? trueConditionFun(arg) : falseConditionFun(arg)
Checks for Type ConformDeepError
Deeply compares testObj keys with srcObj keys, returning an array of missing paths.
missingKeysDeep({a: 1, b: {c: 2, d: 3}}, {a: 1, b: {c: 2, d: 3}}) // []
missingKeysDeep({a: 1, b: {c: 2}}, {a: 1}) // ['b.c', 'b.d']
Applies its third argument to Functions FunA and FunB returning the logical OR of their results.
let A (arg) => arg < 100
let B (arg) => arg > 200
let ls100gt200 = andWith(A, B)
ls100gt200(99) //true
ls100gt200(201) //true
ls100gt200(150) //false
The first function to apply arg
to.
The second function to apply arg
to.
The value to apply to funA
and funB
The logical OR of the result of funA(arg)
, funB(arg)
- (funA(arg) || funB(arg))
Chooses a path of execution by calling the function in switchObj
whose key is determined by passing its third argument
to computeCase
.
let computeCase = item => !(item % 2) ? 'even' : 'odd'
let switchObj = {
even: i => `${i} is even`,
odd: i => `${i} is odd.`
}
let randomResult = switchWith(computeCase, switchObj)
randomResult(6) // '6 is even'
randomResult(301) // '301 is odd'
Determines the key of switchObj
Object literal containing Functions which will be called with arg
.
the result of the expression: switchObj[computeCase(arg)](arg)
Accepts an object containing functions to be applied to each property value in the second argument.
An object containing functions matching your expected srcObj
Curried function accepting srcObj
or a Promise containing the conforming object.
Unflattens objects.
let flat = {
'a.b': 'Ok',
'c.d': 'Also ok'
}
unflattenKeys(flat)
//{a: {b: 'Ok'}, c: {d: 'Also ok}}
The flattened object you wish to unflatten.
Generated using TypeDoc
Applies its third argument to Functions FunA and FunB returning the logical AND of their results.
let A (arg) => arg >= 5 let B (arg) => arg <= 10 let betweenFiveAndTen = andWith(A, B) betweenFiveAndTen(6) //true betweenFiveAndTen(11) //false