23 lines
473 B
JavaScript
23 lines
473 B
JavaScript
/**
|
|
* Encodes an object as base64 string..
|
|
* @param obj The object to encode
|
|
*/
|
|
exports.objToBase64 = function(obj) {
|
|
return btoa(JSON.stringify(obj));
|
|
}
|
|
|
|
/**
|
|
* Decodes a base64 encoded object.
|
|
* @param base64 Encoded object
|
|
*/
|
|
exports.base64ToObj = function(base64) {
|
|
return JSON.parse(atob(base64));
|
|
}
|
|
|
|
function atob(base64) {
|
|
return Buffer.from(base64, 'base64').toString('binary')
|
|
}
|
|
|
|
function btoa(string) {
|
|
return Buffer.from(string).toString('base64')
|
|
} |