Interface UnderscoreStatic

Index

Call signatures

Properties

Methods

Call signatures

(value: Array<T>): Underscore

Underscore OOP Wrapper, all Underscore functions that take an object as the first parameter can be invoked through this function.

Parameters

  • value: Array<T>

Returns

Underscore

(value: T): Underscore

Parameters

  • value: T

Returns

Underscore

Properties

public templateSettings: TemplateSettings

By default, Underscore uses ERB-style template delimiters, change the following template settings to use alternative delimiters.

Methods

public after(count: number, fn: Function): Function

Creates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.

fn

The function to defer execution count times.

Parameters

  • count: number

    Number of times to be called before actually executing.

  • fn: Function

Returns

Function

Copy of fn that will not execute until it is invoked count times.

public all(list: List, iterator?: ListIterator, context?: any): boolean

see

_.every

Parameters

Returns

boolean

public all(list: Dictionary, iterator?: ObjectIterator, context?: any): boolean

see

_.every

Parameters

Returns

boolean

public any(list: List, iterator?: ListIterator, context?: any): boolean

see

_.some

Parameters

Returns

boolean

public any(object: Dictionary, iterator?: ObjectIterator, context?: any): boolean

see

_.some

Parameters

Returns

boolean

public bind(func: Function, context: any, arguments?: Array<any>): () => any

Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application.

Parameters

  • func: Function

    The function to bind this to object.

  • context: any

    The this pointer whenever fn is called.

  • arguments?: Array<any> optional

    Additional arguments to pass to fn when called.

Returns

() => any

fn with this bound to object.

public bindAll(object: any, methodNames?: Array<string>): any

Binds a number of methods on the object, specified by methodNames, to be run in the context of that object whenever they are invoked. Very handy for binding functions that are going to be used as event handlers, which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the object's function properties will be bound to it.

Parameters

  • object: any

    The object to bind the methods methodName to.

  • methodNames?: Array<string> optional

    The methods to bind to object, optional and if not provided all of object's methods are bound.

Returns

any

public chain(obj: Array<T>): _Chain

Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value() is used.

Parameters

  • obj: Array<T>

    Object to chain.

Returns

_Chain

Wrapped obj.

public chain(obj: T): _Chain

Parameters

  • obj: T

Returns

_Chain

public clone(object: T): T

Create a shallow-copied clone of the object. Any nested objects or arrays will be copied by reference, not duplicated.

Parameters

  • object: T

    Object to clone.

Returns

T

Copy of object.

public collect(list: List, iterator: ListIterator, context?: any): Array<TResult>

see

_.map

Parameters

Returns

Array<TResult>

public collect(object: Dictionary, iterator: ObjectIterator, context?: any): Array<TResult>

see

_.map

Parameters

Returns

Array<TResult>

public compact(array: List): Array<T>

Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, "", undefined and NaN are all falsy.

Parameters

  • array: List

    Array to compact.

Returns

Array<T>

Copy of array without false values.

public compose(functions?: Array<Function>): Function

Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).

Parameters

  • functions?: Array<Function> optional

    List of functions to compose.

Returns

Function

Composition of functions.

public constant(value: T): () => T

Creates a function that returns the same value that is used as the argument of _.constant

Parameters

  • value: T

    Identity of this object.

Returns

() => T

Function that return value.

public contains(list: List, value: T): boolean

Returns true if the value is present in the list. Uses indexOf internally, if list is an Array.

Parameters

  • list: List

    Checks each element to see if value is present.

  • value: T

    The value to check for within list.

Returns

boolean

True if value is present in list, otherwise false.

public contains(object: Dictionary, value: T): boolean

see

_.contains

Parameters

Returns

boolean

public countBy(list: List, iterator?: ListIterator, context?: any): Dictionary

Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy, but instead of returning a list of values, returns a count for the number of values in that group.

Parameters

  • list: List

    Group elements in this list and then count the number of elements in each group.

  • iterator?: ListIterator optional

    Group iterator for each element within list, return the key to group the element by.

  • context?: any optional

    this object in iterator, optional.

Returns

Dictionary

An object with the group names as properties where each property contains the number of elements in that group.

public countBy(list: List, iterator: string, context?: any): Dictionary

see

_.countBy

Parameters

  • list: List
  • iterator: string

    Function name

  • context?: any optional

Returns

Dictionary

public debounce(fn: Function, wait: number, immediate?: boolean): Function

Creates and returns a new debounced version of the passed function that will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. For example: rendering a preview of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on.

Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double -clicks on a "submit" button from firing a second time.

Parameters

  • fn: Function

    Function to debounce waitMS ms.

  • wait: number

    The number of milliseconds to wait before fn can be invoked again.

  • immediate?: boolean optional

    True if fn should be invoked on the leading edge of waitMS instead of the trailing edge.

Returns

Function

Debounced version of fn that waits wait ms when invoked.

public defaults(object: any, defaults?: Array<any>): any

Fill in null and undefined properties in object with values from the defaults objects, and return the object. As soon as the property is filled, further defaults will have no effect.

Parameters

  • object: any

    Fill this object with default values.

  • defaults?: Array<any> optional

    The default values to add to object.

Returns

any

object with added defaults values.

public defer(fn: Function, arguments?: Array<any>)

Defers invoking the function until the current call stack has cleared, similar to using setTimeout with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

Parameters

  • fn: Function

    The function to defer.

  • arguments?: Array<any> optional

    Additional arguments to pass to fn.

public delay(func: Function, wait: number, arguments?: Array<any>): any

Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

arguments

Additional arguments to pass to fn.

Parameters

  • func: Function

    Function to delay waitMS amount of ms.

  • wait: number

    The amount of milliseconds to delay fn.

  • arguments?: Array<any> optional

Returns

any

public delay(func: Function, arguments?: Array<any>): any

see

_delay

Parameters

  • func: Function
  • arguments?: Array<any> optional

Returns

any

public detect(list: List, iterator: ListIterator, context?: any): T

see

_.find

Parameters

Returns

T

public detect(object: Dictionary, iterator: ObjectIterator, context?: any): T

see

_.find

Parameters

Returns

T

public difference(array: List, others?: List[]): Array<T>

Similar to without, but returns the values from array that are not present in the other arrays.

Parameters

  • array: List

    Keeps values that are within others.

  • others?: List[] optional

    The values to keep within array.

Returns

Array<T>

Copy of array with only others values.

public drop(array: List, n?: number): Array<T>

see

_.rest

Parameters

  • array: List
  • n?: number optional

Returns

Array<T>

public each(list: List, iterator: ListIterator, context?: any): List

Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is bound to the context object, if one is passed. Each invocation of iterator is called with three arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be (value, key, object). Delegates to the native forEach function if it exists.

Parameters

  • list: List

    Iterates over this list of elements.

  • iterator: ListIterator

    Iterator function for each element list.

  • context?: any optional

    'this' object in iterator, optional.

Returns

List

public each(object: Dictionary, iterator: ObjectIterator, context?: any): Dictionary

see

_.each

Parameters

  • object: Dictionary

    Iterates over properties of this object.

  • iterator: ObjectIterator

    Iterator function for each property on object.

  • context?: any optional

    'this' object in iterator, optional.

Returns

Dictionary

public escape(str: string): string

Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters.

Parameters

  • str: string

    Raw string to escape.

Returns

string

str HTML escaped.

public every(list: List, iterator?: ListIterator, context?: any): boolean

Returns true if all of the values in the list pass the iterator truth test. Delegates to the native method every, if present.

Parameters

  • list: List

    Truth test against all elements within this list.

  • iterator?: ListIterator optional

    Trust test iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

boolean

True if all elements passed the truth test, otherwise false.

public every(list: Dictionary, iterator?: ObjectIterator, context?: any): boolean

see

_.every

Parameters

Returns

boolean

public extend(destination: any, sources?: Array<any>): any

Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.

Parameters

  • destination: any

    Object to extend all the properties from sources.

  • sources?: Array<any> optional

    Extends destination with all properties from these source objects.

Returns

any

destination extended with all the properties from the sources objects.

public filter(list: List, iterator: ListIterator, context?: any): Array<T>

Looks through each value in the list, returning an array of all the values that pass a truth test (iterator). Delegates to the native filter method, if it exists.

Parameters

  • list: List

    Filter elements out of this list.

  • iterator: ListIterator

    Filter iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<T>

The filtered list of elements.

public filter(object: Dictionary, iterator: ObjectIterator, context?: any): Array<T>

see

_.filter

Parameters

Returns

Array<T>

public find(list: List, iterator: ListIterator, context?: any): T

Looks through each value in the list, returning the first one that passes a truth test (iterator). The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.

Parameters

  • list: List

    Searches for a value in this list.

  • iterator: ListIterator

    Search iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

T

The first acceptable found element in list, if nothing is found undefined/null is returned.

public find(object: Dictionary, iterator: ObjectIterator, context?: any): T

see

_.find

Parameters

Returns

T

public findWhere(list: List, properties: U): T

Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.

Parameters

  • list: List

    Search through this list's elements for the first object with all properties.

  • properties: U

    Properties to look for on the elements within list.

Returns

T

The first element in list that has all properties.

public first(array: List): T

Returns the first element of an array. Passing n will return the first n elements of the array.

Parameters

  • array: List

    Retrieves the first element of this array.

Returns

T

Returns the first element of array.

public first(array: List, n: number): Array<T>

see

_.first

Parameters

  • array: List
  • n: number

    Return more than one element from array.

Returns

Array<T>

public flatten(array: List, shallow?: boolean): Array<any>

Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will only be flattened a single level.

Parameters

  • array: List

    The array to flatten.

  • shallow?: boolean optional

    If true then only flatten one level, optional, default = false.

Returns

Array<any>

array flattened.

public foldl(list: Collection, iterator: MemoIterator, memo?: TResult, context?: any): TResult

see

_.reduce

Parameters

Returns

TResult

public foldr(list: Collection, iterator: MemoIterator, memo?: TResult, context?: any): TResult

see

_.reduceRight

Parameters

Returns

TResult

public forEach(list: List, iterator: ListIterator, context?: any): List

see

_.each

Parameters

Returns

List

public forEach(object: Dictionary, iterator: ObjectIterator, context?: any): Dictionary

see

_.each

Parameters

Returns

Dictionary

public functions(object: any): Array<string>

Returns a sorted list of the names of every method in an object - that is to say, the name of every function property of the object.

Parameters

  • object: any

    Object to pluck all function property names from.

Returns

Array<string>

List of all the function names on object.

public groupBy(list: List, iterator?: ListIterator, context?: any): Dictionary

Splits a collection into sets, grouped by the result of running each value through iterator. If iterator is a string instead of a function, groups by the property named by iterator on each of the values.

Parameters

  • list: List

    Groups this list.

  • iterator?: ListIterator optional

    Group iterator for each element within list, return the key to group the element by.

  • context?: any optional

    this object in iterator, optional.

Returns

Dictionary

An object with the group names as properties where each property contains the grouped elements from list.

public groupBy(list: List, iterator: string, context?: any): Dictionary

see

_.groupBy

Parameters

  • list: List
  • iterator: string

    Property on each object to group them by.

  • context?: any optional

Returns

Dictionary

public has(object: any, key: string): boolean

Does the object contain the given key? Identical to object.hasOwnProperty(key), but uses a safe reference to the hasOwnProperty function, in case it's been overridden accidentally.

Parameters

  • object: any

    Object to check for key.

  • key: string

    The key to check for on object.

Returns

boolean

True if key is a property on object, otherwise false.

public head(array: List): T

see

_.first

Parameters

Returns

T

public head(array: List, n: number): Array<T>

see

_.first

Parameters

  • array: List
  • n: number

Returns

Array<T>

public identity(value: T): T

Returns the same value that is used as the argument. In math: f(x) = x This function looks useless, but is used throughout Underscore as a default iterator.

Parameters

  • value: T

    Identity of this object.

Returns

T

value.

public include(list: Collection, value: T): boolean

see

_.contains

Parameters

Returns

boolean

public include(object: Dictionary, value: T): boolean

see

_.contains

Parameters

Returns

boolean

public indexBy(list: List, iterator: ListIterator, context?: any): Dictionary

Given a list, and an iterator function that returns a key for each element in the list (or a property name), returns an object with an index of each item. Just like _.groupBy, but for when you know your keys are unique.

Parameters

Returns

Dictionary

public indexBy(list: List, iterator: string, context?: any): Dictionary

see

_.indexBy

Parameters

  • list: List
  • iterator: string

    Property on each object to index them by.

  • context?: any optional

Returns

Dictionary

public indexOf(array: List, value: T, isSorted?: boolean): number

Returns the index at which value can be found in the array, or -1 if value is not present in the array. Uses the native indexOf function unless it's missing. If you're working with a large array, and you know that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number as the third argument in order to look for the first matching value in the array after the given index.

Parameters

  • array: List

    The array to search for the index of value.

  • value: T

    The value to search for within array.

  • isSorted?: boolean optional

    True if the array is already sorted, optional, default = false.

Returns

number

The index of value within array.

public indexOf(array: List, value: T, startFrom: number): number

see

_indexof

Parameters

  • array: List
  • value: T
  • startFrom: number

Returns

number

public initial(array: List, n?: number): Array<T>

Returns everything but the last entry of the array. Especially useful on the arguments object. Pass n to exclude the last n elements from the result.

Parameters

  • array: List

    Retrieve all elements except the last n.

  • n?: number optional

    Leaves this many elements behind, optional.

Returns

Array<T>

Returns everything but the last n elements of array.

public inject(list: Collection, iterator: MemoIterator, memo?: TResult, context?: any): TResult

see

_.reduce

Parameters

Returns

TResult

public intersection(arrays?: List[]): Array<T>

Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.

Parameters

  • arrays?: List[] optional

    Array of arrays to compute the intersection of.

Returns

Array<T>

The intersection of elements within arrays.

public invert(object: any): any

Returns a copy of the object where the keys have become the values and the values the keys. For this to work, all of your object's values should be unique and string serializable.

Parameters

  • object: any

    Object to invert key/value pairs.

Returns

any

An inverted key/value paired version of object.

public invoke(list: List, methodName: string, arguments?: Array<any>): any

Calls the method named by methodName on each value in the list. Any extra arguments passed to invoke will be forwarded on to the method invocation.

Parameters

  • list: List

    The element's in this list will each have the method methodName invoked.

  • methodName: string

    The method's name to call on each element within list.

  • arguments?: Array<any> optional

    Additional arguments to pass to the method methodName.

Returns

any

public isArguments(object: any): boolean

Returns true if object is an Arguments object.

Parameters

  • object: any

    Check if this object is an Arguments object.

Returns

boolean

True if object is an Arguments object, otherwise false.

public isArray(object: any): boolean

Returns true if object is an Array.

Parameters

  • object: any

    Check if this object is an Array.

Returns

boolean

True if object is an Array, otherwise false.

public isBoolean(object: any): boolean

Returns true if object is either true or false.

Parameters

  • object: any

    Check if this object is a bool.

Returns

boolean

True if object is a bool, otherwise false.

public isDate(object: any): boolean

Returns true if object is a Date.

Parameters

  • object: any

    Check if this object is a Date.

Returns

boolean

True if object is a Date, otherwise false.

public isElement(object: any): boolean

Returns true if object is a DOM element.

Parameters

  • object: any

    Check if this object is a DOM element.

Returns

boolean

True if object is a DOM element, otherwise false.

public isEmpty(object: any): boolean

Returns true if object contains no values.

Parameters

  • object: any

    Check if this object has no properties or values.

Returns

boolean

True if object is empty.

public isEqual(object: any, other: any): boolean

Performs an optimized deep comparison between the two objects, to determine if they should be considered equal.

Parameters

  • object: any

    Compare to other.

  • other: any

    Compare to object.

Returns

boolean

True if object is equal to other.

public isFinite(object: any): boolean

Returns true if object is a finite Number.

Parameters

  • object: any

    Check if this object is a finite Number.

Returns

boolean

True if object is a finite Number.

public isFunction(object: any): boolean

Returns true if object is a Function.

Parameters

  • object: any

    Check if this object is a Function.

Returns

boolean

True if object is a Function, otherwise false.

public isNaN(object: any): boolean

Returns true if object is NaN. Note: this is not the same as the native isNaN function, which will also return true if the variable is undefined.

Parameters

  • object: any

    Check if this object is NaN.

Returns

boolean

True if object is NaN, otherwise false.

public isNull(object: any): boolean

Returns true if the value of object is null.

Parameters

  • object: any

    Check if this object is null.

Returns

boolean

True if object is null, otherwise false.

public isNumber(object: any): boolean

Returns true if object is a Number (including NaN).

Parameters

  • object: any

    Check if this object is a Number.

Returns

boolean

True if object is a Number, otherwise false.

public isObject(object: any): boolean

Returns true if value is an Object. Note that JavaScript arrays and functions are objects, while (normal) strings and numbers are not.

Parameters

  • object: any

    Check if this object is an Object.

Returns

boolean

True of object is an Object, otherwise false.

public isRegExp(object: any): boolean

Returns true if object is a RegExp.

Parameters

  • object: any

    Check if this object is a RegExp.

Returns

boolean

True if object is a RegExp, otherwise false.

public isString(object: any): boolean

Returns true if object is a String.

Parameters

  • object: any

    Check if this object is a String.

Returns

boolean

True if object is a String, otherwise false.

public isUndefined(value: any): boolean

Returns true if value is undefined.

Parameters

  • value: any

Returns

boolean

True if object is undefined, otherwise false.

public keys(object: any): Array<string>

Retrieve all the names of the object's properties.

Parameters

  • object: any

    Retrieve the key or property names from this object.

Returns

Array<string>

List of all the property names on object.

public last(array: List): T

Returns the last element of an array. Passing n will return the last n elements of the array.

Parameters

  • array: List

    Retrieves the last element of this array.

Returns

T

Returns the last element of array.

public last(array: List, n: number): Array<T>

see

_.last

