Home Reference Source Test

Function

Static Public Summary
public

Applicative(f: any): Appicative

Appicative implementation.

public

Apply(f: any): Apply

Apply implementation.

public

Either()

Either implementation.

public

Functor implementation.

public

Just(value: any): Just

Just Implementation.

public

LazyFunctor implementation.

public

Left(value: any): Left

Left Implementation.

public

Maybe()

Maybe implementation.

public

Monad(x: any): Monad

Monad implementation.

public

Nothing(value: any): Nothing

Creates new Nothing.

public

Right(value: any): Right

Right Implementation.

public

add(augend: number, addendList: ...number): number

Adds numbers.

public

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

Creates a function that invokes fn once it's called n or more times.

public

alt(fn1: Function, fn2: Function): Function

This combinator takes two functions and returns the result of the first one if the value is defined (not false, null, or undefined); otherwise, it returns the result of the second function.

public

always(value: T): Function

Creates function which will always return passed argument.

public

and(predicates: ...Function): Function

Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return true.

public

any(source: Array<T>, fn: Function): boolean

Checks if predicate returns truthy for any element of collection.

public

assoc(propName: string, valueToBeSet: T, source: object): object

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

public

assocPath(path: Array<String|Number>, valueToBeSet: any, source: Object | Array): Object | Array

Updates Array or Object by given path with given value.

public

buildResource(src: String, args: Array<T>): String

Works similarly to templates.

public

Converts string to camel case.

public

castArray(valueToCast: ...T): Array<T>

Casts values as an array if it's not one.

public

changeOrder(source: Array<T>, order: Array<number>): Array<T>

Returns array with changed order.

public

cloneArray(source: Array<T>): Array<T>

Will create clone of given array.

public

cloneObject(objectToClone: object): object

Will create object clone.

public

compact(source: Array<T>): Array<T>

Creates an array with all falsey values removed.

public

Compares two small decimal values.

public

This method is like pipe except that it creates a function that invokes the provided functions from right to left.

public

conformsTo(object: object, predicateSetModel: object): boolean

Checks object properties with set of predicates.

public

curry(fn: Function): Function | T

Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on.

public

deepClone(objectToDeepClone: object): object

Will create an object deep clone.

public

deepEquals(first: any, second: any): boolean

Compares two elements.

public

Will deep frezee all properties.

public

divide(dividend: number, divisorList: number): number

Divide numbers.

public

Takes function and invokes it with passed argument two times.

public

eq(elem1: T): Function

Checks if two elements are the same

public

Will compare two strings with ignore case.

public

every(source: Array<T>, fn: Function): boolean

Checks if predicate returns truthy for all elements of collection.

public

fill(source: T, number: number): Array<T>

Will fill array by given value.

public

fillLeft(value: T, number: number, source: Array<T|D>): Array<T|D>

Will fill array in the begining for n elements and add given array in the end.

public

fillRight(value: T, number: number, source: Array<T|D>): Array<T|D>

Will fill array in the end for n elements and add given array from begining.

public

filter(source: Array<T>, fn: Function): Array<T>

Will filter an array.

public

find(source: Array<T>, fn: Function): T

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

public

first(source: Array<T>): T

Will return first element from array.

public

flatten(source: Array<T>): *

Flattens array.

public

Takes function and changes argument order.

public

fork(join: Function, fn1: Function, fn2: Function): Function

The fork combinator is useful in cases where you need to process a single resource in two different ways and then combine the results.

public

Will return first lower letter from source.

public

Will return first upper letter from source.

public

Will return last lower letter from source.

public

Will return last upper letter from source.

public

Will generate random integer.

public

Will generate random integer in passed range.

public

getType(valToCheck: T): string

Checks type of passed value.

public

getTypeByClass(clazz: T): string

Returns class name.

public

Curry version of get function that expects in future to get property list.

public

Curry version of get function that expects in future to get context.

public

groupBy(args: ...any): object

Will group objects in array by given property, function or path.

public

groupByFn(source: Array<object>, groupFn: Function): object

Will group objects in array by function.

public

groupByPath(source: Array<object>, groupPath: *): object

Will group objects in array by object path.

public

groupByProp(source: Array<object>, groupVal: string): object

Will group objects in array by property.

public

gt(number1: number): Function

Saves number1 and returns predicate function that will be checking if number2 is greater then number1.

public

gte(number1: number): Function

Saves number1 and returns predicate function that will be checking if number2 is greater then or equal to number1.

public

head(source: Array<T>): T

Will return first element from array.

public

identity(value: T): T

The identity combinator is a function that returns the same value it was provided as an argument.

public

includes(source: String, includement: String | number): boolean

Work similary to indexOf method but returns boolean.

public

invoke(fns: ...Function): object

Will invoke list of functions with given context.

public

invokeWithCtx(ctx: object, fns: ...Function): void

Will invoke list of functions with given context in single invokation.

public

isArray(valToCheck: T): boolean

Checks if passed value is Array.

public

isBoolean(valToCheck: T): boolean

Checks if passed value is boolean.

public

isDate(valToCheck: T): boolean

Checks if passed value is Date.

public

isFunction(valToCheck: T): boolean

Checks if passed value is Function.

public

isNaN(valToCheck: T): boolean

Checks if passed value is NaN.

public

isNegativeZero(numberToCheck: number): boolean

Checks if passed value is negative zero.

public

isNotArray(valToCheck: T): boolean

Checks if passed value is not Array.

public

isNotBoolean(valToCheck: T): boolean

Checks if passed value is not boolean.

public

isNotDate(valToCheck: T): boolean

Checks if passed value is not Date.

public

isNotFunction(valToCheck: T): boolean

Checks if passed value is not Function.

public

isNotNaN(valToCheck: T): boolean

Checks if passed value is not NaN.

public

isNotNegativeZero(numberToCheck: number): boolean

Checks if passed value is not negative zero.

public

isNotNull(valToCheck: T): boolean

Checks if passed value is not null.

public

isNotNumber(valToCheck: T): boolean

Checks if passed value is not number.

public

isNotObject(valToCheck: T): boolean

Checks if passed value is not Object.

public

isNotPrimitive(value: T): boolean

Determine whether a value is not a primitive type.

public

isNotRegExp(valToCheck: T): boolean

Checks if passed value is not RegExp.

public

isNotString(valToCheck: T): boolean

Checks if passed value is not string.

public

isNotSymbol(valToCheck: T): boolean

Checks if passed value is not Symbol.

public

isNotUndefined(valToCheck: T): boolean

Checks if passed value is not undefined.

public

isNull(valToCheck: T): boolean

Checks if passed value is null.

public

isNumber(valToCheck: T): boolean

Checks if passed value is number.

public

isObject(valToCheck: T): boolean

Checks if passed value is Object.

public

isPrimitive(value: T): boolean

Determine whether a value is a primitive type.

public

isRegExp(valToCheck: T): boolean

Checks if passed value is RegExp.

public

Checks if passed object implements setoid.

public

isString(valToCheck: T): boolean

Checks if passed value is string.

public

isSymbol(valToCheck: T): boolean

Checks if passed value is Symbol.

public

isUndefined(valToCheck: T): boolean

Checks if passed value is undefined.

public

Converts string to kebab case.

public

last(source: Array<T>): T

Will return last element from array.

public

lensIndex(index: number, source: Array<T>): T

Returns value taken by index from source.

public

lensProp(propName: string): Function

Returns a lens whose focus is the specified property.

public

lt(number1: number): Function

Saves number1 and returns predicate function that will be checking if number2 is less then number1.

public

lte(number1: number): Function

Saves number1 and returns predicate function that will be checking if number2 is less then or equal to number1.

public

map(source: Array<T>, fn: Function): Array<D>

Will project array object.

public

Creates a function that memoizes the result of fn.

public

multiply(multiplier: number, multiplicandList: number): number

Multiply numbers.

public

not(predicates: ...Function): Function

Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return false.

public

notEq(elem1: T): Function

Checks if two elements are not the same.

public

notOr(predicates: ...Function): Function

Takes list of predicates and returns a one predicate, current predicate will return true only in the case if none of passed prdicates returns true.

public

notToBe(expectation: T): Function

Takes expectation and returns predicate function which will be checking if new passed variable not equal to expectation.

public

nth(source: Array<T>, index: number): T

Will return element from array by given index.

public

numAndStrComparator(first: string | number, second: string | number, prop: string): number

number or string comparator.

public

Iterates by object properties.

public

omit(source: object, omitArray: ...string): object

Will create and return a new object with omited properties from omitArray.

public

once(fn: Function): T | undefined

Creates a function that is restricted to invoking func once.

public

or(predicates: ...Function): Function

Takes list of predicates and returns a one predicate, current predicate will return true if at least one of passed predicates returns true.

public

orCurry(fn: Function, args: ArrayLike | Array<any>): Function | T

Creates curry variation of function if some of arguments are missed.

public

partial(fn: Function, partialArgs: ...T): Function

Creates a function that invokes fn with partials prepended to the arguments it receives.

public

path(p: Array<string>, source: object): any

Retrieve the value at a given path.

public

pathEq(path: Array<string>, source: object, value: any): any

Retrieve the value at a given path and compares it with given value.

public

pathOr(path: Array<string>, source: object, orValue: any): any

Retrieve the value at a given path and if value is undefined returns orValue.

public

pathSatisfies(path: Array<string>, source: object, satisfyFn: Function): any

Retrieve the value at a given path and returns result of invocation satisfy function with value by path.

public

pick(source: object, pickArray: ...string): object

Will create and return a new object with selected properties from pickArray.

public

pipe(fns: ...Function): Function

Creates a function that returns the result of invoking the provided f unctions with the this binding of the created function, where each successive invocation is supplied the return value of the previous.

public

pluck(source: Array<Object>, propName: string): Array<T>

Will return array of selected properties.

public

prop(propName: string, source: object): T

Returns value taken by property from source.

public

range(number1: number, number2: number): Function

Saves number1, number2 and returns predicate function that will be checking if future passed number is in range of number1 and number2.

public

rangeEqual(number1: number, number2: number): Function

Saves number1, number2 and returns predicate function that will be checking if future passed number is in range of number1 and number2 or equal to number1/number2.

public

rearg(fn: Function, order: Array<number>): *

Reorginizes argument order.

public

reject(source: Array<T>, fn: Function): Array<T>

The opposite of filter; this method returns the elements of collection that predicate does not return truthy for.

public

replaceAll(replaceable: String, from: String, to: T): String

Will replace all occurrences.

public

replaceAllDifferences(replaceable: String, fromList: Array<T>, to: Array<T>): String

Will replace all different occurrences.

public

safeGet(obj: object, props: ...string): *

Implementation of optional chain operator.

public

safeGetOr(obj: object, orValue: any, props: ...string): any

Implementation of optional chain operator.

public

sample(source: Array<T>): T

Will return random element from array.

public

seq(fns: ...Function): Function

The seq combinator is used to loop over a sequence of functions.

public

shuffle(source: Array<T>): Array<T>

Will shuffle elements in array.

public

Converts string to snake case.

public

some(source: Array<T>, fn: Function): boolean

Checks if predicate returns truthy for any element of collection.

public

sortBy(source: Array<object>, propList: Array<string>): Array<object>

Sorts array of objects by given properties with priorities.

public

subtract(minuend: number, subtrahendList: number): number

Subtract numbers.

public

tail(source: Array<T>): T

Will return last element from array.

public

take(source: Array<T>, sourceLength: number): Array<T>

Will return first n elements.

public

takeRight(source: Array<T>, numberOfLastElements: number): Array<T>

Will return last n elements from an array.

public

takeRightWhile(source: Array<T>, rightWhileFn: Function): Array<T>

Creates a slice of array with elements taken from the end.

public

takeWhile(source: Array<T>, whileFn: Function): Array<T>

Creates a slice of array with elements taken from the beginning.

public

Helps to check data in chain.

public

Throws IncorrectArgsTypeError if at least one of conditions is positive.

public

Takes argument and returns function which expects to get function which will be invoked with first argument.

public

times(iterationNumber: number, fn: Function): Array<T>

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

public

toBe(expectation: T): Function

Takes expectation and returns predicate function which will be checking if new passed variable equal to expectation.

public

toSetoid(eqFn: Function): Setoid

Creates Setoid from given function.

public

trim(stringSource: String): *

Removes leading and trailing whitespace or specified characters from string.

public

typeCheck(clazz: T, actualType: any): any

Checks if type is correct and throws error in negative case.

public

Create funtion that makes same as passed function but newly created function will use only first argument.

public

uniq(source: Array<any>): Array<any>

returns new array only with uniq elements

public

Will make a capital first letter.

public

Is opposite to invoke function.

public

without(source: Array<T>, matchItem: T): Array<T>

Returns an array without match item.

public

words(strValue: String): Array<String>

Splits string into an array of its words.

public

wrap(fn: Function, args: ...T): void

Will take function, arguments and return function that will invoke given function with given arguments.

public

zip(source: ...Array<T>): Array<D>

Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.

public

Will zip multiple Arrays using projection function.

Static Public

public Applicative(f: any): Appicative source

import {Applicative} from 'js-helpers/src/Fantasy-Land/index.js'

Appicative implementation.

Params:

NameTypeAttributeDescription
f any

Appicative value.

Return:

Appicative

Appicative with current value.

Example:


    
let sideEffectVar = 0
  , curry2Add = x => y => x + y
  , applicative = Applicative.of(curry2Add)
     .tap(() => sideEffectVar = 3);

 sideEffectVar; // 3
 isFunction(applicative.get()); // true
 isFunction(applicative.fold(identity)); // true
 isFunction(applicative.ap(2).get()); // true
 applicative.ap(2).ap(3).get(); // 5
 applicative.ap(2).apGet(3); // 5
 applicative.ap(2).ap(3).toString(); // 'Apply(5)'
 applicative.ap(2).ap(3).inspect(); // 'Apply(5)');
 applicative
   .ap(2)
   .ap(3)
   .map(n => `Number is ${n}`)
   .get(); // 'Number is 5'

public Apply(f: any): Apply source

Apply implementation.

Params:

NameTypeAttributeDescription
f any

Apply value.

Return:

Apply

Apply with current value.

Example:

let sideEffectVar = 0
  , curry2Add = x => y => x + y
  , apply = Apply(curry2Add)
     .tap(() => sideEffectVar = 3);

 sideEffectVar; // 3
 isFunction(apply.get()); // true
 isFunction(apply.fold(identity)); // true
 isFunction(apply.ap(2).get()); // true
 apply.ap(2).ap(3).get(); // 5
 apply.ap(2).apGet(3); // 5
 apply.ap(2).ap(3).toString(); // 'Apply(5)'
 apply.ap(2).ap(3).inspect(); // 'Apply(5)');
 apply
   .ap(2)
   .ap(3)
   .map(n => `Number is ${n}`)
   .get(); // 'Number is 5'

public Either() source

Either implementation.

Example:

Either.right(3); // Either.Right(3)
Either.left(3);  // Either.Left(3)
Either.of(3); // Either.Right(3)
Either.fromNullable(null); // Either.Left(null)
Either.fromNullable(3); // Either.Right(3)

public Functor(x: any): Functor source

import {Functor} from 'js-helpers/src/Fantasy-Land/index.js'

Functor implementation.

Params:

NameTypeAttributeDescription
x any

Functor value.

Return:

Functor

Functor with current value.

Example:

let sideEffectVar = 0
  , functor = Functor('  64  ')
     .map(s => s.trim())
     .map(r => parseInt(r))
     .tap(v => sideEffectVar = 3)
     .map(i => i + 1)
     .map(i => String.fromCharCode(i));

 functor.fold(identity); // 'A'
 functor.get(); // 'A'
 sideEffectVar; // 3
 functor.toString(); // 'Functor(A)'
 functor.inspect(); // 'Functor(A)'

public Just(value: any): Just source

Just Implementation.

Params:

NameTypeAttributeDescription
value any

Just with given value.

Return:

Just

Newly created Just with given value.

Example:

Maybe.just(3); // Maybe.Just(3)

public LazyFunctor(x: any): LazyFunctor source

import {LazyFunctor} from 'js-helpers/src/Fantasy-Land/index.js'

LazyFunctor implementation.

Params:

NameTypeAttributeDescription
x any

LazyFunctor value.

Return:

LazyFunctor

LazyFunctor with current value.

Example:

let wasInvoked = false;
let multiplyWithInvokeUpdate = x => {
   wasInvoked = true;
   return x * x;
}

isNotNumber(
   LazyFunctor(() => 7)
      .lazyMap(multiplyWithInvokeUpdate)
      .lazyMap(x => x  * 100)
);

wasInvoked; // false

isNumber(
   LazyFunctor(() => 7)
      .lazyMap(multiplyWithInvokeUpdate)
      .lazyMap(x => x  * 100)
      .lazyFold(identity)
);

wasInvoked; // true

 LazyFunctor(() => 7)
   .lazyMap(multiplyWithInvokeUpdate)
   .lazyMap(x => x  * 10)
   .lazyFold(identity); // 490

public Left(value: any): Left source

Left Implementation.

Params:

NameTypeAttributeDescription
value any

Left with given value.

Return:

Left

Newly created Left with given value.

Example:

Either.left(3); // Either.Left(3)

public Maybe() source

Maybe implementation.

Example:

Maybe.just(3); // Maybe.Just(3)
Maybe.nothing(3);  // Maybe.Nothing()
Maybe.of(3); // Maybe.Just(3)
Maybe.fromNullable(null); // Maybe.Nothing()
Maybe.fromNullable(3); // Maybe.Just(3)

public Monad(x: any): Monad source

Monad implementation.

Params:

NameTypeAttributeDescription
x any

Monad value.

Return:

Monad

Monad with current value.

Example:

let sideEffectVar = 0
  , curry2Add = x => y => x + y
  , monad = Monad.of(curry2Add)
     .tap(() => sideEffectVar = 3);

sideEffectVar; // 3
isFunction(monad.get()); // true
isFunction(monad.fold(identity)); // true
isFunction(monad.ap(2).get()); // true
monad.ap(2).ap(3).get(); // 5
monad.ap(2).apGet(3); // 5
monad.ap(2).ap(3).toString() // 'Monad(5)'
monad.ap(2).ap(3).inspect(); // 'Monad(5)'

monad
  .ap(2)
  .ap(3)
  .map(n => `Number is ${n}`)
  .get(); // 'Number is 5'

