diff --git a/src/tools/index.ts b/src/tools/index.ts index c7f0d983..6ad328f8 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 00000000..100476a0 --- /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 00000000..c6523d9b --- /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 00000000..80290e83 --- /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 00000000..fc3abb5f --- /dev/null +++ b/src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue @@ -0,0 +1,30 @@ + + + + + + + + Your text in NATO phonetic alphabet + + {{ natoText }} + + + + Copy NATO string + + + + + + + +