From c8e2c421a62404a49c19fddd39d108ac8272b4e4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 27 Sep 2016 23:50:52 +0200 Subject: [PATCH] added punycode de- and encoder --- app/converter/punycodedecoder.ts | 20 ++++++++++++++++++++ app/converter/punycodeencoder.ts | 20 ++++++++++++++++++++ app/converterregistry.service.ts | 4 ++++ app/nativelibrarywrapper.service.ts | 5 ++++- index.html | 1 + package.json | 3 ++- 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 app/converter/punycodedecoder.ts create mode 100644 app/converter/punycodeencoder.ts diff --git a/app/converter/punycodedecoder.ts b/app/converter/punycodedecoder.ts new file mode 100644 index 0000000..e61a8b4 --- /dev/null +++ b/app/converter/punycodedecoder.ts @@ -0,0 +1,20 @@ +import {Converter} from "./converter"; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; + +export class PunycodeDecoder implements Converter { + + constructor(private nativeLibraryWrapperService: NativeLibraryWrapperService) { + } + + getDisplayname(): string { + return "Decode from punycode"; + } + + getId(): string { + return "decodepunycode"; + } + + convert(input: string): string { + return this.nativeLibraryWrapperService.punycode.decode(input); + } +} diff --git a/app/converter/punycodeencoder.ts b/app/converter/punycodeencoder.ts new file mode 100644 index 0000000..66345d6 --- /dev/null +++ b/app/converter/punycodeencoder.ts @@ -0,0 +1,20 @@ +import {Converter} from "./converter"; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; + +export class PunycodeEncoder implements Converter { + + constructor(private nativeLibraryWrapperService: NativeLibraryWrapperService) { + } + + getDisplayname(): string { + return "Encode as punycode"; + } + + getId(): string { + return "encodepunycode"; + } + + convert(input: string): string { + return this.nativeLibraryWrapperService.punycode.encode(input); + } +} diff --git a/app/converterregistry.service.ts b/app/converterregistry.service.ts index 48817b7..af6e30b 100644 --- a/app/converterregistry.service.ts +++ b/app/converterregistry.service.ts @@ -15,6 +15,8 @@ import {BinToDecConverter} from "./converter/bintodecconverter"; import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder"; import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; +import {PunycodeEncoder} from "./converter/punycodeencoder"; +import {PunycodeDecoder} from "./converter/punycodedecoder"; @Injectable() export class ConverterRegistryService { @@ -52,6 +54,8 @@ export class ConverterRegistryService { this.registerConverter(new HexToDecConverter()); this.registerConverter(new DecToBinConverter()); this.registerConverter(new BinToDecConverter()); + this.registerConverter(new PunycodeEncoder(this.wrapper)); + this.registerConverter(new PunycodeDecoder(this.wrapper)); } private registerConverter(converter:Converter):void { diff --git a/app/nativelibrarywrapper.service.ts b/app/nativelibrarywrapper.service.ts index 6a7d840..2a905b9 100644 --- a/app/nativelibrarywrapper.service.ts +++ b/app/nativelibrarywrapper.service.ts @@ -2,14 +2,17 @@ import {Injectable} from "@angular/core"; declare var utf8:any; declare var quotedPrintable:any; +declare var punycode:any; @Injectable() export class NativeLibraryWrapperService { public utf8:any; public quotedPrintable:any; + public punycode:any; constructor() { this.utf8 = utf8; this.quotedPrintable = quotedPrintable; + this.punycode = punycode; } -} \ No newline at end of file +} diff --git a/index.html b/index.html index 0481aa4..f12af09 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@ +