mirror of
https://github.com/Art051/it-tools.git
synced 2025-08-11 19:29:03 +00:00
feat(new-tool): String to NATO alphabet
This commit is contained in:
@@ -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(' ');
|
||||
}
|
||||
Reference in New Issue
Block a user