adjust(idx, fn, list) → {Array}

Since:
  • v3.0.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
idxNumberThe index the value we want to change is at
fnfunctionThe function to apply
listArrayThe array of data

Returns

TypeDescription
ArrayA 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]) // => [0, 2, 2, 3]
adjust(1, toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c']

// adjust can also be curried

const fn = adjust(1)

fn(toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c]

chunk(size, data) → {Array}

Since:
  • v0.12.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> Array -> Array

Takes an array of data and chunks it into smaller arrays based on the size param passed in

Parameters

NameTypeDescription
sizeNumberThe size the inner arrays should be
dataArrayThe array of data to chunk out

Returns

TypeDescription
ArrayA new array of arrays containing the chunked data
import { chunk } from 'kyanite'

chunk(2, [1, 2, 3, 4, 5, 6]) // => [[1, 2], [3, 4], [5, 6]]
chunk(2, [1, 2, 3, 4, 5]) // => [[1, 2], [3, 4], [5]]

// It's also curried
const fn = chunk(2)

fn([1, 2, 3, 4, 5, 6]) // => [[1, 2], [3, 4], [5, 6]]
fn([1, 2, 3, 4, 5]) // => [[1, 2], [3, 4], [5]]

concatMap(fn, arr) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (* -> b) -> [a] -> [b]

Take an array and concats the values into a new array after applying the function

Parameters

NameTypeDescription
fnfunctionThe function to be applied to each value
arrArrayThe array to concat together

Returns

TypeDescription
ArrayA newly created array of the concated values
import { concatMap, identity } from 'kyanite'

concatMap(x => [x, x], [1, 2, 3]) // => [1, 1, 2, 2, 3, 3]
concatMap(identity, [[1, 2], [3, 4], [5, 6]]) // => [1, 2, 3, 4, 5, 6]

// It's also curried

const con = concatMap(x => [x, x])

con([1, 2, 3]) // => [1, 1, 2, 2, 3, 3]

countBy(fn, arr) → {Object}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe function to apply to each piece of data during iteration
arrArrayThe array to iterate and count through

Returns

TypeDescription
ObjectA 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) // => { '1': 3, '2': 2, '3': 1 }
countBy(x => x.toLowerCase(), letters) // => { 'a': 3, 'b': 2, 'c': 1 }

// It's also curried
const fn = countBy(Math.floor)

fn(numbers) // => { '1': 3, '2': 2, '3': 1 }

difference(arrs) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • [*] -> [*] -> [*]

Returns a new array of values that are not contained within any of the arrays

Parameters

NameTypeDescription
arrsArrayThe array of arrays we want to get the difference of

Returns

TypeDescription
ArrayAn array of elements that are not present in all of the arrays
import { difference } from 'kyanite'

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

drop(i, list) → {Array}

Since:
  • v0.2.2
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> [a] -> [a]

Starts at a at desired index and pulls the values from that point until the end

Parameters

NameTypeDescription
iNumberThe index we want the slice to start at
listArrayThe array we want to drop from

Returns

TypeDescription
ArrayAn array with the indicated values removed from the array
import { drop } from 'kyanite'

drop(3, [1, 2, 3, 4, 5]) // => [4, 5]
drop(6, [1, 2, 3, 4, 5]) // => []
drop(-1, [1, 2, 3, 4, 5]) // => [1, 2, 3, 4, 5]

// It's also curried

const d = drop(3)

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

dropLast(n, list) → {Array}

Since:
  • v2.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> Array -> Array

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

Parameters

NameTypeDescription
nNumberThe number of values we want to drop
listArrayThe array we want to drop from

Returns

TypeDescription
ArrayAn array with the indicated values removed from the array
import { dropLast } from 'kyanite'

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

// It's also curried

const d = dropLast(3)

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

dropWhile(fn, arr) → {Array}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe function to apply per iteration
arrArrayThe array of data to iterate through

Returns

TypeDescription
ArrayA new array without the dropped values
import { dropWhile } from 'kyanite'

dropWhile(x => x <= 2, [1, 2, 3, 4, 3, 2, 1]) //=> [3, 4, 3, 2, 1]

// It's also curried
const fn = dropWhile(x => x <= 2)

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

ensureArray(x) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
xAnyThe value to ensure

Returns

TypeDescription
ArrayReturns a new array
import { ensureArray } from 'kyanite'

ensureArray(1) // => [1]
ensureArray() // => []
ensureArray(null) // => []
ensureArray('test') // => ['test']

every(fn, data) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> Boolean) -> [a] -> Boolean

Loops through a provided list verifying that every value evaluates to a truthy value.

Parameters

NameTypeDescription
fnfunctionThe function to send our values to for validation
dataArrayThe list we are to loop through

Returns

TypeDescription
BooleanIf all values passed will return true else false
import { every } from 'kyanite'

const data = [1, 2, 3, 4]

every(x => x > 0, data) // => true
every(x => x < 3, data) // => false

// It is also curried

const run = every(x => x > 0)

run([1, 2, 3]) // => true
run([-1, 0, 1]) // => false

everyPass(fns, data) → {Boolean}

Since:
  • v0.12.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnsArrayThe array of functions to pass the value to
dataAnyThe data value to give to each function

Returns

TypeDescription
BooleanBased on if all the functions pass or not
import { everyPass } from 'kyanite'

everyPass([x => x > 2, x => x < 4], 3) // => true
everyPass([x => x > 7, x => x < 3], 5) // => false

// It is also curried

const fn = everyPass([x => x > 0, x => x < 4])

fn(3) // => true
fn(2) // => true
fn(0) // => false

filter(fn, arr) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> Boolean) -> [a] -> [a]

Filter through a filterable data piece using the provided function

Parameters

NameTypeDescription
fnfunctionThe predicate function to run on our values
arrArrayThe filterable list to go through

Returns

TypeDescription
ArrayReturns 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]) // => [2, 4]

// Is also curried

const filterer = filter(isEven)

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

find(fn, arr) → {Maybe}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> Boolean) -> [a] -> Maybe a

Find an item based on the function sent in and its list

Parameters

NameTypeDescription
fnfunctionThe function used/called during the find
arrArrayThe list we want to search through

Returns

TypeDescription
MaybeReturns either the found item, or undefined if no item is found
import { find } from 'kyanite'

find(v => v.val === 'none', [{val: 'test'}, {val: 'none'}]) // => { val: 'none' }
find(v => v > 2, [1, 2, 3, 4, 5]) // => 3

// find is also curried

const fn = find(v => v.val === 'test')

fn([{val: 'test'}, {val: 'none'}]) // => { val: 'test' }

findIndex(fn, list) → {Number}

Since:
  • v0.2.2
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe function to test our value against
listArrayThe array to loop through

Returns

TypeDescription
NumberThe 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]) // => 4
findIndex(x => x < 0, [1, 3, 4, 5, 6]) // => -1

// It's also curried
const f = findIndex(x => x > 5)

f([1, 2, 3, 4, 5, 6]) // => 5

fold(fn, arr) → {Any}

Since:
  • v0.13.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe function used/called during the fold
arrArrayThe array we want to fold/reduce down

Returns

TypeDescription
AnyA value based on the results of the function
import { fold } from 'kyanite'

fold((a, acc) => a <= acc ? a : acc, [5, 6, 3, 9, 1]) // => 1
fold((a, acc) => a + acc, [1, 2, 3, 4, 5]) // => 15

// fold is also curried

const fn = fold((a, acc) => a <= acc ? a : acc)

fn([5, 4, 19, 20, 32, 1]) // => 1
fn(['z', 'x', 'd', 'p']) // => 'd'

fromPairs(pairs) → {Object}

Since:
  • v1.5.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • [[k, v]] -> { k: v }

Takes an array of arrays which contain key value pairs and builds a new object

Parameters

NameTypeDescription
pairsArrayAnd array of arrays containing key value pairing

Returns

TypeDescription
ObjectA new object built from the provided key value pairs
import { fromPairs } from 'kyanite'

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

groupBy(fn, list) → {Object}

Since:
  • v0.2.1
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> String) -> [a] -> { String: [a] }

Groups values of an array based on the function passed in

Parameters

NameTypeDescription
fnfunctionThe function to run our values through
listArrayThe array to go through

Returns

TypeDescription
ObjectAn object with the grouped values
import { groupBy } from 'kyanite'

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

// It's also curried

const g = groupBy(Math.floor)

g([4.2, 6.1, 6.4]) // => { '4': [4.2], '6': [6.1, 6.4] }

insert(i, d, arr) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> [a] -> [a]

Insert an item in a certain index of an array

Parameters

NameTypeDescription
iNumberThe index number to remove from
dAnyThe data we are going to be inserting
arrArrayThe array to insert into

Returns

TypeDescription
ArrayA new array with the inserted data
import { insert } from 'kyanite'

insert(2, 'x', [1, 2, 3, 4]) // => [1, 2, 'x', 3, 4]

// It's also curried

const ins = insert(2)

ins('x', [1, 2, 3, 4]) // => [1, 2, 'x', 3, 4]

intersection(a, b) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • [*] -> [*] -> [*]

Returns an array containing elements present in both arrays

Parameters

NameTypeDescription
aArrayOur first array value to compare with
bArrayOur second array value to compare with

Returns

TypeDescription
ArrayA new array containing values that both arrays had
import { intersection } from 'kyanite'

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

// It's also curried

const inter = intersection([1, 2, 3, 4])

inter([3, 4, 5, 6]) // => [3, 4]

join(str, list) → {String}

Since:
  • v0.4.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • String a -> Array String

Joins together an array of strings with whatever string was passed in

Parameters

NameTypeDescription
strStringThe string we want to use for the join
listArrayThe array to join

Returns

TypeDescription
StringThe joined string
import { join } from 'kyanite'

join(' ', ['test', 'this', 'thing']) // => 'test this thing'
join('aaa', ['test', 'that', 'thing']) // => 'testaaathataaathing'

// It's also curried
const j = join(' ')

j(['test', 'this', 'thing']) // => 'test this thing'
j(['test', 'that', 'thing']) // => 'test that thing'

juxt(fns, x) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnsArrayAn array of functions to apply
xArrayThe data to map our functions against

Returns

TypeDescription
ArrayAn array of results from the ran functions
import { juxt } from 'kyanite'

juxt([Math.min, Math.max], [3, 6, -7, 1]) // => [-7, 6]

// It's curried
const getRange = juxt([Math.min, Math.max])

getRange([3, 4, 9, -3]) // => [-3, 9]

map(fn, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> b) -> [a] -> [b]

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

NameTypeDescription
fnfunctionThe function to run against the values in our functor
listArrayThe list to iterate through

Returns

TypeDescription
ArrayThe new Array or Object that was created
import { map } from 'kyanite'

const dbl = n => n * 2

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

// It's also curried

const dbler = map(dbl)

dbler([1, 2, 3]) // => [2, 4, 6]

max(list) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • [Number|String] -> Number|String

Iterates through an array to find the max value

Parameters

NameTypeDescription
listArrayThe Array to iterate through

Returns

TypeDescription
AnyThe found or "deemed" maximum value of the array
import { max } from 'kyanite'

max([1, 3, 2, 5, 4]) // => 5
max(['c', 'a', 'b', 'f']) // => 'f'

maxBy(fn, list) → {Any}

Since:
  • v0.5.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> b) -> [a] -> a

Finds the maximum value in an array by applying a provided function to the value first before comparing it

Parameters

NameTypeDescription
fnfunctionThe function to apply to each value of the array
listArrayThe Array to iterate through

Returns

TypeDescription
AnyThe found or "deemed" maximum value of the array
import { maxBy } from 'kyanite'

maxBy(x => x.size, [{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }]) // => { size: 6 }
maxBy(x => x.alpha, [{ alpha: 'b' }, { alpha: 'c' }, { alpha: 'a' }]) // => { alpha: 'c' }

// It's also curried

const m = maxBy(x => x.size)

m([{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }]) // => { size: 6 }

min(list) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array

Iterates through an array to find the min value

Parameters

NameTypeDescription
listArrayThe Array to iterate through

Returns

TypeDescription
AnyThe found or "deemed" minimum value of the array
import { min } from 'kyanite'

min([1, 3, 2, 5, 4]) // => 1
min(['c', 'a', 'b', 'f']) // => 'a'

minBy(fn, list) → {Any}

Since:
  • v0.5.0
Kind:
  • function
Source:
Category:
  • Array

Finds the minimum value in an array by applying a provided function to the value first before comparing it

Parameters

NameTypeDescription
fnfunctionThe function to apply to each value of the array
listArrayThe Array to iterate through

Returns

TypeDescription
AnyThe found or "deemed" minimum value of the array
import { minBy } from 'kyanite'

minBy(x => x.size, [{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }]) // => { size: 2 }
minBy(x => x.alpha, [{ alpha: 'b' }, { alpha: 'c' }, { alpha: 'a' }]) // => { alpha: 'a' }

// It's also curried

const m = minBy(x => x.size)

m([{ size: 4 }, { size: 2 }, { size: 6 }, { size: 3 }]) // => { size: 2 }

partition(fn, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe predicate function to check each of the values
listArrayThe array to partition out

Returns

TypeDescription
ArrayAn 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]) // => [ ['foo', 'bar'], [100] ]

// Is curried as well

const part = partition(is(String))

part(['foo', 'bar', 100]) // => [ ['foo', 'bar'], [100] ]

pluck(p, list) → {Array}

Since:
  • v1.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • String -> Array -> Array

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

Parameters

NameTypeDescription
pString | NumberThe key to pluck the value of
listArrayThe list of objects to map through

Returns

TypeDescription
ArrayA new array of values plucked from our original list
import { pluck } from 'kyanite'

pluck('age', [{ name: 'george', age: 19 }, { name: 'gavin', age: 26 }]) // => [19, 26]
pluck(0, [[1, 2], [3, 4]]) // => [1, 3]

// It's also curried
const fn = pluck('age')

fn([{ name: 'george', age: 19 }, { name: 'gavin', age: 26 }]) // => [19, 26]

prepend(x, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • a -> [a] -> [a]

Returns a new list with the provided value at the front of the given list

Parameters

NameTypeDescription
xAnyThe value we want to put at the front of our list
listArrayThe Array or list to prepend to

Returns

TypeDescription
ArrayA new array
import { prepend } from 'kyanite'

prepend('testing', ['is', 'cool']) // => ['testing', 'is', 'cool']

// It's curried

const pender = prepend('testing')

pender(['is', 'cool']) // => ['testing', 'is', 'cool']

reduceRight(fn, acc, arr) → {Any}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe iterator function to call for the reduce
accAnyThe init value to start the accumulator at
arrArrayThe Array to reduce

Returns

TypeDescription
AnyThe new accumulated value
import { reduceRight } from 'kyanite'

reduceRight((n, acc) =>
  typeof n === 'number' ? acc.push(n) : acc, [], ['', 1, 2, '0', 3]) // => [3, 2, 1]

// It's also curried
const fn = reduceRight((x, acc) => typeof n === 'number' ? acc.push(n) : acc)

fn([], ['', 1, 2, '0', 3]) // => [3, 2, 1]

reject(fn, arr) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> Boolean) -> Array [a] -> Array [a]

Iterate through a list and reject any value that does not pass the provided function

Parameters

NameTypeDescription
fnfunctionThe predicate function to run on our values
arrArrayThe filterable list to go through

Returns

TypeDescription
ArrayReturns 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]) // => [1, 3]
reject(x => x.val > 2, [{ val: 2 }, { val: 5 }, { val: 3 }]) // => [{ val: 2 }]

// Is also curried

const rejecter = reject(isEven)

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

remove(i, x) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> [a] -> [b]

Remove an item from a certain point in the index

Parameters

NameTypeDescription
iNumberThe index number to remove from
xArrayThe array in question

Returns

TypeDescription
Arrayreturns the modified array back
import { remove } from 'kyanite'

const test = remove(2, [1, 2, 3, 4]) // => [1, 2, 4]

// This is also a curried method

const remover = remove(2)
const test = remover([1, 2, 3, 4]) // => [1, 2, 4]

some(fn, arr) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> Boolean) -> [a] -> Boolean

Loops through a provided list verifying that at least some values evaluates to a truthy value.

Parameters

NameTypeDescription
fnfunctionThe function to send our values to for validation
arrArrayThe list we are to loop through

Returns

TypeDescription
BooleanIf any values passed will return true else false
import { some } from 'kyanite'

const data = [1, 2, 3, 4]

some(x => x > 0, data) // => true
some(x => x < 3) // => true
some(x => x < 0, data) // => false

// It is also curried

const run = some(x => x > 0)

run([1, 2, 3]) // => true
run([-1, 0, 1]) // => true
run([-3, -2, -1]) // => false

somePass(fns, data) → {Boolean}

Since:
  • v0.12.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnsArrayThe array of functions to pass the value to
dataAnyThe data value to give to each function

Returns

TypeDescription
BooleanIf any function passed then returns true, otherwise returns false
import { somePass } from 'kyanite'

somePass([x => x > 2, x => x < 4], 3) // => true
somePass([x => x > 7, x => x < 3], 5) // => true
somePass([x => x === 4, x => x === 6], 5) // => false

// It is also curried

const fn = somePass([x => x > 0, x => x < 4])

fn(3) // => true
fn(2) // => true
fn(0) // => false

sort(fn, a) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • ((a, a) -> Number) -> Array a -> Array a

Uses a comparison function to sort an array

Parameters

NameTypeDescription
fnfunctionThe function used to sort the array
aArrayThe array to be sorted

Returns

TypeDescription
ArrayA new sorted array
import { sort } from 'kyanite'

sort((a, b) => a - b, [99, 23, 10, 53, 1]) // => [1, 10, 23, 53, 99]

// It's also curried

const sorter = sort((a, b) => a - b)

sorter([99, 23, 10, 53, 1]) // => [1, 10, 23, 53, 99]
sorter([5, 3, 4, 6, 2, 1]) // => [1, 2, 3, 4, 5, 6]

sortBy(fn, list) → {Array}

Since:
  • v0.2.1
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Function -> Array -> Array

Sorts through an array of values using the provided function on each value

Parameters

NameTypeDescription
fnfunctionThe function to use on values within our array
listArrayThe array to run through

Returns

TypeDescription
ArrayA newly sorted array
import { sortBy } from 'kyanite'

sortBy(x => x.name, [
 { name: 'bob' },
 { name: 'amanda' },
 { name: 'carl' },
 { name: 'amanda' }
]) // => [{ name: 'amanda' }, { name: 'amanda' }, { name: 'bob' }, { name: 'carl' }]

// It's also curried

const sb = sortBy(x => x.name)

sb([
 { name: 'bob' },
 { name: 'amanda' },
 { name: 'carl' },
 { name: 'amanda' }
]) // => [{ name: 'amanda' }, { name: 'amanda' }, { name: 'bob' }, { name: 'carl' }]

sortWith(fns, arr) → {Array}

Since:
  • v0.2.2
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnsArrayAn array of functions to sort with
arrArrayThe array to be sorted

Returns

TypeDescription
ArrayA 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) // => [{name: 'alice', age: 40}, {name: 'clara', age: 40}, {name: 'bob', age: 30}]

// It's also curried

const ageNameSort = sortWith([
  descendBy(x => x.age),
  ascendBy(x => x.name)
])

ageNameSort(data) // =>[{name: 'alice', age: 40}, {name: 'clara', age: 40}, {name: 'bob', age: 30}]

take(i, list) → {Array}

Since:
  • v0.2.2
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> Array -> Array

Takes the values from an array up until the point specified, then brings those values back

Parameters

NameTypeDescription
iNumberThe index we want our take to start at
listArrayThe array we are taking from

Returns

TypeDescription
ArrayA new array of the values taken
import { take } from 'kyanite'

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

// It's also curried

const t = take(3)

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

takeLast(n, list) → {Array, String}

Since:
  • v2.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> Array -> Array

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

NameTypeDescription
nNumberThe index we want our take to start at
listArray | StringThe array we are taking from

Returns

TypeDescription
Array | StringA new array of the values taken
import { takeLast } from 'kyanite'

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

// It's also curried

const t = takeLast(3)

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

takeWhile(fn, arr) → {Array}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Array
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

NameTypeDescription
fnfunctionThe function ran against each value within the array should return a boolean
arrArrayThe array to take from

Returns

TypeDescription
ArrayA new array of data that passed the param function
import { takeWhile } from 'kyanite'

takeWhile(x => x < 4, [1, 2, 3, 4, 5, 6]) // => [1, 2, 3]

