Home Reference Source

Function

Static Public Summary
public

F(): Boolean

A function that always returns false.

public

T(): Boolean

A function that always returns true.

public

adjust(fn: Function, idx: Number, list: Array): Array

Autocurry for 3 arguments

Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application.

public

all(fn: Function, arr: Array): Boolean

Autocurry for 2 arguments

Returns true if all the elements of the array match the predicate, false otherwise.

public

all(fn: Function, obj: Object): Boolean

Autocurry for 2 arguments

Tests whether every [key, value] pair in the object passes the test implemented by the provided function.

public

allPass(fns: Array, args: ...*): Function

Autocurry for 2 arguments

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if every one of the provided predicates is satisfied by those arguments.

public

always(x: *): Function

Returns a function that always returns the given value.

public

any(fn: Function, arr: Array): Boolean

Autocurry for 2 arguments

Returns true if at least one of elements of the list match the predicate, false otherwise.

public

any(fn: Function, obj: Object): Boolean

Autocurry for 2 arguments

Tests whether at least one [key, value] pair in the object passes the test implemented by the provided function.

public

anyPass(fns: Array, args: ...*): Function

Autocurry for 2 arguments

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if at least one of the provided predicates is satisfied by those arguments.

public

append(el: *, list: Array): Array

Autocurry for 2 arguments

Returns a new list containing the contents of the given list, followed by the given element.

public

applyOrReturn(args: Array, test: *): *

Autocurry for 2 arguments

If test is function it calls with applied first argument, otherwise just returns test

public

array(test: *): boolean

Checks if test is array.

public

arrayLike(test: *): boolean

Checks if test is arrayLike (has length and index properties).

public

assign(sources: *): *

Create a new object/array with the own properties of the first entry merged with the own properties of the others objects.

public

assoc(prop: String, val: *, obj: Object): Object

this function was deprecated. use object/propSet instead

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the given value.

public

boolean(test: *): boolean

Checks if test is boolean.

public

Autocurry for 2 arguments

A function wrapping calls to the two functions in an && operation, returning the result of the first function if it is false-y and the result of the second function otherwise.

public

Converts string to camel case.

public

Returns the capitalized version of a string.

public

clone(x: *): *

Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates.

public

Makes a comparator function out of a function that reports whether the first element is less than the second.

public

Takes a function f and returns a function g such that if called with the same arguments when f returns a "truthy" value, g returns false and when f returns a "falsy" value g returns true.

public

Performs right-to-left function composition.

public

composeP(chain: ...Function): Function

Performs right-to-left composition of Promise-returning functions.

public

Autocurry for 2 arguments

Returns the result of concatenating the given arrays or strings.

public

cond(pairs: F): Function

Returns a function, fn, which encapsulates if/else-if/else logic.

public

Creates a cache instance base on passed object.

public

Returns a curried equivalent of the provided function.

public

curryN(arity: Number, fn: Function): Function

Returns a curried equivalent of the provided function, with the specified arity.

public

Autocurry for 2 arguments

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

public

Autocurry for 2 arguments

Memoize function with multiply arguments of any type, but it clears cache every time it reaches the limit.

public

defaultTo(dflt: a, x: b): *

Autocurry for 2 arguments

Returns the second argument if it is not null, undefined or NaN otherwise the first argument is returned.

public

Autocurry for 2 arguments

Returns the array of all elements in the first array not contained in the second array.

public

drop(n: Number, xs: *): *

Autocurry for 2 arguments

Returns all but the first n elements of the given list, string.

public

Autocurry for 2 arguments

Returns a list containing all but the last n elements of the given list.

public

Autocurry for 2 arguments

Returns a new list excluding the leading elements of a given list which satisfy the supplied predicate function.

public

each(fn: Function, arr: Array)

Autocurry for 2 arguments

Iterate over an input list, calling a provided function fn for each element in the list.

public

each(fn: Function, obj: Object): Object

Autocurry for 2 arguments

Iterate over an input object, calling a provided function fn for each key and value in the object.

public

Autocurry for 2 arguments

A function wrapping calls to the two functions in an || operation, returning the result of the first function if it is truth-y and the result of the second function otherwise.

public

element(test: *): boolean

Checks if value is likely a DOM element.

public

empty(test: *): boolean

Checks if test is empty.

public

endsWith(postfix: string, str: string): Boolean

Autocurry for 2 arguments

Checks if a string ends with the provided postfix

public

eqProps(prop: String, obj1: Object, obj2: Object): Boolean

Autocurry for 3 arguments

Reports whether two objects have the same value, in equal terms, for the specified property.

public

Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.

public

Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.

public

filter(fn: Function, arr: Array): Array

Autocurry for 2 arguments

Takes a predicate and a "arr", and returns a new array of the same type containing the members of the given arr which satisfy the given predicate.

public

Autocurry for 2 arguments

Takes a predicate and a object, and returns a new object containing only members which satisfy the given predicate.

public

filterMap(filterFn: Function, mapFn: Function, arr: Array): Array

Autocurry for 3 arguments

This is shortcut for filter + map, but applied in one iteration.

public

find(fn: Function, arr: Array): Object

Autocurry for 2 arguments

Returns the first element of the list which matches the predicate, or undefined if no element matches.

public

Autocurry for 2 arguments

Returns the index of the first element of the list which matches the predicate, or -1 if no element matches.

public

Autocurry for 2 arguments

Returns first key in obj satisfied to fn, or undefined if there is no such keys

public

findLast(fn: Function, list: Array): Object

Autocurry for 2 arguments

Returns the last element of the list which matches the predicate, or undefined if no element matches.

public

finite(test: *): boolean

Checks if test is finite.

public

Returns a new list by pulling every item out of it (and all its sub-arrays) and putting them in a new array, depth-first.

public

flip(fn: Function): *

Returns a new function much like the supplied one, except that the first two arguments' order is reversed.

public

Creates a new object from a list key-value pairs.

public

function(test: *): boolean

Checks if test is function.

public

groupBy(fns: Array<Function>, list: Array): Array

Autocurry for 2 arguments

Creates an array of arrays generated from the results of running each element of list thru each fn.

public

Autocurry for 2 arguments

Creates an object composed of keys generated from the results of running each element of object thru fn.

public

has(prop: String, obj: Object): Boolean

Autocurry for 2 arguments

Returns whether or not an object has an own property with the specified name

public

head(arr: Array): *

Returns the first element of the given array.

public

identity(x: *): *

A function that does nothing but return the parameter supplied to it.

public

ifElse(condition: Function, onTrue: Function, onFalse: Function): Function

Autocurry for 3 arguments

Creates a function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

public

includes(value: *, arr: Array | String): Boolean

Autocurry for 2 arguments

Dispatches call to arr.indexOf, returns true if arr is array and value in the array or if arr is string and value is substring of arr

public

Autocurry for 2 arguments

Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key.

public

indexOf(target: *, xs: Array): Number

Autocurry for 2 arguments

Returns the position of the first occurrence of an item in an array, or -1 if the item is not included in the array.

public

init(arr: Array): *

Returns all but the last element of the given list or string.

public

Autocurry for 2 arguments

