How to use docx-templates - 2 common examples

To help you get started, we’ve selected a few docx-templates examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github guigrpa / docx-templates / packages / example-webpack / client / index.js View on Github external
async function onTemplateChosen() {
  console.log('Template chosen');

  // Read template
  const template = await readFileIntoArrayBuffer(this.files[0]);

  // Create report
  console.log('Creating report (can take some time) ...');
  const report = await createReport({
    template,
    data: async query => {
      const finalQuery = query || '{ viewer { login }}';
      const resp = await fetch('/github', {
        method: 'post',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ query: finalQuery }),
      });
      const js = await resp.json();
      console.log(js);
      return js;
    },
    additionalJsContext: {
      tile: async (z, x, y) => {
        const resp = await fetch(
          `http://tile.stamen.com/toner/${z}/${x}/${y}.png`
github guigrpa / docx-templates / packages / example-node / index.js View on Github external
require('isomorphic-fetch');
const qrcode = require('yaqrcode');
const createReport = require('docx-templates').default;

createReport({
  template: process.argv[2],
  output: process.argv.length > 3 ? process.argv[3] : null,
  data: query =>
    fetch('http://swapi.apis.guru', {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ query }),
    })
      .then(res => res.json())
      .then(res => res.data),
  additionalJsContext: {

docx-templates

Template-based docx report creation

MIT
Latest version published 7 months ago

Package Health Score

77 / 100
Full package analysis

Popular docx-templates functions