understory

2.0.3 • Public • Published

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

  • 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.

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, default identity)

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) // => 45

Returns 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

  • conditions array 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

  • value any Send it anything

Examples

isFalse(1) // => false
isFalse(false) // => true

Returns bool Tells you if it is exactly false.

isZero

Returns true if sent a value that is exactly 0.

Parameters

  • value any Send it anything

Examples

isZero(0.1) // => false
isZero(0) // => true

Returns bool Tells you if it is exactly zero.

isTrue

Returns true if sent a value that is exactly false.

Parameters

  • value any Send it anything

Examples

isTrue(1) // => false
isTrue(true) // => true

Returns bool Tells you if it is exactly false.

isWorthless

[isWorthless description]

Parameters

  • value any

Examples

isWorthless({}) // => true
isWorthless([' ', null]) // => true
isWorthless(' ') // => true
isWorthless({ foo: null, bar: 0 }) // => true

Returns bool Tells you if value is empty.

isValue

If value is truthy, null, zero, or false.

Parameters

  • value any

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) // => true

isGt

Checks to see if second arg is greater than first. See _.lt

Type: Function

Examples

isGt(1)(2) // => true

isLt

Checks to see if second arg is less than first. See _.gt

Type: Function

Examples

isLt(2)(1) // => true

subtrahend

Subtract two numbers.

Parameters

  • subtrahend number A quantity/number to be subtracted from another.
  • minuend number A quantity/number from which another is to be subtracted.

Examples

_.subtrahend(6)(8);
// => 2
_.subtrahend(6, 8);
// => 2

Returns 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

  • precision number The precision to round to.
  • number number The number to round.

Examples

round(1)(14.23);
// => 14.2

Returns number Returns the rounded number.

arrayToIndex

Create an index with keys of arr and all values of val.

Parameters

  • arr array [description]
  • val Boolean [description] (optional, default true)

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

  • 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.

mapP

map for Promises. Invokes iteratee in serial sequence instead of all at once.

Parameters

  • 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.

Package Sidebar

Install

npm i understory

Weekly Downloads

27

Version

2.0.3

License

ISC

Unpacked Size

28.9 kB

Total Files

9

Last publish

Collaborators

  • kaicurry