Skip to content

Augmentedjs/next-core-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

next-core-utilities

Augmented Next Core - Utilities and Functions

API

Table of Contents

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

Returns boolean Returns true of the param is an object

allKeys

Augmented.allKeys

Parameters

Returns array Returns the array of ALL keys including prototyped

create

Augmented.create

Parameters

  • prototype object The input prototype
  • props object The properties (optional)

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 function
  • context object The context to call from
  • args 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 print
  • spaces boolean Use spaces instead of tabs (optional, default false)
  • number number Number spaces to use (if spaces is true) (optional, default 2)

Returns string formatted JSON string

prettyPrintHTML

Prints an object nicely in HTML

Parameters

  • obj object The object to print
  • indent (optional, default 0)
  • array (optional, default false)
  • last (optional, default true)

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

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 transform
  • type 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

  • object object Object to filter
  • keys array keys to filter from the object

Returns object returns a new object with only these keys

findByMatchingProperties

find an oject from matching properties

Parameters

  • set Array array/set of objects
  • properties object properties to find by

Returns array returns a the objects that matched

sortObjects

Sorts an array of objects by propery in object

Parameters

  • array array The object array to sort
  • key object The property to sort by

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 format
  • pres 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 characters
  • pad 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

  • date date The date to format
  • noTime boolean Exclude the time

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 item
  • second any The second item

Returns boolean Returns true if equal

About

Augmented.js Next Core - Utilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published