Parameters

  • array: List
  • n: number

    Return more than one element from array.

Returns

Array<T>

public lastIndexOf(array: List, value: T, from?: number): number

Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the native lastIndexOf function if possible. Pass fromIndex to start your search at a given index.

Parameters

  • array: List

    The array to search for the last index of value.

  • value: T

    The value to search for within array.

  • from?: number optional

    The starting index for the search, optional.

Returns

number

The index of the last occurrence of value within array.

public map(list: List, iterator: ListIterator, context?: any): Array<TResult>

Produces a new array of values by mapping each value in list through a transformation function (iterator). If the native map method exists, it will be used instead. If list is a JavaScript object, iterator's arguments will be (value, key, object).

Parameters

  • list: List

    Maps the elements of this array.

  • iterator: ListIterator

    Map iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<TResult>

The mapped array result.

public map(object: Dictionary, iterator: ObjectIterator, context?: any): Array<TResult>

see

_.map

Parameters

  • object: Dictionary

    Maps the properties of this object.

  • iterator: ObjectIterator

    Map iterator function for each property on object.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<TResult>

The mapped object result.

public matches(attrs: T): ListIterator

Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.

Parameters

  • attrs: T

    Object with key values pair

Returns

ListIterator

Predicate function

public max(list: List): number

Returns the maximum value in list.

Parameters

  • list: List

    Finds the maximum value in this list.

Returns

number

Maximum value in list.

public max(list: List, iterator?: ListIterator, context?: any): T

Returns the maximum value in list. If iterator is passed, it will be used on each value to generate the criterion by which the value is ranked.

Parameters

  • list: List

    Finds the maximum value in this list.

  • iterator?: ListIterator optional

    Compares each element in list to find the maximum value.

  • context?: any optional

    this object in iterator, optional.

Returns

T

The maximum element within list.

public memoize(fn: Function, hashFn?: (...args: any[]) => string): Function

Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based on the arguments to the original function. The default hashFunction just uses the first argument to the memoized function as the key.

Parameters

  • fn: Function

    Computationally expensive function that will now memoized results.

  • hashFn?: (...args: any[]) => string optional

    Hash function for storing the result of fn.

Returns

Function

Memoized version of fn.

public methods(object: any): Array<string>

see

_functions

Parameters

  • object: any

Returns

Array<string>

public min(list: List): number

Returns the minimum value in list.

Parameters

  • list: List

    Finds the minimum value in this list.

Returns

number

Minimum value in list.

public min(list: List, iterator?: ListIterator, context?: any): T

Returns the minimum value in list. If iterator is passed, it will be used on each value to generate the criterion by which the value is ranked.

Parameters

  • list: List

    Finds the minimum value in this list.

  • iterator?: ListIterator optional

    Compares each element in list to find the minimum value.

  • context?: any optional

    this object in iterator, optional.

Returns

T

The minimum element within list.

public mixin(object: any)

Allows you to extend Underscore with your own utility functions. Pass a hash of {name: function} definitions to have your functions added to the Underscore object, as well as the OOP wrapper.

Parameters

  • object: any

    Mixin object containing key/function pairs to add to the Underscore object.

public noConflict(): any

Give control of the "_" variable back to its previous owner. Returns a reference to the Underscore object.

Returns

any

Underscore object reference.

public now(): number

Returns an integer timestamp for the current time, using the fastest method available in the runtime. Useful for implementing timing/animation functions.

Returns

number

public object(keys: List, values: List): TResult

Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys, and a list of values.

Parameters

  • keys: List

    Key array.

  • values: List

    Value array.

Returns

TResult

An object containing the keys as properties and values as the property values.

public object(keyValuePairs?: Array<any[]>): TResult

Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys, and a list of values.

Parameters

  • keyValuePairs?: Array<any[]> optional

    Array of [key, value] pairs.

Returns

TResult

An object containing the keys as properties and values as the property values.

public object(list: List, values?: any): TResult

see

_.object

Parameters

  • list: List
  • values?: any optional

Returns

TResult

public omit(object: any, keys?: Array<string>): any

Return a copy of the object, filtered to omit the blacklisted keys (or array of keys).

Parameters

  • object: any

    Object to strip unwanted key/value pairs.

  • keys?: Array<string> optional

    The key/value pairs to remove on object.

Returns

any

Copy of object without the keys properties.

public omit(object: any, keys: Array<string>): any

see

_.omit

Parameters

  • object: any
  • keys: Array<string>

Returns

any

public once(fn: Function): Function

Creates a version of the function that can only be called one time. Repeated calls to the modified function will have no effect, returning the value from the original call. Useful for initialization functions, instead of having to set a boolean flag and then check it later.

