Miscellaneous app/browser helpers that do not yet fit better
specialized common modules.
- Since:
- Source:
Methods
Wait for the global MetacatUI object to be available, and optionally for
a specific property on it to be defined.
Parameters:
| Name |
Type |
Attributes |
Description |
options |
object
|
<optional>
|
Options object.
Properties
| Name |
Type |
Attributes |
Description |
maxAttempts |
number
|
<optional>
|
Maximum number of attempts. |
delay |
number
|
<optional>
|
Delay between attempts in ms. |
property |
string
|
<optional>
|
Optional property name to wait for. |
appName |
string
|
<optional>
|
Optional MetacatUI property containing
the object to wait for. |
|
- Since:
- Source:
Throws:
-
If the requested value is not available in time.
-
-
Type
-
Error
Returns:
Promise resolving to the requested global object or
property value.
-
Type
-
Promise.<*>
Get the list of object formats from the Coordinating Node.
- Since:
- Source:
Returns:
Promise resolving to the object
formats collection.
-
Type
-
Promise.<ObjectFormats>
buildInstanceKey(options, keys, normalizersopt, separatoropt, encodeopt) → {string}
Build a unique string to represent a class instance or options set.
Parameters:
| Name |
Type |
Attributes |
Description |
options |
object
|
|
The object containing key values. |
keys |
Array.<string>
|
|
Field names required to build the key. |
normalizers |
object
|
<optional>
|
Optional field normalizers. |
separator |
string
|
<optional>
|
Separator to use between key parts. |
encode |
boolean
|
<optional>
|
Whether to md5-encode the key. |
- Since:
- Source:
Throws:
-
If keys is not a non-empty array.
-
-
Type
-
Error
Returns:
The generated instance key.
-
Type
-
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:
- 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
Format a finite number using a fixed number of decimal places.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
value |
number
|
|
|
The number value to be formatted. |
digits |
number
|
<optional>
|
2
|
The number of decimal places to display. |
fallback |
string
|
<optional>
|
""
|
The value to return when `value` is not finite. |
- Since:
- Source:
Returns:
A fixed-decimal number string or the fallback value.
-
Type
-
string
Format the number into a string with better readability, based on the
magnitude 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:
- Source:
Returns:
A formatted number based on the magnitude of `range`.
-
Type
-
string
getMaxConcurrent(maxConcurrentopt) → {number}
Resolve a positive concurrency limit from a caller value or the project
default.
Parameters:
| Name |
Type |
Attributes |
Description |
maxConcurrent |
number
|
<optional>
|
Preferred limit |
- Since:
- Source:
Returns:
Positive integer limit.
-
Type
-
number
Read a MetacatUI property directly, via Backbone's `get`, or from a
nested appModel.
Parameters:
| Name |
Type |
Attributes |
Description |
property |
string
|
|
Property name to retrieve. |
app |
object
|
<optional>
|
MetacatUI object. |
- Since:
- Source:
Returns:
Property value, or `undefined` when not present.
-
Type
-
*
getSingleton(ClassRef, optionsopt, buildInstanceKey) → {object}
Get or create a singleton instance for a class.
Parameters:
| Name |
Type |
Attributes |
Description |
ClassRef |
function
|
|
Class reference. |
options |
object
|
<optional>
|
Options passed to the class constructor. |
buildInstanceKey |
function
|
|
Function that builds a unique key. |
- Since:
- Source:
Returns:
The singleton instance.
-
Type
-
object
isValidDOI(identifier) → {boolean}
Validates that the given string is a valid DOI
Parameters:
| Name |
Type |
Description |
identifier |
string
|
String to be validated. |
- Since:
- Source:
Returns:
True if identifier is a valid DOI.
-
Type
-
boolean
normalizeUrl(url, fallbackopt) → {string}
Normalize a URL string by trimming whitespace and removing trailing slashes.
Parameters:
| Name |
Type |
Attributes |
Description |
url |
string
|
|
The URL to normalize. |
fallback |
string
|
<optional>
|
A fallback URL to use if url is empty. |
- Since:
- Source:
Returns:
Normalized URL, or empty string if not available.
-
Type
-
string
processConcurrently(items, worker, optionsopt) → {Promise.<object>}
Run work with one concurrency limit and no batch abstraction.
Parameters:
| Name |
Type |
Attributes |
Description |
items |
Array.<*>
|
|
Items to process. |
worker |
function
|
|
Async item worker. |
options |
object
|
<optional>
|
Processing options.
Properties
| Name |
Type |
Attributes |
Description |
maxConcurrent |
number
|
<optional>
|
Worker limit. |
signal |
AbortSignal
|
<optional>
|
Abort signal. |
stopOnError |
boolean
|
<optional>
|
Stop scheduling after an error. |
onItemComplete |
function
|
<optional>
|
Called after each item
settles. |
|
- Since:
- Source:
Returns:
Collected errors.
-
Type
-
Promise.<object>
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:
- Source:
stableStringify(val, optionsopt) → {string}
Stringify any value deterministically, where order doesn't impact the
result.
Parameters:
| Name |
Type |
Attributes |
Description |
val |
*
|
|
The value to stringify. |
options |
object
|
<optional>
|
Options object.
Properties
| Name |
Type |
Attributes |
Description |
ignoreCase |
boolean
|
<optional>
|
Whether to convert all string
values to lower case before stringifying. |
processed |
WeakSet
|
<optional>
|
WeakSet tracking visited objects. |
orderMatters |
boolean
|
<optional>
|
Whether to preserve array order
during stringification. |
|
- Since:
- Source:
Throws:
-
If a circular reference is detected.
-
-
Type
-
Error
Returns:
A stable string representation.
-
Type
-
string
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>
|
Additional properties to remove |
- Since:
- Source:
Returns:
The JSON representation with defaults removed
-
Type
-
object
Attempt to parse the header/column names from a chunk of a CSV file
Doesn't handle:
- Commas inside quoted headers
Parameters:
| Name |
Type |
Description |
text |
string
|
A chunk of a file |
- Since:
- Source:
Returns:
A list of names
-
Type
-
Array
wildcardToRegex(pattern) → {RegExp}
Convert a wildcard pattern to a safe RegExp.
Parameters:
| Name |
Type |
Description |
pattern |
string
|
A simple wildcard pattern |
- Source:
Returns:
Regex for case-insensitive matching
-
Type
-
RegExp