2016-10-31 23:22:38 +00:00
|
|
|
"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':
|
2016-11-01 17:59:43 +00:00
|
|
|
this.refString = exports.base64.decode(inputStringArg);
|
2016-10-31 23:22:38 +00:00
|
|
|
break;
|
|
|
|
case 'base64uri':
|
2016-11-01 17:59:43 +00:00
|
|
|
this.refString = exports.base64.decode(inputStringArg);
|
2016-10-31 23:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* the simple string (unencoded)
|
|
|
|
*/
|
|
|
|
get simpleString() {
|
|
|
|
return this.refString;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* the base64 encoded version of the original string
|
|
|
|
*/
|
|
|
|
get base64String() {
|
2016-11-01 17:59:43 +00:00
|
|
|
return exports.base64.encode(this.refString);
|
2016-10-31 23:22:38 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* the base64uri encoded version of the original string
|
|
|
|
*/
|
2016-11-02 21:55:17 +00:00
|
|
|
get base64UriString() {
|
2016-11-01 17:59:43 +00:00
|
|
|
return exports.base64.encodeUri(this.refString);
|
2016-10-31 23:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.Base64 = Base64;
|
2016-11-01 17:59:43 +00:00
|
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuYmFzZTY0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuYmFzZTY0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxpREFBZ0Q7QUFPaEQ7O0dBRUc7QUFDSDtJQUVJLFlBQVksY0FBYyxFQUFFLE9BQXFCO1FBQzdDLE1BQU0sQ0FBQyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7WUFDZCxLQUFLLFFBQVE7Z0JBQ1QsSUFBSSxDQUFDLFNBQVMsR0FBRyxjQUFjLENBQUE7Z0JBQy9CLEtBQUssQ0FBQTtZQUNULEtBQUssUUFBUTtnQkFDVCxJQUFJLENBQUMsU0FBUyxHQUFHLGNBQU0sQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLENBQUE7Z0JBQzlDLEtBQUssQ0FBQTtZQUNULEtBQUssV0FBVztnQkFDWixJQUFJLENBQUMsU0FBUyxHQUFHLGNBQU0sQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLENBQUE7UUFDdEQsQ0FBQztJQUNMLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUksWUFBWTtRQUNaLE1BQU0sQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFBO0lBQ3pCLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUksWUFBWTtRQUNaLE1BQU0sQ0FBQyxjQUFNLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUN4QyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLGVBQWU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