Functions

Browse all available utility functions by category

util

attempt

Attempts to invoke func, returning either the result or the caught error object.

Example:

const elements = attempt((selector: string) => document.querySelectorAll(selector), '>_>');
util

bindAll

Binds methods of an object to the object itself, overwriting the existing method.

Example:

const view = {
util

cond

Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy.

Example:

const func = cond([
util

conforms

Creates a function that invokes the predicate properties of source with the corresponding property values of a given object.

Example:

const objects = [
util

constant

Creates a function that returns value.

Example:

const objects = times(2, constant({ 'a': 1 }));
util

defaultTo

Checks value to determine whether a default value should be returned in its place.

Example:

defaultTo(1, 10); // 1
util

flow

Creates a function that returns the result of invoking the given functions with the this binding of the created function.

Example:

function square(n: number) {
util

flowRight

This method is like flow except that it creates a function that invokes the given functions from right to left.

Example:

function square(n: number) {
util

identity

This method returns the first argument it receives.

Example:

const object = { 'a': 1 };
util

iteratee

Creates a function that invokes the predicate at the path of a given object.

Example:

const users = [
util

matches

Creates a function that performs a partial deep comparison between a given object and source.

Example:

const objects = [
util

matchesProperty

Creates a function that performs a partial deep comparison between the value at path of a given object and srcValue.

Example:

const objects = [
util

method

Creates a function that invokes the method at path of a given object.

Example:

const objects = [
util

methodOf

The opposite of method; this method creates a function that invokes the method at a given path of object.

Example:

const array = [
util

mixin

Adds all own enumerable string keyed function properties of a source object to the destination object.

Example:

function vowels(string) {
util

noConflict

Reverts the _ variable to its previous value and returns a reference to the tulx object.

Example:

const tulx = noConflict();
util

noop

A no-operation function that returns undefined regardless of the arguments it receives.

Example:

const object = { 'user': 'fred' };
util

nthArg

Creates a function that gets the argument at index n.

Example:

const func = nthArg(1);
util

over

Creates a function that invokes iteratees with the arguments it receives and returns their results.

Example:

const func = over([Math.max, Math.min]);
util

overEvery

Creates a function that checks if all of the predicates return truthy when invoked with the arguments it receives.

Example:

const func = overEvery([Boolean, isFinite]);
util

overSome

Creates a function that checks if any of the predicates return truthy when invoked with the arguments it receives.

Example:

const func = overSome([Boolean, isFinite]);
util

property

Creates a function that returns the value at path of a given object.

Example:

const objects = [
util

propertyOf

The opposite of property; this method creates a function that returns the value at a given path of object.

Example:

const array = [0, 1, 2];
util

range

Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end.

Example:

range(4); // [0, 1, 2, 3]
util

rangeRight

This method is like range except that it populates values in descending order.

Example:

rangeRight(4); // [3, 2, 1, 0]
util

runInContext

Create a new pristine lodash function using the given context object.

Example:

const _ = runInContext();
util

stubArray

This method returns a new empty array.

Example:

const arrays = times(2, stubArray);
util

stubFalse

This method returns false.

Example:

times(2, stubFalse); // [false, false]
util

stubObject

This method returns a new empty object.

Example:

const objects = times(2, stubObject);
util

stubString

This method returns an empty string.

Example:

times(2, stubString); // ['', '']
util

stubTrue

This method returns true.

Example:

times(2, stubTrue); // [true, true]
util

times

Invokes the iteratee n times, returning an array of the results of each invocation.

Example:

times(3, String); // ['0', '1', '2']
util

toPath

Converts value to a property path array.

Example:

toPath('a.b.c'); // ['a', 'b', 'c']
util

uniqueId

Generates a unique ID.

Example:

uniqueId('contact_'); // 'contact_1'