diff --git a/app/converter/uricomponentdecoder.ts b/app/converter/uricomponentdecoder.ts new file mode 100644 index 0000000..ee96e28 --- /dev/null +++ b/app/converter/uricomponentdecoder.ts @@ -0,0 +1,15 @@ +import {Converter} from "./converter"; + +export class URIComponentDecoder implements Converter { + getDisplayname():string { + return "Decode URI component"; + } + + getId():string { + return "uricomponentdecode"; + } + + convert(input:string):string { + return decodeURIComponent(input); + } +} diff --git a/app/converter/uricomponentencoder.ts b/app/converter/uricomponentencoder.ts new file mode 100644 index 0000000..b4fb478 --- /dev/null +++ b/app/converter/uricomponentencoder.ts @@ -0,0 +1,17 @@ +import {Converter} from "./converter"; + +export class URIComponentEncoder implements Converter { + getDisplayname():string { + return "Encode URI component"; + } + + getId():string { + return "uricomponentencode"; + } + + convert(input:string):string { + return encodeURIComponent(input).replace(/[!'()*]/g, function (c) { + return '%' + c.charCodeAt(0).toString(16); + }); + } +} diff --git a/app/converter/uridecoder.ts b/app/converter/uridecoder.ts new file mode 100644 index 0000000..1949940 --- /dev/null +++ b/app/converter/uridecoder.ts @@ -0,0 +1,15 @@ +import {Converter} from "./converter"; + +export class URIDecoder implements Converter { + getDisplayname():string { + return "Decode URI"; + } + + getId():string { + return "uridecode"; + } + + convert(input:string):string { + return decodeURI(input); + } +} diff --git a/app/converter/uriencoder.ts b/app/converter/uriencoder.ts new file mode 100644 index 0000000..b56c747 --- /dev/null +++ b/app/converter/uriencoder.ts @@ -0,0 +1,15 @@ +import {Converter} from "./converter"; + +export class URIEncoder implements Converter { + getDisplayname():string { + return "Encode URI"; + } + + getId():string { + return "uriencode"; + } + + convert(input:string):string { + return encodeURI(input).replace(/%5B/g, '[').replace(/%5D/g, ']'); + } +} diff --git a/app/converterregistry.service.ts b/app/converterregistry.service.ts index 8bd7f7f..7b89416 100644 --- a/app/converterregistry.service.ts +++ b/app/converterregistry.service.ts @@ -2,6 +2,10 @@ import {Injectable} from "@angular/core"; import {Converter} from "./converter/converter"; import {Base64Encoder} from "./converter/base64encoder"; import {Base64Decoder} from "./converter/base64decoder"; +import {URIEncoder} from "./converter/uriencoder"; +import {URIDecoder} from "./converter/uridecoder"; +import {URIComponentEncoder} from "./converter/uricomponentencoder"; +import {URIComponentDecoder} from "./converter/uricomponentdecoder"; @Injectable() export class ConverterregistryService { @@ -27,6 +31,10 @@ export class ConverterregistryService { private init():void { this.registerConverter(new Base64Encoder()); this.registerConverter(new Base64Decoder()); + this.registerConverter(new URIEncoder()); + this.registerConverter(new URIDecoder()); + this.registerConverter(new URIComponentEncoder()); + this.registerConverter(new URIComponentDecoder()); } private registerConverter(converter:Converter):void { diff --git a/dencode.js b/dencode.js index a076423..7c73642 100644 --- a/dencode.js +++ b/dencode.js @@ -10,57 +10,6 @@ }; } }, - { - "id": "base64decode", - "name": "Decode Base64", - "convert": function (input) { - try { - return { - "status": "OK", - "content": atob(input) - }; - } catch (exception) { - return { - "status": "ERROR", - "content": "Invalid base64 input string." - }; - } - } - }, - { - "id": "decodeuri", - "name": "Decode URI", - "convert": function (input) { - try { - return { - "status": "OK", - "content": decodeURI(input) - }; - } catch (exception) { - return { - "status": "ERROR", - "content": "Invalid URI input string." - }; - } - } - }, - { - "id": "decodeuricomponent", - "name": "Decode URI component", - "convert": function (input) { - try { - return { - "status": "OK", - "content": decodeURIComponent(input) - }; - } catch (exception) { - return { - "status": "ERROR", - "content": "Invalid URI component input string." - }; - } - } - }, { "id": "decodehtmlentities", "name": "Decode HTML entities", @@ -133,38 +82,6 @@ } } }, - { - "id": "base64encode", - "name": "Encode Base64", - "convert": function (input) { - return { - "status": "OK", - "content": btoa(input) - }; - } - }, - { - "id": "encodeuri", - "name": "Encode URI", - "convert": function (input) { - return { - "status": "OK", - "content": encodeURI(input).replace(/%5B/g, '[').replace(/%5D/g, ']') - }; - } - }, - { - "id": "encodeuricomponent", - "name": "Encode URI component", - "convert": function (input) { - return { - "status": "OK", - "content": encodeURIComponent(input).replace(/[!'()*]/g, function(c) { - return '%' + c.charCodeAt(0).toString(16); - }) - }; - } - }, { "id": "encodehtmlentities", "name": "Encode HTML entities",