59 lines
2.9 KiB
JavaScript
59 lines
2.9 KiB
JavaScript
"use strict";
|
|
const plugins = require("./smartstring.plugins");
|
|
/**
|
|
* handle base64 strings
|
|
*/
|
|
class Base64 {
|
|
constructor(inputStringArg, typeArg) {
|
|
switch (typeArg) {
|
|
case 'string':
|
|
this.refString = inputStringArg;
|
|
break;
|
|
case 'base64':
|
|
this.refString = exports.base64.decode(inputStringArg);
|
|
break;
|
|
case 'base64uri':
|
|
this.refString = exports.base64.decode(inputStringArg);
|
|
}
|
|
}
|
|
/**
|
|
* the simple string (unencoded)
|
|
*/
|
|
get simpleString() {
|
|
return this.refString;
|
|
}
|
|
/**
|
|
* the base64 encoded version of the original string
|
|
*/
|
|
get base64String() {
|
|
return exports.base64.encode(this.refString);
|
|
}
|
|
/**
|
|
* the base64uri encoded version of the original string
|
|
*/
|
|
get base64UriString() {
|
|
return exports.base64.encodeUri(this.refString);
|
|
}
|
|
}
|
|
exports.Base64 = Base64;
|
|
exports.base64 = {
|
|
/**
|
|
* encodes the string
|
|
*/
|
|
encode: (stringArg) => {
|
|
return plugins.jsBase64.encode(stringArg);
|
|
},
|
|
/**
|
|
* encodes a stringArg to base64 uri style
|
|
*/
|
|
encodeUri: (stringArg) => {
|
|
return plugins.jsBase64.encodeURI(stringArg);
|
|
},
|
|
/**
|
|
* decodes a base64 encoded string
|
|
*/
|
|
decode: (stringArg) => {
|
|
return plugins.jsBase64.decode(stringArg);
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuYmFzZTY0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuYmFzZTY0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxpREFBZ0Q7QUFPaEQ7O0dBRUc7QUFDSDtJQUVJLFlBQVksY0FBYyxFQUFFLE9BQXFCO1FBQzdDLE1BQU0sQ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