// It's also curried
const fn = takeWhile(x => x < 4)

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

union(a, rest) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Array a -> Array a -> Array a

Creates a union between two arrays, removing duplicates from each

Parameters

NameTypeDescription
aArrayAn array to put through combining
restArrayThe rest of the arrays

Returns

TypeDescription
ArrayA new array of unique values from each of the passed in arrays
import { union } from 'kyanite'

union([1, 2, 3], [3, 4, 5]) // => [1, 2, 3, 4, 5]
union([1, 2, 3], [[3, 4, 5], [4, 5, 6]]) // => [1, 2, 3, 4, 5, 6]

// It's also curried

const un = union([1, 2, 3])

un([3, 4, 5]) // => [1, 2, 3, 4, 5]
un([[3, 4, 5], [4, 5, 6]]) // => [1, 2, 3, 4, 5, 6]

uniq(list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> b) -> Array a -> Array a

Returns an array of unique values from the applied function

Parameters

NameTypeDescription
listArrayThe list to sift through

Returns

TypeDescription
ArrayAn array of uniq values from the provided function
import { uniq } from 'kyanite'

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

uniqBy(fn, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • (a -> b) -> Array a -> Array a

Returns an array of unique values from the applied function

Parameters

NameTypeDescription
fnfunctionThe function to apply
listArrayThe list to sift through

Returns

TypeDescription
ArrayAn array of unique values from the provided function
import { uniqBy } from 'kyanite'

uniqBy(x => x > 2, [1, 2, 3, 4, 5]) // => [3, 4, 5]

// It is also curried

const uq = uniqBy(x => x > 2)

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

update(idx, val, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Number -> a -> [b] -> [c]

Add an item to an array within a certain index of the array

Parameters

NameTypeDescription
idxNumberThe index number to add at
valAnyWhat we want to add to our array
listArrayThe array in question

Returns

TypeDescription
ArrayReturns the modified array
import { update } from 'kyanite'

update(1, 10, [1, 2, 3]) // => [1, 10, 3]
update(-1, 10, [1, 2, 3]) // => [1, 2, 10]

// You can also use it as a curried method

const updater = update(2, 10)

updater([1, 2, 3]) // => [1, 2, 10]

// This can be taken further like so

const index = update(2)
const val = index(10)
val([1, 2, 3]) // => [1, 2, 10]

zip(x, y) → {Object}

Since:
  • v0.5.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Array -> Array -> Object

Takes two arrays and combines them into a key value pair object

Parameters

NameTypeDescription
xArrayThe array that will act as keys
yArrayThe array that will act as values

Returns

TypeDescription
ObjectThe combined arrays key value pair
import { zip } from 'kyanite'

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

// It's also curried

const z = zip(['a', 'b', 'c'])

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

F() → {Boolean}

Since:
  • v1.2.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • () -> Boolean

A Function that will always return false, any given parameters are ignored

Returns

TypeDescription
BooleanA boolean of false
import { F } from 'kyanite'

F() // => false

T() → {Boolean}

Since:
  • v1.2.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • () -> Boolean

A Function that will always return true, any given parameters are ignored

Returns

TypeDescription
BooleanA boolean of true
import { T } from 'kyanite'

T() // => true

addIndex(fn) → {function}

Since:
  • v0.11.2
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe original function to add the index and list onto

Returns

TypeDescription
functionA 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-0', 'o-1', 'o-2', 'b-3', 'a-4', 'r-5']
f((_, i) => i > 2, data) // => ['b', 'a', 'r']
r((val, acc, i) => acc.concat(val + i), [], data) // => ['f0', 'o1', 'o2', 'b3', 'a4', 'r5']

always(a, _) → {Any}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> a

Always returns the first param sent to it, and ignores the 2nd also known as the K combinator

Parameters

NameTypeDescription
aAnyThe value we want to return
_AnyThe ignored parameter

Returns

TypeDescription
AnyThe first parameter passed in
import { always } from 'kyanite'

always(false, true) // => false
always(true, true) // => true
always('dino', 'saur') // => 'dino'

// It's also curried
const fn = always('dino')

fn('') // => 'dino'

and(a, b) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> a | b

Runs an and comparison on the two values passed in

Parameters

NameTypeDescription
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
AnyThe evaluated outcome of the parameters
import { and } from 'kyanite'

and(true, true) // => true
and(true, false) // => false
and(false, false) // => false

ap(fn, gn, x) → {Any}

Since:
  • v0.4.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe setter function for ap x => y => z
gnfunctionThe getter function for ap x => y
xAnyThe data that is given to the provided functions

Returns

TypeDescription
AnyThe 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) // => { a: { b: 4 } }

// It's also curried

const fn = ap(x => y => x + y, z => z * 2)

fn(2) // => 6
fn(3) // => 9

apply(fn, a) → {Any}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> b) -> a -> b

Applies a function to a parameter/argument. Useful for creating a fixed-arity function, also known as the A combinator

Parameters

NameTypeDescription
fnfunctionThe function we want to apply to the data
aAnyThe parameter to call the function with

Returns

TypeDescription
AnyThe result of whatever fn(a) will be
import { apply } from 'kyanite'

apply(x => x * 2, 2) // => 4

// It's also curried
const fn = apply(x => x * 2)

fn(2) // => 4
fn(100) // => 200

applyN(fn, a) → {Any}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe function we want to apply to the data
aArrayThe parameter(s) to call the function with

Returns

TypeDescription
AnyThe result of whatever fn(...a) will be
import { applyN } from 'kyanite'

applyN(x => x * 2, [2]) // => 4
applyN((a, b, c) => a + b + c, [1, 2, 3]) // => 6
applyN(Math.max, [1, 2, 3, -99, 42, 6, 7]) // => 42

// It's also curried
const fn = applyN(x => x * 2)

fn([2]) // => 4
fn([100]) // => 200

ascend(a, b) → {Number}

Since:
  • v0.2.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Any -> Any -> Number

Determines which of the two passed in values should be ascended

Parameters

NameTypeDescription
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
NumberA number based on which value should ascend
import { ascend } from 'kyanite'

[4, 10, 1, 6, 7, 12].sort(ascend) // => [1, 4, 6, 7, 10, 12]

ascendBy(fn, a, b) → {Number}

Since:
  • v0.2.1
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Function -> Any -> Any -> Number

Can be used with sort to ascend an array based on the function passed in

Parameters

NameTypeDescription
fnfunctionThe function to use on values within our array
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
NumberA 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)) // => [{ name: 'amanda' }, { name: 'amanda' }, { name: 'bob' }, { name: 'carl' }]

// It's also curried

const desc = ascendBy(x => x.name)

[
 { name: 'bob' },
 { name: 'amanda' },
 { name: 'carl' },
 { name: 'amanda' }
].sort(desc) // => [{ name: 'amanda' }, { name: 'amanda' }, { name: 'bob' }, { name: 'carl' }]

both(f, g, a) → {Boolean}

Since:
  • v0.2.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Function -> Function -> Any -> Boolean

Validates that the same value passed into two different functions returns truthy for both

Parameters

NameTypeDescription
ffunctionThe first function to test the value in
gfunctionThe second function to test the value in
aAnyThe value to run in the previous two functions

Returns

TypeDescription
BooleanBased on if both functions return a truthy value when ran
import { both } from 'kyanite'

both(x => x > 10, x => x < 20, 15) // => true

// It's also curried

const b = both(x => x > 10, x => x < 20)

b(15) // => true
b(9) // => false

branch(p, f, g, a) → {Any}

Since:
  • v0.4.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
pfunctionThe first function to determine the path of our branch
ffunctionThe function to run if the first passes
gfunctionThe function to run if the first fails
aAnyThe data to pass long our functions

Returns

TypeDescription
AnyThe result of the branch function used
import { branch } from 'kyanite'

branch(
  x => x < 10,
  x => x + 1,
  x => x - 1,
  0
) // => 1

// It's also curried
const b = branch(
  x => x < 10,
  x => x + 1,
  x => x - 1
)

b(0) // => 1
b(12) // => 11

complement(fn, a) → {function}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function

Takes a function and returns the opposite boolean value of what the predicate returns

Parameters

NameTypeDescription
fnfunctionThe function we want to apply the complement of
aAnyThe value our functionality is being ran against

Returns

TypeDescription
functionReturns the opposite function back
import { complement } from 'kyanite'

complement(x => x > 10, 11) // => false
complement(x => x < 10, 11) // => true

// It's also curried

const notGtTen = complement(x => x > 10)

notGtTen(11) // => false
notGtTen(10) // => true

compose(fn, gn, a) → {Any}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> b) -> (b -> c) -> a -> c

Applies value through two functions, from right to left, also known as the B combinator

Parameters

NameTypeDescription
fnfunctionThe second function to apply to our result of the first
gnfunctionThe first function to run against the data
aAnyThe data to compose our functions on

Returns

TypeDescription
AnyThe result of our function composition
import { compose } from 'kyanite'

compose(Math.sqrt, x => x + 1, 99) // => 10

// It's also curried

const comp = compose(Math.sqrt, x => x + 1)

comp(99) // => 10
comp(399) // => 20

composeP(fn, gn, a) → {Promise}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> Promise b) -> (b -> Promise c) -> a -> (a -> Promise c)

Applies async functions that return a promise from right to left

Parameters

NameTypeDescription
fnfunctionThe second async function to apply
gnfunctionThe first async function to apply
aAnyThe data to apply the functions to

Returns

TypeDescription
PromiseBased 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) // => '100123555'

// It's also curried
const fn = compose(bar, foo)

fn('100').then(console.log) // => '100123555'

cond(preds, value) → {Any}

Since:
  • v1.2.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
predsArrayAn array of arrays hold predicate functions for a check and action
valueAnyThe value we want to run through the function list

Returns

TypeDescription
AnyThe 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) // => 'It is a one!'

// It's also curried
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) // => 'It is a one!'
fn(2) // => 'It is a two!'
fn(3) // => 'It was nothing special'

converge(convFn, fns, data) → {Any}

Since:
  • v1.3.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
convFnfunctionThe converging function our array of data is given to
fnsArrayThe array of data functions to run our data with
dataAnyThe data we want to converge with

Returns

TypeDescription
AnyThe results of the converging function
import { converge, divide, length, sum } from 'kyanite'

converge(divide, [sum, length], [1, 2, 3, 4, 5, 6, 7]) // => 4

