Skip to content

Latest commit

 

History

History
1063 lines (853 loc) · 28.4 KB

API.md

File metadata and controls

1063 lines (853 loc) · 28.4 KB

API

NOTES

  • These API docs are still being written. However, we have attempted to stick to the Lodash signature as much as possible. So, in most cases, the lodash documentation is a good point of reference.
  • All mudash methods are immutable. The signatures of a few methods are different from Lodash.
  • mudash uses data type hinting to determine return type. In most cases if a method receives an Immutable data type it will return the result in an Immutable form and equivalent for mutable data.
  • A few additional methods exist beyond what is provided by Lodash. These have been documented here.

Legend

  • *TODO - Immutable.JS support still needs to be implemented
  • *Lo - No changes from Lodash method required (passthrough to Lodash)

TOC

Array and Immutable.List

chunk()

chunk(
  data: Array | List,
  size: number
): Array | List

Creates an array or list of elements split into groups the length of size. If data can't be split evenly, the final chunk will be the remaining elements.

difference()

difference(
  data: Array | List,
  ...values: Array<Array | List>
): Array | List

Creates an Indexed instance of values not included in the other given Indexed instances using SameValueZeroOrImmutableEqual for equality comparisons. The order and references of result values are determined by the first Indexed instance.

differenceBy()

differenceBy(
  data: Array | List,
  ...values: Array<Array | List>,
  iteratee=_.identity: (
    value: any
  ) => any
): Array | List

This method is like difference except that it accepts iteratee which is invoked for each element of data and values to generate the criterion by which they're compared. The order and references of result values are determined by the first Indexed instance.

differenceWith()

differenceWith(
  data: Array | List,
  ...values: Array<Array | List>,
  comparator=_.identity: (
    dataValue: any,
    otherValue: any
  ) => boolean
): Array | List

This method is like difference except that it accepts comparator which is invoked to compare elements of data to values. The order and references of result values are determined by the first Indexed instance.

drop()

drop(
  data: Array | Immutable.List,
  n: number
): Array | Immutable.List

Creates an slice of data with n elements dropped from the beginning.

dropRight()

dropRight(
  data: Array | Immutable.List,
  n: number
): Array | Immutable.List

Creates an slice of data excluding n elements dropped from the end.

dropRightWhile()

dropRightWhile(
  data: Array | List,
  predicate: (
    value: any,
    index: number,
    data: Array | Immutable.List
  ) => any
): Array | Immutable.List

Creates a slice of data excluding elements dropped from the end. Elements are dropped until predicate returns falsey.

dropWhile()

dropWhile(
  data: Array | List,
  predicate: (
    value: any,
    index: number,
    data: Array | Immutable.List
  ) => any
): Array | Immutable.List

Creates a slice of data excluding elements dropped from the beginning. Elements are dropped until predicate returns falsey.

Collection and Immutable.Iterable

find()

find(
  data: Array | Immutable.Iterable | Object,
  ?predicate=_.identity: (
    value: any,
    key: string | number,
    collection: Array | Immutable.Iterable | Object
  ) => boolean,
  ?fromIndex=0: number
): any

Iterates over elements of collection, returning the first element predicate returns truthy for.

forEach()

forEach(
  data: Array | Immutable.Iterable | Object,
  ?iteratee=_.identity: (
    value: any,
    key: string | number,
    data: Array | Immutable.Iterable | Object
  ) => boolean
): Array | Immutable.Iterable | Object

Iterates over elements of data and invokes iteratee for each element. Iteratee functions may exit iteration early by explicitly returning false.

forEachRight()

forEachRight(
  data: Array | Immutable.Iterable | Object,
  ?iteratee=_.identity: (
    value: any,
    key: string | number,
    data: Array | Immutable.Iterable | Object
  ) => boolean
): Array | Immutable.Iterable | Object

This method is like forEach except that it iterates over elements of data from right to left.

includes()

includes(
  data: Array | Immutable.Iterable | Object | String,
  value: any,
  ?fromIndex=0: number
): boolean

Checks if value is in data. If data is a string, it's checked for a substring of value, otherwise SameValueZeroOrImmutableEqual is used for equality comparisons. If fromIndex is negative, it's used as the offset from the end of collection.

includesWith()

includes(
  data: Array | Immutable.Iterable | Object | String,
  value: any,
  comparator: (
    dataValue: any,
    value: any
  ) => boolean,
  ?fromIndex=0: number
): boolean

This method is like includes except that it accepts comparator which is invoked to compare elements of the data to the value.

slice()

slice(

): Array | Immutable.Iterable | Object

Creates a slice of an Indexed value from start up to, but not including, end.

If the requested slice is equivalent to the current Indexed, then it will return itself.

Function

compose()

compose(
  ...functions: Array<any => any>
): (...args:any) => any

Used to compose multiple functions together in to a single function

Lang

isArray()

isArray(
  data: any
): boolean

Returns true if value is an Array. Otherwise false.

isArrayLike()

isArrayLike(
  data: any
): boolean

Returns true if value is array-like. Otherwise false.

A value is considered array-like if it's not a function and has a value.length that's an integer greater than or equal to 0 and less than or equal to Number.MAX_SAFE_INTEGER.

isBoolean()

isBoolean(
  data: any
): boolean

Returns true if value is classified as a boolean primitive or object. Otherwise false.

