Utilities

Utilities

JavaScript utilities.

Source:

Methods

compare(a, b) → {Integer}

A generic comparator function, for use with the sort method. Works with Strings and Numbers.

Source:
Parameters:
Name Type Description
a Any

First item to be compared

b Any

Second item to be compared

Returns:
Type:
Integer

Returns 1 if the first item is greater, -1 if the first item is lesser, and 0 if the two items are the same.

Example
items.sort((a, b) => compare(a.year, b.year) || compare(a.title, b.title));

debounce(func, wait, immediate) → {function}

A debounce function.

Source:
See:
Parameters:
Name Type Description
func function

The function to debounce

wait Number

The time to wait, in milliseconds

immediate Boolean

Whether to invoke the function immediately

Returns:
Type:
function

html2element(html) → {HTMLElement}

Converts an HTML string to a DOM tree. Only the first top-level element will be returned. (In other words, the HTML string should consist of only 1 top-level element.)

Source:
Parameters:
Name Type Description
html String

An HTML string.

Returns:
Type:
HTMLElement