This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes invalid XML characters from a string | |
* @param {string} str - a string containing potentially invalid XML characters (non-UTF8 characters, STX, EOX etc) | |
* @param {boolean} removeDiscouragedChars - should it remove discouraged but valid XML characters | |
* @return {string} a sanitized string stripped of invalid XML characters | |
*/ | |
function removeXMLInvalidChars(str, removeDiscouragedChars) { | |
// remove everything forbidden by XML 1.0 specifications, plus the unicode replacement character U+FFFD | |
var regex = /((?:[\0-\x08\x0B\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a string to JSON safe key (property name) by removing unsafe | |
* characters and converting to camel case | |
* @param {string} src - string to convert | |
* @Example | |
* stringToJsonSafeKey('r@ndAm wo5d') // rndamWo5d | |
* @returns {string} id/key safe string | |
*/ | |
function stringToJsonSafeKey(src) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileStorage = { | |
/** | |
* Saves a file on the device | |
* @param {string} name - filename (can include sub folders) | |
* @param {string} data - file contents | |
* @param {boolean} useSandbox - uses protected sandbox if true, otherwise external (default false) | |
* @returns {Promise} executes .then with saved file path as first param | |
*/ | |
write: function (name, data, useSandbox) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets attribute off HTML element or nearest parent | |
* @param {object} el - HTML element to retrieve attribute from | |
* @param {string} attributeName - name of the attribute | |
* @param {any} defaultValue - default value to return if no match found | |
* @returns {any} attribute value or defaultValue | |
*/ | |
function getNearestAttribute(el, attributeName, defaultValue) { | |
// walk up the dom tree looking for data-action and data-trigger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wait for the browser to fire an event (including custom events) | |
* @param {string} eventName - Event name | |
* @param {integer} seconds - number of seconds to wait. | |
* @returns {Promise} resolves when event fires or timeout is reached | |
*/ | |
async function waitForEvent(eventName, seconds) { | |
seconds = seconds || 30; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executes an array of functions that return a promise in sequence | |
* @example | |
* promisesInSequence([ | |
* function() { return Promise.resolve(1); } | |
* function() { return Promise.resolve(2); }, | |
* function() { return Promise.resolve(3); } | |
* ]) | |
* .then(function(result) { | |
* console.log(result.join(',')); // output = 1,2,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Waits for multiple DOM events to fire | |
* @example | |
* waitForEvents(window, [ | |
* 'DOMContentLoaded', | |
* 'online' | |
* ]) | |
* .then(function(result) { | |
* // do stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if a JavaScript value is empty | |
* @example | |
* isEmpty(null); // true | |
* isEmpty(undefined); // true | |
* isEmpty(''); // true | |
* isEmpty([]); // true | |
* isEmpty({}); // true | |
* @param {any} value - item to test | |
* @returns {boolean} true if empty, otherwise false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if a string is a URL | |
* @example isUrl('https://orcascan.com') // true; | |
* @param {string} str - value to test | |
* @returns {boolean} true if URL otherwise false | |
*/ | |
function isUrl(str) { | |
return /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(str); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs-extra'); | |
var fetch = require('node-fetch'); | |
/** | |
* Download a file to disk | |
* @example downloadFile('https://orcascan.com', './barcode-tracking.html') | |
* @param {string} fileUrl - url of file to download | |
* @param {string} destPath - destination path | |
* @returns {Promise} resolves once complete, otherwise rejects | |
*/ |