Combines two array into a set (i.e.

public

isEqual(test1: *, test2: *): Boolean

Autocurry for 2 arguments

Returns true if its arguments are equivalent, false otherwise.

public

Returns whether a value is a plain object (an object that is created using an object literal, Object.create(null) or similar).

public

isTrue(val: *): boolean

Returns true if val is true or equal to string 'true'

public

join(separator: String, arr: Array): String

Autocurry for 2 arguments

Returns a string made by inserting the separator between each element and concatenating all the elements into a single string.

public

Converts string to kebab case.

public

keyBy(fn: Function, obj: Object): Object

Autocurry for 2 arguments

Creates an object composed of keys generated from the results of running each element of object thru fn.

public

keys(obj: Object): Array

Returns a list containing the names of all the enumerable own properties of the supplied object.

public

last(arr: Array): *

Returns the last element of the given array.

public

Returns the number of elements in the array by returning arr.length.

public

map(fn: Function, arr: Array): Array

Autocurry for 2 arguments

Creates an array of values by running each element in list through fn.

public

map(fn: Function, obj: Object): Object

Autocurry for 2 arguments

Applies fn to each of the obj values, and returns new object.

public

maxBy(fn: Function, arr: Array): *

Autocurry for 2 arguments

Return max value in array, depending on result of calling fn

public

merge(sources: ...Object): Object

Autocurry for 2 arguments

Create a new object with the own properties of the first object merged with the own properties of the others objects.

public

mergeDeep(sources: ...Object): Object

Autocurry for 2 arguments

Create a new object with the own properties of the first object deeply merged with the own properties of the other objects.

public

mergeWith(fn: Function, sources: ...Object): Object

Autocurry for 3 arguments

Create a new object with the own properties of the first object merged with the own properties of the others objects.

public

Negates its argument.

public

nil(test: *): boolean

Checks if test is nil (null or undefined).

public

noop()

This method doing nothing and returns undefined.

public

not(val: *): Boolean

A function that returns the ! of its argument.

public

nothing(): Undefined

A function that always returns undefined.

public

nth(index: Number, arr: *): *

Autocurry for 2 arguments

Returns the nth element of the given array.

public

number(test: *): boolean

Checks if test is number.

public

objOf(key: String, value: *): Object

Autocurry for 2 arguments

Creates an object containing a single key:value pair.

public

object(test: *): boolean

Checks if test is object.

public

omit(props: Array, obj: Object): Object

Autocurry for 2 arguments

Returns a partial copy of an object omitting the keys specified.

public

Accepts a function fn and returns a function that guards invocation of fn such that fn can only ever be called once, no matter how many times the returned function is invoked.

public

one(fn: Function, isEqual: Function): Function

Memoize function with multiply arguments of any type.

public

Autocurry for 2 arguments

Wraps a one-parameter function, new function returns true if passed parameter is undefined, otherwise returns result of calling fn

public

Autocurry for 2 arguments

Takes a predicate and a array and returns the pair of arrays of the same type of elements which do and do not satisfy, the predicate, respectively.

public

pathApply(paths: [String], fn: Function, obj: Object): *

Autocurry for 3 arguments

Returns the result of fn with given value at path.

public

pathEq(paths: Array, value: *, obj: Object): Boolean

Autocurry for 3 arguments

Determines whether a nested path on an object has a specific value

public

pathOr(paths: [String], value: *, obj: Object): *

Autocurry for 3 arguments

If the given, non-null object has a value at the given path, returns the value at that path.

public

pathSet(paths: [String], value: *, obj: Object): Object

Autocurry for 3 arguments

Returns the result of "setting" the portion of the given data structure focused by the given paths to the given value.

public

pathSetBy(paths: [String], fn: Function, obj: Object): Object

Autocurry for 3 arguments

Returns the result of "setting" the portion of the given data structure focused by the given paths to the result of fn call.

public

pick(props: [String], obj: Object): Object

Autocurry for 2 arguments

Returns a partial copy of an object containing only the keys specified.

public

Autocurry for 2 arguments

Returns a partial copy of an object containing only the keys with fn predicate returns true

public

pluck(key: String, arr: Array): Array

Autocurry for 2 arguments

Returns a new list by plucking the same named property off all objects in the list supplied.

public

promise(test: *): boolean

Checks if test is Promise.

public

prop(prop: String, obj: Object): *

Autocurry for 2 arguments

Returns a function that when supplied an object returns the indicated property of that object, if it exists.

public

propApply(propName: String, fn: Function, obj: Object): *

Autocurry for 3 arguments

Returns the result of fn with value of property in obj.

public

propEq(propName: String, value: *, obj: *): Boolean

Autocurry for 3 arguments

Returns true if the specified object property is equal to the given value; false otherwise.

public

propOr(propName: String, value: *, obj: Object): *

Autocurry for 3 arguments

If the given, non-null object has an own property with the specified name, returns the value of that property.

public

propSet(prop: String, val: *, obj: Object): Object

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the given value.

public

propSetBy(prop: String, fn: Function, obj: Object): Object

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the result of fn call.

public

range(a: number, b: number, step: number): Array

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

public

reduce(fn: Function, acc: *, arr: Array): *

Autocurry for 3 arguments

Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.

public

reduce(fn: Function, acc: *, obj: Object): *

Autocurry for 3 arguments

Returns a single item by iterating through the obj, successively calling the iterator function and passing it an accumulator value, current value and current key from the obj, and then passing the result to the next call.

public

reduceWhile(pred: Function, fn: Function, acc: *, arr: Array): *

Autocurry for 4 arguments

Returns a single item by iterating through the list, successively calling the iterator function.

public

reject(fn: Function, arr: Array): Array

Autocurry for 2 arguments

Takes a predicate and a "arr", and returns a new array of the same type containing the members of the given arr which do not satisfy the given predicate.

public

rejectWith(func: Function, payload: *[]): Promise

Autocurry for 2 arguments

Returns a promise that rejects with a value returned by the supplied function when passed the supplied payload

public

remove(start: Number, count: Number, list: Array): *

Autocurry for 3 arguments

Removes the sub-list of list starting at index start and containing count elements.

public

repeat(n: Number, value: *): Array

Autocurry for 2 arguments

Returns a fixed list of size n containing a specified identical value.

public

repeat(n: Number, value: String): String

Autocurry for 2 arguments

Returns a string containing a repeated identical value.

public

replace(pattern: RegExp | String, replacement: String, str: String): String

Autocurry for 3 arguments

Replace a substring or regex match in a string with a replacement.

public

resolveWith(func: Function, payload: *[]): Promise

Autocurry for 2 arguments

Returns a promise that resolves with a value returned by the supplied function when passed the supplied payload

public

Returns a new list or string with the elements or characters in reverse order.

public

shallowEqual(test1: *, test2: *): Boolean

Returns true if its arguments are equivalent is shallow equal terms, false otherwise.

public

Creates an array of shuffled values

public

size(obj: Object): number

Gets the size of obj by returning the number of own enumerable properties.

public

slice(fromIndex: Number, toIndex: Number, list: Array | String): Array | String

Autocurry for 3 arguments

Returns the elements of the given list or string (or object with a slice method) from fromIndex (inclusive) to toIndex (exclusive).

public

Returns the snake case version of a string.

public

sort(comparator: Function, arr: Array): Array

Autocurry for 2 arguments

Returns a copy of the array, sorted according to the comparator function, which should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal. Please note that this is a copy of the list. It does not modify the original.

public

sortBy(fn: Function, arr: Array): Array

Autocurry for 2 arguments

Sorts the array according to the supplied function.

public

split(delim: String | RegExp, str: String): Array

Autocurry for 2 arguments

Splits a string into an array of strings based on the given separator.

public

splitEvery(length: Number, arr: Array | String): Array[] | String[]

Autocurry for 2 arguments

Splits a collection into slices of the specified length

public

Autocurry for 2 arguments

Sorts the array according to the supplied function and keeping the order of elements.

public

startsWith(prefix: string, str: string): Boolean

Autocurry for 2 arguments

Checks if a string starts with the provided prefix

public

strictEqual(test1: *, test2: *): Boolean

Returns true if its arguments are equivalent is same value zero terms, false otherwise.

public

string(test: *): boolean

Checks if test is string.

public

sum(arr: Array): Number

Adds together all the elements of a list.

public

tail(arr: Array): *

Returns all but the first element of the given array.

public

take(n: Number, arr: Array | String): *

Autocurry for 2 arguments

Returns the first n elements of the given array or string

public

Autocurry for 2 arguments

Returns a new array|string containing the last n elements of a given array|string, passing each value to the supplied predicate function, and terminating when the predicate function returns false.

public

tap(fn: Function, x: *): *

Autocurry for 2 arguments

Runs the given function with the supplied argument, then returns the argument.

public

tap(fn: Function, x: *): *

Autocurry for 2 arguments

Runs the given promise with the supplied argument.

public

template(replacements: Object, str: String): String

Autocurry for 2 arguments

Replaces string keywords with provided values

public

test(pattern: RegExp, str: String): Boolean

Autocurry for 2 arguments

Determines whether a given string matches a given regular expression.

public

throttle(wait: number, fn: Function): *

Autocurry for 2 arguments

Creates a throttled function that only invokes fn at most once per every wait milliseconds.

public

throttleEnd(wait: number, fn: Function): *

Autocurry for 2 arguments

Creates a throttled function that only invokes fn at most once per every wait milliseconds.

public

toArray(val: *): Array

Converts val to array.

public

Returns the lower case version of a string.

public

Converts an object into an array of key, value arrays.

public

toString(val: *): string

Converts value to a string.

public

Returns the upper case version of a string.

public

trim(str: String): String

Removes leading and trailing whitespace from str.

public

Removes leading whitespace from str.

public

tryCatch(tryer: Function, catcher: Function): Function

Autocurry for 2 arguments

Takes two functions, tryer and catcher.

public

type(x: *): String

Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', 'Number', 'Array', or 'Null'.

public

undefined(test: *): boolean

Checks if test is undefined.

public

The inverse of escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.

public

uniq(arr: Array): Array

Returns unique items in array

public

uniqBy(fn: Function, arr: Array): Array

Autocurry for 2 arguments

Returns unique items in array.

public

Generates a unique ID.

public

update(idx: Number, x: *, list: Array): Array

Autocurry for 3 arguments

Returns a new copy of the array with the element at the provided index replaced with the given value.

public

updatePropertyValue(propertyName: String, propertyValue: Any, obj: Object): Object

this function was deprecated. use propSet instead

Autocurry for 2 arguments

A function to change value by property name in object.

public

Converts the first character of string to upper case and returns the new string.

public

Returns a list of all the enumerable own properties of the supplied object.

public

when(pred: Function, onTrue: Function, x: *): *

Autocurry for 3 arguments

Tests the final argument by passing it to the given predicate function.

public

where(spec: Object, obj: Object): Boolean

Autocurry for 2 arguments

Takes a spec object and a test object; returns true if the test satisfies the spec.

public

with(createCache: Function, hasher: Function, function: Function): Function

Autocurry for 3 arguments

memoizeWith is a memoize function fabric.

public

without(xs: Array, list: Array): Array

this function was deprecated. use array/difference instead

Autocurry for 2 arguments

Returns a new list without values in the first argument.

public

words(str: String): String[]

Splits string into an array of its words.

public

zip(a: Array, b: Array): Array

Autocurry for 2 arguments

Creates a new list out of the two supplied by pairing up equally-positioned items from both lists.

public

zipWith(fn: Function, a: Array, b: Array): Array

Autocurry for 3 arguments

Creates a new list out of the two supplied by applying the function to each equally-positioned pair in the lists.

Static Private Summary
private

_path(paths: *[], obj: {}): *

Autocurry for 2 arguments

null

Static Public

public F(): Boolean source

A function that always returns false. Any passed in parameters are ignored.

Return:

Boolean

Example:


     F(); //=> false

public T(): Boolean source

A function that always returns true. Any passed in parameters are ignored.

Return:

Boolean

Example:


     T(); //=> true

public adjust(fn: Function, idx: Number, list: Array): Array source

import adjust from '@tinkoff/utils/array/adjust'

Autocurry for 3 arguments

Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application.

Params:

NameTypeAttributeDescription
fn Function

The function to apply.

idx Number

The index.

list Array

An array whose value at the supplied index will be replaced.

Return:

Array

A copy of the supplied array with the element at index idx replaced with the value returned by applying fn to the existing element.

Example:


     adjust(add(10), 1, [1, 2, 3]);     //=> [1, 12, 3]
     adjust(add(10))(1)([1, 2, 3]);     //=> [1, 12, 3]

public all(fn: Function, arr: Array): Boolean source

import all from '@tinkoff/utils/array/all'

Autocurry for 2 arguments

Returns true if all the elements of the array match the predicate, false otherwise.

Params:

NameTypeAttributeDescription
fn Function

The predicate function.

arr Array

The array to consider.

Return:

Boolean

true if the predicate is satisfied all elements, false otherwise.

Example:


     var lessThan2 = x => x < 2;
     var lessThan3 = x => x < 3;
     all(lessThan2)([1, 2]); //=> false
     all(lessThan3)([1, 2]); //=> true

public all(fn: Function, obj: Object): Boolean source

import all from '@tinkoff/utils/object/all'

Autocurry for 2 arguments

Tests whether every [key, value] pair in the object passes the test implemented by the provided function.

Params:

NameTypeAttributeDescription
fn Function

The function to test for each [key, value] pair. Takes a predicate and an object.

obj Object

The object whose enumerable own property [key, value] pairs are to be tested.

Return:

Boolean

Returns true if the callback function returns a truthy value for every [key, value] pair, otherwise, false.

Example:


     var isBiggerThanZero = x => x > 0;

     all(isBiggerThanZero, {}); //=> true
     all(isBiggerThanZero, { a: 1 }); //=> true
     all(isBiggerThanZero, { a: 1, b: 1, c: 1 }); //=> true
     all(isBiggerThanZero, { a: 0, b: 1, c: 0 }); //=> false
     all(isBiggerThanZero, { a: 1, b: 0, c: 1 }); //=> false
     all(isBiggerThanZero)({ a: 0, b: 0, c: 0 }); //=> false
     all(isBiggerThanZero)({ a: 1, b: 0, c: 1 }); //=> false

public allPass(fns: Array, args: ...*): Function source

import allPass from '@tinkoff/utils/function/allPass'

Autocurry for 2 arguments

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if every one of the provided predicates is satisfied by those arguments.

Params:

NameTypeAttributeDescription
fns Array

predicates

args ...*

passed arguments to predicates

Return:

Function

Example:


     var isQueen = propEq('rank', 'Q');
     var isSpade = propEq('suit', '♠︎');
     var isQueenOfSpades = allPass([isQueen, isSpade]);

     isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false
     isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true

public always(x: *): Function source

import always from '@tinkoff/utils/function/always'

Returns a function that always returns the given value. Note that for non-primitives the value returned is a reference to the original value.

Params:

NameTypeAttributeDescription
x *

The value to wrap in a function

Return:

Function

Example:


     var t = always('Tee');
     t(); //=> 'Tee'

public any(fn: Function, arr: Array): Boolean source

import any from '@tinkoff/utils/array/any'

Autocurry for 2 arguments

Returns true if at least one of elements of the list match the predicate, false otherwise.

Params:

NameTypeAttributeDescription
fn Function

The predicate function.

arr Array

The array to consider.

Return:

Boolean

true if the predicate is satisfied by at least one element, false otherwise.

Example:


     var lessThan0 = x => x < 0;
     var lessThan2 = x => x < 2;
     any(lessThan0)([1, 2]); //=> false
     any(lessThan2)([1, 2]); //=> true

public any(fn: Function, obj: Object): Boolean source

import any from '@tinkoff/utils/object/any'

Autocurry for 2 arguments

Tests whether at least one [key, value] pair in the object passes the test implemented by the provided function.

Params:

NameTypeAttributeDescription
fn Function

The function to test for each [key, value] pair. Takes a predicate and an object.

obj Object

The object whose enumerable own property [key, value] pairs are to be tested.

Return:

Boolean

Returns true if the callback function returns a truthy value for any [key, value] pair, otherwise, false.

Example:


     var isBiggerThanZero = x => x > 0;

     any(isBiggerThanZero, {}); //=> false
     any(isBiggerThanZero, { a: 0 }); //=> false
     any(isBiggerThanZero, { a: 0, b: 1, c: 0 }); //=> true
     any(isBiggerThanZero, { a: 1, b: 0, c: -1 }); //=> true
     any(isBiggerThanZero)({ a: 0, b: 0, c: 0 }); //=> false
     any(isBiggerThanZero)({ a: 0, b: 1, c: 0 }); //=> true

public anyPass(fns: Array, args: ...*): Function source

import anyPass from '@tinkoff/utils/function/anyPass'

Autocurry for 2 arguments

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if at least one of the provided predicates is satisfied by those arguments.

Params:

NameTypeAttributeDescription
fns Array

predicates

args ...*

passed arguments to predicates

Return:

Function

Example:


     var isClub = propEq('rank', '♣');
     var isSpade = propEq('suit', '♠︎');
     var isBlackCard = anyPass([isClub, isSpade]);

     isBlackCard({rank: '10', suit: '♣'}); //=> true
     isBlackCard({rank: 'Q', suit: '♠'}); //=> true
     isBlackCard({rank: 'Q', suit: '♦'}); //=> false

public append(el: *, list: Array): Array source

import append from '@tinkoff/utils/array/append'

Autocurry for 2 arguments

Returns a new list containing the contents of the given list, followed by the given element.

Params:

NameTypeAttributeDescription
el *

The element to add to the end of the new list.

list Array

The list of elements to add a new item to. list.

Return:

Array

A new list containing the elements of the old list followed by el.

Example:


     append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
     append('tests', []); //=> ['tests']
     append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]

public applyOrReturn(args: Array, test: *): * source

import applyOrReturn from '@tinkoff/utils/function/applyOrReturn'

Autocurry for 2 arguments

If test is function it calls with applied first argument, otherwise just returns test

Params:

NameTypeAttributeDescription
args Array

Arguments passed to test if it's a function

test *

if test is function it's called with args

Return:

*

Example:


     applyOrReturn([1,2,3], (...args) => args) // => [1,2,3]
     applyOrReturn([1,2,3], 'test') // => 'test'

