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-provider

v1.5.1

Published

A lodash synatic suguar module to eaily mix and match your own utility functions with lodash ones.

Downloads

11

Readme

Lodash Provider

A utility function provider that exports lodash functions dynamically. You can create your own hybrid utility module using a mix of your own functions and the lodash provided ones.

The provider will search your own utility functions if requested method is not present try to load and present the lodash one.

Install

npm install lodash-provider

Or

yarn add lodash-provider

The purpose of this module

Most sensible people can do not bother with refactoring-on-refactoring of private methods. Normally, we do not wish to unit test private code. It is for these reasons that using lodash is good practice.

The newest version of lodash, allows methods to be imported individually. This avoids bloating your own modules with the entire lodash export.

The pain of all this is having to require-in each module individually and mix that in with your own utility functions not provided by lodash. This module aims to make this process slightly easier by providing some sugar.

Example

const util = require('lodash-provider');

// Use lodash functions

util.isString('A string');
util.flatten([['A','B'],'C');

So, what is happening here is not just an exotic way to require('lodash') and get everything. Each function call is doing a require for that lodash function. So, in the background,this has happened:

require('lodash.isstring');
require('lodash.flatten);

This is achieved through proxies and will throw a helpful error when lodash module is not found (did you forget to install it?)

Mixing with your own utility functions

It is more useful when you combine it with your own functions.

Example

'use strict';

const util = require('lodash-provider');

util.makeArray = function makeArray(value) {
	if (value === undefined) return [];
	if (value instanceof Set) return [...value];
	return util.castArray(value);
};

module.exports = util;

Here we have added our utility function that is similar to lodash's castArray. All our utility functions could be addded here and then we can include in other parts of our project:

const util = require('./util);

Older node versions

If JavaScript Proxy and Reflect are available this module will simply require in the lodash functions as they are requested. In older node versions this cannot be achieved with proxies. In this setting the module will parse the package.json hierarchy and load in the lodash dependencies.