Edit in JSFiddle

(function(){
    
    var  chars36 = '0123456789abcdefghijklmnopqrstuvwxyz'
        ,chars62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
    function encode(intVal, base, chars){
        var i, str = '';
        do {    
            i = intVal % base;
            str = chars[i] + str;
            intVal = Math.floor((intVal - 1) / base);
        } while(intVal > 0);
        return str;
    }
    
    function decode(strVal, base, chars){
        var  len = strVal.length
            ,val = 0
            ,i;
        for(i = 0; i < len; i++){
            val += chars.indexOf(strVal[i]) * Math.pow(base, len - i - 1);
        }
        return val;
    }
    
    var toExport = {
         chars36: chars36
        ,chars62: chars62
        ,encode: encode
        ,decode:decode
    };
    
    if(window){
        window.BaseX = toExport;
    } else {
        exports = toExport;
    }
    
})();

console.log(BaseX.encode(2000000, 36, BaseX.chars36));
console.log(BaseX.encode(2000000, 62, BaseX.chars62));