Class: GenUtils

GenUtils()

Collection of general purpose utilities. TODO: could pull in assert and remove these asserts TODO: needs cleanup as ES6+ utility class

Constructor

new GenUtils()

Source:

Methods

(static) arrayContains(arr, obj)

Indicates if the given array contains the given object.
Parameters:
Name Type Description
arr is the array that may or may not contain the object
obj is the object to check for inclusion in the array
Source:
Returns:
true if the array contains the object, false otherwise

(static) arraysEqual(arr1, arr2)

Determines if two arrays are equal.
Parameters:
Name Type Description
arr1 is an array to compare
arr2 is an array to compare
Source:
Returns:
true if the arrays are equal, false otherwise

(static) arrToCsv(arr)

Converts the given array to a CSV string.
Parameters:
Name Type Description
arr is a 2-dimensional array of strings
Source:
Returns:
the CSV string

(static) assertArray(arg, msg)

Asserts that the given argument is an array.
Parameters:
Name Type Description
arg is the argument to assert as an array
msg is the message to throw if the argument is not an array
Source:

(static) assertBase58(arg, msg)

Asserts that the given argument is base58.
Parameters:
Name Type Description
arg is the argument to assert as base58
msg is the message to throw if the argument is not base58
Source:

(static) assertBase64(arg, msg)

Asserts that the given argument is base64.
Parameters:
Name Type Description
arg is the argument to assert as base64
msg is the message to throw if the argument is not base64
Source:

(static) assertBoolean(arg, msg)

Asserts that the given argument is a boolean.
Parameters:
Name Type Description
arg is the argument to assert as a boolean
msg is the message to throw if the argument is not a boolean
Source:

(static) assertDefined(arg, msg)

Asserts that the given argument is defined. Throws an exception if undefined.
Parameters:
Name Type Description
arg is the argument to assert defined
msg is the message to throw if arg is undefined (optional)
Source:

(static) assertEquals(arg1, arg2, msg)

Asserts that the given arguments are equal. Throws an exception if not equal.
Parameters:
Name Type Description
arg1 is an argument to assert as equal
arg2 is an argument to assert as equal
msg is the message to throw if the arguments are not equal
Source:

(static) assertFalse(bool, msg)

Asserts that the given boolean is false. Throws an exception if not a boolean or true.
Parameters:
Name Type Description
bool is the boolean to assert false
msg is the message to throw if bool is true (optional)
Source:

(static) assertFunction(arg, msg)

Asserts that the given argument is a static.
Parameters:
Name Type Description
arg is the argument to assert as a static
msg is the message to throw if the argument is not a static
Source:

(static) assertHex(arg, msg)

Asserts that the given argument is hex.
Parameters:
Name Type Description
arg is the argument to assert as hex
msg is the message to throw if the argument is not hex
Source:

(static) assertInitialized(arg, msg)

Asserts that the given argument is initialized. Throws an exception if not initialized.
Parameters:
Name Type Description
arg is the argument to assert as initialized
msg is the message to throw if arg is not initialized (optional)
Source:

(static) assertInt(arg, msg)

Asserts that the given argument is an integer.
Parameters:
Name Type Description
arg is the argument to assert as an integer
msg is the message to throw if the argument is not an integer
Source:

(static) assertNotEquals(arg1, arg2, msg)

Asserts that the given arguments are not equal. Throws an exception if equal.
Parameters:
Name Type Description
arg1 is an argument to assert as not equal
arg2 is an argument to assert as not equal
msg is the message to throw if the arguments are equal
Source:

(static) assertNotNull(arg, msg)

Asserts that the given argument is not null. Throws an exception if null.
Parameters:
Name Type Description
arg is the argument to assert not null
msg is the message to throw if arg is null (optional)
Source:

(static) assertNull(arg, msg)

Asserts that the given argument is null. Throws an exception if not null.
Parameters:
Name Type Description
arg is the argument to assert null
msg is the message to throw if arg is not null (optional)
Source:

(static) assertNumber(arg, msg)

Asserts that the given argument is a number.
Parameters:
Name Type Description
arg is the argument to assert as a number
msg is the message to throw if the argument is not a number
Source:

(static) assertObject(arg, obj, msg)

Asserts that the given argument is an object with the given name.
Parameters:
Name Type Description
arg is the argument to test
obj is an object to assert arg instanceof obj (optional)
msg is the message to throw if the argument is not the specified object
Source:

(static) assertString(arg, msg)

