cajole
Version:
coax data into formats
134 lines • 4.54 kB
JavaScript
function to(a0) {
if (a0 === 'string') {
return function toString(a0$2) {
if (typeof a0$2 === 'string' || Object.prototype.toString.call(a0$2) === '[object String]') {
var x$2 = a0$2;
return x$2;
}
if (Array.isArray ? Array.isArray(a0$2) : Object.prototype.toString.call(a0$2) === '[object Array]') {
var x$2 = a0$2;
return JSON.stringify(x$2);
}
if (a0$2 != null) {
var r0$2 = Object(a0$2);
if ('toString' in r0$2) {
var r1$2 = r0$2['toString'];
if ((typeof r1$2 === 'function' || Object.prototype.toString.call(r1$2) === '[object Function]') && a0$2.toString !== Object.prototype.toString) {
var x$2 = a0$2;
return x$2.toString();
}
}
}
if (Object.prototype.toString.call(a0$2) === '[object Object]') {
var x$2 = a0$2;
return JSON.stringify(x$2);
}
var x$2 = a0$2;
throw new TypeError('Cannot convert ' + x$2 + ' to string (except I just did lol)');
return;
};
}
if (a0 === 'number') {
return function toNumber(a0$2) {
if (typeof a0$2 === 'string' || Object.prototype.toString.call(a0$2) === '[object String]') {
var x$2 = a0$2;
return parseFloat(x$2);
}
if (typeof a0$2 === 'number' || Object.prototype.toString.call(a0$2) === '[object Number]') {
var x$2 = a0$2;
return x$2;
}
var x$2 = a0$2;
throw new TypeError('Cannot convert ' + x$2 + ' to number');
return;
};
}
if (a0 === 'integer') {
return function toInteger(a0$2) {
if (typeof a0$2 === 'string' || Object.prototype.toString.call(a0$2) === '[object String]') {
var x$2 = a0$2;
return parseInt(x$2);
}
if (typeof a0$2 === 'number' || Object.prototype.toString.call(a0$2) === '[object Number]') {
var x$2 = a0$2;
return Math.floor(x$2);
}
var x$2 = a0$2;
throw new TypeError('Cannot convert ' + x$2 + ' to integer');
return;
};
}
if (a0 === 'boolean') {
return function toBoolean(a0$2) {
if (typeof a0$2 === 'boolean' || Object.prototype.toString.call(a0$2) === '[object Boolean]') {
var x$2 = a0$2;
return x$2;
}
if (a0$2 === 'true') {
return true;
}
if (a0$2 === 'false') {
return false;
}
var x$2 = a0$2;
return !!x$2;
};
}
if (typeof a0 === 'function' || Object.prototype.toString.call(a0) === '[object Function]') {
var x = a0;
return x;
}
if ((Array.isArray ? Array.isArray(a0) : Object.prototype.toString.call(a0) === '[object Array]') && a0.length >= 0) {
var r0 = [];
var r1 = 1;
for (var r2 = 0, r3 = a0.length, r4; r2 < r3; r2++) {
r4 = a0[r2];
r0[r0.length] = r4;
}
if (r1) {
var xs = r0;
return function toArray(vs) {
return xs.map(function (x$2, i) {
return module.exports(x$2)(vs[i]);
});
};
}
}
if (Object.prototype.toString.call(a0) === '[object Object]') {
var x = a0;
return function toObject(obj) {
var out = {};
for (var p in x) {
out[p] = module.exports(x[p])(obj[p]);
}
return out;
};
}
throw new TypeError('No match');
}
;
function type(a0) {
if (a0 != null) {
var r0 = Object(a0);
if ('name' in r0) {
var r1 = r0['name'];
if (r1 === '') {
var x = a0;
return x;
}
}
}
if (typeof a0 === 'function' || Object.prototype.toString.call(a0) === '[object Function]') {
var
// anonymous functions are always converters
x = a0;
return x.name.toLowerCase();
}
var x = a0;
return x;
}
module.exports = function (t) {
return function (val) {
return to(type(t))(val);
};
};