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, """); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue