mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -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 { arabicToRoman } from './roman-numeral-converter.service';
|
||||
|
||||
describe('roman-numeral-converter', () => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
export const MIN_ARABIC_TO_ROMAN = 1;
|
||||
export const MAX_ARABIC_TO_ROMAN = 3999;
|
||||
export function arabicToRoman(num: number) {
|
||||
if (num < MIN_ARABIC_TO_ROMAN || num > MAX_ARABIC_TO_ROMAN) return '';
|
||||
if (num < MIN_ARABIC_TO_ROMAN || num > MAX_ARABIC_TO_ROMAN) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const lookup: { [key: string]: number } = {
|
||||
M: 1000,
|
||||
|
@ -28,7 +30,7 @@ export function arabicToRoman(num: number) {
|
|||
return roman;
|
||||
}
|
||||
|
||||
const ROMAN_NUMBER_REGEX = new RegExp(/^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/);
|
||||
const ROMAN_NUMBER_REGEX = /^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/;
|
||||
|
||||
export function isValidRomanNumber(romanNumber: string) {
|
||||
return ROMAN_NUMBER_REGEX.test(romanNumber);
|
||||
|
|
|
@ -1,3 +1,45 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import {
|
||||
MAX_ARABIC_TO_ROMAN,
|
||||
MIN_ARABIC_TO_ROMAN,
|
||||
arabicToRoman,
|
||||
isValidRomanNumber,
|
||||
romanToArabic,
|
||||
} from './roman-numeral-converter.service';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const inputNumeral = ref(42);
|
||||
const outputRoman = computed(() => arabicToRoman(inputNumeral.value));
|
||||
|
||||
const { attrs: validationNumeral } = useValidation({
|
||||
source: inputNumeral,
|
||||
rules: [
|
||||
{
|
||||
validator: value => value >= MIN_ARABIC_TO_ROMAN && value <= MAX_ARABIC_TO_ROMAN,
|
||||
message: `We can only convert numbers between ${MIN_ARABIC_TO_ROMAN.toLocaleString()} and ${MAX_ARABIC_TO_ROMAN.toLocaleString()}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const inputRoman = ref('XLII');
|
||||
const outputNumeral = computed(() => romanToArabic(inputRoman.value));
|
||||
|
||||
const validationRoman = useValidation({
|
||||
source: inputRoman,
|
||||
rules: [
|
||||
{
|
||||
validator: value => isValidRomanNumber(value),
|
||||
message: 'The input you entered is not a valid roman number',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const { copy: copyRoman } = useCopy({ source: outputRoman, text: 'Roman number copied to the clipboard' });
|
||||
const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic number copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Arabic to roman">
|
||||
|
@ -20,54 +62,14 @@
|
|||
<div class="result">
|
||||
{{ outputNumeral }}
|
||||
</div>
|
||||
<c-button :disabled="!validationRoman.isValid" @click="copyArabic"> Copy </c-button>
|
||||
<c-button :disabled="!validationRoman.isValid" @click="copyArabic">
|
||||
Copy
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import {
|
||||
arabicToRoman,
|
||||
romanToArabic,
|
||||
MAX_ARABIC_TO_ROMAN,
|
||||
MIN_ARABIC_TO_ROMAN,
|
||||
isValidRomanNumber,
|
||||
} from './roman-numeral-converter.service';
|
||||
|
||||
const inputNumeral = ref(42);
|
||||
const outputRoman = computed(() => arabicToRoman(inputNumeral.value));
|
||||
|
||||
const { attrs: validationNumeral } = useValidation({
|
||||
source: inputNumeral,
|
||||
rules: [
|
||||
{
|
||||
validator: (value) => value >= MIN_ARABIC_TO_ROMAN && value <= MAX_ARABIC_TO_ROMAN,
|
||||
message: `We can only convert numbers between ${MIN_ARABIC_TO_ROMAN.toLocaleString()} and ${MAX_ARABIC_TO_ROMAN.toLocaleString()}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const inputRoman = ref('XLII');
|
||||
const outputNumeral = computed(() => romanToArabic(inputRoman.value));
|
||||
|
||||
const validationRoman = useValidation({
|
||||
source: inputRoman,
|
||||
rules: [
|
||||
{
|
||||
validator: (value) => isValidRomanNumber(value),
|
||||
message: `The input you entered is not a valid roman number`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const { copy: copyRoman } = useCopy({ source: outputRoman, text: 'Roman number copied to the clipboard' });
|
||||
const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic number copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.result {
|
||||
font-size: 22px;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue