Action

Convert to NATO

Posted by omarshahine, Last update 2 days ago

This action converts the selected text—or the entire draft if no text is selected—into the NATO phonetic alphabet. Letters are translated into their phonetic equivalents (e.g., “Q” becomes “Quebec”), and numbers are preserved as-is. Each character is output on its own line for easy readability and use in aviation, military, or radio communication contexts.

Steps

  • script

    // Drafts Action Script: Convert Selection or Full Draft to NATO Phonetic Alphabet 
    
    // NATO phonetic map
    let natoMap = {
      'A': 'Alpha',    'B': 'Bravo',   'C': 'Charlie',
      'D': 'Delta',    'E': 'Echo',    'F': 'Foxtrot',
      'G': 'Golf',     'H': 'Hotel',   'I': 'India',
      'J': 'Juliett',  'K': 'Kilo',    'L': 'Lima',
      'M': 'Mike',     'N': 'November','O': 'Oscar',
      'P': 'Papa',     'Q': 'Quebec',  'R': 'Romeo',
      'S': 'Sierra',   'T': 'Tango',   'U': 'Uniform',
      'V': 'Victor',   'W': 'Whiskey', 'X': 'X-ray',
      'Y': 'Yankee',   'Z': 'Zulu',
      '0': '0', '1': '1', '2': '2', '3': '3', '4': '4',
      '5': '5', '6': '6', '7': '7', '8': '8', '9': '9'
    };
    
    // Get text and range
    let range = editor.getSelectedRange();
    let input = editor.getSelectedText();
    if (input.length === 0) {
      input = draft.content;
      range = [0, draft.content.length];
    }
    
    // Split lines and process each line separately
    let lines = input.split('\n');
    let convertedLines = lines.map(line => {
      let converted = [];
      for (let c of line.toUpperCase()) {
        if (natoMap[c]) {
          converted.push(natoMap[c]);
        }
      }
      return converted.join('-');
    });
    
    // Join lines with newlines
    let result = convertedLines.join('\n');
    
    // Replace the original text
    editor.setTextInRange(range[0], range[1], result);

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.