JSFiddle - React, Tailwind, and code Playground
by Steven Senkus
JavaScript
function output(text, color) {
var p = document.createElement('p');
p.innerHTML = text;
p.style.color = color;
document.body.appendChild(p);
}
function testCase(name, tests) {
assert.count = 0;
var successful = 0;
var testCount = 0;
var hasSetup = typeof tests.setUp == "function";
var hasTeardown = typeof tests.tearDown == "function";
for (var test in tests) {
if (!/^test/.test(test)) {
continue;
}
testCount++;
try {
if (hasSetup) {
tests.setUp();
}
tests[test]();
output(test, "#0c0");
if (hasTeardown) {
tests.tearDown();
}
successful++;
} catch (e) {
output(test + " failed: " + e.message, "#c00");
}
}
var color = (successful == testCount) ? "#0c0" : "#c00";
var plural = testCount > 1 ? 's' : '';
output("<strong>" + testCount + " test" + plural + ", " + (testCount - successful) + " failure" + plural + "</strong>", color);
}
Date.prototype.strftime = (function () {
function strftime(format) {
var date = this;
return (format + "").replace(/%([a-zA-Z])/g, function (m, f) {
var formatter = Date.formats && Date.formats[f];
if (typeof formatter == "function") {
return formatter.call(Date.formats, date);
} else if (typeof formatter == "string") {
return date.strftime(formatter);
}
return f;
});
}
// internal helper
function zeroPad(num) {
return (+num < 10 ? "0" : "") + num;
}
Date.formats = {
// formatting methods
d: function (date) {
return zeroPad(date.getDate())
},
m: function (date) {
return zeroPad(date.getMonth() + 1)
},
y: function (date) {
return zeroPad(date.getYear() % 100);
...