From 1386babee5a4c32aab846b285ea66696732f80e6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 14 Mar 2017 23:36:39 +0100 Subject: [PATCH] Fixed conversions that depend on pure JS modules That is: - quoted printable - punycode - (utf8), dependency of quoted printable --- package.json | 20 ++++++++++---------- src/app/converter/punycodedecoder.ts | 3 +-- src/app/converter/punycodeencoder.ts | 3 +-- src/app/converter/quotedprintabledecoder.ts | 8 ++++---- src/app/converter/quotedprintableencoder.ts | 3 +-- src/app/converterregistry.service.ts | 16 ++++++++-------- src/app/nativelibrarywrapper.service.ts | 19 +++++++++---------- src/app/punycode.ts | 4 ++++ src/app/quotedprintable.ts | 4 ++++ src/app/utf8.ts | 4 ++++ src/vendor.ts | 16 ++++------------ 11 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 src/app/punycode.ts create mode 100644 src/app/quotedprintable.ts create mode 100644 src/app/utf8.ts diff --git a/package.json b/package.json index d63eb57..3caf487 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ "url": "https://gittr.ch/manuel/dencode.org.git" }, "dependencies": { - "@angular/common": "~2.4.0", - "@angular/compiler": "~2.4.0", - "@angular/core": "~2.4.0", - "@angular/forms": "~2.4.0", - "@angular/platform-browser": "~2.4.0", - "@angular/platform-browser-dynamic": "~2.4.0", + "@angular/common": "^2.4.0", + "@angular/compiler": "^2.4.0", + "@angular/core": "^2.4.0", + "@angular/forms": "^2.4.0", + "@angular/platform-browser": "^2.4.0", + "@angular/platform-browser-dynamic": "^2.4.0", "core-js": "^2.4.1", - "rxjs": "5.0.1", + "rxjs": "^5.0.1", "zone.js": "^0.7.4", "bootstrap": "^3.3.0", "quoted-printable": "^1.0.0", @@ -53,9 +53,9 @@ "raw-loader": "^0.5.1", "rimraf": "^2.5.2", "style-loader": "^0.13.1", - "typescript": "~2.0.10", - "webpack": "2.2.1", - "webpack-dev-server": "2.4.1", + "typescript": "^2.0.10", + "webpack": "^2.2.1", + "webpack-dev-server": "^2.4.1", "webpack-merge": "^3.0.0" }, "scripts": { diff --git a/src/app/converter/punycodedecoder.ts b/src/app/converter/punycodedecoder.ts index 15fc909..e61a8b4 100644 --- a/src/app/converter/punycodedecoder.ts +++ b/src/app/converter/punycodedecoder.ts @@ -15,7 +15,6 @@ export class PunycodeDecoder implements Converter { } convert(input: string): string { - // return this.nativeLibraryWrapperService.punycode.decode(input); - return ""; + return this.nativeLibraryWrapperService.punycode.decode(input); } } diff --git a/src/app/converter/punycodeencoder.ts b/src/app/converter/punycodeencoder.ts index 202d822..66345d6 100644 --- a/src/app/converter/punycodeencoder.ts +++ b/src/app/converter/punycodeencoder.ts @@ -15,7 +15,6 @@ export class PunycodeEncoder implements Converter { } convert(input: string): string { - // return this.nativeLibraryWrapperService.punycode.encode(input); - return ""; + return this.nativeLibraryWrapperService.punycode.encode(input); } } diff --git a/src/app/converter/quotedprintabledecoder.ts b/src/app/converter/quotedprintabledecoder.ts index bc1e857..d998038 100644 --- a/src/app/converter/quotedprintabledecoder.ts +++ b/src/app/converter/quotedprintabledecoder.ts @@ -14,10 +14,10 @@ export class QuotedPrintableDecoder implements Converter { } convert(input:string):string { - // try { - // return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); - // } catch (error) { + try { + return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); + } catch (error) { throw new Error("The input can not be interpreted as quoted-printable. May be corrupt?"); - // } + } } } diff --git a/src/app/converter/quotedprintableencoder.ts b/src/app/converter/quotedprintableencoder.ts index c97c9d7..048dbc6 100644 --- a/src/app/converter/quotedprintableencoder.ts +++ b/src/app/converter/quotedprintableencoder.ts @@ -14,7 +14,6 @@ export class QuotedPrintableEncoder implements Converter { } convert(input:string):string { - // return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input)); - return ""; + return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input)); } } diff --git a/src/app/converterregistry.service.ts b/src/app/converterregistry.service.ts index 1fea66c..af6e30b 100644 --- a/src/app/converterregistry.service.ts +++ b/src/app/converterregistry.service.ts @@ -12,11 +12,11 @@ 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"; +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"; +import {PunycodeEncoder} from "./converter/punycodeencoder"; +import {PunycodeDecoder} from "./converter/punycodedecoder"; @Injectable() export class ConverterRegistryService { @@ -48,14 +48,14 @@ export class ConverterRegistryService { this.registerConverter(new URIComponentDecoder()); this.registerConverter(new HTMLEntitiesEncoder()); this.registerConverter(new HTMLEntitiesDecoder()); - // this.registerConverter(new QuotedPrintableEncoder(this.wrapper)); - // this.registerConverter(new QuotedPrintableDecoder(this.wrapper)); + this.registerConverter(new QuotedPrintableEncoder(this.wrapper)); + this.registerConverter(new QuotedPrintableDecoder(this.wrapper)); this.registerConverter(new DecToHexConverter()); this.registerConverter(new HexToDecConverter()); this.registerConverter(new DecToBinConverter()); this.registerConverter(new BinToDecConverter()); - // this.registerConverter(new PunycodeEncoder(this.wrapper)); - // this.registerConverter(new PunycodeDecoder(this.wrapper)); + this.registerConverter(new PunycodeEncoder(this.wrapper)); + this.registerConverter(new PunycodeDecoder(this.wrapper)); } private registerConverter(converter:Converter):void { diff --git a/src/app/nativelibrarywrapper.service.ts b/src/app/nativelibrarywrapper.service.ts index 1ee1437..468b21d 100644 --- a/src/app/nativelibrarywrapper.service.ts +++ b/src/app/nativelibrarywrapper.service.ts @@ -1,18 +1,17 @@ import {Injectable} from "@angular/core"; - -declare var utf8:any; -declare var quotedPrintable:any; -declare var punycode:any; +import {Punycode} from "./punycode"; +import {Utf8} from "./utf8"; +import {QuotedPrintable} from "./quotedprintable"; @Injectable() export class NativeLibraryWrapperService { - // public utf8:any; - // public quotedPrintable:any; - // public punycode:any; + public utf8:Utf8; + public quotedPrintable:QuotedPrintable; + public punycode:Punycode; constructor() { - // this.utf8 = utf8; - // this.quotedPrintable = quotedPrintable; - // this.punycode = punycode; + this.utf8 = require("utf8"); + this.quotedPrintable = require("quoted-printable"); + this.punycode = require("punycode"); } } diff --git a/src/app/punycode.ts b/src/app/punycode.ts new file mode 100644 index 0000000..a141d24 --- /dev/null +++ b/src/app/punycode.ts @@ -0,0 +1,4 @@ +export interface Punycode { + encode(input:string):string; + decode(input:string):string; +} diff --git a/src/app/quotedprintable.ts b/src/app/quotedprintable.ts new file mode 100644 index 0000000..2cfb171 --- /dev/null +++ b/src/app/quotedprintable.ts @@ -0,0 +1,4 @@ +export interface QuotedPrintable { + encode(input:string):string; + decode(input:string):string; +} diff --git a/src/app/utf8.ts b/src/app/utf8.ts new file mode 100644 index 0000000..cce1ba8 --- /dev/null +++ b/src/app/utf8.ts @@ -0,0 +1,4 @@ +export interface Utf8 { + encode(input:any):string; + decode(input:string):any; +} diff --git a/src/vendor.ts b/src/vendor.ts index c7c86fe..bae9e0f 100644 --- a/src/vendor.ts +++ b/src/vendor.ts @@ -1,13 +1,5 @@ -import {Component, Injectable, NgModule, OnInit} from "@angular/core"; -import {BrowserModule} from "@angular/platform-browser"; -import {platformBrowserDynamic} from "@angular/platform-browser-dynamic"; -import {FormsModule} from "@angular/forms"; - +import "@angular/core"; +import "@angular/platform-browser"; +import "@angular/platform-browser-dynamic"; +import "@angular/forms"; import "rxjs"; - -import "utf8"; -import "quoted-printable"; -import "punycode"; -require("utf8"); -require("quoted-printable"); -require("punycode");