Skip to content

Commit 0c63eb7

Browse files
committed
feat: handle prefix 0x, &H, \x and custom output prefix
1 parent 73e97f9 commit 0c63eb7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/tools/hex-file-converter/hex-file-converter.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fileName = ref('');
88
const fileExtension = ref('');
99
const hexInput = ref('');
1010
const base64Input = computed(() => {
11-
const hexString = hexInput.value?.replace(/[^\da-f]/gi, '');
11+
const hexString = hexInput.value?.replace(/^(?:0x|&H|\\x)/gi, '').replace(/[^\da-f]/gi, '');
1212
try {
1313
return `data:application/octet-stream;base64,${Buffer.from(hexString, 'hex').toString('base64')}`;
1414
}
@@ -51,11 +51,13 @@ async function ReadFileAsHex(file: File, separator: string = ' '): Promise<strin
5151
5252
const separator = useStorage('hex-converter:sep', ' ');
5353
const fileInput = ref() as Ref<File>;
54+
const prefix = useStorage('hex-converter:prefix', '');
5455
const fileHex = computedAsync(async () => {
5556
const file = fileInput.value;
5657
const sep = separator.value;
58+
const pref = prefix.value;
5759
58-
return await ReadFileAsHex(file, sep);
60+
return pref + await ReadFileAsHex(file, sep);
5961
});
6062
const { copy: copyFileHex } = useCopy({ source: fileHex, text: 'Hex string copied to the clipboard' });
6163
@@ -119,6 +121,14 @@ function onUpload(file: File) {
119121
mb-2
120122
/>
121123

124+
<c-input-text
125+
v-model:value="prefix"
126+
label="Prefix"
127+
label-position="left"
128+
placeholder="Enter a prefix (ie, 0x, &H or empty)"
129+
mb-2
130+
/>
131+
122132
<n-divider />
123133

124134
<n-form-item label="File in Hex">

0 commit comments

Comments
 (0)