next-core-utilities
v3.4.1
Published
Augmented Next Core - Utilities and Functions.
Downloads
195
Maintainers
Readme
next-core-utilities
Augmented Next Core - Utilities and Functions
API
Table of Contents
- isString
- isFunction
- has
- isObject
- allKeys
- create
- result
- arrayhas
- exec
- isDefined
- prettyPrint
- prettyPrintHTML
- shuffle
- binarySearch
- TransformerType
- Transformer
- wrap
- filterObject
- findByMatchingProperties
- sortObjects
- mergeSort
- mergeSort
- mergeSort
- QuickSort
- formatBinary
- binaryToHex
- formatDate
- filter
- sizeOf
- formatByteSize
- memorySizeOf
- hammingDistance
- isEqual
isString
isString - checks if a value is a String
Parameters
val
variable
string to check
Returns boolean true if value is a string
isFunction
isFunction - returns true if called name is a function simular to jQuery .isFunction method
Parameters
name
function The name of the function to test
Returns any true if called name is a function
has
has
Parameters
Returns boolean Returns true of the key exists
isObject
isObject
Parameters
obj
object The input object
Returns boolean Returns true of the param is an object
allKeys
Augmented.allKeys
Parameters
obj
object The input object
Returns array Returns the array of ALL keys including prototyped
create
Augmented.create
Parameters
Returns object Returns the created object
result
Augmented.result - returns named property in an object simular to underscore .result method
Returns any named property in an object
arrayhas
Array.has - returns is a property is in the array (very fast return)
Parameters
Returns any true if property is included in an array
exec
exec method - Execute a function by name
Parameters
functionName
string The name of the functioncontext
object The context to call fromargs
object Arguments
isDefined
isDefined - Checks and returns if a passed variable is defined
Parameters
val
variable
string to check
Returns boolean true if value is defined
prettyPrint
Prints an object nicely
Parameters
obj
object The object to printspaces
boolean Use spaces instead of tabs (optional, defaultfalse
)number
number Number spaces to use (if spaces is true) (optional, default2
)
Returns string formatted JSON string
prettyPrintHTML
Prints an object nicely in HTML
Parameters
obj
object The object to printindent
(optional, default0
)array
(optional, defaultfalse
)last
(optional, defaulttrue
)
Returns string formatted JSON string in HTML
shuffle
Shuffles an Array with Fisher-Yates Shuffle algorithm
Parameters
array
array The array to shuffle
Returns array A new shuffled array
binarySearch
Performs a binary search on the host array. vs indexOf Binary Search is a complexity of O(n log n) vs O(n) with indexOf
Parameters
arr
Array The array.find
Any The item to search for within the array.comparator
function The comparator to use
Returns Number The index of the element which defaults to -1 when not found.
TransformerType
Augmented.Utility.TransformerType Transformer type for use in the transformer
Type: Symbol
Properties
String
Symbol Standard StringInteger
Symbol IntegerNumber
Symbol Any numberBoolean
Symbol True/FalseArray
Symbol Stanrdard ArrayObject
Symbol Any ObjectNull
Symbol Null
Transformer
Augmented.Utility.Transformer Transform an object, type, or array to another type, object, or array
transform
The transformer type enum
Type: Augmented.Utility.TransformerType
Parameters
source
type
transform
Transform an object, primitive, or array to another object, primitive, or array
Parameters
source
object Source primitive to transformtype
Augmented.Utility.TransformerType Type to transform to
Returns object returns a transformed object or primitive
isType
Returns a Augmented.Utility.TransformerType of a passed object
Parameters
source
object The source primitive
Returns Augmented.Utility.TransformerType type of source as Augmented.Utility.TransformerType
wrap
Wrap method to handle wrapping functions (simular to _.wrap)
Parameters
fn
wrap
filterObject
filter an object from array of values
Parameters
Returns object returns a new object with only these keys
findByMatchingProperties
find an oject from matching properties
Parameters
Returns array returns a the objects that matched
sortObjects
Sorts an array of objects by propery in object
Parameters
Returns array The sorted array
mergeSort
Split the array into halves and merge them recursively
Parameters
array
array The array to sort
Returns array The sorted array
mergeSort
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Parameters
array
array The array to sort
Returns array The sorted array
mergeSort
Simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Parameters
array
array The array to sort
Returns array The sorted array
QuickSort
Quick Sort implimentation for Arrays -
Parameters
arr
Array Array to Sort
Returns Array Returns a sorted array
formatBinary
Format a number into binary string at a set precision
Parameters
num
num The number to formatpres
pres The bit precision
Returns string The formatted binary string
binaryToHex
Format a binary string into a hex value (two characters)
Parameters
binary
binary The 8-bit binary string to return as hex characterspad
pad Add a zero if under '10'
Returns string The hex value
formatDate
Format a date to US format (MM/DD/YYYY HH:mm AM/PM) or (MM/DD/YYYY) only
Parameters
Returns string The formatted date
filter
Filter a string by removing a char
Parameters
Returns string The filtered string
sizeOf
Returns the size in bytes of an object
Returns Number size in bytes
formatByteSize
Returns the number (in bytes) as a human readable string
Returns String size in formated human readable string
memorySizeOf
Returns the object size as a human readable string
Returns String size in formated human readable string
hammingDistance
The Hamming Distance is the number of different symbols between two strings/numbers (equal length). It can be also considered as the number of changes required to convert from one input to another.
Parameters
Returns number the distance
isEqual
Performs a deep comparison between two values to determine if they are equivalent. This is a simular function to lodash isEquals.
Note: This method supports comparing arrays, array buffers, booleans, dates, error objects, maps, numbers, objects, regexes, sets, strings, symbols, and typed arrays. Objects are compared by their own, not inherited, enumerable properties. Functions are compared by strict equality, i.e. ===. DOM nodes are considered objects and treaked as such as this library does not assume browsers.
Parameters
first
any The first itemsecond
any The second item
Returns boolean Returns true if equal