Function
| Static Public Summary | ||
| public |
Applicative(f: any): Appicative Appicative implementation. |
|
| public |
Apply implementation. |
|
| public |
Either() Either implementation. |
|
| public |
Functor implementation. |
|
| public |
Just Implementation. |
|
| public |
LazyFunctor(x: any): LazyFunctor LazyFunctor implementation. |
|
| public |
Left Implementation. |
|
| public |
Maybe() Maybe implementation. |
|
| public |
Monad implementation. |
|
| public |
Creates new Nothing. |
|
| public |
Right Implementation. |
|
| public |
Adds numbers. |
|
| public |
Creates a function that invokes fn once it's called n or more times. |
|
| public |
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 |
Creates function which will always return passed argument. |
|
| public |
Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return true. |
|
| public |
Checks if predicate returns truthy for any element of collection. |
|
| public |
Makes a deep clone of an object, setting or overriding the specified property with the given value. |
|
| public |
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 |
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 |
Creates an array with all falsey values removed. |
|
| public |
compareDecimalNumbers(number1: number, number2: number): boolean 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 |
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 |
Will create an object deep clone. |
|
| public |
deepEquals(first: any, second: any): boolean Compares two elements. |
|
| public |
deepFreeze(obj: object): object Will deep frezee all properties. |
|
| public |
Divide numbers. |
|
| public |
duplication(fn: Function): Function Takes function and invokes it with passed argument two times. |
|
| public |
Checks if two elements are the same |
|
| public |
equalsIgnoreCase(str1: String, str2: String): boolean Will compare two strings with ignore case. |
|
| public |
Checks if predicate returns truthy for all elements of collection. |
|
| public |
Will fill array by given value. |
|
| public |
Will fill array in the begining for n elements and add given array in the end. |
|
| public |
Will fill array in the end for n elements and add given array from begining. |
|
| public |
Will filter an array. |
|
| public |
Iterates over elements of collection, returning the first element predicate returns truthy for. |
|
| public |
Will return first element from array. |
|
| public |
Flattens array. |
|
| public |
Takes function and changes argument order. |
|
| public |
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 |
getFirstLowerLetter(source: String): String Will return first lower letter from source. |
|
| public |
getFirstUpperLetter(source: String): String Will return first upper letter from source. |
|
| public |
getLastLowerLetter(source: String): String Will return last lower letter from source. |
|
| public |
getLastUpperLetter(source: String): String Will return last upper letter from source. |
|
| public |
getRandomInt(max: number): number Will generate random integer. |
|
| public |
getRandomIntFromTo(min: number, max: number): number Will generate random integer in passed range. |
|
| public |
Checks type of passed value. |
|
| public |
getTypeByClass(clazz: T): string Returns class name. |
|
| public |
getWithCtx(obj: object): Function Curry version of get function that expects in future to get property list. |
|
| public |
getWithProps(props: ...string): Function Curry version of get function that expects in future to get context. |
|
| public |
Will group objects in array by given property, function or path. |
|
| public |
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 |
Saves number1 and returns predicate function that will be checking if number2 is greater then number1. |
|
| public |
Saves number1 and returns predicate function that will be checking if number2 is greater then or equal to number1. |
|
| public |
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 |
Work similary to indexOf method but returns boolean. |
|
| public |
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 |
Checks if passed value is Array. |
|
| public |
Checks if passed value is boolean. |
|
| public |
Checks if passed value is Date. |
|
| public |
isFunction(valToCheck: T): boolean Checks if passed value is Function. |
|
| public |
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 |
Checks if passed value is not Date. |
|
| public |
isNotFunction(valToCheck: T): boolean Checks if passed value is not Function. |
|
| public |
Checks if passed value is not NaN. |
|
| public |
isNotNegativeZero(numberToCheck: number): boolean Checks if passed value is not negative zero. |
|
| public |
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 |
Checks if passed value is null. |
|
| public |
Checks if passed value is number. |
|
| public |
Checks if passed value is Object. |
|
| public |
isPrimitive(value: T): boolean Determine whether a value is a primitive type. |
|
| public |
Checks if passed value is RegExp. |
|
| public |
Checks if passed object implements setoid. |
|
| public |
Checks if passed value is string. |
|
| public |
Checks if passed value is Symbol. |
|
| public |
isUndefined(valToCheck: T): boolean Checks if passed value is undefined. |
|
| public |
Converts string to kebab case. |
|
| public |
Will return last element from array. |
|
| public |
Returns value taken by index from source. |
|
| public |
Returns a lens whose focus is the specified property. |
|
| public |
Saves number1 and returns predicate function that will be checking if number2 is less then number1. |
|
| public |
Saves number1 and returns predicate function that will be checking if number2 is less then or equal to number1. |
|
| public |
Will project array object. |
|
| public |
Creates a function that memoizes the result of fn. |
|
| public |
Multiply numbers. |
|
| public |
Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return false. |
|
| public |
Checks if two elements are not the same. |
|
| public |
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 |
Takes expectation and returns predicate function which will be checking if new passed variable not equal to expectation. |
|
| public |
Will return element from array by given index. |
|
| public |
number or string comparator. |
|
| public |
Iterates by object properties. |
|
| public |
Will create and return a new object with omited properties from omitArray. |
|
| public |
Creates a function that is restricted to invoking func once. |
|
| public |
Takes list of predicates and returns a one predicate, current predicate will return true if at least one of passed predicates returns true. |
|
| public |
Creates curry variation of function if some of arguments are missed. |
|
| public |
Creates a function that invokes fn with partials prepended to the arguments it receives. |
|
| public |
Retrieve the value at a given path. |
|
| public |
Retrieve the value at a given path and compares it with given value. |
|
| public |
Retrieve the value at a given path and if value is undefined returns orValue. |
|
| public |
Retrieve the value at a given path and returns result of invocation satisfy function with value by path. |
|
| public |
Will create and return a new object with selected properties from pickArray. |
|
| public |
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 |
Will return array of selected properties. |
|
| public |
Returns value taken by property from source. |
|
| public |
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 |
Reorginizes argument order. |
|
| public |
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 |
Implementation of optional chain operator. |
|
| public |
Implementation of optional chain operator. |
|
| public |
Will return random element from array. |
|
| public |
The seq combinator is used to loop over a sequence of functions. |
|
| public |
Will shuffle elements in array. |
|
| public |
Converts string to snake case. |
|
| public |
Checks if predicate returns truthy for any element of collection. |
|
| public |
Sorts array of objects by given properties with priorities. |
|
| public |
Subtract numbers. |
|
| public |
Will return last element from array. |
|
| public |
Will return first n elements. |
|
| public |
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 |
Creates a slice of array with elements taken from the beginning. |
|
| public |
Helps to check data in chain. |
|
| public |
throwIncorrectArgsTypeErrorIfSomeOf(conditions: ...boolean) 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 |
Invokes the iteratee n times, returning an array of the results of each invocation. |
|
| public |
Takes expectation and returns predicate function which will be checking if new passed variable equal to expectation. |
|
| public |
Creates Setoid from given function. |
|
| public |
Removes leading and trailing whitespace or specified characters from string. |
|
| public |
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 |
returns new array only with uniq elements |
|
| public |
upperFirst(str: String): String Will make a capital first letter. |
|
| public |
Is opposite to invoke function. |
|
| public |
Returns an array without match item. |
|
| public |
Splits string into an array of its words. |
|
| public |
Will take function, arguments and return function that will invoke given function with given arguments. |
|
| public |
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 |
zipWithProjection(): Array<D> 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:
| Name | Type | Attribute | Description |
| 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
import {Apply} from 'js-helpers/src/Fantasy-Land/index.js'Apply implementation.
Params:
| Name | Type | Attribute | Description |
| f | any | Apply 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
import {Either} from 'js-helpers/src/Fantasy-Land/either.js'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:
| Name | Type | Attribute | Description |
| x | any | Functor 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
import {Just} from 'js-helpers/src/Fantasy-Land/maybe.js'Just Implementation.
Params:
| Name | Type | Attribute | Description |
| value | any | 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:
| Name | Type | Attribute | Description |
| x | any | LazyFunctor 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
import {Left} from 'js-helpers/src/Fantasy-Land/either.js'Left Implementation.
Params:
| Name | Type | Attribute | Description |
| value | any | Left with given value. |
Example:
Either.left(3); // Either.Left(3)
public Maybe() source
import {Maybe} from 'js-helpers/src/Fantasy-Land/maybe.js'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
import {Monad} from 'js-helpers/src/Fantasy-Land/index.js'Monad implementation.
Params:
| Name | Type | Attribute | Description |
| x | any | Monad 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:
| Name | Type | Attribute | Description |
| value | any | Nothing value. |
Example:
Maybe.nothing(); // Maybe.Nothing()
public Right(value: any): Right source
import {Right} from 'js-helpers/src/Fantasy-Land/either.js'Right Implementation.
Params:
| Name | Type | Attribute | Description |
| value | any | 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.
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.
public alt(fn1: Function, fn2: Function): Function source
import {alt} from 'js-helpers/src/Function-Combinators/index.js'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.
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
import {always} from 'js-helpers/src/Function-Combinators/index.js'Creates function which will always return passed argument. K - combinator implementation.
Params:
| Name | Type | Attribute | Description |
| value | T | Argument that should returned back from function which was returned. |
Example:
always(2)(); // 2
public and(predicates: ...Function): Function source
import {and} from 'js-helpers/src/Predicate-Combinator/index.js'Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return true.
Params:
| Name | Type | Attribute | Description |
| predicates | ...Function | List of predicates. |
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.
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.
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.
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}...).
public camelCase(str: String): String source
import {camelCase} from 'js-helpers/src/String/index.js'Converts string to camel case.
Params:
| Name | Type | Attribute | Description |
| str | String | The string to convert. |
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:
| Name | Type | Attribute | Description |
| valueToCast | ...T | All values will be included in array that will be returned back. |
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.
public cloneArray(source: Array<T>): Array<T> source
import {cloneArray} from 'js-helpers/src/Array/index.js'Will create clone of given array.
Params:
| Name | Type | Attribute | Description |
| source | Array<T> | Array that should be cloned. |
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:
| Name | Type | Attribute | Description |
| objectToClone | object | Object that should be cloned. |
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:
| Name | Type | Attribute | Description |
| source | Array<T> | Array to compact. truthly 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.
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:
| Name | Type | Attribute | Description |
| fns | ...Function | Function that should be invoked with given arguments. |
public conformsTo(object: object, predicateSetModel: object): boolean source
import {conformsTo} from 'js-helpers/src/Object/index.js'Checks object properties with set of predicates.
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:
| Name | Type | Attribute | Description |
| fn | Function | Function for Curring. |
public deepClone(objectToDeepClone: object): object source
import {deepClone} from 'js-helpers/src/Object/index.js'Will create an object deep clone.
Params:
| Name | Type | Attribute | Description |
| objectToDeepClone | object | Object that should be deep cloned. |
public deepEquals(first: any, second: any): boolean source
import {deepEquals} from 'js-helpers/src/Object/index.js'Compares two elements.
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:
| Name | Type | Attribute | Description |
| obj | object | Object that should be fully freezed. |
public divide(dividend: number, divisorList: number): number source
import {divide} from 'js-helpers/src/Math/index.js'Divide numbers.
public duplication(fn: Function): Function source
import {duplication} from 'js-helpers/src/Function-Combinators/index.js'Takes function and invokes it with passed argument two times.
Params:
| Name | Type | Attribute | Description |
| fn | Function | Function which will be invoked two times with the same argument. |
Example:
const add = x => y => x + y;
duplication(add)(7); // 14
public eq(elem1: T): Function source
import {eq} from 'js-helpers/src/Predicate/index.js'Checks if two elements are the same
Params:
| Name | Type | Attribute | Description |
| elem1 | T | Element which will be compared with other. |
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.
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.
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:
| Name | Type | Attribute | Description |
| source | T | Fill value. |
|
| number | number | Number of filled elements in Array. |
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.
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.
public filter(source: Array<T>, fn: Function): Array<T> source
import {filter} from 'js-helpers/src/Array/index.js'Will filter an 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.
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:
| Name | Type | Attribute | Description |
| source | Array<T> |
|
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:
| Name | Type | Attribute | Description |
| source | Array<T> | Array that should be flatten. |
Return:
| * | Returns the new flattened array. |
public flip(fn: Function): Function source
import {flip} from 'js-helpers/src/Function-Combinators/index.js'Takes function and changes argument order. C - combinator implementation.
Params:
| Name | Type | Attribute | Description |
| 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
import {fork} from 'js-helpers/src/Function-Combinators/index.js'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.
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:
| Name | Type | Attribute | Description |
| source | String | Source for searching. |
public getFirstUpperLetter(source: String): String source
import {getFirstUpperLetter} from 'js-helpers/src/String/index.js'Will return first upper letter from source.
Params:
| Name | Type | Attribute | Description |
| source | String | Source for searching. |
public getLastLowerLetter(source: String): String source
import {getLastLowerLetter} from 'js-helpers/src/String/index.js'Will return last lower letter from source.
Params:
| Name | Type | Attribute | Description |
| source | String | Source for searching. |
public getLastUpperLetter(source: String): String source
import {getLastUpperLetter} from 'js-helpers/src/String/index.js'Will return last upper letter from source.
Params:
| Name | Type | Attribute | Description |
| source | String | Source for searching. |
public getRandomInt(max: number): number source
import {getRandomInt} from 'js-helpers/src/Math/index.js'Will generate random integer.
Params:
| Name | Type | Attribute | Description |
| max | number | Max number that can be returned. |
public getRandomIntFromTo(min: number, max: number): number source
import {getRandomIntFromTo} from 'js-helpers/src/Math/index.js'Will generate random integer in passed range.
public getType(valToCheck: T): string source
import {getType} from 'js-helpers/src/Type/index.js'Checks type of passed value.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public getTypeByClass(clazz: T): string source
import {getTypeByClass} from 'js-helpers/src/Type/index.js'Returns class name.
Params:
| Name | Type | Attribute | Description |
| clazz | T | Source which should be a 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:
| Name | Type | Attribute | Description |
| obj | object | Context object. |
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:
| Name | Type | Attribute | Description |
| props | ...string | Property chain. |
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:
| Name | Type | Attribute | Description |
| args | ...any | grouping arguments. |
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.
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.
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.
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
import {gt} from 'js-helpers/src/Predicate/index.js'Saves number1 and returns predicate function that will be checking if number2 is greater then number1.
Params:
| Name | Type | Attribute | Description |
| number1 | number | First number. |
public gte(number1: number): Function source
import {gte} from 'js-helpers/src/Predicate/index.js'Saves number1 and returns predicate function that will be checking if number2 is greater then or equal to number1.
Params:
| Name | Type | Attribute | Description |
| number1 | number | First number. |
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:
| Name | Type | Attribute | Description |
| source | Array<T> |
|
Array where to check for first element. |
Return:
| T | Returns first element from Array. |
public identity(value: T): T source
import {identity} from 'js-helpers/src/Function-Combinators/index.js'The identity combinator is a function that returns the same value it was provided as an argument. I - combinator implementation.
Params:
| Name | Type | Attribute | Description |
| 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.
public invoke(fns: ...Function): object source
import {invoke} from 'js-helpers/src/Context/index.js'Will invoke list of functions with given context.
Params:
| Name | Type | Attribute | Description |
| 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.
Return:
| void |
public isArray(valToCheck: T): boolean source
import {isArray} from 'js-helpers/src/Type/index.js'Checks if passed value is Array.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isBoolean(valToCheck: T): boolean source
import {isBoolean} from 'js-helpers/src/Type/index.js'Checks if passed value is boolean.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isDate(valToCheck: T): boolean source
import {isDate} from 'js-helpers/src/Type/index.js'Checks if passed value is Date.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isFunction(valToCheck: T): boolean source
import {isFunction} from 'js-helpers/src/Type/index.js'Checks if passed value is Function.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNaN(valToCheck: T): boolean source
import {isNaN} from 'js-helpers/src/Type/index.js'Checks if passed value is NaN.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNegativeZero(numberToCheck: number): boolean source
import {isNegativeZero} from 'js-helpers/src/Type/index.js'Checks if passed value is negative zero.
Params:
| Name | Type | Attribute | Description |
| numberToCheck | number | Value to Check. |
public isNotArray(valToCheck: T): boolean source
import {isNotArray} from 'js-helpers/src/Type/index.js'Checks if passed value is not Array.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotBoolean(valToCheck: T): boolean source
import {isNotBoolean} from 'js-helpers/src/Type/index.js'Checks if passed value is not boolean.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotDate(valToCheck: T): boolean source
import {isNotDate} from 'js-helpers/src/Type/index.js'Checks if passed value is not Date.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotFunction(valToCheck: T): boolean source
import {isNotFunction} from 'js-helpers/src/Type/index.js'Checks if passed value is not Function.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotNaN(valToCheck: T): boolean source
import {isNotNaN} from 'js-helpers/src/Type/index.js'Checks if passed value is not NaN.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotNegativeZero(numberToCheck: number): boolean source
import {isNotNegativeZero} from 'js-helpers/src/Type/index.js'Checks if passed value is not negative zero.
Params:
| Name | Type | Attribute | Description |
| numberToCheck | number | Value to Check. |
public isNotNull(valToCheck: T): boolean source
import {isNotNull} from 'js-helpers/src/Type/index.js'Checks if passed value is not null.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotNumber(valToCheck: T): boolean source
import {isNotNumber} from 'js-helpers/src/Type/index.js'Checks if passed value is not number.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotObject(valToCheck: T): boolean source
import {isNotObject} from 'js-helpers/src/Type/index.js'Checks if passed value is not Object.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
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:
| Name | Type | Attribute | Description |
| value | T | Value to Check. |
public isNotRegExp(valToCheck: T): boolean source
import {isNotRegExp} from 'js-helpers/src/Type/index.js'Checks if passed value is not RegExp.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotString(valToCheck: T): boolean source
import {isNotString} from 'js-helpers/src/Type/index.js'Checks if passed value is not string.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotSymbol(valToCheck: T): boolean source
import {isNotSymbol} from 'js-helpers/src/Type/index.js'Checks if passed value is not Symbol.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNotUndefined(valToCheck: T): boolean source
import {isNotUndefined} from 'js-helpers/src/Type/index.js'Checks if passed value is not undefined.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNull(valToCheck: T): boolean source
import {isNull} from 'js-helpers/src/Type/index.js'Checks if passed value is null.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isNumber(valToCheck: T): boolean source
import {isNumber} from 'js-helpers/src/Type/index.js'Checks if passed value is number.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isObject(valToCheck: T): boolean source
import {isObject} from 'js-helpers/src/Type/index.js'Checks if passed value is Object.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isPrimitive(value: T): boolean source
import {isPrimitive} from 'js-helpers/src/Type/index.js'Determine whether a value is a primitive type.
Params:
| Name | Type | Attribute | Description |
| value | T | Value to Check. |
public isRegExp(valToCheck: T): boolean source
import {isRegExp} from 'js-helpers/src/Type/index.js'Checks if passed value is RegExp.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isSetoid(obj: object): boolean source
import {isSetoid} from 'js-helpers/src/Fantasy-Land/setoid.js'Checks if passed object implements setoid.
Params:
| Name | Type | Attribute | Description |
| obj | object | Object to check. |
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:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isSymbol(valToCheck: T): boolean source
import {isSymbol} from 'js-helpers/src/Type/index.js'Checks if passed value is Symbol.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public isUndefined(valToCheck: T): boolean source
import {isUndefined} from 'js-helpers/src/Type/index.js'Checks if passed value is undefined.
Params:
| Name | Type | Attribute | Description |
| valToCheck | T | Value to Check. |
public kebabCase(str: String): String source
import {kebabCase} from 'js-helpers/src/String/index.js'Converts string to kebab case.
Params:
| Name | Type | Attribute | Description |
| str | String | The string to convert. |
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:
| Name | Type | Attribute | Description |
| source | Array<T> |
|
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.
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:
| Name | Type | Attribute | Description |
| propName | string | Property name which should be taken within source. |
public lt(number1: number): Function source
import {lt} from 'js-helpers/src/Predicate/index.js'Saves number1 and returns predicate function that will be checking if number2 is less then number1.
Params:
| Name | Type | Attribute | Description |
| number1 | number | First number. |
public lte(number1: number): Function source
import {lte} from 'js-helpers/src/Predicate/index.js'Saves number1 and returns predicate function that will be checking if number2 is less then or equal to number1.
Params:
| Name | Type | Attribute | Description |
| number1 | number | First number. |
public map(source: Array<T>, fn: Function): Array<D> source
import {map} from 'js-helpers/src/Array/index.js'Will project array object.
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:
| Name | Type | Attribute | Description |
| fn | Function | Function to memoize. |
public multiply(multiplier: number, multiplicandList: number): number source
import {multiply} from 'js-helpers/src/Math/index.js'Multiply numbers.
public not(predicates: ...Function): Function source
import {not} from 'js-helpers/src/Predicate-Combinator/index.js'Takes list of predicates and returns a one predicate, current predicate will return true only in case if all passed predicates return false.
Params:
| Name | Type | Attribute | Description |
| predicates | ...Function | List of predicates. |
public notEq(elem1: T): Function source
import {notEq} from 'js-helpers/src/Predicate/index.js'Checks if two elements are not the same.
Params:
| Name | Type | Attribute | Description |
| elem1 | T | Element which will be compared with other. |
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
import {notOr} from 'js-helpers/src/Predicate-Combinator/index.js'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:
| Name | Type | Attribute | Description |
| predicates | ...Function | List of predicates. |
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:
| Name | Type | Attribute | Description |
| expectation | T | Not expected value. |
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.
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.
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.
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.
public once(fn: Function): T | undefined source
import {once} from 'js-helpers/src/Function/index.js'Creates a function that is restricted to invoking func once. Repeat calls to the function return undefined.
Params:
| Name | Type | Attribute | Description |
| fn | Function | Function that should be invoked only once. |
public or(predicates: ...Function): Function source
import {or} from 'js-helpers/src/Predicate-Combinator/index.js'Takes list of predicates and returns a one predicate, current predicate will return true if at least one of passed predicates returns true.
Params:
| Name | Type | Attribute | Description |
| predicates | ...Function | List of predicates. |
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.
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:
| Name | Type | Attribute | Description |
| fn | Function | The function to partially apply arguments to. |
|
| partialArgs | ...T | Arguments that should be applied. |
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.
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.
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.
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.
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.
public pipe(fns: ...Function): Function source
import {pipe} from 'js-helpers/src/Function/index.js'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:
| Name | Type | Attribute | Description |
| fns | ...Function | Function that should be invoked with given arguments. |
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.
public prop(propName: string, source: object): T source
import {prop} from 'js-helpers/src/Lens/index.js'Returns value taken by property from source.
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.
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.
public rearg(fn: Function, order: Array<number>): * source
import {rearg} from 'js-helpers/src/Function/index.js'Reorginizes 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.
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.
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.
public safeGet(obj: object, props: ...string): * source
import {safeGet} from 'js-helpers/src/Object/index.js'Implementation of optional chain operator.
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.
public sample(source: Array<T>): T source
import {sample} from 'js-helpers/src/Array/index.js'Will return random element from array.
Params:
| Name | Type | Attribute | Description |
| source | Array<T> | Array from where should be choosen random element. |
Return:
| T | Random element. |
public seq(fns: ...Function): Function source
import {seq} from 'js-helpers/src/Function-Combinators/index.js'The seq combinator is used to loop over a sequence of functions.
Params:
| Name | Type | Attribute | Description |
| fns | ...Function | List of functions which will be invoked sequently. |
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:
| Name | Type | Attribute | Description |
| source | Array<T> | Array to shuffle. |
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:
| Name | Type | Attribute | Description |
| str | String | The string to convert. |
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.
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.
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.
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:
| Name | Type | Attribute | Description |
| source | Array<T> |
|
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.
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.
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.
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.
public tap(fn: Function): Function source
import {tap} from 'js-helpers/src/Function-Combinators/index.js'Helps to check data in chain. Useful for debugging.
Params:
| Name | Type | Attribute | Description |
| fn | Function | Middleware function. |
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:
| Name | Type | Attribute | Description |
| conditions | ...boolean | Conditions which should be negative in order to not throw IncorrectArgsTypeError error. |
Throw:
throw error when one of conditions is true. |
public thrush(x: any): Function source
import {thrush} from 'js-helpers/src/Function-Combinators/index.js'Takes argument and returns function which expects to get function which will be invoked with first argument. T - combinator implementation.
Params:
| Name | Type | Attribute | Description |
| x | any | Argument which will be passed into a function which is expected as a second 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.
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:
| Name | Type | Attribute | Description |
| expectation | T | Expected value. |
public toSetoid(eqFn: Function): Setoid source
import {toSetoid} from 'js-helpers/src/Fantasy-Land/setoid.js'Creates Setoid from given function.
Params:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| clazz | T | Expected source which should be a class. |
|
| actualType | any | Value which should be checked. |
Throw:
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:
| Name | Type | Attribute | Description |
| fn | Function | Function that should use only one 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
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:
| Name | Type | Attribute | Description |
| str | String | Source string. |
public using(ctx: object): object source
import {using} from 'js-helpers/src/Context/index.js'Is opposite to invoke function.
Params:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| source | Array<T> | Array from where to remove match item. |
|
| matchItem | T | item that should not be included in result array. |
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:
| Name | Type | Attribute | Description |
| strValue | String | The string to inspect. |
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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| source | ...Array<T> | Array to zip. |
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.