diff --git a/docs/master.html b/docs/master.html index 621dd82..60f8c41 100644 --- a/docs/master.html +++ b/docs/master.html @@ -342,6 +342,8 @@

`.d(f)`

Maps each item in `this` through `f`, then returns `true` if any are truthy, and `false` otherwise.

`.e(f)`

Maps each item in `this` through `f`, then returns `true` if all are truthy, and `false` otherwise.

+

`.e(a)`

+

Returns `true` if the length of `this``is equal to the length of `a` and each element in `this` is equal to the corresponing element in `a`, and `false` otherwise.

`.f(f)`

Selects the items in `this` that return truthily to `f`.

`.f(a)`

diff --git a/docs/v2.html b/docs/v2.html index b8d5a9f..6d78dab 100644 --- a/docs/v2.html +++ b/docs/v2.html @@ -337,6 +337,8 @@

`.d(f)`

Maps each item in `this` through `f`, then returns `true` if any are truthy, and `false` otherwise.

`.e(f)`

Maps each item in `this` through `f`, then returns `true` if all are truthy, and `false` otherwise.

+

`.e(a)`

+

Returns `true` if the length of `this``is equal to the length of `a` and every element in `this` is equal to the corresponing element in `a`, and `false` otherwise.

`.f(f)`

Selects the items in `this` that return truthily to `f`.

`.f(a)`

@@ -466,8 +468,8 @@

`.b(n,n)`

Returns `this` bounded with min `n₁` and max `n₂`.

`.c(n=1)`

Returns `this` rounded up to the nearest multiple of `n`.

-

`.d()`

-

Returns the char at code-point `this`.

+

`.d(n=0)`

+

Returns the char at code-point `this+n`.

`.e(n)`

Returns `this*Math.pow(10,n)`.

`.f(n=1)`

diff --git a/index.html b/index.html index 4112304..f49ccaf 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - + Japt interpreter @@ -64,7 +64,7 @@

  Japt Interpreter

