guigrpa / docx-templates

Template-based docx report creation
MIT License
882 stars 145 forks source link

Exec function with a subtract #358

Closed troylateral closed 5 months ago

troylateral commented 6 months ago

I am trying to add a percentage function to the template and to do so i need the function to include a subtract. I have narrowed the issue down to the subtract. +++EXEC subtract = (val1,val2) => (val1 – val2); +++

i get.... Error: Error executing command 'subtract= (val1,val2) => val1 – val2;': SyntaxError: Invalid or unexpected token at new t (errors.js:72:28) at jsSandbox.js:105:32 at jsSandbox.js:33:23 at Object.next (jsSandbox.js:14:53) at jsSandbox.js:8:71 at new Promise () at r (jsSandbox.js:4:12) at t.runUserJsAndGetRaw (jsSandbox.js:54:12) at processTemplate.js:532:54 at processTemplate.js:33:23

I would expect that the template runs without error and if i added... +++subtract(10, 2) +++ it would output... 8

I am using

jjhbw commented 5 months ago

Note that is not the character you think it is. Note that Word tends to replace characters, like ' and apparently - with fancier unicode stuff.

VSCode warns me as follows:

The character U+2013 "–" could be confused with the ASCII character U+002d "-", which is more common in source code.