nl_tokens: / * # reference ( Python ) versions of compress and uncompress # only uncompress function is featured lower as JavaScript # if you want to unit test roundtrip just transcribe the reference # compress function from Python into JavaScript
pl_tokens: function uncompress ( data ) { var decoded = '0123456789abcdef' , encoded = 'klmnopqrstuvwxyz' , mapping = { } ; for ( var i = 0 ; i < encoded . length ; i ++ ) { mapping [ encoded [ i ] ] = decoded [ i ] ; } var undef , output = { } , sign = 1 , stringparts // undef. will be [] in string mode , activeobject = output , parentchain = [ ] , parent_key_pair , keyparts = '' , valueparts = '' , key // undef. will be Truthy when Key is resolved. , datalen = data . length - 1 // stripping ending } , ch ; i = 1 ; // stripping starting { while ( i != datalen ) { // - { } ' are special. ch = data [ i ] ; i += 1 ; if ( ch == "'" ) { if ( stringparts ) { // end of string mode key = stringparts . join ( '' ) ; stringparts = undef ; } else { // start of string mode stringparts = [ ] ; } } else if ( stringparts ) { stringparts . push ( ch ) ; } else if ( ch == '{' ) { // start of object parentchain . push ( [ activeobject , key ] ) ; activeobject = { } ; key = undef ; } else if ( ch == '}' ) { // end of object parent_key_pair = parentchain . pop ( ) ; parent_key_pair [ 0 ] [ parent_key_pair [ 1 ] ] = activeobject ; <mask> = undef ; activeobject = parent_key_pair [ 0 ] ; } else if ( ch == '-' ) { sign = - 1 ; } else { // must be number if ( key === undef ) { if ( mapping . hasOwnProperty ( ch ) ) { keyparts += mapping [ ch ] ; key = parseInt ( keyparts , 16 ) * sign ; sign = + 1 ; keyparts = '' ; } else { keyparts += ch ; } } else { if ( mapping . hasOwnProperty ( ch ) ) { valueparts += mapping [ ch ] ; activeobject [ key ] = parseInt ( valueparts , 16 ) * sign ; sign = + 1 ; key = undef ; valueparts = '' ; } else { valueparts += ch ; } } } } // end while return output ; }