Module: util

Common utility methods

Since:
  • v0.1.1
Source:

Methods

(static) addHoursToDate(d, h) → {Date}

Add hours to a date

Parameters:
Name Type Description
d Date

Original date

h Number

Hours to add

Source:

(static) checkTimeInput(x) → {String}

Determines if a string of 1-4 numbers is a valid time (24-hr time, without a colon as 'H', 'HH', 'HMM', or 'HHMM'). If input is a valid time, returns the input as a 4-digit string as 'HHMM'. If not valid, returns an empty string.

Parameters:
Name Type Description
x Number | String

One to four digits representing a time

Source:

(static) checkValue(x, minopt, maxopt, zeroAllowedopt) → {Number}

Evaluates a number, returns if is valid, between optional minimum and maximum, otherwise returns zero (or undefined if zero is allowed).

Parameters:
Name Type Attributes Default Description
x Number | String

Value to check

min Number <optional>
-Infinity

Minimum of acceptable range

max Number <optional>
Infinity

Maximum of acceptable range

zeroAllowed Boolean <optional>
false

Is zero acceptable?

Source:

(static) colorScale(val, colors) → {String}

Provides a color, scaled between specified or default colors. Values in between color stops are scaled using R, G, and B values

Parameters:
Name Type Description
val Number

Value to calculate color for

colors Array.<ColorStop>

Stops and color values

Source:

(static) displayDate(d) → {String}

Convert date object to string formatted as 'M/d/yyyy HH:mm' Returns empty string if input is not a valid date

Parameters:
Name Type Description
d Date

date object to convert

Source:

(static) displayTime(d) → {String}

Convert a date object to string formatted as 'HH:mm' Returns empty string if input is not a valid date

Parameters:
Name Type Description
d Date

date object to convert

Since:
  • v1.1.1
Source:

(static) displayValue(el, numopt, roundopt, unitopt, preopt, allowNegativeopt, allowZeroopt) → {HTMLElement|String}

Displays a number, rounded, with units in the specified HTML element. If number is zero, clears input element instead, unless allowZero is true (then undefined will clear input) To get the result without specifying an HTML element, pass an empty string ('') for the first parameter.

Parameters:
Name Type Attributes Default Description
el String | HTMLElement

Valid jQuery selector for target element.

num Number | Array.<Number> <optional>
0

The number or range to go in the input field. Range must be array with length of 2.

round Number <optional>
-1

The desired rounding factor

unit String <optional>
""

Units to append to rounded value

pre String <optional>
""

Text to prepend to rounded value

allowNegative Boolean <optional>
false

Accept negative values as valid

allowZero Boolean <optional>
false

Accept 0 as valid

Source:

(static) getDateTime(d, t) → {Date}

Convert date and time raw input to a date object.

Parameters:
Name Type Description
d String

date string from input field

t String

time string from input field

Source:

(static) getHoursBetweenDates(first, second) → {Number}

Calculate the number of hours between two dates

Parameters:
Name Type Description
first Date

first Date object

second Date

second Date object

Source:

(static) hexToRgb(h) → {Array.<Number>}

Convert a hex color string to rgb values

Parameters:
Name Type Description
h String

Hex color string, as #000000

Source:

(static) parseAge(x) → {Number}

Parses age input in years, months, days, or months+days and returns in years.

Parameters:
Name Type Description
x String

Age input

Source:

(static) rgbToHex(val) → {String}

Convert RGB value to Hex value.

Parameters:
Name Type Description
val String

RGB value to convert

Source:
Example
rgbToHex('RGB(0, 0, 0)')
rgbToHex('rgb(0, 0, 0)')
rgbToHex('0, 0, 0')
rgbToHex('0,0,0') * 

(static) roundTo(x, n) → {Number}

Rounds a number to a specified factor.

Parameters:
Name Type Description
x Number

The number to round

n Number

The rounding factor

Source:

Type Definitions

ColorStop :Object

Color Scale Options

Properties:
Name Type Description
stop Number

Value to set the color stop

hex String

Hexadecimal color string

Source: