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

lodash-backports

v1.0.1

Published

Backfill lodash aliases that were removed in v4

Downloads

15

Readme

Build Status downloads npm Code Climate Test Coverage dependencies Size Greenkeeper badge

lodash-backports

Backfill lodash aliases and functions that were removed in v4

Installation

npm install --save lodash-backports

Summary

Lodash v4 removed a bunch of aliases and functions. Some of the aliases I prefer to the non-alias names, and some of the functions seem more semantically intuitive than their replacements (e.g. pluck vs. map). This module backfills those aliases, as well as some removed functions, so that they continue to function as expected. If you have a large code-base, where renaming or removing references to methods that are now gone would make upgrading to lodash v4 impossible, consider using this library as migration stop-gap.

Usage

Lodash-backports exports a single function, register, that uses _.mixin to recreate now missing functions and aliases (in the browser, use window.lodashBackports.register). There are a variety of ways to use this function. First, you can call it with no parameters. It will require lodash, augment it with the missing functions, and return it. This is probably want you want to do. As this version uses require('lodash'), it will modify the global version of lodash (i.e. it will not use runInContext), but that's basically the idea of this library. Anywhere you require('lodash') now, it will have the missing methods, so if you're trying to backfill, they will be there, but they still shouldn't cause conflicts as only methods that have been removed are being added back.

var _ = require('lodash-backports').register();
// Now use old v3 aliases and functions as normal

You can, however, isolate the changes this library makes if you choose to. You can pass in your own copy of lodash:

var _ = require('lodash').runInContext();
_ = require('lodash-backports').register(_);

// Or
var _ = require('lodash');
var v3 = require('lodash-backports').register(_.runInContext());

Or you can tell lodash-backports to do this for you:

// Passing an options object with "noConflict" tells lodash-backports
// not to augment the main lodash instance, but instead to generate it's own
// using runInContext and to augment that one instead.
var _ = require('lodash-backports').register({ noConflict: true });

You can also combine these if, for some reason, that's helpful.

var _ = require('lodash');
_ = require('lodash-backports').register(_, { noConflict: true });

Finally, if you only want to create some of the previous aliases and functions, you can pass an omit option that is a list of functions not to create.

var _ = require('lodash-backports').register({ noConflict: true, omit: ['foldl', 'foldr', 'backflow'] });

Scope

The scope of this backfill is in progress. All of the aliases removed in v4 have been added, but only a subset of the functions. That's primarily because of the level of work needed to even determine what was removed and what it does. If a function you would like to use is not backfilled by this library, please do open a pull request, and I will add it. That is, in fact, how this library came to exist. It used to be lodash-aliases, but when someone asked for _.pluck to be backported, which was not an alias, I decided to create this more semantically correct library to support such requests.

Contributing

Please see the contribution guidelines.