docx-templates
Advanced tools
Changelog
4.1.0 (2020-4-25)
failFast: false
to collect all errors in a template before failing. This allows for less cumbersome interactive correction of typos or other mistakes in template commands.Changelog
4.0.0 (2020-04-13)
Removed Flow and switched entire codebase over to TypeScript. In the process a few minor soundness issues were fixed.
Breaking change Removed dependency on Node filesystem APIs so the library no longer needs a separate node and browser entrypoint, simplifying maintenance and development. This has the following implications for the public API, justifying the version bump to 4.0.0:
You can no longer provide image data as a path, and need to provide an ArrayBuffer
or base64-encoded string instead.
You can no longer provide a template as a filesystem path, and you'll need to read it into a Buffer first.
Removed output: 'buffer'
argument. The output of createReport
is now always a Uint8Array
, unless the debug argument _probe
is specified.
The README and examples have also been updated to reflect the above changes.
Changelog
3.1.1 (2019-8-20)
END-IF/FOR
for a previous loop and IF/FOR
for a new one (#72).Changelog
3.1.0 (2019-8-20)
cmdDelimiter: ['{', '}']
(#66, #70).INS
(or =
) command (#70).Changelog
3.0.0 (2019-2-17)
replaceImages
, replaceImagesBase64
options (deprecated since v2.4.0). Please use the IMAGE
command instead.vm2
sandbox: replaced vm2Sandbox
option (which caused headaches for users in the browser) with runJs
, a custom hook for JS snippet execution. If you want to use vm2:import createReport from 'docx-templates';
import { VM, VMScript } from 'vm2';
createReport({
template: /* ... */,
data: /* ... */,
runJs: ({ sandbox }) => {
const script = new VMScript(
`
__result__ = eval(__code__);
`
).compile();
const vm2 = new VM({ sandbox });
vm2.run(script);
const { VMError, Buffer, ...modifiedSandbox } = vm2._context;
const result = modifiedSandbox.__result__;
return { modifiedSandbox, result };
}
})