diff options
author | 2023-02-15 00:43:08 +0100 | |
---|---|---|
committer | 2023-02-15 00:45:20 +0100 | |
commit | 0ddf18f4b5347230759b9be800ef1541e150d9cf (patch) | |
tree | 8fe8e1562835d819c815826bb9e381b131ade275 | |
parent | 9634f5d9a83af03b408d80a700c6bde43866151f (diff) | |
download | it-tools-0ddf18f4b5347230759b9be800ef1541e150d9cf.tar.gz it-tools-0ddf18f4b5347230759b9be800ef1541e150d9cf.tar.zst it-tools-0ddf18f4b5347230759b9be800ef1541e150d9cf.zip |
feat(new-tool): String to NATO alphabet
-rw-r--r-- | src/tools/index.ts | 2 | ||||
-rw-r--r-- | src/tools/text-to-nato-alphabet/index.ts | 11 | ||||
-rw-r--r-- | src/tools/text-to-nato-alphabet/text-to-nato-alphabet.constants.ts | 28 | ||||
-rw-r--r-- | src/tools/text-to-nato-alphabet/text-to-nato-alphabet.service.ts | 19 | ||||
-rw-r--r-- | src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue | 30 |
5 files changed, 90 insertions, 0 deletions
diff --git a/src/tools/index.ts b/src/tools/index.ts index c7f0d98..6ad328f 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -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, ], }, { diff --git a/src/tools/text-to-nato-alphabet/index.ts b/src/tools/text-to-nato-alphabet/index.ts new file mode 100644 index 0000000..100476a --- /dev/null +++ b/src/tools/text-to-nato-alphabet/index.ts @@ -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, +}); diff --git a/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.constants.ts b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.constants.ts new file mode 100644 index 0000000..c6523d9 --- /dev/null +++ b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.constants.ts @@ -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', +]; diff --git a/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.service.ts b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.service.ts new file mode 100644 index 0000000..80290e8 --- /dev/null +++ b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.service.ts @@ -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(' '); +} diff --git a/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue new file mode 100644 index 0000000..fc3abb5 --- /dev/null +++ b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue @@ -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> |