Namespace: Utilities

Utilities

A generic utility object that contains functions used throughout MetacatUI to perform useful functions, but not used to store or manipulate any state about the application.
Since:
  • 2.14.0
Source:

Methods

bytesToSize(integer, integer, bytes, precision)

Convert number of bytes into human readable format
Parameters:
Name Type Description
integer bytes Number of bytes to convert
integer precision Number of digits after the decimal separator
bytes
precision
Source:
Returns:
string

deepEqual(a, b) → {boolean}

Checks if two objects are deeply equal. Simpler than the _.isEqual function.
Parameters:
Name Type Description
a object The first object to compare
b object The second object to compare
Since:
  • 2.31.0
Source:
Returns:
True if the objects are deeply equal
Type
boolean

encodeHTML(s) → {string}

HTML-encodes the given string so it can be inserted into an HTML page without running any embedded Javascript.
Parameters:
Name Type Description
s string String to be encoded.
Source:
Returns:
HTML encoded string.
Type
string

formatNumber(value, range) → {string}

Format the number into a string with better readability, based on the manitude of a range this number falls in.
Parameters:
Name Type Description
value number The number value to be formatted.
range number The range of numerics this value can fall in.
Since:
  • 2.30.0
Source:
Returns:
A formatted number based on the magnitude of `range`.
Type
string

getNumDecimalPlaces(range) → {number}

Calculate the number of decimal places we should use based on the range of the data.
Parameters:
Name Type Description
range number The range of data values.
Since:
  • 2.30.0
Source:
Returns:
The number of decimal places we should use.
Type
number

isValidDOI(identifier) → {boolean}

Validates that the given string is a valid DOI
Parameters:
Name Type Description
identifier string String to be validated.
Since:
  • 2.15.0
Source:
Returns:
True if identifier is a valid DOI.
Type
boolean

readSlice(file, context, callback, bytes)

Read the first part of a file
Parameters:
Name Type Description
file File A reference to a file
context Backbone.View The View to bind `callback` to
callback function A function to run after the read is complete. The function is bound to `context`.
bytes number The number of bytes to read from the start of the file
Since:
  • 2.15.0
Source:

toJSONWithoutDefaults(model, removePropsopt) → {object}

Removes default values from a model's JSON representation
Parameters:
Name Type Attributes Description
model Backbone.Model The model to remove defaults from
removeProps Array.<string> <optional>
An array of additional properties to remove from the model
Since:
  • 2.31.0
Source:
Returns:
The JSON representation of the model with defaults removed
Type
object

tryParseCSVHeader(text) → {Array}

Attempt to parse the header/column names from a chunk of a CSV file Doesn't handle: - UTF BOM (garbles first col name) - Commas inside quoted headers
Parameters:
Name Type Description
text string A chunk of a file
Since:
  • 2.15.0
Source:
Returns:
A list of names
Type
Array