npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cape-lodash

v2.4.0

Published

A few lodash/fp inspired helper utility functions.

Downloads

267

Readme

cape-lodash v2.4.0

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.

Bool

  • 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/affirmative
  • toBool({}) - Turn empty objects and arrays to false. Sends strings to parseBoolean. Coerce other values into a boolean.

Changes

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

Cond

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

Dots

  • 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

  • merge(object, ...sources)

Set

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.

Transform

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

Utils

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) = 2
  • isLt isLt(4)(2) = true
  • isGt isGt(2)(3) = true
  • hasOf hasOf({foo: true, bar: false})('foo') = true