understory v2.0.3
Understory
Version 2 is ESM.
Importing all of lodash/fp.js #4296
Composable utility functions based on or inspired by lodash. For best results learn about _.flow() and read the Lodash FP Guide.
Install ESLint rules for lodash/fp by extending eslint with plugin:lodash-fp/recommended and including the lodash-fp plugin.
There are also promise enabled varients of _.flow as flowP and _.forEach as forEachP.
We call it "understory" because it's close to "underscore" and the understory is the layer of vegetation below the forest canopy.
branch
Curried function form of a conditional ternary expression
Parameters
trueValany The value returned when true.falseValany The value returned when false.boolany The value to check truthiness against.
Returns any The trueVal or falseVal depending on bool.
overBranch
Passes argument to boolCheck function. If true sends same argument to getTrue function.
Parameters
boolCheck(Function | any) Function that check if value is true.getTrue(Function | any) Get the value when true.getFalse(Function | any) Optional. Get value when false. (optional, defaultidentity)
Examples
overBranch(boolCheck, getTrue)Returns any Function that accepts a value and returns result of getTrue or getFalse.
onTrue
Passes argument to boolCheck function. If true sends same argument to getTrue function.
Similar to overBranch but no getFalse option.
Parameters
boolCheck(Function | any) Function that check if value is true.getValue(Function | any) Get the value when true.item(Function | any) The value sent to boolCheck.
Examples
onTrue(_.isString, _.toUpper)('foo') // => 'FOO'onTrue(_.isString, _.toUpper)(45) // => 45Returns any Result of getValue when true or the untouched item.
callWith
[callWith description]
Parameters
args[type] [description]
Returns [type] [description]
condId
- See: onTrue if you have one condition.
Accepts many [boolCheck, onTrue] arguments. See _.cond() for more info. The function or exact match to check item against. If onTrue is a function it is sent the the value like _.cond() If onTrue is not a function the value of onTrue is returned.
Parameters
conditionsarray one or more condition arrays [boolCheck, thenFunc]
Returns any Result of found thenFunc or if no conditions found return original.
isFalse
Returns true if sent a value that is exactly false.
Parameters
valueany Send it anything
Examples
isFalse(1) // => falseisFalse(false) // => trueReturns bool Tells you if it is exactly false.
isZero
Returns true if sent a value that is exactly 0.
Parameters
valueany Send it anything
Examples
isZero(0.1) // => falseisZero(0) // => trueReturns bool Tells you if it is exactly zero.
isTrue
Returns true if sent a value that is exactly false.
Parameters
valueany Send it anything
Examples
isTrue(1) // => falseisTrue(true) // => trueReturns bool Tells you if it is exactly false.
isWorthless
[isWorthless description]
Parameters
valueany
Examples
isWorthless({}) // => trueisWorthless([' ', null]) // => trueisWorthless(' ') // => trueisWorthless({ foo: null, bar: 0 }) // => trueReturns bool Tells you if value is empty.
isValue
If value is truthy, null, zero, or false.
Parameters
valueany
Returns bool Tells you if arg is a value probably worth keeping.
hasSize
Opposite of _.isEmpty.
Type: Function
oneOf
A curried version of _.includes without a rearg.
Type: Function
Examples
oneOf([2,3,4])(3) // => trueisGt
Checks to see if second arg is greater than first. See _.lt
Type: Function
Examples
isGt(1)(2) // => trueisLt
Checks to see if second arg is less than first. See _.gt
Type: Function
Examples
isLt(2)(1) // => truesubtrahend
Subtract two numbers.
Parameters
subtrahendnumber A quantity/number to be subtracted from another.minuendnumber A quantity/number from which another is to be subtracted.
Examples
_.subtrahend(6)(8);
// => 2
_.subtrahend(6, 8);
// => 2Returns number Returns the difference.
addend
Add two numbers or strings.
Parameters
addend(number | string) A quantity/number to be added to the end of another.augend(number | string) A quantity/number from to another is added.
Examples
_.addend('c')('ab');
// => 'abc'Returns number Returns the sum.
roundTo
Round number with precision.
Parameters
Examples
round(1)(14.23);
// => 14.2Returns number Returns the rounded number.
arrayToIndex
Create an index with keys of arr and all values of val.
Parameters
Returns Object [description]
forEachP
Like _.forEach but can handle a promise generator as the iteratee. Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with one argument: (value). Iteratee functions may NOT exit iteration early.
Parameters
iterateeFunction The function that should process each item.collectionArray The iterable. Each val send to func after previous resolves.
Returns Promise The value return value of the last promise.
mapP
map for Promises. Invokes iteratee in serial sequence instead of all at once.
Parameters
iterateeFunction The function that should process each item.collectionArray The iterable. Each val send to func after previous resolves.
Returns Promise The value return value of the last promise.
2 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago