skald
Shakeable, tested javascript utility functions in a pure functional programming style
What is it?
Short answer: Yet another utility library
Long answer: Skald is a utility library to aid in pure functional javascript programming. It's meant to be shakeable, light-weight, and 100% tested. The entire library will compile down to < 7kb before gzipping (at present) and contains ~90 functions.
How do you use it?
Here's an example of a block of a short ES6 module
const sumPlusOne = arr ; ;
Here's an example of how that code might be written with skald
; const addOne = ;const mapByAddOne = ;const reduceByAdd = ;const sumPlusOne = ; ;
It's a little more code in your module, but:
- We didn't need to declare any functions directly
- We were able to reuse a simple function like add
- The code is easy to understand
- It slims down nicely when run through a build minification
That's about it.
Functions
- add(a, b) ⇒
number
Add two numbers
- and(...args) ⇒
boolean
Determine if all arguments are truthy or if array is truthy
- andWith(fns, val) ⇒
boolean
|function
Take an array of functions (or values) and determine if all results are true given value
- appendTo(str, append) ⇒
function
|string
Append string to the end of another string
- apply(fns, vals) ⇒
function
|array
Apply functions from an array to corresponding index in other array
- args(...vals) ⇒
Array
Returns an array of passed arguments
- at(index, val) ⇒
*
Returns copy of entry or character at given index in string or array
- attempt(toTry, onError) ⇒
*
Attempt something. If an error is thrown, return something else. (Wrapper for try / catch)
- bindTo(fn, ...args) ⇒
function
Takes a function and arguments. Leaves undefined arguments unbound and binds defined arguments to their position in arguments list.
- call(fn, arr) ⇒
function
Execute function with array as arguments
- callback(cb, predicate) ⇒
*
Take two arguments and if second argument is truthy, return first.
- callbackWith(cb, predicate, val) ⇒
*
Take two arguments and if second argument is truthy, return first based on val
- concat(val) ⇒
function
Returns a function which accepts no params and returns the passed value
- compose(...args) ⇒
function
Compose functions from right to left
- composeL(...args) ⇒
function
Compose functions from right to left
- concat(...args) ⇒
function
|Array
Returns a new array, which is a merge of at least two arrays
- curry(fn, ...args) ⇒
function
|*
Curry arguments to function and return new function
- deepEquals(a, b) ⇒
boolean
|function
Allow comparison of two objects or arrays
- defaultTo(def, val) ⇒
*
Sets default value if passed value is falsy
- define(fn) ⇒
function
|*
Take a function with a known signature and allow arguments to be passed until it executes
- divide(a, b) ⇒
number
|function
Divide two numbers
- equals(a, b) ⇒
boolean
|function
Determine if two values are equal
- everyBy(fn, arr) ⇒
function
|boolean
Determine if all values in array satisfy function
- excludes(search, val) ⇒
boolean
|function
Returns true if string is not in string or array
- executeWith(val, fn) ⇒
function
|*
Create a function which executes a function based on a defined value
- executeWith(fn, ...args) ⇒
function
Create a function which executes a function with each arg being transformed by a function
- fillBy(val, arr) ⇒
function
|arr
Fill an array with a defined value
- filterBy(fn, arr) ⇒
function
|Array
Filter elements in an array by function
- getEmptyArr() ⇒
Array
Returns an empty array
- getEmptyObj() ⇒
Object
Returns an empty object
- getObject(prop, value) ⇒
function
|Object
Get an object with single property and value
- getProp(prop, obj) ⇒
function
|*
Get property of an object
- gt(a, b) ⇒
function
|boolean
Determine if first value is greater than
- gte(a, b) ⇒
function
|boolean
Determine if value is greater than or equal to other value
- has(obj, key) ⇒
function
|boolean
Return true if object has key
- identity() ⇒
*
A function which returns whatever is passed into it
- includes(search, val) ⇒
boolean
|function
Returns true if string is in string or array
- invoke(fn) ⇒
*
Invoke a function without arguments
- isArray(val) ⇒
boolean
Determine if value is array
- isBoolean(val) ⇒
boolean
Determine if value is boolean;
- isEmpty(val) ⇒
boolean
Check whether object, array, or string is empty
- isFunction(val) ⇒
boolean
Determine if value is function
- isNaN(val) ⇒
boolean
Determine if value is NaN
- isNull(val) ⇒
boolean
Determine if value is null
- isNumber(val) ⇒
boolean
Determine if value is function
- isObject(val) ⇒
boolean
Detemine if value is object
- isPromise(val) ⇒
boolean
Take a value and determine if it is a promise
- isPropertyOf(key, obj) ⇒
boolean
Determine if string is property of object
- isString(val) ⇒
boolean
Determine if value is string
- isUndefined(val) ⇒
boolean
Determine if value is undefined
- iterate(fn, len) ⇒
Array
Return array of function iterations of specified length generated from 0-based index
- joinBy(delimiter, arr) ⇒
function
|string
Join array to string, delimited by other string
- lt(a, b) ⇒
function
|boolean
Determine if value is less than other value
- lte(a, b) ⇒
function
|boolean
Determine if value is less than or equal to other value
- mapBy(fn, arr) ⇒
function
|Array
Map elements in an array by function
- maybe(fn, val) ⇒
function
|*
Execute a function if the argument is not null or undefined
- memoize(fn, [function]) ⇒
function
Cache return contents of functions
- merge(...args) ⇒
Object
Returns new object, which is a shallow merge of multiple objects
- multiply(a, b) ⇒
function
|number
Multiply two numbers together
- none(...args) ⇒
boolean
Returns true if no argument or array value is true
- noop() ⇒
undefined
Executes a noop
- not(val) ⇒
boolean
|function
Returns false if truthy, true if falsy, negation if function
- notEquals(a, b) ⇒
function
|boolean
Return true if two values are not equal
- or(...args) ⇒
boolean
Determine if at least one argument or array value is truthy
- orWith(args, val) ⇒
boolean
|function
Take an array of functions (or values) and determine if one result is true given value
- orderBy(template, src) ⇒
function
|Array
Generate array based on template of indexes and source
- power(exponent, base) ⇒
function
|number
Return exponent from one number to another
- prependTo(str, append) ⇒
function
|string
Prepend string to the beginning of another string
- reduceBy(fn, accumulator, arr) ⇒
function
|*
Reduce array to new value by function
- replaceWith(search, rep, str) ⇒
string
|function
Replace search with new value in string
- reverse(fn) ⇒
function
Take a function and return a function which accepts args in reverse order
- setProp(prop, value, obj) ⇒
function
|Object
Returns a copy of an object with a new name / value pair
- sliceFrom(start, end, val) ⇒
function
|Array
|string
Slice an array or string
- someBy(fn, arr) ⇒
function
|boolean
Determine if at least one value in array satisfy function
- splitBy(search, str) ⇒
function
|Array
Split string to array by another string
- spread(...args) ⇒
Array
Convert argument list to array (alias args)
- subtract(a, b) ⇒
function
|number
Subtract one number from another
- ternary(failure, success, predicate) ⇒
*
Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result.
- ternaryL(predicate, success, failure) ⇒
*
Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result.
- ternaryWith(failure, success, predicate, val) ⇒
*
Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result with passed in parameter;
- toArray(...args) ⇒
Array
Force args to array if not arrays
- toBoolean(value) ⇒
boolean
Returns boolean value and converts string 'false' to false
- toFunction(value) ⇒
function
Returns function which returns value if value is not a function.
- toNumber(value) ⇒
number
Parses int or float or Infinity to numeric value
- toObject(value) ⇒
Object
Forces value into object. If not object, returns {}
- toPromise(val) ⇒
Promise
Take a value and if not a promise, make it a promise
- toString(value) ⇒
string
Converts value to string. Converts undefined to empty string.
- traverse(obj, path) ⇒
*
Safely traverse object nested properties
- traverseR(path, obj) ⇒
*
Safely traverse object nested properties
- typeOf(val) ⇒
string
Returns typeof value
number
add(a, b) ⇒ Add two numbers
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number |
b | number |
Example
; //=> 3 3; //=> 5
boolean
and(...args) ⇒ Determine if all arguments are truthy or if array is truthy
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
...args | * |
Example
; //=> true ; //=> true ; //=> false
boolean
| function
andWith(fns, val) ⇒ Take an array of functions (or values) and determine if all results are true given value
Kind: global function
Since: 1.10.0
Param | Type |
---|---|
fns | Array |
val | * |
Example
const foo = val < 10; const bar = val > 5; ; //=> true 1; //=> false
function
| string
appendTo(str, append) ⇒ Append string to the end of another string
Kind: global function
Since: 1.13.0
Param | Type |
---|---|
str | string |
append | string |
Example
; //=> 'foobar' 'baz'; //=> 'barbaz'
function
| array
apply(fns, vals) ⇒ Apply functions from an array to corresponding index in other array
Kind: global function
Since: 1.11.0
Param | Type |
---|---|
fns | Array |
vals | Array |
Example
const add1 = a + 1; const add2 = a + 2; ; //=> [1, 2]; 1 2 3; //=> [2, 2, 3];
Array
args(...vals) ⇒ Returns an array of passed arguments
Kind: global function
Since: 1.16.0
Param | Type |
---|---|
...vals | * |
Example
; //=> [1, 2, [3, 4]]
*
at(index, val) ⇒ Returns copy of entry or character at given index in string or array
Kind: global function
Since: 1.5.0
Param | Type |
---|---|
index | number |
val | Array | string |
Example
; //=> 'o' 0 1 2; //=> 1
*
attempt(toTry, onError) ⇒ Attempt something. If an error is thrown, return something else. (Wrapper for try / catch)
Kind: global function
Since: 1.7.0
Param | Type |
---|---|
toTry | * |
onError | * |
Example
; //=> false ; //=> 5
function
bindTo(fn, ...args) ⇒ Takes a function and arguments. Leaves undefined arguments unbound and binds defined arguments to their position in arguments list.
Kind: global function
Since: 1.8.0
Param | Type |
---|---|
fn | function |
...args | * |
Example
const foo = a b c = a + b + c; 3; //=> 6 1; //=> 4 1 2; //=> 6 11; //=> 3
function
call(fn, arr) ⇒ Execute function with array as arguments
Kind: global function
Since: 1.17.0
Param | Type |
---|---|
fn | function |
arr | Array |
Example
const foo = a + b; //=> 3 2 3 //=> 5
*
callback(cb, predicate) ⇒ Take two arguments and if second argument is truthy, return first.
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
cb | * |
predicate | * |
Example
; //=> 'foo' ; //=> null
*
callbackWith(cb, predicate, val) ⇒ Take two arguments and if second argument is truthy, return first based on val
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
cb | * |
predicate | * |
val | * |
Example
; //=> 3 ; //=> null
function
concat(val) ⇒ Returns a function which accepts no params and returns the passed value
Kind: global function
Since: 1.16.0
Param | Type |
---|---|
val | * |
Example
; //=> () = 6;
function
compose(...args) ⇒ Compose functions from right to left
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
...args | function |
Example
; //=> val => val + 3
function
composeL(...args) ⇒ Compose functions from right to left
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
...args | function |
Example
; //=> val => val + 3
function
| Array
concat(...args) ⇒ Returns a new array, which is a merge of at least two arrays
Kind: global function
Since: 1.16.0
Param | Type |
---|---|
...args | Array |
Example
const1 2 3 4; //=> [1, 2, 3, 4]
function
| *
curry(fn, ...args) ⇒ Curry arguments to function and return new function
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
fn | function |
...args | * |
Example
const foo = a + b + c; 3; //=> 6 3 4; //=> 8 34; //=> 9 111; // => 3
boolean
| function
deepEquals(a, b) ⇒ Allow comparison of two objects or arrays
Kind: global function
Since: 1.4.0
Param | Type |
---|---|
a | * |
b | * |
Example
; //=> true ; //=> true
*
defaultTo(def, val) ⇒ Sets default value if passed value is falsy
Kind: global function
Since: 1.2.0
Param | Type |
---|---|
def | * |
val | * |
Example
; //=> 5 4; //=> 4
function
| *
define(fn) ⇒ Take a function with a known signature and allow arguments to be passed until it executes
Kind: global function
Update:
Since: 1.0.0
Param | Type |
---|---|
fn | function |
Example
const foo = a + b + c; const bar = ; ; // (b, c) => 1 + b + c 2; // c => 1 + 2 + c 23; // 6
number
| function
divide(a, b) ⇒ Divide two numbers
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number |
b | number |
Example
; //=> 3 2; //=> 2
boolean
| function
equals(a, b) ⇒ Determine if two values are equal
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | * |
b | * |
Example
; //=> true 2; //=> false
function
| boolean
everyBy(fn, arr) ⇒ Determine if all values in array satisfy function
Kind: global function
Since: 1.17.0
Param | Type |
---|---|
fn | function |
arr | Array |
Example
const isTrue = val === true; //=> true true false //=> false
boolean
| function
excludes(search, val) ⇒ Returns true if string is not in string or array
Kind: global function
Since: 1.4.0
Param | Type |
---|---|
search | string | number |
val | string | Array |
Example
; //=> false 'apple'; //=> false
function
| *
executeWith(val, fn) ⇒ Create a function which executes a function based on a defined value
Kind: global function
Since: 1.11.0
Param | Type |
---|---|
val | * |
fn | function |
Example
const addOne = a + 1; ; //=> 2 addOne; //=> 3
function
executeWith(fn, ...args) ⇒ Create a function which executes a function with each arg being transformed by a function
Kind: global function
Since: 1.11.0
Param | Type |
---|---|
fn | function |
...args | * |
Example
const foo = a + b; const add1 = a + 1; const add2 = b + 2; 0 0; //=> 3 0 0; //=> 1
function
| arr
fillBy(val, arr) ⇒ Fill an array with a defined value
Kind: global function
Since: 1.17.0
Param | Type |
---|---|
val | val |
arr | Array |
Example
; //=> [1, 1] undefined undefined; //=> [2, 2]
function
| Array
filterBy(fn, arr) ⇒ Filter elements in an array by function
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
fn | function |
arr | Array |
Example
const foo = val < 3; ; //=> [1, 2] 23; //=> [2]
Array
getEmptyArr() ⇒ Returns an empty array
Kind: global function
Since: 1.16.0
Example
; //=> []
Object
getEmptyObj() ⇒ Returns an empty object
Kind: global function
Since: 1.16.0
Example
; //=> {}
function
| Object
getObject(prop, value) ⇒ Get an object with single property and value
Kind: global function
Since: 1.15.0
Param | Type |
---|---|
prop | string | number |
value | * |
Example
; //=> { a: 1 } 2; //=> { b: 2 }
function
| *
getProp(prop, obj) ⇒ Get property of an object
Kind: global function
Since: 1.15.0
Param | Type |
---|---|
prop | string | number |
obj | Object |
Example
; //=> 1 b: 2 ; //=> 2
function
| boolean
gt(a, b) ⇒ Determine if first value is greater than
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number | string |
b | number | string |
Example
; //=> true 'c'; //=> false
function
| boolean
gte(a, b) ⇒ Determine if value is greater than or equal to other value
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number | string |
b | number | string |
Example
; //=> true 'a'; //=> true
function
| boolean
has(obj, key) ⇒ Return true if object has key
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
obj | Object |
key | string |
Example
; //=> true 'a'; //=> true 'b'; //=> false
*
identity() ⇒ A function which returns whatever is passed into it
Kind: global function
Params: *
val
Since: 1.5.0
Example
; //=> 5 ; //=> {}
boolean
| function
includes(search, val) ⇒ Returns true if string is in string or array
Kind: global function
Since: 1.4.0
Param | Type |
---|---|
search | string | number |
val | string | Array |
Example
; //=> true 'apple'; //=> true
*
invoke(fn) ⇒ Invoke a function without arguments
Kind: global function
Since: 1.18.0
Param | Type |
---|---|
fn | function |
Example
var 1; ; //=> 1;
boolean
isArray(val) ⇒ Determine if value is array
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
boolean
isBoolean(val) ⇒ Determine if value is boolean;
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> false ; //=> true
boolean
isEmpty(val) ⇒ Check whether object, array, or string is empty
Kind: global function
Since: 1.5.0
Param | Type |
---|---|
val | Object | Array | string |
Example
; //=> true ; //=> true ; //=> true
boolean
isFunction(val) ⇒ Determine if value is function
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> false ; //=> true
boolean
isNaN(val) ⇒ Determine if value is NaN
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | number |
Example
; //=> true ; //=> false
boolean
isNull(val) ⇒ Determine if value is null
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
boolean
isNumber(val) ⇒ Determine if value is function
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
boolean
isObject(val) ⇒ Detemine if value is object
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
boolean
isPromise(val) ⇒ Take a value and determine if it is a promise
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
boolean
isPropertyOf(key, obj) ⇒ Determine if string is property of object
Kind: global function
Since: 1.13.0
Param | Type |
---|---|
key | string |
obj | Object |
Example
; //=> true bar: 'b' ; //=> false
boolean
isString(val) ⇒ Determine if value is string
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true; ; //=> false;
boolean
isUndefined(val) ⇒ Determine if value is undefined
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> true ; //=> false
Array
iterate(fn, len) ⇒ Return array of function iterations of specified length generated from 0-based index
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
fn | function |
len | number |
Example
const foo = index + 1; ; //=> [1, 2, 3] 2; //=> [1, 2]
function
| string
joinBy(delimiter, arr) ⇒ Join array to string, delimited by other string
Kind: global function
Since: 1.13.0
Param | Type |
---|---|
delimiter | string |
arr | Array |
Example
; //=> 'foo.bar.baz' 1 2 3; //=> '1.2.3';
function
| boolean
lt(a, b) ⇒ Determine if value is less than other value
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number | string |
b | number | string |
Example
; //=> true 'b'; //=> true
function
| boolean
lte(a, b) ⇒ Determine if value is less than or equal to other value
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number | string |
b | number | string |
Example
; //=> true 'b'; //=> true
function
| Array
mapBy(fn, arr) ⇒ Map elements in an array by function
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
fn | function |
arr | Array |
Example
const foo = val + 1; ; //=> [2, 3] 4 5; //=> [5, 6]
function
| *
maybe(fn, val) ⇒ Execute a function if the argument is not null or undefined
Kind: global function
Since: 1.23.0
Author: oculus42
Param | Type |
---|---|
fn | function |
val | * |
Example
const foo = val + 1; ; //=> 2 null; //=> null
function
memoize(fn, [function]) ⇒ Cache return contents of functions
Kind: global function
Since: 1.9.0
Param | Type | Description |
---|---|---|
fn | function |
Function to templatize |
[function] | template - Function to determine cache key |
Object
merge(...args) ⇒ Returns new object, which is a shallow merge of multiple objects
Kind: global function
Since: 1.16.0
Param | Type |
---|---|
...args | Object |
Example
; //=> { a: 1, b: 2 }
function
| number
multiply(a, b) ⇒ Multiply two numbers together
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number |
b | number |
Example
; //=> 6 2; //=> 4
boolean
none(...args) ⇒ Returns true if no argument or array value is true
Kind: global function
Since: 1.4.0
Param | Type |
---|---|
...args | * |
undefined
noop() ⇒ Executes a noop
Kind: global function
Since: 1.5.0
boolean
| function
not(val) ⇒ Returns false if truthy, true if falsy, negation if function
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
val | * |
Example
const identity = a; ; //=> false ; //=> true true; //=> false
function
| boolean
notEquals(a, b) ⇒ Return true if two values are not equal
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
a | * |
b | * |
Example
; //=> true 4; //=> true
boolean
or(...args) ⇒ Determine if at least one argument or array value is truthy
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
...args | * |
Example
; //=> true ; //=> true
boolean
| function
orWith(args, val) ⇒ Take an array of functions (or values) and determine if one result is true given value
Kind: global function
Since: 1.10.0
Param | Type |
---|---|
args | Array |
val | * |
Example
const foo = val > 10; const bar = val < 5; ; //=> false 1; //=> true
function
| Array
orderBy(template, src) ⇒ Generate array based on template of indexes and source
Kind: global function
Since: 1.19.0
Param | Type |
---|---|
template | Array |
src | Array |
Example
; //=> ['b', 'c', 'a']; 'd' 'e' 'f'; //=> ['f', 'd', 'e'];
function
| number
power(exponent, base) ⇒ Return exponent from one number to another
Kind: global function
Since: 1.20.0
Param | Type |
---|---|
exponent | number |
base | number |
Example
; //=> 9 2; //=> 4
function
| string
prependTo(str, append) ⇒ Prepend string to the beginning of another string
Kind: global function
Since: 1.13.0
Param | Type |
---|---|
str | string |
append | string |
Example
; //=> 'barfoo' 'baz'; //=> 'bazbar'
function
| *
reduceBy(fn, accumulator, arr) ⇒ Reduce array to new value by function
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
fn | function |
accumulator | * |
arr | Array |
Example
const foo = acc val = acc + val; ; //=> 3 2 2; //=> 6 33 3; //=> 9
string
| function
replaceWith(search, rep, str) ⇒ Replace search with new value in string
Kind: global function
Since: 1.6.0
Param | Type |
---|---|
search | string | RegExp |
rep | string |
str | string |
Example
; //=> 'boo' 'a''foo'; //=> 'faa'
function
reverse(fn) ⇒ Take a function and return a function which accepts args in reverse order
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
fn | function |
Example
const foo = a + b - c; ; //=> (c)(b)(a) => c + b - a;
function
| Object
setProp(prop, value, obj) ⇒ Returns a copy of an object with a new name / value pair
Kind: global function
Since: 1.21.0
Param | Type |
---|---|
prop | string | number |
value | * |
obj | Object |
Example
; //=> { a: 1 } 2{}; //=> { b: 2 }
function
| Array
| string
sliceFrom(start, end, val) ⇒ Slice an array or string
Kind: global function
Since: 1.17.1
Param | Type |
---|---|
start | number |
end | number |
val | Array | string |
Example
//=> [0];
function
| boolean
someBy(fn, arr) ⇒ Determine if at least one value in array satisfy function
Kind: global function
Since: 1.17.0
Param | Type |
---|---|
fn | function |
arr | Array |
Example
const isTrue = val === true; //=> true false false //=> false
function
| Array
splitBy(search, str) ⇒ Split string to array by another string
Kind: global function
Since: 1.13.0
Param | Type |
---|---|
search | string |
str | string |
Example
; //=> ['foo', 'bar', 'baz'] '1,2,3'; //=> ['1', '2', '3'];
Array
spread(...args) ⇒ Convert argument list to array (alias args)
Kind: global function
Since: 1.17.0
Param | Type |
---|---|
...args | * |
Example
; //=> [1, 2, 3]
function
| number
subtract(a, b) ⇒ Subtract one number from another
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
a | number |
b | number |
Example
; //=> 1 1; //=> 1
*
ternary(failure, success, predicate) ⇒ Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result.
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
failure | * |
success | * |
predicate | * |
Example
; //=> 2 ; //=> 1
*
ternaryL(predicate, success, failure) ⇒ Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result.
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
predicate | * |
success | * |
failure | * |
Example
; //=> 1 ; //=> 2
*
ternaryWith(failure, success, predicate, val) ⇒ Return success or failure based on predicate evaluation. If success or failure are functions, returns executed result with passed in parameter;
Kind: global function
Since: 1.9.0
Param | Type |
---|---|
failure | * |
success | * |
predicate | * |
val | * |
Example
const foo = val + 1; const bar = val - 1; ; //=> 4 ; //=> 1
Array
toArray(...args) ⇒ Force args to array if not arrays
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
...args | * |
Example
; //=> [1, 2] ; //=> [2, 3]
boolean
toBoolean(value) ⇒ Returns boolean value and converts string 'false' to false
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
value | * |
Example
; //=> false ; //=> true
function
toFunction(value) ⇒ Returns function which returns value if value is not a function.
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
value | * |
Example
; //=> () => 3 ; //=> () => 1
number
toNumber(value) ⇒ Parses int or float or Infinity to numeric value
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
value | * |
Example
; //=> Infinity ; //=> 1 ; //=> NaN
Object
toObject(value) ⇒ Forces value into object. If not object, returns {}
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
value | * |
Example
; //=> { a: 1 } ; //=> null ; //=> {}
Promise
toPromise(val) ⇒ Take a value and if not a promise, make it a promise
Kind: global function
Since: 1.1.0
Param | Type |
---|---|
val | * |
Example
const foo = ; foo; //=> 5;
string
toString(value) ⇒ Converts value to string. Converts undefined to empty string.
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
value | * |
Example
; //=> 'foo' ; //=> 'false' ; //=> ''
*
traverse(obj, path) ⇒ Safely traverse object nested properties
Kind: global function
Since: 1.6.0
Param | Type |
---|---|
obj | Object |
path | Array.<string> |
Example
; //=> undefined 'a'; //=> 1
*
traverseR(path, obj) ⇒ Safely traverse object nested properties
Kind: global function
Since: 1.14.0
Param | Type |
---|---|
path | Array.<string> |
obj | Object |
Example
; //=> undefined a: 1 ; //=> 1
string
typeOf(val) ⇒ Returns typeof value
Kind: global function
Since: 1.0.0
Param | Type |
---|---|
val | * |
Example
; //=> 'object' ; //=> 'undefined' ; //=> 'number'