added 6 more converters:
- dec <-> bin - dec <-> hex - htmlentities de- and encode
This commit is contained in:
		
							parent
							
								
									5a1ca42f0d
								
							
						
					
					
						commit
						01df7ac29c
					
				
					 8 changed files with 106 additions and 103 deletions
				
			
		
							
								
								
									
										14
									
								
								app/converter/bintodecconverter.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/converter/bintodecconverter.ts
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								app/converter/dectobinconverter.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/converter/dectobinconverter.ts
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								app/converter/dectohexconverter.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/converter/dectohexconverter.ts
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								app/converter/hextodecconverter.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								app/converter/hextodecconverter.ts
									
										
									
									
									
										Normal 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/converter/htmlentitiesdecoder.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/converter/htmlentitiesdecoder.ts
									
										
									
									
									
										Normal 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(/\"\;/g, "\"") | ||||
|             .replace(/\>\;/g, ">") | ||||
|             .replace(/\<\;/g, "<") | ||||
|             .replace(/\&\;/g, "&"); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								app/converter/htmlentitiesencoder.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/converter/htmlentitiesencoder.ts
									
										
									
									
									
										Normal 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, "&") | ||||
|             .replace(/\</g, "<") | ||||
|             .replace(/\>/g, ">") | ||||
|             .replace(/\"/g, """); | ||||
|     } | ||||
| } | ||||
|  | @ -6,6 +6,12 @@ import {URIEncoder} from "./converter/uriencoder"; | |||
| import {URIDecoder} from "./converter/uridecoder"; | ||||
| import {URIComponentEncoder} from "./converter/uricomponentencoder"; | ||||
| import {URIComponentDecoder} from "./converter/uricomponentdecoder"; | ||||
| import {HTMLEntitiesEncoder} from "./converter/htmlentitiesencoder"; | ||||
| import {HTMLEntitiesDecoder} from "./converter/htmlentitiesdecoder"; | ||||
| import {DecToHexConverter} from "./converter/dectohexconverter"; | ||||
| import {HexToDecConverter} from "./converter/hextodecconverter"; | ||||
| import {DecToBinConverter} from "./converter/dectobinconverter"; | ||||
| import {BinToDecConverter} from "./converter/bintodecconverter"; | ||||
| 
 | ||||
| @Injectable() | ||||
| export class ConverterregistryService { | ||||
|  | @ -35,6 +41,12 @@ export class ConverterregistryService { | |||
|         this.registerConverter(new URIDecoder()); | ||||
|         this.registerConverter(new URIComponentEncoder()); | ||||
|         this.registerConverter(new URIComponentDecoder()); | ||||
|         this.registerConverter(new HTMLEntitiesEncoder()); | ||||
|         this.registerConverter(new HTMLEntitiesDecoder()); | ||||
|         this.registerConverter(new DecToHexConverter()); | ||||
|         this.registerConverter(new HexToDecConverter()); | ||||
|         this.registerConverter(new DecToBinConverter()); | ||||
|         this.registerConverter(new BinToDecConverter()); | ||||
|     } | ||||
| 
 | ||||
|     private registerConverter(converter:Converter):void { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue