or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array-methods.mdcollection-methods.mdfunction-methods.mdindex.mdlang-methods.mdmath-methods.mdobject-methods.mdstring-methods.mdutil-methods.md
tile.json

util-methods.mddocs/

Utility Methods

General-purpose utilities including function creation, control flow, miscellaneous helpers, and core Lodash functionality.

Capabilities

Attempt

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

/**
 * Attempts to invoke `func`, returning either the result or the caught error object.
 * Any additional arguments are provided to `func` when it's invoked.
 * @param func - The function to attempt
 * @param args - The arguments to invoke `func` with
 * @returns Returns the `func` result or error object
 */
function attempt<T>(func: (...args: any[]) => T, ...args: any[]): T | Error;

Bind All

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

/**
 * Binds methods of an object to the object itself, overwriting the existing
 * methods.
 * @param object - The object to bind and assign the bound methods to
 * @param methodNames - The object method names to bind
 * @returns Returns `object`
 */
function bindAll<T>(object: T, ...methodNames: string[]): T;

Cond

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

/**
 * Creates a function that iterates over `pairs` and invokes the corresponding
 * function of the first predicate to return truthy. The predicate-function
 * pairs are invoked with the `this` binding and arguments of the created function.
 * @param pairs - The predicate-function pairs
 * @returns Returns the new composite function
 */
function cond<T, R>(pairs: Array<[(args: T) => boolean, (args: T) => R]>): (args: T) => R;
function cond<R>(pairs: Array<[(...args: any[]) => boolean, (...args: any[]) => R]>): (...args: any[]) => R;

Conforms

Creates a function that invokes the predicate properties of source with the corresponding property values of a given object, returning true if all predicates return truthy, else false.

/**
 * Creates a function that invokes the predicate properties of `source` with
 * the corresponding property values of a given object, returning `true` if
 * all predicates return truthy, else `false`.
 * @param source - The object of property predicates to conform to
 * @returns Returns the new spec function
 */
function conforms<T>(source: Record<keyof T, (value: any) => boolean>): (object: T) => boolean;

Constant

Creates a function that returns value.

/**
 * Creates a function that returns `value`.
 * @param value - The value to return from the new function
 * @returns Returns the new constant function
 */
function constant<T>(value: T): () => T;

Default To

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

/**
 * Checks `value` to determine whether a default value should be returned in
 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
 * or `undefined`.
 * @param value - The value to check
 * @param defaultValue - The default value
 * @returns Returns the resolved value
 */
function defaultTo<T>(value: T | null | undefined, defaultValue: T): T;
function defaultTo<T, TDefault>(value: T | null | undefined, defaultValue: TDefault): T | TDefault;

Flow

Creates a function that is the composition of the provided functions, where each successive invocation is supplied the return value of the previous.

/**
 * Creates a function that is the composition of the provided functions,
 * where each successive invocation is supplied the return value of the previous.
 * @param funcs - The functions to invoke
 * @returns Returns the new composite function
 */
function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(
  f1: (...args: A) => R1,
  f2: (a: R1) => R2,
  f3?: (a: R2) => R3,  
  f4?: (a: R3) => R4,
  f5?: (a: R4) => R5,
  f6?: (a: R5) => R6,
  f7?: (a: R6) => R7
): (...args: A) => R7;

function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;

Flow Right

Like flow except that it creates a function that invokes the given functions from right to left.

/**
 * This method is like `flow` except that it creates a function that invokes
 * the given functions from right to left.
 * @param funcs - The functions to invoke
 * @returns Returns the new composite function
 */
function flowRight<A extends any[], R1, R2, R3, R4, R5, R6, R7>(
  f7: (a: R6) => R7,
  f6?: (a: R5) => R6,
  f5?: (a: R4) => R5,
  f4?: (a: R3) => R4,
  f3?: (a: R2) => R3,
  f2?: (a: R1) => R2,
  f1?: (...args: A) => R1
): (...args: A) => R7;

