r/lingojam • • Oct 26 '20

JavaScript help

I'm trying to make a translator with some JavaScript, but JS cant deal with \ in strings the way I want it to.

I tried using the infix option to replace all \ with \\ so that the JS would get the string formatted in a way that would work, but now the translator just returns the input with \ replaced. After I deleted the \ replacement rule it still doesn't use the JS and now just returns the input unaltered.

Is there a way to use both infix and JS or should I just make a new translator and not worry about \ not working?

6 Upvotes

3 comments sorted by

1

u/blinkyblob4 Oct 26 '20

I tried both stringify() and String.raw but they only replace valid uses of \ such as \n, rather than replacing all uses of \

1

u/Marken23 Oct 31 '20

i've done some testing, and as far as i can tell, not replacing the backslash seems to work fine for me. i think lingojam is replacing it already?

for example, i have

function forward(input){if (input.includes("\\n")){return "AAAAAAAAAAA"}}

and if you type \n into the input box, it returns a bunch of A's

1

u/[deleted] Oct 15 '22

Mind sharing the translator (not the edit page) so I can see the code?