Javascript String encrypt()

Description

Javascript String encrypt()



String.prototype.encrypt = (function () {
   var secret = {
       'p' : '\u0044',
       '1' : 'a'
   };/* w w  w.j  a v  a 2  s .c  om*/
   return function(){
       var regex = /\w|\d|\s/gi;

       return this.replace(regex, function(a) {
          return typeof (secret[a.toLowerCase()]) !== "undefined" ? secret[a.toLowerCase()] : a;
       });
   }
})();

console.log('Een 1pekst'.encrypt());



PreviousNext

Related