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
/** | |
* Returns the length of a Subform or -1 if no length can be found | |
* @param {array} s Subform element | |
* @return {int} length of the Subform, or -1 | |
*/ | |
function getSubformLength(s) { | |
if(typeof s === "undefined" || s == null || Array.isArray(s) === false) { | |
return -1; | |
} else { | |
return s.length; |
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
/** | |
* search through an object and return only whitelisted keys | |
* @param {object} r the original record | |
* @param {string} keep_list comma-separated list of keys to keep | |
* @return {object} object with only found whitelisted keys | |
*/ | |
function keepKeys(r,keep_list) { | |
var obj = {}; | |
for(var key in r) { | |
if(keep_list.indexOf(key) >= 0) { |
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
/** | |
* Function to format a date object. Used to format Date, Time, Date/Time elements | |
* @param {object} d Date, Time, Date/Time element | |
* @param {string} s Format string | |
* @return {string} Formatted Date object | |
*/ | |
function formatDate(d,s) { | |
if(typeof s === "undefined" || s.trim() === "") { return d.toISOString(); } | |
var full_months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; |
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
function getAge(d) { | |
var today = new Date(); | |
var age = today.getFullYear() - d.getFullYear(); | |
var m = today.getMonth() - d.getMonth(); | |
if (m < 0 || (m === 0 && today.getDate() < d.getDate())) { | |
age--; | |
} | |
return age; | |
} |
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
/** | |
* upscales an iFormBuilder/Data Collector JSON v9.0 record to v10.0 | |
* @param {object} r a valid iFormBuilder/Data Collector record | |
* @return {object} record with modified metadata to match JSON v10.0 | |
*/ | |
function jsonV10(r) { | |
function convert_dates(rec) { | |
var date_keys = ["created_date", "modified_date", "server_modified_date"]; | |
for (var i = 0; i < date_keys.length; i++) { |
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
/** | |
* function returns subform as 2D array | |
* @param {object} r valid JSON object | |
* @param {int} n integer greater than 1 | |
* @return {object} 2D array where number of objects per row is equal to n | |
*/ | |
function subform_to_multi_array(r,n) { | |
if(typeof n !== 'number' || n !== Math.floor(n) || n <= 1 || n > r.length) return r; | |
var cols = []; | |
var count = 0; |
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
function split_location(r,dcn) { | |
if(!r.hasOwnProperty(dcn)) return r; | |
var l = r[dcn]; | |
l = l.replace(/(\r\n|\n|\r)/gm,""); | |
var location_arr = l.split(","); | |
for(var i=0; i<location_arr.length; i++) { | |
var kvp = location_arr[i].split(":"); | |
var key = kvp[0]; | |
var value = (key === "Time") ? value = kvp[1] + ":" + kvp[2] + ":" + kvp[3] : kvp[1]; |
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
/** | |
* Search through an object and delete any properties supplied in the list. | |
* Is case-sensitive and recursive by default. Both can be toggled by passing false. | |
* @param {Object} r original JS object | |
* @param {Array} properties list of keys/properties to remove | |
* @param {Boolean} [case_sensitive=true] set to false for case-insensitive | |
* @param {Boolean} [recursive=true] set to true for recursive | |
* @return {Object} modified JS object | |
*/ | |
function remove_properties(r,properties,case_sensitive,recursive) { |
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
function full_flatten(data) { | |
// Edit these two variables to change the character(s) before and after the index value | |
var before_index = "_"; | |
var after_index = "_"; | |
// Do not edit below here | |
var result = {}; | |
function recurse(cur, prop) { | |
if (Object(cur) !== cur) { |
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
function remove_subforms(r) { | |
// loop through and store each key | |
for(var key in r) { | |
// if property is a subform (array) | |
if(Array.isArray(r[key])) { | |
// delete the property | |
delete r[key]; | |
} | |
} | |