Merge branch 'feat/smart-raw-errors-conv' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 21:28:23 +01:00
commit 8fc2d72618
6 files changed
+87 -2

No files matched your search

+2 -2
View File
@@ -5148,7 +5148,7 @@ packages:
/@types/lodash-es@4.17.10:
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
dependencies:
'@types/lodash': 4.14.192
'@types/lodash': 4.14.200
dev: false
/@types/lodash.defaultsdeep@4.6.9:
@@ -5171,6 +5171,7 @@ packages:
/@types/lodash@4.14.192:
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
dev: true
/@types/lodash@4.14.200:
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
@@ -10135,7 +10136,6 @@ packages:
/jsesc@2.5.2:
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
engines: {node: '>=4'}
hasBin: true
/jsesc@3.0.2:
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
+2
View File
@@ -34,6 +34,7 @@ import { tool as passphraseGenerator } from './passphrase-generator';
import { tool as pinCodeGenerator } from './pin-code-generator';
import { tool as punycodeConverter } from './punycode-converter';
import { tool as rsaEcdsaSigning } from './rsa-ecdsa-signing';
import { tool as smartRawConverter } from './smart-raw-converter';
import { tool as cssXpathConverter } from './css-xpath-converter';
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -232,6 +233,7 @@ export const toolsByCategory: ToolCategory[] = [
jsonToGo,
markdownTocGenerator,
rmbNumbers,
smartRawConverter,
],
},
{
+12
View 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,
});
});
});
});
@@ -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,
};
}
@@ -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>