Asserts that the given argument is a string.
Parameters:
Name Type Description
arg is the argument to assert as a string
msg is the message to throw if the argument is not a string
Source:

(static) assertTrue(bool, msg)

Asserts that the given boolean is true. Throws an exception if not a boolean or false.
Parameters:
Name Type Description
bool is the boolean to assert true
msg is the message to throw if bool is false (optional)
Source:

(static) assertUndefined(arg, msg)

Asserts that the given argument is undefined. Throws an exception if defined.
Parameters:
Name Type Description
arg is the argument to assert undefined
msg is the message to throw if arg is defined (optional)
Source:

(static) assertUninitialized(arg, msg)

Asserts that the given argument is uninitialized. Throws an exception if initialized.
Parameters:
Name Type Description
arg is the argument to assert as uninitialized
msg is the message to throw if arg is initialized (optional)
Source:

(static) buildHtmlDocument(content)

Manually builds an HTML document string.
Parameters:
Name Type Description
content specifies optional document content content.div is a pre-existing div to stringify and add to the body content.title is the title of the new tab content.dependencyPaths specifies paths to js, css, or img paths content.internalCss is css to embed in the html document content.metas are meta elements with keys/values to include
Source:
Returns:
str is the document string

(static) copyArray(arr)

Copies the given array.
Parameters:
Name Type Description
arr is the array to copy
Source:
Returns:
a copy of the given array

(static) copyProperties(obj)

Copies properties in the given object to a new object.
Parameters:
Name Type Description
obj is object to copy properties for
Source:
Returns:
a new object with properties copied from the given object

(static) countNonWhitespaceCharacters(str)

Counts the number of non-whitespace characters in the given string.
Parameters:
Name Type Description
str is the string to count the number of non-whitespace characters in
Source:
Returns:
int is the number of non-whitespace characters in the given string

(static) csvToArr(csv)

Converts a CSV string to a 2-dimensional array of strings.
Parameters:
Name Type Description
csv is the CSV string to convert
Source:
Returns:
a 2-dimensional array of strings

(static) deleteProperties(obj)

Deletes all properties in the given object.
Parameters:
Name Type Description
obj is the object to delete properties from
Source:

(static) deleteUndefinedKeys(obj)

Deletes properties from the object that undefined.
Parameters:
Name Type Description
obj is the object to delete undefined keys from
Source:

(static) equals(arg1, arg2)

Determines if two arguments are deep equal.
Parameters:
Name Type Description
arg1 is an argument to compare
arg2 is an argument to compare
Source:
Returns:
true if the arguments are deep equals, false otherwise

(static) fail(msg)

Throws an exception with the given message.
Parameters:
Name Type Description
msg defines the message to throw the exception with (optional)
Source:

(static) getCombinations(arr, combinationSize)

Returns combinations of the given array of the given size.
Parameters:
Name Type Description
arr is the array to get combinations from
combinationSize specifies the size of each combination
Source:

(static) getDownloadableA(name, contents)

Gets an 'a' element that is downloadable when clicked.
Parameters:
Name Type Description
name is the name of the file to download
contents are the string contents of the file to download
Source:
Returns:
'a' dom element with downloadable file

(static) getIEVersion()

Gets the IE version number. Credit: https://stackoverflow.com/questions/19999388/check-if-user-is-using-ie-with-jquery/21712356#21712356
Source:
Returns:
the IE version number of null if not IE

(static) getImages(paths, onDone(err,)

Fetches the given list of images. Prerequisite: async.js.
Parameters:
Name Type Description
paths are the paths to the images to fetch
onDone(err, images) is called when done
Source:

(static) getIndent(length) → {string}

Returns a string indentation of the given length;
Parameters:
Name Type Description
length is the length of the indentation
Source:
Returns:
is an indentation string of the given length
Type
string

(static) getIndices(size)

Returns an array of indices of the given size.
Parameters:
Name Type Description
size specifies the size to get indices for
Source:
Returns:
array of the given size with indices starting at 0

(static) getInternalStyleSheet()

Returns the document's first stylesheet which has no href.
Source:
Returns:
StyleSheet is the internal stylesheet

(static) getInternalStyleSheetText()

Returns the document's internal stylesheet as text.
Source:
Returns:
str is the document's internal stylesheet

(static) getLines(str, string[)

Returns lines separated by newlines from the given string.
Parameters:
Name Type Description
str is the string to get lines from
string[ are the lines separated by newlines within the string
Source:

(static) getOuterHtml(node)

Returns the given node's outer HTML.
Parameters:
Name Type Description
node is the node to get outer HTML for
Source:
Returns:
the outer HTML of the given node

(static) getParameterByName(name, url)

Gets a parameter value. Credit: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
Parameters:
Name Type Description
name is the name of the parameter to get the value of
url is a URL to get the parameter from, uses the window's current href if not given
Source:
Returns:
the parameter's value

(static) getPowerSet(arr)

Returns the power set of the given array.
Parameters:
Name Type Description
arr is the array to get the power set of
Source:
Returns:
[][] is the power set of the given array

(static) getPowerSetOfLength(arr, size)

Returns the power set of the given array whose elements are the given size.
Parameters:
Name Type Description
arr is the array to get the power set of
size is the required size of the elements within the power set returns [][] is the power set of the given array whose elements are the given size
Source:

(static) getRandomInt(min, max)

Gets a non-cryptographically secure random number within a given range.
Parameters:
Name Type Description
min is the minimum range of the int to generate, inclusive
max is the maximum range of the int to generate, inclusive Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
Source:

(static) getRandomInts(min, max, count)

Gets random ints.
Parameters:
Name Type Description
min is the minimum range of the ints to generate, inclusive
max is the maximum range of the ints to generate, inclusive
count is the number of random ints to get
Source:

(static) getUniqueRandomInts(min, max, count)

Gets a given number of unique random ints within a range.
Parameters:
Name Type Description
min is the minimum range of the ints to generate, inclusive
max is the maximum range of the ints to generate, inclusive
count is the number of unique random ints to get
Source:

(static) getWhitespaceTokens(str)

Returns tokens separated by whitespace from the given string.
Parameters:
Name Type Description
str is the string to get tokens from
Source:
Returns:
string[] are the tokens separated by whitespace within the string

(static) hasWhitespace(str)

Indicates if the given string contains whitespace.
Parameters:
Name Type Description
str is the string to test
Source:
Returns:
true if the string contains whitespace, false otherwise

(static) imgToDataUrl(img, quality)

Converts the given image to a base64 encoded data url.
Parameters:
Name Type Description
img is the image to convert
quality is a number between 0 and 1 specifying the image quality
Source:

(static) inheritsFrom(child, parent)

Sets the child's prototype to the parent's prototype.
Parameters:
Name Type Description
child is the child class
parent is the parent class
Source:

(static) invoke()

Invokes functions with arguments. arguments[0] is assumed to be an array of functions to invoke arguments[1...n] are args to invoke the functions with
Source:

(static) isArray(arg)

Indicates if the given argument is an array. TODO: remove this entirely since just a direct wrapper?
Parameters:
Name Type Description
arg is the argument to test as being an array
Source:
Returns:
true if the argument is an array, false otherwise

(static) isBase32()

Determines if the given string is base32.
Source:

(static) isBase58()

Determines if the given string is base58.
Source:

(static) isBase64()

Determines if the given string is base64.
Source:

(static) isBoolean(arg)

Determines if the given argument is a boolean.
Parameters:
Name Type Description
arg is the argument to test as being a boolean
Source:
Returns:
true if the argument is a boolean, false otherwise

(static) isCsvFile(file)

Determines if the given file is a csv file.
Parameters:
Name Type Description
file is a file
Source:
Returns:
true if the given file is a csv file, false otherwise

(static) isDefined(arg)

Indicates if the given argument is defined.
Parameters:
Name Type Description
arg is the arg to test
Source:
Returns:
true if the given arg is defined, false otherwise

(static) isFunction(arg)

Determines if the given argument is a static.
Parameters:
Name Type Description
arg is the argument to test as being a static
Source:
Returns:
true if the argument is a static, false otherwise

(static) isHex(str)

Indicates if the given argument is a hexidemal string. Credit: https://github.com/roryrjb/is-hex/blob/master/is-hex.js.
Parameters:
Name Type Description
str is the string to test
Source:
Returns:
true if the given string is hexidecimal, false otherwise

(static) isImageAccessible(url, timeout, onDone(bool))

Determines if the image at the given URL is accessible.
Parameters:
Name Type Description
url is the url to an image
timeout is the maximum time to wait
onDone(bool) when the image is determined to be accessible or not
Source:

(static) isInitialized(arg)

Indicates if the given arg is initialized.
Parameters:
Name Type Description
arg is the arg to test
Source:
Returns:
true if the given arg is initialized, false otherwise

(static) isInt(arg)

Indicates if the given argument is an integer.
Parameters:
Name Type Description
arg is the argument to test
Source:
Returns:
true if the given argument is an integer, false otherwise

(static) isJsonFile(file)

Determines if the given file is a json file.
Parameters:
Name Type Description
file is a file
Source:
Returns:
true if the given file is a json file, false otherwise

(static) isLowerCase(str, true)

Determines if all alphabet characters in the given string are lower case.
Parameters:
Name Type Description
str is the string to test
true if the string is lower case, false otherwise
Source:

(static) isNewline(char)

Indicates if the given character is a newline.
Parameters:
Name Type Description
char is the character to test
Source:
Returns:
true if the given character is a newline, false otherwise

(static) isNumber(arg)

Indicates if the given argument is a number.
Parameters:
Name Type Description
arg is the argument to test
Source:
Returns:
true if the argument is a number, false otherwise

(static) isObject(arg, obj)

Indicates if the given argument is an object and optionally if it has the given constructor name.
Parameters:
Name Type Description
arg is the argument to test
obj is an object to test arg instanceof obj (optional)
Source:
Returns:
true if the given argument is an object and optionally has the given constructor name

(static) isString(arg)

Indicates if the given argument is a string.
Parameters:
Name Type Description
arg is the argument to test as being a string
Source:
Returns:
true if the argument is a string, false otherwise

(static) isTxtFile(file)

Determines if the given file is a txt file.
Parameters:
Name Type Description
file is a file
Source:
Returns:
true if the given file is a txt file, false otherwise

(static) isUndefined(arg)

Indicates if the given argument is undefined.
Parameters:
Name Type Description
arg is the arg to test
Source:
Returns:
true if the given arg is undefined, false otherwise

(static) isUninitialized(arg)

Indicates if the given arg is uninitialized.
Parameters:
Name Type Description
arg is the arg to test
Source:
Returns:
true if the given arg is uninitialized, false otherwise

(static) isUpperCase(str)

Determines if all alphabet characters in the given string are upper case.
Parameters:
Name Type Description
str is the string to test
Source:
Returns:
true if the string is upper case, false otherwise

(static) isWhitespace(char)

Indicates if the given character is whitespace.
Parameters:
Name Type Description
char is the character to test
Source:
Returns:
true if the given character is whitespace, false otherwise

(static) isZipFile(file)

Determines if the given file is a zip file.
Parameters:
Name Type Description
file is a file
Source:
Returns:
true if the given file is a zip file, false otherwise

(static) listify(arrOrElem)

Listifies the given argument.
Parameters:
Name Type Description
arrOrElem is an array or an element in the array
Source:
Returns:
an array which is the given arg if it's an array or an array with the given arg as an element

(static) newWindow(content, onLoad(err,)

Opens the given div in a new window.
Parameters:
Name Type Description
content specifies optional window content content.div is a pre-existing div to stringify and add to the body content.title is the title of the new tab content.dependencyPaths specifies paths to js, css, or img paths content.internalCss is css to embed in the html document content.metas are meta elements with keys/values to include
onLoad(err, window) is invoked with a reference to the window when available
Source:

(static) objectsEqual(map1, map2)

Determines if two objects are deep equal.
Parameters:
Name Type Description
map1 is a map to compare
map2 is a map to compare
Source:
Returns:
true if the maps have identical keys and values, false otherwise

(static) remove(arr, val)

Removes every instance of the given value from the given array.
Parameters:
Name Type Description
arr is the array to remove the value from
val is the value to remove from the array
Source:
Returns:
true if the value is found and removed, false otherwise

(static) shuffle()

Randomize array element order in-place using Durstenfeld shuffle algorithm. Credit: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
Source:

(static) sort(the)

Sorts an array by natural ordering.
Parameters:
Name Type Description
the array to sort
Source:

(static) strContains(str, substring)

Indicates if the given string contains the given substring.
Parameters:
Name Type Description
str is the string to search for a substring
substring is the substring to searchin within the string
Source:
Returns:
true if the substring is within the string, false otherwise

(static) toLowerCaseArray(arr)

Returns a copy of the given array where each element is lowercase.
Parameters:
Name Type Description
arr is the array to convert to lowercase
Source:
Returns:
a copy of the given array where each element is lowercase

(static) toUniqueArray(arr)

Returns a new array containing unique elements of the given array.
Parameters:
Name Type Description
arr is the array to return unique elements from
Source:
Returns:
a new array with the given array's unique elements

(static) uuidv4()

Generates a v4 UUID. Source: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
Source: