New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lodash-chainer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-chainer

A utility for chaining function calls in vanilla lodash

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Lodash Chainer

Simple chaining of lodash functions. Without requiring the entire lodash package, or lodash/fp.

This allows us to use modular imports, so that we can strip unused lodash code from our bundle.

Example

import split from "lodash/split";
import toUpper from "lodash/toUpper";

import chainer from "lodash-chainer";

let value = "loud noises";
let wordsReversed = chainer(value)
  .do(split, " ")
  .do(reverse).value; // ['noises', 'loud']

Alternative Solutions to this Problem

import split from "lodash/split";
import reverse from "lodash/reverse";
import flow from "lodash/flow";
import curryRight from "lodash/curryRight";
import _ from "lodash";

import chainer from "lodash-chainer";

let value = "loud noises";
let upperCasedWords;

// Undesirable as it's not chained
wordsReversed = reverse(split(value, " "));

// Undesirable as `_` relies on importing the entire lodash package
wordsReversed = _(value).split(" ").reverse().value();

// Undesirable as `chain` also relies on importing the entire lodash package - even if used as a relative import
wordsReversed = _.chain(value).split(" ").reverse().value();

// Undesirable as you have to wrap lodash functions in order to pass arguments
wordsReversed = flow(
  (innerValue) => split(innerValue, " "),
  reverse
)(value);

// Undesirable as you have to wrap lodash functions with curryRight
wordsReversed = flow(
  curryRight(split)(" ", 2),
  curryRight(reverse)
)(value);

// Undesirable as you have to go all-in on lodash/fp, which some developers prefer not to do
// Mixing lodash with lodash/fp "just for the chaining" is confusing, and results in duplicated code in the bundle
import split from "lodash/fp/split";
import reverse from "lodash/fp/reverse";
import flow from "lodash/fp/flow";
wordsReversed = flow(split(" "), reverse)(value);

// Has a nice interface, but requires the additional step to set plugins every time you use it.
import lodashChain from "lodash-chain";
lodashChain.plugins({ split, reverse });
wordsReversed = lodashChain
  .chain(value)
  .split(" ")
  .reverse()
  .value();
expect(wordsReversed).toEqual(["noises", "loud"]);

// Similar to above, undesirable due to having to wrap functions to pass arguments
import { chain } from "@spacet.me/chain";
wordsReversed = chain(value)
  .thru((value) => split(value, " "))
  .thru(reverse)
  .value();

Keywords

FAQs

Package last updated on 05 May 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc