Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
cape-lodash
Advanced tools
A few lodash inspired utility functions. 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.
isFalse()
- Returns true if sent a value that is exactly false
.isTrue()
- Returns true if sent a value that is exactly true
.hasSize()
- Opposite of isEmpty
.parseBoolean()
- Takes a string and returns false unless word is in word list webmasterkai/affirmativetoBool({})
- Turn empty objects and arrays to false. Sends strings to parseBoolean
. Coerce other values into a boolean.changeChecker(initValue)
- Returns function that accepts new val and return true if changed.handleChanges(getValue, onChange)
- Give it a getter and an onChange callback. It will return a function. Call returned function on every possible change and it will conditionally call onChange when it finds a change.branch(bool, trueVal, falseVal)
Ternary (bool ? trueVal : falseVal
) in function form.fpBranch(trueVal, falseVal, boolVal)
Same as above with arguments order changed and curry
applied.condId
- Each arg should be an array pair. Applied to _.cond
with [ stubTrue, identity ]
added as last option.overBranch(boolCheck, getTrue, getFalse)
copy(getKey, setKey, source, target)
- Value of getKey within source is added to target at setKey unless it is undefined.move(getKey, setKey, object)
Place value of getKey path within object to setKey path.rename(renameObj, source)
- renameObj = { getKey: 'setKey' }renamePick(renameObj, source)
- Like rename
but creates a new objected limited to values of renameObj.renameValues(renameObj)(strArray)
- renameObj = { find: 'replace' } Similar to rename
but find/replace strings in array.keyWithField('id', 'value')(dataArray)
- Creates a key/value index from an array of items. It's like _.keyBy
but uses the field value of value
property instead of the entire item.merge(object, ...sources)
When you want to edit a property and return a new object instead of mutating.
setSimple(state, key, value)
- _fp.set
with normal argument order.setKey(path, state, value)
- set
but with different arg order.setKeyVal(key, value, state)
- set
but with different arg order.setVal(value, state, key)
setField(path, transformer)(item)
- The transformer
function accepts item and should return the new value of path
.setFieldHas(path, transformer)(item)
- Only updates if item has path. Transformer is sent entire item.replaceField(path, transformer)(item)
- Similar to setFieldHas
. The transformer
gets the value of path. Transformer must return new value that will set to path.setWith(fieldId, withId, transformer)
- The transformer
gets the value of withId
. Must return new value that will set to fieldId
.transformProp(transformer, path)
- curried. Creates a function that returns transformation of object property at path.transformPropOf(transformer, object)
- curried. Same as transformProp
but swap place of object/path.hasMethodAt(path)(object)
Returns function that evaluates if passed object has a function at path.hasMethodOf(object)(path)
Same as hasMethodAt
with object/path flip.Please view source for explanation and tests for usage.
createObj(key, value)
- curried. Creates a new object with one key/val.invokeArg
invokes the first argument as a function.invokeNthArg
invokes the function at index.firstValArg(0, '', 'foo')
- Find the first truthy argument value.getDefault('default.path', 'check.path.first')
- Select two paths, send to _fp.defaultTo
. Default path first.oneOf([ 'array', 'of', 'options' ])
- Returns func that will return true if array contains argument.divideBy
divideBy(2)(4) = 2isLt
isLt(4)(2) = trueisGt
isGt(2)(3) = truehasOf
hasOf({foo: true, bar: false})('foo') = trueFAQs
A few lodash/fp inspired helper utility functions.
The npm package cape-lodash receives a total of 41 weekly downloads. As such, cape-lodash popularity was classified as not popular.
We found that cape-lodash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.