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

v0.1.1

Published

An opinionated lodash mod with extras

Downloads

5

Readme

lodash-extras

npm version Build Status Join the chat at https://gitter.im/rjhilgefort/lodash-extras

An opinionated lodash modification with extras.

Installation / Usage

Follow the below instructions, depending on your runtime environment (client/server). After which, the _ (lodash) object will have been modified with the "extras" included in this project.

Client-side

This project depends on lodash being loaded first. Then simply download, or install this package via bower. After which, you'll need to source both projects in your web application.

bower install --save lodash
bower install --save lodash-extras
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/lodash-extras/dist/lodash-extras.js"></script>

Or for Ember.js support

<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/lodash-extras/dist/lodash-extras-w-ember.js"></script>

Then merge in the all object from lodashExtras into _

_.merge(_, lodashExtras.all);

Server-side

Install via npm

npm install --save lodash
npm install --save lodash-extras

Then merge in the all object from lodashExtras into _.

const _ = require('lodash');
_.merge(_, require('lodash-extras').all);

Further Reading

Features

The full API Docs are still a work in progress. Look for them to get more fleshed out as proper interface documentation including examples. For now, here's a bulleted list of some features to check out. As with anything, your best bet it to check out the source (it's well documented).

> _.is[Condition]

Additional is conditions

  • _.isPresent: Not null or undefined
  • _.isPromise Is the object a then-able
  • _.moment.isMoment Is value a moment object

> _.is

Checks a value for an array of lodash boolean conditions

// Standard usage, trivial example (`_.isPlainObject` would accomplish the same)
_.is('foo', ['isPresent', 'isPlainObject']); // -> false

// You may prefix any method with `!` to invert the check
_.is('foo', ['isPresent', '!isPlainObject']); // -> true

// You may omit the the "is" prefix on any method
_.is([1, 2], ['Array', '!Empty']); // -> true

> _.ensure[Type]

Ensure type methods ensure that a value is of the type specified (default can be specified)

  • _.ensureString
  • _.ensureArray
  • _.ensurePlainObject
  • _.ensureBoolean
  • _.ensureNumber
  • _.moment.ensureMoment
var foo = 'foo';

// Standard usage
foo = _.ensureString(foo); // -> 'foo'
foo = _.ensurePlainObject(foo); // -> {}

// A default can be specified
foo = _.ensureArray(foo, ['foo', 'bar']); // -> ['foo', 'bar']

// Providing a default that doesn't match the ensure[Type] will ignore your default
foo = _.ensureNumber(foo, 'foo'); // -> 1

// ensureMoment is handled slightly different, it will try to convert anything you pass to moment first before falling back to default it ensures a moment object but not one with a valid date
foo = _.ensureMoment(new Date(2015, 11, 5), moment()); // -> Moment with 11-5-2015 as date
foo = _.ensureMoment('foo', moment()); // -> Moment with today as date
foo = _.ensureMoment('foo'); // -> Moment with invalid date

> _.typeOf

An alias for native JS typeOf method. Aliased for common interface and the ability to be overrieden by other "extras" (as seen in lodash-ember)

> _.is[Condition]

lodash provides many type checking methods out of the box. These are all of the following format _.is[Condition]. For example, _.isString. All the lodash _.is[Condition]methods now take two params and follow the interface of _.get.

foo = {
  bar: 'bar',
  baz: {
    qux: false
  }
};

_.isString(foo, 'bar'); // -> true
_.isPlainObject(foo, 'baz'); // -> true
_.isBoolean(foo, 'baz.qux'); // -> true
_.isPresent(foo, 'baz.qux.foo.bar'); // -> false

> _.deepEnsure[Type]

Same as _.ensure[Type], but adheres to the _.get interface. Look for this to be merged with the _.ensure[Type] namespace in the near future. The return of these methods is as you'd expect- the entire modified object. In the examples below, I only show the updated bits.

  • _.deepEnsureString
  • _.deepEnsureArray
  • _.deepEnsurePlainObject
  • _.deepEnsureBoolean
  • _.deepEnsureNumber
foo = {
  bar: 'bar',
  baz: {
    qux: false
  }
};

// Standard usage
foo = _.deepEnsureString(foo, 'bar'); // -> { bar: 'bar' }
foo = _.deepEnsurePlainObject(foo, 'bar'); // -> { bar: {} }

// Still accepts defaults
foo = _.deepEnsureArray(foo, 'bar', ['foo', 'bar']); // -> { bar: ['foo', 'bar'] }

// Still ignores your default if wrong type
foo = _.deepEnsureNumber(foo, 'baz.qux', 'foo'); // -> 'foo'

> _.deepDelete

Delete properties on an object using the _.get interface. This will eventually probably be renamed to _.delete. This utility is still a work in progress, use at your own risk.

foo = {
  bar: 'bar'
};

_.deepDelete(foo, 'bar'); // -> {}

> lodash-ember

This module constitutes nearly half of the the "lodash-extras" project and I unfortunately do not have the time to do the feature write up for them yet. I opted to shortcut doing the write up as the use case for them is specific to Ember applications. That being said, there's some great stuff in there and I encourage you to check out the source (again, it's well documented).

> lodash-moment

This module is simply for mixins that depend on the presence of the moment global variable.

  • _.moment.ensureMoment
  • _.moment.isMoment