feat(new-tool): String to NATO alphabet

This commit is contained in:
Corentin Thomasset 2023-02-15 00:43:08 +01:00
parent 9634f5d9a8
commit 0ddf18f4b5
No known key found for this signature in database
GPG Key ID: DBD997E935996158
5 changed files with 90 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as textToNatoAlphabet } from './text-to-nato-alphabet';
import { tool as slugifyString } from './slugify-string';
import { tool as keycodeInfo } from './keycode-info';
import { tool as jsonMinify } from './json-minify';
@ -55,6 +56,7 @@ export const toolsByCategory: ToolCategory[] = [
base64FileConverter,
colorConverter,
caseConverter,
textToNatoAlphabet,
],
},
{

View File

@ -0,0 +1,11 @@
import { Speakerphone } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Text to NATO alphabet',
path: '/text-to-nato-alphabet',
description: 'Transform text into NATO phonetic alphabet for oral transmission.',
keywords: ['string', 'nato', 'alphabet', 'phonetic', 'oral', 'transmission'],
component: () => import('./text-to-nato-alphabet.vue'),
icon: Speakerphone,
});

View File

@ -0,0 +1,28 @@
export const natoAlphabet = [
'Alpha',
'Bravo',
'Charlie',
'Delta',
'Echo',
'Foxtrot',
'Golf',
'Hotel',
'India',
'Juliet',
'Kilo',
'Lima',
'Mike',
'November',
'Oscar',
'Papa',
'Quebec',
'Romeo',
'Sierra',
'Tango',
'Uniform',
'Victor',
'Whiskey',
'X-ray',
'Yankee',
'Zulu',
];

View File

@ -0,0 +1,19 @@
import { natoAlphabet } from './text-to-nato-alphabet.constants';
export { textToNatoAlphabet };
function getLetterPositionInAlphabet({ letter }: { letter: string }) {
return letter.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0);
}
function textToNatoAlphabet({ text }: { text: string }) {
return text
.split('')
.map((character) => {
const alphabetIndex = getLetterPositionInAlphabet({ letter: character });
const natoWord = natoAlphabet[alphabetIndex];
return natoWord ?? character;
})
.join(' ');
}

View File

@ -0,0 +1,30 @@
<template>
<div>
<n-form-item label="Your text to convert to NATO phonetic alphabet">
<n-input v-model:value="input" placeholder="Put your text here..." clearable />
</n-form-item>
<n-space v-if="natoText" vertical>
<n-text>Your text in NATO phonetic alphabet</n-text>
<n-card>
{{ natoText }}
</n-card>
<n-space justify="center">
<n-button secondary autofocus @click="copy"> Copy NATO string </n-button>
</n-space>
</n-space>
</div>
</template>
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { computed, ref } from 'vue';
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
const input = ref('');
const natoText = computed(() => textToNatoAlphabet({ text: input.value }));
const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.' });
</script>
<style lang="less" scoped></style>