public array(test: *): boolean source

import array from '@tinkoff/utils/is/array'

Checks if test is array.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is array, else false.

Example:


isArray([]); // => true
isArray(null); // => false

public arrayLike(test: *): boolean source

import arrayLike from '@tinkoff/utils/is/arrayLike'

Checks if test is arrayLike (has length and index properties).

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Example:


isArrayLike([]); // => true
isArrayLike({ 0:'a', 1: 'b', length: 2 }); // => true
isArrayLike(null); // => false

public assign(sources: *): * source

import assign from '@tinkoff/utils/assign'

Create a new object/array with the own properties of the first entry merged with the own properties of the others objects. If a key exists in several objects, the value from the last object will be used.

Note if first argument is array then result of function is array, otherwise it is an object.

Params:

NameTypeAttributeDescription
sources *

Return:

*

Example:


assign({a:1}, {b:2}) // => {a:1, b:2}
assign([1,2,3], [4,5]) // => [4,5,3]

public assoc(prop: String, val: *, obj: Object): Object source

import assoc from '@tinkoff/utils/object/assoc'
this function was deprecated. use object/propSet instead

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the given value. All non-primitive properties are copied by reference.

Params:

NameTypeAttributeDescription
prop String

The property name to set

val *

The new value

obj Object

The object to clone

Return:

Object

A new object equivalent to the original except for the changed property.

Example:


     assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}

public boolean(test: *): boolean source

import boolean from '@tinkoff/utils/is/boolean'

Checks if test is boolean.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if value is boolean, else false.

Example:


isBool(false); // => true
isBool(new Boolean()); // => true
isBool(null); // => false

public both(f: Function, g: Function): Function source

import both from '@tinkoff/utils/function/both'

Autocurry for 2 arguments

A function wrapping calls to the two functions in an && operation, returning the result of the first function if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a false-y value.

Params:

NameTypeAttributeDescription
f Function

a predicate

g Function

another predicate

Return:

Function

a function that applies its arguments to f and g and &&s their outputs together.

Example:


     var gt10 = x => x > 10;
     var even = x => x % 2 === 0;
     var f = both(gt10, even);
     f(100); //=> true
     f(101); //=> false

public camelCaseName(str: String): String source

import camelCaseName from '@tinkoff/utils/string/camelCaseName'

Converts string to camel case.

This function convert only latin chars. The preferred purpose is to generate file or class names in your code generation tools.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

The camel cased string.

Example:


     camelCase('Foo Bar'); //=> 'fooBar'
     camelCase('foo-bar'); //=> 'fooBar'
     camelCase('foo_bar'); //=> 'fooBar'
     camelCase('FOO_BAR'); //=> 'fooBar'
     camelCase('fooBar');  //=> 'fooBar'
     camelCase('Foo Bär'); //=> 'fooBR' only latin chars are supported

public capitalize(str: String): String source

import capitalize from '@tinkoff/utils/string/capitalize'

Returns the capitalized version of a string.

Params:

NameTypeAttributeDescription
str String

The string to capitalize.

Return:

String

The capitalized version of str.

Example:


     capitalize('xyz'); //=> 'Xyz'

public clone(x: *): * source

import clone from '@tinkoff/utils/clone'

Creates a deep copy of the value which may contain (nested) Arrays and Objects, Numbers, Strings, Booleans and Dates. Functions are not copied, but assigned by their reference.

Params:

NameTypeAttributeDescription
x *

The value to clone

Return:

*

A copy of a value.

Example:


     var objects = [{}, {}, {}];
     var objectsClone = clone(objects);
     objects[0] === objectsClone[0]; //=> false

public comparator(pred: Function): Function source

import comparator from '@tinkoff/utils/function/comparator'

Makes a comparator function out of a function that reports whether the first element is less than the second.

Params:

NameTypeAttributeDescription
pred Function

A predicate function of arity two which will return true if the first argument is less than the second, false otherwise

Return:

Function

A Function :: a -> b -> Int that returns -1 if a < b, 1 if b < a, otherwise 0

Example:


     var byAge = comparator((a, b) => a.age < b.age);
     var people = [
       // ...
     ];
     var peopleByIncreasingAge = sort(byAge, people);

public complement(fn: Function): Function source

import complement from '@tinkoff/utils/function/complement'

Takes a function f and returns a function g such that if called with the same arguments when f returns a "truthy" value, g returns false and when f returns a "falsy" value g returns true.

Params:

NameTypeAttributeDescription
fn Function

Return:

Function

Example:


     var isNotNil = complement(isNil);
     isNil(null); //=> true
     isNotNil(null); //=> false
     isNil(7); //=> false
     isNotNil(7); //=> true

public compose(fns: ...Function): Function source

import compose from '@tinkoff/utils/function/compose'

Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.

Note: The result of compose is not automatically curried.

Params:

NameTypeAttributeDescription
fns ...Function

Return:

Function

Example:


     var f = compose(x => x + 1, x => -x, Math.pow);

     f(3, 4); // -(3^4) + 1

public composeP(chain: ...Function): Function source

import composeP from '@tinkoff/utils/function/composeP'

Performs right-to-left composition of Promise-returning functions. The rightmost function may have any arity; the remaining functions must be unary.

Note: ALL of the chained functions must return a Promise.

Note: The result of compose is not automatically curried.

Params:

NameTypeAttributeDescription
chain ...Function

Return:

Function

Example:

     var res = x => Promise.resolve(x);
     var f = composeP(x => res(-x), (x, y) => res(Math.pow(x, y)));
     f(3, 4).then(console.log); // -(3^4)

public concat(a: Array | String, b: Array | String): Array | String source

import concat from '@tinkoff/utils/array/concat'

Autocurry for 2 arguments

Returns the result of concatenating the given arrays or strings.

Params:

NameTypeAttributeDescription
a Array | String

The first list

b Array | String

The second list

Return:

Array | String

A list consisting of the elements of firstList followed by the elements of secondList.

Example:


     concat('ABC', 'DEF'); // 'ABCDEF'
     concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
     concat([], []); //=> []

public cond(pairs: F): Function source

import cond from '@tinkoff/utils/function/cond'

Returns a function, fn, which encapsulates if/else-if/else logic. cond takes a list of [predicate, transform] pairs. All of the arguments to fn are applied to each of the predicates in turn until one returns a "truthy" value, at which point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates matches, fn returns undefined.

Params:

NameTypeAttributeDescription
pairs F

Return:

Function

Example:


     var fn = cond([
       [isEqual(0),   always('water freezes at 0°C')],
       [isEqual(100), always('water boils at 100°C')],
       [T,           temp => 'nothing special happens at ' + temp + '°C']
     ]);
     fn(0); //=> 'water freezes at 0°C'
     fn(50); //=> 'nothing special happens at 50°C'
     fn(100); //=> 'water boils at 100°C'

public createCache(obj: Function): * source

Creates a cache instance base on passed object. Return instance has 3 methods: get, set, has

*

Params:

NameTypeAttributeDescription
obj Function

object that will be used as cache

Return:

*

Example:

     const cache = createCache();
     cache.set('a', 5);
     cache.has('a'); // true
     cache.get('a'); // 5

public curry(fn: Function): Function source

import curry from '@tinkoff/utils/function/curry'

Returns a curried equivalent of the provided function. The arguments of curried function needn't be provided one at a time. If f is a ternary function and g is curry(f), the following are equivalent:

  • g(1)(2)(3)
  • g(1)(2, 3)
  • g(1, 2)(3)
  • g(1, 2, 3)

Params:

NameTypeAttributeDescription
fn Function

The function to curry.

Return:

Function

A new, curried function.

Example:


     var addFourNumbers = (a, b, c, d) => a + b + c + d;

     var curriedAddFourNumbers = curry(addFourNumbers);
     var f = curriedAddFourNumbers(1, 2);
     var g = f(3);
     g(4); //=> 10

public curryN(arity: Number, fn: Function): Function source

import curryN from '@tinkoff/utils/function/curryN'

Returns a curried equivalent of the provided function, with the specified arity. If g is curryN(3, f), the following are equivalent:

  • g(1)(2)(3)
  • g(1)(2, 3)
  • g(1, 2)(3)
  • g(1, 2, 3)

Params:

NameTypeAttributeDescription
arity Number

The arity for the returned function.

fn Function

The function to curry.

Return:

Function

A new, curried function.

Example:


     var sumArgs = (...args) => sum(args);

     var curriedAddFourNumbers = curryN(4, sumArgs);
     var f = curriedAddFourNumbers(1, 2);
     var g = f(3);
     g(4); //=> 10

public debounce(wait: number, fn: Function): Function source

import debounce from '@tinkoff/utils/function/debounce'

Autocurry for 2 arguments

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. Delayed function invocation might be cancelled by calling cancel method.

Params:

NameTypeAttributeDescription
wait number

The number of milliseconds to delay.

fn Function

The function to debounce.

Return:

Function

Returns the new debounced function.

public deepSizeLimit(): Function source

Autocurry for 2 arguments

Memoize function with multiply arguments of any type, but it clears cache every time it reaches the limit. Use it when you need deep equality for cache lookup and afraid of memory leak.

Params:

NameTypeAttributeDescription
sizeLimit. Number

Cache size limit

Return:

Function

fn

Example:

    const addFlag = obj => ({...obj, flag: true });
    const memoize = memoizeDeepSizeLimit(2, addFlag));
    memoize({test: 2}); // from addFlag call
    memoize({test: 2}); // from cache
    memoize({test: 3}); //from addFlag call
    memoize({test: 4}); // from addFlag call
    memoize({test: 2}); // from addFlag call (memory was cleared)

public defaultTo(dflt: a, x: b): * source

import defaultTo from '@tinkoff/utils/defaultTo'

Autocurry for 2 arguments

Returns the second argument if it is not null, undefined or NaN otherwise the first argument is returned.

Params:

NameTypeAttributeDescription
dflt a

The default value.

x b

The value to return if it is not null or undefined

Return:

*

The the second value or the default value

Example:


     var defaultTo42 = defaultTo(42);

     defaultTo42(null);  //=> 42
     defaultTo42(undefined);  //=> 42
     defaultTo42('Example');  //=> 'Example'
     defaultTo42(parseInt('string')); //=> 42

public difference(a: Array, b: Array): Array source

import difference from '@tinkoff/utils/array/difference'

Autocurry for 2 arguments

Returns the array of all elements in the first array not contained in the second array.

Params:

NameTypeAttributeDescription
a Array

The first array.

b Array

The second array.

Return:

Array

The elements in a that are not in b.

Example:


     difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
     difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]

public drop(n: Number, xs: *): * source

import drop from '@tinkoff/utils/array/drop'

Autocurry for 2 arguments

Returns all but the first n elements of the given list, string.

Params:

NameTypeAttributeDescription
n Number
xs *

Return:

*

A copy of list without the first n elements

Example:


     drop(1, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
     drop(2, ['foo', 'bar', 'baz']); //=> ['baz']
     drop(3, ['foo', 'bar', 'baz']); //=> []
     drop(4, ['foo', 'bar', 'baz']); //=> []

public dropLast(n: Number, xs: Array): Array source

import dropLast from '@tinkoff/utils/array/dropLast'

Autocurry for 2 arguments

Returns a list containing all but the last n elements of the given list.

Params:

NameTypeAttributeDescription
n Number

The number of elements of list to skip.

xs Array

The list of elements to consider.

Return:

Array

A copy of the list with only the first list.length - n elements

Example:


     dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
     dropLast(2, ['foo', 'bar', 'baz']); //=> ['foo']
     dropLast(3, ['foo', 'bar', 'baz']); //=> []
     dropLast(4, ['foo', 'bar', 'baz']); //=> []
     dropLast(3, 'ramda');               //=> 'ra'

public dropWhile(fn: Function, arr: Array): Array source

import dropWhile from '@tinkoff/utils/array/dropWhile'

Autocurry for 2 arguments

Returns a new list excluding the leading elements of a given list which satisfy the supplied predicate function. It passes each value to the supplied predicate function, skipping elements while the predicate function returns true.

Params:

NameTypeAttributeDescription
fn Function

The function called per iteration.

arr Array

The collection to iterate over.

Return:

Array

A new array.

Example:


     var lteTwo = x => x <= 2;

     dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1]

public each(fn: Function, arr: Array) source

import each from '@tinkoff/utils/array/each'

Autocurry for 2 arguments

Iterate over an input list, calling a provided function fn for each element in the list.

Params:

NameTypeAttributeDescription
fn Function

The function to invoke. Receives three argument: value, index, arr.

arr Array

The list to iterate over.

Example:


     var printXPlusFive = x => console.log(x + 5);
     each(printXPlusFive, [1, 2, 3]);
     // logs 6
     // logs 7
     // logs 8

public each(fn: Function, obj: Object): Object source

import each from '@tinkoff/utils/object/each'

Autocurry for 2 arguments

Iterate over an input object, calling a provided function fn for each key and value in the object.

Params:

NameTypeAttributeDescription
fn Function

The function to invoke. Receives three argument, value, key, obj.

obj Object

The object to iterate over.

Return:

Object

The original object.

Example:


     var printKeyConcatValue = (value, key) => console.log(key + ':' + value);
     each(printKeyConcatValue, {x: 1, y: 2}); //=> {x: 1, y: 2}
     // logs x:1
     // logs y:2

public either(f: Function, g: Function): Function source

import either from '@tinkoff/utils/function/either'

Autocurry for 2 arguments

A function wrapping calls to the two functions in an || operation, returning the result of the first function if it is truth-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a truth-y value.

Params:

NameTypeAttributeDescription
f Function

a predicate

g Function

another predicate

Return:

Function

a function that applies its arguments to f and g and ||s their outputs together.

Example:


     var gt10 = x => x > 10;
     var even = x => x % 2 === 0;
     var f = either(gt10, even);
     f(101); //=> true
     f(8); //=> true
     f(3); //=> false

public element(test: *): boolean source

import element from '@tinkoff/utils/is/element'

Checks if value is likely a DOM element.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if value is a DOM element, else false.

Example:


isElement(document.body); // => true

isElement('<body>'); // => false

public empty(test: *): boolean source

import empty from '@tinkoff/utils/is/empty'

Checks if test is empty.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is empty, else false.

Example:


isEmpty([]); // => true
isEmpty(null); // => true
isEmpty({}); // => true
isEmpty(''); // => true
isEmpty('test'); // => false
isEmpty({ a: 5 }); // => false
isEmpty([1]); // => false

public endsWith(postfix: string, str: string): Boolean source

import endsWith from '@tinkoff/utils/string/endsWith'

Autocurry for 2 arguments

Checks if a string ends with the provided postfix

Params:

NameTypeAttributeDescription
postfix string
str string

Return:

Boolean

Example:


     endsWith('c', 'abc')                //=> true
     endsWith('b', 'abc')                //=> false

public eqProps(prop: String, obj1: Object, obj2: Object): Boolean source

import eqProps from '@tinkoff/utils/object/eqProps'

Autocurry for 3 arguments

Reports whether two objects have the same value, in equal terms, for the specified property. Useful as a curried predicate.

Params:

NameTypeAttributeDescription
prop String

The name of the property to compare

obj1 Object
obj2 Object

Return:

Boolean

Example:


     var o1 = { a: 1, b: 2, c: 3, d: 4 };
     var o2 = { a: 10, b: 20, c: 3, d: 40 };
     eqProps('a', o1, o2); //=> false
     eqProps('c', o1, o2); //=> true

public escape(str: string): string source

import escape from '@tinkoff/utils/string/escape'

Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.

Params:

NameTypeAttributeDescription
str string

The string to escape.

Return:

string

Returns the escaped string.

Example:


escape('fred, barney, & pebbles'); // => 'fred, barney, &amp; pebbles'

public escapeRegExp(str: string): string source

import escapeRegExp from '@tinkoff/utils/string/escapeRegExp'

Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.

Params:

NameTypeAttributeDescription
str string

The string to escape.

Return:

string

Returns the escaped string.

Example:


escapeRegExp('[test](utils)'); // => '\[test\]\(utils\)'

public filter(fn: Function, arr: Array): Array source

import filter from '@tinkoff/utils/array/filter'

Autocurry for 2 arguments

Takes a predicate and a "arr", and returns a new array of the same type containing the members of the given arr which satisfy the given predicate.

Params:

NameTypeAttributeDescription
fn Function

predicate

arr Array

Return:

Array

Example:


     var isEven = n => n % 2 === 0;

     filter(isEven, [1, 2, 3, 4]); //=> [2, 4]

public filter(fn: Function, obj: Object): Object source

import filter from '@tinkoff/utils/object/filter'

Autocurry for 2 arguments

Takes a predicate and a object, and returns a new object containing only members which satisfy the given predicate.

Params:

NameTypeAttributeDescription
fn Function
obj Object

Return:

Object

Example:


     var isEven = n => n % 2 === 0;

     filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}

public filterMap(filterFn: Function, mapFn: Function, arr: Array): Array source

import filterMap from '@tinkoff/utils/array/filterMap'

Autocurry for 3 arguments

This is shortcut for filter + map, but applied in one iteration.

Params:

NameTypeAttributeDescription
filterFn Function

filter function

mapFn Function

map function

arr Array

Return:

Array

Example:


     var isEven = n => n % 2 === 0;
     var double = x => x * 2;

     filterMap(isEven, double, [1, 2, 3, 4]); //=> [4, 8]

     // this is equivalent to
     // map(double, filter(isEven, [1, 2, 3, 4]));

public find(fn: Function, arr: Array): Object source

import find from '@tinkoff/utils/array/find'

Autocurry for 2 arguments

Returns the first element of the list which matches the predicate, or undefined if no element matches.

Params:

NameTypeAttributeDescription
fn Function

The predicate function used to determine if the element is the desired one.

arr Array

The array to consider.

Return:

Object

The element found, or undefined.

Example:


     var xs = [{a: 1}, {a: 2}, {a: 3}];
     find(x => x.a === 2)(xs); //=> {a: 2}
     find(x => x.a === 4)(xs); //=> undefined

public findIndex(fn: Function, arr: Array): Number source

import findIndex from '@tinkoff/utils/array/findIndex'

Autocurry for 2 arguments

Returns the index of the first element of the list which matches the predicate, or -1 if no element matches.

Params:

NameTypeAttributeDescription
fn Function

The predicate function used to determine if the element is the desired one.

arr Array

The array to consider.

Return:

Number

The index of the element found, or -1.

Example:


     var xs = [{a: 1}, {a: 2}, {a: 3}];
     findIndex(x => x.a === 2)(xs); //=> 1
     findIndex(x => x.a === 4)(xs); //=> -1

public findKey(fn: Function, obj: Object): String | undefined source

import findKey from '@tinkoff/utils/object/findKey'

Autocurry for 2 arguments

Returns first key in obj satisfied to fn, or undefined if there is no such keys

Params:

NameTypeAttributeDescription
fn Function

Receives three argument, value, key, obj

obj Object

Return:

String | undefined

Example:


     findKey(identity, {a: 0, b: 3}) // => 'b'
     findKey(x => x > 3, { a: 2, b: 1 }) // => undefined
     findKey(x => x > 3, { a: 4, b: 5 }) // => 'a'

public findLast(fn: Function, list: Array): Object source

import findLast from '@tinkoff/utils/array/findLast'

Autocurry for 2 arguments

Returns the last element of the list which matches the predicate, or undefined if no element matches.

Params:

NameTypeAttributeDescription
fn Function

The predicate function used to determine if the element is the desired one.

list Array

The array to consider.

Return:

Object

The element found, or undefined.

Example:


     const xs = [{a: 1, b: 0}, {a:1, b: 1}];

     findLast(propEq('a', 1))(xs); //=> {a: 1, b: 1}
     findLast(propEq('a', 4))(xs); //=> undefined

public finite(test: *): boolean source

import finite from '@tinkoff/utils/is/finite'

Checks if test is finite.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is finite, else false.

Example:


isFinite(5); // => true
isFinite(null); // => false

public flatten(arr: Array): Array source

import flatten from '@tinkoff/utils/array/flatten'

Returns a new list by pulling every item out of it (and all its sub-arrays) and putting them in a new array, depth-first.

Params:

NameTypeAttributeDescription
arr Array

The array to consider.

Return:

Array

The flattened list.

Example:


     flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
     //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

public flip(fn: Function): * source

import flip from '@tinkoff/utils/function/flip'

Returns a new function much like the supplied one, except that the first two arguments' order is reversed.

Params:

NameTypeAttributeDescription
fn Function

The function to invoke with its first two parameters reversed.

Return:

*

The result of invoking fn with its first two parameters' order reversed.

Example:


     const neg = (a, b) => a - b

     flip(neg)(3, 5); //=> 2

public fromPairs(arr: Array): Object source

import fromPairs from '@tinkoff/utils/object/fromPairs'

Creates a new object from a list key-value pairs. If a key appears in multiple pairs, the rightmost pair is included in the object.

Params:

NameTypeAttributeDescription
arr Array

An array of two-element arrays that will be the keys and values of the output object.

Return:

Object

The object made by pairing up keys and values.

Example:


     fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}

public function(test: *): boolean source

import function from '@tinkoff/utils/is/function'

Checks if test is function.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is function, else false.

Example:


isFunction(() => {}); // => true
isFunction(null); // => false

public groupBy(fns: Array<Function>, list: Array): Array source

import groupBy from '@tinkoff/utils/array/groupBy'

Autocurry for 2 arguments

Creates an array of arrays generated from the results of running each element of list thru each fn. The corresponding value of each index is an array of elements satisfies to function with that index, and the last array is elements with no satisfied function

Params:

NameTypeAttributeDescription
fns Array<Function>

The functions to check values in a list.

list Array

The list to iterate over.

Return:

Array

Returns the composed array.

Example:


groupBy([isPositive, isZero, isNegative], [0, -3, 2, 'str', 4, -1]);// => [[2,4], [0], [-3, -1], ['str']]

public groupBy(fn: Function, obj: Object): Object source

import groupBy from '@tinkoff/utils/object/groupBy'

Autocurry for 2 arguments

Creates an object composed of keys generated from the results of running each element of object thru fn. The corresponding value of each key is an array of elements responsible for generating the key.

Params:

NameTypeAttributeDescription
fn Function

The function to transform value to group key. Receives three argument, value, key, obj.

obj Object

The obj to iterate over.

Return:

Object

Returns the composed aggregate object.

Example:


groupBy(x => x, { a: 1, b: 1, c: 3});// => { '1': [1, 1], '3': [3] }

public has(prop: String, obj: Object): Boolean source

import has from '@tinkoff/utils/object/has'

Autocurry for 2 arguments

Returns whether or not an object has an own property with the specified name

Params:

NameTypeAttributeDescription
prop String

The name of the property to check for.

obj Object

The object to query.

Return:

Boolean

Whether the property exists.

Example:


     var hasName = has('name');
     hasName({name: 'alice'});   //=> true
     hasName({name: 'bob'});     //=> true
     hasName({});                //=> false

public head(arr: Array): * source

import head from '@tinkoff/utils/array/head'

Returns the first element of the given array.

Params:

NameTypeAttributeDescription
arr Array

Return:

*

Example:


     head(['fi', 'fo', 'fum']); //=> 'fi'
     head([]); //=> undefined

public identity(x: *): * source

import identity from '@tinkoff/utils/function/identity'

A function that does nothing but return the parameter supplied to it. Good as a default or placeholder function.

Params:

NameTypeAttributeDescription
x *

The value to return.

Return:

*

The input value, x.

Example:


     identity(1); //=> 1

     const obj = {};
     identity(obj) === obj; //=> true

public ifElse(condition: Function, onTrue: Function, onFalse: Function): Function source

import ifElse from '@tinkoff/utils/function/ifElse'

Autocurry for 3 arguments

Creates a function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

Params:

NameTypeAttributeDescription
condition Function

A predicate function

onTrue Function

A function to invoke when the condition evaluates to a truthy value.

onFalse Function

A function to invoke when the condition evaluates to a falsy value.

Return:

Function

A new unary function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

Example:


     const prop = ifElse(
       x => x.a,
       x => x.b,
       x => x.c
     );
     prop({ a: false, c: 2 }); //=> 2
     prop({ a: true, b: 1, c: 2 }); //=> 1

public includes(value: *, arr: Array | String): Boolean source

import includes from '@tinkoff/utils/array/includes'

Autocurry for 2 arguments

Dispatches call to arr.indexOf, returns true if arr is array and value in the array or if arr is string and value is substring of arr

Params:

NameTypeAttributeDescription
value *

The item to compare against.

arr Array | String

The array to consider.

Return:

Boolean

true if the item is in the list, false otherwise.

Example:


     includes(3, [1, 2, 3]); //=> true
     includes(4, [1, 2, 3]); //=> false
     includes('test', 'aaatest'); //=> true

public indexBy(fn: Function, arr: Array): Object source

import indexBy from '@tinkoff/utils/array/indexBy'

Autocurry for 2 arguments

Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key. Note that if multiple objects generate the same value for the indexing key only the last value will be included in the generated object.

Params:

NameTypeAttributeDescription
fn Function

Function :: a -> String

arr Array

The array of objects to index

Return:

Object

An object indexing each array element by the given property.

Example:


     var list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
     indexBy(x => x.id, list);
     //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}

public indexOf(target: *, xs: Array): Number source

import indexOf from '@tinkoff/utils/array/indexOf'

Autocurry for 2 arguments

Returns the position of the first occurrence of an item in an array, or -1 if the item is not included in the array.

Params:

NameTypeAttributeDescription
target *

The item to find.

xs Array

The array to search in.

Return:

Number

the index of the target, or -1 if the target is not found.

Example:


     indexOf(3, [1,2,3,4]); //=> 2
     indexOf(10, [1,2,3,4]); //=> -1

public init(arr: Array): * source

import init from '@tinkoff/utils/array/init'

Returns all but the last element of the given list or string.

Params:

NameTypeAttributeDescription
arr Array

Return:

*

Example:


     init([1, 2, 3]);  //=> [1, 2]
     init([1, 2]);     //=> [1]
     init([1]);        //=> []
     init([]);         //=> []

public intersection(a: Array, b: Array): Array source

import intersection from '@tinkoff/utils/array/intersection'

Autocurry for 2 arguments

Combines two array into a set (i.e. no duplicates) composed of those elements common to both arrays.

Params:

NameTypeAttributeDescription
a Array

The first array.

b Array

The second array.

Return:

Array

The array of elements found in both a and b.

Example:


     intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]

public isEqual(test1: *, test2: *): Boolean source

Autocurry for 2 arguments

Returns true if its arguments are equivalent, false otherwise.

Params:

NameTypeAttributeDescription
test1 *
test2 *

Return:

Boolean

Example:


     isEqual(1, 1); //=> true
     isEqual(1, '1'); //=> false
     isEqual([1, 2, 3], [1, 2, 3]); //=> true
     isEqual({ a: { b: 1 }}, { a: { b: 1 }}); //=> true

public isPlainObject(test: *): boolean source

import isPlainObject from '@tinkoff/utils/is/plainObject'

Returns whether a value is a plain object (an object that is created using an object literal, Object.create(null) or similar). Rejects anything with a custom prototype or a non-object ECMAScript type. Also rejects React elements and components

Note: if the host environment does not support Symbol, any object with a $$typeof property is considered a React element

Params:

NameTypeAttributeDescription
test *

The value to check

Return:

boolean

Returns true if test is a plain object, else false.

Example:


isPlainObject({ a: 'test' }); // => true

isPlainObject(moment()); // => false

isPlainObject(<span></span>); // => false

public isTrue(val: *): boolean source

import isTrue from '@tinkoff/utils/isTrue'

Returns true if val is true or equal to string 'true'

Params:

NameTypeAttributeDescription
val *

Return:

boolean

Example:


     isTrue(true) // => true
     isTrue('true') // => true
     isTrue([true]) // => false
     isTrue('false') // => false

public join(separator: String, arr: Array): String source

import join from '@tinkoff/utils/array/join'

Autocurry for 2 arguments

Returns a string made by inserting the separator between each element and concatenating all the elements into a single string.

Params:

NameTypeAttributeDescription
separator String

The string used to separate the elements.

arr Array

The elements to join into a string.

Return:

String

str The string made by concatenating arr with separator.

Example:


     var spacer = join(' ');
     spacer(['a', 2, 3.4]);   //=> 'a 2 3.4'
     join('|', [1, 2, 3]);    //=> '1|2|3'

public kebabCaseName(str: String): String source

import kebabCaseName from '@tinkoff/utils/string/kebabCaseName'

Converts string to kebab case.

This function convert only latin chars. The preferred purpose is to generate file or class names in your code generation tools.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

The kebab cased string.

Example:


     kebabCase('Foo Bar'); //=> 'foo-bar'
     kebabCase('fooBar');  //=> 'foo-bar'
     kebabCase('foo_bar'); //=> 'foo-bar'
     kebabCase('FOO_BAR'); //=> 'foo-bar'
     kebabCase('Foo Bär'); //=> 'foo-b-r' — only latin chars are supported

public keyBy(fn: Function, obj: Object): Object source

import keyBy from '@tinkoff/utils/object/keyBy'

Autocurry for 2 arguments

Creates an object composed of keys generated from the results of running each element of object thru fn. The corresponding value of each key is the last element responsible for generating the key

Params:

NameTypeAttributeDescription
fn Function

The function to transform value to group key. Receives three argument, value, key, obj.

obj Object

The obj to iterate over.

Return:

Object

Returns the composed aggregate object.

Example:


keyBy(x => x < 2, { a: 0, b: 1, c: 3});// => { false: 1, true: 3 }

public keys(obj: Object): Array source

import keys from '@tinkoff/utils/object/keys'

Returns a list containing the names of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

Params:

NameTypeAttributeDescription
obj Object

The object to extract properties from

Return:

Array

An array of the object's own properties.

Example:


     keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']

public last(arr: Array): * source

import last from '@tinkoff/utils/array/last'

Returns the last element of the given array.

Params:

NameTypeAttributeDescription
arr Array

Return:

*

Example:


     last(['fi', 'fo', 'fum']); //=> 'fum'
     last([]); //=> undefined

public length(arr: Array): Number source

import length from '@tinkoff/utils/array/length'

Returns the number of elements in the array by returning arr.length.

Params:

NameTypeAttributeDescription
arr Array

The array to inspect.

Return:

Number

The length of the array.

Example:


     length([]); //=> 0
     length([1, 2, 3]); //=> 3

public map(fn: Function, arr: Array): Array source

import map from '@tinkoff/utils/array/map'

Autocurry for 2 arguments

Creates an array of values by running each element in list through fn. The fn is invoked with three arguments: (value, index, arr).

Params:

NameTypeAttributeDescription
fn Function

The function to be called on every element of the input list.

arr Array

The list to be iterated over.

Return:

Array

The new list.

Example:


     var double = x => x * 2;

     map(double, [1, 2, 3]); //=> [2, 4, 6]

public map(fn: Function, obj: Object): Object source

import map from '@tinkoff/utils/object/map'

Autocurry for 2 arguments

Applies fn to each of the obj values, and returns new object.

Params:

NameTypeAttributeDescription
fn Function

The function to be called on every value of the input obj. Receives three argument, value, key, obj.

obj Object

The object to be iterated over.

Return:

Object

The new object.

Example:


     var double = x => x * 2;

     map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6}

public maxBy(fn: Function, arr: Array): * source

import maxBy from '@tinkoff/utils/array/maxBy'

Autocurry for 2 arguments

Return max value in array, depending on result of calling fn

Params:

NameTypeAttributeDescription
fn Function

The function invoked per element.

arr Array

Return:

*

Returns the maximum value.

Example:


     var objects = [{ 'n': 1 }, { 'n': 2 }];

     maxBy(o => o.n, objects); // => { 'n': 2 }

public merge(sources: ...Object): Object source

import merge from '@tinkoff/utils/object/merge'

Autocurry for 2 arguments

Create a new object with the own properties of the first object merged with the own properties of the others objects. If a key exists in several objects, the value from the last object will be used.

Params:

NameTypeAttributeDescription
sources ...Object

Return:

Object

Example:


merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 }); //=> { 'name': 'fred', 'age': 40 }

public mergeDeep(sources: ...Object): Object source

Autocurry for 2 arguments

Create a new object with the own properties of the first object deeply merged with the own properties of the other objects. If a key exists in several objects, then all values associated with this key are merged recursively unless at least one of them is not a plain object. Merging is done from left to right.

Params:

NameTypeAttributeDescription
sources ...Object

Return:

Object

Example:


mergeDeep({ 'name': 'fred', 'info': { 'age': 10, 'sex': 'm' } }, { 'info': { 'age': 40 }); //=> { 'name': 'fred', 'info': { 'age': 40, 'sex': 'm' } }

public mergeWith(fn: Function, sources: ...Object): Object source

import mergeWith from '@tinkoff/utils/object/mergeWith'

Autocurry for 3 arguments

Create a new object with the own properties of the first object merged with the own properties of the others objects. If a key exists in several objects provided fn will be called and should return resolve value

Params:

NameTypeAttributeDescription
fn Function

function to call if prop conflict appear. Receives three argument, valueLeft, valueRight, key, leftObj, rightObj.

sources ...Object

Return:

Object

Example:


mergeWith((x, y) => x + y, { 'name': 'fred', 'age': 10 }, { 'age': 40 }); //=> { 'name': 'fred', 'age': 50 }

public negate(n: Number): Number source

import negate from '@tinkoff/utils/negate'

Negates its argument.

Params:

NameTypeAttributeDescription
n Number

Return:

Number

Example:


     negate(42); //=> -42

public nil(test: *): boolean source

import nil from '@tinkoff/utils/is/nil'

Checks if test is nil (null or undefined).

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is nil, else false.

Example:


isNil(undefined); // => true
isNil(null); // => true
isNil(''); // => false
isNil(5); // => false

public noop() source

import noop from '@tinkoff/utils/function/noop'

This method doing nothing and returns undefined.

public not(val: *): Boolean source

import not from '@tinkoff/utils/not'

A function that returns the ! of its argument. It will return true when passed false-y value, and false when passed a truth-y one.

Params:

NameTypeAttributeDescription
val *

any value

Return:

Boolean

the logical inverse of passed argument.

Example:


     not(true); //=> false
     not(false); //=> true
     not(0); //=> true
     not(1); //=> false

public nothing(): Undefined source

import nothing from '@tinkoff/utils/function/nothing'

A function that always returns undefined. Any passed in parameters are ignored.

Return:

Undefined

Example:


     nothing(); //=> undefined

public nth(index: Number, arr: *): * source

import nth from '@tinkoff/utils/array/nth'

Autocurry for 2 arguments

Returns the nth element of the given array. If n is negative the element at index length + n is returned.

Params:

NameTypeAttributeDescription
index Number
arr *

Return:

*

Example:


     var list = ['foo', 'bar', 'baz', 'quux'];
     nth(1, list); //=> 'bar'
     nth(2, list); //=> 'baz'
     nth(-1, list); //=> 'quux'
     nth(-99, list); //=> undefined

public number(test: *): boolean source

import number from '@tinkoff/utils/is/number'

Checks if test is number.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is number, else false.

Example:


isNumber(5); // => true
isNumber(null); // => false

public objOf(key: String, value: *): Object source

import objOf from '@tinkoff/utils/object/objOf'

Autocurry for 2 arguments

Creates an object containing a single key:value pair.

Params:

NameTypeAttributeDescription
key String
value *

Return:

Object

Example:


     objOf('key', 5) // => { key: 5 }

public object(test: *): boolean source

import object from '@tinkoff/utils/is/object'

Checks if test is object.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is object, else false.

Example:


isObject({ a: 'test' }); // => true
isObject(null); // => false

public omit(props: Array, obj: Object): Object source

import omit from '@tinkoff/utils/object/omit'

Autocurry for 2 arguments

Returns a partial copy of an object omitting the keys specified.

Params:

NameTypeAttributeDescription
props Array

an array of String property names to omit from the new object

obj Object

The object to copy from

Return:

Object

A new object with properties from names not on it.

Example:


     omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}

public once(fn: Function): Function source

import once from '@tinkoff/utils/function/once'

Accepts a function fn and returns a function that guards invocation of fn such that fn can only ever be called once, no matter how many times the returned function is invoked. The first value calculated is returned in subsequent invocations.

Params:

NameTypeAttributeDescription
fn Function

The function to wrap in a call-only-once wrapper.

Return:

Function

The wrapped function.

Example:


     var addOneOnce = once(x => x + 1);
     addOneOnce(10); //=> 11
     addOneOnce(addOneOnce(50)); //=> 11

public one(fn: Function, isEqual: Function): Function source

Memoize function with multiply arguments of any type. Use it when you need to cache lookup only for last result (like reselect).

Params:

NameTypeAttributeDescription
fn Function
isEqual Function

checks equality for two values

Return:

Function

Example:

    const addFlag = obj => ({...obj, flag: true });
    const memoize = memoizeOnce(addFlag));
    memoize(1); // from addFlag call
    memoize(1); // from cache
    memoize(1,2) // from addFlag call,
    memoize(1) // from addFlag call, cache was flashed on previous step

public optional(fn: Function): Function source

import optional from '@tinkoff/utils/function/optional'

Autocurry for 2 arguments

Wraps a one-parameter function, new function returns true if passed parameter is undefined, otherwise returns result of calling fn

Params:

NameTypeAttributeDescription
fn Function

function to wrap

Return:

Function

Example:


     const optIsString = optional(isString);
     optIsString() // => true
     optIsString({}) // => false
     optIsString('str') // => true

public partition(fn: Function, arr: Array): Array source

import partition from '@tinkoff/utils/array/partition'

Autocurry for 2 arguments

Takes a predicate and a array and returns the pair of arrays of the same type of elements which do and do not satisfy, the predicate, respectively.

Params:

NameTypeAttributeDescription
fn Function

A predicate to determine which side the element belongs to.

arr Array

the array to partition.

Return:

Array

An array, containing first the subset of elements that satisfy the predicate, and second the subset of elements that do not satisfy.

Example:


     partition(includes('s'), ['sss', 'ttt', 'foo', 'bars']);
     // => [ [ 'sss', 'bars' ],  [ 'ttt', 'foo' ] ]

public pathApply(paths: [String], fn: Function, obj: Object): * source

import pathApply from '@tinkoff/utils/object/pathApply'

Autocurry for 3 arguments

Returns the result of fn with given value at path.

Params:

NameTypeAttributeDescription
paths [String]

The path to use.

fn Function

function to apply

obj Object

The object to retrieve the nested property from.

Return:

*

result of calling fn with nested property.

Example:


     pathApply(['a', 'b'], x => 'is ' + x, {a: {b: 2}}); //=> is 2
     pathApply(['a', 'b'], x => x > 0, {a: {b: 2}}); //=> true

public pathEq(paths: Array, value: *, obj: Object): Boolean source

import pathEq from '@tinkoff/utils/object/pathEq'

Autocurry for 3 arguments

Determines whether a nested path on an object has a specific value

Params:

NameTypeAttributeDescription
paths Array

The path of the nested property to use

value *

The value to compare the nested property with

obj Object

The object to check the nested property in

Return:

Boolean

true if the value is the nested object property, false otherwise.

Example:


     var user1 = { address: { zipCode: 90210 } };
     var user2 = { address: { zipCode: 55555 } };
     var user3 = { name: 'Bob' };
     var users = [ user1, user2, user3 ];
     var isFamous = pathEq(['address', 'zipCode'], 90210);
     filter(isFamous, users); //=> [ user1 ]

public pathOr(paths: [String], value: *, obj: Object): * source

import pathOr from '@tinkoff/utils/object/pathOr'

Autocurry for 3 arguments

If the given, non-null object has a value at the given path, returns the value at that path. Otherwise returns the provided default value.

Params:

NameTypeAttributeDescription
paths [String]

The path to use.

value *

The default value.

obj Object

The object to retrieve the nested property from.

Return:

*

The data at path of the supplied object or the default value.

Example:


     pathOr(['a', 'b'],'N/A', {a: {b: 2}}); //=> 2
     pathOr(['a', 'b'], 'N/A', {c: {b: 2}}); //=> "N/A"

public pathSet(paths: [String], value: *, obj: Object): Object source

import pathSet from '@tinkoff/utils/object/pathSet'

Autocurry for 3 arguments

Returns the result of "setting" the portion of the given data structure focused by the given paths to the given value.

Note: If property in the object is equal to value by reference then function just returns object without changes

Params:

NameTypeAttributeDescription
paths [String]
value *
obj Object

Return:

Object

Example:


     pathSet(['a', 'b'], 3, {}) // => { a: { b: 3 } }

public pathSetBy(paths: [String], fn: Function, obj: Object): Object source

import pathSetBy from '@tinkoff/utils/object/pathSetBy'

Autocurry for 3 arguments

Returns the result of "setting" the portion of the given data structure focused by the given paths to the result of fn call.

Note: If property in the object is equal to value by reference then function just returns object without changes

Params:

NameTypeAttributeDescription
paths [String]
fn Function
obj Object

Return:

Object

Example:


     pathSetBy(['a', 'b'], x => x+1, {a: { b:1 }}) // => { a: { b: 2 } }

public pick(props: [String], obj: Object): Object source

import pick from '@tinkoff/utils/object/pick'

Autocurry for 2 arguments

Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.

Params:

NameTypeAttributeDescription
props [String]

an array of String property names to copy onto a new object

obj Object

The object to copy from

Return:

Object

A new object with only properties from names on it.

Example:


     pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
     pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}

public pickBy(fn: Function, obj: Object): Object source

import pickBy from '@tinkoff/utils/object/pickBy'

Autocurry for 2 arguments

Returns a partial copy of an object containing only the keys with fn predicate returns true

Params:

NameTypeAttributeDescription
fn Function

predicate to pick keys. Receives three argument, value, key, obj.

obj Object

The object to copy from

Return:

Object

A new object with only properties from names on it.

Example:


     pickBy(x => x > 2, {a: 1, b: 2, c: 3, d: 4}); //=> {c: 3, d: 4}

public pluck(key: String, arr: Array): Array source

import pluck from '@tinkoff/utils/array/pluck'

Autocurry for 2 arguments

Returns a new list by plucking the same named property off all objects in the list supplied.

Params:

NameTypeAttributeDescription
key String

The key name to pluck off of each object.

arr Array

The array to consider.

Return:

Array

The list of values for the given key.

Example:


     pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2]
     pluck(0)([[1, 2], [3, 4]]);   //=> [1, 3]

public promise(test: *): boolean source

import promise from '@tinkoff/utils/is/promise'

Checks if test is Promise.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if test is Promise, else false.

Example:


     isPromise({}) // => false
     isPromise(Promise.resolve()) // => true

public prop(prop: String, obj: Object): * source

import prop from '@tinkoff/utils/object/prop'

Autocurry for 2 arguments

Returns a function that when supplied an object returns the indicated property of that object, if it exists.

Params:

NameTypeAttributeDescription
prop String

The property name

obj Object

The object to query

Return:

*

The value at obj.p.

Example:


     prop('x', {x: 100}); //=> 100
     prop('x', {}); //=> undefined

public propApply(propName: String, fn: Function, obj: Object): * source

import propApply from '@tinkoff/utils/object/propApply'

Autocurry for 3 arguments

Returns the result of fn with value of property in obj.

Params:

NameTypeAttributeDescription
propName String

The property name to apply.

fn Function

function to apply

obj Object

The object to retrieve the property from.

Return:

*

result of calling fn with property.

Example:


     propApply('a', x => 'is ' + x, {a: 2}); //=> is 2
     propApply('b', x => x > 0, {b: 2}); //=> true

public propEq(propName: String, value: *, obj: *): Boolean source

import propEq from '@tinkoff/utils/object/propEq'

Autocurry for 3 arguments

Returns true if the specified object property is equal to the given value; false otherwise.

Params:

NameTypeAttributeDescription
propName String
value *
obj *

Return:

Boolean

Example:


     var abby = {name: 'Abby', age: 7, hair: 'blond'};
     var fred = {name: 'Fred', age: 12, hair: 'brown'};
     var rusty = {name: 'Rusty', age: 10, hair: 'brown'};
     var alois = {name: 'Alois', age: 15, disposition: 'surly'};
     var kids = [abby, fred, rusty, alois];
     var hasBrownHair = propEq('hair', 'brown');
     filter(hasBrownHair, kids); //=> [fred, rusty]

public propOr(propName: String, value: *, obj: Object): * source

import propOr from '@tinkoff/utils/object/propOr'

Autocurry for 3 arguments

If the given, non-null object has an own property with the specified name, returns the value of that property. Otherwise returns the provided default value.

Params:

NameTypeAttributeDescription
propName String

The name of the property to return.

value *

The default value.

obj Object

The object to query.

Return:

*

The value of given property of the supplied object or the default value.

Example:


     var alice = {
       name: 'ALICE',
       age: 101
     };

     propOr('name', 'Bob')(alice);  //=> 'ALICE'
     propOr('favoriteLibrary', 'react')(alice);  //=> 'react'

public propSet(prop: String, val: *, obj: Object): Object source

import propSet from '@tinkoff/utils/object/propSet'

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the given value. All non-primitive properties are copied by reference.

Note: If property in the object is equal to value by reference then function just returns object without changes

Params:

NameTypeAttributeDescription
prop String

The property name to set

val *

The new value

obj Object

The object to clone

Return:

Object

A new object equivalent to the original except for the changed property.

Example:


     propSet('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}

public propSetBy(prop: String, fn: Function, obj: Object): Object source

import propSetBy from '@tinkoff/utils/object/propSetBy'

Autocurry for 3 arguments

Makes a shallow clone of an object, setting or overriding the specified property with the result of fn call.

Note: If property in the object is equal to value by reference then function just returns object without changes

Params:

NameTypeAttributeDescription
prop String

The property name to set

fn Function

The function to execute

obj Object

The object to clone

Return:

Object

A new object equivalent to the original except for the changed property.

Example:


     propSetBy('a', x => x+1, {a: 1}); //=> {a: 2}

public range(a: number, b: number, step: number): Array source

import range from '@tinkoff/utils/array/range'

Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. A step of -1 is used if a negative start is specified without an end or step. If end is not specified, it's set to start with start then set to 0.

Note: JavaScript follows the IEEE-754 standard for resolving floating-point values which can produce unexpected results.

Params:

NameTypeAttributeDescription
a number
  • optional
  • default: 0

The start of the range.

b number

The end of the range.

step number
  • optional
  • default: 1

The value to increment or decrement by.

Return:

Array

Returns the range of numbers.

Example:


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

range(-4); // => [0, -1, -2, -3]

range(1, 5); // => [1, 2, 3, 4]

range(0, 20, 5); // => [0, 5, 10, 15]

range(0, -4, -1); // => [0, -1, -2, -3]

range(0); // => []

public reduce(fn: Function, acc: *, arr: Array): * source

import reduce from '@tinkoff/utils/array/reduce'

Autocurry for 3 arguments

Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.

Params:

NameTypeAttributeDescription
fn Function

The iterator function. Receives two values, the accumulator and the current element from the array.

acc *

The accumulator value.

arr Array

The list to iterate over.

Return:

*

The final, accumulated value.

Example:


     var numbers = [1, 2, 3];
     var plus = (a, b) => a + b;

     reduce(plus, 10, numbers); //=> 16

public reduce(fn: Function, acc: *, obj: Object): * source

import reduce from '@tinkoff/utils/object/reduce'

Autocurry for 3 arguments

Returns a single item by iterating through the obj, successively calling the iterator function and passing it an accumulator value, current value and current key from the obj, and then passing the result to the next call.

Params:

NameTypeAttributeDescription
fn Function

The iterator function. Receives three argument, accumulator, value, key.

acc *

The accumulator value.

obj Object

The object to iterate over.

Return:

*

The final, accumulated value.

Example:


     var obj = { a: 1, b: 2, c: 3};
     var plus = (a, b) => a + b;

     reduce(plus, 10, obj); //=> 16

public reduceWhile(pred: Function, fn: Function, acc: *, arr: Array): * source

import reduceWhile from '@tinkoff/utils/array/reduceWhile'

Autocurry for 4 arguments

Returns a single item by iterating through the list, successively calling the iterator function. reduceWhile also takes a predicate that is evaluated before each step. If the predicate returns false, it "short-circuits" the iteration and returns the current value of the accumulator.

Note: if arr is undefined or null, acc will be returned by reference immediately

Params:

NameTypeAttributeDescription
pred Function

The predicate function. If it returns a truthy value, reduce continues. Receives the accumulator and the current element

fn Function

The iterator function. Receives four values, the accumulator, the current element from the array, its index, and the original array.

acc *

The accumulator value.

arr Array

The list to iterate over.

Return:

*

The final, accumulated value.

Example:


     reduceWhile(acc => acc.length < 3, (acc, x) => acc + x, '1', ['2', '3', '4', '5']) // '123'

public reject(fn: Function, arr: Array): Array source

import reject from '@tinkoff/utils/array/reject'

Autocurry for 2 arguments

Takes a predicate and a "arr", and returns a new array of the same type containing the members of the given arr which do not satisfy the given predicate.

Params:

NameTypeAttributeDescription
fn Function

predicate

arr Array

Return:

Array

Example:


     var isEven = n => n % 2 === 0;

     reject(isEven, [1, 2, 3, 4]); //=> [1, 3]

public rejectWith(func: Function, payload: *[]): Promise source

import rejectWith from '@tinkoff/utils/promise/rejectWith'

Autocurry for 2 arguments

Returns a promise that rejects with a value returned by the supplied function when passed the supplied payload

Params:

NameTypeAttributeDescription
func Function
payload *[]

Return:

Promise

Example:

     rejectWith(toLowerCase, 'Error').catch( err => console.error(err) );// => 'error'

public remove(start: Number, count: Number, list: Array): * source

import remove from '@tinkoff/utils/array/remove'

Autocurry for 3 arguments

Removes the sub-list of list starting at index start and containing count elements. Note that this is not destructive: it returns a copy of the list with the changes. <small>No lists have been harmed in the application of this function.</small>

Params:

NameTypeAttributeDescription
start Number

The position to start removing elements

count Number

The number of elements to remove

list Array

The list to remove from

Return:

*

Example:


     remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]

public repeat(n: Number, value: *): Array source

import repeat from '@tinkoff/utils/array/repeat'

Autocurry for 2 arguments

Returns a fixed list of size n containing a specified identical value.

Params:

NameTypeAttributeDescription
n Number

The desired size of the output list.

value *

The value to repeat.

Return:

Array

A new array containing n values.

Example:


     repeat(5, 'hi'); //=> ['hi', 'hi', 'hi', 'hi', 'hi']

     var obj = {};
     var repeatedObjs = repeat(5, obj); //=> [{}, {}, {}, {}, {}]
     repeatedObjs[0] === repeatedObjs[1]; //=> true

public repeat(n: Number, value: String): String source

import repeat from '@tinkoff/utils/string/repeat'

Autocurry for 2 arguments

Returns a string containing a repeated identical value.

Params:

NameTypeAttributeDescription
n Number

The number to repeat value.

value String

The value to repeat.

Return:

String

A new string containing n values.

Example:


     repeat(5, 'h'); //=> 'hhhhh'

public replace(pattern: RegExp | String, replacement: String, str: String): String source

import replace from '@tinkoff/utils/string/replace'

Autocurry for 3 arguments

Replace a substring or regex match in a string with a replacement.

Params:

NameTypeAttributeDescription
pattern RegExp | String

A regular expression or a substring to match.

replacement String

The string to replace the matches with.

str String

The String to do the search and replacement in.

Return:

String

The result.

Example:


     replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
     replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'

     // Use the "g" (global) flag to replace all occurrences:
     replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'

public resolveWith(func: Function, payload: *[]): Promise source

import resolveWith from '@tinkoff/utils/promise/resolveWith'

Autocurry for 2 arguments

Returns a promise that resolves with a value returned by the supplied function when passed the supplied payload

Params:

NameTypeAttributeDescription
func Function
payload *[]

Return:

Promise

Example:

     rejectWith(toLowerCase, 'OK').then( res => console.info(res) );// => 'ok'

public reverse(list: Array | String): Array | String source

import reverse from '@tinkoff/utils/array/reverse'

Returns a new list or string with the elements or characters in reverse order.

Params:

NameTypeAttributeDescription
list Array | String

Return:

Array | String

Example:


     reverse([1, 2, 3]);  //=> [3, 2, 1]
     reverse([1, 2]);     //=> [2, 1]
     reverse([1]);        //=> [1]
     reverse([]);         //=> []

     reverse('abc');      //=> 'cba'
     reverse('ab');       //=> 'ba'
     reverse('a');        //=> 'a'
     reverse('');         //=> ''

public shallowEqual(test1: *, test2: *): Boolean source

import shallowEqual from '@tinkoff/utils/is/shallowEqual'

Returns true if its arguments are equivalent is shallow equal terms, false otherwise.

Params:

NameTypeAttributeDescription
test1 *
test2 *

Return:

Boolean

Example:


     isShallowEqual(1, 1); //=> true
     isShallowEqual(1, '1'); //=> false
     isShallowEqual([1, 2, 3], [1, 2, 3]); //=> true
     isShallowEqual({ a: { b: 1 }}, { a: { b: 1 }}); //=> false

public shuffle(arr: Array): Array source

import shuffle from '@tinkoff/utils/array/shuffle'

Creates an array of shuffled values

Params:

NameTypeAttributeDescription
arr Array

The collection to shuffle.

Return:

Array

Returns the new shuffled array.

Example:


shuffle([1, 2, 3, 4]); // => [4, 1, 3, 2]

public size(obj: Object): number source

import size from '@tinkoff/utils/object/size'

Gets the size of obj by returning the number of own enumerable properties.

Params:

NameTypeAttributeDescription
obj Object

The collection to inspect.

Return:

number

Returns the collection size.

Example:


size({ 'a': 1, 'b': 2 }); // => 2

public slice(fromIndex: Number, toIndex: Number, list: Array | String): Array | String source

import slice from '@tinkoff/utils/array/slice'

Autocurry for 3 arguments

Returns the elements of the given list or string (or object with a slice method) from fromIndex (inclusive) to toIndex (exclusive).

Params:

NameTypeAttributeDescription
fromIndex Number

The start index (inclusive).

toIndex Number

The end index (exclusive).

list Array | String

Return:

Array | String

Example:


     slice(1, 3, ['a', 'b', 'c', 'd']);        //=> ['b', 'c']
     slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
     slice(0, -1, ['a', 'b', 'c', 'd']);       //=> ['a', 'b', 'c']
     slice(-3, -1, ['a', 'b', 'c', 'd']);      //=> ['b', 'c']

public snakeCaseName(str: String): String source

import snakeCaseName from '@tinkoff/utils/string/snakeCaseName'

Returns the snake case version of a string.

This function convert only latin chars. The preferred purpose is to generate file or class names in your code generation tools.

Params:

NameTypeAttributeDescription
str String

The string to switch to snake case.

Return:

String

The snake case version of str.

Example:


     snakeCaseName('Foo Bar'); //=> 'foo_bar'
     snakeCaseName('fooBar');  //=> 'foo_bar'
     snakeCaseName('foo-bar'); //=> 'foo_bar'
     snakeCaseName('FOO-BAR'); //=> 'foo_bar'
     snakeCaseName('Foo Bär'); //=> 'foo_b_r' only latin chars are supported

public sort(comparator: Function, arr: Array): Array source

import sort from '@tinkoff/utils/array/sort'

Autocurry for 2 arguments

Returns a copy of the array, sorted according to the comparator function, which should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal. Please note that this is a copy of the list. It does not modify the original.

Params:

NameTypeAttributeDescription
comparator Function

A sorting function

arr Array

The list to sort

Return:

Array

a new array with its elements sorted by the comparator function.

Example:


     var diff = function(a, b) { return a - b; };
     sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]

public sortBy(fn: Function, arr: Array): Array source

import sortBy from '@tinkoff/utils/array/sortBy'

Autocurry for 2 arguments

Sorts the array according to the supplied function.

Params:

NameTypeAttributeDescription
fn Function
arr Array

The array to sort.

Return:

Array

A new array sorted by the keys generated by fn.

Example:


     var sortByFirstItem = sortBy(x => x[0]);
     var pairs = [[-1, 1], [-2, 2], [-3, 3]];
     sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]]

public split(delim: String | RegExp, str: String): Array source

import split from '@tinkoff/utils/string/split'

Autocurry for 2 arguments

Splits a string into an array of strings based on the given separator.

Params:

NameTypeAttributeDescription
delim String | RegExp

The pattern.

str String

The string to separate into an array.

Return:

Array

The array of strings from str separated by str.

Example:


     split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']

public splitEvery(length: Number, arr: Array | String): Array[] | String[] source

import splitEvery from '@tinkoff/utils/array/splitEvery'

Autocurry for 2 arguments

Splits a collection into slices of the specified length

Params:

NameTypeAttributeDescription
length Number

desired length of slices

arr Array | String

a collection to split

Return:

Array[] | String[]

Example:

     splitEvery(2, [1, 2, 3, 4, 5]); // => [[1, 2], [3, 4], [5]]

public stableSortBy(fn: Function, arr: Array): Array source

import stableSortBy from '@tinkoff/utils/array/stableSortBy'

Autocurry for 2 arguments

Sorts the array according to the supplied function and keeping the order of elements.

Params:

NameTypeAttributeDescription
fn Function
arr Array

The array to sort.

Return:

Array

A new array sorted by the keys generated by fn.

Example:


     const people = [
         { name: 'Ann', age: 20 },
         { name: 'Gary', age: 20 },
         { name: 'John', age: 17 },
         { name: 'Sam', age: 21 },
         { name: 'Bob', age: 17 }
     ];
     stableSortBy(path(['age']), people) => [
         { name: 'John', age: 17 },
         { name: 'Bob', age: 17 },
         { name: 'Ann', age: 20 },
         { name: 'Gary', age: 20 },
         { name: 'Sam', age: 21 }
     ]

public startsWith(prefix: string, str: string): Boolean source

import startsWith from '@tinkoff/utils/string/startsWith'

Autocurry for 2 arguments

Checks if a string starts with the provided prefix

Params:

NameTypeAttributeDescription
prefix string
str string

Return:

Boolean

Example:


     startsWith('a', 'abc')                //=> true
     startsWith('b', 'abc')                //=> false

public strictEqual(test1: *, test2: *): Boolean source

import strictEqual from '@tinkoff/utils/is/strictEqual'

Returns true if its arguments are equivalent is same value zero terms, false otherwise.

Params:

NameTypeAttributeDescription
test1 *
test2 *

Return:

Boolean

Example:


     isStrictEqual(1, 1); //=> true
     isStrictEqual(1, '1'); //=> false
     isStrictEqual({}, {}); //=> false
     isStrictEqual(NaN, NaN); //=> true
     isStrictEqual(-0, 0); //=> true

public string(test: *): boolean source

import string from '@tinkoff/utils/is/string'

Checks if test is string.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if value is string, else false.

Example:


isString('test'); // => true
isString(new String('test')); // => true
isString(null); // => false

public sum(arr: Array): Number source

import sum from '@tinkoff/utils/array/sum'

Adds together all the elements of a list.

Params:

NameTypeAttributeDescription
arr Array

An array of numbers

Return:

Number

The sum of all the numbers in the list.

Example:


     sum([2,4,6,8,100,1]); //=> 121

public tail(arr: Array): * source

import tail from '@tinkoff/utils/array/tail'

Returns all but the first element of the given array.

Params:

NameTypeAttributeDescription
arr Array

Return:

*

Example:


     tail(['fi', 'fo', 'fum']); //=> ['fo', 'fum']
     tail([]); //=> []

public take(n: Number, arr: Array | String): * source

import take from '@tinkoff/utils/array/take'

Autocurry for 2 arguments

Returns the first n elements of the given array or string

Params:

NameTypeAttributeDescription
n Number
arr Array | String

Return:

*

Example:


     take(1, ['foo', 'bar', 'baz']); //=> ['foo']
     take(2, ['foo', 'bar', 'baz']); //=> ['foo', 'bar']
     take(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
     take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
     take(3, 'ramda');               //=> 'ram'

public takeRightWhile(fn: Function, arr: Array | String): Array | String source

import takeRightWhile from '@tinkoff/utils/array/takeRightWhile'

Autocurry for 2 arguments

Returns a new array|string containing the last n elements of a given array|string, passing each value to the supplied predicate function, and terminating when the predicate function returns false. Excludes the element that caused the predicate function to fail.

Params:

NameTypeAttributeDescription
fn Function

The function called per iteration.

arr Array | String

The collection to iterate over.

Return:

Array | String

A new array or string.

Example:


     var isNotOne = x => x !== 1;

     takeRightWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4]

public tap(fn: Function, x: *): * source

import tap from '@tinkoff/utils/function/tap'

Autocurry for 2 arguments

Runs the given function with the supplied argument, then returns the argument.

Params:

NameTypeAttributeDescription
fn Function

The function to call with x. The return value of fn will be thrown away.

x *

Return:

*

x.

Example:


     var sayX = x => console.log('x is ' + x);
     tap(sayX, 100); //=> 100
     // logs 'x is 100'

public tap(fn: Function, x: *): * source

import tap from '@tinkoff/utils/promise/tap'

Autocurry for 2 arguments

Runs the given promise with the supplied argument. Returns the argument, when promise is resolved.

Params:

NameTypeAttributeDescription
fn Function

The function to call with x. The return value of fn will be thrown away.

x *

Return:

*

x.

Example:


     var sayX = x => console.log('x is ' + x);
     Promise.resolve(5).then(promiseTap(sayX));
     // logs 'x is 5'

public template(replacements: Object, str: String): String source

import template from '@tinkoff/utils/string/template'

Autocurry for 2 arguments

Replaces string keywords with provided values

Params:

NameTypeAttributeDescription
replacements Object

object with keywords and corresponding replacements

str String

string with keywords in a correct format '%{keyword}'

Return:

String

String with replaced keywords

Example:


     template({ fruit: 'banana' }, 'Petya has a %{fruit}') // => Petya has a banana

public test(pattern: RegExp, str: String): Boolean source

import test from '@tinkoff/utils/string/test'

Autocurry for 2 arguments

Determines whether a given string matches a given regular expression.

Params:

NameTypeAttributeDescription
pattern RegExp
str String

Return:

Boolean

public throttle(wait: number, fn: Function): * source

import throttle from '@tinkoff/utils/function/throttle'

Autocurry for 2 arguments

