How to encode base 64

PHP

<?php 
function base64_urlsafe_encode($data) { 
  return strtr(base64_encode($data), '+/', '-_');
} 

function base64_urlsafe_decode($data) { 
  return base64_decode(strtr($data, '-_', '+/')); 
} 

$customer_info = "Michael|Scott|[email protected]|0123456789|123ABC";

$cz_user = base64_urlsafe_encode($customer_info);

echo $cz_user;
//TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD
?>

Python

import base64

customer_info = 'Michael|Scott|[email protected]|0123456789|123ABC'

cz_user = base64.urlsafe_b64encode(customer_info)

print cz_user
#TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD

JavaScript

base64_encode = function(unencoded) {
  return new Buffer(unencoded || '').toString('base64');
};

base64_decode = function(encoded) {
  return new Buffer(encoded || '', 'base64').toString('utf8');
};

base64_urlsage_encode = function(unencoded) {
  var encoded = base64_encode(unencoded);
  return encoded.replace(/\+/g, '-').replace(/\//g, '_');
};

base64_urlsafe_decode = function(encoded) {
  encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
  return base64_decode(encoded);
};

var customer_info = "Michael|Scott|[email protected]|0123456789|123ABC"

var cz_user = base64_urlsage_encode(customer_info)

console.log(cz_user)
//TWljaGFlbHxTY290dHxtaWNoYWVsLnNjb3R0QGR1bmRlcm1pZmZsaW4uY29tfDAxMjM0NTY3ODl8MTIzQUJD