added 6 more converters:

- dec <-> bin
- dec <-> hex
- htmlentities de- and encode
This commit is contained in:
Manuel Friedli 2016-09-20 21:12:13 +02:00
parent 5a1ca42f0d
commit 01df7ac29c
8 changed files with 106 additions and 103 deletions

View file

@ -0,0 +1,14 @@
import {Converter} from "./converter";
export class BinToDecConverter implements Converter {
getDisplayname():string {
return "Convert binary to decimal";
}
getId():string {
return "bintodec";
}
convert(input:string):string {
return parseInt(input, 2).toString(10);
}
}

View file

@ -0,0 +1,14 @@
import {Converter} from "./converter";
export class DecToBinConverter implements Converter {
getDisplayname():string {
return "Convert decimal to binary";
}
getId():string {
return "dectobin";
}
convert(input:string):string {
return parseInt(input, 10).toString(2);
}
}

View file

@ -0,0 +1,14 @@
import {Converter} from "./converter";
export class DecToHexConverter implements Converter {
getDisplayname():string {
return "Convert decimal to heximal";
}
getId():string {
return "dectohex";
}
convert(input:string):string {
return parseInt(input, 10).toString(16);
}
}

View file

@ -0,0 +1,14 @@
import {Converter} from "./converter";
export class HexToDecConverter implements Converter {
getDisplayname():string {
return "Convert heximal to decimal";
}
getId():string {
return "hextodec";
}
convert(input:string):string {
return parseInt(input, 16).toString(10);
}
}

View file

@ -0,0 +1,19 @@
import {Converter} from "./converter";
export class HTMLEntitiesDecoder implements Converter {
getDisplayname():string {
return "Decode HTML entities";
}
getId():string {
return "decodehtmlentities";
}
convert(input:string):string {
return input
.replace(/\&quot\;/g, "\"")
.replace(/\&gt\;/g, ">")
.replace(/\&lt\;/g, "<")
.replace(/\&amp\;/g, "&");
}
}

View file

@ -0,0 +1,19 @@
import {Converter} from "./converter";
export class HTMLEntitiesEncoder implements Converter {
getDisplayname():string {
return "Encode HTML entities";
}
getId():string {
return "encodehtmlentities";
}
convert(input:string):string {
return input
.replace(/\&/g, "&amp;")
.replace(/\</g, "&lt;")
.replace(/\>/g, "&gt;")
.replace(/\"/g, "&quot;");
}
}