Posted By

Pjotor on 05/18/18


Tagged

packer unpacker


Versions (?)

Pack strings


 / Published in: JavaScript
 

URL: pjotor.com

Packs strings using unicode

  1. String.prototype.pack = function() { return unescape([...this].map(_=>_.charCodeAt(0).toString(16)).join('').replace(/.{2,4}/g,"%u$&")+'00') }
  2. String.prototype.unpack = function() { return unescape(escape(this).replace(/u(..)/g,"$1%")) }
  3.  
  4. //"hello world".pack()

Report this snippet  

You need to login to post a comment.