nl_tokens: Original Name encode and decode logic is in github . com / eosio / eos native . hpp Encode a name ( a base32 string ) to a number .
pl_tokens: function encodeName ( name , littleEndian = true ) { if ( typeof name !== "string" ) throw new TypeError ( "name parameter is a required string" ) ; if ( name . length > 13 ) throw new TypeError ( "A name can be up to 13 characters long" ) ; let bitstr = "" ; for ( let i = 0 ; i <= 12 ; i ++ ) { // process all 64 bits (even if name is short) const c = i < name . length ? charidx ( name [ i ] ) : 0 ; const bitlen = i < 12 ? 5 : 4 ; let bits = Number ( c ) . toString ( 2 ) ; if ( bits . length > bitlen ) { throw new TypeError ( "Invalid name " + name ) ; } bits = "0" . repeat ( bitlen - bits . length ) + bits ; bitstr += bits ; } const value = Long . fromString ( bitstr , true , 2 ) ; // convert to LITTLE_ENDIAN let leHex = "" ; const <mask> = littleEndian ? value . toBytesLE ( ) : value . toBytesBE ( ) ; for ( const b of bytes ) { const n = Number ( b ) . toString ( 16 ) ; leHex += ( n . length === 1 ? "0" : "" ) + n ; } const ulName = Long . fromString ( leHex , true , 16 ) . toString ( ) ; // console.log('encodeName', name, value.toString(), ulName.toString(), JSON.stringify(bitstr.split(/(.....)/).slice(1))) return ulName . toString ( ) ; }