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
/** | |
* tests for all the ways a variable might be undefined or not have a value | |
* @param {*} x the variable to test | |
* @return {Boolean} true if variable is defined and has a value | |
*/ | |
function isDefined(x) { | |
if ( x === '' || x === null || x === undefined) { | |
return false; | |
} | |
return true; |
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
/** | |
* utility to extract h/m/s from seconds | |
* @param {number} secs - seconds to convert to hh:mm:ss | |
* @returns {object} object with members h (hours), m (minutes), s (seconds) | |
*/ | |
function secondsToTime(secs) { | |
var hours = Math.floor(secs / (60 * 60)), | |
divisor_for_minutes = secs % (60 * 60), | |
minutes = Math.floor(divisor_for_minutes / 60), | |
divisor_for_seconds = divisor_for_minutes % 60, |
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
/** | |
* append new HTML elements to some existing one - efficiently | |
* @param {Object} htmlEl reference to the HTML element to append new HTML to | |
*/ | |
function appendHTML(htmlEl) { | |
var i = 0, el, fragment = document.createDocumentFragment(); | |
while (i < 200) { | |
el = document.createElement('li'); | |
el.innerText = 'This is my list item number ' + 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
/** | |
* gets value of a URL param if exists | |
* @param {string} name the param you want the value of | |
* @return {string} result value of param if exists or "" | |
*/ | |
function getURLparam(name) { | |
var regex, | |
results; | |
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); |
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
/** | |
* remove spaces from a string | |
* @param {String} str string to process | |
* @return {String} trimmed string | |
*/ | |
function removeSpaces(str) { | |
str= str.replace(/\s/g, ''); | |
return 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
/* | |
* tests to see if a string is json | |
* @param {String} str string to test | |
* @return {Boolean} | |
*/ | |
function isJson(str) { | |
try { | |
JSON.parse(str); | |
} catch (e) { | |
return 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
a.push.apply( a, b ); |
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
/** | |
* dedupe a simple array of strings or numbers | |
* @param {array} arr the array to be deduped | |
* @return {array} out the deduped array | |
*/ | |
function dedupe(arr) { | |
var i, | |
len = arr.length, | |
out = [], | |
obj = {}; |
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
/** | |
* remove spaces from a string | |
* @param {String} str string to process | |
* @return {String} trimmed string | |
*/ | |
function removeSpaces(str) { | |
str= str.replace(/\s/g, ''); | |
return str; | |
} |
OlderNewer