adjust(idx, fn, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> (a -> a) -> [a] -> [a]
Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application.
Parameters
| Name | Type | Description |
|---|
idx | Number | The index the value we want to change is at |
fn | function | The function to apply |
list | Array | The array of data |
Returns
| Type | Description |
|---|
| Array | A copy of the supplied array with the element at index `idx` replaced with the value returned by applying `fn` to the existing element. |
import { adjust, inc, toUpper } from 'kyanite'
adjust(1, inc, [0, 1, 2, 3])
adjust(1, toUpper, ['a', 'b', 'c'])
const fn = adjust(1)
fn(toUpper, ['a', 'b', 'c'])
chunk(size, data) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes an array of data and chunks it into smaller arrays based on the size param passed in
Parameters
| Name | Type | Description |
|---|
size | Number | The size the inner arrays should be |
data | Array | The array of data to chunk out |
Returns
| Type | Description |
|---|
| Array | A new array of arrays containing the chunked data |
import { chunk } from 'kyanite'
chunk(2, [1, 2, 3, 4, 5, 6])
chunk(2, [1, 2, 3, 4, 5])
const fn = chunk(2)
fn([1, 2, 3, 4, 5, 6])
fn([1, 2, 3, 4, 5])
concatMap(fn, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Take an array and concats the values into a new array after applying the function
Parameters
| Name | Type | Description |
|---|
fn | function | The function to be applied to each value |
arr | Array | The array to concat together |
Returns
| Type | Description |
|---|
| Array | A newly created array of the concated values |
import { concatMap, identity } from 'kyanite'
concatMap(x => [x, x], [1, 2, 3])
concatMap(identity, [[1, 2], [3, 4], [5, 6]])
const con = concatMap(x => [x, x])
con([1, 2, 3])
countBy(fn, arr) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> String) -> [a] -> {*}
Counts the elements of a list according to how many match each value of a key generated by the supplied function
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply to each piece of data during iteration |
arr | Array | The array to iterate and count through |
Returns
| Type | Description |
|---|
| Object | A new object of counted values { value: count } |
import { countBy } from 'kyanite'
const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]
const letters = ['a', 'b', 'A', 'a', 'B', 'c']
countBy(Math.floor, numbers)
countBy(x => x.toLowerCase(), letters)
const fn = countBy(Math.floor)
fn(numbers)
difference(arrs) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a new array of values that are not contained within any of the arrays
Parameters
| Name | Type | Description |
|---|
arrs | Array | The array of arrays we want to get the difference of |
Returns
| Type | Description |
|---|
| Array | An array of elements that are not present in all of the arrays |
import { difference } from 'kyanite'
difference([[1, 2, 3], [1]])
difference([[1], [1, 2, 3]])
difference([[1], [1, 2, 3], [2, 4]])
drop(i, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Starts at a at desired index and pulls the values from that point until the end
Parameters
| Name | Type | Description |
|---|
i | Number | The index we want the slice to start at |
list | Array | The array we want to drop from |
Returns
| Type | Description |
|---|
| Array | An array with the indicated values removed from the array |
import { drop } from 'kyanite'
drop(3, [1, 2, 3, 4, 5])
drop(6, [1, 2, 3, 4, 5])
drop(-1, [1, 2, 3, 4, 5])
const d = drop(3)
d([1, 2, 3, 4, 5])
dropLast(n, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a list containing all but the last n elements of the given list.
Parameters
| Name | Type | Description |
|---|
n | Number | The number of values we want to drop |
list | Array | The array we want to drop from |
Returns
| Type | Description |
|---|
| Array | An array with the indicated values removed from the array |
import { dropLast } from 'kyanite'
dropLast(3, [1, 2, 3, 4, 5])
const d = dropLast(3)
d([1, 2, 3, 4, 5])
dropWhile(fn, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> [a]
Runs through an array and drops values so long as the function used returns true once the function returns false iteration will stop
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply per iteration |
arr | Array | The array of data to iterate through |
Returns
| Type | Description |
|---|
| Array | A new array without the dropped values |
import { dropWhile } from 'kyanite'
dropWhile(x => x <= 2, [1, 2, 3, 4, 3, 2, 1])
const fn = dropWhile(x => x <= 2)
fn([1, 2, 3, 4, 3, 2, 1])
fn([-1, 0, 1, 2, 3])
ensureArray(x) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Ensures that the value passed in is an array, if not it will make it an array or
pass back an empty array if the value if undefined/null
Parameters
| Name | Type | Description |
|---|
x | Any | The value to ensure |
Returns
| Type | Description |
|---|
| Array | Returns a new array |
import { ensureArray } from 'kyanite'
ensureArray(1)
ensureArray()
ensureArray(null)
ensureArray('test')
every(fn, data) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> Boolean
Loops through a provided list verifying that every value evaluates to a truthy value.
Parameters
| Name | Type | Description |
|---|
fn | function | The function to send our values to for validation |
data | Array | The list we are to loop through |
Returns
| Type | Description |
|---|
| Boolean | If all values passed will return true else false |
import { every } from 'kyanite'
const data = [1, 2, 3, 4]
every(x => x > 0, data)
every(x => x < 3, data)
const run = every(x => x > 0)
run([1, 2, 3])
run([-1, 0, 1])
everyPass(fns, data) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[(a -> Boolean)] -> a -> Boolean
Takes a value and passes it through an array of functions until the end of the array or one of the functions returns false
Parameters
| Name | Type | Description |
|---|
fns | Array | The array of functions to pass the value to |
data | Any | The data value to give to each function |
Returns
| Type | Description |
|---|
| Boolean | Based on if all the functions pass or not |
import { everyPass } from 'kyanite'
everyPass([x => x > 2, x => x < 4], 3)
everyPass([x => x > 7, x => x < 3], 5)
const fn = everyPass([x => x > 0, x => x < 4])
fn(3)
fn(2)
fn(0)
filter(fn, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> [a]
Filter through a filterable data piece using the provided function
Parameters
| Name | Type | Description |
|---|
fn | function | The predicate function to run on our values |
arr | Array | The filterable list to go through |
Returns
| Type | Description |
|---|
| Array | Returns a new Array based on the type of list provided |
import { filter } from 'kyanite'
const isEven = n => n % 2 === 0
filter(isEven, [1, 2, 3, 4])
const filterer = filter(isEven)
filterer([1, 2, 3, 4])
find(fn, arr) → {Maybe}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> Maybe a
Find an item based on the function sent in and its list
Parameters
| Name | Type | Description |
|---|
fn | function | The function used/called during the find |
arr | Array | The list we want to search through |
Returns
| Type | Description |
|---|
| Maybe | Returns either the found item, or undefined if no item is found |
import { find } from 'kyanite'
find(v => v.val === 'none', [{val: 'test'}, {val: 'none'}])
find(v => v > 2, [1, 2, 3, 4, 5])
const fn = find(v => v.val === 'test')
fn([{val: 'test'}, {val: 'none'}])
findIndex(fn, list) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> Maybe
Runs through an array of values, until it finds the index of one that passes the function, else returns -1
Parameters
| Name | Type | Description |
|---|
fn | function | The function to test our value against |
list | Array | The array to loop through |
Returns
| Type | Description |
|---|
| Number | The index the passing value lives at or -1 if it's not found |
import { findIndex } from 'kyanite'
findIndex(x => x > 5, [1, 3, 4, 5, 6])
findIndex(x => x < 0, [1, 3, 4, 5, 6])
const f = findIndex(x => x > 5)
f([1, 2, 3, 4, 5, 6])
fold(fn, arr) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> acc -> b) -> [a] -> b
Takes an array and folds it using a function, basically a reduce without the need to send an initial accumulator value
Parameters
| Name | Type | Description |
|---|
fn | function | The function used/called during the fold |
arr | Array | The array we want to fold/reduce down |
Returns
| Type | Description |
|---|
| Any | A value based on the results of the function |
import { fold } from 'kyanite'
fold((a, acc) => a <= acc ? a : acc, [5, 6, 3, 9, 1])
fold((a, acc) => a + acc, [1, 2, 3, 4, 5])
const fn = fold((a, acc) => a <= acc ? a : acc)
fn([5, 4, 19, 20, 32, 1])
fn(['z', 'x', 'd', 'p'])
fromPairs(pairs) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes an array of arrays which contain key value pairs and builds a new object
Parameters
| Name | Type | Description |
|---|
pairs | Array | And array of arrays containing key value pairing |
Returns
| Type | Description |
|---|
| Object | A new object built from the provided key value pairs |
import { fromPairs } from 'kyanite'
fromPairs([['a', 1], ['b', 2], ['c', 3]]
fromPairs([[1, 'a'], [2, 'b']])
fromPairs([])
fromPairs([[]])
groupBy(fn, list) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> String) -> [a] -> { String: [a] }
Groups values of an array based on the function passed in
Parameters
| Name | Type | Description |
|---|
fn | function | The function to run our values through |
list | Array | The array to go through |
Returns
| Type | Description |
|---|
| Object | An object with the grouped values |
import { groupBy } from 'kyanite'
groupBy(Math.floor, [4.2, 6.1, 6.4])
const g = groupBy(Math.floor)
g([4.2, 6.1, 6.4])
insert(i, d, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Insert an item in a certain index of an array
Parameters
| Name | Type | Description |
|---|
i | Number | The index number to remove from |
d | Any | The data we are going to be inserting |
arr | Array | The array to insert into |
Returns
| Type | Description |
|---|
| Array | A new array with the inserted data |
import { insert } from 'kyanite'
insert(2, 'x', [1, 2, 3, 4])
const ins = insert(2)
ins('x', [1, 2, 3, 4])
intersection(a, b) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns an array containing elements present in both arrays
Parameters
| Name | Type | Description |
|---|
a | Array | Our first array value to compare with |
b | Array | Our second array value to compare with |
Returns
| Type | Description |
|---|
| Array | A new array containing values that both arrays had |
import { intersection } from 'kyanite'
intersection([1, 2, 3, 4], [3, 4, 5, 6])
const inter = intersection([1, 2, 3, 4])
inter([3, 4, 5, 6])
join(str, list) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Joins together an array of strings with whatever string was passed in
Parameters
| Name | Type | Description |
|---|
str | String | The string we want to use for the join |
list | Array | The array to join |
Returns
| Type | Description |
|---|
| String | The joined string |
import { join } from 'kyanite'
join(' ', ['test', 'this', 'thing'])
join('aaa', ['test', 'that', 'thing'])
const j = join(' ')
j(['test', 'this', 'thing'])
j(['test', 'that', 'thing'])
juxt(fns, x) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[(a, b, ...) -> c] -> [a, b, ...] -> [[c]]
Applies the provided function and turns them into a single function you can use on a value
Parameters
| Name | Type | Description |
|---|
fns | Array | An array of functions to apply |
x | Array | The data to map our functions against |
Returns
| Type | Description |
|---|
| Array | An array of results from the ran functions |
import { juxt } from 'kyanite'
juxt([Math.min, Math.max], [3, 6, -7, 1])
const getRange = juxt([Math.min, Math.max])
getRange([3, 4, 9, -3])
map(fn, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes a function and applies it to all of the values within the provided list,
and brings back a new list of the same type.
Parameters
| Name | Type | Description |
|---|
fn | function | The function to run against the values in our functor |
list | Array | The list to iterate through |
Returns
| Type | Description |
|---|
| Array | The new Array or Object that was created |
import { map } from 'kyanite'
const dbl = n => n * 2
map(dbl, [1, 2, 3])
const dbler = map(dbl)
dbler([1, 2, 3])
max(list) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[Number|String] -> Number|String
Iterates through an array to find the max value
Parameters
| Name | Type | Description |
|---|
list | Array | The Array to iterate through |
Returns
| Type | Description |
|---|
| Any | The found or "deemed" maximum value of the array |
import { max } from 'kyanite'
max([1, 3, 2, 5, 4])
max(['c', 'a', 'b', 'f'])
maxBy(fn, list) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Finds the maximum value in an array by applying a provided function to the value first before comparing it
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply to each value of the array |
list | Array | The Array to iterate through |
Returns
| Type | Description |
|---|
| Any | The found or "deemed" maximum value of the array |
import { maxBy } from 'kyanite'
maxBy(x => x.size, [{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }])
maxBy(x => x.alpha, [{ alpha: 'b' }, { alpha: 'c' }, { alpha: 'a' }])
const m = maxBy(x => x.size)
m([{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }])
min(list) → {Any}
- Since:
- Kind:
- Source:
- Category:
Iterates through an array to find the min value
Parameters
| Name | Type | Description |
|---|
list | Array | The Array to iterate through |
Returns
| Type | Description |
|---|
| Any | The found or "deemed" minimum value of the array |
import { min } from 'kyanite'
min([1, 3, 2, 5, 4])
min(['c', 'a', 'b', 'f'])
minBy(fn, list) → {Any}
- Since:
- Kind:
- Source:
- Category:
Finds the minimum value in an array by applying a provided function to the value first before comparing it
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply to each value of the array |
list | Array | The Array to iterate through |
Returns
| Type | Description |
|---|
| Any | The found or "deemed" minimum value of the array |
import { minBy } from 'kyanite'
minBy(x => x.size, [{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }])
minBy(x => x.alpha, [{ alpha: 'b' }, { alpha: 'c' }, { alpha: 'a' }])
const m = minBy(x => x.size)
m([{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }])
partition(fn, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Filterable f => (a -> Boolean) -> f a -> [f a, f a]
Takes a predicate function and an array of data and returns the pair
One contains the data which passes the predicate function, the other is the values that did not
Parameters
| Name | Type | Description |
|---|
fn | function | The predicate function to check each of the values |
list | Array | The array to partition out |
Returns
| Type | Description |
|---|
| Array | An array containing the first set of elements that passed the predicate function,
And a second that did not |
import { partition } from 'kyanite'
partition(is(String), ['foo', 'bar', 100])
const part = partition(is(String))
part(['foo', 'bar', 100])
pluck(p, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a new array by plucking the same named property off all objects in the array supplied
Parameters
| Name | Type | Description |
|---|
p | String | Number | The key to pluck the value of |
list | Array | The list of objects to map through |
Returns
| Type | Description |
|---|
| Array | A new array of values plucked from our original list |
import { pluck } from 'kyanite'
pluck('age', [{ name: 'george', age: 19 }, { name: 'gavin', age: 26 }])
pluck(0, [[1, 2], [3, 4]])
const fn = pluck('age')
fn([{ name: 'george', age: 19 }, { name: 'gavin', age: 26 }])
prepend(x, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a new list with the provided value at the front of the given list
Parameters
| Name | Type | Description |
|---|
x | Any | The value we want to put at the front of our list |
list | Array | The Array or list to prepend to |
Returns
| Type | Description |
|---|
| Array | A new array |
import { prepend } from 'kyanite'
prepend('testing', ['is', 'cool'])
const pender = prepend('testing')
pender(['is', 'cool'])
reduceRight(fn, acc, arr) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
((a, b) -> b) -> b -> [a] -> b
Similar to reduce except this moves through the array starting from the right
The reducer function accepts the params a bit differently than the vanilla counterpart
As the reducer should expect the value first, and the accumulator second
Parameters
| Name | Type | Description |
|---|
fn | function | The iterator function to call for the reduce |
acc | Any | The init value to start the accumulator at |
arr | Array | The Array to reduce |
Returns
| Type | Description |
|---|
| Any | The new accumulated value |
import { reduceRight } from 'kyanite'
reduceRight((n, acc) =>
typeof n === 'number' ? acc.push(n) : acc, [], ['', 1, 2, '0', 3])
const fn = reduceRight((x, acc) => typeof n === 'number' ? acc.push(n) : acc)
fn([], ['', 1, 2, '0', 3])
reject(fn, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> Array [a] -> Array [a]
Iterate through a list and reject any value that does not pass the provided function
Parameters
| Name | Type | Description |
|---|
fn | function | The predicate function to run on our values |
arr | Array | The filterable list to go through |
Returns
| Type | Description |
|---|
| Array | Returns a new Array of values that were not rejected |
import { reject } from 'kyanite'
const isEven = n => n % 2 === 0
reject(isEven, [1, 2, 3, 4])
reject(x => x.val > 2, [{ val: 2 }, { val: 5 }, { val: 3 }])
const rejecter = reject(isEven)
rejecter([1, 2, 3, 4])
remove(i, x) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Remove an item from a certain point in the index
Parameters
| Name | Type | Description |
|---|
i | Number | The index number to remove from |
x | Array | The array in question |
Returns
| Type | Description |
|---|
| Array | returns the modified array back |
import { remove } from 'kyanite'
const test = remove(2, [1, 2, 3, 4])
const remover = remove(2)
const test = remover([1, 2, 3, 4])
some(fn, arr) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [a] -> Boolean
Loops through a provided list verifying that at least some values evaluates to a truthy value.
Parameters
| Name | Type | Description |
|---|
fn | function | The function to send our values to for validation |
arr | Array | The list we are to loop through |
Returns
| Type | Description |
|---|
| Boolean | If any values passed will return true else false |
import { some } from 'kyanite'
const data = [1, 2, 3, 4]
some(x => x > 0, data)
some(x => x < 3)
some(x => x < 0, data)
const run = some(x => x > 0)
run([1, 2, 3])
run([-1, 0, 1])
run([-3, -2, -1])
somePass(fns, data) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[(a -> Boolean)] -> a -> Boolean
Takes a value and passes it through an array of functions until a function returns true, or the end of the array is met
Parameters
| Name | Type | Description |
|---|
fns | Array | The array of functions to pass the value to |
data | Any | The data value to give to each function |
Returns
| Type | Description |
|---|
| Boolean | If any function passed then returns true, otherwise returns false |
import { somePass } from 'kyanite'
somePass([x => x > 2, x => x < 4], 3)
somePass([x => x > 7, x => x < 3], 5)
somePass([x => x === 4, x => x === 6], 5)
const fn = somePass([x => x > 0, x => x < 4])
fn(3)
fn(2)
fn(0)
sort(fn, a) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
((a, a) -> Number) -> Array a -> Array a
Uses a comparison function to sort an array
Parameters
| Name | Type | Description |
|---|
fn | function | The function used to sort the array |
a | Array | The array to be sorted |
Returns
| Type | Description |
|---|
| Array | A new sorted array |
import { sort } from 'kyanite'
sort((a, b) => a - b, [99, 23, 10, 53, 1])
const sorter = sort((a, b) => a - b)
sorter([99, 23, 10, 53, 1])
sorter([5, 3, 4, 6, 2, 1])
sortBy(fn, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Function -> Array -> Array
Sorts through an array of values using the provided function on each value
Parameters
| Name | Type | Description |
|---|
fn | function | The function to use on values within our array |
list | Array | The array to run through |
Returns
| Type | Description |
|---|
| Array | A newly sorted array |
import { sortBy } from 'kyanite'
sortBy(x => x.name, [
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
])
const sb = sortBy(x => x.name)
sb([
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
])
sortWith(fns, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(Array -> Function) -> Array -> Array
Sorts an array based on the functions passed it, will go through the functions in order
and use ties to the next function in order to break ties
Parameters
| Name | Type | Description |
|---|
fns | Array | An array of functions to sort with |
arr | Array | The array to be sorted |
Returns
| Type | Description |
|---|
| Array | A new and sorted array |
import { sortWith } from 'kyanite'
const data = [{name: 'alice', age: 40}, {name: 'bob', age: 30}, {name: 'clara', age: 40}]
sortWith([
descendBy(x => x.age),
ascendBy(x => x.name)
], data)
const ageNameSort = sortWith([
descendBy(x => x.age),
ascendBy(x => x.name)
])
ageNameSort(data)
take(i, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes the values from an array up until the point specified, then brings those values back
Parameters
| Name | Type | Description |
|---|
i | Number | The index we want our take to start at |
list | Array | The array we are taking from |
Returns
| Type | Description |
|---|
| Array | A new array of the values taken |
import { take } from 'kyanite'
take(3, [1, 2, 3, 4, 5])
const t = take(3)
t([1, 2, 3, 4, 5])
takeLast(n, list) → {Array, String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a new list containing the last n elements of the given list. If n > list.length, returns a list of list.length elements.
Parameters
| Name | Type | Description |
|---|
n | Number | The index we want our take to start at |
list | Array | String | The array we are taking from |
Returns
| Type | Description |
|---|
| Array | String | A new array of the values taken |
import { takeLast } from 'kyanite'
takeLast(3, [1, 2, 3, 4, 5])
const t = takeLast(3)
t([1, 2, 3, 4, 5])
takeWhile(fn, arr) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> Array [a] -> Array [a]
Takes values from an array and puts them into a new array while the function parameter returns true
Parameters
| Name | Type | Description |
|---|
fn | function | The function ran against each value within the array should return a boolean |
arr | Array | The array to take from |
Returns
| Type | Description |
|---|
| Array | A new array of data that passed the param function |
import { takeWhile } from 'kyanite'
takeWhile(x => x < 4, [1, 2, 3, 4, 5, 6])
const fn = takeWhile(x => x < 4)
fn([1, 2, 3, 4, 5])
fn([3, 4, 5])
union(a, rest) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Array a -> Array a -> Array a
Creates a union between two arrays, removing duplicates from each
Parameters
| Name | Type | Description |
|---|
a | Array | An array to put through combining |
rest | Array | The rest of the arrays |
Returns
| Type | Description |
|---|
| Array | A new array of unique values from each of the passed in arrays |
import { union } from 'kyanite'
union([1, 2, 3], [3, 4, 5])
union([1, 2, 3], [[3, 4, 5], [4, 5, 6]])
const un = union([1, 2, 3])
un([3, 4, 5])
un([[3, 4, 5], [4, 5, 6]])
uniq(list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b) -> Array a -> Array a
Returns an array of unique values from the applied function
Parameters
| Name | Type | Description |
|---|
list | Array | The list to sift through |
Returns
| Type | Description |
|---|
| Array | An array of uniq values from the provided function |
import { uniq } from 'kyanite'
uniq([1, 2, 2, 3, 3, 4, 5])
uniqBy(fn, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b) -> Array a -> Array a
Returns an array of unique values from the applied function
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply |
list | Array | The list to sift through |
Returns
| Type | Description |
|---|
| Array | An array of unique values from the provided function |
import { uniqBy } from 'kyanite'
uniqBy(x => x > 2, [1, 2, 3, 4, 5])
const uq = uniqBy(x => x > 2)
uq([1, 2, 3, 4, 5])
update(idx, val, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> a -> [b] -> [c]
Add an item to an array within a certain index of the array
Parameters
| Name | Type | Description |
|---|
idx | Number | The index number to add at |
val | Any | What we want to add to our array |
list | Array | The array in question |
Returns
| Type | Description |
|---|
| Array | Returns the modified array |
import { update } from 'kyanite'
update(1, 10, [1, 2, 3])
update(-1, 10, [1, 2, 3])
const updater = update(2, 10)
updater([1, 2, 3])
const index = update(2)
const val = index(10)
val([1, 2, 3])
zip(x, y) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes two arrays and combines them into a key value pair object
Parameters
| Name | Type | Description |
|---|
x | Array | The array that will act as keys |
y | Array | The array that will act as values |
Returns
| Type | Description |
|---|
| Object | The combined arrays key value pair |
import { zip } from 'kyanite'
zip(['a', 'b', 'c'], [1, 2, 3])
zip(['a', 'b', 'c'], [1, 2, 3, 4])
zip(['a', 'b', 'c'], [1, 2])
const z = zip(['a', 'b', 'c'])
z([1, 2, 3])
z([1, 2, 3, 4])
z([1, 2])
F() → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
A Function that will always return false, any given parameters are ignored
Returns
| Type | Description |
|---|
| Boolean | A boolean of false |
import { F } from 'kyanite'
F()
T() → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
A Function that will always return true, any given parameters are ignored
Returns
| Type | Description |
|---|
| Boolean | A boolean of true |
import { T } from 'kyanite'
T()
addIndex(fn) → {function}
- Since:
- Kind:
- Source:
- Category:
- Signature:
((a … → b) … → [a] → *) → ((a …, Int, [a] → b) … → [a] → *)
Creates a new function to iterate through an array, the provided function should be one that accepts a higher order function (such as reduce, filter, or map). It will then attach the index to the provided function upon calling it.
Parameters
| Name | Type | Description |
|---|
fn | function | The original function to add the index and list onto |
Returns
| Type | Description |
|---|
| function | A new function that will come with the index and full list attached. |
import { addIndex, filter, map, reduce } from 'kyanite'
const m = addIndex(map)
const f = addIndex(filter)
const r = addIndex(reduce)
const data = ['f', 'o', 'o', 'b', 'a', 'r']
m((x, i) => `${x}-${i}`, data)
f((_, i) => i > 2, data)
r((val, acc, i) => acc.concat(val + i), [], data)
always(a, _) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Always returns the first param sent to it, and ignores the 2nd also known as the K combinator
Parameters
| Name | Type | Description |
|---|
a | Any | The value we want to return |
_ | Any | The ignored parameter |
Returns
| Type | Description |
|---|
| Any | The first parameter passed in |
import { always } from 'kyanite'
always(false, true)
always(true, true)
always('dino', 'saur')
const fn = always('dino')
fn('')
and(a, b) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Runs an and comparison on the two values passed in
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Any | The evaluated outcome of the parameters |
import { and } from 'kyanite'
and(true, true)
and(true, false)
and(false, false)
ap(fn, gn, x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b -> c) -> (a -> b) -> a -> c
Takes a setter and getter function to transform provided data also known as the S combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The setter function for ap x => y => z |
gn | function | The getter function for ap x => y |
x | Any | The data that is given to the provided functions |
Returns
| Type | Description |
|---|
| Any | The results of running the S combinator functions |
import { ap } from 'kyanite'
const state = {
a: {
b: 2
}
}
ap(s => doubleB => ({
...s,
a: { b: doubleB }
}), s => s.a.b * 2, state)
const fn = ap(x => y => x + y, z => z * 2)
fn(2)
fn(3)
apply(fn, a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Applies a function to a parameter/argument. Useful for creating a fixed-arity function, also known as the A combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The function we want to apply to the data |
a | Any | The parameter to call the function with |
Returns
| Type | Description |
|---|
| Any | The result of whatever fn(a) will be |
import { apply } from 'kyanite'
apply(x => x * 2, 2)
const fn = apply(x => x * 2)
fn(2)
fn(100)
applyN(fn, a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b) -> Array [a] -> b
Applies a function to a parameter/argument. Useful for creating a fixed-arity function, also known as the A combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The function we want to apply to the data |
a | Array | The parameter(s) to call the function with |
Returns
| Type | Description |
|---|
| Any | The result of whatever fn(...a) will be |
import { applyN } from 'kyanite'
applyN(x => x * 2, [2])
applyN((a, b, c) => a + b + c, [1, 2, 3])
applyN(Math.max, [1, 2, 3, -99, 42, 6, 7])
const fn = applyN(x => x * 2)
fn([2])
fn([100])
ascend(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Determines which of the two passed in values should be ascended
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Number | A number based on which value should ascend |
import { ascend } from 'kyanite'
[4, 10, 1, 6, 7, 12].sort(ascend)
ascendBy(fn, a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Function -> Any -> Any -> Number
Can be used with sort to ascend an array based on the function passed in
Parameters
| Name | Type | Description |
|---|
fn | function | The function to use on values within our array |
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Number | A number based on where it falls when compared with the other value |
import { ascendBy } from 'kyanite'
[
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
].sort(ascendBy(x => x.name))
const desc = ascendBy(x => x.name)
[
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
].sort(desc)
both(f, g, a) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Function -> Function -> Any -> Boolean
Validates that the same value passed into two different functions returns truthy for both
Parameters
| Name | Type | Description |
|---|
f | function | The first function to test the value in |
g | function | The second function to test the value in |
a | Any | The value to run in the previous two functions |
Returns
| Type | Description |
|---|
| Boolean | Based on if both functions return a truthy value when ran |
import { both } from 'kyanite'
both(x => x > 10, x => x < 20, 15)
const b = both(x => x > 10, x => x < 20)
b(15)
b(9)
branch(p, f, g, a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> (a -> b) -> (a -> b)
Takes 3 functions and a value, and will run either the 2nd or 3rd function based on if the first passes
Parameters
| Name | Type | Description |
|---|
p | function | The first function to determine the path of our branch |
f | function | The function to run if the first passes |
g | function | The function to run if the first fails |
a | Any | The data to pass long our functions |
Returns
| Type | Description |
|---|
| Any | The result of the branch function used |
import { branch } from 'kyanite'
branch(
x => x < 10,
x => x + 1,
x => x - 1,
0
)
const b = branch(
x => x < 10,
x => x + 1,
x => x - 1
)
b(0)
b(12)
complement(fn, a) → {function}
- Since:
- Kind:
- Source:
- Category:
Takes a function and returns the opposite boolean value of what the predicate returns
Parameters
| Name | Type | Description |
|---|
fn | function | The function we want to apply the complement of |
a | Any | The value our functionality is being ran against |
Returns
| Type | Description |
|---|
| function | Returns the opposite function back |
import { complement } from 'kyanite'
complement(x => x > 10, 11)
complement(x => x < 10, 11)
const notGtTen = complement(x => x > 10)
notGtTen(11)
notGtTen(10)
compose(fn, gn, a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b) -> (b -> c) -> a -> c
Applies value through two functions, from right to left, also known as the B combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The second function to apply to our result of the first |
gn | function | The first function to run against the data |
a | Any | The data to compose our functions on |
Returns
| Type | Description |
|---|
| Any | The result of our function composition |
import { compose } from 'kyanite'
compose(Math.sqrt, x => x + 1, 99)
const comp = compose(Math.sqrt, x => x + 1)
comp(99)
comp(399)
composeP(fn, gn, a) → {Promise}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Promise b) -> (b -> Promise c) -> a -> (a -> Promise c)
Applies async functions that return a promise from right to left
Parameters
| Name | Type | Description |
|---|
fn | function | The second async function to apply |
gn | function | The first async function to apply |
a | Any | The data to apply the functions to |
Returns
| Type | Description |
|---|
| Promise | Based on the functions given the result of the functional composition |
import { composeP } from 'kyanite'
const foo = a => new Promise(resolve => resolve(a + '123'))
const bar = a => new Promise(resolve => resolve(a + '555'))
compose(bar, foo, '100').then(console.log)
const fn = compose(bar, foo)
fn('100').then(console.log)
cond(preds, value) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Array [(a -> Boolean)] -> Any -> Any
Runs an array of predicate functions as a series of logic, once one of the predicate functions passes it will then call the action function provided
Parameters
| Name | Type | Description |
|---|
preds | Array | An array of arrays hold predicate functions for a check and action |
value | Any | The value we want to run through the function list |
Returns
| Type | Description |
|---|
| Any | The outcome of the triggered action function |
import { always, cond, eq, T } from 'kyanite'
cond([
[eq(1), always('It is a one!')],
[eq(2), always('It is a two!')],
[T, always('It was nothing special')]
], 1)
const fn = cond([
[eq(1), always('It is a one!')],
[eq(2), always('It is a two!')],
[T, always('It was nothing special')]
])
fn(1)
fn(2)
fn(3)
converge(convFn, fns, data) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(...b -> c) -> [...(a -> b)] -> a -> c
Takes a converging function, a list of data functions, and the data itself. Runs the data through each data function individually, and then passes the array of values to the converging function.
Parameters
| Name | Type | Description |
|---|
convFn | function | The converging function our array of data is given to |
fns | Array | The array of data functions to run our data with |
data | Any | The data we want to converge with |
Returns
| Type | Description |
|---|
| Any | The results of the converging function |
import { converge, divide, length, sum } from 'kyanite'
converge(divide, [sum, length], [1, 2, 3, 4, 5, 6, 7])
const fn = converge(divide, [sum, length])
fn([1, 2, 3, 4, 5, 6, 7])
fn([1, 2, 3])
count(a) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Counts the number of values within a collection of data
Parameters
| Name | Type | Description |
|---|
a | Array | String | Object | Map | Set | The data to count |
Returns
| Type | Description |
|---|
| Number | The number of counted values within the provided data |
import { count } from 'kyanite'
count([1, 2, 3])
count({ a: 1, b: 2, c: 3 })
count('coolkid')
count(new Map([['a', 1], ['b', 2], ['c', 3]]))
count(new Set([1, 2, 3]))
count([])
count({})
count('')
count(new Map())
count(new Set())
curry(f, args) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Create a curried or partial function
Parameters
| Name | Type | Description |
|---|
f | function | The function we will be running |
args | Any | extra args to apply if needed |
Returns
| Type | Description |
|---|
| Any | Returns based on the function sent in |
import { curry } from 'kyanite'
const add = curry((a, b) => a + b)
add(1)(2)
add(1, 2)
const add1 = add(1)
add1(2)
const foo = curry((a, b) => a)
foo(1)()
const bar = foo(1)
bar()
bar(null)
curryN(n, f, args) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> ((a, b) -> c) -> a -> b -> c
Acts like curry but this one expects you to tell it how many arguments to expect
this allows it to work well with rest parameters and default params.
Parameters
| Name | Type | Description |
|---|
n | Number | The number of arguments the function is expecting |
f | function | The function we are going to be running with said arguments |
args | Any | The arguments to apply to said function curry wont execute until this length matches n |
Returns
| Type | Description |
|---|
| Any | Returns based on the results of the function passed in |
import { curryN } from 'kyanite'
const add = curryN(2, (a, b) => a + b)
add(1)(2)
add(1, 2)
const sum = add(1)
sum(2)
sum(4)
const add2 = curryN(2, (a, b = 1) => a + b)
const sum1 = add(1)
sum1(4)
sum1(undefined)
const foo = curryN(2, (a, b) => a)
foo(1)()
const bar = foo(1)
bar()
bar(null)
deepEq(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes and compares two items. Capable of handling cyclical data structures
Parameters
| Name | Type | Description |
|---|
a | Any | First item to compare |
b | Any | Second item to compare |
Returns
| Type | Description |
|---|
| Boolean | Returns the boolean after running our comparison check |
import { deepEq } from 'kyanite'
const q = { a: 1 }
deepEq({ a: 1 }, { a: 1 })
deepEq({ a: 1, b: 2 }, { b: 2, a: 1 })
deepEq(/[A-Z]/, new RegExp('[A-Z]')
deepEq([1, 2], [1, 2])
deepEq(new Date(), new Date())
deepEq({ a: { q } }, { a: { q } })
deepEq('test', new String('test'))
deepEq(false, new Boolean(false))
deepEq(5, new Number(5))
deepEq([1, 2], [2, 1])
deepEq({ a: 1 }, { b: 1 })
deepEq(new Date('11/14/1992'), new Date('11/14/2018'))
deepEq([], {})
defaultTo(def, val) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns the value if it isn't null, NaN, or undefined. Returns the provided default value if it is
Parameters
| Name | Type | Description |
|---|
def | Any | The default value to fall back on |
val | Any | The value to return if not null, NaN, or undefined |
Returns
| Type | Description |
|---|
| Any | Returns the value if it exists, returns the default otherwise |
import { defaultTo } from 'kyanite'
defaultTo('foo', null)
defaultTo('foo', 'bar')
const fn = defaultTo('foo')
fn(null)
fn('bar')
descend(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Determines which of the two passed in values should be descended
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Number | A number based on which value should descend |
import { descend } from 'kyanite'
[4, 10, 1, 6, 7, 12].sort(descend)
descendBy(fn, a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Function -> Any -> Any -> Number
Can be used with sort to descend an array based on the function passed in
Parameters
| Name | Type | Description |
|---|
fn | function | The function to use on values within our array |
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Number | A number based on where it falls when compared with the other value |
import { descendBy } from 'kyanite'
[
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
].sort(descendBy(x => x.name))
const desc = descendBy(x => x.name)
[
{ name: 'bob' },
{ name: 'amanda' },
{ name: 'carl' },
{ name: 'amanda' }
].sort(desc)
either(fn, gn, a) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean)-> (a -> Boolean) -> a -> Boolean
Validates that the value passes in either the provided functions
Parameters
| Name | Type | Description |
|---|
fn | function | The first function to test the value in |
gn | function | The second function to test the value in |
a | Any | The value to run in the two functions |
Returns
| Type | Description |
|---|
| Boolean | Based on if either functions return a truthy value when ran |
import { either } from 'kyanite'
either(x => x > 10, x => x < 20, 21)
const e = either(x => x < 10, x => x === 11)
e(20)
e(9)
e(11)
encase(fn, a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Encase the provided function in a try catch which if the function errors will give back an undefined
Parameters
| Name | Type | Description |
|---|
fn | function | The function to encase before running |
a | Any | The value we want to pass into the given function |
Returns
| Type | Description |
|---|
| Any | The return of the provided function or undefined if it errors |
import { encase } from 'kyanite'
encase(x => x.a.b.c, {a: 0})
encase(x => x.a.b.c, {a: {b: {c: 0}}})
const getter = x => x.a.b.c
const en = encase(getter)
en({a: 0})
en(a: {b: {c: 0}}})
eq(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Performs an equality check of two values
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Boolean | Returns a boolean based on the check |
import { eq } from 'kyanite'
eq(1, 1)
eq(NaN, NaN)
eq([1], [1])
const o = {}
eq({}, {})
eq(o, o)
const test = eq(NaN)
test(NaN)
eqBy(fn, a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b) -> a -> a -> Boolean
Gives back a result of comparing two values after applying a function over the values
Parameters
| Name | Type | Description |
|---|
fn | function | The function to apply to both of the given values |
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Boolean | The result of the value comparison |
import { eqBy } from 'kyanite'
eqBy(Math.abs, 5, -5)
eqBy(x => x[0], [1], [1])
eqBy(x => x.length, 'ab', 'abc')
const fn = eqBy(Math.abs)
fn(5, -5)
fn(5, -1)
flip(fn, a, b) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b -> c) -> b -> a -> c
Takes a function and two parameters and flips them when passing them to the given function,
also known as the C combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The function to give the parameters to |
a | Any | The param to become the 2nd past into the function |
b | Any | The param to become the 1st past into the function |
Returns
| Type | Description |
|---|
| Any | The value returned by the passed in function |
import { flip } from 'kyanite'
flip((a, b) => b > a, 2, 1)
flip((a, b) => b > a, 1, 2)
const _gt = flip((a, b) => b > a)
_gt(1, 2)
_gt(2, 1)
gt(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if a value is greater than the other
Parameters
| Name | Type | Description |
|---|
a | Any | Value to determine if it is greater than the other |
b | Any | Value to compare to see if it is less than the other |
Returns
| Type | Description |
|---|
| Boolean | Based on the outcome of the logic a Boolean |
import { gt } from 'kyanite'
gt(1, 2)
gt('b', 'a')
const fn = gt(2)
fn(1)
fn(2)
gte(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if a value is greater than or equal to the other
Parameters
| Name | Type | Description |
|---|
a | Any | Value to determine if it is greater than or equal to the other |
b | Any | Value to compare to see if it is less than or equal to the other |
Returns
| Type | Description |
|---|
| Boolean | Based on the outcome of the logic a Boolean |
import { gte } from 'kyanite'
gte(1, 2)
gte(1, 1)
gte('a', 'b')
const fn = gte(2)
fn(1)
fn(2)
fn(3)
has(key, data) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if the provided key/value exsists within the given data the data should be a supported type
Supported types: Array, String, Object, Map, and Set
Parameters
| Name | Type | Description |
|---|
key | String | The key or value to check for |
data | Array | String | Object | Map | Set | The data to search through |
Returns
| Type | Description |
|---|
| Any | The value found within the data |
import { has } from 'kyanite'
has('foo', { foo: 1 })
has('foo', ['bar', 'foo', 'baz'])
has('foo', 'barfoobaz')
has('foo', new Map([['foo', 1], ['bar', 2]]))
has('foo', new Set(['bar', 'foo', 'baz']))
has('foo', 1)
has('foo', /[foo]/g)
const fn = has('foo')
fn({ foo: 1 })
fn(new Map([['foo', 1]])
fn(['bar'])
identity(a) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
A function that returns the value passed to it, also known as the I combinator
Parameters
| Name | Type | Description |
|---|
a | Any | The value to identify |
Returns
| Type | Description |
|---|
| Any | The identified value |
import { identity } from 'kyanite'
identity(10)
[0, 'cool', null, 1].filter(identity)
isEmpty(x) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Determines if the entered value is empty or not
Parameters
| Name | Type | Description |
|---|
x | Any | Value to check against |
Returns
| Type | Description |
|---|
| Boolean | Returns the boolean after running our check |
import { isEmpty } from 'kyanite'
isEmpty([])
isEmpty({})
isEmpty('')
isEmpty(NaN)
isEmpty(null)
isEmpty(undefined)
isEmpty(true)
isEmpty(false)
isNil(x) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if the value is a null value
Parameters
| Name | Type | Description |
|---|
x | Any | The value to run our test against |
Returns
| Type | Description |
|---|
| Boolean | Returns a boolean based on the check |
import { isNil } from 'kyanite'
isNil(null)
isNil()
isNil(1)
isNil(0)
isNil('')
lt(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if a value is less than the other
Parameters
| Name | Type | Description |
|---|
a | Any | Value to determine if it is greater than the other |
b | Any | Value to compare to see if it is less than the other |
Returns
| Type | Description |
|---|
| Boolean | Based on the outcome of the logic a Boolean |
import { lt } from 'kyanite'
lt(2, 1)
lt('b', 'a')
const fn = lt(2)
fn(1)
fn(2)
fn(3)
lte(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if a value is less than or equal to the other
Parameters
| Name | Type | Description |
|---|
a | Any | Value to determine if it is greater than or equal to the other |
b | Any | Value to compare to see if it is less than or equal to the other |
Returns
| Type | Description |
|---|
| Boolean | Based on the outcome of the logic a Boolean |
import { lte } from 'kyanite'
lte(2, 1)
lte(1, 1)
lte('b', 'a')
const fn = lte(2)
fn(1)
fn(2)
fn(3)
memoizeWith(keyFn, fn) → {function}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(*... -> String) -> function -> function
Wraps a function with a memoization layer to cache the results of the function
Parameters
| Name | Type | Description |
|---|
keyFn | function | The function to generate a key to store the results |
fn | function | The function to wrap with memoization |
Returns
| Type | Description |
|---|
| function | A new function that will cache the results of the function |
import { memoizeWith } from 'kyanite'
const add = (a, b) => a + b
const memoizedAdd = memoizeWith((a, b) => `${a}-${b}`, add)
memoizedAdd(1, 2)
memoizedAdd(1, 2)
not(x) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns boolean based on if the value is not
Parameters
| Name | Type | Description |
|---|
x | Boolean | The values to compare against |
Returns
| Type | Description |
|---|
| Boolean | Returns boolean back based on the results |
import { not } from 'kyanite'
const reverse = not(true)
notEq(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes in two values and checks to make sure they're not equal to each other
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to compare |
b | Any | The second value to compare |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the values provided are equal |
import { notEq } from 'kyanite'
notEq(1, '1')
notEq('test', 'Test')
notEq(2, 2)
const fn = notEq(1)
fn('1')
fn(2)
fn(1)
on(fn, gn, a, b) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(c -> c -> d) -> (a -> b -> c) -> a -> b -> d
Applies the second function to the values passed in, and then runs the first function against those new values,
also known as the P combinator
Parameters
| Name | Type | Description |
|---|
fn | function | The first function being ran against the values from the second |
gn | function | The function to be applied to the two values passed in |
a | Any | The first value to use |
b | Any | The second value we want to use |
Returns
| Type | Description |
|---|
| Any | A value based on the first functions return |
import { on } from 'kyanite'
on((x, y) => x === y, x => x.length, 'you', 'are')
const f = on((x, y) => x === y)
f(x => x.length, 'you', 'are')
const g = f(x => x.length)
g('you', 'are')
const h = f('you')
h('are')
or(a, b) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Runs an or comparison on the two values passed in
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to check for a truthy value |
b | Any | The second value to check for a truthy value |
Returns
| Type | Description |
|---|
| Any | The value that returns truthy |
import { or } from 'kyanite'
or(true, true)
or(true, false)
or(false, false)
pipe(arr, init) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Applies a sequence of transformations over a value.
Parameters
| Name | Type | Description |
|---|
arr | Array | The array of functions to apply to our value |
init | Any | The value to apply our functions too |
Returns
| Type | Description |
|---|
| Any | The transformed value |
import { pipe } from 'kyanite'
pipe([add(2), multiply(2)], 10)
const piper = pipe([add(2), multiply(2)])
piper(10)
pipeP(fns, data) → {Promise}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[(a -> Promise b), (b -> Promise c), ..., (y -> Promise z)] -> a -> (a -> Promise z)
Runs a pipe of promise based functions against data
Parameters
| Name | Type | Description |
|---|
fns | Array | The list of async functions to run |
data | Any | The data to apply our functions to |
Returns
| Type | Description |
|---|
| Promise | A promise that once fulfilled has the results from the pipe |
import { pipeP } from 'kyanite'
const foo = a => new Promise(resolve => resolve(a + '123'))
const bar = a => new Promise(resolve => resolve(a + '555'))
pipeP([foo, bar], '0').then(console.log)
const fn = pipeP([foo, bar])
fn('0').then(console.log)
fn('10').then(console.log)
reduce(fn, acc, list) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> b -> b) -> b -> Array a -> b
Accepts an array and runs a reduce based on the passed values
The reducer function accepts the params a bit differently than the vanilla counterpart
As the reducer should expect the value first, and the accumulator second
Parameters
| Name | Type | Description |
|---|
fn | function | The function to run with the reduce should expect the value first and the accumulator second: (a, acc) => {} |
acc | Any | The empty initial state of the reduce accumulator |
list | Iterable | The list to run our reduce against |
Returns
| Type | Description |
|---|
| Any | Returns based on the original init parameter that is passed in |
import { reduce } from 'kyanite'
reduce((n, acc) => acc + n, 0, [1, 2, 3, 4, 5])
reduce((n, acc) => {
if (typeof n === 'number') {
acc.push(n)
}
return acc
}, [], ['', 1, 2, '0', 3])
reduce((val, acc) => acc.concat(val * 2), [], new Set([1, 2, 3, 4]))
reduced(x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Used to optimize reduce iterations, can be used to short circuit a reduce without needing to iterate an entire array
The returned value should be considered as a black box, it is not guaranteed to be stable
This optimization only works with `reduce`, and `reduceRight` currently
Parameters
| Name | Type | Description |
|---|
x | Any | The data that is considered reduced |
Returns
| Type | Description |
|---|
| Any | The wrapped value |
import { compose, inc, dec, pipe, reduce, reduced, when } from 'kyanite'
reduce((item, acc) =>
item > 3 ? reduced(acc) : acc.concat(item), [], [1, 2, 3, 4, 5])
reduce((item, acc) =>
acc.length === 3 ? reduced(acc) : acc.concat(item * 2), [], [1, 2, 3, 4, 5])
const fn = pipe([
when(lt(10), compose(reduced, inc)),
when(gt(10), compose(reduced, dec))
])
fn(1)
fn(20)
fn(10)
type(x) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Finds the type of the sent value
Parameters
| Name | Type | Description |
|---|
x | Any | The value to test |
Returns
| Type | Description |
|---|
| String | A string based on the type of the value passed in |
import { type } from 'kyanite'
type({})
type([])
type(null)
type(undefined)
type('hi')
type(1)
type(/1/g)
type(new Date())
type(true)
unless(fn, act, x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> (a -> b) -> a -> b
Takes a value and if it fails the check function (1st param) then it will apply the action function (2nd param) otherwise it gives back the given value
Parameters
| Name | Type | Description |
|---|
fn | function | The check function that when failed triggers the action function |
act | function | The action function to apply to our data |
x | Any | The argument to pass to both functions |
Returns
| Type | Description |
|---|
| Any | Returns whatever the action function returns, or the value that was passed in |
import { unless } from 'kyanite'
unless(x => x > 2, x => x * 2, 5)
unless(x => x > 5, x => x * 2, 5)
const un = unless(x => x > 2, x => x * 2)
un(5)
un(1)
when(fn, act, x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> (a -> b) -> a -> b
Takes a value and if it passes the check function (1st param) then it will apply the action function (2nd param) otherwise it gives back the given value
Parameters
| Name | Type | Description |
|---|
fn | function | The check function that when passed triggers the action function |
act | function | The action function which is fired when the logic passes |
x | Any | The argument to pass to both functions |
Returns
| Type | Description |
|---|
| Any | Returns whatever the action function returns, or the value that was passed in |
import { when } from 'kyanite'
when(x => x > 2, x => x * 2, 5)
when(x => x > 5, x => x * 2, 5)
const w = when(x => x > 2, x => x * 2)
w(5)
w(1)
xor(a, b) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Exclusive or logical operation, returns true if one of the arguments is truthy and the other is falsy, otherwise it returns false
Parameters
| Name | Type | Description |
|---|
a | Any | The first value to check for a truthy value |
b | Any | The second value to check for a truthy value |
Returns
| Type | Description |
|---|
| Boolean | The boolean outcome of the check |
import { xor } from 'kyanite'
xor(true, true)
xor(true, false)
xor(false, true)
xor(false, false)
concat(val, list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
a -> Array -> Array,String -> String -> String
Take a List and concats the values into a new List
Parameters
| Name | Type | Description |
|---|
val | Any | The value to concat into the List |
list | Array | String | The list of items or characters we want to concat the value to |
Returns
| Type | Description |
|---|
| Array | A newly created list with the value added |
import { concat } from 'kyanite'
concat(4, [1, 2, 3])
concat('bar', 'foo')
endsWith(a, list) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
a -> List -> Boolean,String -> String -> Boolean
Checks to see if the provided value is at the end of a given list
Parameters
| Name | Type | Description |
|---|
a | String | Array | The value to check for at the end of the list |
list | String | Array | The list to check through |
Returns
| Type | Description |
|---|
| Boolean | If the value is at the end of the provided list |
import { endsWith } from 'kyanite'
endsWith('c' , 'abc')
endsWith(['c'], ['a', 'b', 'c'])
endsWith('b', 'abc')
endsWith(['b'], ['a', 'b', 'c'])
const fn = endsWith('c')
fn('abc')
fn('cba')
first(x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[a] -> a | Undefined,String -> String | Undefined
Grabs the first index of a list
Parameters
| Name | Type | Description |
|---|
x | Array | String | The list or string we want to use |
Returns
| Type | Description |
|---|
| Any | Returns whatever was the first piece of our list |
import { first } from 'kyanite'
const arr = first([1, 3])
const str = first('abc')
includes(value, list) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
String | Number -> Array -> Boolean,String -> String -> Boolean
Checks to see if the provided list contains at least 1 of the provided value within it
Parameters
| Name | Type | Description |
|---|
value | Any | The value we want to search the list for |
list | Array | String | The list of items or characters we want to search through |
Returns
| Type | Description |
|---|
| Boolean | A Boolean based on if the value is found or not |
import { includes } from 'kyanite'
includes(3, [1, 2, 3])
includes('yan', 'kyanite')
const checker = includes(3)
checker([1, 2, 3])
checker('123')
last(x) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[a] -> a | Undefined,String -> String
Grabs the last index of a list
Parameters
| Name | Type | Description |
|---|
x | Array | String | The list or string we want to use |
Returns
| Type | Description |
|---|
| Any | Returns whatever was the last piece of our list |
import { last } from 'kyanite'
const arr = last([1, 3])
const str = last('abc')
length(a) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Array -> Number,String -> Number
Obtains the length of the passed array
Parameters
| Name | Type | Description |
|---|
a | Array | The array to find the length of |
Returns
| Type | Description |
|---|
| Number | The length of the array |
import { length } from 'kyanite'
length([1, 2, 3, 4])
length([])
nth(o, list) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Array a -> a | Undefined,Number -> String -> String | Undefined
Returns the nth element of the given list
Parameters
| Name | Type | Description |
|---|
o | Number | How much to offset the value |
list | Array | String | The Array or list to crawl through |
Returns
| Type | Description |
|---|
| Any | Returns the value found at the index |
import { nth } from 'kyanite'
nth(3, [1, 2, 3, 4, 5, 6, 7])
const third = nth(2)
third([1, 2, 3, 4, 5])
reverse(list) → {Array, String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Array -> Array,String -> String
Accepts a list of values or characters and reverses it
Parameters
| Name | Type | Description |
|---|
list | Array | String | The list to reverse |
Returns
| Type | Description |
|---|
| Array | String | A new reversed list |
import { reverse } from 'kyanite'
reverse([1, 2, 3])
reverse([])
reverse('abc')
slice(a, b, list) → {Array, String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Array a -> Array a,Number -> Number -> String -> String
Slices out items from a list type of data, like a list of characters or items
Parameters
| Name | Type | Description |
|---|
a | Number | The index at which to begin extraction |
b | Number | The index for what the extraction goes to. |
list | Array | String | The list of items or characters to slice |
Returns
| Type | Description |
|---|
| Array | String | The newly created list |
import { slice } from 'kyanite'
slice(1, 3, [1, 2, 3, 4, 5])
slice(0, 4, 'kyanite')
const slicer = slice(1, 3)
slicer([1, 2, 3, 4, 5])
slicer('kyanite')
startsWith(a, list) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
a -> List -> Boolean,String -> String -> Boolean
Checks to see if the provided value is at the beginning of a given list
Parameters
| Name | Type | Description |
|---|
a | String | Array | The value to check for at the beginning of the list |
list | String | Array | The list to check through |
Returns
| Type | Description |
|---|
| Boolean | If the value is at the end of the provided list |
import { startsWith } from 'kyanite'
startsWith('c' , 'cab')
startsWith(['c'], ['c', 'b', 'a'])
startsWith('b', 'abc')
startsWith(['b'], ['a', 'b', 'c'])
const fn = startsWith('c')
fn('cab')
fn('abc')
tail(list) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Drops the first value of an array and returns the rest as a tail array
Parameters
| Name | Type | Description |
|---|
list | String | Array | The array we want to get the tail of |
Returns
| Type | Description |
|---|
| Array | A new array of arrays containing the tail end values |
import { tail } from 'kyanite'
tail([1, 2, 3, 4, 5])
add(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Adds the provided numbers together
Parameters
| Name | Type | Description |
|---|
a | Number | The first number to add |
b | Number | The second number to add |
Returns
| Type | Description |
|---|
| Number | The sum of the numbers |
import { add } from 'kyanite'
add(1, 2)
const adder = add(2)
adder(3)
adder(2)
between(min, max, n) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number -> Boolean
Checks to see if a number is between two other provided numbers (inclusive)
Parameters
| Name | Type | Description |
|---|
min | Number | The number our value should be greater than or equal too |
max | Number | The number our value should be less than or equal too |
n | Number | The value to compare with |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the provided number is between the other two numbers |
import { between } from 'kyanite'
between(1, 3, 2)
between(1, 10, 7)
between(1, 10, 11)
const b = between(1)
b(10, 9)
const c = b(10)
c(9)
c(11)
clamp(min, max, val) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number -> Number
Restricts a number to be within a range
Parameters
| Name | Type | Description |
|---|
min | Number | The minimum of the clamp |
max | Number | The maximum of the clamp |
val | Number | The number to clamp |
Returns
| Type | Description |
|---|
| Number | The value if its inbetween min and max, min if its below and max if its above |
import { clamp } from 'kyanite'
clamp(1, 900, 23)
clamp(1, 900, 901)
clamp(1, 900, 0)
const fn = clamp(1, 900)
fn(23)
fn(901)
fn(0)
dec(n) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes in a number and returns it decremented by 1
Parameters
| Name | Type | Description |
|---|
n | Number | The number to decrement |
Returns
| Type | Description |
|---|
| Number | The decremented number |
import { dec } from 'kyanite'
dec(1)
dec(dec(3))
divide(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Divides the provided numbers
Parameters
| Name | Type | Description |
|---|
a | Number | The divisor which the dividend will be divided by |
b | Number | The dividend of the division problem |
Returns
| Type | Description |
|---|
| Number | The quotient of the two numbers |
import { divide } from 'kyanite'
divide(2, 1)
const div = divide(15)
div(3)
div(5)
factors(x) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes a number and builds an array of factors for that number
Parameters
| Name | Type | Description |
|---|
x | Number | The number it should find the factors of |
Returns
| Type | Description |
|---|
| Array | A new array which will contain the valid factors of the given number |
import { factors } from 'kyanite'
factors(36)
factors(-36)
factors(102)
factors(-102)
factors()
factors(0)
factors(NaN)
import { compose, factors, map, negate } from 'kyanite'
map(negate, factors(-36))
const negativeFactors = compose(map(negate), factors)
negativeFactors(-36)
negativeFactors(36)
gcd(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Determines the greatest common denominator of the numbers passed in
Parameters
| Name | Type | Description |
|---|
a | Number | The First number to use |
b | Number | The Second number to use |
Returns
| Type | Description |
|---|
| Number | The Greatest Common Denominator |
import { gcd } from 'kyanite'
gcd(80, 90)
gcd(20, 600)
const a = gcd(80)
a(90)
a(93)
inc(n) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes in a number and returns it incremented by 1
Parameters
| Name | Type | Description |
|---|
n | Number | The number to increment |
Returns
| Type | Description |
|---|
| Number | The incremented number |
import { inc } from 'kyanite'
inc(1)
inc(inc(1))
isEven(n) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if the provided number is even or not
Parameters
| Name | Type | Description |
|---|
n | Number | The number to check if its even |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the provided number is even |
import { isEven } from 'kyanite'
isEven(2)
isEven(12)
isEven('h')
isEven(1)
isEven(NaN)
isOdd(n) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if the provided number is odd or not
Parameters
| Name | Type | Description |
|---|
n | Number | The number to check against |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the number is odd |
import { isOdd } from 'kyanite'
isOdd(1)
isOdd(3)
isOdd('h')
isOdd(2)
isOdd(NaN)
isPrime(x) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Determines if the number passed in is a prime number or not
Parameters
| Name | Type | Description |
|---|
x | Number | The number to check if its prime or not |
Returns
| Type | Description |
|---|
| Boolean | A boolean based on if the number is prime |
import { isPrime } from 'kyanite'
isPrime(5)
isPrime(5009)
isPrime(6)
isPrime(5010)
isZero(n) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Checks if the provided number is equal to the number zero or not
Parameters
| Name | Type | Description |
|---|
n | Number | The number to check compare |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the provided number was equal to zero |
import { isZero } from 'kyanite'
isZero(1)
isZero('0')
isZero(0)
lcm(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Finds the least common multiple of the provided numbers
Parameters
| Name | Type | Description |
|---|
a | Number | The first number to use |
b | Number | The second number to use |
Returns
| Type | Description |
|---|
| Number | The least common multiple of the two numbers |
import { lcm } from 'kyanite'
lcm(90, 70)
lcm(91, 4)
const a = lcm(90)
a(70)
a(4)
mean(x) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Gets the average from a given array of numbers
Parameters
| Name | Type | Description |
|---|
x | Array | An array of numbers to add together |
Returns
| Type | Description |
|---|
| Number | Returns the mean average of the numbers |
import { mean } from 'kyanite'
mean([1, 2, 3, 2])
mean([2])
mean([])
mean()
mod(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Behaves like the modulo operator should mathematically, unlike the `%` operator. The arguments are required to be integers and will return NaN when the modulus is zero or negative.
Parameters
| Name | Type | Description |
|---|
a | Number | The dividend |
b | Number | The modulus |
Returns
| Type | Description |
|---|
| Number | The result of `b mod a` |
import { mod } from 'kyanite'
mod(17, 5)
mod(-17, 5)
mod(-5, 4)
mod(17, 0)
mod(17, -5)
mod(17.2, 5)
mod(17, 5.3)
const fn = mod(17)
fn(5)
fn(-5)
fn(0)
fn(5.3)
multiples(limit, n) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Array [Number]
Finds all of the multiples of a number up until the limit provided
Parameters
| Name | Type | Description |
|---|
limit | Number | The limit to stop at, once the result equals or exceeds this value the function will return the current list |
n | Number | The number to find the multiples for |
Returns
| Type | Description |
|---|
| Array | A new Array of multiples that the function found |
import { multiples } from 'kyanite'
multiples(100, 5)
multiples(100, 6)
const fn = multiples(100)
fn(5)
fn(6)
multiply(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Multiplies the provided numbers
Parameters
| Name | Type | Description |
|---|
a | Number | The first factor to multiply with |
b | Number | The second factor to multiply with |
Returns
| Type | Description |
|---|
| Number | The product of the numbers |
import { multiply } from 'kyanite'
multiply(2, 1)
const mul = multiply(5)
mul(3)
mul(2)
negate(n) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Negates the number passed in
Parameters
| Name | Type | Description |
|---|
n | Number | The number to negate |
Returns
| Type | Description |
|---|
| Number | The negated number |
import { negate } from 'kyanite'
negate(1)
negate(-1)
pow(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Take a base number and brings it to the value of base^exponent
Parameters
| Name | Type | Description |
|---|
a | Number | The exponent used to raise the base number |
b | Number | The base Number |
Returns
| Type | Description |
|---|
| Number | A number representing the given base taken to the power of the given exponent |
import { pow } from 'kyanite'
pow(3, 7)
pow(0.5, 4)
const p = pow(3)
p(7)
product(arr) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes an Array of numbers and multiplies all of them together
Parameters
| Name | Type | Description |
|---|
arr | Array | The array of numbers to combine |
Returns
| Type | Description |
|---|
| Number | The product of the numbers |
import { product } from 'kyanite'
product([1, 2, 3])
product([2, 3, 0])
range(from, to) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number a -> Number b -> [Number a...b]
Create an array range from start to end
Parameters
| Name | Type | Description |
|---|
from | Number | Starting number for the range |
to | Number | Number to end on for the range |
Returns
| Type | Description |
|---|
| Array | Returns an array of numbers consisting of the range |
import { range } from 'kyanite'
range(3, 7)
range(0, 3)
range(0, 0)
range(NaN)
rem(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Takes two numbers and gets the remainder from the division
Parameters
| Name | Type | Description |
|---|
a | Number | The dividend of the division problem |
b | Number | The divisor which the dividend will be divided by |
Returns
| Type | Description |
|---|
| Number | The remainder of the two numbers |
import { rem } from 'kyanite'
rem(5, 12)
rem(2, -1)
rem(2, NaN)
const r = rem(5)
r(12)
round(precision, num) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Round a number using exponent rounding to a desired precision
Parameters
| Name | Type | Description |
|---|
precision | Number | The precision we want the number to be rounded to |
num | Number | The number we are going to round |
Returns
| Type | Description |
|---|
| Number | The rounded number to the desired precision |
import { round } from 'kyanite'
round(2, 112.336)
round(3, 112.3354)
const rounder = round(3)
rounder(122.4456)
rounder(122.332)
subtract(a, b) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number
Subtracts the provided numbers
Parameters
| Name | Type | Description |
|---|
a | Number | The subtrahend number to subtract with |
b | Number | The minuend number to subtract from |
Returns
| Type | Description |
|---|
| Number | The difference of the numbers |
import { subtract } from 'kyanite'
subtract(2, 1)
const sub = subtract(5)
sub(3)
sub(2)
sum(arr) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Takes an Array of numbers and adds all of them together
Parameters
| Name | Type | Description |
|---|
arr | Array | The array of numbers to combine |
Returns
| Type | Description |
|---|
| Number | The sum of the numbers |
import { sum } from 'kyanite'
sum([1, 2, 3])
sum([1, 2, -3])
within(min, max, n) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Number -> Number -> Number -> Boolean
Checks to see if a number is between two other numbers (exclusive)
Parameters
| Name | Type | Description |
|---|
min | Number | The number our value should be greater than or equal too |
max | Number | The number our value should be less than or equal too |
n | Number | The value to compare with |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the provided number is between the other two numbers |
import { within } from 'kyanite'
within(1, 3, 2)
within(1, 10, 7)
within(1, 10, 10)
const fn = within(1, 10)
fn(4)
fn(10)
fn(1)
amend(a, b) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object -> Object -> Object
Updates an object by amending from right to left
Parameters
| Name | Type | Description |
|---|
a | Object | The new object data or values |
b | Object | The object we want to amend/update |
Returns
| Type | Description |
|---|
| Object | The newly amended object (shallow copy) |
import { amend } from 'kyanite'
amend({ b: 2 }, { a: 1 })
const fn = amend({ b: 2 })
fn({ a: 1 })
fn({ c: 3 })
any(schema, obj) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object k (v -> Boolean) -> Object -> Boolean
Takes in a schema of functions to apply to an object, makes sure any of them pass
Parameters
| Name | Type | Description |
|---|
schema | Object | An Object schema containing the matching properties and the function to run |
obj | Object | The object to iterate through |
Returns
| Type | Description |
|---|
| Boolean | A boolean dependent on whether or not any values passed |
import { any } from 'kyanite'
const run = any({
a: x => x === 'foo',
b: x => x !== 'bar'
})
run({ a: 'foo', b: 'xxx', x: 11, y: 19 })
run({ a: 'xxx', b: 'bar' })
draft(fn, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Function (a -> b) -> Object { k: v }
Runs a provided function against all of the values that are within the provided object
Parameters
| Name | Type | Description |
|---|
fn | function | The Function we want to apply to all of the data values |
obj | Object | The object to apply our functions too |
Returns
| Type | Description |
|---|
| Object | A new object with the updated data from our applied function |
import { draft } from 'kyanite'
draft(x => x * 2, { a: 1, b: 2, c: 3 })
const d = draft(x => x * 2)
d({ a: 1, b: 2, c: 3 })
height(obj) → {Number}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Works a lot like length for arrays, but allows you to get the length of an object
Parameters
| Name | Type | Description |
|---|
obj | Object | The object we want to read the length of |
Returns
| Type | Description |
|---|
| Number | The length of the object |
import { height } from 'kyanite'
height({ a: 1, b: 2 })
keys(obj) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Returns a list of all the own properties of an object
Parameters
| Name | Type | Description |
|---|
obj | Object | The object we want to pull the keys from |
Returns
| Type | Description |
|---|
| Array | Returns an array of keys from the provided object |
import { keys } from 'kyanite'
keys({ a: 1, b: 2, c: 3, d: { x: 100, y: 200 } })
objOf(k, v) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Creates an object containing a single key:value pair.
Parameters
| Name | Type | Description |
|---|
k | String | The key to use for the object |
v | Any | The value to use for the object |
Returns
| Type | Description |
|---|
| Object | A new object with the key and value provided |
import { objOf } from 'kyanite'
objOf('a', 1)
objOf('b', 2)
const fn = objOf('a')
fn(1)
omit(keys, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[String] -> {String: *} → {String: *}
Builds out a new object but omits the provided keys in the new one
Parameters
| Name | Type | Description |
|---|
keys | Array | The keys in which to omit from the data |
obj | Object | The object to search through and filter |
Returns
| Type | Description |
|---|
| Object | Returns the newly created data without the omitted values |
import { omit } from 'kyanite'
const obj = omit(['test'], { test: '3432', thing: 123 })
const arr = omit(['a', 'b'], { a: 1, b: 2, c: 3})
const omitKeys = omit(['test'])
omitKeys({ test: '3432', thing: 123 })
omitBy(fn, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
((v, k) -> Boolean) -> { k: v } -> { k: v }
Builds out a new object but omits the key values from the new object that do NOT pass the predicate function
Parameters
| Name | Type | Description |
|---|
fn | function | The function to run our values through the key is also provided to this function as the 2nd param |
obj | Object | The object to search through and filter |
Returns
| Type | Description |
|---|
| Object | Returns the newly created data without the omitted values |
import { omitBy } from 'kyanite'
const obj = omitBy(['test'], { test: '3432', thing: 123 })
const arr = omitBy(['a', 'b'], { a: 1, b: 2, c: 3})
const omitKeys = omitBy(['test'])
omitKeys({ test: '3432', thing: 123 })
over(key, fn, acc) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
String -> Function -> Object -> Object
Applies a function to a value within an object
Parameters
| Name | Type | Description |
|---|
key | String | The key to look for within the object |
fn | function | The function to apply to the value |
acc | Object | The object accumulator |
Returns
| Type | Description |
|---|
| Object | A new object with the applied value |
import { over } from 'kyanite'
over('b', x => x + 1, { a: 1, b: 1, c: 3 })
const o = over('b')
const withFn = o(x => x + 1)
o(x => x - 1, { a: 1, b: 3 })
withFn({ a: 1, b: 1 })
path(keys, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[k] -> { k: a } -> a | Undefined
Safe way to find a value within an object will return the value if found, undefined if not
Parameters
| Name | Type | Description |
|---|
keys | Array | The path to safely traverse the object with |
obj | Object | The object to traverse |
Returns
| Type | Description |
|---|
| Any | Returns the value if found, undefined if not |
import { path } from 'kyanite'
path(['a', 'b'], { a: { b: 3 } })
path(['a', 'b', 'c'], { a: 3 })
const safetyPath = path(['a', 'b'])
safetyPath({ a: { b: 2 } })
pathOr(a, keys, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
a -> [key] -> { key: a } -> a
A safe way to find an item within an object, will return the provided default if it's not found or the value itself if it is found
Parameters
| Name | Type | Description |
|---|
a | Any | The default value to return if the value isn't found |
keys | Array | The path to traverse the object with |
obj | Object | The object to traverse |
Returns
| Type | Description |
|---|
| Any | Either the found value or the provided default value |
import { pathOr } from 'kyanite'
pathOr('N/A', ['a', 'b'], { a: { b: 1 } })
pathOr('N/A', ['c', 'b'], { a: { b: 1 } })
const fn = pathOr('N/A')
const withKeys = fn(['a', 'b'])
fn(['c', 'd'], { c: { d: 2 } })
withKeys({ a: { b: 1 } })
fn(['c', 'd'], { d: { c: 1 } })
withKeys({ b: { a: 1 } })
pathSatisfies(pred, keys, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> [Idx] -> {a} -> Boolean
Runs a path check on a given object and then runs a predicate function on the result
Parameters
| Name | Type | Description |
|---|
pred | function | The predicate function to run on the value that comes back from the object path |
keys | Array | The path to safely traverse the object with |
obj | Object | The object to traverse |
Returns
| Type | Description |
|---|
| Any | true if the given path satifies the given predicate, false otherwise |
import { pathSatisfies } from 'kyanite'
pathSatisfies(y => y > 0, ['x', 'y'], { x: { y: 2 } })
pathSatisfies(y => y > 0, ['a', 'b', 'c'], { a: 3 })
const safetyPath = pathSatisfies(y => y > 0, ['x', 'y'])
safetyPath({ x: { y: 2 } })
pick(keys, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
[k] -> { k: a } -> { k: a }
Picks only the requested keys from a provided object
Parameters
| Name | Type | Description |
|---|
keys | Array | The keys we want to pick out of the object |
obj | Object | The object to pull the data from |
Returns
| Type | Description |
|---|
| Object | Returns a new object of only the picked keys provided |
import { pick } from 'kyanite'
pick(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 })
pick(['a', 'e', 'f'], { a: 3 })
const picker = pick(['a', 'd'])
picker({ a: 1, b: 2, c: 3, d: 4 })
plan(schema, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object -> Object -> Object
Uses a schema to allow you to plan out functions being ran against values within your object
Parameters
| Name | Type | Description |
|---|
schema | Object | The object of functions we want to apply |
obj | Object | The object to apply our functions too |
Returns
| Type | Description |
|---|
| Object | A new object with the updated data from our applied functions |
import { plan } from 'kyanite'
const testFns = {
a: x => x * 2,
b: x => x + 10
}
plan(testFns, { a: 5, b: 10 })
const p = plan(testFns)
p({ a: 5, b: 10 })
prop(p, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
k -> {k: v} -> v | Undefined
Brings back the indicated property of an object if it exists
Parameters
| Name | Type | Description |
|---|
p | Array | The array path of the property we are looking for |
obj | Object | The object to search through |
Returns
| Type | Description |
|---|
| Any | The value that exists at 'obj.p' |
import { prop } from 'kyanite'
prop('thing', { thing: 'test' })
prop('thing', {})
map(prop('a'), [{ a: 1 }, { a: 2 }, { a: 3 }])
const proper = prop('a')
proper({ a: 1, b: 2 })
propEq(key, val, obj) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
String -> * -> { k: * } -> Boolean
Takes a desired property from an object and compares the value against a provided value to make sure they're equal
Parameters
| Name | Type | Description |
|---|
key | String | The key to look for in the object |
val | Any | The value the property should equal |
obj | Object | The object to pull the property from to compare |
Returns
| Type | Description |
|---|
| Boolean | Whether or not the values are equal |
import { propEq } from 'kyanite'
const abby = { name: 'Abby', age: 7, hair: 'blond' }
const fred = { name: 'Fred', age: 12, hair: 'brown' }
const rusty = { name: 'Rusty', age: 10, hair: 'brown' }
const george = { name: 'george', age: 9 }
const kids = [abby, fred, rusty, george]
propEq('hair', 'brown', abby)
propEq('hair', 'brown', george)
propEq('hair', 'brown', rusty)
const fn = propEq('hair')
const gn = fn('brown')
kids.filter(fn('blond'))
kids.filter(gn)
propOr(def, key, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
a -> String -> Object -> a
If the provided object contains it's own property with the specified name, that value is returned. Otherwise it will return the provided default value
Parameters
| Name | Type | Description |
|---|
def | Any | The default value to fallback to if the prop returned null |
key | String | The property name within the provided object |
obj | Object | The object to pull the property from |
Returns
| Type | Description |
|---|
| Any | The value of the found prop, or the provided default value |
import { propOR } from 'kyanite'
propOr('N/A', 'foo', { bar: 1, foo: 2 })
propOr('N/A', 'foo', { bar: 1 })
const fn = propOr('N/A')
const gn = fn('foo')
fn('bar', { bar: 1 })
fn('bar', { foo: 1 })
gn({ foo: 1 })
gn({ baz: 1 })
propSatisfies(pred, key, obj) → {Any}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> String -> { String: a } -> Boolean
Pulls a values from an object and then passes it to a predicate function
Parameters
| Name | Type | Description |
|---|
pred | function | The predicate function to run on the value that comes back from the object |
key | Array | The key to pull from the provided object |
obj | Object | The object to pull from |
Returns
| Type | Description |
|---|
| Any | true if the found value satifies the given predicate, false otherwise |
import { propSatisfies } from 'kyanite'
propSatisfies(y => y > 0, 'y', { x: 1, y: 4 })
propSatisfies(y => y > 0, 'b', { a: 3 })
const safetyProp = propSatisfies(y => y > 0, 'y')
safetyProp({ x: 1, y: 4 })
props(keys, obj) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object { k: v } -> Array v
Pulls a list of values from an object and returns them as an array
Parameters
| Name | Type | Description |
|---|
keys | Array | The list of properties to get values from |
obj | Object | The object to map through |
Returns
| Type | Description |
|---|
| Array | An array of values pulled from the object |
import { props } from 'kyanite'
props(['a', 'b'], { a: 1, b: 2, c: 3 })
const g = props(['a', 'b'])
g({ a: 1, b: 2, c: 3 })
sift(fn, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
(a -> Boolean) -> Object -> Object
Works a lot like an array filter, but for the object data type
Accepts a function and an object, it then runs the function against each value
Parameters
| Name | Type | Description |
|---|
fn | function | A function to run against the values within the object |
obj | Object | The object to sift through |
Returns
| Type | Description |
|---|
| Object | A new filtered out object |
import { sift } from 'kyanite'
sift(x => typeof x === 'string', {
id: 44,
thing: 'test',
other: 'cool'
})
const sifter = sift(x => typeof x === 'string')
sifter({ id: 44, thing: 'test', other: 'cool' })
values(obj) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object { k: v } -> Array v
Takes an object and returns a list of the object values
Parameters
| Name | Type | Description |
|---|
obj | Object | The object to grab the values from |
Returns
| Type | Description |
|---|
| Array | An array of values pulled from the object |
import { values } from 'kyanite'
values({ a: 1, b: 2, c: 3 })
whole(schema, obj) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object k (v -> Boolean) -> Object -> Boolean
Takes a schema of functions to apply to an object, and makes sure all of them pass
Parameters
| Name | Type | Description |
|---|
schema | Object | An Object schema containing the matching properties and the function to run |
obj | Object | The object to iterate through |
Returns
| Type | Description |
|---|
| Boolean | A boolean dependent on whether or not all values passed |
import { whole } from 'kyanite'
const run = whole({ a: x => x === 'foo', b: x => x !== 'bar', x: x => x > 10, y: x => x < 20 })
run({ a: 'foo', b: 'xxx', x: 11, y: 19 })
run({ a: 'xxx', b: 'xxx', x: 11, y: 19 })
withDefaults(def, obj) → {Object}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Object { k: v } -> Object { k: v } -> Object { k: v }
Fills in non exsistent property values (null, undefined, and NaN) with the provided defaults.
Parameters
| Name | Type | Description |
|---|
def | Object | An object containing the desired default values |
obj | Object | The data object to check |
Returns
| Type | Description |
|---|
| Object | A new object with filled in defaults if needed |
import { withDefaults } from 'kyanite'
withDefaults({ a: 1, b: 2, c: 3 }, { b: 10, c: 4 })
withDefaults({ a: 1, b: 2, c: 3 }, { a: null, b: 10, c: 4 })
withDefaults({ a: 1, b: 2, c: 3 }, { b: NaN, c: 4 })
const fn = withDefaults({ a: 1, b: 2, c: 3 })
fn({ b: 10, c: 4 })
fn({ a: 12 })
fn({})
capitalize(str) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Capitalizes the first letter of a string
Parameters
| Name | Type | Description |
|---|
str | String | The string we want to capitalize |
Returns
| Type | Description |
|---|
| String | The capitalized string |
import { capitalize } from 'kyanite'
capitalize('test')
capitalize('small brown cow')
fuzzySearch(needle, haystack) → {Boolean}
- Since:
- Kind:
- Deprecated:
- Source:
- Category:
- Signature:
Fuzzy search setup to look find things fast, effective, and probably the most out of place function here. But it works well so it's hard to get rid of
Parameters
| Name | Type | Description |
|---|
needle | String | The Item to search |
haystack | String | The value to search for |
Returns
| Type | Description |
|---|
| Boolean | Returns a boolean determined by if the value is found or not by the search |
import { fuzzySearch } from 'kyanite'
fuzzySearch('te', 'test')
fuzzySearch('dog', 'testing')
const search = fuzzySearch('te')
search('test')
match(reg, str) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
RegExp -> String -> Array
Matches a string against some regexp to build an array of matching strings
Parameters
| Name | Type | Description |
|---|
reg | RegExp | The regex to match the string against |
str | String | The string to match |
Returns
| Type | Description |
|---|
| Array | An array of matched strings |
import { match } from 'kyanite'
match(/([a-z]a)/g, 'bananas')
match(/a/, 'b')
const fn = match(/([a-z]a)/g)
fn('bananas')
fn('why')
replace(a, b, str) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
RegExp|String -> String -> String -> String
Replaces a substring or regex match in a string and then replaces it with the provided value
Parameters
| Name | Type | Description |
|---|
a | String | RegExp | The String or RegExp we want to find and replace |
b | String | The value we want to replace it with |
str | String | The String to search through |
Returns
| Type | Description |
|---|
| String | The resulting string |
import { replace } from 'kyanite'
replace('foo', 'bar', 'foofoo')
replace(/foo/g, 'bar', 'foofoo')
const rep = replace('foo')
const with = rep('bar')
rep('baz', 'foofoo')
with('foofoo')
split(char, str) → {Array}
- Since:
- Kind:
- Source:
- Category:
- Signature:
String -> String -> Array
Takes a string and splits it into an array based on the character passed in
Parameters
| Name | Type | Description |
|---|
char | String | The character to split the string by |
str | String | The string we want to split |
Returns
| Type | Description |
|---|
| Array | A new array of characters from the string |
import { split } from 'kyanite'
split('', 'abc')
split(':', '123:334')
const sp = split('')
sp('abc')
test(reg, str) → {Boolean}
- Since:
- Kind:
- Source:
- Category:
- Signature:
RegExp -> String -> Boolean
Tests regexp against a string value returns true if matches were found, false if not
Parameters
| Name | Type | Description |
|---|
reg | RegExp | The regex to test the string against |
str | String | The string to test |
Returns
| Type | Description |
|---|
| Boolean | A boolean based on if the string passes the test or not |
import { test } from 'kyanite'
test(/^a/, 'abc')
test(/^b/, 'abc')
const fn = test(/^a/)
fn('abc')
fn('bca')
toLower(a) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Transform a provided string into an lowercase version
Parameters
| Name | Type | Description |
|---|
a | String | The string to lower case |
Returns
| Type | Description |
|---|
| String | The string in lower case format |
import { toLower } from 'kyanite'
toLower('HI')
toLower('TEST.123.HELLO')
toUpper(a) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Transform a provided string into an uppercase version
Parameters
| Name | Type | Description |
|---|
a | String | The string to upper case |
Returns
| Type | Description |
|---|
| String | The string in upper case format |
import { toUpper } from 'kyanite'
toUpper('hi')
toUpper('test.123.hello')
trim(str) → {String}
- Since:
- Kind:
- Source:
- Category:
- Signature:
Accepts a string value and trims it's white space
Parameters
| Name | Type | Description |
|---|
str | String | The string to trim |
Returns
| Type | Description |
|---|
| String | The trimmed string |
import { trim } from 'kyanite'
trim('my new cow ')
trim(' new things ')