// It's also curried
const fn = converge(divide, [sum, length])

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

count(a) → {Number}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> Number

Counts the number of values within a collection of data

Parameters

NameTypeDescription
aArray | String | Object | Map | SetThe data to count

Returns

TypeDescription
NumberThe number of counted values within the provided data
import { count } from 'kyanite'

count([1, 2, 3]) // => 3
count({ a: 1, b: 2, c: 3 }) // => 3
count('coolkid') // => 7
count(new Map([['a', 1], ['b', 2], ['c', 3]])) // => 3
count(new Set([1, 2, 3])) // => 3
count([]) // => 0
count({}) // => 0
count('') // => 0
count(new Map()) // => 0
count(new Set()) // => 0

curry(f, args) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (* -> a) -> (* -> a)

Create a curried or partial function

Parameters

NameTypeDescription
ffunctionThe function we will be running
argsAnyextra args to apply if needed

Returns

TypeDescription
AnyReturns based on the function sent in
import { curry } from 'kyanite'

const add = curry((a, b) => a + b)

add(1)(2) // => 3
add(1, 2) // => 3

const add1 = add(1)

add1(2) // => 3

// Possible gotcha
const foo = curry((a, b) => a)

foo(1)() // => [Function]
const bar = foo(1)

bar() // => [Function]
bar(null) // => 1

curryN(n, f, args) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
nNumberThe number of arguments the function is expecting
ffunctionThe function we are going to be running with said arguments
argsAnyThe arguments to apply to said function curry wont execute until this length matches n

Returns

TypeDescription
AnyReturns based on the results of the function passed in
import { curryN } from 'kyanite'

const add = curryN(2, (a, b) => a + b)

add(1)(2) // => 3
add(1, 2) // => 3

const sum = add(1)

sum(2) // => 3
sum(4) // => 5

const add2 = curryN(2, (a, b = 1) => a + b)
const sum1 = add(1)

sum1(4) // => 5
sum1(undefined) // => 2

// Possible gotcha
const foo = curryN(2, (a, b) => a)

foo(1)() // => [Function]
const bar = foo(1)

bar() // => [Function]
bar(null) // => 1

deepEq(a, b) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Takes and compares two items. Capable of handling cyclical data structures

Parameters

NameTypeDescription
aAnyFirst item to compare
bAnySecond item to compare

Returns

TypeDescription
BooleanReturns the boolean after running our comparison check
import { deepEq } from 'kyanite'

const q = { a: 1 }

deepEq({ a: 1 }, { a: 1 }) // => true
deepEq({ a: 1, b: 2 }, { b: 2, a: 1 }) // => true
deepEq(/[A-Z]/, new RegExp('[A-Z]') // => true
deepEq([1, 2], [1, 2]) // => true
deepEq(new Date(), new Date()) // => true
deepEq({ a: { q } }, { a: { q } }) // => true

deepEq('test', new String('test')) // => false
deepEq(false, new Boolean(false)) // => false
deepEq(5, new Number(5)) // => false
deepEq([1, 2], [2, 1]) // => false
deepEq({ a: 1 }, { b: 1 }) // => false
deepEq(new Date('11/14/1992'), new Date('11/14/2018')) // => false
deepEq([], {}) // => false

defaultTo(def, val) → {Any}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> a|b

Returns the value if it isn't null, NaN, or undefined. Returns the provided default value if it is

Parameters

NameTypeDescription
defAnyThe default value to fall back on
valAnyThe value to return if not null, NaN, or undefined

Returns

TypeDescription
AnyReturns the value if it exists, returns the default otherwise
import { defaultTo } from 'kyanite'

defaultTo('foo', null) // => 'foo'
defaultTo('foo', 'bar') // => 'bar'

// It's also curried
const fn = defaultTo('foo')

fn(null) // => 'foo'
fn('bar') // => 'bar'

descend(a, b) → {Number}

Since:
  • v0.2.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Any -> Any -> Number

Determines which of the two passed in values should be descended

Parameters

NameTypeDescription
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
NumberA number based on which value should descend
import { descend } from 'kyanite'

[4, 10, 1, 6, 7, 12].sort(descend) // => [12, 10, 7, 6, 4, 1]

descendBy(fn, a, b) → {Number}

Since:
  • v0.2.1
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Function -> Any -> Any -> Number

Can be used with sort to descend an array based on the function passed in

Parameters

NameTypeDescription
fnfunctionThe function to use on values within our array
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
NumberA 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)) // => [{ name: 'carl' }, { name: 'bob' }, { name: 'amanda' }, { name: 'amanda' }]

// It's also curried

const desc = descendBy(x => x.name)

[
 { name: 'bob' },
 { name: 'amanda' },
 { name: 'carl' },
 { name: 'amanda' }
].sort(desc) // => [{ name: 'carl' }, { name: 'bob' }, { name: 'amanda' }, { name: 'amanda' }]

either(fn, gn, a) → {Boolean}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> Boolean)-> (a -> Boolean) -> a -> Boolean

Validates that the value passes in either the provided functions

Parameters

NameTypeDescription
fnfunctionThe first function to test the value in
gnfunctionThe second function to test the value in
aAnyThe value to run in the two functions

Returns

TypeDescription
BooleanBased on if either functions return a truthy value when ran
import { either } from 'kyanite'

either(x => x > 10, x => x < 20, 21) // => true

// It's also curried

const e = either(x => x < 10, x => x === 11)

e(20) // => false
e(9) // => true
e(11) // => true

encase(fn, a) → {Any}

Since:
  • v0.2.2
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Function -> Any -> Maybe

Encase the provided function in a try catch which if the function errors will give back an undefined

Parameters

NameTypeDescription
fnfunctionThe function to encase before running
aAnyThe value we want to pass into the given function

Returns

TypeDescription
AnyThe return of the provided function or undefined if it errors
import { encase } from 'kyanite'

encase(x => x.a.b.c, {a: 0}) // => undefined
encase(x => x.a.b.c, {a: {b: {c: 0}}}) // => 0

// It's also curried
const getter = x => x.a.b.c
const en = encase(getter)

en({a: 0}) // => undefined
en(a: {b: {c: 0}}}) // => 0

eq(a, b) → {Boolean}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> a-> Boolean

Performs an equality check of two values

Parameters

NameTypeDescription
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
BooleanReturns a boolean based on the check
import { eq } from 'kyanite'

eq(1, 1) // => true
eq(NaN, NaN) // => true
eq([1], [1]) // => false

const o = {}

eq({}, {}) // => false
eq(o, o) // => true

// eq is also curried

const test = eq(NaN)
test(NaN) // => true

eqBy(fn, a, b) → {Boolean}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> b) -> a -> a -> Boolean

Gives back a result of comparing two values after applying a function over the values

Parameters

NameTypeDescription
fnfunctionThe function to apply to both of the given values
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
BooleanThe result of the value comparison
import { eqBy } from 'kyanite'

eqBy(Math.abs, 5, -5) // => true
eqBy(x => x[0], [1], [1]) // => true
eqBy(x => x.length, 'ab', 'abc') // => false

// It's also curried

const fn = eqBy(Math.abs)

fn(5, -5) // => true
fn(5, -1) // => false

flip(fn, a, b) → {Any}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe function to give the parameters to
aAnyThe param to become the 2nd past into the function
bAnyThe param to become the 1st past into the function

Returns

TypeDescription
AnyThe value returned by the passed in function
import { flip } from 'kyanite'

flip((a, b) => b > a, 2, 1) // => true
flip((a, b) => b > a, 1, 2) // => false

// It's also curried
const _gt = flip((a, b) => b > a)

_gt(1, 2) // => false
_gt(2, 1) // => true

gt(a, b) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Checks if a value is greater than the other

Parameters

NameTypeDescription
aAnyValue to determine if it is greater than the other
bAnyValue to compare to see if it is less than the other

Returns

TypeDescription
BooleanBased on the outcome of the logic a Boolean
import { gt } from 'kyanite'

gt(1, 2) // => true
gt('b', 'a') // => true

// It's also curried

const fn = gt(2)

fn(1) // => true
fn(2) // => false

gte(a, b) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Checks if a value is greater than or equal to the other

Parameters

NameTypeDescription
aAnyValue to determine if it is greater than or equal to the other
bAnyValue to compare to see if it is less than or equal to the other

Returns

TypeDescription
BooleanBased on the outcome of the logic a Boolean
import { gte } from 'kyanite'

gte(1, 2) // => true
gte(1, 1) // => true
gte('a', 'b') // => true

// It's also curried

const fn = gte(2)

fn(1) // => true
fn(2) // => true
fn(3) // => false

has(key, data) → {Any}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> Boolean

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

NameTypeDescription
keyStringThe key or value to check for
dataArray | String | Object | Map | SetThe data to search through

Returns

TypeDescription
AnyThe value found within the data
import { has } from 'kyanite'

has('foo', { foo: 1 }) // => true
has('foo', ['bar', 'foo', 'baz']) // => true
has('foo', 'barfoobaz') // => true
has('foo', new Map([['foo', 1], ['bar', 2]])) // => true
has('foo', new Set(['bar', 'foo', 'baz'])) // => true

has('foo', 1) // => TypeError: Unsupported type: Number
has('foo', /[foo]/g) // => TypeError: Unsupported type: RegExp

// It's also curried
const fn = has('foo')

