Capitalize each word in a string
(String
= ''
)
String to capitalize
String
:
capitalize('foo') // 'Foo'
capitalize('BAR BAZ') // 'Bar Baz'
Compose functions
(...any)
Functions to compose
any
:
const addOne = x => x + 1
const addThree = compose(addOne, addOne, addOne)
addThree(3) // 6
Curry a function
(Function)
Function to curry
(...any)
any
:
const add = (x, y) => x + y
const addTwo = curry(add, 2)
addTwo(4) // 6
Debounce function invocations
(Function)
Function to debounce
(Integer?
= 250
)
Wait period
(Boolean?
= false
)
Whether function should be invoked immediately
function log() { console.log('hi') }
const debouncedLog = debounce(log)
debouncedLog()
debouncedLog()
debouncedLog() // Hi
Iterates over elements returning an array of all elements predicate returns truthy
Array
:
const items = [1, 2, 3, 4]
const isMoreThanTwo = x => x > 2
filter(isMoreThanTwo)(items) // [3, 4]
filter(isMoreThanTwo, items) // [3, 4]
Flattens array
Array
:
flatten([1, [2, 3]]) // [1, 2, 3]
Get a nested object property using dot notation
Check if nested key exists in a object
Check if value is a array
(any)
Value to check
Boolean
:
isArr([]) // true
isArr(1) // false
Check if value is boolean
(any)
Value to check
Boolean
:
isBool(true) // true
isBool(false) // true
isBool(1) // false
Check if string, object or array empty
(any
= ''
)
Value to check
Check if value is error
(any)
Value to check
Boolean
:
isErr(new Error('example')) // true
isErr('example') // false
Check if one or more values are functions
(...any)
Boolean
:
import isFunc from 'nova-is-func'
isFunc(() => {}) // true
isFunc(false) // false
Check if one or more values are integers
(...any)
(any)
Value to check
import isInt from 'nova-is-num'
isInt(1) // true
isInt(1, 2, 3) // true
isInt(1.1) // false
Check if one or more values are numbers
(...any)
Check if value is object
(any)
Value to check
Check if
(...any)
(any)
Value to check
Performs no operation
any
:
undefined
import noop from 'nova-noop'
console.log(noop()) // undefined
Get a random integer in range
(Integer)
Minimum value
(Integer)
Maximum value
Randomize items in array
(Array)
Array to randomize
JS version of Python range function. Based on https://stackoverflow.com/a/8273091/7027045
Sort array by object property
Throttle a function's invocation
(Function)
Function to throttle
(any
= 250
)
(Integer)
Wait in miliseconds
import throttle from 'nova-throttle'
const sayHi = () => console.log('Hi')
const throttledHi = throttle(sayHi, 1000)
throttledHi() // 'Hi' throttledHi() throttledHi()