guigrpa / docx-templates

Template-based docx report creation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exec function with a subtract

troylateral opened this issue · comments

commented

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

  • Brave 1.63.174
  • "react": "^17.0.2",
  • node v18.17.0

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.