diff --git a/demo/demo.js b/demo/demo.js new file mode 100644 index 0000000000..58e7fdfd8d --- /dev/null +++ b/demo/demo.js @@ -0,0 +1,15 @@ +const docx = require('../build'); + +var doc = new docx.Document(); + +var paragraph = new docx.Paragraph("Hello World"); +var institutionText = new docx.TextRun("University College London").bold(); +var dateText = new docx.TextRun("5th Dec 2015").tab().bold(); +paragraph.addText(institutionText); +paragraph.addText(dateText); + +doc.addParagraph(paragraph); +var exporter = new docx.LocalPacker(doc); +exporter.pack('My Document'); + +console.log('Document created succesfully at project root!'); \ No newline at end of file diff --git a/package.json b/package.json index 9574cc3ac4..2cee1629ad 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "mocha ./build-tests --recursive", "prepublishOnly": "npm run build", "lint": "tslint --project ./ts", - "build": "rimraf ./build && tsc -p ts" + "build": "rimraf ./build && tsc -p ts", + "demo": "npm run build && node ./demo/demo.js" }, "files": [ "ts", diff --git a/ts/export/packer/express.ts b/ts/export/packer/express.ts index 539fac40d4..737c220779 100644 --- a/ts/export/packer/express.ts +++ b/ts/export/packer/express.ts @@ -18,7 +18,7 @@ export class ExpressPacker extends Packer { } public pack(name: string): void { - this.res.attachment(name + ".docx"); + this.res.attachment(`${name}.docx`); super.pack(this.res); } } diff --git a/ts/export/packer/local.ts b/ts/export/packer/local.ts index 6b8c371c94..319f2e16f1 100644 --- a/ts/export/packer/local.ts +++ b/ts/export/packer/local.ts @@ -13,7 +13,7 @@ export class LocalPacker extends Packer { } public pack(path: string): void { - this.stream = fs.createWriteStream(path); + this.stream = fs.createWriteStream(`${path}.docx`); super.pack(this.stream); } }