mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 01:06:15 -04:00
chore(lint): switched to a better lint config
This commit is contained in:
parent
4d2b037dbe
commit
33c9b6643f
178 changed files with 4105 additions and 3371 deletions
|
@ -1,4 +1,4 @@
|
|||
import { expect, describe, it } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { convertBase } from './integer-base-converter.model';
|
||||
|
||||
describe('integer-base-converter', () => {
|
||||
|
|
|
@ -7,9 +7,9 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
|
|||
.reverse()
|
||||
.reduce((carry: number, digit: string, index: number) => {
|
||||
if (!fromRange.includes(digit)) {
|
||||
throw new Error('Invalid digit "' + digit + '" for base ' + fromBase + '.');
|
||||
throw new Error(`Invalid digit "${digit}" for base ${fromBase}.`);
|
||||
}
|
||||
return (carry += fromRange.indexOf(digit) * Math.pow(fromBase, index));
|
||||
return (carry += fromRange.indexOf(digit) * fromBase ** index);
|
||||
}, 0);
|
||||
let newValue = '';
|
||||
while (decValue > 0) {
|
||||
|
|
|
@ -1,56 +1,103 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
import { convertBase } from './integer-base-converter.model';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { getErrorMessageIfThrows } from '@/utils/error';
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
const inputProps = {
|
||||
'labelPosition': 'left',
|
||||
'labelWidth': '170px',
|
||||
'labelAlign': 'right',
|
||||
'readonly': true,
|
||||
'mb-2': '',
|
||||
} as const;
|
||||
|
||||
const input = ref('42');
|
||||
const inputBase = ref(10);
|
||||
const outputBase = ref(42);
|
||||
|
||||
function errorlessConvert(...args: Parameters<typeof convertBase>) {
|
||||
try {
|
||||
return convertBase(...args);
|
||||
}
|
||||
catch (err) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
const error = computed(() =>
|
||||
getErrorMessageIfThrows(() =>
|
||||
convertBase({ value: input.value, fromBase: inputBase.value, toBase: outputBase.value }),
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<div v-if="styleStore.isSmallScreen">
|
||||
<n-input-group>
|
||||
<n-input-group-label style="flex: 0 0 120px"> Input number: </n-input-group-label>
|
||||
<n-input-group-label style="flex: 0 0 120px">
|
||||
Input number:
|
||||
</n-input-group-label>
|
||||
<n-input v-model:value="input" w-full :status="error ? 'error' : undefined" />
|
||||
</n-input-group>
|
||||
<n-input-group>
|
||||
<n-input-group-label style="flex: 0 0 120px"> Input base: </n-input-group-label>
|
||||
<n-input-group-label style="flex: 0 0 120px">
|
||||
Input base:
|
||||
</n-input-group-label>
|
||||
<n-input-number v-model:value="inputBase" max="64" min="2" w-full />
|
||||
</n-input-group>
|
||||
</div>
|
||||
|
||||
<n-input-group v-else>
|
||||
<n-input-group-label style="flex: 0 0 120px"> Input number: </n-input-group-label>
|
||||
<n-input-group-label style="flex: 0 0 120px">
|
||||
Input number:
|
||||
</n-input-group-label>
|
||||
<n-input v-model:value="input" :status="error ? 'error' : undefined" />
|
||||
<n-input-group-label style="flex: 0 0 120px"> Input base: </n-input-group-label>
|
||||
<n-input-group-label style="flex: 0 0 120px">
|
||||
Input base:
|
||||
</n-input-group-label>
|
||||
<n-input-number v-model:value="inputBase" max="64" min="2" />
|
||||
</n-input-group>
|
||||
|
||||
<n-alert v-if="error" style="margin-top: 25px" type="error">{{ error }}</n-alert>
|
||||
<n-alert v-if="error" style="margin-top: 25px" type="error">
|
||||
{{ error }}
|
||||
</n-alert>
|
||||
<n-divider />
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
label="Binary (2)"
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 2 })"
|
||||
placeholder="Binary version will be here..."
|
||||
/>
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
label="Octal (8)"
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 8 })"
|
||||
placeholder="Octal version will be here..."
|
||||
/>
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
label="Decimal (10)"
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 10 })"
|
||||
placeholder="Decimal version will be here..."
|
||||
/>
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
label="Hexadecimal (16)"
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 16 })"
|
||||
placeholder="Hexadecimal version will be here..."
|
||||
/>
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
label="Base64 (64)"
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 64 })"
|
||||
|
@ -63,7 +110,7 @@
|
|||
<n-input-number v-model:value="outputBase" max="64" min="2" />
|
||||
</n-input-group>
|
||||
|
||||
<input-copyable
|
||||
<InputCopyable
|
||||
flex-1
|
||||
v-bind="inputProps"
|
||||
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: outputBase })"
|
||||
|
@ -74,42 +121,6 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { getErrorMessageIfThrows } from '@/utils/error';
|
||||
import { convertBase } from './integer-base-converter.model';
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
const inputProps = {
|
||||
labelPosition: 'left',
|
||||
labelWidth: '170px',
|
||||
labelAlign: 'right',
|
||||
readonly: true,
|
||||
'mb-2': '',
|
||||
} as const;
|
||||
|
||||
const input = ref('42');
|
||||
const inputBase = ref(10);
|
||||
const outputBase = ref(42);
|
||||
|
||||
function errorlessConvert(...args: Parameters<typeof convertBase>) {
|
||||
try {
|
||||
return convertBase(...args);
|
||||
} catch (err) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
const error = computed(() =>
|
||||
getErrorMessageIfThrows(() =>
|
||||
convertBase({ value: input.value, fromBase: inputBase.value, toBase: outputBase.value }),
|
||||
),
|
||||
);
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.n-input-group:not(:first-child) {
|
||||
margin-top: 5px;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue