UI Utilities
A small ES6 library of common utility functions.
Use
Install
npm install ui-utils --save
Import
;
API
camelToDash()
Convert camelCase strings to dash-case
; // 'camel-case'
currentTime()
Get current page timestamp
Uses performance.now()
if available, falls back to Date()
.
createBuffer()
Create a buffer array
Create a FIFO buffer array. Default maximum size is 3
items.
Currently only push
checks for maximum size.
Set maximum size
const buffer = ;buffer;buffer1; // 3
each()
Iterate over an object
{} ;
Checks for hasOwnProperty
before firing callback
.
hasChanged()
true
if different
Compare two iterations of the same object and return const a = foo: 1 ;const b = foo: 1 ;const c = foo: 2 ; ; // false; // true
isArray()
Check if provided variable is an array
; // true; // false
isFunc()
Check if provided variable is a function
; // true; // false
isNum()
Check if provided variable is a number
; // true; // false
isObj()
Check if provided variable is an object
; // true; // false
isRelativeValue()
Check if provided variable is a relative value
; // true; // false
isString()
Check if provided variable is a string
; // true; // false
toDecimal()
Round number to x decimal places
const pi = 314159265359; ; // 3.14; // 3.14159
splitValueUnit()
value
and unit
props
Split a value with a unit into an object with ;/* Returns: { value: 200, unit: 'px' }*/