diff --git a/app/app.component.ts b/app/app.component.ts index 2c8f5a1..7cde15f 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -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) { diff --git a/app/converter/quotedprintabledecoder.ts b/app/converter/quotedprintabledecoder.ts new file mode 100644 index 0000000..834b048 --- /dev/null +++ b/app/converter/quotedprintabledecoder.ts @@ -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." + }; + } + } + }, + + */ \ No newline at end of file diff --git a/app/converter/quotedprintableencoder.ts b/app/converter/quotedprintableencoder.ts new file mode 100644 index 0000000..9276161 --- /dev/null +++ b/app/converter/quotedprintableencoder.ts @@ -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)); + } +} diff --git a/app/converterregistry.service.ts b/app/converterregistry.service.ts index d1212b3..a3fa684 100644 --- a/app/converterregistry.service.ts +++ b/app/converterregistry.service.ts @@ -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 { diff --git a/dencode.js b/dencode.js index 73607b3..2cce239 100644 --- a/dencode.js +++ b/dencode.js @@ -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)) - }; - } } ]; diff --git a/index.html b/index.html index 5f08ba3..3ecebde 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,8 @@ + +