added QuotedPrintable{De,En}coder.

This commit is contained in:
Manuel Friedli 2016-09-20 22:02:38 +02:00
parent 01df7ac29c
commit 02735ff4a1
7 changed files with 72 additions and 28 deletions

View file

@ -32,6 +32,9 @@ export class AppComponent extends OnInit {
try {
result = converter.convert(content);
} catch (error) {
if (typeof console === "object" && typeof console.log === "function") {
console.log(error);
}
result = null;
}
if (result === null) {

View file

@ -0,0 +1,42 @@
import {Converter} from "./converter";
declare var window:any;
export class QuotedPrintableDecoder implements Converter {
private utf8:any = window.utf8;
private quotedPrintable:any = window.quotedPrintable;
getDisplayname():string {
return "Decode quoted printable";
}
getId():string {
return "decodequotedprintable";
}
convert(input:string):string {
return this.utf8.decode(this.quotedPrintable.decode(input));
}
}
/*
{
"id": "decodequotedprintable",
"name": "Decode quoted printable",
"convert": function (input) {
try {
return {
"status": "OK",
"content": utf8.decode(quotedPrintable.decode(input))
};
} catch (exception) {
return {
"status": "ERROR",
"content": "Invalid quoted printable string."
};
}
}
},
*/

View file

@ -0,0 +1,18 @@
import {Converter} from "./converter";
declare var window:any;
export class QuotedPrintableEncoder implements Converter {
getDisplayname():string {
return "Encode quoted printable";
}
getId():string {
return "encodequotedprintable";
}
convert(input:string):string {
return window.quotedPrintable.encode(window.utf8.encode(input));
}
}

View file

@ -12,6 +12,8 @@ import {DecToHexConverter} from "./converter/dectohexconverter";
import {HexToDecConverter} from "./converter/hextodecconverter";
import {DecToBinConverter} from "./converter/dectobinconverter";
import {BinToDecConverter} from "./converter/bintodecconverter";
import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder";
import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder";
@Injectable()
export class ConverterregistryService {
@ -47,6 +49,8 @@ export class ConverterregistryService {
this.registerConverter(new HexToDecConverter());
this.registerConverter(new DecToBinConverter());
this.registerConverter(new BinToDecConverter());
this.registerConverter(new QuotedPrintableEncoder());
this.registerConverter(new QuotedPrintableDecoder());
}
private registerConverter(converter:Converter):void {

View file

@ -9,33 +9,6 @@
"content": ""
};
}
},
{
"id": "decodequotedprintable",
"name": "Decode quoted printable",
"convert": function (input) {
try {
return {
"status": "OK",
"content": utf8.decode(quotedPrintable.decode(input))
};
} catch (exception) {
return {
"status": "ERROR",
"content": "Invalid quoted printable string."
};
}
}
},
{
"id": "encodequotedprintable",
"name": "Encode quoted printable",
"convert": function (input) {
return {
"status": "OK",
"content": quotedPrintable.encode(utf8.encode(input))
};
}
}
];

View file

@ -9,6 +9,8 @@
<script type="text/javascript" src="node_modules/zone.js/dist/zone.js"></script>
<script type="text/javascript" src="node_modules/reflect-metadata/Reflect.js"></script>
<script type="text/javascript" src="node_modules/systemjs/dist/system.src.js"></script>
<script type="text/javascript" src="node_modules/utf8/utf8.js"></script>
<script type="text/javascript" src="node_modules/quoted-printable/quoted-printable.js"></script>
<script type="text/javascript" src="systemjs.config.js"></script>
<script type="text/javascript">

View file

@ -25,7 +25,9 @@
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "^0.19.27",
"zone.js": "^0.6.12"
"zone.js": "^0.6.12",
"quoted-printable": "^1.0.0",
"utf8": "^2.1.1"
},
"devDependencies": {
"concurrently": "^2.2.0",