Merge 6b660bf436 into 07eea0f484
				
					
				
			This commit is contained in:
		
						commit
						8b93147552
					
				
							
								
								
									
										4
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -130,7 +130,6 @@ declare module '@vue/runtime-core' { | |||||||
|     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] |     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] | ||||||
|     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] |     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] | ||||||
|     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] |     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] | ||||||
|     NCheckbox: typeof import('naive-ui')['NCheckbox'] |  | ||||||
|     NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] |     NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] | ||||||
|     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] |     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] | ||||||
|     NDivider: typeof import('naive-ui')['NDivider'] |     NDivider: typeof import('naive-ui')['NDivider'] | ||||||
| @ -141,8 +140,6 @@ declare module '@vue/runtime-core' { | |||||||
|     NLayout: typeof import('naive-ui')['NLayout'] |     NLayout: typeof import('naive-ui')['NLayout'] | ||||||
|     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] |     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] | ||||||
|     NMenu: typeof import('naive-ui')['NMenu'] |     NMenu: typeof import('naive-ui')['NMenu'] | ||||||
|     NSpace: typeof import('naive-ui')['NSpace'] |  | ||||||
|     NTable: typeof import('naive-ui')['NTable'] |  | ||||||
|     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] |     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] | ||||||
|     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] |     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] | ||||||
|     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] |     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] | ||||||
| @ -162,6 +159,7 @@ declare module '@vue/runtime-core' { | |||||||
|     RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default'] |     RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default'] | ||||||
|     SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default'] |     SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default'] | ||||||
|     SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default'] |     SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default'] | ||||||
|  |     SmartRawConverter: typeof import('./src/tools/smart-raw-converter/smart-raw-converter.vue')['default'] | ||||||
|     SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default'] |     SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default'] | ||||||
|     SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default'] |     SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default'] | ||||||
|     StringObfuscator: typeof import('./src/tools/string-obfuscator/string-obfuscator.vue')['default'] |     StringObfuscator: typeof import('./src/tools/string-obfuscator/string-obfuscator.vue')['default'] | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter'; | |||||||
| import { tool as base64StringConverter } from './base64-string-converter'; | import { tool as base64StringConverter } from './base64-string-converter'; | ||||||
| import { tool as basicAuthGenerator } from './basic-auth-generator'; | import { tool as basicAuthGenerator } from './basic-auth-generator'; | ||||||
| import { tool as emailNormalizer } from './email-normalizer'; | import { tool as emailNormalizer } from './email-normalizer'; | ||||||
|  | import { tool as smartRawConverter } from './smart-raw-converter'; | ||||||
| 
 | 
 | ||||||
| import { tool as asciiTextDrawer } from './ascii-text-drawer'; | import { tool as asciiTextDrawer } from './ascii-text-drawer'; | ||||||
| 
 | 
 | ||||||
| @ -115,6 +116,7 @@ export const toolsByCategory: ToolCategory[] = [ | |||||||
|       tomlToYaml, |       tomlToYaml, | ||||||
|       xmlToJson, |       xmlToJson, | ||||||
|       jsonToXml, |       jsonToXml, | ||||||
|  |       smartRawConverter, | ||||||
|       markdownToHtml, |       markdownToHtml, | ||||||
|     ], |     ], | ||||||
|   }, |   }, | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								src/tools/smart-raw-converter/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/smart-raw-converter/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { Disc } from '@vicons/tabler'; | ||||||
|  | import { defineTool } from '../tool'; | ||||||
|  | 
 | ||||||
|  | export const tool = defineTool({ | ||||||
|  |   name: 'SMART Raw Converter', | ||||||
|  |   path: '/smart-raw-converter', | ||||||
|  |   description: 'Convert SMART Raw values to human readable', | ||||||
|  |   keywords: ['smart', 'raw', 'converter'], | ||||||
|  |   component: () => import('./smart-raw-converter.vue'), | ||||||
|  |   icon: Disc, | ||||||
|  |   createdAt: new Date('2024-07-14'), | ||||||
|  | }); | ||||||
| @ -0,0 +1,13 @@ | |||||||
|  | import { describe, expect, it } from 'vitest'; | ||||||
|  | import { getSmartValue } from './smart-raw-converter.service'; | ||||||
|  | 
 | ||||||
|  | describe('smart-raw-converter', () => { | ||||||
|  |   describe('getSmartValue', () => { | ||||||
|  |     it('to return correct values', () => { | ||||||
|  |       expect(getSmartValue(8590065666)).to.deep.eq({ | ||||||
|  |         errors: 2, | ||||||
|  |         operations: 131074, | ||||||
|  |       }); | ||||||
|  |     }); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										14
									
								
								src/tools/smart-raw-converter/smart-raw-converter.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/tools/smart-raw-converter/smart-raw-converter.service.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | export function getSmartValue(raw: number) { | ||||||
|  |   const n = raw.toString(2); | ||||||
|  |   let bin = ''; | ||||||
|  |   for (let i = 0; i < 64 - n.length; ++i) { | ||||||
|  |     bin += '0'; | ||||||
|  |   } | ||||||
|  |   bin += n; | ||||||
|  |   const lo = Number.parseInt(bin.slice(0, 32), 2); | ||||||
|  |   const hi = Number.parseInt(bin.slice(32), 2); | ||||||
|  |   return { | ||||||
|  |     errors: lo, | ||||||
|  |     operations: hi, | ||||||
|  |   }; | ||||||
|  | } | ||||||
							
								
								
									
										44
									
								
								src/tools/smart-raw-converter/smart-raw-converter.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/tools/smart-raw-converter/smart-raw-converter.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | <script setup lang="ts"> | ||||||
|  | import { getSmartValue } from './smart-raw-converter.service'; | ||||||
|  | import { useValidation } from '@/composable/validation'; | ||||||
|  | 
 | ||||||
|  | const inputRegex = /^(?:0x(?<hex>[a-f\d]+)|(?<dec>\d+))$/i; | ||||||
|  | const rawValue = ref('0xFE45E3'); | ||||||
|  | const rawValueValidation = useValidation({ | ||||||
|  |   source: rawValue, | ||||||
|  |   rules: [ | ||||||
|  |     { | ||||||
|  |       validator: (v) => { | ||||||
|  |         return inputRegex.test(v?.trim()); | ||||||
|  |       }, | ||||||
|  |       message: 'Smart Raw Value must be decimal or "0x" hexadecimal.', | ||||||
|  |     }, | ||||||
|  |   ], | ||||||
|  | }); | ||||||
|  | const smartDecodedValue = computed(() => { | ||||||
|  |   if (!rawValueValidation.isValid) { | ||||||
|  |     return null; | ||||||
|  |   } | ||||||
|  |   const inputMatch = rawValue.value.match(inputRegex); | ||||||
|  |   const rawValueInt = inputMatch?.groups?.hex | ||||||
|  |     ? Number.parseInt(inputMatch?.groups?.hex, 16) | ||||||
|  |     : Number.parseInt(inputMatch?.groups?.dec || '0', 10); | ||||||
|  |   return getSmartValue(rawValueInt); | ||||||
|  | }); | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <div style="max-width: 600px;"> | ||||||
|  |     <c-input-text | ||||||
|  |       v-model:value="rawValue" | ||||||
|  |       label="Smart Raw Value" | ||||||
|  |       placeholder="Put your Smart Raw Value (decimal or '0x' hexa)" | ||||||
|  |       :validation="rawValueValidation" | ||||||
|  |       mb-2 | ||||||
|  |     /> | ||||||
|  | 
 | ||||||
|  |     <c-card v-if="smartDecodedValue" title="Decoded"> | ||||||
|  |       <strong>{{ smartDecodedValue.errors }}</strong> in {{ smartDecodedValue.operations }} operations | ||||||
|  |     </c-card> | ||||||
|  |   </div> | ||||||
|  | </template> | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user