From d4ce4d005843815da7f62a3fe9edecb57b1889d6 Mon Sep 17 00:00:00 2001 From: Myx Date: Fri, 24 Jan 2025 23:01:35 +0100 Subject: [PATCH] Simplify code --- .../oracle-guid-converter.component.html | 36 +++-------- .../oracle-guid-converter.component.ts | 64 ++++++++++++------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.html b/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.html index 7227230..734c7ed 100644 --- a/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.html +++ b/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.html @@ -1,27 +1,9 @@ -
-

GUID to Oracle RAW(16) Converter

- -
-

Convert GUID to RAW(16)

- - - - - -

RAW(16) Output:

-

{{ output }}

-
-
- -
-

Convert RAW(16) to GUID

- - - - - -

GUID Output:

-

{{ converted }}

-
-
-
\ No newline at end of file + + \ No newline at end of file diff --git a/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.ts b/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.ts index dc8f2e5..d6095c2 100644 --- a/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.ts +++ b/bytefy.webapp/src/tools/client-side/oracle-guid-converter/oracle-guid-converter.component.ts @@ -1,13 +1,15 @@ import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; +import { DualTextareaComponent } from '../../../app/shared/dual-textarea/dual-textarea.component'; @Component({ selector: 'app-oracle-guid-converter', standalone: true, imports: [ FormsModule, - CommonModule + CommonModule, + DualTextareaComponent ], templateUrl: './oracle-guid-converter.component.html', styleUrl: './oracle-guid-converter.component.scss' @@ -17,6 +19,22 @@ export class OracleGuidConverterComponent { rawOutput: string = ''; convertedGuid: string = ''; + onConvertToRaw(input: string): void { + if (this.isValidGuid(input)) { + this.rawOutput = this.guidToRaw(input); + } else { + this.rawOutput = 'Invalid GUID format'; + } + } + + onConvertToGuid(input: string): void { + if (this.isValidRaw(input)) { + this.convertedGuid = this.rawToGuid(input); + } else { + this.convertedGuid = 'Invalid RAW(16) format'; + } + } + private isValidGuid(guid: string): boolean { const guidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; return guidPattern.test(guid); @@ -34,13 +52,22 @@ export class OracleGuidConverterComponent { ); const reorderedBytes = [ - guidBytes[3], guidBytes[2], guidBytes[1], guidBytes[0], - guidBytes[5], guidBytes[4], - guidBytes[7], guidBytes[6], + guidBytes[3], + guidBytes[2], + guidBytes[1], + guidBytes[0], + guidBytes[5], + guidBytes[4], + guidBytes[7], + guidBytes[6], ...guidBytes.slice(8, 16) ]; - return reorderedBytes.map(b => b.toString(16).padStart(2, '0')).join('').toUpperCase(); + return reorderedBytes + .map(byte => byte.toString(16) + .padStart(2, '0')) + .join('') + .toUpperCase(); } private rawToGuid(raw: string): string { @@ -49,9 +76,14 @@ export class OracleGuidConverterComponent { ); const reorderedBytes = [ - rawBytes[3], rawBytes[2], rawBytes[1], rawBytes[0], - rawBytes[5], rawBytes[4], - rawBytes[7], rawBytes[6], + rawBytes[3], + rawBytes[2], + rawBytes[1], + rawBytes[0], + rawBytes[5], + rawBytes[4], + rawBytes[7], + rawBytes[6], ...rawBytes.slice(8, 16) ]; @@ -65,20 +97,4 @@ export class OracleGuidConverterComponent { hexArray.slice(10, 16).join('') ].join('-'); } - - onConvertToRaw(): void { - if (this.isValidGuid(this.guidInput)) { - this.rawOutput = this.guidToRaw(this.guidInput); - } else { - this.rawOutput = 'Invalid GUID format'; - } - } - - onConvertToGuid(): void { - if (this.isValidRaw(this.rawOutput)) { - this.convertedGuid = this.rawToGuid(this.rawOutput); - } else { - this.convertedGuid = 'Invalid RAW(16) format'; - } - } }