monad
  .ap(2)
  .ap(3)
  .chain(v => Monad.of(v * v))
  .get(); // 25

monad
  .ap(2)
  .ap(3)
  .map(v => Monad.of(v * v))
  .join()
  .get(); // 25

monad
  .ap(3)
  .apChain(Monad.of(2))
  .get(); // 5

public Nothing(value: any): Nothing source

import {Nothing} from 'js-helpers/src/Fantasy-Land/maybe.js'

Creates new Nothing.

Params:

NameTypeAttributeDescription
value any

Nothing value.

Return:

Nothing

Newly created Nothing.

Example:

Maybe.nothing(); // Maybe.Nothing()

public Right(value: any): Right source

Right Implementation.

Params:

NameTypeAttributeDescription
value any

Right with given value.

Return:

Right

Newly created Right with given value.

Example:

Either.right(3); // Either.Right(3)

public add(augend: number, addendList: ...number): number source

import {add} from 'js-helpers/src/Math/index.js'

Adds numbers.

Params:

NameTypeAttributeDescription
augend number

The first number in an addition.

addendList ...number

The addend list.

Return:

number

Returns the total.

Example:

add(1, 2, 3, 1); // 7
add(1, 3); // 4

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

import {after} from 'js-helpers/src/Function/index.js'

Creates a function that invokes fn once it's called n or more times.

Params:

NameTypeAttributeDescription
count number

The number of calls before func is invoked.

fn Function

The function to restrict.

Return:

Function

Function that invokes fn once it's called n or more times.

public alt(fn1: Function, fn2: Function): Function source

This combinator takes two functions and returns the result of the first one if the value is defined (not false, null, or undefined); otherwise, it returns the result of the second function.

Params:

NameTypeAttributeDescription
fn1 Function

First result function.

fn2 Function

Second result function.

Return:

Function

Returns the result of the first one if the value is defined (not false, null, or undefined); otherwise, it returns the result of the second function

Example:

const calc = alt(identity, x => x + 1);
calc(0); // 1
calc(2); // 2

public always(value: T): Function source

Creates function which will always return passed argument. K - combinator implementation.

Params:

NameTypeAttributeDescription
value T

Argument that should returned back from function which was returned.

Return:

Function

Returns function which will always return first passed argument.

Example:

always(2)(); // 2

public and(predicates: ...Function): Function source

Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return true.

Params:

NameTypeAttributeDescription
predicates ...Function

List of predicates.

Return:

Function

Predicate function.

public any(source: Array<T>, fn: Function): boolean source