isFunction()

isFunction(
  data: any
): boolean

Returns true if data is classified as a function. Otherwise false.

isImmutable()

aliases: isIm

isImmutable(
  data: any
): boolean

Returns true if data is an immutable data type from immutable js. Otherwise false.

isImmutableIndexedSeq()

aliases: isImIndexedSeq

isImmutableIndexedSeq(
  data: any
): boolean

Returns true if data is of type Immutable.Seq.Indexed. Otherwise false.

isImmutableIterable()

aliases: isImIterable

isImmutableIterable(
  data: any
): boolean

Returns true if data is of type Immutable.Iterable. Otherwise false.

isImmutableKeyedSeq()

aliases: isImKeyedSeq

isImmutableKeyedSeq(
  data: any
): boolean

Returns true if data is of type Immutable.Seq.Keyed. Otherwise false.

isImmutableList()

aliases: isImList

isImmutableList(
  data: any
): boolean

Returns true if data is of type Immutable.List. Otherwise false.

isImmutableMap()

aliases: isImMap

isImmutableMap(
  data: any
): boolean

Returns true if data is of type Immutable.Map. Otherwise false.

isImmutableOrderedMap()

aliases: isImOrderedMap

isImmutableOrderedMap(
  data: any
): boolean

Returns true if data is of type Immutable.OrderedMap. Otherwise false.

isImmutableOrderedSet()

aliases: isImOrderedSet

isImmutableOrderedSet(
  data: any
): boolean

Returns true if data is of type Immutable.OrderedSet. Otherwise false.

isImmutableSeq()

aliases: isImSeq

isImmutableSeq(
  data: any
): boolean

Returns true if data is of type Immutable.Seq. Otherwise false.

isImmutableSet()

aliases: isImSet

isImmutableSet(
  data: any
): boolean

Returns true if data is of type Immutable.Set. Otherwise false.

isImmutableSetSeq()

aliases: isImSetSeq

isImmutableSetSeq(
  data: any
): boolean

Returns true if data is of type Immutable.Seq.Set. Otherwise false.

isImmutableStack()

aliases: isImStack

isImmutableStack(
  data: any
): boolean

Returns true if data is of type Immutable.Stack. Otherwise false.

isLength()

isLength(
  data: any
): boolean

Returns true if value is a valid array-like length. Otherwise false.

isNil()

isNil(
  data: any
): boolean

Returns true if value is null or undefined. Otherwise false.

isNumber()

isNumber(
  data: any
): boolean

Returns true if value is classified as a Number primitive or object. Otherwise false.

isObject()

isObject(
  data: any
): boolean

Returns true if value is the language type of Object. Otherwise false.

isString()

isString(
  data: any
): boolean

Returns true if value is classified as a String primitive or object. Otherwise false.

isSymbol()

isSymbol(
  data: any
): boolean

Returns true if value is classified as a Symbol primitive or object. Otherwise false.

toFinite()

toFinite(
  data: any
): number

Converts value to a finite number.

toInteger()

toInteger(
  data: any
): number

Converts value to an integer.

toNumber()

toNumber(
  data: any
): number

Converts value to a number.

Object and Immutable.Map

set()

Note: Unlike Lodash, this method is immutable and does NOT mutate data.

set(
  data: Array | Immutable.List | Immutable.Map | Object,
  path: string,
  value: any
): Array | Immutable.List | Immutable.Map | Object

Sets the value at path of data. If a portion of path doesn't exist, it's created. When creating path, this method will preserve the parent data type. Therefore, Immutable instances will be created for Immutable parents and mutable Object/Array instances will be created for mutable parents. Arrays and Lists will be created for index properties while Objects and Maps are created for all other missing properties. Use setWith to customize path creation.

setWith()

Note: Unlike Lodash, this method is immutable and does NOT mutate data.

setWith(
  data: Array | Immutable.List | Immutable.Map | Object,
  path: string,
  value: any,
  ?customizer: (
    value: any,
    key: string,
    data: Array | Immutable.List | Immutable.Map | Object,
  ) => Array | Immutable.List | Immutable.Map | Object
): Array | Immutable.List | Immutable.Map | Object

This method is like set except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead.

unset()

Note: Unlike Lodash, this method is immutable and does NOT mutate data.

unset(
  data: Array | Immutable.List | Immutable.Map | Object,
  path: string
): Array | Immutable.List | Immutable.Map | Object

Removes the property at path of data. This method returns a new instance.

update()

Note: Unlike Lodash, this method is immutable and does NOT mutate data.

update(
  data: Array | Immutable.List | Immutable.Map | Object,
  path: string,
  updater: (value: any) => any
): Array | Immutable.List | Immutable.Map | Object

This method is like set except that accepts updater to produce the value to set. Use updateWith to customize path creation. This method returns a new instance.

updateWith()

Note: Unlike Lodash, this method is immutable and does NOT mutate data.

updateWith(
  data: Array | Immutable.List | Immutable.Map | Object,
  path: string,
  updater: (value: any) => any,
  ?customizer: (
    value: any,
    key: string,
    data: Array | Immutable.List | Immutable.Map | Object,
  ) => Array | Immutable.List | Immutable.Map | Object
): Array | Immutable.List | Immutable.Map | Object

This method is like update except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead. This method returns a new instance.