function flowRight(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;

Identity

This method returns the first argument it receives.

/**
 * This method returns the first argument it receives.
 * @param value - Any value
 * @returns Returns `value`
 */
function identity<T>(value: T): T;

Iteratee

Creates a function that invokes func with the arguments of the created function.

/**
 * Creates a function that invokes `func` with the arguments of the created
 * function. If `func` is a property name, the created function returns the
 * property value for a given element. If `func` is an array or object, the
 * created function returns `true` for elements that contain the equivalent
 * source properties, otherwise it returns `false`.
 * @param func - The value to convert to a callback
 * @returns Returns the callback
 */
function iteratee<T>(func?: T): T extends string 
  ? (object: any) => any
  : T extends object
  ? (object: any) => boolean  
  : T extends (...args: any[]) => any
  ? T
  : (value: any) => any;

Matches

Creates a function that performs a partial deep comparison between a given object and source, returning true if the given object has equivalent property values, else false.

/**
 * Creates a function that performs a partial deep comparison between a given
 * object and `source`, returning `true` if the given object has equivalent
 * property values, else `false`.
 * @param source - The object of property values to match
 * @returns Returns the new spec function
 */
function matches<T>(source: T): (object: any) => boolean;

Matches Property

Creates a function that performs a partial deep comparison between the value at path of a given object to srcValue, returning true if the object value is equivalent, else false.

/**
 * Creates a function that performs a partial deep comparison between the
 * value at `path` of a given object to `srcValue`, returning `true` if the
 * object value is equivalent, else `false`.
 * @param path - The path of the property to get
 * @param srcValue - The value to match
 * @returns Returns the new spec function
 */
function matchesProperty(path: PropertyPath, srcValue: any): (object: any) => boolean;

Method

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

/**
 * Creates a function that invokes the method at `path` of a given object.
 * Any additional arguments are provided to the invoked method.
 * @param path - The path of the method to invoke
 * @param args - The arguments to invoke the method with
 * @returns Returns the new invoker function
 */
function method(path: PropertyPath, ...args: any[]): (object: any) => any;

Method Of

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

/**
 * The opposite of `method`; this method creates a function that invokes
 * the method at a given path of `object`. Any additional arguments are
 * provided to the invoked method.
 * @param object - The object to query
 * @param args - The arguments to invoke the method with
 * @returns Returns the new invoker function
 */
function methodOf(object: any, ...args: any[]): (path: PropertyPath) => any;

Mixin

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

/**
 * Adds all own enumerable string keyed function properties of a source
 * object to the destination object. If `object` is a function, then methods
 * are added to its prototype as well.
 * @param object - The destination object
 * @param source - The object of functions to add
 * @param options - The options object
 * @returns Returns `object`
 */
function mixin<T>(object: T, source: any, options?: { chain?: boolean }): T;
function mixin(source: any, options?: { chain?: boolean }): typeof _;

No Conflict

Reverts the _ variable to its previous value and returns a reference to the lodash function.

/**
 * Reverts the `_` variable to its previous value and returns a reference to
 * the `lodash` function.
 * @returns Returns the `lodash` function
 */
function noConflict(): typeof _;

Noop

This method returns undefined.

/**
 * This method returns `undefined`.
 * @returns Returns `undefined`
 */
function noop(): void;

Nth Arg

Creates a function that gets the argument at index n.

/**
 * Creates a function that gets the argument at index `n`. If `n` is negative,
 * the nth argument from the end is returned.
 * @param n - The index of the argument to return
 * @returns Returns the new pass-thru function
 */
function nthArg(n?: number): (...args: any[]) => any;

Over

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

/**
 * Creates a function that invokes `iteratees` with the arguments it receives
 * and returns their results.
 * @param iteratees - The iteratees to invoke
 * @returns Returns the new function
 */
function over<T extends ReadonlyArray<(...args: any[]) => any>>(
  ...iteratees: T
): (...args: any[]) => { [K in keyof T]: T[K] extends (...args: any[]) => infer R ? R : never };

Over Every

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

/**
 * Creates a function that checks if **all** of the provided predicates return
 * truthy when invoked with the arguments it receives.
 * @param predicates - The predicates to check
 * @returns Returns the new function
 */
function overEvery<T extends ReadonlyArray<(...args: any[]) => boolean>>(
  ...predicates: T
): (...args: any[]) => boolean;

Over Some

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

/**
 * Creates a function that checks if **any** of the provided predicates return
 * truthy when invoked with the arguments it receives.
 * @param predicates - The predicates to check
 * @returns Returns the new function
 */
function overSome<T extends ReadonlyArray<(...args: any[]) => boolean>>(
  ...predicates: T
): (...args: any[]) => boolean;

Property

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

/**
 * Creates a function that returns the value at `path` of a given object.
 * @param path - The path of the property to get
 * @returns Returns the new accessor function
 */
function property<T>(path: PropertyPath): (obj: any) => T;

Property Of

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

/**
 * The opposite of `property`; this method creates a function that returns
 * the value at a given path of `object`.
 * @param object - The object to query
 * @returns Returns the new accessor function
 */
function propertyOf<T>(object: T): (path: PropertyPath) => any;

Run In Context

Create a pristine lodash function to avoid conflicts caused by modifying the original.

/**
 * Create a pristine `lodash` function to avoid conflicts caused by modifying
 * the original.
 * @param context - The context object
 * @returns Returns a new `lodash` function
 */
function runInContext(context?: any): typeof _;

Times

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

/**
 * Invokes the iteratee `n` times, returning an array of the results of
 * each invocation. The iteratee is invoked with one argument; (index).
 * @param n - The number of times to invoke `iteratee`
 * @param iteratee - The function invoked per iteration
 * @returns Returns the array of results
 */
function times<T>(n: number, iteratee: (index: number) => T): T[];
function times(n: number): number[];

Unique Id

Generates a unique ID.

/**
 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
 * @param prefix - The value to prefix the ID with
 * @returns Returns the unique ID
 */
function uniqueId(prefix?: string): string;

Date Methods

Now

Gets the timestamp of the number of milliseconds that have elapsed since the Unix epoch.

/**
 * Gets the timestamp of the number of milliseconds that have elapsed since
 * the Unix epoch (1 January 1970 00:00:00 UTC).
 * @returns Returns the timestamp
 */
function now(): number;

Number Methods

Clamp

Clamps number within the inclusive lower and upper bounds.

/**
 * Clamps `number` within the inclusive `lower` and `upper` bounds.
 * @param number - The number to clamp
 * @param lower - The lower bound
 * @param upper - The upper bound
 * @returns Returns the clamped number
 */
function clamp(number: number, lower: number, upper?: number): number;

Random

Produces a random number between the inclusive lower and upper bounds.

/**
 * Produces a random number between the inclusive `lower` and `upper` bounds.
 * If only one argument is provided a number between `0` and the given number
 * is returned. If `floating` is `true`, or either `lower` or `upper` are
 * floats, a floating-point number is returned instead of an integer.
 * @param lower - The lower bound
 * @param upper - The upper bound
 * @param floating - Specify returning a floating-point number
 * @returns Returns the random number
 */
function random(lower?: number, upper?: number, floating?: boolean): number;
function random(floating?: boolean): number;

Sequence Methods

Chain

Creates a lodash wrapper instance that wraps value with explicit method chain sequences enabled.

/**
 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
 * chain sequences enabled. The result of such sequences must be unwrapped
 * with `_#value`.
 * @param value - The value to wrap
 * @returns Returns the new `lodash` wrapper instance
 */
function chain<T>(value: T): LodashExplicitWrapper<T>;

Tap

This method invokes interceptor and returns value.

/**
 * This method invokes `interceptor` and returns `value`. The interceptor
 * is invoked with one argument; (value). The purpose of this method is to
 * "tap into" a method chain sequence in order to modify intermediate results.
 * @param value - The value to provide to `interceptor`
 * @param interceptor - The function to invoke
 * @returns Returns `value`
 */
function tap<T>(value: T, interceptor: (value: T) => void): T;

Thru

This method is like tap except that it returns the result of interceptor.

/**
 * This method is like `tap` except that it returns the result of `interceptor`.
 * The purpose of this method is to "pass thru" values replacing intermediate
 * results in a method chain sequence.
 * @param value - The value to provide to `interceptor`
 * @param interceptor - The function to invoke
 * @returns Returns the result of `interceptor`
 */
function thru<T, R>(value: T, interceptor: (value: T) => R): R;

Method Aliases

Each

Alias for forEach. Iterates over elements of collection and invokes iteratee for each element.

/**
 * Iterates over elements of `collection` and invokes `iteratee` for each element.
 * The iteratee is invoked with three arguments: (value, index|key, collection).
 * Iteratee functions may exit iteration early by explicitly returning `false`.
 * @param collection - The collection to iterate over
 * @param iteratee - The function invoked per iteration
 * @returns Returns `collection`
 */
function each<T>(collection: T[], iteratee?: (value: T, index: number, collection: T[]) => any): T[];
function each<T>(collection: Record<string, T>, iteratee?: (value: T, key: string, collection: Record<string, T>) => any): Record<string, T>;

Each Right

Alias for forEachRight. Like each except that it iterates over elements of collection from right to left.

/**
 * This method is like `each` except that it iterates over elements of
 * `collection` from right to left.
 * @param collection - The collection to iterate over
 * @param iteratee - The function invoked per iteration
 * @returns Returns `collection`
 */
function eachRight<T>(collection: T[], iteratee?: (value: T, index: number, collection: T[]) => any): T[];
function eachRight<T>(collection: Record<string, T>, iteratee?: (value: T, key: string, collection: Record<string, T>) => any): Record<string, T>;

Entries

Alias for toPairs. Creates an array of own enumerable string keyed-value pairs for object.

/**
 * Creates an array of own enumerable string keyed-value pairs for `object`
 * which can be consumed by `fromPairs`. If `object` is a map or set, its
 * entries are returned.
 * @param object - The object to query
 * @returns Returns the key-value pairs
 */
function entries<T>(object?: Record<string, T>): Array<[string, T]>;
function entries(object?: any): Array<[string, any]>;

Entries In

Alias for toPairsIn. Creates an array of own and inherited enumerable string keyed-value pairs for object.

/**
 * Creates an array of own and inherited enumerable string keyed-value pairs
 * for `object` which can be consumed by `fromPairs`. If `object` is a map
 * or set, its entries are returned.
 * @param object - The object to query
 * @returns Returns the key-value pairs
 */
function entriesIn<T>(object?: Record<string, T>): Array<[string, T]>;
function entriesIn(object?: any): Array<[string, any]>;

Extend

Alias for assign. Assigns own enumerable string keyed properties of source objects to the destination object.

/**
 * Assigns own enumerable string keyed properties of source objects to the
 * destination object. Source objects are applied from left to right.
 * Subsequent sources overwrite property assignments of previous sources.
 * @param object - The destination object
 * @param sources - The source objects
 * @returns Returns `object`
 */
function extend<TObject, TSource>(object: TObject, source: TSource): TObject & TSource;
function extend<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;
function extend<TObject>(object: TObject, ...sources: any[]): any;

Extend With

Alias for assignWith. Like extend except that it accepts customizer which is invoked to produce the assigned values.

/**
 * This method is like `extend` except that it accepts `customizer` which
 * is invoked to produce the assigned values. If `customizer` returns `undefined`,
 * assignment is handled by the method instead. The `customizer` is invoked
 * with five arguments: (objValue, srcValue, key, object, source).
 * @param object - The destination object
 * @param sources - The source objects
 * @param customizer - The function to customize assigned values
 * @returns Returns `object`
 */
function extendWith<TObject, TSource>(
  object: TObject,
  source: TSource,
  customizer: (objValue: any, srcValue: any, key: string, object: TObject, source: TSource) => any
): TObject & TSource;
function extendWith<TObject>(object: TObject, ...otherArgs: any[]): any;

First

Alias for head. Gets the first element of array.

/**
 * Gets the first element of `array`.
 * @param array - The array to query
 * @returns Returns the first element of `array`
 */
function first<T>(array: T[] | null | undefined): T | undefined;

Types

type PropertyPath = string | number | symbol | Array<string | number | symbol>;

interface LodashExplicitWrapper<TValue> {
  chain(): LodashExplicitWrapper<TValue>;
  value(): TValue;
  valueOf(): TValue;
}

declare const _: LoDashStatic;

interface LoDashStatic {
  VERSION: string;
  templateSettings: TemplateSettings;
  
  // All lodash methods
  [key: string]: any;
}

interface TemplateSettings {
  escape?: RegExp;
  evaluate?: RegExp;
  interpolate?: RegExp;
  variable?: string;
}