var defv = "1.4.5"; var v = defv; var code, input; - + function escapedBtoA(text) { return btoa( text.replace(/./g,function(x){ @@ -74,11 +74,11 @@

  Japt Interpreter

}) ); } - + function escapedAtoB(text) { return atob(text).replace(/\\u[0-9A-Fa-f]{4}/g,function(x){return String.fromCharCode(parseInt(x.slice(2),16))}); } - + function splitAddress() { var args=location.search.match(/[&?](code|input|v)=([^&]|&(?!(code|input|v)=))*/g); if (args) for (var q in args) { @@ -125,7 +125,7 @@

  Japt Interpreter

var script = document.createElement('script'); script.setAttribute("src", "https://rawgit.com/ETHproductions/japt/" + (realv === 'v2' ? 'master' : realv) + file); document.getElementsByTagName('head')[0].appendChild(script); - + var docs = document.getElementById('docs'); function addDocs(header, text) { docs.innerHTML = header; @@ -138,7 +138,7 @@

  Japt Interpreter

}) .replace(/arrow:([a-z-]+)/gi, ''); } - + var versionText; function addMaster (x) { return function () { @@ -149,7 +149,7 @@

  Japt Interpreter

}); } } - + if (iscommit) { versionText = "

You're using Japt " + (isv2 ? "v2 " : "") + "commit " + realv.slice(0, 7) + ".

"; getWebpage('https://rawgit.com/ETHproductions/Japt/' + realv + '/docs/' + (isv2 ? 'v2.html' : 'master.html'), function (response) { @@ -185,7 +185,7 @@

  Japt Interpreter

request.open("GET", url); request.send(); } - + function setup() { if(typeof code !== "undefined" && !document.getElementById("code").value) document.getElementById("code").value = code; if(typeof input !== "undefined" && !document.getElementById("input").value) document.getElementById("input").value = input; @@ -195,27 +195,27 @@

  Japt Interpreter

} update(); } - + function update() { var code = document.getElementById("code").value, encoding = "ISO-8859-1"; if (/[^\x00-\xff]/.test(code)) code = unescape(encodeURI(code)), encoding = "UTF-8"; document.getElementById('bytes').innerHTML = code.length + " byte" + (code.length === 1 ? "" : "s") + " in " + encoding; document.getElementById('js-code').value = (window.Japt || window).transpile(document.getElementById('code').value); } - + function getURL() { var code = escapedBtoA(document.getElementById("code").value); var input = escapedBtoA(document.getElementById("input").value); document.getElementById("output").value = "https://ethproductions.github.io/japt/?v="+v+"&code="+code+"&input="+input; } - + function toggleTab(tab) { var style = document.getElementById(tab).style; if (style.display == "none") style.display = "block"; else style.display = "none"; var text = document.getElementById("toggle-" + tab); if (text.innerHTML == "▼") text.innerHTML="▲"; else text.innerHTML = "▼"; } - + function toggleAll(src) { var arrows = document.getElementsByClassName("arrow"); for (var i in arrows) { @@ -225,7 +225,7 @@

  Japt Interpreter

} src.innerHTML = (src.innerHTML[0] === "▼" ? "▲ Collapse all" : "▼ Expand all"); } - + function onrun() { var start; if (window.Japt) { @@ -250,7 +250,7 @@

  Japt Interpreter

document.getElementById('time').innerHTML = '(took ' + ((new Date - start) / 1e3).toFixed(3) + ' seconds)'; } } - + splitAddress(); var int = setInterval(function(){if(window.Japt || window.run) setup(), clearInterval(int)}, 100); diff --git a/src/japt-interpreter.js b/src/japt-interpreter.js index 96011b2..8c110a6 100755 --- a/src/japt-interpreter.js +++ b/src/japt-interpreter.js @@ -15,7 +15,7 @@ var isnode = typeof window === "undefined"; if (isnode) var shoco = require("../dependencies/shoco"); Object.defineProperty(isnode ? global : window, "K", { enumerable: false, configurable: true, get: function() { return fb(_K, new Date()); }, set: function(x) { return _K=x; }}); -var pairs_1_3 = { +var pairs_1_3 = { // Unicode shortcuts // Using \u to avoid encoding incompatibilities "@": "XYZ{", @@ -69,7 +69,7 @@ var pairs_1_3 = { "\xDF": "$rp$(" // ß - 223 }; -var pairs_2_0 = { +var pairs_2_0 = { // A new list of Unicode shortcuts // Using \u to avoid encoding incompatibilities "@": "XYZ{", @@ -188,7 +188,7 @@ df(Array,'a',function(x,y){if(id(y))x=functify(x,y);return typeof x=="function"? df(Array,'b',function(x,y){if(id(y))x=functify(x,y);return typeof x=="function"?this.map(function(a,b,c){return!!x(a,fb(y,b),c)}).indexOf(true):this.indexOf(x)}); df(Array,'c',function(x){if(id(x))return this.concat(x);var f=[];for(var i of this){if(i instanceof Array)for(var j of i.c())f.push(j);else f.push(i);}return f}); df(Array,'d',function(x,y){x=fb(x,function(y){return!!y});x=functify(x,y);return this.some(function(a,b,c){return x(a,fb(y,b),c)})}); -df(Array,'e',function(x,y){x=fb(x,function(y){return!!y});x=functify(x,y);return this.every(function(a,b,c){return x(a,fb(y,b),c)})}); +df(Array,'e',function(x,y){if(x instanceof Array){return this.length===x.length&&this.every(function(a,b){return a==x[b]})}else{x=fb(x,function(y){return!!y});x=functify(x,y);return this.every(function(a,b,c){return x(a,fb(y,b),c)})}}); df(Array,'f',function(x,y){if(x instanceof Array){y=fb(y,0)%3;if(y===2)return this.filter(function(q){var a=x.indexOf(q);if(~a)x.splice(a,1);return~a});else if(y===1)return this.filter(function(q,i,a){return~x.indexOf(q)&&a.indexOf(q)===i});else return this.filter(function(q){return~x.indexOf(q)})}x=fb(x,function(y){return!!y});x=functify(x,y);return this.filter(function(a,b,c){return x(a,fb(y,b),c)})}); df(Array,'g',function(x){var l=this.length;x=pm(fb(x,0),l);return this[x]}); df(Array,'h',function(x,y){var l=this.length,z;if(!id(y))y=x,x=0;if(typeof x!=="number"&&typeof y==="number")z=x,x=y,y=z;x=pm(x,l);this[x]=y;return this}); @@ -242,7 +242,7 @@ df(Array,'\xFB',function(x,y){return this.pad(x,y,0)}); df(Number,'a',function(x){x=fb(x,0);return Math.abs(this-x)}); df(Number,'b',function(x,y){return thisy?y:this}); df(Number,'c',function(x){x=fb(x,1);return Math.ceil(this/x)*x}); -df(Number,'d',function(x){x=fb(x,0);return String.fromCharCode(this+x)}); +df(Number,'d',function(x){x=fb(x,0);return String.fromCodePoint(this+x)}); df(Number,'e',function(x){return this*Math.pow(10,x)}); df(Number,'f',function(x){x=fb(x,1);return Math.floor(this/x)*x}); df(Number,'g',function(){return this.toString()=="NaN"?"NaN":this<0?-1:this>0?1:0}); @@ -342,7 +342,7 @@ Math.S = Math.SQRT_2; Math.T = Math.PI * 2; // String compression -shoco.c = function (str) { return Array.prototype.map.call(shoco.compress(str), function (char) { return String.fromCharCode(char) }).join('') }; +shoco.c = function (str) { return Array.prototype.map.call(shoco.compress(str), function (char) { return String.fromCodePoint(char) }).join('') }; shoco.d = function (str) { return shoco.decompress(new Uint8Array( ( str.constructor == Array ? str[0] : str ).split('').map(function (char) {return char.charCodeAt(0)})))}; void(0); @@ -471,10 +471,10 @@ function deparen(snippet) { var rp, program; var Japt = { - + stdout: null, stderr: null, - + clear_output: function() { if (isnode) { // Not sure how to do this... Would console.log("\033c") work? @@ -491,7 +491,7 @@ var Japt = { } } }, - + output: function(x) { Japt.implicit_output = false; if (isnode) { @@ -502,13 +502,13 @@ var Japt = { alert ("Error: Japt.stdout must be sent to an HTMLElement"); } }, - + stop: function() { for (var i = 0; i < Japt.intervals.length; i++) clearInterval(Japt.intervals[i]); Japt.intervals = []; }, - + error: function(msg) { if (isnode) { process.stderr.write(msg); @@ -519,7 +519,7 @@ var Japt = { alert ("Error: Japt.stderr must be sent to an HTMLElement"); } }, - + evalInput: function(input) { if (input.constructor === Array) return input; var input_mode = "next", current, processed = [], level = 0; @@ -610,15 +610,15 @@ var Japt = { } return processed; }, - + strings: [], use_safe: false, is_safe: false, implicit_output: true, - + run: function(code, input, safe, before, onsuccess, onerror) { Japt.clear_output(); - + input = Japt.evalInput(input); A = 10, B = 11, @@ -657,9 +657,9 @@ var Japt = { X = 3 in N ? N[3] : 0, Y = 4 in N ? N[4] : 0, Z = 5 in N ? N[5] : 0; - + Japt.use_safe = fb(safe, false), Japt.is_safe = true, Japt.implicit_output = true, Japt.flags = input.flags || {}; - + code = Japt.transpile(code); if (!Japt.is_safe) { if (onerror) onerror(new Error("Raw JS cannot be used in safe mode")); @@ -687,7 +687,7 @@ var Japt = { return program.cache[id] = eval(code); }; var result; - + if (Japt.flags.m || Japt.flags.d || Japt.flags.e || Japt.flags.f || Japt.flags.æ) { if (Japt.flags.d) result = false; else if (Japt.flags.e) result = true; @@ -728,32 +728,32 @@ var Japt = { } else { result = program(U,V,W,X,Y,Z); } - + if (Japt.flags.hasOwnProperty('h')) result = result.g(-1); else if (Japt.flags.hasOwnProperty('g')) result = result.g(Japt.flags.g === true ? 0 : Japt.flags.g); - + if (Japt.flags.hasOwnProperty('!')) result = !result; else if (Japt.flags.hasOwnProperty('¡')) result = !!result; - + if (Japt.flags.N) result = +result; - + if (Japt.flags.P && result instanceof Array) result = result.join(""); else if (Japt.flags.Q) result = JSON.stringify(result); else if (Japt.flags.R && result instanceof Array) result = result.join("\n"); else if (Japt.flags.S && result instanceof Array) result = result.join(" "); - + if (Japt.flags.x) result = result.x(); - + if (onsuccess) onsuccess(result); } catch (e) { if (onerror) onerror(e); } }, - + transpile: function(code) { Japt.strings = []; Japt.intervals = []; - + function pretranspile(code) { var level = 0, // Current number of parentheses or curly braces that we're inside extrabraces = Array(20).fill(0), @@ -766,7 +766,7 @@ var Japt = { lines = [], strchars = Array(20).fill(""), internary = false; - + for (; i < code.length; ++i) { var char = code[i]; if (level === 0) { @@ -915,13 +915,13 @@ var Japt = { lines.push(subtranspile(newcode)); return lines.join(""); } - + function subtranspile(code) { var level = 0, // Current number of parentheses or curly braces that we're inside i = 0, outp = "", // Temporary output extraparen = false; - + for (i = 0; i < code.length; ++i) { var char = code[i], opMatch = code.slice(i).match(/^(===|!==|==|!=|>>>|>>|<<|&&|\|\||>=|<=|\+(?!\+)|-(?!-)|\.(?!\d)|[*%^&|<>,])(?!=)/), @@ -941,7 +941,7 @@ var Japt = { code = code.slice(0,i)+'2'+code.slice(i); else if ((outp === "" || outp.slice(-1) === ";") && /[a-zà-ÿ*/%^|&<=>?]/.test(char)) outp += "U"; - + if (char === "\"") { var tms = code.slice(i).match(/"(\d+)"/)[0]; outp += tms; @@ -1034,14 +1034,14 @@ var Japt = { outp += char; } } - + outp = fixParens(outp); - + return outp; } - + var outp = pretranspile(code); - + outp = outp .replace(/(\+\+|--)[A-Z]|[A-Z](\+\+|--)/g, function(s) { Japt.strings.push("(" + s + ")"); return "\"" + (Japt.strings.length - 1) + "\""; }) .replace(/[,;]/g, "$& ") @@ -1052,7 +1052,7 @@ var Japt = { outp = outp.replace(/"(\d+)"/g,function(_,a){return Japt.strings[+a]}); return outp; }, - + eval: function(code) { return eval(Japt.transpile(code)); } diff --git a/src/japt.js b/src/japt.js index 4fd5459..f209683 100644 --- a/src/japt.js +++ b/src/japt.js @@ -11,7 +11,7 @@ Object.defineProperty(isnode ? global : window, "K", { return fb(_K, new Date()); }, set: function(x) { - return _K = x; + return _K = x; } }); @@ -50,13 +50,13 @@ function regexify(string, flags) { // you dirty rotten liar return string; string = String(string); - + if (flags !== "") { flags = String(fb(flags, "")); if (!flags.contains("g")) flags += "g"; } - + var regex = "", inCharClass = false; for(var i = 0; i < string.length; i++) { var char = string[i]; @@ -104,7 +104,7 @@ function regexify(string, flags) { regex += char; } } - + return RegExp(regex, flags); } @@ -123,18 +123,18 @@ function regexify2(string) { var end = string.lastIndexOf("/"); var flags = string.slice(end + 1); string = string.slice(1, end); - + if (flags.contains("g")) flags = flags.replace("g", ""); else flags += "g"; - + var dotAll = false; if (flags.contains("s")) { dotAll = true; flags = flags.replace("s", ""); } - + var regex = "", inCharClass = false, parens = 0; for(var i = 0; i < string.length; i++) { var char = string[i]; @@ -198,13 +198,13 @@ function regexify2(string) { regex += char; } } - + if (inCharClass) regex += "]"; while (parens > 0) { regex += ")"; parens -= 1; } - + return RegExp(regex, flags); } @@ -218,11 +218,11 @@ function saferegex(object, flags) { function functify(operator, argument) { if (typeof operator === "function") return operator; - + var hasArg = id(argument), func = "f=function(a,b){return ", isMethod = /^!?[a-zà-öø-ÿ]$/.test(operator); - + if (isMethod) { if (operator[0] !== "!") func += "a." + operator + (hasArg ? "(b)" : "()"); @@ -236,7 +236,7 @@ function functify(operator, argument) { func += "b" + operator.slice(1) + "a"; } func += "}"; - + return eval(func); } @@ -244,11 +244,11 @@ function functify(operator, argument) { function functify2(operator, argument) { if (typeof operator === "function") return operator; - + var hasArg = id(argument) && argument !== true, func = "(function(a, b) { return ", isMethod = /^!?[a-zà-öø-ÿ]$/.test(operator); - + if (isMethod) { if (operator[0] !== "!") func += "a." + operator + (hasArg ? "(" + str(argument) + ")" : argument === true ? "(b)" : "()"); @@ -262,7 +262,7 @@ function functify2(operator, argument) { func += (hasArg ? str(argument) : "b") + operator.slice(1) + "a"; } func += "; })"; - + return eval(func); } @@ -300,7 +300,7 @@ function clone(x) { return x; } -var pairs_1_3 = { +var pairs_1_3 = { // Unicode shortcuts // Using \u to avoid encoding incompatibilities "@": "XYZ{", @@ -354,7 +354,7 @@ var pairs_1_3 = { "\xDF": "$rp$(" // ß - 223 }; -var pairs_2_0 = { +var pairs_2_0 = { // A new list of Unicode shortcuts // Using \u to avoid encoding incompatibilities "@": "XYZ{", @@ -414,18 +414,18 @@ function perm (arr, len) { return [[]]; if (arr.length < 2) return [x]; - + var id = len + ';' + str(arr); if (permcache[id]) return permcache[id]; - + var result = []; for (var index = 0; index < arr.length; index++) if (index === arr.indexOf(arr[index])) perm(arr.slice(0, index).concat(arr.slice(index + 1)), len - 1).map(function(b) { result.push([arr[index]].concat(b)); }); - + return permcache[id] = result; } @@ -435,25 +435,25 @@ function comb(arr, len) { return [[]]; if (arr.length < 1 && !isNaN(len)) return []; - + var id = len + ';' + str(arr); if (combcache[id]) return ccache[id]; - + var result = []; for (var index = 0; index < arr.length; index++) if (index === arr.indexOf(arr[index])) comb(arr.slice(index + 1), len - 1).map(function(b) { result.push([arr[index]].concat(b)); }); - + if (isNaN(len)) result.push([]); return combcache[id] = result; } if (!id(String.prototype.repeat)) String.prototype.repeat = function(len) { len = Math.trunc(fb(len, 1)); - + var i = Math.pow(2, Math.floor(Math.log2(len))); var str = ''; while (i >= 1) { @@ -477,7 +477,7 @@ if (!id(Array.prototype.sortBy)) Array.prototype.sortBy = function(func) { return this.sort(); if (typeof func !== "function") throw new TypeError("Array.prototype.sortBy expects a function"); - + return this.sort(function(a, b) { a = func(a); b = func(b); @@ -623,7 +623,7 @@ df(String.prototype, { var z = clone(x).sortBy(function(x) { return -x.length; }).map(regescape).join("|"); - + var result = this.match(RegExp(z, y ? 'gi' : 'g')) || []; return result.reduce(function(prev, curr) { var i = x.indexOf(curr); @@ -771,7 +771,7 @@ df(String.prototype, { var s = this; return x.some(function(a) { return s.contains(a); }); }, - + pad: function(x, y, a) { var s = String(this), z; if (/\n/.test(s)) @@ -841,9 +841,14 @@ df(Array.prototype, { return this.some(x); }, e: function (x, y) { - x = fb(x, Boolean); - x = functify(x, y); - return this.every(x); + if (x instanceof Array) { + return this.length === x.length && this.every(function(a, b){ return a == x[b]; }); + } + else { + x = fb(x, Boolean); + x = functify(x, y); + return this.every(x); + } }, f: function (x, y) { if (x instanceof Array) { @@ -1290,7 +1295,7 @@ df(Number.prototype, { }, d: function (x) { x = fb(x, 0); - return String.fromCharCode(this + x); + return String.fromCodePoint(this + x); }, e: function (x) { return this * Math.pow(10, x); @@ -1338,7 +1343,7 @@ df(Number.prototype, { k: function () { var n = +this, f = []; - + for (var r = 2; r <= Math.sqrt(n); r += r % 2 + 1) { while (n % r === 0) { f.push(r); @@ -1347,7 +1352,7 @@ df(Number.prototype, { } if (n > 1) // True unless n is divisible by its largest factor more than once f.push(n); - + return f; }, l: function () { @@ -1372,7 +1377,7 @@ df(Number.prototype, { f = functify2(x, y), x = y = undefined; if (typeof y === "function") f = y, y = undefined; - + var z = +this; y = y || 1; if (!id(x)) @@ -1383,7 +1388,7 @@ df(Number.prototype, { _ = x, x = z, z = _; if (s & 1) x++; - + var r = [], i = 0; if (y > 0) @@ -1392,7 +1397,7 @@ df(Number.prototype, { else for ( ; z < x; x += y ) r.push(x); - + if (typeof f === "function") return r.map(f); return r; @@ -1482,13 +1487,13 @@ df(Number.prototype, { return []; var n = Math.abs(this); var a = []; - + for (var i = 1; i < Math.sqrt(n); ++i) if(n % i === 0) a.push(i, n / i); if (i * i === n) a.push(i); - + a.n(); if (x) a.pop(); @@ -1601,7 +1606,7 @@ df(Date, { i: function (x, y) { return this[ts(x) + "FullYear"](y || 0); }, j: function (x, y) { return this[ts(x) + "Time"](y || 0); }, k: function () { return this.getTimezoneOffset(); }, - + s: function (x) { return this["to" + [ "", @@ -1629,21 +1634,21 @@ function bij (num, radix) { radix = fb(radix, 10); if (radix % 1 || radix < 2) return result; - + if (num < 0) result = "-", num = -num - 1; - + var c = 0, x = 1; while (num >= x) { c++; num -= x; x *= radix; } - + for (var i = 0; i < c; i++) { result = (num % radix) + result; num = Math.trunc(num / radix); } - + return result; } @@ -1768,7 +1773,7 @@ Math.T = Math.PI * 2; // String compression shoco.c = function (str) { return Array.prototype.map.call(shoco.compress(str), function (char) { - return String.fromCharCode(char); + return String.fromCodePoint(char); }).join(''); }; @@ -1890,10 +1895,10 @@ function deparen(snippet) { var rp, program; var Japt = { - + stdout: null, stderr: null, - + clear_output: function() { if (isnode) { // Not sure how to do this... Would console.log("\033c") work? @@ -1910,7 +1915,7 @@ var Japt = { } } }, - + output: function(x) { Japt.implicit_output = false; if (isnode) { @@ -1921,13 +1926,13 @@ var Japt = { alert ("Error: Japt.stdout must be sent to an HTMLElement"); } }, - + stop: function() { for (var i = 0; i < Japt.intervals.length; i++) clearInterval(Japt.intervals[i]); Japt.intervals = []; }, - + error: function(msg) { if (isnode) { process.stderr.write(msg); @@ -1938,7 +1943,7 @@ var Japt = { alert ("Error: Japt.stderr must be sent to an HTMLElement"); } }, - + evalInput: function(input) { if (input.constructor === Array) return input; var input_mode = "next", current, processed = [], level = 0; @@ -2029,15 +2034,15 @@ var Japt = { } return processed; }, - + strings: [], use_safe: false, is_safe: false, implicit_output: true, - + run: function(code, input, safe, before, onsuccess, onerror) { Japt.clear_output(); - + input = Japt.evalInput(input); A = 10, B = 11, @@ -2076,9 +2081,9 @@ var Japt = { X = 3 in N ? N[3] : 0, Y = 4 in N ? N[4] : 0, Z = 5 in N ? N[5] : 0; - + Japt.use_safe = fb(safe, false), Japt.is_safe = true, Japt.implicit_output = true, Japt.flags = input.flags || {}; - + code = Japt.transpile(code); if (!Japt.is_safe) { if (onerror) onerror(new Error("Raw JS cannot be used in safe mode")); @@ -2106,7 +2111,7 @@ var Japt = { return program.cache[id] = eval(code); }; var result; - + if (Japt.flags.m || Japt.flags.d || Japt.flags.e || Japt.flags.f || Japt.flags.æ) { if (Japt.flags.d) result = false; else if (Japt.flags.e) result = true; @@ -2147,32 +2152,32 @@ var Japt = { } else { result = program(U,V,W,X,Y,Z); } - + if (Japt.flags.hasOwnProperty('h')) result = result.g(-1); else if (Japt.flags.hasOwnProperty('g')) result = result.g(Japt.flags.g === true ? 0 : Japt.flags.g); - + if (Japt.flags.hasOwnProperty('!')) result = !result; else if (Japt.flags.hasOwnProperty('¡')) result = !!result; - + if (Japt.flags.N) result = +result; - + if (Japt.flags.P && result instanceof Array) result = result.join(""); else if (Japt.flags.Q) result = JSON.stringify(result); else if (Japt.flags.R && result instanceof Array) result = result.join("\n"); else if (Japt.flags.S && result instanceof Array) result = result.join(" "); - + if (Japt.flags.x) result = result.x(); - + if (onsuccess) onsuccess(result); } catch (e) { if (onerror) onerror(e); } }, - + transpile: function(code) { Japt.strings = []; Japt.intervals = []; - + function pretranspile(code) { var level = 0, // Current number of parentheses or curly braces that we're inside extrabraces = Array(20).fill(0), @@ -2355,7 +2360,7 @@ var Japt = { lines.push(subtranspile(newcode)); return lines.join(""); } - + function subtranspile(code) { var level = 0, // Current number of parentheses or curly braces that we're inside i = 0, @@ -2479,9 +2484,9 @@ var Japt = { return outp; } - + var outp = pretranspile(code); - + outp = outp .replace(/(\+\+|--)[A-Z]|[A-Z](\+\+|--)/g, function(s) { Japt.strings.push("(" + s + ")"); return "\"" + (Japt.strings.length - 1) + "\""; }) .replace(/[,;]/g, "$& ") @@ -2493,7 +2498,7 @@ var Japt = { outp = outp.replace(/"(\d+)"/g, function(_, a) { return Japt.strings[+a]; }); return outp; }, - + eval: function(code) { return eval(Japt.transpile(code)); }