Add Express packer deprecation warning

This commit is contained in:
Dolan
2018-08-07 02:23:58 +01:00
parent e9aecfac1c
commit cf0c2c7691
2 changed files with 18 additions and 4 deletions

View File

@ -32,21 +32,32 @@ const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.StreamPacker(doc);
const buffer = exporter.pack();
const stream = exporter.pack();
```
## Express Packer
The old express packer is now deprecated and may disappear soon, so you should upgrade.
The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns.
It will still be usable (for now), but it is ill advised.
I used the express exporter in my [website](http://www.dolan.bio).
Pass in the necessary parameters:
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
```js
const docx = require("docx");
const doc = new docx.Document();
const exporter = new docx.ExpressPacker(doc, res);
exporter.pack("My Document");
const exporter = new docx.StreamPacker(doc);
const stream = exporter.pack();
// Express' response object
res.attachment('yourfile.xlsx');
stream.pipe(res);
```
where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser.

View File

@ -4,6 +4,9 @@ import { File } from "file";
import { Compiler } from "./compiler";
import { IPacker } from "./packer";
/**
* @deprecated ExpressPacker is now deprecated. Please use the StreamPacker instead and pipe that to `express`' `res` object
*/
export class ExpressPacker implements IPacker {
private readonly packer: Compiler;