utils_misc

Misc utils

Methods

private, inner clamp(n, max, min) → {number}

Clamps a given value between a minimum and maximum value.

Parameters:
Name Type Description
n number

The value to clamp.

max number

The maximum allowed value.

min number

The minimum allowed value.

Returns:
number -

The clamped value.

inner clampLatLng(latlng) → {Array.<number>}

Clamps a latitude and longitude to the maximum and minimum valid values.

Parameters:
Name Type Description
latlng L.LatLng

The latitude and longitude to clamp.

Returns:
Array.<number> -

The clamped latitude and longitude.

inner clampLatLngBounds(bounds) → {L.LatLngBounds}

Clamps a latitude and longitude bounds to the maximum and minimum valid values.

Parameters:
Name Type Description
bounds L.LatLngBounds

The bounds to clamp.

Returns:
L.LatLngBounds -

The clamped bounds.

inner convertTextToTableMagic(text) → {string}

Converts text with newlines (\n) and tabs (\t) into an HTML table.

Parameters:
Name Type Description
text string

The text to convert.

Returns:
string -

The resulting HTML table.

inner digits(d) → {string}

Adds thousand separators to a given number.

Parameters:
Name Type Description
d number

The number to format.

Returns:
string -

The formatted number with thousand separators.

See:

inner eraseCookie(name)

Erases a cookie with a specified name.

Parameters:
Name Type Description
name string

The name of the cookie to erase.

inner escapeHtmlSpecialChars(str) → {string}

Escapes HTML special characters in a string.

Parameters:
Name Type Description
str string

The string to escape.

Returns:
string -

The escaped string.

inner escapeJavascriptString(str) → {string}

Escapes special characters in a string for use in JavaScript. (for strings passed as parameters to html onclick="..." for example)

Parameters:
Name Type Description
str string

The string to escape.

Returns:
string -

The escaped string.

inner formatDistance(distance) → {string}

Formats a distance in meters, converting to kilometers if the distance is over 10,000 meters.

Parameters:
Name Type Description
distance number

The distance in meters.

Returns:
string -

The formatted distance.

inner formatInterval(seconds, maxTermsopt) → {string}

Formats an interval of time given in seconds into a human-readable string.

Parameters:
Name Type Attributes Description
seconds number

The interval in seconds.

maxTerms number <optional>

The maximum number of time units to include.

Returns:
string -

The formatted time interval.

inner getURLParam(param) → {string}

Retrieves a parameter from the URL query string.

Parameters:
Name Type Description
param string

The name of the parameter to retrieve.

Returns:
string -

The value of the parameter, or an empty string if not found.

inner isTouchDevice() → {boolean}

Checks if the device is a touch-enabled device.

Returns:
boolean -

True if the device is touch-enabled, otherwise false.

Creates a link to open a specific portal in Ingress Prime.

Parameters:
Name Type Description
guid string

The globally unique identifier of the portal.

lat number

The latitude of the portal.

lng number

The longitude of the portal.

Returns:
string -

The Ingress Prime link for the portal

inner prettyEnergy(nrg) → {string}

Formats energy of portal.

Parameters:
Name Type Description
nrg number

The energy value to format.

Returns:
string -

The formatted energy value.

inner rangeLinkClick()

Changes the coordinates and map scale to show the range for portal links.

inner readCookie(name) → {string}

Reads a cookie by name.

Parameters:
Name Type Description
name string

The name of the cookie to read.

Returns:
string -

The value of the cookie, or undefined if not found.

See:

inner scrollBottom(elm) → {number}

Calculates the number of pixels left to scroll down before reaching the bottom of an element.

Parameters:
Name Type Description
elm string | jQuery

The element to calculate the scroll bottom for.

Returns:
number -

The number of pixels from the bottom.

inner selectPortalByLatLng(lat, lngopt)

Selects a portal by its latitude and longitude.

Parameters:
Name Type Attributes Description
lat number | Array | L.LatLng

The latitude of the portal or an array or L.LatLng object containing both latitude and longitude.

lng number <optional>

The longitude of the portal.

Displays a dialog with links to show the specified location on various map services.

Parameters:
Name Type Description
lat number

Latitude of the location.

lng number

Longitude of the location.

name string

Name of the location.

inner uniqueArray(arr) → {Array}

Converts a list of items into a unique array, removing duplicates.

Parameters:
Name Type Description
arr Array

The array to process.

Returns:
Array -

A new array containing only unique elements.

inner unixTimeToDateTimeString(time, millisecondopt) → {string|null}

Converts a UNIX timestamp to a precise date and time string in the local timezone. Formatted in ISO-style YYYY-MM-DD hh:mm:ss.mmm - but using local timezone

Parameters:
Name Type Attributes Description
time number

The UNIX timestamp to convert.

millisecond boolean <optional>

Whether to include millisecond precision.

Returns:
string | null -

The formatted date and time string.

inner unixTimeToHHmm(time) → {string|null}

Converts a UNIX timestamp to a time string formatted as HH:mm.

Parameters:
Name Type Description
time number | string

The UNIX timestamp to convert.

Returns:
string | null -

Formatted time as HH:mm.

inner unixTimeToString(time, fullopt) → {string|null}

Converts a UNIX timestamp to a human-readable string. If the timestamp is from today, returns the time (HH:mm:ss format); otherwise, returns the date (YYYY-MM-DD).

Parameters:
Name Type Attributes Description
time number

The UNIX timestamp to convert.

full boolean <optional>

If true, returns both date and time.

Returns:
string | null -

The formatted date and/or time.

inner writeCookie(name, val)

Writes a cookie with a specified name and value.

Parameters:
Name Type Description
name string

The name of the cookie.

val string

The value of the cookie.

inner zeroPad(number, pad) → {string}

Pads a number with zeros up to a specified length.

Parameters:
Name Type Description
number number

The number to pad.

pad number

The desired length of the output string.

Returns:
string -

The padded number as a string.

inner zoomToAndShowPortal(guid, latlng)

Zooms the map to a specific portal and shows its details if available.

Parameters:
Name Type Description
guid string

The globally unique identifier of the portal.

latlng L.LatLng

The latitude and longitude of the portal.