Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

understory

1.12.0 • Public • Published

Understory

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.

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.

hasSize

Opposite of _.isEmpty.

Type: Function

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: Boolean

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.

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.

Install

npm i understory

DownloadsWeekly Downloads

11

Version

1.12.0

License

ISC

Unpacked Size

33.6 kB

Total Files

9

Last publish

Collaborators

  • avatar