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 {URIDecoder} from "./converter/uridecoder"; | ||||||
| import {URIComponentEncoder} from "./converter/uricomponentencoder"; | import {URIComponentEncoder} from "./converter/uricomponentencoder"; | ||||||
| import {URIComponentDecoder} from "./converter/uricomponentdecoder"; | 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() | @Injectable() | ||||||
| export class ConverterregistryService { | export class ConverterregistryService { | ||||||
|  | @ -35,6 +41,12 @@ export class ConverterregistryService { | ||||||
|         this.registerConverter(new URIDecoder()); |         this.registerConverter(new URIDecoder()); | ||||||
|         this.registerConverter(new URIComponentEncoder()); |         this.registerConverter(new URIComponentEncoder()); | ||||||
|         this.registerConverter(new URIComponentDecoder()); |         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 { |     private registerConverter(converter:Converter):void { | ||||||
|  |  | ||||||
							
								
								
									
										103
									
								
								dencode.js
									
										
									
									
									
								
							
							
						
						
									
										103
									
								
								dencode.js
									
										
									
									
									
								
							|  | @ -10,27 +10,6 @@ | ||||||
| 				}; | 				}; | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 		{ |  | ||||||
| 			"id": "decodehtmlentities", |  | ||||||
| 			"name": "Decode HTML entities", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": input |  | ||||||
| 							.replace(/\"\;/g, "\"") |  | ||||||
| 							.replace(/\>\;/g, ">") |  | ||||||
| 							.replace(/\<\;/g, "<") |  | ||||||
| 							.replace(/\&\;/g, "&") |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid HTML entity string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ | 		{ | ||||||
| 			"id": "decodequotedprintable", | 			"id": "decodequotedprintable", | ||||||
| 			"name": "Decode quoted printable", | 			"name": "Decode quoted printable", | ||||||
|  | @ -48,54 +27,6 @@ | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 		{ |  | ||||||
| 			"id": "hextodec", |  | ||||||
| 			"name": "Decode hex as decimal", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": parseInt(input, 16).toString(10) |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid number (integer) string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "bintodec", |  | ||||||
| 			"name": "Decode binary as decimal", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": parseInt(input, 2).toString(10) |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid number (integer) string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "encodehtmlentities", |  | ||||||
| 			"name": "Encode HTML entities", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				return { |  | ||||||
| 					"status": "OK", |  | ||||||
| 					"content": input |  | ||||||
| 						.replace(/\&/g, "&") |  | ||||||
| 						.replace(/\</g, "<") |  | ||||||
| 						.replace(/\>/g, ">") |  | ||||||
| 						.replace(/\"/g, """) |  | ||||||
| 				}; |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ | 		{ | ||||||
| 			"id": "encodequotedprintable", | 			"id": "encodequotedprintable", | ||||||
| 			"name": "Encode quoted printable", | 			"name": "Encode quoted printable", | ||||||
|  | @ -105,40 +36,6 @@ | ||||||
| 					"content": quotedPrintable.encode(utf8.encode(input)) | 					"content": quotedPrintable.encode(utf8.encode(input)) | ||||||
| 				}; | 				}; | ||||||
| 			} | 			} | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "dectohex", |  | ||||||
| 			"name": "Encode decimal as hex", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": parseInt(input).toString(16) |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid number (integer) string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "dectobin", |  | ||||||
| 			"name": "Encode decimal as binary", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": parseInt(input).toString(2) |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid number (integer) string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 	]; | 	]; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue