capitalize

Capitalize each word in a string

capitalize(val: String): String
Parameters
val (String = '') String to capitalize
Returns
String:
Example
capitalize('foo') // 'Foo'
capitalize('BAR BAZ') // 'Bar Baz'

compose

Compose functions

compose(funcs: ...any): any
Parameters
funcs (...any) Functions to compose
Returns
any:
Example
const addOne = x => x + 1
const addThree = compose(addOne, addOne, addOne)

addThree(3) // 6

curry

Curry a function

curry(func: Function, args: ...any): any
Parameters
func (Function) Function to curry
args (...any)
Returns
any:
Example
const add = (x, y) => x + y
const addTwo = curry(add, 2)
addTwo(4) // 6

debounce

Debounce function invocations

debounce(func: Function, wait: Integer?, immediate: Boolean?)
Parameters
func (Function) Function to debounce
wait (Integer? = 250) Wait period
immediate (Boolean? = false) Whether function should be invoked immediately
Example
function log() { console.log('hi') }
const debouncedLog = debounce(log)
debouncedLog()
debouncedLog()
debouncedLog() // Hi

filter

Iterates over elements returning an array of all elements predicate returns truthy

filter(func: Function, arg: Array?): Array
Parameters
func (Function) Predicate to filter by
arg (Array?) Array to filter
Returns
Array:
Example
const items = [1, 2, 3, 4]
const isMoreThanTwo = x => x > 2

filter(isMoreThanTwo)(items) // [3, 4]
filter(isMoreThanTwo, items) // [3, 4]

flatten

Flattens array

flatten(arr: Array, deeply: Boolean): Array
Parameters
arr (Array = []) Array to flatten
deeply (Boolean = true) Flatten deeply
Returns
Array:
Example
flatten([1, [2, 3]]) // [1, 2, 3]

getProp

Get a nested object property using dot notation

getProp(obj: Object, key: String, def: Any)
Parameters
obj (Object) Object to get property from
key (String) Key to find
def (Any) Default value if key not find

hasProp

Check if nested key exists in a object

hasProp(obj: Object, key: String)
Parameters
obj (Object) Object to check
key (String) Key to find

isArr

Check if value is a array

isArr(val: any): Boolean
Parameters
val (any) Value to check
Returns
Boolean:
Example
isArr([]) // true
isArr(1) // false

isBool

Check if value is boolean

isBool(val: any): Boolean
Parameters
val (any) Value to check
Returns
Boolean:
Example
isBool(true) // true
isBool(false) // true
isBool(1) // false

isEmpty

Check if string, object or array empty

isEmpty(val: any)
Parameters
val (any = '') Value to check

isErr

Check if value is error

isErr(val: any): Boolean
Parameters
val (any) Value to check
Returns
Boolean:
Example
isErr(new Error('example')) // true
isErr('example') // false

isFunc

Check if one or more values are functions

isFunc(values: ...any): Boolean
Parameters
values (...any)
Returns
Boolean:
Example
import isFunc from 'nova-is-func'
isFunc(() => {}) // true
isFunc(false) // false

isInt

Check if one or more values are integers

isInt(values: ...any, val: any)
Parameters
values (...any)
val (any) Value to check
Example
import isInt from 'nova-is-num'
isInt(1) // true
isInt(1, 2, 3) // true
isInt(1.1) // false

isNum

Check if one or more values are numbers

isNum(values: ...any)
Parameters
values (...any)

isObj

Check if value is object

isObj(val: any)
Parameters
val (any) Value to check

isStr

Check if

isStr(args: ...any, val: any)
Parameters
args (...any)
val (any) Value to check

noop

Performs no operation

noop(): any
Returns
any: undefined
Example
import noop from 'nova-noop'
console.log(noop()) // undefined

random

Get a random integer in range

random(min: Integer, max: Integer)
Parameters
min (Integer) Minimum value
max (Integer) Maximum value

randomize

Randomize items in array

randomize(arr: Array)
Parameters
arr (Array) Array to randomize

range

JS version of Python range function. Based on https://stackoverflow.com/a/8273091/7027045

range(start: Number, end: Number, step: Number)
Parameters
start (Number) Start of range
end (Number) End of range
step (Number = 1) Range step size

sortBy

Sort array by object property

sortBy(arr: Array, key: String, compareFunc: Function)
Parameters
arr (Array = []) Array of objects
key (String) Property to short by
compareFunc (Function = defaultCompareFunc) Camparison function

throttle

Throttle a function's invocation

throttle(func: Function, delay: any, wait: Integer)
Parameters
func (Function) Function to throttle
delay (any = 250)
wait (Integer) Wait in miliseconds

import throttle from 'nova-throttle'

const sayHi = () => console.log('Hi')

const throttledHi = throttle(sayHi, 1000)

throttledHi() // 'Hi' throttledHi() throttledHi()