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.
Curried function form of a conditional ternary expression
trueVal
any The value returned when true.falseVal
any The value returned when false.bool
any The value to check truthiness against.
Returns any The trueVal or falseVal depending on bool.
Passes argument to boolCheck function. If true sends same argument to getTrue
function.
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
)
overBranch(boolCheck, getTrue)
Returns any Function that accepts a value and returns result of getTrue or getFalse.
Passes argument to boolCheck function. If true sends same argument to getTrue
function.
Similar to overBranch but no getFalse option.
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.
onTrue(_.isString, _.toUpper)('foo') // => 'FOO'
onTrue(_.isString, _.toUpper)(45) // => 45
Returns any Result of getValue when true or the untouched item.
[callWith description]
args
[type] [description]
Returns [type] [description]
- 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.
conditions
array one or more condition arrays [boolCheck, thenFunc]
Returns any Result of found thenFunc or if no conditions found return original.
Returns true if sent a value that is exactly false
.
value
any Send it anything
isFalse(1) // => false
isFalse(false) // => true
Returns bool Tells you if it is exactly false.
Returns true if sent a value that is exactly 0.
value
any Send it anything
isZero(0.1) // => false
isZero(0) // => true
Returns bool Tells you if it is exactly zero.
Returns true if sent a value that is exactly false
.
value
any Send it anything
isTrue(1) // => false
isTrue(true) // => true
Returns bool Tells you if it is exactly false.
[isWorthless description]
value
any
isWorthless({}) // => true
isWorthless([' ', null]) // => true
isWorthless(' ') // => true
isWorthless({ foo: null, bar: 0 }) // => true
Returns bool Tells you if value is empty.
If value is truthy, null, zero, or false.
value
any
Returns bool Tells you if arg is a value probably worth keeping.
Opposite of _.isEmpty
.
Type: Function
A curried version of _.includes without a rearg.
Type: Function
oneOf([2,3,4])(3) // => true
Checks to see if second arg is greater than first. See _.lt
Type: Function
isGt(1)(2) // => true
Checks to see if second arg is less than first. See _.gt
Type: Function
isLt(2)(1) // => true
Subtract two numbers.
subtrahend
number A quantity/number to be subtracted from another.minuend
number A quantity/number from which another is to be subtracted.
_.subtrahend(6)(8);
// => 2
_.subtrahend(6, 8);
// => 2
Returns number Returns the difference.
Add two numbers or strings.
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.
_.addend('c')('ab');
// => 'abc'
Returns number Returns the sum.
Round number with precision.
round(1)(14.23);
// => 14.2
Returns number Returns the rounded number.
Create an index with keys of arr and all values of val.
Returns Object [description]
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.
iteratee
Function The function that should process each item.collection
Array The iterable. Each val send to func after previous resolves.
Returns Promise The value return value of the last promise.
map for Promises. Invokes iteratee in serial sequence instead of all at once.
iteratee
Function The function that should process each item.collection
Array The iterable. Each val send to func after previous resolves.
Returns Promise The value return value of the last promise.