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

v2.0.1

Published

Community mixins for lodash

Downloads

1,009

Readme

Lodash Addons

Build Status Dependencies

A collection of utility mixins for lodash. Supports both CommonJS and AMD module formats (meaning, works well with module bundlers or RequireJS-based projects).

Installation

  • Yarn: yarn add --dev lodash-addons
  • NPM: npm install --save-dev lodash-addons

Array

  • _.transformValueMap

Collection

  • _.differenceKeys
  • _.filterKeys

Date

  • _.parseDate

Lang

  • _.getArray
  • _.getBoolean
  • _.getFinite
  • _.getFunction
  • _.getMap
  • _.getNumber
  • _.getObject
  • _.getPlainObject
  • _.getSet
  • _.getString
  • _.getWeakMap
  • _.getWeakSet
  • _.isIterable
  • _.isNonEmptyString
  • _.toBool

Math

  • _.sign

Object

  • _.hasInOfType
  • _.hasOfType
  • _.objectWith
  • _.parseQueryString
  • _.toQueryString

Preconditions

  • _.check

String

  • _.generateKey
  • _.slugify

Util

  • _.getPrototype

“Array” Methods

Transforms a value in each element of collection if the path is not undefined.

Arguments

  1. collection (Array): Array of objects
  2. path (string): The path of the value to transform
  3. transformer (function): Callback which returns the transformed value

“Collection” Methods

Gets indices for which elements differ between two arrays.

Arguments

  1. first (array): First array
  2. second (array): Second array

Example

_.differenceKeys([false, true], [false, false]);
// => [1]

Iterates over keys of a collection, returning an array of all keys predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).

Arguments

  1. collection (object): The object to iterate over.
  2. iteratee (function): The function invoked per iteration.

“Date” Methods

Parses a value by passing it to new Date().

Arguments

  1. val (string): Value to be parsed

“Lang” Methods

Returns value if an array, otherwise a default.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getArray(null);
// => []

_.getArray(null, ['test']);
// => ['test']

Returns value if a boolean, otherwise a default boolean.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getBoolean(null);
// => false

_.getBoolean(null, true);
// => true

Returns value if a finite number, otherwise a default number.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getFinite('');
// => 0

_.getFinite('', 100);
// => 100

_.getFinite(NaN, 25);
// => 25

Returns value if a function, otherwise a default function.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getFunction(null);
// => function () {}

Returns value if a Map, otherwise a default map.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Returns value if a number, otherwise a default number.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getNumber('');
// => 0

_.getNumber('', 100);
// => 100

Returns value if a object, otherwise a default object.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getObject('');
// => {}

Returns value if a plain object, otherwise a default object.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getPlainObject('');
// => {}

Returns value if a Set, otherwise a default set.

Arguments

  1. value (mixed): Source value
  2. replacement (set): Custom default if value is invalid type.

Example

_.getSet('');
// => Set()

Returns value if a string, otherwise a default string.

Arguments

  1. value (mixed): Source value
  2. replacement (number): Custom default if value is invalid type.

Example

_.getString(false);
// => ''

Returns value if a WeakMap, otherwise a default WeakMap.

Arguments

  1. value (mixed): Source value
  2. replacement (weakmap): Custom default if value is invalid type.

Example

_.getWeakMap(false);
// => ''

Returns value if a WeakSet, otherwise a default WeakSet.

Arguments

  1. value (mixed): Source value
  2. replacement (weakset): Custom default if value is invalid type.

Example

_.getWeakSet(false);
// => ''

Checks if value is iterable.

Arguments

  1. object (object): An object

Example

_.isIterable([]);
// => true

Checks if value is a non-empty string.

Arguments

  1. string (object): String

Example

_.isNonEmptyString('');
// => false

Converts a value to a boolean.

Arguments

  1. value (*): Source value

Example

_.toBool(1);
// => true

“Math” Methods

Returns a number representing the sign of value. If value is a positive number, negative number, positive zero or negative zero, the function will return 1, -1, 0 or -0 respectively. Otherwise, NaN is returned.

Arguments

  1. value (number): A number

Returns

(number): A number representing the sign

Example

_.sign(10);
// => 1

_.sign(-10);
// => -1

“Object” Methods

If _.hasIn returns true, run a validator on value.

Arguments

  1. value (mixed): Collection for _.hasIn
  2. path (number|string): Path.
  3. validator (function): Function to validate value.

If _.has returns true, run a validator on value.

Arguments

  1. value (mixed): Collection for _.has
  2. path (string): Path
  3. validator (function): Function to validate value.

Example

_.hasOfType({ test: '' }, 'test', _.isString);
// => true

Shorthand object creation when sole property is a variable, or a path.

Arguments

  1. object (): Existing object *(optional)*
  2. path (number|string): Property
  3. value (mixed): Value

Example

// To create a new object:

_.objectWith('key', 'value');
// => { key: 'value' }

_.objectWith('a.deep.path', 'value');
// => {
  a: {
    deep: {
  	 path: 'value'
    }
  }
}

// Using existing:
_.objectWith({ a: 1 }, 'b', 2);
// => { a: 1, b: 2 }

Parses query string into key/value object.

Arguments

  1. string (string): Query string.

Example

_.parseQueryString('key=value');
// => { key: 'value' }

Converts an object's key/values to a query string.

Arguments

  1. object (object): Source key/value collection

Example

_.toQueryString({ a: 1, b: 2 });
// => a=1&b=2

“Preconditions” Methods

Throw a TypeError if value doesn't match one of any provided validation methods.

Arguments

  1. value (mixed): Value

“String” Methods

Generates a random alphanumeric string with length n.

Arguments

  1. length (int): Desired length.

Example

_.generateKey(5);
// => 'L7IpD'

Generates a url-safe "slug" form of a string.

Arguments

  1. string (string): String value.

Example

_.slugify('A Test');
// => a-test

“Util” Methods

Gets the prototype for the given value.

Arguments

  1. value (*): Source value

Example

_.getPrototype(5);
// => { toFixed: func(), ... }