import {any} from 'js-helpers/src/Array/index.js'

Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. Is analog some(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

The collection to iterate over.

fn Function

The collection to iterate over.

Return:

boolean

Returns true if any element passes the predicate check, else false.

public assoc(propName: string, valueToBeSet: T, source: object): object source

import {assoc} from 'js-helpers/src/Lens/index.js'

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

Params:

NameTypeAttributeDescription
propName string

Property name

valueToBeSet T

New value for property

source object

Object where should be changed property value.

Return:

object

Clone of source with changed value.

public assocPath(path: Array<String|Number>, valueToBeSet: any, source: Object | Array): Object | Array source

import {assocPath} from 'js-helpers/src/Lens/index.js'

Updates Array or Object by given path with given value.

Params:

NameTypeAttributeDescription
path Array<String|Number>

Path to property which should be changed.

valueToBeSet any

Value which should be set by path.

source Object | Array

Source where should be changed property.

Return:

Object | Array

Resurns clone of object or array with applied changes.

public buildResource(src: String, args: Array<T>): String source

import {buildResource} from 'js-helpers/src/String/index.js'

Works similarly to templates. Sequentially replaces all placeholders ({0}, {1}, {2}...).

Params:

NameTypeAttributeDescription
src String
  • optional
  • default: ''

Source for replacements.

args Array<T>

Values for replacements.

Return:

String

New String with all replacements.

public camelCase(str: String): String source

import {camelCase} from 'js-helpers/src/String/index.js'

Converts string to camel case.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

Returns the camel cased string.

public castArray(valueToCast: ...T): Array<T> source

import {castArray} from 'js-helpers/src/Array/index.js'

Casts values as an array if it's not one.

Params:

NameTypeAttributeDescription
valueToCast ...T

All values will be included in array that will be returned back.

Return:

Array<T>

Return array that will include all arguments.

public changeOrder(source: Array<T>, order: Array<number>): Array<T> source

import {changeOrder} from 'js-helpers/src/Array/index.js'

Returns array with changed order.

Params:

NameTypeAttributeDescription
source Array<T>

Array that should change the order.

order Array<number>

Order Array.

Return:

Array<T>

Array with changed order.

public cloneArray(source: Array<T>): Array<T> source

import {cloneArray} from 'js-helpers/src/Array/index.js'

Will create clone of given array.

Params:

NameTypeAttributeDescription
source Array<T>

Array that should be cloned.

Return:

Array<T>

Cloned array.

Example:

cloneArray([1,2,3]); // [1,2,3]

cloneArray([{name: 'John'}, {name: 'Liza'}]); // [{name: 'John'}, {name: 'Liza'}]

public cloneObject(objectToClone: object): object source

import {cloneObject} from 'js-helpers/src/Object/index.js'

Will create object clone.

Params:

NameTypeAttributeDescription
objectToClone object

Object that should be cloned.

Return:

object

Clone of passed object.

public compact(source: Array<T>): Array<T> source

import {compact} from 'js-helpers/src/Array/index.js'

Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.

Params:

NameTypeAttributeDescription
source Array<T>

Array to compact. truthly values

Return:

Array<T>

Returns the new array of filtered values.

Example:

let dataArray = [0, -3, 'Hello', '', false, true, {}, [], null, undefined];

compact(dataArray, 3); // [-3, 'Hello', true, {}, []]

public compareDecimalNumbers(number1: number, number2: number): boolean source

import {compareDecimalNumbers} from 'js-helpers/src/Math/index.js'

Compares two small decimal values.

Params:

NameTypeAttributeDescription
number1 number

First number to compare.

number2 number

Second number to compare.

Return:

boolean

true if two number are equal.

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

import {compose} from 'js-helpers/src/Function/index.js'

This method is like pipe except that it creates a function that invokes the provided functions from right to left.

Params:

NameTypeAttributeDescription
fns ...Function

Function that should be invoked with given arguments.

Return:

Function

Returns the new function.

public conformsTo(object: object, predicateSetModel: object): boolean source

import {conformsTo} from 'js-helpers/src/Object/index.js'

Checks object properties with set of predicates.

Params:

NameTypeAttributeDescription
object object

Object which should be chcked.

predicateSetModel object

Predicate set model.

Return:

boolean

Returns true if all predicates returns true.

Example:

let given = { b: 1, a: 'Hello' };

conformsTo(given, { b: n => n === 1, a: n => n === 'Hello' }); // true

conformsTo(given, { b: n => n === 1, a: n => n === 'NOT-Hello' }); // false

public curry(fn: Function): Function | T source

import {curry} from 'js-helpers/src/Function/index.js'

Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on. The arity of func may be specified if func.length is not sufficient.

Params:

NameTypeAttributeDescription
fn Function

Function for Curring.

Return:

Function | T

Function that should collect arguments.

public deepClone(objectToDeepClone: object): object source

import {deepClone} from 'js-helpers/src/Object/index.js'

Will create an object deep clone.

Params:

NameTypeAttributeDescription
objectToDeepClone object

Object that should be deep cloned.

Return:

object

Clone of passed object.

public deepEquals(first: any, second: any): boolean source

import {deepEquals} from 'js-helpers/src/Object/index.js'

Compares two elements.

Params:

NameTypeAttributeDescription
first any

First element for comparation.

second any

Second element for comparation.

Return:

boolean

Returns true if two elements are the same.

Example:

deepEquals(
  [
    { id: 1, firstName: 'Jon', lastName: 'Snow', age: 14, location: 'Winterfell' },
    { id: 2, firstName: 'Eddard', lastName: 'Stark', age: 35, location: 'Winterfell' },
    { id: 3, firstName: 'Catelyn', lastName: 'Stark', age: 33, location: 'Winterfell' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', age: 40, location: 'Dreadfort' },
    { id: 5, firstName: 'Ramsay', lastName: 'Snow', age: 15, location: 'Dreadfort' }
  ],
  [
    { id: 1, firstName: 'Jon', lastName: 'Snow', age: 14, location: 'Winterfell' },
    { id: 2, firstName: 'Eddard', lastName: 'Stark', age: 35, location: 'Winterfell' },
    { id: 3, firstName: 'Catelyn', lastName: 'Stark', age: 33, location: 'Winterfell' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', age: 40, location: 'Dreadfort' },
    { id: 5, firstName: 'Ramsay', lastName: 'Snow', age: 15, location: 'Dreadfort' }
  ]
); // true

deepEquals(
  [
    { id: 1, firstName: 'Jon', lastName: 'Snow', age: 14, location: 'Winterfell' },
    { id: 2, firstName: 'Eddard', lastName: 'Stark', age: 35, location: 'Winterfell' },
    { id: 3, firstName: 'Catelyn', lastName: 'Stark', age: 33, location: 'Winterfell' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', age: 40, location: 'Dreadfort' },
    { id: 5, firstName: 'Ramsay', lastName: 'Snow', age: 15, location: 'Dreadfort' }
  ],
  [
    { id: 1, firstName: 'Jon', lastName: 'Snow', age: 14, location: 'Winterfell' },
    { id: 2, firstName: 'Eddard', lastName: 'Stark', age: 35, location: 'Winterfell' },
    { id: 3, firstName: 'Catelyn', lastName: 'Stark', age: 33, location: 'Winterfell' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', age: 40, location: 'Dreadfort' },
    { id: 5, firstName: 'Not the same!', lastName: 'Snow', age: 15, location: 'Dreadfort' }
  ]
); // false

public deepFreeze(obj: object): object source

import {deepFreeze} from 'js-helpers/src/Object/index.js'

Will deep frezee all properties.

Params:

NameTypeAttributeDescription
obj object

Object that should be fully freezed.

Return:

object

Freezed object.

public divide(dividend: number, divisorList: number): number source

import {divide} from 'js-helpers/src/Math/index.js'

Divide numbers.

Params:

NameTypeAttributeDescription
dividend number

The first number in a division.

divisorList number

The divisor list.

Return:

number

Returns the quotient.

public duplication(fn: Function): Function source

Takes function and invokes it with passed argument two times.

Params:

NameTypeAttributeDescription
fn Function

Function which will be invoked two times with the same argument.

Return:

Function

Function which expects for argument.

Example:

const add = x => y => x + y;

duplication(add)(7); // 14

public eq(elem1: T): Function source

Checks if two elements are the same

Params:

NameTypeAttributeDescription
elem1 T

Element which will be compared with other.

Return:

Function

Function which take second element for comparation.

Example:

eq(1)(1) // true
eq(1)(2) // false

eq('hello')('hello') // true
eq('hello')('hello2') // false

eq({ greeting: 'hello' })({ greeting: 'hello' }) // false

public equalsIgnoreCase(str1: String, str2: String): boolean source

import {equalsIgnoreCase} from 'js-helpers/src/String/index.js'

Will compare two strings with ignore case.

Params:

NameTypeAttributeDescription
str1 String

First string to compare.

str2 String

Second string to compare.

Return:

boolean

Result of comparison.

public every(source: Array<T>, fn: Function): boolean source

import {every} from 'js-helpers/src/Array/index.js'

Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsey.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array to check.

fn Function

Predicate function.

Return:

boolean

true if all items will be returned by predicate function.

public fill(source: T, number: number): Array<T> source

import {fill} from 'js-helpers/src/Array/index.js'

Will fill array by given value.

Params:

NameTypeAttributeDescription
source T

Fill value.

number number

Number of filled elements in Array.

Return:

Array<T>

Array with n elements filled by T.

public fillLeft(value: T, number: number, source: Array<T|D>): Array<T|D> source

import {fillLeft} from 'js-helpers/src/Array/index.js'

Will fill array in the begining for n elements and add given array in the end.

Params:

NameTypeAttributeDescription
value T

Fill Value.

number number

Number of elements that should be filled in the begining of returned an array.

source Array<T|D>
  • optional
  • default: []

Fill Value.

Return:

Array<T|D>

Returns combination from given and filled array.

public fillRight(value: T, number: number, source: Array<T|D>): Array<T|D> source

import {fillRight} from 'js-helpers/src/Array/index.js'

Will fill array in the end for n elements and add given array from begining.

Params:

NameTypeAttributeDescription
value T

Fill Value.

number number

Number of elements that should be filled in the end of returned an array.

source Array<T|D>
  • optional
  • default: []

Fill Value.

Return:

Array<T|D>

Returns combination from given and filled array.

public filter(source: Array<T>, fn: Function): Array<T> source

import {filter} from 'js-helpers/src/Array/index.js'

Will filter an array.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array that should use filtered function.

fn Function

Predicate function.

Return:

Array<T>

Filtered Array.

public find(source: Array<T>, fn: Function): T source

import {find} from 'js-helpers/src/Array/index.js'

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

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array where check.

fn Function

Predicate function.

Return:

T

Item if it was found by function predicate.

public first(source: Array<T>): T source

import {first} from 'js-helpers/src/Array/index.js'

Will return first element from array. Is analog of head(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array where to check for first element.

Return:

T

Returns first element from Array.

public flatten(source: Array<T>): * source

import {flatten} from 'js-helpers/src/Array/index.js'

Flattens array.

Params:

NameTypeAttributeDescription
source Array<T>

Array that should be flatten.

Return:

*

Returns the new flattened array.

public flip(fn: Function): Function source

Takes function and changes argument order. C - combinator implementation.

Params:

NameTypeAttributeDescription
fn Function

Function which will be invoked with fliped arguments.

Return:

Function

Function which expects to get first argument, which will be used as a second argument.

Example:

const concat2Words = w1 => w2 => `${w1} ${w2}`;

flip(concat2Words)('world')('hello'); // 'hello world'

public fork(join: Function, fn1: Function, fn2: Function): Function source

The fork combinator is useful in cases where you need to process a single resource in two different ways and then combine the results. This combinator takes three functions: a join function and two terminal functions that process the provided input. The result of each forked function is ultimately passed in to a join function of two arguments.

Params:

NameTypeAttributeDescription
join Function

Argument that should returned back from function which was returned.

fn1 Function

First terminal function.

fn2 Function

Second terminal function.

Return:

Function

Returns function which expects to get argument that should be passed into terminal functions.

Example:

const calc = fork(multiply, x => x + x, identity);
calc(2); // 8

public getFirstLowerLetter(source: String): String source

import {getFirstLowerLetter} from 'js-helpers/src/String/index.js'

Will return first lower letter from source.

Params:

NameTypeAttributeDescription
source String

Source for searching.

Return:

String

First lower letter.

public getFirstUpperLetter(source: String): String source

import {getFirstUpperLetter} from 'js-helpers/src/String/index.js'

Will return first upper letter from source.

Params:

NameTypeAttributeDescription
source String

Source for searching.

Return:

String

First capital letter.

public getLastLowerLetter(source: String): String source

import {getLastLowerLetter} from 'js-helpers/src/String/index.js'

Will return last lower letter from source.

Params:

NameTypeAttributeDescription
source String

Source for searching.

Return:

String

Last lower letter.

public getLastUpperLetter(source: String): String source

import {getLastUpperLetter} from 'js-helpers/src/String/index.js'

Will return last upper letter from source.

Params:

NameTypeAttributeDescription
source String

Source for searching.

Return:

String

Last capital letter.

public getRandomInt(max: number): number source

import {getRandomInt} from 'js-helpers/src/Math/index.js'

Will generate random integer.

Params:

NameTypeAttributeDescription
max number

Max number that can be returned.

Return:

number

Random integer.

public getRandomIntFromTo(min: number, max: number): number source

import {getRandomIntFromTo} from 'js-helpers/src/Math/index.js'

Will generate random integer in passed range.

Params:

NameTypeAttributeDescription
min number

Min number that can be returned.

max number

Max number that can be returned.

Return:

number

Random integer.

public getType(valToCheck: T): string source

import {getType} from 'js-helpers/src/Type/index.js'

Checks type of passed value.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

string

Returns object type.

public getTypeByClass(clazz: T): string source

import {getTypeByClass} from 'js-helpers/src/Type/index.js'

Returns class name.

Params:

NameTypeAttributeDescription
clazz T

Source which should be a class.

Return:

string

Name of class.

Example:

getTypeByClass(String); // string
getTypeByClass(RegExp); // regexp
getTypeByClass(Object); // object
getTypeByClass(Function); // function
getTypeByClass(Date); // date
getTypeByClass(Boolean); // boolean
getTypeByClass(Number); // number
getTypeByClass(Array); // array
getTypeByClass(Symbol); // symbol

class Person {}
getTypeByClass(Person); // person

public getWithCtx(obj: object): Function source

import {getWithCtx} from 'js-helpers/src/Object/index.js'

Curry version of get function that expects in future to get property list.

Params:

NameTypeAttributeDescription
obj object

Context object.

Return:

Function

Curry functions that expects to get property list.

public getWithProps(props: ...string): Function source

import {getWithProps} from 'js-helpers/src/Object/index.js'

Curry version of get function that expects in future to get context.

Params:

NameTypeAttributeDescription
props ...string

Property chain.

Return:

Function

Curry functions that expects to get context object.

public groupBy(args: ...any): object source

import {groupBy} from 'js-helpers/src/Array/index.js'

Will group objects in array by given property, function or path.

Params:

NameTypeAttributeDescription
args ...any

grouping arguments.

Return:

object

Grouped object.

Example:

let actualObjArr = [
  { name: 'John', age: 21 },
  { name: 'Liza', age: 23 },
  { name: 'John', age: 23 }
];

groupBy(['one', 'two', 'three'], 'length');
// { '3': ['one', 'two'], '5': ['three'] });

groupBy(actualObjArr, 'name');
// {
//   John: [ { name: 'John', age: 21 }, { name: 'John', age: 23 } ],
//   Liza: [ { name: 'Liza', age: 23 } ]
// }

groupBy(actualObjArr, 'age');
// {
//   '21': [ { name: 'John', age: 21 } ],
//   '23': [ { name: 'Liza', age: 23 }, { name: 'John', age: 23 } ]
// };

groupBy([6.1, 4.2, 6.3], Math.floor)
// { '4': [4.2], '6': [6.1, 6.3] }

groupBy([
  { name: 'John', age: 21 },
  { name: 'Liza', age: 23 },
  { name: 'John', age: 23 }
], item => `name_${item.name}`);
// {
//   name_John: [ { name: 'John', age: 21 }, { name: 'John', age: 23 } ],
//   name_Liza: [ { name: 'Liza', age: 23 } ]
// }

groupBy([
  { name: { first: 'John', last: 'aaa' }, age: 21 },
  { name: { first: 'Liza', last: 'bbb'}, age: 23 },
  { name: { first: 'John', last: 'ccc'}, age: 23 } ], ['name', 'first']);
// {
//   John: [
//     { name: { first: 'John', last: 'aaa' }, age:21 },
//     { name: { first: 'John', last: 'ccc' }, age:23 }
//   ],
//   Liza: [
//     { name :{ first: 'Liza', last: 'bbb' }, age: 23 }
//   ]
// }

public groupByFn(source: Array<object>, groupFn: Function): object source

import {groupByFn} from 'js-helpers/src/Array/index.js'

Will group objects in array by function.

Params:

NameTypeAttributeDescription
source Array<object>

Source which should be used for grouping.

groupFn Function

Function which will define names for groups.

Return:

object

Grouped object.

Example:

groupByFn([6.1, 4.2, 6.3], Math.floor)
// { '4': [4.2], '6': [6.1, 6.3] }

groupByFn([
  { name: 'John', age: 21 },
  { name: 'Liza', age: 23 },
  { name: 'John', age: 23 }
], item => `name_${item.name}`);
// {
//   name_John: [ { name: 'John', age: 21 }, { name: 'John', age: 23 } ],
//   name_Liza: [ { name: 'Liza', age: 23 } ]
// }

public groupByPath(source: Array<object>, groupPath: *): object source

import {groupByPath} from 'js-helpers/src/Array/index.js'

Will group objects in array by object path.

Params:

NameTypeAttributeDescription
source Array<object>

Source which should be used for grouping.

groupPath *

Path which should be used as name for groups.

Return:

object

Grouped object.

Example:

groupByPath([
  { name: { first: 'John', last: 'aaa' }, age: 21 },
  { name: { first: 'Liza', last: 'bbb'}, age: 23 },
  { name: { first: 'John', last: 'ccc'}, age: 23 } ], ['name', 'first']);

// {
//   John: [
//     { name: { first: 'John', last: 'aaa' }, age: 21 },
//     { name: { first: 'John', last: 'ccc' }, age: 23 }
//   ],
//   Liza: [
//     { name :{ first: 'Liza', last: 'bbb' }, age: 23 }
//   ]
// }

public groupByProp(source: Array<object>, groupVal: string): object source

import {groupByProp} from 'js-helpers/src/Array/index.js'

Will group objects in array by property.

Params:

NameTypeAttributeDescription
source Array<object>

Source which should be used for grouping.

groupVal string

Name which should be used for grouping.

Return:

object

Grouped object.

Example:

let actualObjArr = [
  { name: 'John', age: 21 },
  { name: 'Liza', age: 23 },
  { name: 'John', age: 23 }
];

groupBy(['one', 'two', 'three'], 'length');
// { '3': ['one', 'two'], '5': ['three'] }

groupBy(actualObjArr, 'name');
// {
//   John: [ { name: 'John', age: 21 }, { name: 'John', age: 23 } ],
//   Liza: [ { name: 'Liza', age: 23 } ]
// }

groupBy(actualObjArr, 'age');
// {
//   '21': [ { name: 'John', age: 21 } ],
//   '23': [ { name: 'Liza', age: 23 }, { name: 'John', age: 23 } ]
// };

public gt(number1: number): Function source

Saves number1 and returns predicate function that will be checking if number2 is greater then number1.

Params:

NameTypeAttributeDescription
number1 number

First number.

Return:

Function

Predicate Function.

public gte(number1: number): Function source

Saves number1 and returns predicate function that will be checking if number2 is greater then or equal to number1.

Params:

NameTypeAttributeDescription
number1 number

First number.

Return:

Function

Predicate Function.

public head(source: Array<T>): T source

import {head} from 'js-helpers/src/Array/index.js'

Will return first element from array. Is analog of first(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array where to check for first element.

Return:

T

Returns first element from Array.

public identity(value: T): T source

The identity combinator is a function that returns the same value it was provided as an argument. I - combinator implementation.

Params:

NameTypeAttributeDescription
value T

Argument that should returned back.

Return:

T

Returns same value which was passed.

Example:

identity(2); // 2

public includes(source: String, includement: String | number): boolean source

import {includes} from 'js-helpers/src/String/index.js'

Work similary to indexOf method but returns boolean.

Params:

NameTypeAttributeDescription
source String

String source.

includement String | number

Searching value.

Return:

boolean

Result of searching as boolean.

public invoke(fns: ...Function): object source

import {invoke} from 'js-helpers/src/Context/index.js'

Will invoke list of functions with given context.

Params:

NameTypeAttributeDescription
fns ...Function

List of functions that should be invoked with given context.

Return:

object

object that will have a using(*) function. In using function should be passed context object.

public invokeWithCtx(ctx: object, fns: ...Function): void source

import {invokeWithCtx} from 'js-helpers/src/Context/index.js'

Will invoke list of functions with given context in single invokation.

Params:

NameTypeAttributeDescription
ctx object

Contecxt for all functions that should be invoked.

fns ...Function

List of functions that should be invoked with given context.

Return:

void

public isArray(valToCheck: T): boolean source

import {isArray} from 'js-helpers/src/Type/index.js'

Checks if passed value is Array.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is Array.

public isBoolean(valToCheck: T): boolean source

import {isBoolean} from 'js-helpers/src/Type/index.js'

Checks if passed value is boolean.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is boolean.

public isDate(valToCheck: T): boolean source

import {isDate} from 'js-helpers/src/Type/index.js'

Checks if passed value is Date.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is Date.

public isFunction(valToCheck: T): boolean source

import {isFunction} from 'js-helpers/src/Type/index.js'

Checks if passed value is Function.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is Function.

public isNaN(valToCheck: T): boolean source

import {isNaN} from 'js-helpers/src/Type/index.js'

Checks if passed value is NaN.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is NaN.

public isNegativeZero(numberToCheck: number): boolean source

import {isNegativeZero} from 'js-helpers/src/Type/index.js'

Checks if passed value is negative zero.

Params:

NameTypeAttributeDescription
numberToCheck number

Value to Check.

Return:

boolean

Returns true is passed value is negative zero.

public isNotArray(valToCheck: T): boolean source

import {isNotArray} from 'js-helpers/src/Type/index.js'

Checks if passed value is not Array.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not Array.

public isNotBoolean(valToCheck: T): boolean source

import {isNotBoolean} from 'js-helpers/src/Type/index.js'

Checks if passed value is not boolean.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not boolean.

public isNotDate(valToCheck: T): boolean source

import {isNotDate} from 'js-helpers/src/Type/index.js'

Checks if passed value is not Date.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not Date.

public isNotFunction(valToCheck: T): boolean source

import {isNotFunction} from 'js-helpers/src/Type/index.js'

Checks if passed value is not Function.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not Function.

public isNotNaN(valToCheck: T): boolean source

import {isNotNaN} from 'js-helpers/src/Type/index.js'

Checks if passed value is not NaN.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not NaN.

public isNotNegativeZero(numberToCheck: number): boolean source

import {isNotNegativeZero} from 'js-helpers/src/Type/index.js'

Checks if passed value is not negative zero.

Params:

NameTypeAttributeDescription
numberToCheck number

Value to Check.

Return:

boolean

Returns true is passed value is not negative zero.

public isNotNull(valToCheck: T): boolean source

import {isNotNull} from 'js-helpers/src/Type/index.js'

Checks if passed value is not null.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not null.

public isNotNumber(valToCheck: T): boolean source

import {isNotNumber} from 'js-helpers/src/Type/index.js'

Checks if passed value is not number.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not number.

public isNotObject(valToCheck: T): boolean source

import {isNotObject} from 'js-helpers/src/Type/index.js'

Checks if passed value is not Object.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not Object.

public isNotPrimitive(value: T): boolean source

import {isNotPrimitive} from 'js-helpers/src/Type/index.js'

Determine whether a value is not a primitive type.

Params:

NameTypeAttributeDescription
value T

Value to Check.

Return:

boolean

Returns true is passed value is not primitive type.

public isNotRegExp(valToCheck: T): boolean source

import {isNotRegExp} from 'js-helpers/src/Type/index.js'

Checks if passed value is not RegExp.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not RegExp.

public isNotString(valToCheck: T): boolean source

import {isNotString} from 'js-helpers/src/Type/index.js'

Checks if passed value is not string.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not string.

public isNotSymbol(valToCheck: T): boolean source

import {isNotSymbol} from 'js-helpers/src/Type/index.js'

Checks if passed value is not Symbol.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not Symbol.

public isNotUndefined(valToCheck: T): boolean source

import {isNotUndefined} from 'js-helpers/src/Type/index.js'

Checks if passed value is not undefined.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is not undefined.

public isNull(valToCheck: T): boolean source

import {isNull} from 'js-helpers/src/Type/index.js'

Checks if passed value is null.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is null.

public isNumber(valToCheck: T): boolean source

import {isNumber} from 'js-helpers/src/Type/index.js'

Checks if passed value is number.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is number.

public isObject(valToCheck: T): boolean source

import {isObject} from 'js-helpers/src/Type/index.js'

Checks if passed value is Object.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is Object.

public isPrimitive(value: T): boolean source

import {isPrimitive} from 'js-helpers/src/Type/index.js'

Determine whether a value is a primitive type.

Params:

NameTypeAttributeDescription
value T

Value to Check.

Return:

boolean

Returns true is passed value is primitive type.

public isRegExp(valToCheck: T): boolean source

import {isRegExp} from 'js-helpers/src/Type/index.js'

Checks if passed value is RegExp.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is RegExp.

public isSetoid(obj: object): boolean source

import {isSetoid} from 'js-helpers/src/Fantasy-Land/setoid.js'

Checks if passed object implements setoid.

Params:

NameTypeAttributeDescription
obj object

Object to check.

Return:

boolean

true in case is passed object implements Setoid.

Example:

const comparePeopleFn = (p, p2) => p.id === p2.id;
const PersonSetoid = toSetoid(comparePeopleFn);
const person1 = { id: 1, name: 'Oleh' }
const person2 = {
   id: 2,
   name: 'Oleh',
   equals: p => true
};

isSetoid(PersonSetoid(person1)); // true
isSetoid(person1); // false
isSetoid(person2); // false

public isString(valToCheck: T): boolean source

import {isString} from 'js-helpers/src/Type/index.js'

Checks if passed value is string.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is string.

public isSymbol(valToCheck: T): boolean source

import {isSymbol} from 'js-helpers/src/Type/index.js'

Checks if passed value is Symbol.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is Symbol.

public isUndefined(valToCheck: T): boolean source

import {isUndefined} from 'js-helpers/src/Type/index.js'

Checks if passed value is undefined.

Params:

NameTypeAttributeDescription
valToCheck T

Value to Check.

Return:

boolean

Returns true is passed value is undefined.

public kebabCase(str: String): String source

import {kebabCase} from 'js-helpers/src/String/index.js'

Converts string to kebab case.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

Returns the kebab cased string.

public last(source: Array<T>): T source

import {last} from 'js-helpers/src/Array/index.js'

Will return last element from array. Is analog of tail(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array where to check for last element.

Return:

T

Returns last element from Array.

public lensIndex(index: number, source: Array<T>): T source

import {lensIndex} from 'js-helpers/src/Lens/index.js'

Returns value taken by index from source.

Params:

NameTypeAttributeDescription
index number

Index which should be taken within source.

source Array<T>

Array is source from where should be taken value by index.

Return:

T

value by index.

public lensProp(propName: string): Function source

import {lensProp} from 'js-helpers/src/Lens/index.js'

Returns a lens whose focus is the specified property.

Params:

NameTypeAttributeDescription
propName string

Property name which should be taken within source.

Return:

Function

function which expects object to be source.

public lt(number1: number): Function source

Saves number1 and returns predicate function that will be checking if number2 is less then number1.

Params:

NameTypeAttributeDescription
number1 number

First number.

Return:

Function

Predicate Function.

public lte(number1: number): Function source

Saves number1 and returns predicate function that will be checking if number2 is less then or equal to number1.

Params:

NameTypeAttributeDescription
number1 number

First number.

Return:

Function

Predicate Function.

public map(source: Array<T>, fn: Function): Array<D> source

import {map} from 'js-helpers/src/Array/index.js'

Will project array object.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional

Array that should use projection function.

fn Function

Projection function.

Return:

Array<D>

Projection Array.

public memoize(fn: Function): Function source

import {memoize} from 'js-helpers/src/Function/index.js'

Creates a function that memoizes the result of fn. If resolver is provided, it determines the cache key for storing the result based on the arguments provided to the memoized function. By default, the first argument provided to the memoized function is used as the map cache key.

Params:

NameTypeAttributeDescription
fn Function

Function to memoize.

Return:

Function

Memoized function.

public multiply(multiplier: number, multiplicandList: number): number source

import {multiply} from 'js-helpers/src/Math/index.js'

Multiply numbers.

Params:

NameTypeAttributeDescription
multiplier number

The first number in a multiplication.

multiplicandList number

The multiplicand list.

Return:

number

Returns the product.

public not(predicates: ...Function): Function source

Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return false.

Params:

NameTypeAttributeDescription
predicates ...Function

List of predicates.

Return:

Function

Predicate function.

public notEq(elem1: T): Function source

import {notEq} from 'js-helpers/src/Predicate/index.js'

Checks if two elements are not the same.

Params:

NameTypeAttributeDescription
elem1 T

Element which will be compared with other.

Return:

Function

Function which take second element for comparation.

Example:

eq(1)(1) // false
eq(1)(2) // true

eq('hello')('hello') // false
eq('hello')('hello2') // true

eq({ greeting: 'hello' })({ greeting: 'hello' }) // true

public notOr(predicates: ...Function): Function source

Takes list of predicates and returns a one predicate, current predicate will return true only in the case if none of passed prdicates returns true.

Params:

NameTypeAttributeDescription
predicates ...Function

List of predicates.

Return:

Function

Predicate function.

public notToBe(expectation: T): Function source

import {notToBe} from 'js-helpers/src/Type/index.js'

Takes expectation and returns predicate function which will be checking if new passed variable not equal to expectation.

Params:

NameTypeAttributeDescription
expectation T

Not expected value.

Return:

Function

Returns predicate function.

public nth(source: Array<T>, index: number): T source

import {nth} from 'js-helpers/src/Array/index.js'

Will return element from array by given index.

Params:

NameTypeAttributeDescription
source Array<T>

Source where should be taken element by given index.

index number

Index of element which should be returned.

Return:

T

Returns nth element from Array.

Example:

nth([51,35,23], 1) // 35

public numAndStrComparator(first: string | number, second: string | number, prop: string): number source

import {numAndStrComparator} from 'js-helpers/src/Array/index.js'

number or string comparator. Can be used in sort function.

Params:

NameTypeAttributeDescription
first string | number

First argumnet for comparation.

second string | number

Second argumnet for comparation.

prop string

Compare property.

Return:

number

Comparation result.

Example:

let given = [
  { 'name': 'fred',   'age': 48 },
  { 'name': 'barney', 'age': 36 }
];

numAndStrComparator(given[0], given[1], 'name'); // 1
numAndStrComparator(given[1], given[0],'name'); // -1
numAndStrComparator(given[0], given[1],'age'); // 1
numAndStrComparator(given[1], given[0],'age'); // -1

public objectProjection(obj: object, cb: Function, skipCb: Function): Array<any> source

import {objectProjection} from 'js-helpers/src/Object/index.js'

Iterates by object properties.

Params:

NameTypeAttributeDescription
obj object

Context object.

cb Function

Callback function which will be invoked with key and value argument.

skipCb Function

Skip function which allows to skip property by given condition.

Return:

Array<any>

Returns array projected by Callback function.

public omit(source: object, omitArray: ...string): object source

import {omit} from 'js-helpers/src/Object/index.js'

Will create and return a new object with omited properties from omitArray.

Params:

NameTypeAttributeDescription
source object

Object that should have updated structure.

omitArray ...string

Properties that should omited in result object.

Return:

object

Object with excluded properties from omitArray.

public once(fn: Function): T | undefined source

Creates a function that is restricted to invoking func once. Repeat calls to the function return undefined.

Params:

NameTypeAttributeDescription
fn Function

Function that should be invoked only once.

Return:

T | undefined

Returns invocation result of passed function.

public or(predicates: ...Function): Function source

Takes list of predicates and returns a one predicate, current predicate will return true if at least one of passed predicates returns true.

Params:

NameTypeAttributeDescription
predicates ...Function

List of predicates.

Return:

Function

Predicate function.

public orCurry(fn: Function, args: ArrayLike | Array<any>): Function | T source

import {orCurry} from 'js-helpers/src/Function/index.js'

Creates curry variation of function if some of arguments are missed.

Params:

NameTypeAttributeDescription
fn Function

Function for Curring.

args ArrayLike | Array<any>

Arguments which should be invoked woith passed function.

Return:

Function | T

Function that should collect arguments or result on invokation.

public partial(fn: Function, partialArgs: ...T): Function source

import {partial} from 'js-helpers/src/Function/index.js'

Creates a function that invokes fn with partials prepended to the arguments it receives.

Params:

NameTypeAttributeDescription
fn Function

The function to partially apply arguments to.

partialArgs ...T

Arguments that should be applied.

Return:

Function

Returns the new partially applied function.

public path(p: Array<string>, source: object): any source

import {path} from 'js-helpers/src/Lens/index.js'

Retrieve the value at a given path.

Params:

NameTypeAttributeDescription
p Array<string>

Path to value.

source object

Source to use.

Return:

any

Value by path.

public pathEq(path: Array<string>, source: object, value: any): any source

import {pathEq} from 'js-helpers/src/Lens/index.js'

Retrieve the value at a given path and compares it with given value.

Params:

NameTypeAttributeDescription
path Array<string>

Path to value.

source object

Source to use.

value any

Value for comparing.

Return:

any

Comparation result.

public pathOr(path: Array<string>, source: object, orValue: any): any source

import {pathOr} from 'js-helpers/src/Lens/index.js'

Retrieve the value at a given path and if value is undefined returns orValue.

Params:

NameTypeAttributeDescription
path Array<string>

Path to value.

source object

Source to use.

orValue any

Value which should be returned in case if path doesn't exist.

Return:

any

Value by path or orValue.

public pathSatisfies(path: Array<string>, source: object, satisfyFn: Function): any source

import {pathSatisfies} from 'js-helpers/src/Lens/index.js'

Retrieve the value at a given path and returns result of invocation satisfy function with value by path.

Params:

NameTypeAttributeDescription
path Array<string>

Path to value.

source object

Source to use.

satisfyFn Function

Function which will be invoked with path value.

Return:

any

Result of invocation satisfy function with value by path.

public pick(source: object, pickArray: ...string): object source

import {pick} from 'js-helpers/src/Object/index.js'

Will create and return a new object with selected properties from pickArray.

Params:

NameTypeAttributeDescription
source object

Object that should have updated structure.

pickArray ...string

Properties that should be included in result object.

Return:

object

Object that includes pickArray property list.

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

Creates a function that returns the result of invoking the provided f unctions with the this binding of the created function, where each successive invocation is supplied the return value of the previous.

Params:

NameTypeAttributeDescription
fns ...Function

Function that should be invoked with given arguments.

Return:

Function

Returns the new function.

public pluck(source: Array<Object>, propName: string): Array<T> source

import {pluck} from 'js-helpers/src/Array/index.js'

Will return array of selected properties.

Params:

NameTypeAttributeDescription
source Array<Object>
  • optional
  • default: []

Array for propjection.

propName string

Name of the property from that should be included in Array.

Return:

Array<T>

Packed array of selected properties.

public prop(propName: string, source: object): T source

import {prop} from 'js-helpers/src/Lens/index.js'

Returns value taken by property from source.

Params:

NameTypeAttributeDescription
propName string

Property name which should be taken within source.

source object

Object is source from where should be taken value by property name.

Return:

T

property value.

Example:

let user = { name: { first: 'Oleh' } };
eq({ first: 'Oleh' }, prop('name', user)); // false
eq(prop('name', user).first, 'Oleh'); // true

public range(number1: number, number2: number): Function source

import {range} from 'js-helpers/src/Predicate/index.js'

Saves number1, number2 and returns predicate function that will be checking if future passed number is in range of number1 and number2.

Params:

NameTypeAttributeDescription
number1 number

Min range number.

number2 number

Max range number.

Return:

Function

Predicate Function.

public rangeEqual(number1: number, number2: number): Function source

import {rangeEqual} from 'js-helpers/src/Predicate/index.js'

Saves number1, number2 and returns predicate function that will be checking if future passed number is in range of number1 and number2 or equal to number1/number2.

Params:

NameTypeAttributeDescription
number1 number

Min range number.

number2 number

Max range number.

Return:

Function

Predicate Function.

public rearg(fn: Function, order: Array<number>): * source

import {rearg} from 'js-helpers/src/Function/index.js'

Reorginizes argument order.

Params:

NameTypeAttributeDescription
fn Function

Function that should be invoked with reorganized argument order.

order Array<number>

Argument order.

Return:

*

public reject(source: Array<T>, fn: Function): Array<T> source

import {reject} from 'js-helpers/src/Array/index.js'

The opposite of filter; this method returns the elements of collection that predicate does not return truthy for.

Params:

NameTypeAttributeDescription
source Array<T>

Array that should checked.

fn Function

Opposite filter function.

Return:

Array<T>

Returns the new filtered array.

Example:

 let numberArray = [1, 2, 3]
   , objectArray = [{ name: 'John' }, { name: 'Liza' }];

 reject(numberArray, item => item < 3) // [3]
 reject(objectArray, user => user.name === 'Liza') // [{ name: 'John' }]

public replaceAll(replaceable: String, from: String, to: T): String source

import {replaceAll} from 'js-helpers/src/String/index.js'

Will replace all occurrences.

Params:

NameTypeAttributeDescription
replaceable String

Source for replacements.

from String

Property that should be replaced.

to T

Proprty that should be included instead of from propperty.

Return:

String

New String with all replacements.

public replaceAllDifferences(replaceable: String, fromList: Array<T>, to: Array<T>): String source

import {replaceAllDifferences} from 'js-helpers/src/String/index.js'

Will replace all different occurrences.

Params:

NameTypeAttributeDescription
replaceable String

Source for replacements.

fromList Array<T>

Array of properties that should be replaced.

to Array<T>

Array of properties that should be injected to source.

Return:

String

New String with all replacements.

public safeGet(obj: object, props: ...string): * source

import {safeGet} from 'js-helpers/src/Object/index.js'

Implementation of optional chain operator.

Params:

NameTypeAttributeDescription
obj object

Context object.

props ...string

Property chain.

Return:

*

Context value by property chain.

public safeGetOr(obj: object, orValue: any, props: ...string): any source

import {safeGetOr} from 'js-helpers/src/Object/index.js'

Implementation of optional chain operator.

Params:

NameTypeAttributeDescription
obj object

Context object.

orValue any

Value which will be returned if obj doesn't contain truthly value.

props ...string

Property chain.

Return:

any

Context value by property chain or orValue.

public sample(source: Array<T>): T source

import {sample} from 'js-helpers/src/Array/index.js'

Will return random element from array.

Params:

NameTypeAttributeDescription
source Array<T>

Array from where should be choosen random element.

Return:

T

Random element.

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

The seq combinator is used to loop over a sequence of functions.

Params:

NameTypeAttributeDescription
fns ...Function

List of functions which will be invoked sequently.

Return:

Function

Returns a new function, which runs all of them in sequence against the same value.

Example:

let result = 0
  , addToResult = x => result += x;

result; // 0

seq(addToResult, addToResult)(4);

result; // 8

public shuffle(source: Array<T>): Array<T> source

import {shuffle} from 'js-helpers/src/Array/index.js'

Will shuffle elements in array.

Params:

NameTypeAttributeDescription
source Array<T>

Array to shuffle.

Return:

Array<T>

Array that is shuffled out.

Example:

shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// [ 1, 5, 3, 4, 2, 6, 10, 7, 8, 9 ]

shuffle([
  { name: 'name1' },
  { name: 'name2' },
  { name: 'name3' },
  { name: 'name4' },
  { name: 'name5' },
  { name: 'name6' },
  { name: 'name7' },
  { name: 'name8' },
  { name: 'name9' },
  { name: 'name10' }
]);
// [
//   { name: 'name2' },
//   { name: 'name3' },
//   { name: 'name4' },
//   { name: 'name1' },
//   { name: 'name9' },
//   { name: 'name6' },
//   { name: 'name8' },
//   { name: 'name7' },
//   { name: 'name10' },
//   { name: 'name5' }
// ]

public snakeCase(str: String): String source

import {snakeCase} from 'js-helpers/src/String/index.js'

Converts string to snake case.

Params:

NameTypeAttributeDescription
str String

The string to convert.

Return:

String

Returns the snake cased string.

public some(source: Array<T>, fn: Function): boolean source

import {some} from 'js-helpers/src/Array/index.js'

Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. Is analog of any(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

The collection to iterate over.

fn Function

The collection to iterate over.

Return:

boolean

Returns true if any element passes the predicate check, else false.

public sortBy(source: Array<object>, propList: Array<string>): Array<object> source

import {sortBy} from 'js-helpers/src/Array/index.js'

Sorts array of objects by given properties with priorities.

Params:

NameTypeAttributeDescription
source Array<object>

Source which requires sorting.

propList Array<string>

Sorting property list.

Return:

Array<object>

Sorted array of objects.

Example:

 let given = [
   { 'name': 'fred',   'age': 48 },
   { 'name': 'barney', 'age': 36 },
   { 'name': 'fred',   'age': 32 },
   { 'name': 'barney', 'age': 34 }
 ];

 sortBy(given, ['name', 'age']);
 //  [
 //    { name: 'barney', age: 34 },
 //    { name: 'barney', age: 36 },
 //    { name: 'fred', age: 32 },
 //    { name: 'fred', age: 48 }
 //  ]

public subtract(minuend: number, subtrahendList: number): number source

import {subtract} from 'js-helpers/src/Math/index.js'

Subtract numbers.

Params:

NameTypeAttributeDescription
minuend number

The first number in a subtraction.

subtrahendList number

The subtrahend list.

Return:

number

Returns the difference.

public tail(source: Array<T>): T source

import {tail} from 'js-helpers/src/Array/index.js'

Will return last element from array. Is analog of last(*) function.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

Array where to check for last element.

Return:

T

Returns last element from Array.

public take(source: Array<T>, sourceLength: number): Array<T> source

import {take} from 'js-helpers/src/Array/index.js'

Will return first n elements.

Params:

NameTypeAttributeDescription
source Array<T>

Array to slice.

sourceLength number
  • optional
  • default: 1

Number of first n elements that should be returned back.

Return:

Array<T>

First n elements from Array.

Example:

let numberArray = [1, 2, 3]
  , objectArray = [{ name: 'John' }, { name: 'Liza' }];

take(numberArray); // [1]
take(objectArray); // [{ name: 'John' }]

take(numberArray, 2); // [1, 2]
take(objectArray, 2); // [{ name: 'John' }, { name: 'Liza' }]

public takeRight(source: Array<T>, numberOfLastElements: number): Array<T> source

import {takeRight} from 'js-helpers/src/Array/index.js'

Will return last n elements from an array.

Params:

NameTypeAttributeDescription
source Array<T>

Array to slice.

numberOfLastElements number
  • optional
  • default: 1

Number of last n elements that should be returned back.

Return:

Array<T>

Last n elements from Array.

public takeRightWhile(source: Array<T>, rightWhileFn: Function): Array<T> source

import {takeRightWhile} from 'js-helpers/src/Array/index.js'

Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

The array to query.

rightWhileFn Function

The function invoked per iteration.

Return:

Array<T>

Last n elements from Array before match.

public takeWhile(source: Array<T>, whileFn: Function): Array<T> source

import {takeWhile} from 'js-helpers/src/Array/index.js'

Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey.

Params:

NameTypeAttributeDescription
source Array<T>
  • optional
  • default: []

The array to query.

whileFn Function

The function invoked per iteration.

Return:

Array<T>

First n elements from Array before match.

public tap(fn: Function): Function source

Helps to check data in chain. Useful for debugging.

Params:

NameTypeAttributeDescription
fn Function

Middleware function.

Return:

Function

Returns data that was used for tap functio

Example:

let sayHelloTo = name => `Hello ${name}`
  , toUpperCase = str => str.toUpperCase()
  , addDollarSign  = str => `$${str}$`
  , chainMiddleResult = ''
  , tapHandler = data => chainMiddleResult = data
  , sayHelloInUpperCase = compose(addDollarSign, sayHelloTo, tap(tapHandler), toUpperCase);

 sayHelloInUpperCase('oleh'); // '$Hello OLEH$'
 chainMiddleResult; // 'OLEH'

public throwIncorrectArgsTypeErrorIfSomeOf(conditions: ...boolean) source

import {throwIncorrectArgsTypeErrorIfSomeOf} from 'js-helpers/src/Error/index.js'

Throws IncorrectArgsTypeError if at least one of conditions is positive.

Params:

NameTypeAttributeDescription
conditions ...boolean

Conditions which should be negative in order to not throw IncorrectArgsTypeError error.

Throw:

IncorrectArgsTypeError

throw error when one of conditions is true.

public thrush(x: any): Function source

Takes argument and returns function which expects to get function which will be invoked with first argument. T - combinator implementation.

Params:

NameTypeAttributeDescription
x any

Argument which will be passed into a function which is expected as a second argument.

Return:

Function

Function which expects to get function where will be passed first argument.

Example:

const addWorld = w => `${w} world`;

thrush('hello')(addWorld); // 'hello world'

public times(iterationNumber: number, fn: Function): Array<T> source

import {times} from 'js-helpers/src/Array/index.js'

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

Params:

NameTypeAttributeDescription
iterationNumber number

Number of iterations.

fn Function

Function that should be invoked with each iteration.

Return:

Array<T>

Result array.

public toBe(expectation: T): Function source

import {toBe} from 'js-helpers/src/Type/index.js'

Takes expectation and returns predicate function which will be checking if new passed variable equal to expectation.

Params:

NameTypeAttributeDescription
expectation T

Expected value.

Return:

Function

Returns predicate function.

public toSetoid(eqFn: Function): Setoid source

import {toSetoid} from 'js-helpers/src/Fantasy-Land/setoid.js'

Creates Setoid from given function.

Params:

NameTypeAttributeDescription
eqFn Function

Setoid implementation function.

Return:

Setoid

New concrete Setoid implementation.

Example:

const comparePeopleFn = (p, p2) => p.id === p2.id;
const PersonSetoid = toSetoid(comparePeopleFn);
const person1 = { id: 1, name: 'Oleh' };
const person2 = { id: 1, name: 'Oleh' };
const person3 = { id: 7, name: 'Oleh' };

PersonSetoid(person1).equals(PersonSetoid(person2))); // true
PersonSetoid(person2).equals(PersonSetoid(person1))); // true

PersonSetoid(person1).equals(PersonSetoid(person3))); // false
PersonSetoid(person2).equals(PersonSetoid(person3))); // false

Object.keys(PersonSetoid(person1)); // ['id', 'name'];

public trim(stringSource: String): * source

import {trim} from 'js-helpers/src/String/index.js'

Removes leading and trailing whitespace or specified characters from string.

Params:

NameTypeAttributeDescription
stringSource String

The string to trim.

Return:

*

Returns the trimmed string.

public typeCheck(clazz: T, actualType: any): any source

import {typeCheck} from 'js-helpers/src/Type/index.js'

Checks if type is correct and throws error in negative case.

Params:

NameTypeAttributeDescription
clazz T

Expected source which should be a class.

actualType any

Value which should be checked.

Return:

any

actualType if type is correct else throws error.

Throw:

TypeError

If passed actualType has incorrect type.

Example:

typeCheck(String, ''); // ''
typeCheck(RegExp, /ab+c/); // /ab+c/
typeCheck(Object, {}); // {}
typeCheck(Function, () => {}); // () => {}
typeCheck(Date, new Date()); // Sun Nov 04 2018 01:25:43 GMT+0200 (Eastern European Standard Time)
typeCheck(Boolean, true); // true
typeCheck(Number, 333); // 333
typeCheck(Array, []); // []
typeCheck(Symbol, Symbol('desc')); // Symbol('desc')

typeCheck(String, 777); // TypeError
typeCheck(Number, 'hello'); // TypeError
typeCheck(Boolean, {}); // TypeError
...

public unary(fn: Function): Function source

import {unary} from 'js-helpers/src/Function/index.js'

Create funtion that makes same as passed function but newly created function will use only first argument.

Params:

NameTypeAttributeDescription
fn Function

Function that should use only one argument.

Return:

Function

Same function that was passed but now it uses only first argument.

public uniq(source: Array<any>): Array<any> source

import {uniq} from 'js-helpers/src/Array/index.js'

returns new array only with uniq elements

Params:

NameTypeAttributeDescription
source Array<any>

Source for uniqueness.

Return:

Array<any>

New array only with unique elements.

Example:

uniq(
  [
    { id: 1, firstName: 'Jon', lastName: 'Snow', location: 'Winterfell' },
    { id: 2, firstName: 'Eddard', lastName: 'Stark', location: 'Winterfell' },
    { id: 3, firstName: 'Catelyn', lastName: 'Stark', location: 'Winterfell' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', location: 'Dreadfort' },
    { id: 4, firstName: 'Roose', lastName: 'Bolton', location: 'Dreadfort' },
    { id: 5, firstName: 'Ramsay', lastName: 'Snow', location: 'Dreadfort' }
  ]);
// [
//   { id: 1, firstName: 'Jon', lastName: 'Snow', location: 'Winterfell' },
//   { id: 2, firstName: 'Eddard', lastName: 'Stark', location: 'Winterfell' },
//   { id: 3, firstName: 'Catelyn', lastName: 'Stark', location: 'Winterfell' },
//   { id: 4, firstName: 'Roose', lastName: 'Bolton', location: 'Dreadfort' },
//   { id: 5, firstName: 'Ramsay', lastName: 'Snow', location: 'Dreadfort' }
// ]

public upperFirst(str: String): String source

import {upperFirst} from 'js-helpers/src/String/index.js'

Will make a capital first letter.

Params:

NameTypeAttributeDescription
str String

Source string.

Return:

String

Source with first capital letter.

public using(ctx: object): object source

import {using} from 'js-helpers/src/Context/index.js'

Is opposite to invoke function.

Params:

NameTypeAttributeDescription
ctx object

Context for all functions that should be invoked.

Return:

object

Object that will have a invoke(*) function. In invoke function should be passed functions that should be invoked with current context.

public without(source: Array<T>, matchItem: T): Array<T> source

import {without} from 'js-helpers/src/Array/index.js'

Returns an array without match item.

Params:

NameTypeAttributeDescription
source Array<T>

Array from where to remove match item.

matchItem T

item that should not be included in result array.

Return:

Array<T>

Array without matched element.

Example:

let numberArray = without([1, 2, 3], 1);
numberArray // => [2, 3]

public words(strValue: String): Array<String> source

import {words} from 'js-helpers/src/String/index.js'

Splits string into an array of its words.

Params:

NameTypeAttributeDescription
strValue String

The string to inspect.

Return:

Array<String>

Returns the words of string.

public wrap(fn: Function, args: ...T): void source

import {wrap} from 'js-helpers/src/Context/index.js'

Will take function, arguments and return function that will invoke given function with given arguments.

Params:

NameTypeAttributeDescription
fn Function

Function that should be wrapped.

args ...T

List of arguments that should be invoked with given function.

Return:

void

public zip(source: ...Array<T>): Array<D> source

import {zip} from 'js-helpers/src/Array/index.js'

Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.

Params:

NameTypeAttributeDescription
source ...Array<T>

Array to zip.

Return:

Array<D>

Zipped Array.

public zipWithProjection(): Array<D> source

import {zipWithProjection} from 'js-helpers/src/Array/index.js'

Will zip multiple Arrays using projection function. Takes arguments ArrayLike object that should include n number of arrays with same length and in the end should be projection function.

Return:

Array<D>

Projected Array.