fn({ foo: 1 }) // => true
fn(new Map([['foo', 1]]) // => true
fn(['bar']) // => false

identity(a) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> a

A function that returns the value passed to it, also known as the I combinator

Parameters

NameTypeDescription
aAnyThe value to identify

Returns

TypeDescription
AnyThe identified value
import { identity } from 'kyanite'

identity(10) // => 10

[0, 'cool', null, 1].filter(identity) // => ['cool', 1]

isEmpty(x) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> Boolean

Determines if the entered value is empty or not

Parameters

NameTypeDescription
xAnyValue to check against

Returns

TypeDescription
BooleanReturns the boolean after running our check
import { isEmpty } from 'kyanite'

isEmpty([]) // => true
isEmpty({}) // => true
isEmpty('') // => true
isEmpty(NaN) // => true
isEmpty(null) // => true
isEmpty(undefined) // => true
isEmpty(true) // => true
isEmpty(false) // => true

isNil(x) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> Boolean

Checks if the value is a null value

Parameters

NameTypeDescription
xAnyThe value to run our test against

Returns

TypeDescription
BooleanReturns a boolean based on the check
import { isNil } from 'kyanite'

isNil(null) // => true
isNil() // => true
isNil(1) // => false
isNil(0) // => false
isNil('') // => false

lt(a, b) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Checks if a value is less than the other

Parameters

NameTypeDescription
aAnyValue to determine if it is greater than the other
bAnyValue to compare to see if it is less than the other

Returns

TypeDescription
BooleanBased on the outcome of the logic a Boolean
import { lt } from 'kyanite'

lt(2, 1) // => true
lt('b', 'a') // => true

// It's also curried

const fn = lt(2)

fn(1) // => false
fn(2) // => false
fn(3) // => true

lte(a, b) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Checks if a value is less than or equal to the other

Parameters

NameTypeDescription
aAnyValue to determine if it is greater than or equal to the other
bAnyValue to compare to see if it is less than or equal to the other

Returns

TypeDescription
BooleanBased on the outcome of the logic a Boolean
import { lte } from 'kyanite'

lte(2, 1) // => true
lte(1, 1) // => true
lte('b', 'a') // => true

// It's also curried

const fn = lte(2)

fn(1) // => false
fn(2) // => true
fn(3) // => true

not(x) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • * -> Boolean

Returns boolean based on if the value is not

Parameters

NameTypeDescription
xBooleanThe values to compare against

Returns

TypeDescription
BooleanReturns boolean back based on the results
import { not } from 'kyanite'

const reverse = not(true) // => false

notEq(a, b) → {Boolean}

Since:
  • v0.12.2
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • * -> * -> Boolean

Takes in two values and checks to make sure they're not equal to each other

Parameters

NameTypeDescription
aAnyThe first value to compare
bAnyThe second value to compare

Returns

TypeDescription
BooleanWhether or not the values provided are equal
import { notEq } from 'kyanite'

notEq(1, '1') // => true
notEq('test', 'Test') // => true
notEq(2, 2) // => false

// It's also curried

const fn = notEq(1)

fn('1') // => true
fn(2) // => true
fn(1) // => false

on(fn, gn, a, b) → {Any}

Since:
  • v0.4.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe first function being ran against the values from the second
gnfunctionThe function to be applied to the two values passed in
aAnyThe first value to use
bAnyThe second value we want to use

Returns

TypeDescription
AnyA value based on the first functions return
import { on } from 'kyanite'

on((x, y) => x === y, x => x.length, 'you', 'are') // => true

// It's also curried

const f = on((x, y) => x === y)

f(x => x.length, 'you', 'are') // => true

const g = f(x => x.length)

g('you', 'are') // => true

const h = f('you')

h('are') // => true

or(a, b) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> a | b

Runs an or comparison on the two values passed in

Parameters

NameTypeDescription
aAnyThe first value to check for a truthy value
bAnyThe second value to check for a truthy value

Returns

TypeDescription
AnyThe value that returns truthy
import { or } from 'kyanite'

or(true, true) // => true
or(true, false) // => true
or(false, false) // => false

pipe(arr, init) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • Array (a -> b) -> a -> b

Applies a sequence of transformations over a value.

Parameters

NameTypeDescription
arrArrayThe array of functions to apply to our value
initAnyThe value to apply our functions too

Returns

TypeDescription
AnyThe transformed value
import { pipe } from 'kyanite'

pipe([add(2), multiply(2)], 10) // => 24

// It's also curried

const piper = pipe([add(2), multiply(2)])

piper(10) // => 24

pipeP(fns, data) → {Promise}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • [(a -> Promise b), (b -> Promise c), ..., (y -> Promise z)] -> a -> (a -> Promise z)

Runs a pipe of promise based functions against data

Parameters

NameTypeDescription
fnsArrayThe list of async functions to run
dataAnyThe data to apply our functions to

Returns

TypeDescription
PromiseA 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) // => '0123555'

// It's also curried
const fn = pipeP([foo, bar])

fn('0').then(console.log) // => '0123555'
fn('10').then(console.log) // => '10123555'

reduce(fn, acc, list) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe function to run with the reduce should expect the value first and the accumulator second: (a, acc) => {}
accAnyThe empty initial state of the reduce accumulator
listIterableThe list to run our reduce against

Returns

TypeDescription
AnyReturns 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]) // => 15
reduce((n, acc) => {
 if (typeof n === 'number') {
   acc.push(n)
 }

 return acc
}, [], ['', 1, 2, '0', 3]) // => [1, 2, 3]

reduce((val, acc) => acc.concat(val * 2), [], new Set([1, 2, 3, 4])) // => [2, 4, 6, 8]

reduced(x) → {Any}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • (a -> a) -> a

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

NameTypeDescription
xAnyThe data that is considered reduced

Returns

TypeDescription
AnyThe 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]) // => [1, 2, 3]
reduce((item, acc) =>
  acc.length === 3 ? reduced(acc) : acc.concat(item * 2), [], [1, 2, 3, 4, 5]) // => [2, 4, 6]

// Using it with pipe is also do able
const fn = pipe([
  when(lt(10), compose(reduced, inc)),
  when(gt(10), compose(reduced, dec))
])

fn(1) // => 2
fn(20) // => 19
fn(10) // => 10

type(x) → {String}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> String

Finds the type of the sent value

Parameters

NameTypeDescription
xAnyThe value to test

Returns

TypeDescription
StringA string based on the type of the value passed in
import { type } from 'kyanite'

type({}) // => 'Object'
type([]) // => 'Array'
type(null) // => 'Null'
type(undefined) // => 'Undefined'
type('hi') // => 'String'
type(1) // => 'Number'
type(/1/g) // => 'RegExp'
type(new Date()) // => 'Date'
type(true) // => 'Boolean'

unless(fn, act, x) → {Any}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe check function that when failed triggers the action function
actfunctionThe action function to apply to our data
xAnyThe argument to pass to both functions

Returns

TypeDescription
AnyReturns whatever the action function returns, or the value that was passed in
import { unless } from 'kyanite'

unless(x => x > 2, x => x * 2, 5) // => 5
unless(x => x > 5, x => x * 2, 5) // => 10

// It's also curried

const un = unless(x => x > 2, x => x * 2)

un(5) // => 5
un(1) // => 2

when(fn, act, x) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Function
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

NameTypeDescription
fnfunctionThe check function that when passed triggers the action function
actfunctionThe action function which is fired when the logic passes
xAnyThe argument to pass to both functions

Returns

TypeDescription
AnyReturns whatever the action function returns, or the value that was passed in
import { when } from 'kyanite'

when(x => x > 2, x => x * 2, 5) // => 10
when(x => x > 5, x => x * 2, 5) // => 5

// It's also curried

const w = when(x => x > 2, x => x * 2)

w(5) // => 10
w(1) // => 1

xor(a, b) → {Boolean}

Since:
  • v1.3.0
Kind:
  • function
Source:
Category:
  • Function
Signature:
  • a -> b -> Boolean

Exclusive or logical operation, returns true if one of the arguments is truthy and the other is falsy, otherwise it returns false

Parameters

NameTypeDescription
aAnyThe first value to check for a truthy value
bAnyThe second value to check for a truthy value

Returns

TypeDescription
BooleanThe boolean outcome of the check
import { xor } from 'kyanite'

xor(true, true) // => false
xor(true, false) // => true
xor(false, true) // => true
xor(false, false) // => false

concat(val, list) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • a -> Array -> Array,String -> String -> String

Take a List and concats the values into a new List

Parameters

NameTypeDescription
valAnyThe value to concat into the List
listArray | StringThe list of items or characters we want to concat the value to

Returns

TypeDescription
ArrayA newly created list with the value added
import { concat } from 'kyanite'

concat(4, [1, 2, 3]) // => [1, 2, 3, 4]
concat('bar', 'foo') // => 'foobar'

endsWith(a, list) → {Boolean}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • a -> List -> Boolean,String -> String -> Boolean

Checks to see if the provided value is at the end of a given list

Parameters

NameTypeDescription
aString | ArrayThe value to check for at the end of the list
listString | ArrayThe list to check through

Returns

TypeDescription
BooleanIf the value is at the end of the provided list
import { endsWith } from 'kyanite'

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

// It's also curried
const fn = endsWith('c')

fn('abc') // => true
fn('cba') // => false

first(x) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • [a] -> a | Undefined,String -> String | Undefined

Grabs the first index of a list

Parameters

NameTypeDescription
xArray | StringThe list or string we want to use

Returns

TypeDescription
AnyReturns whatever was the first piece of our list
import { first } from 'kyanite'

const arr = first([1, 3]) // => 1
const str = first('abc') // => 'a'

includes(value, list) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
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

NameTypeDescription
valueAnyThe value we want to search the list for
listArray | StringThe list of items or characters we want to search through

Returns

TypeDescription
BooleanA Boolean based on if the value is found or not
import { includes } from 'kyanite'

includes(3, [1, 2, 3]) // => true
includes('yan', 'kyanite') // => true

// It is also curried

const checker = includes(3)

checker([1, 2, 3]) // => true
checker('123') // => true

last(x) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • [a] -> a | Undefined,String -> String

Grabs the last index of a list

Parameters

NameTypeDescription
xArray | StringThe list or string we want to use

Returns

TypeDescription
AnyReturns whatever was the last piece of our list
import { last } from 'kyanite'

const arr = last([1, 3]) // => 3
const str = last('abc') // => 'c'

length(a) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Array
Signature:
  • Array -> Number,String -> Number

Obtains the length of the passed array

Parameters

NameTypeDescription
aArrayThe array to find the length of

Returns

TypeDescription
NumberThe length of the array
import { length } from 'kyanite'

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

nth(o, list) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • Number -> Array a -> a | Undefined,Number -> String -> String | Undefined

Returns the nth element of the given list

Parameters

NameTypeDescription
oNumberHow much to offset the value
listArray | StringThe Array or list to crawl through

Returns

TypeDescription
AnyReturns the value found at the index
import { nth } from 'kyanite'

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

// nth is curried

const third = nth(2)

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

reverse(list) → {Array, String}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • Array -> Array,String -> String

Accepts a list of values or characters and reverses it

Parameters

NameTypeDescription
listArray | StringThe list to reverse

Returns

TypeDescription
Array | StringA new reversed list
import { reverse } from 'kyanite'

reverse([1, 2, 3]) // => [3, 2, 1]
reverse([]) // => []
reverse('abc') // => 'cba'

slice(a, b, list) → {Array, String}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • List
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

NameTypeDescription
aNumberThe index at which to begin extraction
bNumberThe index for what the extraction goes to.
listArray | StringThe list of items or characters to slice

Returns

TypeDescription
Array | StringThe newly created list
import { slice } from 'kyanite'

slice(1, 3, [1, 2, 3, 4, 5]) // => [2, 3]
slice(0, 4, 'kyanite') // => 'kyan'

// It is curried

const slicer = slice(1, 3)

slicer([1, 2, 3, 4, 5]) // => [2, 3]
slicer('kyanite') // => 'yan'

startsWith(a, list) → {Boolean}

Since:
  • v0.14.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • a -> List -> Boolean,String -> String -> Boolean

Checks to see if the provided value is at the beginning of a given list

Parameters

NameTypeDescription
aString | ArrayThe value to check for at the beginning of the list
listString | ArrayThe list to check through

Returns

TypeDescription
BooleanIf the value is at the end of the provided list
import { startsWith } from 'kyanite'

startsWith('c' , 'cab') // => true
startsWith(['c'], ['c', 'b', 'a']) // => true
startsWith('b', 'abc') // => false
startsWith(['b'], ['a', 'b', 'c']) // => false

// It's also curried
const fn = startsWith('c')

fn('cab') // => true
fn('abc') // => false

tail(list) → {Array}

Since:
  • v1.2.0
Kind:
  • function
Source:
Category:
  • List
Signature:
  • List -> Array

Drops the first value of an array and returns the rest as a tail array

Parameters

NameTypeDescription
listString | ArrayThe array we want to get the tail of

Returns

TypeDescription
ArrayA new array of arrays containing the tail end values
import { tail } from 'kyanite'

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

add(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Adds the provided numbers together

Parameters

NameTypeDescription
aNumberThe first number to add
bNumberThe second number to add

Returns

TypeDescription
NumberThe sum of the numbers
import { add } from 'kyanite'

add(1, 2) // => 3

// It's also curried

const adder = add(2)

adder(3) // => 5
adder(2) // => 4

between(min, max, n) → {Boolean}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number -> Boolean

Checks to see if a number is between two other provided numbers (inclusive)

Parameters

NameTypeDescription
minNumberThe number our value should be greater than or equal too
maxNumberThe number our value should be less than or equal too
nNumberThe value to compare with

Returns

TypeDescription
BooleanWhether or not the provided number is between the other two numbers
import { between } from 'kyanite'

between(1, 3, 2) // => true
between(1, 10, 7) // => true
between(1, 10, 11) // => false

// It's also curried
const b = between(1)

b(10, 9) // => true

// A step further
const c = b(10)
// OR
// const c = between(1, 10)

c(9) // => true
c(11) // => false

clamp(min, max, val) → {Number}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number -> Number

Restricts a number to be within a range

Parameters

NameTypeDescription
minNumberThe minimum of the clamp
maxNumberThe maximum of the clamp
valNumberThe number to clamp

Returns

TypeDescription
NumberThe value if its inbetween min and max, min if its below and max if its above
import { clamp } from 'kyanite'

clamp(1, 900, 23) // => 23
clamp(1, 900, 901) // => 900
clamp(1, 900, 0) // => 1

const fn = clamp(1, 900)

fn(23) // => 23
fn(901) // => 900
fn(0) // => 1

dec(n) → {Number}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number

Takes in a number and returns it decremented by 1

Parameters

NameTypeDescription
nNumberThe number to decrement

Returns

TypeDescription
NumberThe decremented number
import { dec } from 'kyanite'

dec(1) // => 0
dec(dec(3)) // => 1

divide(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Divides the provided numbers

Parameters

NameTypeDescription
aNumberThe divisor which the dividend will be divided by
bNumberThe dividend of the division problem

Returns

TypeDescription
NumberThe quotient of the two numbers
import { divide } from 'kyanite'

divide(2, 1) // => 2

// It's also curried

const div = divide(15)

div(3) // => 5
div(5) // => 3

factors(x) → {Array}

Since:
  • v0.8.3
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Array

Takes a number and builds an array of factors for that number

Parameters

NameTypeDescription
xNumberThe number it should find the factors of

Returns

TypeDescription
ArrayA new array which will contain the valid factors of the given number
import { factors } from 'kyanite'

factors(36) // => [1, 2, 3, 4, 6, 9, 12, 18, 36]
factors(-36) // => [1, 2, 3, 4, 6, 9, 12, 18, 36]
factors(102) // => [1, 2, 3, 6, 17, 34, 51, 102]
factors(-102) // => [1, 2, 3, 6, 17, 34, 51, 102]
factors() // => []
factors(0) // => []
factors(NaN) // => []

// You can convert the array to negatives with map and negate
// (Imagining this is a brand new .js file)
import { compose, factors, map, negate } from 'kyanite'
map(negate, factors(-36)) // => [-1, -2, -3, -4, -6, -9, -12, -18, -36]
// Or even cleaner approach:
const negativeFactors = compose(map(negate), factors)

negativeFactors(-36) // => [-1, -2, -3, -4, -6, -9, -12, -18, -36]
negativeFactors(36) // => [-1, -2, -3, -4, -6, -9, -12, -18, -36]

gcd(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Determines the greatest common denominator of the numbers passed in

Parameters

NameTypeDescription
aNumberThe First number to use
bNumberThe Second number to use

Returns

TypeDescription
NumberThe Greatest Common Denominator
import { gcd } from 'kyanite'

gcd(80, 90) // => 10
gcd(20, 600) // => 20

// It's also curried

const a = gcd(80)

a(90) // => 10
a(93) // => 1

inc(n) → {Number}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number

Takes in a number and returns it incremented by 1

Parameters

NameTypeDescription
nNumberThe number to increment

Returns

TypeDescription
NumberThe incremented number
import { inc } from 'kyanite'

inc(1) // => 2
inc(inc(1)) // => 3

isEven(n) → {Boolean}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Boolean

Checks if the provided number is even or not

Parameters

NameTypeDescription
nNumberThe number to check if its even

Returns

TypeDescription
BooleanWhether or not the provided number is even
import { isEven } from 'kyanite'

isEven(2) // => true
isEven(12) // => true
isEven('h') // => false
isEven(1) // => false
isEven(NaN) // => false

isOdd(n) → {Boolean}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Boolean

Checks if the provided number is odd or not

Parameters

NameTypeDescription
nNumberThe number to check against

Returns

TypeDescription
BooleanWhether or not the number is odd
import { isOdd } from 'kyanite'

isOdd(1) // => true
isOdd(3) // => true
isOdd('h') // => false
isOdd(2) // => false
isOdd(NaN) // => false

isPrime(x) → {Boolean}

Since:
  • v0.8.3
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Boolean

Determines if the number passed in is a prime number or not

Parameters

NameTypeDescription
xNumberThe number to check if its prime or not

Returns

TypeDescription
BooleanA boolean based on if the number is prime
import { isPrime } from 'kyanite'

isPrime(5) // => true
isPrime(5009) // => true
isPrime(6) // => false
isPrime(5010) // => false

isZero(n) → {Boolean}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Boolean

Checks if the provided number is equal to the number zero or not

Parameters

NameTypeDescription
nNumberThe number to check compare

Returns

TypeDescription
BooleanWhether or not the provided number was equal to zero
import { isZero } from 'kyanite'

isZero(1) // => false
isZero('0') // => false
isZero(0) // => true

lcm(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Finds the least common multiple of the provided numbers

Parameters

NameTypeDescription
aNumberThe first number to use
bNumberThe second number to use

Returns

TypeDescription
NumberThe least common multiple of the two numbers
import { lcm } from 'kyanite'

lcm(90, 70) // => 630
lcm(91, 4) // => 364

// It's also curried

const a = lcm(90)

a(70) // => 630
a(4) // => 180

mean(x) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • [Number] -> Number

Gets the average from a given array of numbers

Parameters

NameTypeDescription
xArrayAn array of numbers to add together

Returns

TypeDescription
NumberReturns the mean average of the numbers
import { mean } from 'kyanite'

mean([1, 2, 3, 2]) // => 2
mean([2]) // => 2
mean([]) // => NaN
mean() // => Ref Error

median(list) → {Number}

Since:
  • v0.12.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • [Number] -> Number

Takes an array of numbers and calculates the median

Parameters

NameTypeDescription
listArrayThe array of numbers to calculate

Returns

TypeDescription
NumberThe calculated median from the array
import { median } from 'kyanite'

median([3, 13, 7, 5, 21, 23, 39, 23, 40, 23, 14, 12, 56, 23, 29]) // => 23
median([3, 13, 7, 5, 21, 23, 23, 40, 23, 14, 12, 56, 23, 29]) // => 22

mod(a, b) → {Number}

Since:
  • v0.12.0
Kind:
  • function
Source:
Category:
  • Number
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

NameTypeDescription
aNumberThe dividend
bNumberThe modulus

Returns

TypeDescription
NumberThe result of `b mod a`
import { mod } from 'kyanite'

mod(17, 5) // => 2
mod(-17, 5) // => 3
mod(-5, 4) // => 3
mod(17, 0) // => NaN
mod(17, -5) // => NaN
mod(17.2, 5) // => NaN
mod(17, 5.3) // => NaN

// It's also curried
const fn = mod(17)

fn(5) // => 2
fn(-5) // => NaN
fn(0) // => NaN
fn(5.3) // => NaN

multiples(limit, n) → {Array}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Array [Number]

Finds all of the multiples of a number up until the limit provided

Parameters

NameTypeDescription
limitNumberThe limit to stop at, once the result equals or exceeds this value the function will return the current list
nNumberThe number to find the multiples for

Returns

TypeDescription
ArrayA new Array of multiples that the function found
import { multiples } from 'kyanite'

multiples(100, 5) // => [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
multiples(100, 6) // => [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]

// It's also curried
const fn = multiples(100)

fn(5) // => [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
fn(6) // => [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]

multiply(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Multiplies the provided numbers

Parameters

NameTypeDescription
aNumberThe first factor to multiply with
bNumberThe second factor to multiply with

Returns

TypeDescription
NumberThe product of the numbers
import { multiply } from 'kyanite'

multiply(2, 1) // => 2

// It's also curried

const mul = multiply(5)

mul(3) // => 15
mul(2) // => 10

negate(n) → {Number}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number

Negates the number passed in

Parameters

NameTypeDescription
nNumberThe number to negate

Returns

TypeDescription
NumberThe negated number
import { negate } from 'kyanite'

negate(1) // => -1
negate(-1) // => 1

pow(a, b) → {Number}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Take a base number and brings it to the value of base^exponent

Parameters

NameTypeDescription
aNumberThe exponent used to raise the base number
bNumberThe base Number

Returns

TypeDescription
NumberA number representing the given base taken to the power of the given exponent
import { pow } from 'kyanite'

pow(3, 7) // => 343
pow(0.5, 4) // => 2

// It's also curried
const p = pow(3)

p(7) // => 343

product(arr) → {Number}

Since:
  • v0.11.3
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Array -> Number

Takes an Array of numbers and multiplies all of them together

Parameters

NameTypeDescription
arrArrayThe array of numbers to combine

Returns

TypeDescription
NumberThe product of the numbers
import { product } from 'kyanite'

product([1, 2, 3]) // => 6
product([2, 3, 0]) // => 0

range(from, to) → {Array}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number a -> Number b -> [Number a...b]

Create an array range from start to end

Parameters

NameTypeDescription
fromNumberStarting number for the range
toNumberNumber to end on for the range

Returns

TypeDescription
ArrayReturns an array of numbers consisting of the range
import { range } from 'kyanite'

range(3, 7) // => [3, 4, 5, 6]
range(0, 3) // => [0, 1, 2]
range(0, 0) // => []
range(NaN) // => []

rem(a, b) → {Number}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Takes two numbers and gets the remainder from the division

Parameters

NameTypeDescription
aNumberThe dividend of the division problem
bNumberThe divisor which the dividend will be divided by

Returns

TypeDescription
NumberThe remainder of the two numbers
import { rem } from 'kyanite'

rem(5, 12) // => 2
rem(2, -1) // => -1
rem(2, NaN) // => NaN

// It's also curried
const r = rem(5)

r(12) // => 2

round(precision, num) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Round a number using exponent rounding to a desired precision

Parameters

NameTypeDescription
precisionNumberThe precision we want the number to be rounded to
numNumberThe number we are going to round

Returns

TypeDescription
NumberThe rounded number to the desired precision
import { round } from 'kyanite'

round(2, 112.336) // => 112.34
round(3, 112.3354) // => 112.335

// It is curried
const rounder = round(3)

rounder(122.4456) // => 112.446
rounder(122.332) // => 122.332

subtract(a, b) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number

Subtracts the provided numbers

Parameters

NameTypeDescription
aNumberThe subtrahend number to subtract with
bNumberThe minuend number to subtract from

Returns

TypeDescription
NumberThe difference of the numbers
import { subtract } from 'kyanite'

subtract(2, 1) // => 1

// It's also curried

const sub = subtract(5)

sub(3) // => 2
sub(2) // => 3

sum(arr) → {Number}

Since:
  • v0.11.3
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Array -> Number

Takes an Array of numbers and adds all of them together

Parameters

NameTypeDescription
arrArrayThe array of numbers to combine

Returns

TypeDescription
NumberThe sum of the numbers
import { sum } from 'kyanite'

sum([1, 2, 3]) // => 6
sum([1, 2, -3]) // => 0

within(min, max, n) → {Boolean}

Since:
  • v0.11.0
Kind:
  • function
Source:
Category:
  • Number
Signature:
  • Number -> Number -> Number -> Boolean

Checks to see if a number is between two other numbers (exclusive)

Parameters

NameTypeDescription
minNumberThe number our value should be greater than or equal too
maxNumberThe number our value should be less than or equal too
nNumberThe value to compare with

Returns

TypeDescription
BooleanWhether or not the provided number is between the other two numbers
import { within } from 'kyanite'

within(1, 3, 2) // => true
within(1, 10, 7) // => true
within(1, 10, 10) // => false

const fn = within(1, 10)

fn(4) // => true
fn(10) // => false
fn(1) // => false

amend(a, b) → {Object}

Since:
  • v0.11.2
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Object -> Object -> Object

Updates an object by amending from right to left

Parameters

NameTypeDescription
aObjectThe new object data or values
bObjectThe object we want to amend/update

Returns

TypeDescription
ObjectThe newly amended object (shallow copy)
import { amend } from 'kyanite'

amend({ b: 2 }, { a: 1 }) // => { a: 1, b: 2 }

// It's also curried
const fn = amend({ b: 2 })

fn({ a: 1 }) // => { a: 1, b: 2 }
fn({ c: 3 }) // => { c: 3, b: 2 }

any(schema, obj) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
schemaObjectAn Object schema containing the matching properties and the function to run
objObjectThe object to iterate through

Returns

TypeDescription
BooleanA 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 }) // => true
run({ a: 'xxx', b: 'bar' }) // => false

draft(fn, obj) → {Object}

Since:
  • v0.6.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Function (a -> b) -> Object { k: v }

Runs a provided function against all of the values that are within the provided object

Parameters

NameTypeDescription
fnfunctionThe Function we want to apply to all of the data values
objObjectThe object to apply our functions too

Returns

TypeDescription
ObjectA new object with the updated data from our applied function
import { draft } from 'kyanite'

draft(x => x * 2, { a: 1, b: 2, c: 3 }) // => { a: 2, b: 4, c: 6 }

// It's also curried

const d = draft(x => x * 2)

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

height(obj) → {Number}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Object -> Number

Works a lot like length for arrays, but allows you to get the length of an object

Parameters

NameTypeDescription
objObjectThe object we want to read the length of

Returns

TypeDescription
NumberThe length of the object
import { height } from 'kyanite'

height({ a: 1, b: 2 }) // => 2

keys(obj) → {Array}

Since:
  • v3.0.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • { k: v } -> [k]

Returns a list of all the own properties of an object

Parameters

NameTypeDescription
objObjectThe object we want to pull the keys from

Returns

TypeDescription
ArrayReturns an array of keys from the provided object
import { keys } from 'kyanite'

keys({ a: 1, b: 2, c: 3, d: { x: 100, y: 200 } }) // => ['a', 'b', 'c', 'd']

omit(keys, obj) → {Object}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • [String] -> {String: *} → {String: *}

Builds out a new object but omits the provided keys in the new one

Parameters

NameTypeDescription
keysArrayThe keys in which to omit from the data
objObjectThe object to search through and filter

Returns

TypeDescription
ObjectReturns the newly created data without the omitted values
import { omit } from 'kyanite'

const obj = omit(['test'], { test: '3432', thing: 123 }) // => { thing: 123 }
const arr = omit(['a', 'b'], { a: 1, b: 2, c: 3}) // => { c: 3 }

// omit is curried

const omitKeys = omit(['test'])

omitKeys({ test: '3432', thing: 123 }) // => { thing: 123 }

omitBy(fn, obj) → {Object}

Since:
  • v1.5.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
fnfunctionThe function to run our values through the key is also provided to this function as the 2nd param
objObjectThe object to search through and filter

Returns

TypeDescription
ObjectReturns the newly created data without the omitted values
import { omitBy } from 'kyanite'

const obj = omitBy(['test'], { test: '3432', thing: 123 }) // => { thing: 123 }
const arr = omitBy(['a', 'b'], { a: 1, b: 2, c: 3}) // => { c: 3 }

// omitBy is curried

const omitKeys = omitBy(['test'])

omitKeys({ test: '3432', thing: 123 }) // => { thing: 123 }

over(key, fn, acc) → {Object}

Since:
  • v0.10.1
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • String -> Function -> Object -> Object

Applies a function to a value within an object

Parameters

NameTypeDescription
keyStringThe key to look for within the object
fnfunctionThe function to apply to the value
accObjectThe object accumulator

Returns

TypeDescription
ObjectA new object with the applied value
import { over } from 'kyanite'

over('b', x => x + 1, { a: 1, b: 1, c: 3 }) // => { a: 1, b: 2, c: 3 }

// It's also curried

const o = over('b')
const withFn = o(x => x + 1)

o(x => x - 1, { a: 1, b: 3 }) // => { a: 1, b: 2 }
withFn({ a: 1, b: 1 }) // => { a: 1, b: 2 }

path(keys, obj) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
keysArrayThe path to safely traverse the object with
objObjectThe object to traverse

Returns

TypeDescription
AnyReturns the value if found, undefined if not
import { path } from 'kyanite'

path(['a', 'b'], { a: { b: 3 } }) // => 3
path(['a', 'b', 'c'], { a: 3 }) // => undefined

// Is also curried

const safetyPath = path(['a', 'b'])

safetyPath({ a: { b: 2 } }) // => 2

pathOr(a, keys, obj) → {Any}

Since:
  • v0.10.2
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
aAnyThe default value to return if the value isn't found
keysArrayThe path to traverse the object with
objObjectThe object to traverse

Returns

TypeDescription
AnyEither the found value or the provided default value
import { pathOr } from 'kyanite'

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

// It's also curried
const fn = pathOr('N/A')
const withKeys = fn(['a', 'b'])

fn(['c', 'd'], { c: { d: 2 } }) // => 2
withKeys({ a: { b: 1 } }) // => 1
fn(['c', 'd'], { d: { c: 1 } }) // => 'N/A'
withKeys({ b: { a: 1 } }) // => 'N/A'

pathSatisfies(pred, keys, obj) → {Any}

Since:
  • v1.6.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • (a -> Boolean) -> [Idx] -> {a} -> Boolean

Runs a path check on a given object and then runs a predicate function on the result

Parameters

NameTypeDescription
predfunctionThe predicate function to run on the value that comes back from the object path
keysArrayThe path to safely traverse the object with
objObjectThe object to traverse

Returns

TypeDescription
Anytrue if the given path satifies the given predicate, false otherwise
import { pathSatisfies } from 'kyanite'

pathSatisfies(y => y > 0, ['x', 'y'], { x: { y: 2 } }) // => true
pathSatisfies(y => y > 0, ['a', 'b', 'c'], { a: 3 }) // => false

// Is also curried

const safetyPath = pathSatisfies(y => y > 0, ['x', 'y'])

safetyPath({ x: { y: 2 } }) // => true

pick(keys, obj) → {Object}

Since:
  • v2.1.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • [k] -> { k: a } -> { k: a }

Picks only the requested keys from a provided object

Parameters

NameTypeDescription
keysArrayThe keys we want to pick out of the object
objObjectThe object to pull the data from

Returns

TypeDescription
ObjectReturns a new object of only the picked keys provided
import { pick } from 'kyanite'

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

// Is also curried

const picker = pick(['a', 'd'])

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

plan(schema, obj) → {Object}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Object -> Object -> Object

Uses a schema to allow you to plan out functions being ran against values within your object

Parameters

NameTypeDescription
schemaObjectThe object of functions we want to apply
objObjectThe object to apply our functions too

Returns

TypeDescription
ObjectA 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 }) // => { a: 10, b: 20 }

// It's also curried

const p = plan(testFns)

p({ a: 5, b: 10 }) // => { a: 10, b: 20 }

prop(p, obj) → {Any}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • k -> {k: v} -> v | Undefined

Brings back the indicated property of an object if it exists

Parameters

NameTypeDescription
pArrayThe array path of the property we are looking for
objObjectThe object to search through

Returns

TypeDescription
AnyThe value that exists at 'obj.p'
import { prop } from 'kyanite'

prop('thing', { thing: 'test' }) // => 'test'
prop('thing', {}) // => undefined
map(prop('a'), [{ a: 1 }, { a: 2 }, { a: 3 }]) // => [1, 2, 3]

// It is also curried

const proper = prop('a')

proper({ a: 1, b: 2 }) // => 1

propEq(key, val, obj) → {Boolean}

Since:
  • v0.12.2
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
keyStringThe key to look for in the object
valAnyThe value the property should equal
objObjectThe object to pull the property from to compare

Returns

TypeDescription
BooleanWhether 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) // => false
propEq('hair', 'brown', george) // => false
propEq('hair', 'brown', rusty) // => true

// It's also curried

const fn = propEq('hair')
const gn = fn('brown')

kids.filter(fn('blond')) // => [abby]
kids.filter(gn) // => [fred, rusty]

propOr(def, key, obj) → {Any}

Since:
  • v0.12.3
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
defAnyThe default value to fallback to if the prop returned null
keyStringThe property name within the provided object
objObjectThe object to pull the property from

Returns

TypeDescription
AnyThe value of the found prop, or the provided default value
import { propOR } from 'kyanite'

propOr('N/A', 'foo', { bar: 1, foo: 2 }) // => 2
propOr('N/A', 'foo', { bar: 1 }) // => 'N/A'

// It's also curried
const fn = propOr('N/A')
const gn = fn('foo')

fn('bar', { bar: 1 }) // => 1
fn('bar', { foo: 1 }) // => 'N/A'
gn({ foo: 1 }) // => 1
gn({ baz: 1 }) // => 'N/A'

propSatisfies(pred, key, obj) → {Any}

Since:
  • v1.6.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • (a -> Boolean) -> String -> { String: a } -> Boolean

Pulls a values from an object and then passes it to a predicate function

Parameters

NameTypeDescription
predfunctionThe predicate function to run on the value that comes back from the object
keyArrayThe key to pull from the provided object
objObjectThe object to pull from

Returns

TypeDescription
Anytrue if the found value satifies the given predicate, false otherwise
import { propSatisfies } from 'kyanite'

propSatisfies(y => y > 0, 'y', { x: 1, y: 4 }) // => true
propSatisfies(y => y > 0, 'b', { a: 3 }) // => false

// Is also curried

const safetyProp = propSatisfies(y => y > 0, 'y')

safetyProp({ x: 1, y: 4 }) // => true

props(keys, obj) → {Array}

Since:
  • v0.4.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Object { k: v } -> Array v

Pulls a list of values from an object and returns them as an array

Parameters

NameTypeDescription
keysArrayThe list of properties to get values from
objObjectThe object to map through

Returns

TypeDescription
ArrayAn array of values pulled from the object
import { props } from 'kyanite'

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

// It's also curried

const g = props(['a', 'b'])

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

sift(fn, obj) → {Object}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
fnfunctionA function to run against the values within the object
objObjectThe object to sift through

Returns

TypeDescription
ObjectA new filtered out object
import { sift } from 'kyanite'

sift(x => typeof x === 'string', {
  id: 44,
  thing: 'test',
  other: 'cool'
}) // => { thing: 'test', other: 'cool' }

// It's also curried

const sifter = sift(x => typeof x === 'string')

sifter({ id: 44, thing: 'test', other: 'cool' }) // => { thing: 'test', other: 'cool' }

values(obj) → {Array}

Since:
  • v1.4.0
Kind:
  • function
Source:
Category:
  • Object
Signature:
  • Object { k: v } -> Array v

Takes an object and returns a list of the object values

Parameters

NameTypeDescription
objObjectThe object to grab the values from

Returns

TypeDescription
ArrayAn array of values pulled from the object
import { values } from 'kyanite'

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

whole(schema, obj) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
schemaObjectAn Object schema containing the matching properties and the function to run
objObjectThe object to iterate through

Returns

TypeDescription
BooleanA 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 }) // => true
run({ a: 'xxx', b: 'xxx', x: 11, y: 19 }) // => false

withDefaults(def, obj) → {Object}

Since:
  • v1.0.0
Kind:
  • function
Source:
Category:
  • Object
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

NameTypeDescription
defObjectAn object containing the desired default values
objObjectThe data object to check

Returns

TypeDescription
ObjectA new object with filled in defaults if needed
import { withDefaults } from 'kyanite'

withDefaults({ a: 1, b: 2, c: 3 }, { b: 10, c: 4 }) // => { a: 1, b: 10, c: 4 }
withDefaults({ a: 1, b: 2, c: 3 }, { a: null, b: 10, c: 4 }) // => { a: 1, b: 10, c: 4 }
withDefaults({ a: 1, b: 2, c: 3 }, { b: NaN, c: 4 }) // => { a: 1, b: 2, c: 4 }

// It's also curried
const fn = withDefaults({ a: 1, b: 2, c: 3 })

fn({ b: 10, c: 4 }) // => { a: 1, b: 10, c: 4 }
fn({ a: 12 }) // => { a: 12, b: 2, c: 3 }
fn({}) // => { a: 1, b: 2, c: 3 }

capitalize(str) → {String}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • String -> String

Capitalizes the first letter of a string

Parameters

NameTypeDescription
strStringThe string we want to capitalize

Returns

TypeDescription
StringThe capitalized string
import { capitalize } from 'kyanite'

capitalize('test') // => 'Test'
capitalize('small brown cow') // => 'Small brown cow'

fuzzySearch(needle, haystack) → {Boolean}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • a -> Boolean

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

NameTypeDescription
needleStringThe Item to search
haystackStringThe value to search for

Returns

TypeDescription
BooleanReturns a boolean determined by if the value is found or not by the search
import { fuzzySearch } from 'kyanite'

fuzzySearch('te', 'test') // => true
fuzzySearch('dog', 'testing') // => false

// search is also curried

const search = fuzzySearch('te')
search('test') // => true

match(reg, str) → {Array}

Since:
  • v0.10.2
Kind:
  • function
Source:
Category:
  • String
Signature:
  • RegExp -> String -> Array

Matches a string against some regexp to build an array of matching strings

Parameters

NameTypeDescription
regRegExpThe regex to match the string against
strStringThe string to match

Returns

TypeDescription
ArrayAn array of matched strings
import { match } from 'kyanite'

match(/([a-z]a)/g, 'bananas') //=> ['ba', 'na', 'na']
match(/a/, 'b') // => null

// It's also curried
const fn = match(/([a-z]a)/g)

fn('bananas') // => ['ba', 'na', 'na']
fn('why') // => null

replace(a, b, str) → {String}

Since:
  • v0.10.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • RegExp|String -> String -> String -> String

Replaces a substring or regex match in a string and then replaces it with the provided value

Parameters

NameTypeDescription
aString | RegExpThe String or RegExp we want to find and replace
bStringThe value we want to replace it with
strStringThe String to search through

Returns

TypeDescription
StringThe resulting string
import { replace } from 'kyanite'

replace('foo', 'bar', 'foofoo') // => 'barfoo'
replace(/foo/g, 'bar', 'foofoo') // => 'barbar'

// It's also curried
const rep = replace('foo')
const with = rep('bar')

rep('baz', 'foofoo') // => 'bazfoo'
with('foofoo') // => 'barfoo'

split(char, str) → {Array}

Since:
  • v0.9.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • String -> String -> Array

Takes a string and splits it into an array based on the character passed in

Parameters

NameTypeDescription
charStringThe character to split the string by
strStringThe string we want to split

Returns

TypeDescription
ArrayA new array of characters from the string
import { split } from 'kyanite'

split('', 'abc') // => ['a', 'b', 'c']
split(':', '123:334') // => ['123', '334']

const sp = split('')

sp('abc') // => ['a', 'b', 'c']

test(reg, str) → {Boolean}

Since:
  • v0.10.2
Kind:
  • function
Source:
Category:
  • String
Signature:
  • RegExp -> String -> Boolean

Tests regexp against a string value returns true if matches were found, false if not

Parameters

NameTypeDescription
regRegExpThe regex to test the string against
strStringThe string to test

Returns

TypeDescription
BooleanA boolean based on if the string passes the test or not
import { test } from 'kyanite'

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

// It's also curried
const fn = test(/^a/)

fn('abc') // => true
fn('bca') // => false

toLower(a) → {String}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • String -> String

Transform a provided string into an lowercase version

Parameters

NameTypeDescription
aStringThe string to lower case

Returns

TypeDescription
StringThe string in lower case format
import { toLower } from 'kyanite'

toLower('HI') // => 'hi'
toLower('TEST.123.HELLO') // => 'test.123.hello'

toUpper(a) → {String}

Since:
  • v0.7.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • String -> String

Transform a provided string into an uppercase version

Parameters

NameTypeDescription
aStringThe string to upper case

Returns

TypeDescription
StringThe string in upper case format
import { toUpper } from 'kyanite'

toUpper('hi') // => 'HI'
toUpper('test.123.hello') // => 'TEST.123.HELLO'

trim(str) → {String}

Since:
  • v0.1.0
Kind:
  • function
Source:
Category:
  • String
Signature:
  • String a -> String a

Accepts a string value and trims it's white space

Parameters

NameTypeDescription
strStringThe string to trim

Returns

TypeDescription
StringThe trimmed string
import { trim } from 'kyanite'

trim('my new cow   ') // => 'my new cow'
trim('   new things   ') // => 'new things'