Class GenUtils

Collection of general purpose utilities.

Hierarchy

  • GenUtils

Constructors

Methods

  • Get the absolute value of the given bigint or number.

    Parameters

    • bi: number | bigint

      the bigint or number to get the absolute value of

    Returns number | bigint

    the absolute value of the given bigint or number

  • Indicates if the given array contains the given object.

    Parameters

    • arr: any

      array that may or may not contain the object

    • obj: any

      object to check for inclusion in the array

    • Optional compareByReference: boolean = false

      compare strictly by reference, forgoing deep equality check (default false)

    Returns boolean

    true if the array contains the object, false otherwise

  • Determines if two arrays are equal.

    Parameters

    • arr1: any

      is an array to compare

    • arr2: any

      is an array to compare

    Returns boolean

    true if the arrays are equal, false otherwise

  • Asserts that the given argument is an array.

    Parameters

    • arg: any

      is the argument to assert as an array

    • Optional msg: any

      is the message to throw if the argument is not an array

    Returns void

  • Asserts that the given argument is base58.

    Parameters

    • str: any
    • msg: any

      is the message to throw if the argument is not base58

    Returns void

  • Asserts that the given argument is base64.

    Parameters

    • str: any
    • msg: any

      is the message to throw if the argument is not base64

    Returns void

  • Asserts that the given argument is a boolean.

    Parameters

    • arg: any

      is the argument to assert as a boolean

    • Optional msg: any

      is the message to throw if the argument is not a boolean

    Returns void

  • Asserts that the given argument is defined. Throws an exception if undefined.

    Parameters

    • arg: any

      is the argument to assert defined

    • Optional msg: any

      is the message to throw if arg is undefined (optional)

    Returns void

  • Asserts that the given arguments are equal. Throws an exception if not equal.

    Parameters

    • arg1: any

      is an argument to assert as equal

    • arg2: any

      is an argument to assert as equal

    • Optional msg: any

      is the message to throw if the arguments are not equal

    Returns void

  • Asserts that the given boolean is false. Throws an exception if not a boolean or true.

    Parameters

    • bool: any

      is the boolean to assert false

    • Optional msg: any

      is the message to throw if bool is true (optional)

    Returns void

  • Asserts that the given argument is a static.

    Parameters

    • arg: any

      is the argument to assert as a static

    • Optional msg: any

      is the message to throw if the argument is not a static

    Returns void

  • Asserts that the given argument is hex.

    Parameters

    • str: any
    • msg: any

      is the message to throw if the argument is not hex

    Returns void

  • Asserts that the given argument is initialized. Throws an exception if not initialized.

    Parameters

    • arg: any

      is the argument to assert as initialized

    • Optional msg: any

      is the message to throw if arg is not initialized (optional)

    Returns void

  • Asserts that the given argument is an integer.

    Parameters

    • arg: any

      is the argument to assert as an integer

    • Optional msg: any

      is the message to throw if the argument is not an integer

    Returns void

  • Asserts that the given arguments are not equal. Throws an exception if equal.

    Parameters

    • arg1: any

      is an argument to assert as not equal

    • arg2: any

      is an argument to assert as not equal

    • Optional msg: any

      is the message to throw if the arguments are equal

    Returns void

  • Asserts that the given argument is not null. Throws an exception if null.

    Parameters

    • arg: any

      is the argument to assert not null

    • Optional msg: any

      is the message to throw if arg is null (optional)

    Returns void

  • Asserts that the given argument is null. Throws an exception if not null.

    Parameters

    • arg: any

      is the argument to assert null

    • Optional msg: any

      is the message to throw if arg is not null (optional)

    Returns void

  • Asserts that the given argument is a number.

    Parameters

    • arg: any

      is the argument to assert as a number

    • Optional msg: any

      is the message to throw if the argument is not a number

    Returns void

  • Asserts that the given argument is an object with the given name.

    Parameters

    • arg: any

      is the argument to test

    • obj: any

      is an object to assert arg instanceof obj (optional)

    • Optional msg: any

      is the message to throw if the argument is not the specified object

    Returns void

  • Asserts that the given argument is a string.

    Parameters

    • arg: any

      is the argument to assert as a string

    • Optional msg: any

      is the message to throw if the argument is not a string

    Returns void

  • Asserts that the given condition is true. Throws an exception if not a boolean or false.

    Parameters

    • condition: any

      is the boolean to assert true

    • Optional msg: any

      is the message to throw if condition is false (optional)

    Returns void

  • Asserts that the given argument is undefined. Throws an exception if defined.

    Parameters

    • arg: any

      is the argument to assert undefined

    • Optional msg: any

      is the message to throw if arg is defined (optional)

    Returns void

  • Asserts that the given argument is uninitialized. Throws an exception if initialized.

    Parameters

    • arg: any

      is the argument to assert as uninitialized

    • Optional msg: any

      is the message to throw if arg is initialized (optional)

    Returns void

  • Manually builds an HTML document string.

    Parameters

    • content: any

      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

    Returns string

    str is the document string

  • Copies the given array.

    Parameters

    • arr: any

      is the array to copy

    Returns any[]

    a copy of the given array

  • Copies properties in the given object to a new object.

    Parameters

    • obj: any

      is object to copy properties for

    Returns any

    a new object with properties copied from the given object

  • Counts the number of non-whitespace characters in the given string.

    Parameters

    • str: any

      is the string to count the number of non-whitespace characters in

    Returns number

    int is the number of non-whitespace characters in the given string

  • Deletes all properties in the given object.

    Parameters

    • obj: any

      is the object to delete properties from

    Returns void

  • Deletes properties from the object that are undefined.

    Parameters

    • obj: any

      is the object to delete undefined keys from

    Returns void

  • Determines if two arguments are deep equal.

    Parameters

    • arg1: any

      is an argument to compare

    • arg2: any

      is an argument to compare

    Returns boolean

    true if the arguments are deep equals, false otherwise

  • Resolve the given promise with a timeout.

    Parameters

    • promise: any

      the promise to resolve within the timeout

    • timeoutMs: any

      the timeout in milliseconds to resolve the promise

    Returns Promise<any>

    the result of the promise unless error thrown

  • Throws an exception with the given message.

    Parameters

    • Optional msg: any

      defines the message to throw the exception with (optional)

    Returns void

  • Returns combinations of the given array of the given size.

    Parameters

    • arr: any

      is the array to get combinations from

    • combinationSize: any

      specifies the size of each combination

    Returns any[]

  • Gets an 'a' element that is downloadable when clicked.

    Parameters

    • name: any

      is the name of the file to download

    • contents: any

      are the string contents of the file to download

    Returns HTMLAnchorElement

    'a' dom element with downloadable file

  • Get an enum key name by value.

    Parameters

    • enumType: any

      is the enum type to get the key from

    • enumValue: any

      is the enum value to get the key for

    Returns string

    the enum key name

  • Fetches the given list of images.

    Prerequisite: async.js.

    Parameters

    • paths: any

      are the paths to the images to fetch

    • onDone: any

    Returns void

  • Returns a string indentation of the given length;

    Parameters

    • length: any

      is the length of the indentation

    Returns string

    is an indentation string of the given length

  • Returns an array of indices of the given size.

    Parameters

    • size: any

      specifies the size to get indices for

    Returns any[]

    array of the given size with indices starting at 0

  • Returns the document's first stylesheet which has no href.

    Returns CSSStyleSheet

    StyleSheet is the internal stylesheet

  • Returns the document's internal stylesheet as text.

    Returns string

    str is the document's internal stylesheet

  • Returns lines separated by newlines from the given string.

    Parameters

    • str: any

      is the string to get lines from

    Returns any

  • Returns the power set of the given array.

    Parameters

    • arr: any

      is the array to get the power set of

    Returns any[]

    [][] is the power set of the given array

  • Returns the power set of the given array whose elements are the given size.

    Parameters

    • arr: any

      is the array to get the power set of

    • size: any

      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

    Returns any[]

  • Gets random ints.

    Parameters

    • min: any

      is the minimum range of the ints to generate, inclusive

    • max: any

      is the maximum range of the ints to generate, inclusive

    • count: any

      is the number of random ints to get

    Returns any[]

  • Gets a given number of unique random ints within a range.

    Parameters

    • min: any

      is the minimum range of the ints to generate, inclusive

    • max: any

      is the maximum range of the ints to generate, inclusive

    • count: any

      is the number of unique random ints to get

    Returns any[]

  • Returns tokens separated by whitespace from the given string.

    Parameters

    • str: any

      is the string to get tokens from

    Returns any

    string[] are the tokens separated by whitespace within the string

  • Indicates if the given string contains whitespace.

    Parameters

    • str: any

      is the string to test

    Returns boolean

    true if the string contains whitespace, false otherwise

  • Converts the given image to a base64 encoded data url.

    Parameters

    • img: any

      is the image to convert

    • quality: any

      is a number between 0 and 1 specifying the image quality

    Returns string

  • Sets the child's prototype to the parent's prototype.

    Parameters

    • child: any

      is the child class

    • parent: any

      is the parent class

    Returns void

  • Returns void

  • 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

    Returns void

  • Indicates if the given argument is an array.

    Parameters

    • arg: any

      is the argument to test as being an array

    Returns boolean

    true if the argument is an array, false otherwise

  • Determines if the given string is base32.

    Parameters

    • str: any

    Returns boolean

  • Determines if the given string is base58.

    Parameters

    • str: any

    Returns boolean

  • Determines if the given string is base64.

    Parameters

    • str: any

    Returns boolean

  • Determines if the given argument is a boolean.

    Parameters

    • arg: any

      is the argument to test as being a boolean

    Returns boolean

    true if the argument is a boolean, false otherwise

  • Indicates if the current environment is a browser.

    Returns boolean

    true if the environment is a browser, false otherwise

  • Indicates if the given argument is defined.

    Parameters

    • arg: any

      is the arg to test

    Returns boolean

    true if the given arg is defined, false otherwise

  • Indicates if the current environment is a firefox-based browser.

    Returns boolean

    true if the environment is a firefox-based browser, false otherwise

  • Determines if the given argument is a static.

    Parameters

    • arg: any

      is the argument to test as being a static

    Returns boolean

    true if the argument is a static, false otherwise

  • Determines if the image at the given URL is accessible.

    Parameters

    • url: any

      is the url to an image

    • timeout: any

      is the maximum time to wait

    • onDone: any

    Returns void

  • Indicates if the given arg is initialized.

    Parameters

    • arg: any

      is the arg to test

    Returns boolean

    true if the given arg is initialized, false otherwise

  • Indicates if the given argument is an integer.

    Parameters

    • arg: any

      is the argument to test

    Returns boolean

    true if the given argument is an integer, false otherwise

  • Determines if the given file is a json file.

    Parameters

    • file: any

      is a file

    Returns any

    true if the given file is a json file, false otherwise

  • Determines if all alphabet characters in the given string are lower case.

    Parameters

    • str: any

      is the string to test

    Returns boolean

  • Indicates if the given character is a newline.

    Parameters

    • char: any

      is the character to test

    Returns boolean

    true if the given character is a newline, false otherwise

  • Indicates if the given argument is a number.

    Parameters

    • arg: any

      is the argument to test

    Returns boolean

    true if the argument is a number, false otherwise

  • Indicates if the given argument is an object and optionally if it has the given constructor name.

    Parameters

    • arg: any

      is the argument to test

    • Optional obj: any

      is an object to test arg instanceof obj (optional)

    Returns boolean

    true if the given argument is an object and optionally has the given constructor name

  • Indicates if the given argument is a string.

    Parameters

    • arg: any

      is the argument to test as being a string

    Returns boolean

    true if the argument is a string, false otherwise

  • Determines if the given file is a txt file.

    Parameters

    • file: any

      is a file

    Returns any

    true if the given file is a txt file, false otherwise

  • Indicates if the given argument is undefined.

    Parameters

    • arg: any

      is the arg to test

    Returns boolean

    true if the given arg is undefined, false otherwise

  • Indicates if the given arg is uninitialized.

    Parameters

    • arg: any

      is the arg to test

    Returns boolean

    true if the given arg is uninitialized, false otherwise

  • Determines if all alphabet characters in the given string are upper case.

    Parameters

    • str: string

      is the string to test

    Returns boolean

    true if the string is upper case, false otherwise

  • Indicates if the given character is whitespace.

    Parameters

    • char: any

      is the character to test

    Returns boolean

    true if the given character is whitespace, false otherwise

  • Determines if the given file is a zip file.

    Parameters

    • file: any

      is a file

    Returns any

    true if the given file is a zip file, false otherwise

  • Kill the given nodejs child process.

    Parameters

    • process: ChildProcess

      the nodejs child process to kill

    • Optional signal: number | Signals

      the kill signal, e.g. SIGTERM, SIGKILL, SIGINT (default)

    Returns Promise<number>

    the exit code from killing the process

  • Returns a human-friendly key value line.

    Parameters

    • key: any

      is the key

    • value: any

      is the value

    • indent: number = 0

      indents the line

    • newline: boolean = true

      specifies if the string should be terminated with a newline or not

    • ignoreUndefined: boolean = true

      specifies if undefined values should return an empty string

    Returns string

    is the human-friendly key value line

  • Listifies the given argument.

    Parameters

    • arrOrElem: any

      is an array or an element in the array

    Returns any

    an array which is the given arg if it's an array or an array with the given arg as an element

  • Opens the given div in a new window.

    Parameters

    • content: any

      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: any

    Returns void

  • Normalize a URI.

    Parameters

    • uri: any

      the URI to normalize

    Returns any

    the normalized URI

  • Determines if two objects are deep equal.

    Undefined values are considered equal to non-existent keys.

    Parameters

    • map1: any

      is a map to compare

    • map2: any

      is a map to compare

    Returns boolean

    true if the maps have identical keys and values, false otherwise

  • Print the current stack trace.

    Parameters

    • msg: any

      optional message to print with the trace

    Returns void

  • Reconciles two values.

    TODO: remove custom error message

    Parameters

    • val1: any

      is a value to reconcile

    • val2: any

      is a value to reconcile

    • Optional config: any

      specifies reconciliation configuration config.resolveDefined uses defined value if true or undefined, undefined if false config.resolveTrue uses true over false if true, false over true if false, must be equal if undefined config.resolveMax uses max over min if true, min over max if false, must be equal if undefined

    • Optional errMsg: any

      is the error message to throw if the values cannot be reconciled (optional)

    Returns any

    the reconciled value if reconcilable, throws error otherwise

  • Removes every instance of the given value from the given array.

    Parameters

    • arr: any

      is the array to remove the value from

    • val: any

      is the value to remove from the array

    Returns boolean

    true if the value is found and removed, false otherwise

  • Sets the given value ensuring a previous value is not overwritten.

    TODO: remove for portability because function passing not supported in other languages, use reconcile only

    Parameters

    • obj: any

      is the object to invoke the getter and setter on

    • getFn: any

      gets the current value

    • setFn: any

      sets the current value

    • val: any

      is the value to set iff it does not overwrite a previous value

    • Optional config: any

      specifies reconciliation configuration config.resolveDefined uses defined value if true or undefined, undefined if false config.resolveTrue uses true over false if true, false over true if false, must be equal if undefined config.resolveMax uses max over min if true, min over max if false, must be equal if undefined

    • Optional errMsg: any

      is the error message to throw if the values cannot be reconciled (optional)

    Returns void

  • Sorts an array by natural ordering.

    Parameters

    • array: any

    Returns void

  • Indicates if the given string contains the given substring.

    Parameters

    • str: any

      is the string to search for a substring

    • substring: any

      is the substring to searchin within the string

    Returns boolean

    true if the substring is within the string, false otherwise

  • Replace big integers (16 or more consecutive digits) with strings in order to preserve numeric precision.

    Parameters

    • str: any

      is the string to be modified

    Returns any

    the modified string with big numbers converted to strings

  • Returns a copy of the given array where each element is lowercase.

    Parameters

    • arr: any

      is the array to convert to lowercase

    Returns any[]

    a copy of the given array where each element is lowercase

  • Returns a new array containing unique elements of the given array.

    Parameters

    • arr: any

      is the array to return unique elements from

    Returns any

    a new array with the given array's unique elements

  • Wait for the duration.

    Parameters

    • durationMs: any

      the duration to wait for in milliseconds

    Returns Promise<unknown>

Generated using TypeDoc