Parameters

  • fn: Function

    Function to only execute once.

Returns

Function

Copy of fn that can only be invoked once.

public pairs(object: any): Array<any[]>

Convert an object into a list of [key, value] pairs.

Parameters

  • object: any

    Convert this object to a list of [key, value] pairs.

Returns

Array<any[]>

List of [key, value] pairs on object.

public partial(fn: Function, arguments?: Array<any>): Function

Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be pre-filled, but left open to supply at call-time.

Parameters

  • fn: Function

    Function to partially fill in arguments.

  • arguments?: Array<any> optional

    The partial arguments.

Returns

Function

fn with partially filled in arguments.

public partition(array: Array<T>, iterator: ListIterator, context?: any): Array<T[]>

Split array into two arrays: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.

Parameters

  • array: Array<T>

    Array to split in two.

  • iterator: ListIterator

    Filter iterator function for each element in array.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<T[]>

Array where Array[0] are the elements in array that satisfies the predicate, and Array[1] the elements that did not.

public pick(object: any, keys?: Array<string>): any

Return a copy of the object, filtered to only have values for the whitelisted keys (or array of valid keys).

keys

The key/value pairs to keep on object.

Parameters

  • object: any

    Object to strip unwanted key/value pairs.

  • keys?: Array<string> optional

Returns

any

Copy of object with only the keys properties.

public pluck(list: List, propertyName: string): Array<any>

A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.

Parameters

  • list: List

    The list to pluck elements out of that have the property propertyName.

  • propertyName: string

    The property to look for on each element within list.

Returns

Array<any>

The list of elements within list that have the property propertyName.

public property(key: string): (object: Object) => any

Returns a function that will itself return the key property of any passed-in object.

Parameters

  • key: string

    Property of the object.

Returns

(object: Object) => any

Function which accept an object an returns the value of key in that object.

public random(max: number): number

Returns a random integer between min and max, inclusive. If you only pass one argument, it will return a number between 0 and that number.

Parameters

  • max: number

    The maximum random number.

Returns

number

A random number between 0 and max.

public random(min: number, max: number): number

see

_.random

Parameters

  • min: number

    The minimum random number.

  • max: number

Returns

number

A random number between min and max.

public range(start: number, stop: number, step?: number): Array<number>

A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented) by step, exclusive.

Parameters

  • start: number

    Start here.

  • stop: number

    Stop here.

  • step?: number optional

    The number to count up by each iteration, optional, default = 1.

Returns

Array<number>

Array of numbers from start to stop with increments of step.

public range(stop: number): Array<number>

see

_.range

note

If start is not specified the implementation will never pull the step (step = arguments[2] || 0)

Parameters

  • stop: number

    Stop here.

Returns

Array<number>

Array of numbers from 0 to stop with increments of 1.

public reduce(list: Collection, iterator: MemoIterator, memo?: TResult, context?: any): TResult

Also known as inject and foldl, reduce boils down a list of values into a single value. Memo is the initial state of the reduction, and each successive step of it should be returned by iterator. The iterator is passed four arguments: the memo, then the value and index (or key) of the iteration, and finally a reference to the entire list.

Parameters

  • list: Collection

    Reduces the elements of this array.

  • iterator: MemoIterator

    Reduce iterator function for each element in list.

  • memo?: TResult optional

    Initial reduce state.

  • context?: any optional

    this object in iterator, optional.

Returns

TResult

Reduced object result.

public reduceRight(list: Collection, iterator: MemoIterator, memo?: TResult, context?: any): TResult

The right-associative version of reduce. Delegates to the JavaScript 1.8 version of reduceRight, if it exists. foldr is not as useful in JavaScript as it would be in a language with lazy evaluation.

Parameters

  • list: Collection

    Reduces the elements of this array.

  • iterator: MemoIterator

    Reduce iterator function for each element in list.

  • memo?: TResult optional

    Initial reduce state.

  • context?: any optional

    this object in iterator, optional.

Returns

TResult

Reduced object result.

public reject(list: List, iterator: ListIterator, context?: any): Array<T>

Returns the values in list without the elements that the truth test (iterator) passes. The opposite of filter. Return all the elements for which a truth test fails.

Parameters

  • list: List

    Reject elements within this list.

  • iterator: ListIterator

    Reject iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<T>

The rejected list of elements.

public reject(object: Dictionary, iterator: ObjectIterator, context?: any): Array<T>

see

_.reject

Parameters

Returns

Array<T>

public rest(array: List, n?: number): Array<T>

Returns the rest of the elements in an array. Pass an index to return the values of the array from that index onward.

Parameters

  • array: List

    The array to retrieve all but the first index elements.

  • n?: number optional

    The index to start retrieving elements forward from, optional, default = 1.

Returns

Array<T>

Returns the elements of array from index to the end of array.

public result(object: any, property: string): any

If the value of the named property is a function then invoke it; otherwise, return it.

Parameters

  • object: any

    Object to maybe invoke function property on.

  • property: string

    The function by name to invoke on object.

Returns

any

The result of invoking the function property on `object.

public sample(list: Collection, n: number): Array<T>

Produce a random sample from the list. Pass a number to return n random elements from the list. Otherwise a single random item will be returned.

Parameters

Returns

Array<T>

Random sample of n elements in list.

public sample(list: Collection): T

see

_.sample

Parameters

Returns

T

public select(list: List, iterator: ListIterator, context?: any): Array<T>

see

_.filter

Parameters

Returns

Array<T>

public select(object: Dictionary, iterator: ObjectIterator, context?: any): Array<T>

see

_.filter

Parameters

Returns

Array<T>

public shuffle(list: Collection): Array<T>

Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle.

Parameters

Returns

Array<T>

Shuffled copy of list.

public size(list: Collection): number

Return the number of values in the list.

Parameters

  • list: Collection

    Count the number of values/elements in this list.

Returns

number

Number of values in list.

public some(list: List, iterator?: ListIterator, context?: any): boolean

Returns true if any of the values in the list pass the iterator truth test. Short-circuits and stops traversing the list if a true element is found. Delegates to the native method some, if present.

Parameters

  • list: List

    Truth test against all elements within this list.

  • iterator?: ListIterator optional

    Trust test iterator function for each element in list.

  • context?: any optional

    this object in iterator, optional.

Returns

boolean

True if any elements passed the truth test, otherwise false.

public some(object: Dictionary, iterator?: ObjectIterator, context?: any): boolean

see

_.some

Parameters

Returns

boolean

public sortBy(list: List, iterator?: ListIterator, context?: any): Array<T>

Returns a sorted copy of list, ranked in ascending order by the results of running each value through iterator. Iterator may also be the string name of the property to sort by (eg. length).

Parameters

  • list: List

    Sorts this list.

  • iterator?: ListIterator optional

    Sort iterator for each element within list.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<T>

A sorted copy of list.

public sortBy(list: List, iterator: string, context?: any): Array<T>

see

_.sortBy

Parameters

  • list: List
  • iterator: string

    Sort iterator for each element within list.

  • context?: any optional

Returns

Array<T>

public sortedIndex(list: List, value: T, iterator?: (x: T) => TSort, context?: any): number

Uses a binary search to determine the index at which the value should be inserted into the list in order to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking of each value, including the value you pass.

Parameters

  • list: List

    The sorted list.

  • value: T

    The value to determine its index within list.

  • iterator?: (x: T) => TSort optional

    Iterator to compute the sort ranking of each value, optional.

  • context?: any optional

Returns

number

The index where value should be inserted into list.

public tail(array: List, n?: number): Array<T>

see

_.rest

Parameters

  • array: List
  • n?: number optional

Returns

Array<T>

public take(array: List): T

see

_.first

Parameters

Returns

T

public take(array: List, n: number): Array<T>

see

_.first

Parameters

  • array: List
  • n: number

Returns

Array<T>

public tap(object: T, intercepter: Function): T

Invokes interceptor with the object, and then returns object. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.

Parameters

  • object: T

    Argument to interceptor.

  • intercepter: Function

    The function to modify object before continuing the method chain.

Returns

T

Modified object.

public template(templateString: string, data?: any, settings?: TemplateSettings): (...data: any[]) => string

Compiles JavaScript templates into functions that can be evaluated for rendering. Useful for rendering complicated bits of HTML from JSON data sources. Template functions can both interpolate variables, using <%= ... %>, as well as execute arbitrary JavaScript code, with <% ... %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- ... %> When you evaluate a template function, pass in a data object that has properties corresponding to the template's free variables. If you're writing a one-off, you can pass the data object as the second parameter to template in order to render immediately instead of returning a template function. The settings argument should be a hash containing any _.templateSettings that should be overridden.

Parameters

  • templateString: string

    Underscore HTML template.

  • data?: any optional

    Data to use when compiling templateString.

  • settings?: TemplateSettings optional

    Settings to use while compiling.

Returns

(...data: any[]) => string

Returns the compiled Underscore HTML template.

public throttle(func: any, wait: number, options?: ThrottleSettings): Function

Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with. By default, throttle will execute the function as soon as you call it for the first time, and, if you call it again any number of times during the wait period, as soon as that period is over. If you'd like to disable the leading-edge call, pass {leading: false}, and if you'd like to disable the execution on the trailing-edge, pass {trailing: false}.

Parameters

  • func: any

    Function to throttle waitMS ms.

  • wait: number

    The number of milliseconds to wait before fn can be invoked again.

  • options?: ThrottleSettings optional

    Allows for disabling execution of the throttled function on either the leading or trailing edge.

Returns

Function

fn with a throttle of wait.

public times(n: number, iterator: (n: number) => TResult, context?: any): Array<TResult>

Invokes the given iterator function n times. Each invocation of iterator is called with an index argument

Parameters

  • n: number

    Number of times to invoke iterator.

  • iterator: (n: number) => TResult

    Function iterator to invoke n times.

  • context?: any optional

    this object in iterator, optional.

Returns

Array<TResult>

public toArray(list: Collection): Array<T>

Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting the arguments object.

Parameters

  • list: Collection

    object to transform into an array.

Returns

Array<T>

list as an array.

public union(arrays?: List[]): Array<T>

Computes the union of the passed-in arrays: the list of unique items, in order, that are present in one or more of the arrays.

Parameters

  • arrays?: List[] optional

    Array of arrays to compute the union of.

Returns

Array<T>

The union of elements within arrays.

public uniq(array: List, isSorted?: boolean, iterator?: ListIterator, context?: any): Array<T>

Produces a duplicate-free version of the array, using === to test object equality. If you know in advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If you want to compute unique items based on a transformation, pass an iterator function.

Parameters

  • array: List

    Array to remove duplicates from.

  • isSorted?: boolean optional

    True if array is already sorted, optional, default = false.

  • iterator?: ListIterator optional

    Transform the elements of array before comparisons for uniqueness.

  • context?: any optional

    'this' object in iterator, optional.

Returns

Array<T>

Copy of array where all elements are unique.

public uniq(array: List, iterator?: ListIterator, context?: any): Array<T>

see

_.uniq

Parameters

Returns

Array<T>

public unique(array: List, iterator?: ListIterator, context?: any): Array<T>

see

_.uniq

Parameters

Returns

Array<T>

public unique(array: List, isSorted?: boolean, iterator?: ListIterator, context?: any): Array<T>

see

_.uniq

Parameters

  • array: List
  • isSorted?: boolean optional
  • iterator?: ListIterator optional
  • context?: any optional

Returns

Array<T>

public uniqueId(prefix: string): string

Generate a globally-unique id for client-side models or DOM elements that need one. If prefix is passed, the id will be appended to it. Without prefix, returns an integer.

Parameters

  • prefix: string

    A prefix string to start the unique ID with.

Returns

string

Unique string ID beginning with prefix.

public uniqueId(): number

see

_.uniqueId

Returns

number

public value(obj: T): TResult

Extracts the value of a wrapped object.

Parameters

  • obj: T

    Wrapped object to extract the value from.

Returns

TResult

Value of obj.

public values(object: any): Array<any>

Return all of the values of the object's properties.

Parameters

  • object: any

    Retrieve the values of all the properties on this object.

Returns

Array<any>

List of all the values on object.

public where(list: List, properties: U): Array<T>

Looks through each value in the list, returning an array of all the values that contain all of the key-value pairs listed in properties.

Parameters

  • list: List

    List to match elements again properties.

  • properties: U

    The properties to check for on each element within list.

Returns

Array<T>

The elements within list that contain the required properties.

public without(array: List, values?: Array<T>): Array<T>

Returns a copy of the array with all instances of the values removed.

Parameters

  • array: List

    The array to remove values from.

  • values?: Array<T> optional

    The values to remove from array.

Returns

Array<T>

Copy of array without values.

public wrap(fn: Function, wrapper: (fn: Function, ...args: any[]) => any): Function

Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally.

Parameters

  • fn: Function

    Function to wrap.

  • wrapper: (fn: Function, ...args: any[]) => any

    The function that will wrap fn.

Returns

Function

Wrapped version of `fn.

public zip(arrays?: Array<any[]>): Array<any[]>

Merges together the values of each of the arrays with the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes. If you're working with a matrix of nested arrays, zip.apply can transpose the matrix in a similar fashion.

Parameters

  • arrays?: Array<any[]> optional

    The arrays to merge/zip.

Returns

Array<any[]>

Zipped version of arrays.

public zip(arrays?: Array<any>): Array<any>

see

_.zip

Parameters

  • arrays?: Array<any> optional

Returns

Array<any>