Creates a throttled function that only invokes fn at most once per every wait milliseconds. fn is called in start of wait delay

Params:

NameTypeAttributeDescription
wait number

The number of milliseconds to throttle invocations to.

fn Function

The function to throttle.

Return:

*

public throttleEnd(wait: number, fn: Function): * source

import throttleEnd from '@tinkoff/utils/function/throttleEnd'

Autocurry for 2 arguments

Creates a throttled function that only invokes fn at most once per every wait milliseconds. fn is called in the end of wait delay

Params:

NameTypeAttributeDescription
wait number

The number of milliseconds to throttle invocations to.

fn Function

The function to throttle.

Return:

*

public toArray(val: *): Array source

import toArray from '@tinkoff/utils/array/toArray'

Converts val to array. If val is array return it.

Params:

NameTypeAttributeDescription
val *

Return:

Array

Example:


     toArray([1,2,3]) // => [1,2,3]
     toArray(5) // => [5]
     toArray('test') // => ['test']

public toLower(str: String): String source

import toLower from '@tinkoff/utils/string/toLower'

Returns the lower case version of a string.

Params:

NameTypeAttributeDescription
str String

The string to lower case.

Return:

String

The lower case version of str.

Example:


     toLower('XYZ'); //=> 'xyz'

public toPairs(obj: Object): Array source

import toPairs from '@tinkoff/utils/object/toPairs'

Converts an object into an array of key, value arrays. Only the object's own properties are used. Note that the order of the output array is not guaranteed to be consistent across different JS platforms.

Params:

NameTypeAttributeDescription
obj Object

The object to extract from

Return:

Array

An array of key, value arrays from the object's own properties.

Example:


     toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]

public toString(val: *): string source

import toString from '@tinkoff/utils/string/toString'

Converts value to a string. An empty string is returned for null and undefined values.

Params:

NameTypeAttributeDescription
val *

The value to convert.

Return:

string

Returns the converted string.

Example:


toString(null); // => ''

toString('test'); // => 'test'

toString([1, 2, 3]); => '1,2,3'

public toUpper(str: String): String source

import toUpper from '@tinkoff/utils/string/toUpper'

Returns the upper case version of a string.

Params:

NameTypeAttributeDescription
str String

The string to upper case.

Return:

String

The upper case version of str.

Example:


     toLower('xyz'); //=> 'XYZ'

public trim(str: String): String source

import trim from '@tinkoff/utils/string/trim'

Removes leading and trailing whitespace from str.

Params:

NameTypeAttributeDescription
str String

The string to trim.

Return:

String

Returns the trimmed string.

Example:


trim('  abc  '); // => 'abc'

public trimLeft(str: String): String source

import trimLeft from '@tinkoff/utils/string/trimLeft'

Removes leading whitespace from str.

Params:

NameTypeAttributeDescription
str String

The string to trim.

Return:

String

Returns the trimmed string.

Example:


trimLeft('  abc  '); // => 'abc   '

public tryCatch(tryer: Function, catcher: Function): Function source

import tryCatch from '@tinkoff/utils/function/tryCatch'

Autocurry for 2 arguments

Takes two functions, tryer and catcher.

Returns a function that, when invoked with zero or more parameters, calls the tryer with those parameters, and if tryer throws, calls the catcher with the error as first argument and original arguments as rest. If that still throws, then ¯_(ツ)_/¯

Params:

NameTypeAttributeDescription
tryer Function
catcher Function

Return:

Function

Example:

     tryCatch(x => x.length, () => 0)([ 1, 2, 3 ]) // 3
     tryCatch(x => x.length, () => 0)( undefined ) // 0
     tryCatch(
         someDataTransform,
         (err, ...rest) => {
             logAsyncToServer('someDataTransform failed', err, 'with arguments', rest);
             return DEFAULT_VALUE;
         }
     )( someIncompleteData ) // DEFAULT_VALUE (error is logged somewhere)

public type(x: *): String source

import type from '@tinkoff/utils/type'

Gives a single-word string description of the (native) type of a value, returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user Object types any further, reporting them all as 'Object'.

Params:

NameTypeAttributeDescription
x *

The value to test

Return:

String

Example:


     type({}); //=> "Object"
     type(1); //=> "Number"
     type(false); //=> "Boolean"
     type('s'); //=> "String"
     type(null); //=> "Null"
     type([]); //=> "Array"
     type(/[A-z]/); //=> "RegExp"

public undefined(test: *): boolean source

import undefined from '@tinkoff/utils/is/undefined'

Checks if test is undefined.

Params:

NameTypeAttributeDescription
test *

The value to check.

Return:

boolean

Returns true if value is undefined, else false.

Example:


isUndefined(void 0); // => true
isUndefined(null);// => false

public unescape(str: string): string source

import unescape from '@tinkoff/utils/string/unescape'

The inverse of escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.

Params:

NameTypeAttributeDescription
str string

The string to unescape.

Return:

string

Returns the unescaped string.

Example:


unescape('fred, barney, &amp; pebbles'); // => 'fred, barney, & pebbles'

public uniq(arr: Array): Array source

import uniq from '@tinkoff/utils/array/uniq'

Returns unique items in array

Params:

NameTypeAttributeDescription
arr Array

Return:

Array

Example:


 unique([1,2,1,2,3,4,1,2]) // => [1, 2, 3, 4]

public uniqBy(fn: Function, arr: Array): Array source

import uniqBy from '@tinkoff/utils/array/uniqBy'

Autocurry for 2 arguments

Returns unique items in array. Uniqueness is defined by fn.

Params:

NameTypeAttributeDescription
fn Function
arr Array

Return:

Array

Example:


     uniqBy(x => x % 2, [1, 2, 2, 3, 4, 5, 5, 5]) // [1, 2]

public uniqueId(): number source

import uniqueId from '@tinkoff/utils/uniqueId'

Generates a unique ID.

Return:

number

Returns the unique ID.

public update(idx: Number, x: *, list: Array): Array source

import update from '@tinkoff/utils/array/update'

Autocurry for 3 arguments

Returns a new copy of the array with the element at the provided index replaced with the given value.

Params:

NameTypeAttributeDescription
idx Number

index

x *

The value to exist at the given index of the returned array.

list Array

The source array to be updated.

Return:

Array

A copy of list with the value at index idx replaced with x.

Example:


     update(1, 11, [0, 1, 2]);     //=> [0, 11, 2]
     update(1)(11)([0, 1, 2]);     //=> [0, 11, 2]

public updatePropertyValue(propertyName: String, propertyValue: Any, obj: Object): Object source

import updatePropertyValue from '@tinkoff/utils/function/updatePropertyValue'
this function was deprecated. use propSet instead

Autocurry for 2 arguments

A function to change value by property name in object.

Params:

NameTypeAttributeDescription
propertyName String

property name of target object

propertyValue Any

new value

obj Object

a target object

Return:

Object

changed object with new value

Example:

     var fn = () => {};
     var updateName = updatePropertyValue('name', 'newFn');

     fn.name //=> 'fn'

     var newFn = updateName(fn);

     newFn.name //=> 'newFn'
     fn.name //=> 'newFn'

public upperFirst(str: String): String source

import upperFirst from '@tinkoff/utils/string/upperFirst'

Converts the first character of string to upper case and returns the new string.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

The converted string.

Example:


     upperFirst('foo');  //=> 'Foo'
     upperFirst('über'); //=> 'Über'
     upperFirst('FOO');  //=> 'FOO'

public values(obj: Object): Array source

import values from '@tinkoff/utils/object/values'

Returns a list of all the enumerable own properties of the supplied object. Note that the order of the output array is not guaranteed across different JS platforms.

Params:

NameTypeAttributeDescription
obj Object

The object to extract values from

Return:

Array

An array of the values of the object's own properties.

Example:


     values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]

public when(pred: Function, onTrue: Function, x: *): * source

import when from '@tinkoff/utils/function/when'

Autocurry for 3 arguments

Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function will return the result of calling the onTrue function with the same argument. If the predicate is not satisfied, the argument is returned as is.

Params:

NameTypeAttributeDescription
pred Function

A predicate function

onTrue Function

A function to invoke when the condition evaluates to a truthy value.

x *

An object to test with the pred function and pass to onTrue if necessary.

Return:

*

Either x or the result of applying x to onTrue.

Example:


     // truncate :: String -> String
     var truncate = R.when(
       x => x.length > 10,
       x => x.slice(0, 10) + '...'
     );
     truncate('12345');         //=> '12345'
     truncate('0123456789ABC'); //=> '0123456789…'

public where(spec: Object, obj: Object): Boolean source

import where from '@tinkoff/utils/object/where'

Autocurry for 2 arguments

Takes a spec object and a test object; returns true if the test satisfies the spec. Each of the spec's own properties must be a predicate function. Each predicate is applied to the value of the corresponding property of the test object. where returns true if all the predicates return true, false otherwise.

Params:

NameTypeAttributeDescription
spec Object
obj Object

Return:

Boolean

Example:


     // pred :: Object -> Boolean
     var pred = where({
       a: isEqual('foo'),
       b: complement(isEqual('bar')),
       x: a => a > 10,
       y: a => a < 20
     });

     pred({a: 'foo', b: 'xxx', x: 11, y: 19}); //=> true
     pred({a: 'xxx', b: 'xxx', x: 11, y: 19}); //=> false
     pred({a: 'foo', b: 'bar', x: 11, y: 19}); //=> false
     pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false
     pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false

public with(createCache: Function, hasher: Function, function: Function): Function source

Autocurry for 3 arguments

memoizeWith is a memoize function fabric. It has simple classic memoization signature. Use it to build your own memoization function.

It takes three params: 1) function that will be used to create cache object. Cache must have three methods - get, has, set. So it's compatible with Map, WeakMap, LRU (https://www.npmjs.com/package/lru-cache) instances. 2) function that will be used to create hash key for cache lookup. It is invoked with arguments for result function. 3) function, that will be memoized. *

Params:

NameTypeAttributeDescription
createCache Function

creates cache object

hasher Function

creates hash for given arguments

function Function

that will be memoized

Return:

Function

Example:

     const createCache = () => new Map();
     const hasher = (...args) => JSON.stringify(args);
     const memoize = memoizeWith(createCache, hasher);

     const add = (a,b) => a + b;
     const memoizeAdd = memoize(add);
     const sum = add(1,3); // from original add call
     const sum = add(1,4); // from original add call
     const sum = add(1,3); // from cache

public without(xs: Array, list: Array): Array source

import without from '@tinkoff/utils/array/without'
this function was deprecated. use array/difference instead

Autocurry for 2 arguments

Returns a new list without values in the first argument.

Params:

NameTypeAttributeDescription
xs Array

The values to be removed from list2.

list Array

The array to remove values from.

Return:

Array

The new array without values in list1.

Example:


     without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4]

public words(str: String): String[] source

import words from '@tinkoff/utils/string/words'

Splits string into an array of its words.

This function supports only latin chars.

Params:

NameTypeAttributeDescription
str String

The string to split.

Return:

String[]

String' words.

Example:


     words('fooBarZoo');   //=> ['foo', 'Bar', 'Zoo']
     words('foo_bar_zoo'); //=> ['foo', 'bar', 'zoo']
     words('foo-bar-zoo'); //=> ['foo', 'bar', 'zoo']
     words('foo bar zoo'); //=> ['foo', 'bar', 'zoo']
     words('fooBär');      //=> ['foo', 'B', 'r'] only latin chars are supported

public zip(a: Array, b: Array): Array source

import zip from '@tinkoff/utils/array/zip'

Autocurry for 2 arguments

Creates a new list out of the two supplied by pairing up equally-positioned items from both lists. The returned list is truncated to the length of the shorter of the two input lists.

Params:

NameTypeAttributeDescription
a Array

The first array to consider.

b Array

The second array to consider.

Return:

Array

The list made by pairing up same-indexed elements of a and b.

Example:


     zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]

public zipWith(fn: Function, a: Array, b: Array): Array source

import zipWith from '@tinkoff/utils/array/zipWith'

Autocurry for 3 arguments

Creates a new list out of the two supplied by applying the function to each equally-positioned pair in the lists. The returned list is truncated to the length of the shorter of the two input lists.

Params:

NameTypeAttributeDescription
fn Function

The function used to combine the two elements into one value.

a Array

The first array to consider.

b Array

The second array to consider.

Return:

Array

The list made by combining same-indexed elements of a and b using fn.

Example:


     var f = (x, y) => {
       // ...
     };
     zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
     //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]

Static Private

private _path(paths: *[], obj: {}): * source

Autocurry for 2 arguments

null

Params:

NameTypeAttributeDescription
paths *[]
  • optional
  • default: []
obj {}
  • optional
  • default: {}

Return:

*