NATO Phonetic Text Replacement

Trying to generate an action that replaces letters of text in the current draft and substitutes the NATO phonetic library. There is one part of this in the current Drafts library - but was trying to do this on a stand-alone with an array (as opposed to else… statements).

When I run this - it seems to be tripping up at the end - error message is d.update is not a function? But I use this same d.update() in a number of other drafts, so slightly confused.

Any help / pointers would be appreciated…

I skipped a whole bunch of letters in the array when I posted in the code below.

var d = encodeURIComponent(draft.content);
var lctext=d.toLowerCase();
var phonArray=new Array;
phonArray[" "]="[space]";

var transform="";

for(var i=0;i < lctext.length;i++)
			var thisChar=lctext.charAt(i);
			transform += phonArray[thisChar] + " ";
// update content
d.content = transform;


draft.content = transform;
1 Like

To address the error message, change “d” to “draft”. You have defined “d”as encoded text.

Thanks guys - was banging my head trying to fix this!

1 Like

You can simplify your lookup table:

const lookup = {
	a: 'Alpha',
	b: 'Bravo',
	c: 'Charlie',

If you loop over strings a lot, you can simplify it with:

for (const c of lctext)
    transform += lookup[c] + " ";
1 Like

Much cleaner - making those changes now!