/* Python(ish) string formatting:
 * >>> format('{0}', ['zzz'])
 * "zzz"
 * >>> format('{0}{1}', 1, 2)
 * "12"
 * >>> format('{x}', {x: 1})
 * "1"
 */
var format = (function() {
    var re = /\{([^}]+)\}/g;
    return function(s, args) {
        if (!args) return;
        if (!(args instanceof Array || args instanceof Object))
            args = Array.prototype.slice.call(arguments, 1);
        return s.replace(re, function(_, match){ return args[match]; });
    };
})();
function template(s) {
    return function(args) { return format(s, args); };
}

@@ -227,24 +227,97 @@
 (s, args) %7B%0A
+        if (!s) %7B%0A            throw %22Format string is empty!%22;%0A        %7D%0A
         if (
@@ -561,24 +561,87 @@
 mplate(s) %7B%0A
+    if (!s) %7B%0A        throw %22Template string is empty!%22;%0A    %7D%0A
     return f

add safety checks and throws to format code