Pas2JS pascal source code
var c, s: String;
const
cHello = 'Hello';
for c in cHello do
WriteLn(c + ': ' + IntToStr(Ord(c)));
s := #$1D538'A'#$3B1#$1D516;
for c in s do
WriteLn('unicode $' + UpperCase(IntToHex(Ord(c), 5)) + ' len ' +
IntToStr(Length(c)));
var
trap := 'trap';
function TrapIt: String;
begin
Result := trap;
trap := 'bug';
end;
for c in TrapIt do
WriteLn(c + ': $' + UpperCase(IntToHex(Ord(c), 5)));
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
H: 72
e: 101
l: 108
l: 108
o: 111
unicode $1D538 len 2
unicode $00041 len 1
unicode $003B1 len 1
unicode $1D516 len 2
t: $00074
r: $00072
a: $00061
p: $00070
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
function IntToHex(v,d) { var r=v.toString(16); return "00000000".substr(0, d-r.length)+r }
// inspired from
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/charCodeAt
function $uniCharCodeAt(str, idx) {
var c = str.charCodeAt(idx);
if (0xD800 <= c && c <= 0xDBFF) { // High surrogate
var lo = str.charCodeAt(idx+1);
if (isNaN(lo)) return c;
return ((c - 0xD800) * 0x400) + (lo - 0xDC00) + 0x10000;
}
if (0xDC00 <= c && c <= 0xDFFF) { // Low surrogate
return -1;
}
return c;
}
// inspired from
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/charCodeAt
function $uniCharAt(str, idx) {
var c = str.charCodeAt(idx);
if (0xD800 <= c && c <= 0xDBFF) { // High surrogate
return str.substr(idx, 2);
}
if (0xDC00 <= c && c <= 0xDFFF) { // Low surrogate
return null;
}
return str.charAt(idx);
}
function $OrdS(s) { return (s.length>0)?$uniCharCodeAt(s,0):0 }
function WriteLn(value) {
if (window.console) { window.console.log(value); } };
function TrapIt() {
var Result = "";
Result = trap;
trap = "bug";
return Result
};
var c = "";
var s = "";
var trap = "";
/* <<< main JS >>> */
var $temp1 = "Hello";
for (var $temp2 = 0; $temp2 < $temp1.length; $temp2++) {
c = $uniCharAt($temp1, $temp2);
if (!c)
continue;
WriteLn((c + ": " + ($OrdS(c)).toString()))
}
s = "\uD835\uDD38A\u03B1\uD835\uDD16";
for (var $temp3 = 0; $temp3 < s.length; $temp3++) {
c = $uniCharAt(s, $temp3);
if (!c)
continue;
WriteLn(("unicode $" + (IntToHex($OrdS(c), 5)).toUpperCase() + " len " + (c.length).toString()))
}
trap = "trap";
var $temp4 = TrapIt();
for (var $temp5 = 0; $temp5 < $temp4.length; $temp5++) {
c = $uniCharAt($temp4, $temp5);
if (!c)
continue;
WriteLn((c + ": $" + (IntToHex($OrdS(c), 5)).toUpperCase()))
}