mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 13:34:04 +03:00
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:
commit
8fc2d72618
6 files changed
+87
-2
No files matched your search
Generated
+2
-2
@@ -5148,7 +5148,7 @@ packages:
|
|||||||
/@types/lodash-es@4.17.10:
|
/@types/lodash-es@4.17.10:
|
||||||
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/lodash': 4.14.192
|
'@types/lodash': 4.14.200
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/lodash.defaultsdeep@4.6.9:
|
/@types/lodash.defaultsdeep@4.6.9:
|
||||||
@@ -5171,6 +5171,7 @@ packages:
|
|||||||
|
|
||||||
/@types/lodash@4.14.192:
|
/@types/lodash@4.14.192:
|
||||||
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/lodash@4.14.200:
|
/@types/lodash@4.14.200:
|
||||||
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
||||||
@@ -10135,7 +10136,6 @@ packages:
|
|||||||
/jsesc@2.5.2:
|
/jsesc@2.5.2:
|
||||||
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
|
resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
/jsesc@3.0.2:
|
/jsesc@3.0.2:
|
||||||
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
|
resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import { tool as passphraseGenerator } from './passphrase-generator';
|
|||||||
import { tool as pinCodeGenerator } from './pin-code-generator';
|
import { tool as pinCodeGenerator } from './pin-code-generator';
|
||||||
import { tool as punycodeConverter } from './punycode-converter';
|
import { tool as punycodeConverter } from './punycode-converter';
|
||||||
import { tool as rsaEcdsaSigning } from './rsa-ecdsa-signing';
|
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 cssXpathConverter } from './css-xpath-converter';
|
||||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||||
@@ -232,6 +233,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
jsonToGo,
|
jsonToGo,
|
||||||
markdownTocGenerator,
|
markdownTocGenerator,
|
||||||
rmbNumbers,
|
rmbNumbers,
|
||||||
|
smartRawConverter,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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>
|
||||||
Reference in new issue
Block a user