encode objects

This commit is contained in:
Mark Nadal 2023-11-17 03:44:20 -08:00
parent 5d3cbaca19
commit efb2552997

View File

@ -138,7 +138,7 @@ function tot(){ var tmp;
function sub(i,j){ return (this.first||this.word||B.decode((from(this)||'')[0]||'')).substring(i,j) }
function to(){ return this.text = this.text || text(this) }
function join(){ return this.join('|') }
function text(p){ var l = p.limbo;
function text(p){ var l = p.limbo; // TODO: BUG??? Shouldn't any stringify cause limbo to be reset?
if(!l){ return (typeof p.from == 'string')? (p.from||'')+'' : '|'+p.from+'|' }
if(!p.from){ return p.limbo = null, '|'+((l && sort(l).join('|'))||'')+'|' } // TODO: p.limbo should be reset each time we "flush".
return '|'+mix(l, from(p), p).join('|')+'|'; // commenting out this sub-portion of code fixed a more basic test, but will probably cause a bug with a FROM + MEMORY.
@ -160,7 +160,7 @@ function sort(l){ //return l.sort();
});
}
B.encode = function(d, s){ s = s || "|";
B.encode = function(d, s, u){ s = s || "|"; u = u || String.fromCharCode(32);
switch(typeof d){
case 'string': // text
var i = d.indexOf(s), c = 0;
@ -168,7 +168,10 @@ B.encode = function(d, s){ s = s || "|";
return (c?s+c:'')+ '"' + d;
case 'number': return (d < 0)? ''+d : '+'+d;
case 'boolean': return d? '+' : '-';
case 'object': return d? "{TODO}" : ' ';
case 'object': if(!d){ return ' ' }
var l = Object.keys(d).sort(), i = 0, t = s, k, v;
while(k = l[i++]){ t += u+B.encode(k)+u+B.encode(d[k])+u+s }
return t;
}
}
B.decode = function(t, s){ s = s || "|";
@ -201,4 +204,4 @@ function decord(t){
}
try{module.exports=B}catch(e){}
}());
}());