npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spfxappdev/docxmerger

v1.0.2

Published

This is a merge/copy of the [docx-merger package](https://github.com/apurvaojas/docx-merger). But since the package has not been updated for more than 5 years and the package has some bugs regarding "corrupt" Word files, I created my own package. This pac

Downloads

35

Readme

@spfxappdev/docxmerger

This is a merge/copy of the docx-merger package. But since the package has not been updated for more than 5 years and the package has some bugs regarding "corrupt" Word files, I created my own package. This package also has TypeScript support and the API has been changed a bit. The JSZip npm package has also been updated. This package (unpacked) is about 1.5MB smaller than the original docx-merger package

Installation

npm install @spfxappdev/docxmerger

Usage

The example shows how an input field of type "File" is handled after the selection has been changed. The input field allows multiple selections:

HTML

<input type="file" id="wordFileInput" multiple accept=".docx" />

TypeScript

import { DocxMerger } from '@spfxappdev/docxmerger';

const fileInput = document.getElementById('wordFileInput') as HTMLInputElement;

fileInput.addEventListener('change', async (event) => {
  const wordFiles = fileInput.files as FileList;
  
  if(wordFiles.length < 2) {
    alert("Please select at least 2 files");
    return;
  }
  
  //All loaded files in an array of ArrayBuffer
  const promises: Promise<ArrayBuffer>[] = [];

  //Load all files as arrayBuffer and then resolve the "Promise"
  const readFilesPromise = new Promise<void>((res, rej) => {
    for (let fileIndex = 0; fileIndex < (wordFiles as FileList).length; fileIndex++) {
      const reader = new FileReader();
      const wordFile = wordFiles[fileIndex];

      reader.onload = function (event) {
        const arrayBuffer = event.target.result;

        promises.push(Promise.resolve<ArrayBuffer>(arrayBuffer as ArrayBuffer));

        if (promises.length === wordFiles.length) {
          res();
        }
      };

      reader.readAsArrayBuffer(wordFile);
    }
  });

  await readFilesPromise;
  
  const filesToMerge = await Promise.all(promises);

  const docx = new DocxMerger();
  await docx.merge(filesToMerge);
  const mergedFile  = await docx.save();
  
  //DO something with the merged file
});

Demo

In this codepen you will find an example implementation including the code on how to download the merged file after merging

API

merge(files: JSZipFileInput[], options?: DocxMergerOptions)

since @spfxappdev/docxmerger@1.0.0

This method merges the passed files into a single file.

Arguments

| name | type | description | |-------|---------|-------------------------------------| | files | JSZipFileInput ( ==>ArrayBuffer or Uint8Array or Blob) | the files to merge | | options | DocxMergerOptions | Optional options for the merging and saving process |

Type DocxMergerOptions

| name | type | description | |-------|---------|-------------------------------------| | pageBreak | boolean | Determines whether a page break should be inserted after merging the file(s) | | jsZipLoadOptions | JSZip.JSZipLoadOptions | Optional parameters that can be passed to JSZip and the loadAsync method when the merge method is called see JSZip | | jsZipGenerateOptions | JSZip.JSZipGeneratorOptions | Optional parameters that can be passed to JSZip and the generateAsync method when the save method is called see JSZip Default value: { type: 'arraybuffer', compression: 'DEFLATE', compressionOptions: {level: 4} } |


save()

since @spfxappdev/docxmerger@1.0.0

Creates/saves the merged file async and returns it