JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
JavaScript
var namespace = namespace || {};
;(function(global, namespace){
if(namespace.typeOf) return;
namespace.typeOf = function(item){
if (item == null) return 'null';
if (item.nodeName){
if (item.nodeType == 1) return 'element';
if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
} else if (typeof item.length == 'number'){
if (item.callee) return 'arguments';
if ('item' in item) return 'collection';
}
var thetype = typeof item;
if (thetype === 'object') {
if (item) {
if (typeof item.length === 'number' && !(value.propertyIsEnumerable('length')) && typeof value.splice === 'function') {
thetype = 'array';
}
} else {
thetype = 'null';
}
return thetype;
}
return thetype;
};
})(window,namespace);
;(function(global,namespace){
var Hash = namespace.Hash = function(){};
Hash.prototype.toQueryString = function(obj,base){
var queryString = []
,self = this
,key
,obj = (obj)?obj : (this.hash) ? this.hash: false;
if(!obj){
throw new Error(this.errors['toQueryString.param']);
}
for(key in obj){
if (base) key = base + '[' + key + ']';
var result;
switch (namespace.typeOf(obj[key])){
case 'object':
result = self.toQueryString(obj[key], key);
break;
case 'array':
var qs = {};
object[key].each(function(val, i){
qs[i] = val;
});
result = self.toQueryString.toQueryString(qs, key);
break;
default:
result = key + '=' + encodeURIComponent(obj[key]);
break;
}
if (obj[key] != null) queryString.push(result);
...