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 isArray = (function() { | |
if (!isFunction(Array.isArray)) { | |
return function(value) { | |
return toString.call(value) === '[object Array]'; | |
}; | |
} | |
return Array.isArray; | |
})(); |
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 removeSpecialChars (str) { | |
return str.replace(/[^a-zA-Z ]/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
function int(str) { | |
return parseInt(str, 10); | |
} |
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 uid = ['0', '0', '0']; | |
function nextUid() { | |
var index = uid.length; | |
var digit; | |
while(index) { | |
index--; | |
digit = uid[index].charCodeAt(0); | |
if (digit == 57 /*'9'*/) { |
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 isArrayLike(obj) { | |
if (obj == null || isWindow(obj)) { | |
return false; | |
} | |
var length = obj.length; | |
if (obj.nodeType === 1 && length) { | |
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
function cloneObject(obj) { | |
var clone = {}; | |
for(var i in obj) { | |
if(typeof(obj[i])=="object" && obj[i] != null) | |
clone[i] = cloneObject(obj[i]); | |
else | |
clone[i] = obj[i]; | |
} | |
return clone; | |
} |
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
// | |
// Super simple base64 encoding / decoding with node.js | |
// | |
var base64 = exports = { | |
encode: function (unencoded) { | |
return new Buffer(unencoded).toString('base64'); | |
}, | |
decode: function (encoded) { | |
return new Buffer(encoded, 'base64').toString('utf8'); |
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
for (let i = 0; i < 10; i++) { | |
x += 10; | |
} | |
console.log(x); | |
try { | |
console.log(i); | |
} catch(e) { | |
console.log( |
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 getQueryMatch (query,key) { | |
var regx = new RegExp(key+"=([^&]*)"); | |
return decodeURIComponent(query.match(regx)[1]); | |
} | |
console.log(getQueryMatch("http://example.com?x=hello&y=des%20t","y")); |
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 getQueryObj (query) { | |
query = query.substring(query.indexOf("?")+1,query.length); | |
var keys = query.split("&") , obj = {}; | |
for (var i = 0; i < keys.length; i++) { | |
var pair = keys[i].split("="); | |
obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); | |
} | |
return obj; | |
} | |
console.log(getQueryObj("http://example.com?x=hello&y=des%20t")); |