Functions
Browse all available utility functions by category
attempt
Attempts to invoke func, returning either the result or the caught error object.
Example:
const elements = attempt((selector: string) => document.querySelectorAll(selector), '>_>');bindAll
Binds methods of an object to the object itself, overwriting the existing method.
Example:
const view = {cond
Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy.
Example:
const func = cond([conforms
Creates a function that invokes the predicate properties of source with the corresponding property values of a given object.
Example:
const objects = [constant
Creates a function that returns value.
Example:
const objects = times(2, constant({ 'a': 1 }));defaultTo
Checks value to determine whether a default value should be returned in its place.
Example:
defaultTo(1, 10); // 1flow
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) {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) {identity
This method returns the first argument it receives.
Example:
const object = { 'a': 1 };iteratee
Creates a function that invokes the predicate at the path of a given object.
Example:
const users = [matches
Creates a function that performs a partial deep comparison between a given object and source.
Example:
const objects = [matchesProperty
Creates a function that performs a partial deep comparison between the value at path of a given object and srcValue.
Example:
const objects = [method
Creates a function that invokes the method at path of a given object.
Example:
const objects = [methodOf
The opposite of method; this method creates a function that invokes the method at a given path of object.
Example:
const array = [mixin
Adds all own enumerable string keyed function properties of a source object to the destination object.
Example:
function vowels(string) {noConflict
Reverts the _ variable to its previous value and returns a reference to the tulx object.
Example:
const tulx = noConflict();noop
A no-operation function that returns undefined regardless of the arguments it receives.
Example:
const object = { 'user': 'fred' };nthArg
Creates a function that gets the argument at index n.
Example:
const func = nthArg(1);over
Creates a function that invokes iteratees with the arguments it receives and returns their results.
Example:
const func = over([Math.max, Math.min]);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]);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]);property
Creates a function that returns the value at path of a given object.
Example:
const objects = [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];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]rangeRight
This method is like range except that it populates values in descending order.
Example:
rangeRight(4); // [3, 2, 1, 0]runInContext
Create a new pristine lodash function using the given context object.
Example:
const _ = runInContext();stubArray
This method returns a new empty array.
Example:
const arrays = times(2, stubArray);stubFalse
This method returns false.
Example:
times(2, stubFalse); // [false, false]stubObject
This method returns a new empty object.
Example:
const objects = times(2, stubObject);stubString
This method returns an empty string.
Example:
times(2, stubString); // ['', '']stubTrue
This method returns true.
Example:
times(2, stubTrue); // [true, true]times
Invokes the iteratee n times, returning an array of the results of each invocation.
Example:
times(3, String); // ['0', '1', '2']toPath
Converts value to a property path array.
Example:
toPath('a.b.c'); // ['a', 'b', 'c']uniqueId
Generates a unique ID.
Example:
uniqueId('contact_'); // 'contact_1'