From e93d6799fd812df1e6bbdba8bc696fa11bdc68fc Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 23 Jan 2018 01:33:12 +0000 Subject: [PATCH] Made project Prettier compliant --- src/export/packer/compiler.ts | 1 - src/export/packer/express.ts | 5 +- src/export/packer/local.spec.ts | 4 +- src/export/packer/local.ts | 1 - src/export/packer/pdf-convert-wrapper.ts | 15 +- src/file/document/body/body.spec.ts | 1 - src/file/document/body/body.ts | 1 - src/file/document/body/columns.ts | 9 +- src/file/document/body/doc-grid.ts | 9 +- src/file/document/body/page-margin.ts | 21 +- src/file/document/body/page-size.ts | 11 +- src/file/document/body/section-properties.ts | 13 +- src/file/document/document.spec.ts | 44 +- src/file/document/document.ts | 40 +- src/file/drawing/drawing.ts | 1 - .../inline/doc-properties/doc-properties.ts | 13 +- .../inline/effect-extent/effect-extent.ts | 15 +- src/file/drawing/inline/extent/extent.ts | 11 +- .../graphic-frame-locks.ts | 11 +- .../graphic-frame/graphic-frame-properties.ts | 1 - .../graphic/graphic-data/graphic-data.ts | 9 +- .../graphic-data/pic/blip/blip-fill.ts | 1 - .../graphic/graphic-data/pic/blip/blip.ts | 11 +- .../graphic-data/pic/blip/source-rectangle.ts | 1 - .../graphic/graphic-data/pic/blip/stretch.ts | 2 - .../child-non-visual-pic-properties.ts | 1 - .../pic-locks/pic-locks.ts | 11 +- .../non-visual-pic-properties.ts | 2 - .../non-visual-properties.ts | 13 +- .../inline/graphic/graphic-data/pic/pic.ts | 8 +- .../shape-properties/form/extents/extents.ts | 11 +- .../pic/shape-properties/form/form.ts | 1 - .../pic/shape-properties/form/offset/off.ts | 11 +- .../pic/shape-properties/no-fill.ts | 1 - .../pic/shape-properties/outline/no-fill.ts | 1 - .../pic/shape-properties/outline/outline.ts | 1 - .../adjustment-values/adjustment-values.ts | 1 - .../preset-geometry/preset-geometry.ts | 9 +- .../pic/shape-properties/shape-properties.ts | 9 +- src/file/drawing/inline/graphic/index.ts | 9 +- src/file/drawing/inline/inline.ts | 15 +- src/file/file.ts | 7 +- src/file/media/media.ts | 2 +- src/file/numbering/abstract-numbering.ts | 10 +- src/file/numbering/level.ts | 46 +- src/file/numbering/multi-level-type.ts | 9 +- src/file/numbering/num.ts | 31 +- src/file/numbering/numbering.spec.ts | 216 +++------ src/file/numbering/numbering.ts | 67 +-- src/file/paragraph/formatting/alignment.ts | 7 +- src/file/paragraph/formatting/border.ts | 16 +- src/file/paragraph/formatting/indent.ts | 1 - src/file/paragraph/formatting/page-break.ts | 10 +- src/file/paragraph/formatting/spacing.spec.ts | 8 +- src/file/paragraph/formatting/style.ts | 9 +- src/file/paragraph/formatting/tab-stop.ts | 16 +- .../paragraph/formatting/unordered-list.ts | 18 +- src/file/paragraph/paragraph.spec.ts | 137 +++--- src/file/paragraph/properties.ts | 1 - src/file/paragraph/run/break.ts | 1 - src/file/paragraph/run/caps.ts | 2 - src/file/paragraph/run/formatting.ts | 99 ++-- src/file/paragraph/run/picture-run.ts | 1 - src/file/paragraph/run/properties.ts | 1 - .../paragraph/run/run-components/text.spec.ts | 9 +- src/file/paragraph/run/run-components/text.ts | 6 +- src/file/paragraph/run/run-fonts.spec.ts | 5 +- src/file/paragraph/run/run-fonts.ts | 13 +- src/file/paragraph/run/run.spec.ts | 24 +- src/file/paragraph/run/script.ts | 11 +- src/file/paragraph/run/style.ts | 7 +- src/file/paragraph/run/tab.ts | 1 - src/file/paragraph/run/text-run.spec.ts | 8 +- src/file/paragraph/run/text-run.ts | 1 - src/file/paragraph/run/underline.spec.ts | 22 +- src/file/paragraph/run/underline.ts | 28 +- src/file/properties/components.ts | 25 +- src/file/properties/properties.spec.ts | 23 +- src/file/properties/properties.ts | 17 +- .../relationship/relationship.ts | 12 +- src/file/relationships/relationships.ts | 9 +- src/file/styles/defaults/index.ts | 1 - .../styles/defaults/paragraph-properties.ts | 1 - src/file/styles/factory.ts | 11 +- src/file/styles/index.ts | 20 +- src/file/styles/latent-styles/exceptions.ts | 1 - src/file/styles/latent-styles/index.ts | 1 - src/file/styles/sample/index.ts | 338 +++++++------ src/file/styles/style/components.ts | 34 +- src/file/styles/style/index.ts | 13 +- src/file/styles/styles.spec.ts | 453 +++++++++--------- src/file/table/grid.spec.ts | 10 +- src/file/table/grid.ts | 6 +- src/file/table/properties.spec.ts | 10 +- src/file/table/properties.ts | 10 +- src/file/table/table.spec.ts | 179 ++++--- src/file/xml-components/attribute.spec.ts | 1 - src/file/xml-components/default-attributes.ts | 4 +- src/file/xml-components/xml-component.spec.ts | 5 +- src/file/xml-components/xml-component.ts | 14 +- src/file/xml-components/xmlable-object.ts | 2 +- 101 files changed, 1198 insertions(+), 1207 deletions(-) diff --git a/src/export/packer/compiler.ts b/src/export/packer/compiler.ts index afce89f525..33ac1fa604 100644 --- a/src/export/packer/compiler.ts +++ b/src/export/packer/compiler.ts @@ -76,6 +76,5 @@ export class Compiler { resolve(); }); }); - } } diff --git a/src/export/packer/express.ts b/src/export/packer/express.ts index 4c6a573d4f..e6ee3693ac 100644 --- a/src/export/packer/express.ts +++ b/src/export/packer/express.ts @@ -14,7 +14,10 @@ export class ExpressPacker implements IPacker { this.res = res; this.res.on("close", () => { - return res.status(200).send("OK").end(); + return res + .status(200) + .send("OK") + .end(); }); } diff --git a/src/export/packer/local.spec.ts b/src/export/packer/local.spec.ts index 39a721195d..16fb99705b 100644 --- a/src/export/packer/local.spec.ts +++ b/src/export/packer/local.spec.ts @@ -24,7 +24,7 @@ describe("LocalPacker", () => { }); describe("#pack()", () => { - it("should create a standard docx file", async function () { + it("should create a standard docx file", async function() { this.timeout(99999999); await packer.pack("build/tests/test"); fs.statSync("build/tests/test.docx"); @@ -32,7 +32,7 @@ describe("LocalPacker", () => { }); describe("#packPdf", () => { - it("should create a standard PDF file", async function () { + it("should create a standard PDF file", async function() { this.timeout(99999999); await packer.packPdf("build/tests/pdf-test"); diff --git a/src/export/packer/local.ts b/src/export/packer/local.ts index f59526bbc4..2e33f74dfc 100644 --- a/src/export/packer/local.ts +++ b/src/export/packer/local.ts @@ -43,6 +43,5 @@ export class LocalPacker implements IPacker { resolve(); }); }); - } } diff --git a/src/export/packer/pdf-convert-wrapper.ts b/src/export/packer/pdf-convert-wrapper.ts index 3b1c43073d..5067082d12 100644 --- a/src/export/packer/pdf-convert-wrapper.ts +++ b/src/export/packer/pdf-convert-wrapper.ts @@ -13,21 +13,22 @@ export class PdfConvertWrapper { url: "http://mirror1.convertonlinefree.com", encoding: null, headers: { - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36", + "User-Agent": + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36", }, formData: { - "__EVENTTARGET": "", - "__EVENTARGUMENT": "", - "__VIEWSTATE": "", - "ctl00$MainContent$fu": { + __EVENTTARGET: "", + __EVENTARGUMENT: "", + __VIEWSTATE: "", + ctl00$MainContent$fu: { value: fs.readFileSync(filePath), options: { filename: "output.docx", contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", }, }, - "ctl00$MainContent$btnConvert": "Convert", - "ctl00$MainContent$fuZip": "", + ctl00$MainContent$btnConvert: "Convert", + ctl00$MainContent$fuZip: "", }, }); } diff --git a/src/file/document/body/body.spec.ts b/src/file/document/body/body.spec.ts index 01a867044b..26beb7628c 100644 --- a/src/file/document/body/body.spec.ts +++ b/src/file/document/body/body.spec.ts @@ -21,7 +21,6 @@ describe("Body", () => { }); describe("#constructor()", () => { - it("should create the Section Properties", () => { const newJson = Utility.jsonify(body); assert.equal(newJson.root[0].rootKey, "w:sectPr"); diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index 24cb1bf8bc..797242093d 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class Body extends XmlComponent { - constructor() { super("w:body"); } diff --git a/src/file/document/body/columns.ts b/src/file/document/body/columns.ts index 0f66904faa..e95798ccb9 100644 --- a/src/file/document/body/columns.ts +++ b/src/file/document/body/columns.ts @@ -1,11 +1,12 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class Columns extends XmlComponent { - constructor() { super("w:cols"); - this.root.push(new Attributes({ - space: "708", - })); + this.root.push( + new Attributes({ + space: "708", + }), + ); } } diff --git a/src/file/document/body/doc-grid.ts b/src/file/document/body/doc-grid.ts index 5b2f280014..4b23a87d3b 100644 --- a/src/file/document/body/doc-grid.ts +++ b/src/file/document/body/doc-grid.ts @@ -1,11 +1,12 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class DocumentGrid extends XmlComponent { - constructor() { super("w:docGrid"); - this.root.push(new Attributes({ - linePitch: "360", - })); + this.root.push( + new Attributes({ + linePitch: "360", + }), + ); } } diff --git a/src/file/document/body/page-margin.ts b/src/file/document/body/page-margin.ts index b02c788c5f..272dd63786 100644 --- a/src/file/document/body/page-margin.ts +++ b/src/file/document/body/page-margin.ts @@ -1,17 +1,18 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class PageMargin extends XmlComponent { - constructor() { super("w:pgMar"); - this.root.push(new Attributes({ - top: "1440", - right: "1440", - bottom: "1440", - left: "1440", - header: "708", - footer: "708", - gutter: "0", - })); + this.root.push( + new Attributes({ + top: "1440", + right: "1440", + bottom: "1440", + left: "1440", + header: "708", + footer: "708", + gutter: "0", + }), + ); } } diff --git a/src/file/document/body/page-size.ts b/src/file/document/body/page-size.ts index cda39d728e..cf70ade845 100644 --- a/src/file/document/body/page-size.ts +++ b/src/file/document/body/page-size.ts @@ -1,12 +1,13 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class PageSize extends XmlComponent { - constructor() { super("w:pgSz"); - this.root.push(new Attributes({ - w: "11906", - h: "16838", - })); + this.root.push( + new Attributes({ + w: "11906", + h: "16838", + }), + ); } } diff --git a/src/file/document/body/section-properties.ts b/src/file/document/body/section-properties.ts index c112674f44..0310ad5f01 100644 --- a/src/file/document/body/section-properties.ts +++ b/src/file/document/body/section-properties.ts @@ -5,14 +5,15 @@ import { PageMargin } from "./page-margin"; import { PageSize } from "./page-size"; export class SectionProperties extends XmlComponent { - constructor() { super("w:sectPr"); - this.root.push(new Attributes({ - rsidR: "00B64E8F", - rsidRPr: "00D842E4", - rsidSect: "000A6AD0", - })); + this.root.push( + new Attributes({ + rsidR: "00B64E8F", + rsidRPr: "00D842E4", + rsidSect: "000A6AD0", + }), + ); this.root.push(new PageSize()); this.root.push(new PageMargin()); this.root.push(new Columns()); diff --git a/src/file/document/document.spec.ts b/src/file/document/document.spec.ts index 172812e93a..150df18ad2 100644 --- a/src/file/document/document.spec.ts +++ b/src/file/document/document.spec.ts @@ -11,7 +11,6 @@ describe("Document", () => { }); describe("#constructor()", () => { - it("should create valid JSON", () => { const stringifiedJson = JSON.stringify(document); let newJson; @@ -30,7 +29,9 @@ describe("Document", () => { const para = document.createParagraph(); expect(para).to.be.an.instanceof(docx.Paragraph); const body = new Formatter().format(document)["w:document"][1]["w:body"]; - expect(body).to.be.an("array").which.has.length.at.least(1); + expect(body) + .to.be.an("array") + .which.has.length.at.least(1); expect(body[0]).to.have.property("w:p"); }); @@ -38,13 +39,14 @@ describe("Document", () => { const para = document.createParagraph("sample paragraph text"); expect(para).to.be.an.instanceof(docx.Paragraph); const body = new Formatter().format(document)["w:document"][1]["w:body"]; - expect(body).to.be.an("array").which.has.length.at.least(1); - expect(body[0]).to.have.property("w:p").which.includes({ - "w:r": [ - {"w:rPr": []}, - {"w:t": [{_attr: {"xml:space": "preserve"}}, "sample paragraph text"]}, - ], - }); + expect(body) + .to.be.an("array") + .which.has.length.at.least(1); + expect(body[0]) + .to.have.property("w:p") + .which.includes({ + "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "sample paragraph text"] }], + }); }); }); @@ -53,21 +55,27 @@ describe("Document", () => { const table = document.createTable(2, 3); expect(table).to.be.an.instanceof(docx.Table); const body = new Formatter().format(document)["w:document"][1]["w:body"]; - expect(body).to.be.an("array").which.has.length.at.least(1); + expect(body) + .to.be.an("array") + .which.has.length.at.least(1); expect(body[0]).to.have.property("w:tbl"); }); it("should create a table with the correct dimensions", () => { document.createTable(2, 3); const body = new Formatter().format(document)["w:document"][1]["w:body"]; - expect(body).to.be.an("array").which.has.length.at.least(1); - expect(body[0]).to.have.property("w:tbl").which.includes({ - "w:tblGrid": [ - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - ], - }); + expect(body) + .to.be.an("array") + .which.has.length.at.least(1); + expect(body[0]) + .to.have.property("w:tbl") + .which.includes({ + "w:tblGrid": [ + { "w:gridCol": [{ _attr: { "w:w": 1 } }] }, + { "w:gridCol": [{ _attr: { "w:w": 1 } }] }, + { "w:gridCol": [{ _attr: { "w:w": 1 } }] }, + ], + }); expect(body[0]["w:tbl"].filter((x) => x["w:tr"])).to.have.length(2); }); }); diff --git a/src/file/document/document.ts b/src/file/document/document.ts index 5e16212f86..d19803edee 100644 --- a/src/file/document/document.ts +++ b/src/file/document/document.ts @@ -11,25 +11,27 @@ export class Document extends XmlComponent { constructor() { super("w:document"); - this.root.push(new DocumentAttributes({ - wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", - mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", - o: "urn:schemas-microsoft-com:office:office", - r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", - m: "http://schemas.openxmlformats.org/officeDocument/2006/math", - v: "urn:schemas-microsoft-com:vml", - wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", - wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", - w10: "urn:schemas-microsoft-com:office:word", - w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", - w14: "http://schemas.microsoft.com/office/word/2010/wordml", - w15: "http://schemas.microsoft.com/office/word/2012/wordml", - wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", - wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", - wne: "http://schemas.microsoft.com/office/word/2006/wordml", - wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", - Ignorable: "w14 w15 wp14", - })); + this.root.push( + new DocumentAttributes({ + wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", + o: "urn:schemas-microsoft-com:office:office", + r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + m: "http://schemas.openxmlformats.org/officeDocument/2006/math", + v: "urn:schemas-microsoft-com:vml", + wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + w10: "urn:schemas-microsoft-com:office:word", + w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + w14: "http://schemas.microsoft.com/office/word/2010/wordml", + w15: "http://schemas.microsoft.com/office/word/2012/wordml", + wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + wne: "http://schemas.microsoft.com/office/word/2006/wordml", + wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + Ignorable: "w14 w15 wp14", + }), + ); this.body = new Body(); this.root.push(this.body); } diff --git a/src/file/drawing/drawing.ts b/src/file/drawing/drawing.ts index fcaaa960c0..e6dab2f4d1 100644 --- a/src/file/drawing/drawing.ts +++ b/src/file/drawing/drawing.ts @@ -3,7 +3,6 @@ import { XmlComponent } from "file/xml-components"; import { Inline } from "./inline"; export class Drawing extends XmlComponent { - constructor(imageData: IMediaData) { super("w:drawing"); diff --git a/src/file/drawing/inline/doc-properties/doc-properties.ts b/src/file/drawing/inline/doc-properties/doc-properties.ts index b6e03d6953..fa0f97462a 100644 --- a/src/file/drawing/inline/doc-properties/doc-properties.ts +++ b/src/file/drawing/inline/doc-properties/doc-properties.ts @@ -2,14 +2,15 @@ import { XmlComponent } from "file/xml-components"; import { DocPropertiesAttributes } from "./doc-properties-attributes"; export class DocProperties extends XmlComponent { - constructor() { super("wp:docPr"); - this.root.push(new DocPropertiesAttributes({ - id: 0, - name: "", - descr: "", - })); + this.root.push( + new DocPropertiesAttributes({ + id: 0, + name: "", + descr: "", + }), + ); } } diff --git a/src/file/drawing/inline/effect-extent/effect-extent.ts b/src/file/drawing/inline/effect-extent/effect-extent.ts index 97c6caa098..b62dcc8dd0 100644 --- a/src/file/drawing/inline/effect-extent/effect-extent.ts +++ b/src/file/drawing/inline/effect-extent/effect-extent.ts @@ -2,15 +2,16 @@ import { XmlComponent } from "file/xml-components"; import { EffectExtentAttributes } from "./effect-extent-attributes"; export class EffectExtent extends XmlComponent { - constructor() { super("wp:effectExtent"); - this.root.push(new EffectExtentAttributes({ - b: 0, - l: 0, - r: 0, - t: 0, - })); + this.root.push( + new EffectExtentAttributes({ + b: 0, + l: 0, + r: 0, + t: 0, + }), + ); } } diff --git a/src/file/drawing/inline/extent/extent.ts b/src/file/drawing/inline/extent/extent.ts index 3b787e0e66..8602cc4afe 100644 --- a/src/file/drawing/inline/extent/extent.ts +++ b/src/file/drawing/inline/extent/extent.ts @@ -2,13 +2,14 @@ import { XmlComponent } from "file/xml-components"; import { ExtentAttributes } from "./extent-attributes"; export class Extent extends XmlComponent { - constructor(x: number, y: number) { super("wp:extent"); - this.root.push(new ExtentAttributes({ - cx: x, - cy: y, - })); + this.root.push( + new ExtentAttributes({ + cx: x, + cy: y, + }), + ); } } diff --git a/src/file/drawing/inline/graphic-frame/graphic-frame-locks/graphic-frame-locks.ts b/src/file/drawing/inline/graphic-frame/graphic-frame-locks/graphic-frame-locks.ts index c6e70d02ce..42e38435b1 100644 --- a/src/file/drawing/inline/graphic-frame/graphic-frame-locks/graphic-frame-locks.ts +++ b/src/file/drawing/inline/graphic-frame/graphic-frame-locks/graphic-frame-locks.ts @@ -2,13 +2,14 @@ import { XmlComponent } from "file/xml-components"; import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes"; export class GraphicFrameLocks extends XmlComponent { - constructor() { super("a:graphicFrameLocks"); - this.root.push(new GraphicFrameLockAttributes({ - xmlns: "http://schemas.openxmlformats.org/drawingml/2006/main", - noChangeAspect: 1, - })); + this.root.push( + new GraphicFrameLockAttributes({ + xmlns: "http://schemas.openxmlformats.org/drawingml/2006/main", + noChangeAspect: 1, + }), + ); } } diff --git a/src/file/drawing/inline/graphic-frame/graphic-frame-properties.ts b/src/file/drawing/inline/graphic-frame/graphic-frame-properties.ts index 764fb05b19..defa900216 100644 --- a/src/file/drawing/inline/graphic-frame/graphic-frame-properties.ts +++ b/src/file/drawing/inline/graphic-frame/graphic-frame-properties.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks"; export class GraphicFrameProperties extends XmlComponent { - constructor() { super("wp:cNvGraphicFramePr"); diff --git a/src/file/drawing/inline/graphic/graphic-data/graphic-data.ts b/src/file/drawing/inline/graphic/graphic-data/graphic-data.ts index 4b32b25cc4..abc75e3a04 100644 --- a/src/file/drawing/inline/graphic/graphic-data/graphic-data.ts +++ b/src/file/drawing/inline/graphic/graphic-data/graphic-data.ts @@ -3,13 +3,14 @@ import { GraphicDataAttributes } from "./graphic-data-attribute"; import { Pic } from "./pic"; export class GraphicData extends XmlComponent { - constructor(referenceId: number, x: number, y: number) { super("a:graphicData"); - this.root.push(new GraphicDataAttributes({ - uri: "http://schemas.openxmlformats.org/drawingml/2006/picture", - })); + this.root.push( + new GraphicDataAttributes({ + uri: "http://schemas.openxmlformats.org/drawingml/2006/picture", + }), + ); this.root.push(new Pic(referenceId, x, y)); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip-fill.ts b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip-fill.ts index 69b6bf40a4..c4630ddee3 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip-fill.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip-fill.ts @@ -4,7 +4,6 @@ import { SourceRectangle } from "./source-rectangle"; import { Stretch } from "./stretch"; export class BlipFill extends XmlComponent { - constructor(referenceId: number) { super("pic:blipFill"); this.root.push(new Blip(referenceId)); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts index 095bae8696..3f8c737bec 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts @@ -13,12 +13,13 @@ class BlipAttributes extends XmlAttributeComponent { } export class Blip extends XmlComponent { - constructor(referenceId: number) { super("a:blip"); - this.root.push(new BlipAttributes({ - embed: `rId${referenceId}`, - cstate: "none", - })); + this.root.push( + new BlipAttributes({ + embed: `rId${referenceId}`, + cstate: "none", + }), + ); } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/blip/source-rectangle.ts b/src/file/drawing/inline/graphic/graphic-data/pic/blip/source-rectangle.ts index c944ebbc77..d815fb9879 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/blip/source-rectangle.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/blip/source-rectangle.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class SourceRectangle extends XmlComponent { - constructor() { super("a:srcRect"); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/blip/stretch.ts b/src/file/drawing/inline/graphic/graphic-data/pic/blip/stretch.ts index 2de9775885..ac3f33aec9 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/blip/stretch.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/blip/stretch.ts @@ -1,14 +1,12 @@ import { XmlComponent } from "file/xml-components"; class FillRectangle extends XmlComponent { - constructor() { super("a:fillRect"); } } export class Stretch extends XmlComponent { - constructor() { super("a:stretch"); this.root.push(new FillRectangle()); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/child-non-visual-pic-properties.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/child-non-visual-pic-properties.ts index f1e56fe332..2bddee94c5 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/child-non-visual-pic-properties.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/child-non-visual-pic-properties.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; import { PicLocks } from "./pic-locks/pic-locks"; export class ChildNonVisualProperties extends XmlComponent { - constructor() { super("pic:cNvPicPr"); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks.ts index 6a6027b89d..3d30f2836f 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks.ts @@ -2,12 +2,13 @@ import { XmlComponent } from "file/xml-components"; import { PicLocksAttributes } from "./pic-locks-attributes"; export class PicLocks extends XmlComponent { - constructor() { super("a:picLocks"); - this.root.push(new PicLocksAttributes({ - noChangeAspect: 1, - noChangeArrowheads: 1, - })); + this.root.push( + new PicLocksAttributes({ + noChangeAspect: 1, + noChangeArrowheads: 1, + }), + ); } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-pic-properties.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-pic-properties.ts index 50551a9c58..65e83f8d54 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-pic-properties.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-pic-properties.ts @@ -3,12 +3,10 @@ import { ChildNonVisualProperties } from "./child-non-visual-pic-properties/chil import { NonVisualProperties } from "./non-visual-properties/non-visual-properties"; export class NonVisualPicProperties extends XmlComponent { - constructor() { super("pic:nvPicPr"); this.root.push(new NonVisualProperties()); this.root.push(new ChildNonVisualProperties()); - } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.ts index b37e3f77ba..c4d4c76634 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties.ts @@ -2,14 +2,15 @@ import { XmlComponent } from "file/xml-components"; import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes"; export class NonVisualProperties extends XmlComponent { - constructor() { super("pic:cNvPr"); - this.root.push(new NonVisualPropertiesAttributes({ - id: 0, - name: "", - descr: "", - })); + this.root.push( + new NonVisualPropertiesAttributes({ + id: 0, + name: "", + descr: "", + }), + ); } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/pic.ts b/src/file/drawing/inline/graphic/graphic-data/pic/pic.ts index 31bee69136..98f70b4609 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/pic.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/pic.ts @@ -9,9 +9,11 @@ export class Pic extends XmlComponent { constructor(referenceId: number, x: number, y: number) { super("pic:pic"); - this.root.push(new PicAttributes({ - xmlns: "http://schemas.openxmlformats.org/drawingml/2006/picture", - })); + this.root.push( + new PicAttributes({ + xmlns: "http://schemas.openxmlformats.org/drawingml/2006/picture", + }), + ); this.root.push(new NonVisualPicProperties()); this.root.push(new BlipFill(referenceId)); this.root.push(new ShapeProperties(x, y)); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents.ts index de38caab18..bfcb052f72 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents.ts @@ -3,13 +3,14 @@ import { XmlComponent } from "file/xml-components"; import { ExtentsAttributes } from "./extents-attributes"; export class Extents extends XmlComponent { - constructor(x: number, y: number) { super("a:ext"); - this.root.push(new ExtentsAttributes({ - cx: x, - cy: y, - })); + this.root.push( + new ExtentsAttributes({ + cx: x, + cy: y, + }), + ); } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts index 94ed24e1eb..1d0aefbd7e 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts @@ -4,7 +4,6 @@ import { Extents } from "./extents/extents"; import { Offset } from "./offset/off"; export class Form extends XmlComponent { - constructor(x: number, y: number) { super("a:xfrm"); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off.ts index 32c2fcca76..791ed8921c 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off.ts @@ -3,13 +3,14 @@ import { XmlComponent } from "file/xml-components"; import { OffsetAttributes } from "./off-attributes"; export class Offset extends XmlComponent { - constructor() { super("a:off"); - this.root.push(new OffsetAttributes({ - x: 0, - y: 0, - })); + this.root.push( + new OffsetAttributes({ + x: 0, + y: 0, + }), + ); } } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/no-fill.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/no-fill.ts index bbccc05664..4e847a1d56 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/no-fill.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/no-fill.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class NoFill extends XmlComponent { - constructor() { super("a:noFill"); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/no-fill.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/no-fill.ts index bbccc05664..4e847a1d56 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/no-fill.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/no-fill.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class NoFill extends XmlComponent { - constructor() { super("a:noFill"); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline.ts index 5735deb3e5..effded5399 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline.ts @@ -3,7 +3,6 @@ import { XmlComponent } from "file/xml-components"; import { NoFill } from "./no-fill"; export class Outline extends XmlComponent { - constructor() { super("a:ln"); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/adjustment-values/adjustment-values.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/adjustment-values/adjustment-values.ts index 395f61f866..b781479b64 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/adjustment-values/adjustment-values.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/adjustment-values/adjustment-values.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; export class AdjustmentValues extends XmlComponent { - constructor() { super("a:avLst"); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry.ts index 67668bc36a..3ffbb1c045 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry.ts @@ -4,13 +4,14 @@ import { AdjustmentValues } from "./adjustment-values/adjustment-values"; import { PresetGeometryAttributes } from "./preset-geometry-attributes"; export class PresetGeometry extends XmlComponent { - constructor() { super("a:prstGeom"); - this.root.push(new PresetGeometryAttributes({ - prst: "rect", - })); + this.root.push( + new PresetGeometryAttributes({ + prst: "rect", + }), + ); this.root.push(new AdjustmentValues()); } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties.ts index 41b914a0fd..5a245ca0f6 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties.ts @@ -7,13 +7,14 @@ import { PresetGeometry } from "./preset-geometry/preset-geometry"; import { ShapePropertiesAttributes } from "./shape-properties-attributes"; export class ShapeProperties extends XmlComponent { - constructor(x: number, y: number) { super("pic:spPr"); - this.root.push(new ShapePropertiesAttributes({ - bwMode: "auto", - })); + this.root.push( + new ShapePropertiesAttributes({ + bwMode: "auto", + }), + ); this.root.push(new Form(x, y)); this.root.push(new PresetGeometry()); diff --git a/src/file/drawing/inline/graphic/index.ts b/src/file/drawing/inline/graphic/index.ts index 60b336f6ba..1e0f330932 100644 --- a/src/file/drawing/inline/graphic/index.ts +++ b/src/file/drawing/inline/graphic/index.ts @@ -12,12 +12,13 @@ class GraphicAttributes extends XmlAttributeComponent { } export class Graphic extends XmlComponent { - constructor(referenceId: number, x: number, y: number) { super("a:graphic"); - this.root.push(new GraphicAttributes({ - a: "http://schemas.openxmlformats.org/drawingml/2006/main", - })); + this.root.push( + new GraphicAttributes({ + a: "http://schemas.openxmlformats.org/drawingml/2006/main", + }), + ); this.root.push(new GraphicData(referenceId, x, y)); } } diff --git a/src/file/drawing/inline/inline.ts b/src/file/drawing/inline/inline.ts index 15facb5681..6bde46d8d9 100644 --- a/src/file/drawing/inline/inline.ts +++ b/src/file/drawing/inline/inline.ts @@ -9,16 +9,17 @@ import { GraphicFrameProperties } from "./graphic-frame/graphic-frame-properties import { InlineAttributes } from "./inline-attributes"; export class Inline extends XmlComponent { - constructor(referenceId: number, dimensions: IMediaDataDimensions) { super("wp:inline"); - this.root.push(new InlineAttributes({ - distT: 0, - distB: 0, - distL: 0, - distR: 0, - })); + this.root.push( + new InlineAttributes({ + distT: 0, + distB: 0, + distL: 0, + distR: 0, + }), + ); this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y)); this.root.push(new EffectExtent()); diff --git a/src/file/file.ts b/src/file/file.ts index a2af594339..59af3c5ff3 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -9,7 +9,6 @@ import { DefaultStylesFactory } from "./styles/factory"; import { Table } from "./table"; export class File { - private document: Document; private styles: Styles; private properties: Properties; @@ -54,7 +53,11 @@ export class File { public createImage(image: string): void { const mediaData = this.media.addMedia(image); - this.relationships.createRelationship(mediaData.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`); + this.relationships.createRelationship( + mediaData.referenceId, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", + `media/${mediaData.fileName}`, + ); this.document.createDrawing(mediaData); } diff --git a/src/file/media/media.ts b/src/file/media/media.ts index b683e5a3d8..854d19194a 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import * as sizeOf from "image-size"; import * as path from "path"; -import {IMediaData} from "./data"; +import { IMediaData } from "./data"; export class Media { private map: Map; diff --git a/src/file/numbering/abstract-numbering.ts b/src/file/numbering/abstract-numbering.ts index eb64487cdc..39239c548a 100644 --- a/src/file/numbering/abstract-numbering.ts +++ b/src/file/numbering/abstract-numbering.ts @@ -19,10 +19,12 @@ export class AbstractNumbering extends XmlComponent { constructor(id: number) { super("w:abstractNum"); - this.root.push(new AbstractNumberingAttributes({ - abstractNumId: id, - restartNumberingAfterBreak: 0, - })); + this.root.push( + new AbstractNumberingAttributes({ + abstractNumId: id, + restartNumberingAfterBreak: 0, + }), + ); this.root.push(new MultiLevelType("hybridMultilevel")); this.id = id; } diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index 801746ca88..ab8c3ccb53 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -17,42 +17,46 @@ class LevelAttributes extends XmlAttributeComponent } class Start extends XmlComponent { - constructor(value: number) { super("w:start"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } class NumberFormat extends XmlComponent { - constructor(value: string) { super("w:numFmt"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } class LevelText extends XmlComponent { - constructor(value: string) { super("w:lvlText"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } class LevelJc extends XmlComponent { - constructor(value: string) { super("w:lvlJc"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } @@ -62,10 +66,12 @@ export class LevelBase extends XmlComponent { constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) { super("w:lvl"); - this.root.push(new LevelAttributes({ - ilvl: level, - tentative: 1, - })); + this.root.push( + new LevelAttributes({ + ilvl: level, + tentative: 1, + }), + ); if (start !== undefined) { this.root.push(new Start(start)); diff --git a/src/file/numbering/multi-level-type.ts b/src/file/numbering/multi-level-type.ts index 4b688e35fb..c73ebec3cf 100644 --- a/src/file/numbering/multi-level-type.ts +++ b/src/file/numbering/multi-level-type.ts @@ -1,11 +1,12 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class MultiLevelType extends XmlComponent { - constructor(value: string) { super("w:multiLevelType"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } diff --git a/src/file/numbering/num.ts b/src/file/numbering/num.ts index e9362a3c9e..e6b4628ac4 100644 --- a/src/file/numbering/num.ts +++ b/src/file/numbering/num.ts @@ -2,12 +2,13 @@ import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-compon import { LevelForOverride } from "./level"; class AbstractNumId extends XmlComponent { - constructor(value: number) { super("w:abstractNumId"); - this.root.push(new Attributes({ - val: value, - })); + this.root.push( + new Attributes({ + val: value, + }), + ); } } @@ -16,7 +17,7 @@ interface INumAttributesProperties { } class NumAttributes extends XmlAttributeComponent { - protected xmlKeys = {numId: "w:numId"}; + protected xmlKeys = { numId: "w:numId" }; } export class Num extends XmlComponent { @@ -24,9 +25,11 @@ export class Num extends XmlComponent { constructor(numId: number, abstractNumId: number) { super("w:num"); - this.root.push(new NumAttributes({ - numId: numId, - })); + this.root.push( + new NumAttributes({ + numId: numId, + }), + ); this.root.push(new AbstractNumId(abstractNumId)); this.id = numId; } @@ -38,8 +41,8 @@ export class Num extends XmlComponent { } } -class LevelOverrideAttributes extends XmlAttributeComponent<{ilvl: number}> { - protected xmlKeys = {ilvl: "w:ilvl"}; +class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> { + protected xmlKeys = { ilvl: "w:ilvl" }; } export class LevelOverride extends XmlComponent { @@ -48,7 +51,7 @@ export class LevelOverride extends XmlComponent { constructor(levelNum: number, start?: number) { super("w:lvlOverride"); - this.root.push(new LevelOverrideAttributes({ilvl: levelNum})); + this.root.push(new LevelOverrideAttributes({ ilvl: levelNum })); if (start !== undefined) { this.root.push(new StartOverride(start)); } @@ -68,13 +71,13 @@ export class LevelOverride extends XmlComponent { } } -class StartOverrideAttributes extends XmlAttributeComponent<{val: number}> { - protected xmlKeys = {val: "w:val"}; +class StartOverrideAttributes extends XmlAttributeComponent<{ val: number }> { + protected xmlKeys = { val: "w:val" }; } class StartOverride extends XmlComponent { constructor(start: number) { super("w:startOverride"); - this.root.push(new StartOverrideAttributes({val: start})); + this.root.push(new StartOverrideAttributes({ val: start })); } } diff --git a/src/file/numbering/numbering.spec.ts b/src/file/numbering/numbering.spec.ts index a61d352c33..b695d5d1d4 100644 --- a/src/file/numbering/numbering.spec.ts +++ b/src/file/numbering/numbering.spec.ts @@ -6,7 +6,6 @@ import { LevelForOverride } from "./level"; import { Num } from "./num"; describe("Numbering", () => { - let numbering: Numbering; beforeEach(() => { @@ -26,9 +25,7 @@ describe("Numbering", () => { abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => { expect(Object.keys(el)).to.have.lengthOf(1); - expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal([ - "_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr", - ]); + expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal(["_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr"]); expect(el["w:lvl"]).to.have.deep.members([ { _attr: { "w:ilvl": ix, "w15:tentative": 1 } }, { "w:start": [{ _attr: { "w:val": 1 } }] }, @@ -63,9 +60,7 @@ describe("Numbering", () => { const n = numbering.createConcreteNumbering(a2); expect(n).to.be.instanceof(Num); const tree = new Formatter().format(numbering); - const serializedN = tree["w:numbering"].find((obj) => - obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id, - ); + const serializedN = tree["w:numbering"].find((obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id); expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id); }); @@ -110,136 +105,125 @@ describe("AbstractNumbering", () => { describe("formatting methods: paragraph properties", () => { it("#indent", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.") - .indent({ left: 720 }); + const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").indent({ left: 720 }); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [{"w:ind": [{_attr: {"w:left": 720}}]}], + "w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }], }); }); it("#spacing", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.") - .spacing({before: 50, after: 150}); + const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").spacing({ before: 50, after: 150 }); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [ - {"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]}, - ], + "w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }], }); }); it("#center", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.") - .center(); + const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").center(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [ - {"w:jc": [{_attr: {"w:val": "center"}}]}, - ], + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }], }); }); it("#left", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left") - .left(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left").left(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [ - {"w:jc": [{_attr: {"w:val": "left"}}]}, - ], + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }], }); }); it("#right", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .right(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").right(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [ - {"w:jc": [{_attr: {"w:val": "right"}}]}, - ], + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }], }); }); it("#justified", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .justified(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").justified(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [ - {"w:jc": [{_attr: {"w:val": "both"}}]}, - ], + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }], }); }); it("#thematicBreak", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .thematicBreak(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").thematicBreak(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ "w:pPr": [ - {"w:pBdr": [{"w:bottom": [{_attr: { - "w:color": "auto", - "w:space": "1", - "w:val": "single", - "w:sz": "6", - }}]}]}, + { + "w:pBdr": [ + { + "w:bottom": [ + { + _attr: { + "w:color": "auto", + "w:space": "1", + "w:val": "single", + "w:sz": "6", + }, + }, + ], + }, + ], + }, ], }); }); it("#leftTabStop", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .leftTabStop(1200); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").leftTabStop(1200); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ "w:pPr": [ - {"w:tabs": [ - {"w:tab": [{_attr: {"w:val": "left", "w:pos": 1200}}]}, - ]}, + { + "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }], + }, ], }); }); it("#maxRightTabStop", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .maxRightTabStop(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").maxRightTabStop(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ "w:pPr": [ - {"w:tabs": [ - {"w:tab": [{_attr: {"w:val": "right", "w:pos": 9026}}]}, - ]}, + { + "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }], + }, ], }); }); it("#keepLines", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .keepLines(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepLines(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [{"w:keepLines": []}], + "w:pPr": [{ "w:keepLines": [] }], }); }); it("#keepNext", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .keepNext(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepNext(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:pPr": [{"w:keepNext": []}], + "w:pPr": [{ "w:keepNext": [] }], }); }); }); @@ -247,169 +231,129 @@ describe("AbstractNumbering", () => { describe("formatting methods: run properties", () => { it("#size", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .size(24); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").size(24); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:sz": [{_attr: {"w:val": 24}}]}, - ], + "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }], }); }); it("#smallCaps", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .smallCaps(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").smallCaps(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:smallCaps": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }], }); }); it("#allCaps", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .allCaps(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").allCaps(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:caps": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }], }); }); it("#strike", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .strike(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").strike(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:strike": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }], }); }); it("#doubleStrike", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .doubleStrike(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").doubleStrike(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:dstrike": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }], }); }); it("#subScript", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .subScript(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").subScript(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:vertAlign": [{_attr: {"w:val": "subscript"}}]}, - ], + "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }], }); }); it("#superScript", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .superScript(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").superScript(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:vertAlign": [{_attr: {"w:val": "superscript"}}]}, - ], + "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }], }); }); it("#font", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .font("Times"); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").font("Times"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}], + "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }], }); }); it("#bold", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .bold(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").bold(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:b": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }], }); }); it("#italics", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .italics(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").italics(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:i": [{_attr: {"w:val": true}}]}, - ], + "w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }], }); }); describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .underline(); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline(); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:u": [{_attr: {"w:val": "single"}}]}, - ], + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }], }); }); it("should set the style if given", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .underline("double"); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:u": [{_attr: {"w:val": "double"}}]}, - ], + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }], }); }); it("should set the style and color if given", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .underline("double", "005599"); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double", "005599"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]}, - ], + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }], }); }); }); it("#color", () => { const abstractNumbering = new AbstractNumbering(1); - const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") - .color("123456"); + const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").color("123456"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [ - {"w:color": [{_attr: {"w:val": "123456"}}]}, - ], + "w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }], }); }); }); @@ -425,23 +369,19 @@ describe("concrete numbering", () => { numbering = new Numbering(); abstractNumbering = numbering.createAbstractNumbering(); concreteNumbering = numbering.createConcreteNumbering(abstractNumbering); - }); it("sets a new override level for the given level number", () => { concreteNumbering.overrideLevel(3); const tree = new Formatter().format(concreteNumbering); - expect(tree["w:num"]).to.include({"w:lvlOverride": [{_attr: {"w:ilvl": 3}}]}); + expect(tree["w:num"]).to.include({ "w:lvlOverride": [{ _attr: { "w:ilvl": 3 } }] }); }); it("sets the startOverride element if start is given", () => { concreteNumbering.overrideLevel(1, 9); const tree = new Formatter().format(concreteNumbering); expect(tree["w:num"]).to.include({ - "w:lvlOverride": [ - {_attr: {"w:ilvl": 1}}, - {"w:startOverride": [{_attr: {"w:val": 9}}]}, - ], + "w:lvlOverride": [{ _attr: { "w:ilvl": 1 } }, { "w:startOverride": [{ _attr: { "w:val": 9 } }] }], }); }); @@ -451,12 +391,10 @@ describe("concrete numbering", () => { const tree = new Formatter().format(concreteNumbering); expect(tree["w:num"]).to.include({ "w:lvlOverride": [ - {_attr: {"w:ilvl": 1}}, - {"w:lvl": [ - {_attr: {"w15:tentative": 1, "w:ilvl": 1}}, - {"w:pPr": []}, - {"w:rPr": []}, - ]}, + { _attr: { "w:ilvl": 1 } }, + { + "w:lvl": [{ _attr: { "w15:tentative": 1, "w:ilvl": 1 } }, { "w:pPr": [] }, { "w:rPr": [] }], + }, ], }); }); diff --git a/src/file/numbering/numbering.ts b/src/file/numbering/numbering.ts index 59caa49951..64ec0b5a9c 100644 --- a/src/file/numbering/numbering.ts +++ b/src/file/numbering/numbering.ts @@ -10,63 +10,74 @@ export class Numbering extends XmlComponent { constructor() { super("w:numbering"); - this.root.push(new DocumentAttributes({ - wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", - mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", - o: "urn:schemas-microsoft-com:office:office", - r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", - m: "http://schemas.openxmlformats.org/officeDocument/2006/math", - v: "urn:schemas-microsoft-com:vml", - wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", - wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", - w10: "urn:schemas-microsoft-com:office:word", - w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", - w14: "http://schemas.microsoft.com/office/word/2010/wordml", - w15: "http://schemas.microsoft.com/office/word/2012/wordml", - wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", - wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", - wne: "http://schemas.microsoft.com/office/word/2006/wordml", - wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", - Ignorable: "w14 w15 wp14", - })); + this.root.push( + new DocumentAttributes({ + wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", + o: "urn:schemas-microsoft-com:office:office", + r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + m: "http://schemas.openxmlformats.org/officeDocument/2006/math", + v: "urn:schemas-microsoft-com:vml", + wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + w10: "urn:schemas-microsoft-com:office:word", + w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + w14: "http://schemas.microsoft.com/office/word/2010/wordml", + w15: "http://schemas.microsoft.com/office/word/2012/wordml", + wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + wne: "http://schemas.microsoft.com/office/word/2006/wordml", + wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + Ignorable: "w14 w15 wp14", + }), + ); this.nextId = 0; const abstractNumbering = this.createAbstractNumbering(); - abstractNumbering.createLevel(0, "bullet", "•", "left") + abstractNumbering + .createLevel(0, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 720, hanging: 360 })) .addRunProperty(new RunFonts("Symbol", "default")); - abstractNumbering.createLevel(1, "bullet", "o", "left") + abstractNumbering + .createLevel(1, "bullet", "o", "left") .addParagraphProperty(new Indent({ left: 1440, hanging: 360 })) .addRunProperty(new RunFonts("Courier New", "default")); - abstractNumbering.createLevel(2, "bullet", "•", "left") + abstractNumbering + .createLevel(2, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 2160, hanging: 360 })) .addRunProperty(new RunFonts("Wingdings", "default")); - abstractNumbering.createLevel(3, "bullet", "•", "left") + abstractNumbering + .createLevel(3, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 2880, hanging: 360 })) .addRunProperty(new RunFonts("Symbol", "default")); - abstractNumbering.createLevel(4, "bullet", "o", "left") + abstractNumbering + .createLevel(4, "bullet", "o", "left") .addParagraphProperty(new Indent({ left: 3600, hanging: 360 })) .addRunProperty(new RunFonts("Courier New", "default")); - abstractNumbering.createLevel(5, "bullet", "•", "left") + abstractNumbering + .createLevel(5, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 4320, hanging: 360 })) .addRunProperty(new RunFonts("Wingdings", "default")); - abstractNumbering.createLevel(6, "bullet", "•", "left") + abstractNumbering + .createLevel(6, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 5040, hanging: 360 })) .addRunProperty(new RunFonts("Symbol", "default")); - abstractNumbering.createLevel(7, "bullet", "o", "left") + abstractNumbering + .createLevel(7, "bullet", "o", "left") .addParagraphProperty(new Indent({ left: 5760, hanging: 360 })) .addRunProperty(new RunFonts("Courier New", "default")); - abstractNumbering.createLevel(8, "bullet", "•", "left") + abstractNumbering + .createLevel(8, "bullet", "•", "left") .addParagraphProperty(new Indent({ left: 6480, hanging: 360 })) .addRunProperty(new RunFonts("Wingdings", "default")); diff --git a/src/file/paragraph/formatting/alignment.ts b/src/file/paragraph/formatting/alignment.ts index a260aa18ff..fbf0fdcdae 100644 --- a/src/file/paragraph/formatting/alignment.ts +++ b/src/file/paragraph/formatting/alignment.ts @@ -3,14 +3,13 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export type AlignmentOptions = "left" | "center" | "right" | "both"; -export class AlignmentAttributes extends XmlAttributeComponent<{val: AlignmentOptions}> { - protected xmlKeys = {val: "w:val"}; +export class AlignmentAttributes extends XmlAttributeComponent<{ val: AlignmentOptions }> { + protected xmlKeys = { val: "w:val" }; } export class Alignment extends XmlComponent { - constructor(type: AlignmentOptions) { super("w:jc"); - this.root.push(new AlignmentAttributes({val: type})); + this.root.push(new AlignmentAttributes({ val: type })); } } diff --git a/src/file/paragraph/formatting/border.ts b/src/file/paragraph/formatting/border.ts index b8c5142fde..9ceb0c1336 100644 --- a/src/file/paragraph/formatting/border.ts +++ b/src/file/paragraph/formatting/border.ts @@ -2,20 +2,20 @@ import { Attributes, XmlComponent } from "file/xml-components"; class Border extends XmlComponent { - constructor() { super("w:bottom"); - this.root.push(new Attributes({ - color: "auto", - space: "1", - val: "single", - sz: "6", - })); + this.root.push( + new Attributes({ + color: "auto", + space: "1", + val: "single", + sz: "6", + }), + ); } } export class ThematicBreak extends XmlComponent { - constructor() { super("w:pBdr"); this.root.push(new Border()); diff --git a/src/file/paragraph/formatting/indent.ts b/src/file/paragraph/formatting/indent.ts index 98ab4e0212..0b42246689 100644 --- a/src/file/paragraph/formatting/indent.ts +++ b/src/file/paragraph/formatting/indent.ts @@ -20,7 +20,6 @@ class IndentAttributes extends XmlAttributeComponent { describe("#constructor", () => { it("should set the properties given", () => { - const spacing = new Spacing({before: 100, after: 120, line: 150}); + const spacing = new Spacing({ before: 100, after: 120, line: 150 }); const tree = new Formatter().format(spacing); expect(tree).to.deep.equal({ - "w:spacing": [{_attr: {"w:after": 120, "w:before": 100, "w:line": 150}}], + "w:spacing": [{ _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } }], }); }); it("should only set the given properties", () => { - const spacing = new Spacing({before: 100}); + const spacing = new Spacing({ before: 100 }); const tree = new Formatter().format(spacing); expect(tree).to.deep.equal({ - "w:spacing": [{_attr: {"w:before": 100}}], + "w:spacing": [{ _attr: { "w:before": 100 } }], }); }); }); diff --git a/src/file/paragraph/formatting/style.ts b/src/file/paragraph/formatting/style.ts index 08d6500c34..8a4ed4f9ad 100644 --- a/src/file/paragraph/formatting/style.ts +++ b/src/file/paragraph/formatting/style.ts @@ -1,11 +1,12 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class Style extends XmlComponent { - constructor(type: string) { super("w:pStyle"); - this.root.push(new Attributes({ - val: type, - })); + this.root.push( + new Attributes({ + val: type, + }), + ); } } diff --git a/src/file/paragraph/formatting/tab-stop.ts b/src/file/paragraph/formatting/tab-stop.ts index cd65ae76f5..86f61fb747 100644 --- a/src/file/paragraph/formatting/tab-stop.ts +++ b/src/file/paragraph/formatting/tab-stop.ts @@ -2,7 +2,6 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export class TabStop extends XmlComponent { - constructor(tab: Tab) { super("w:tabs"); this.root.push(tab); @@ -11,18 +10,19 @@ export class TabStop extends XmlComponent { export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start"; -export class TabAttributes extends XmlAttributeComponent<{val: TabValue, pos: string | number}> { - protected xmlKeys = {val: "w:val", pos: "w:pos"}; +export class TabAttributes extends XmlAttributeComponent<{ val: TabValue; pos: string | number }> { + protected xmlKeys = { val: "w:val", pos: "w:pos" }; } export class Tab extends XmlComponent { - constructor(value: TabValue, position: string | number) { super("w:tab"); - this.root.push(new TabAttributes({ - val: value, - pos: position, - })); + this.root.push( + new TabAttributes({ + val: value, + pos: position, + }), + ); } } diff --git a/src/file/paragraph/formatting/unordered-list.ts b/src/file/paragraph/formatting/unordered-list.ts index 82a432603a..0b6c4daae0 100644 --- a/src/file/paragraph/formatting/unordered-list.ts +++ b/src/file/paragraph/formatting/unordered-list.ts @@ -1,7 +1,6 @@ import { Attributes, XmlComponent } from "file/xml-components"; export class NumberProperties extends XmlComponent { - constructor(numberId: number, indentLevel: number) { super("w:numPr"); this.root.push(new IndentLevel(indentLevel)); @@ -10,20 +9,23 @@ export class NumberProperties extends XmlComponent { } class IndentLevel extends XmlComponent { - constructor(level: number) { super("w:ilvl"); - this.root.push(new Attributes({ - val: level, - })); + this.root.push( + new Attributes({ + val: level, + }), + ); } } class NumberId extends XmlComponent { constructor(id: number) { super("w:numId"); - this.root.push(new Attributes({ - val: id, - })); + this.root.push( + new Attributes({ + val: id, + }), + ); } } diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 7d9720ce1d..048cca7d03 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -12,7 +12,6 @@ describe("Paragraph", () => { }); describe("#constructor()", () => { - it("should create valid JSON", () => { const stringifiedJson = JSON.stringify(paragraph); let newJson; @@ -37,12 +36,11 @@ describe("Paragraph", () => { const run = paragraph.createTextRun("this is a test run"); expect(run).to.be.instanceof(file.TextRun); const tree = new Formatter().format(paragraph)["w:p"]; - expect(tree).to.be.an("array").which.includes({ - "w:r": [ - {"w:rPr": []}, - {"w:t": [{_attr: {"xml:space": "preserve"}}, "this is a test run"]}, - ], - }); + expect(tree) + .to.be.an("array") + .which.includes({ + "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }], + }); }); }); @@ -53,7 +51,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading1"}}]}], + "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading1" } }] }], }, ], }); @@ -67,7 +65,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading2"}}]}], + "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading2" } }] }], }, ], }); @@ -81,7 +79,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading3"}}]}], + "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading3" } }] }], }, ], }); @@ -95,7 +93,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Title"}}]}], + "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Title" } }] }], }, ], }); @@ -109,7 +107,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [{"w:jc": [{_attr: {"w:val": "center"}}]}], + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }], }, ], }); @@ -121,20 +119,28 @@ describe("Paragraph", () => { paragraph.thematicBreak(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{ - "w:pPr": [{ - "w:pBdr": [{ - "w:bottom": [{ - _attr: { - "w:val": "single", - "w:color": "auto", - "w:space": "1", - "w:sz": "6", - }, - }], - }], - }], - }], + "w:p": [ + { + "w:pPr": [ + { + "w:pBdr": [ + { + "w:bottom": [ + { + _attr: { + "w:val": "single", + "w:color": "auto", + "w:space": "1", + "w:sz": "6", + }, + }, + ], + }, + ], + }, + ], + }, + ], }); }); }); @@ -144,14 +150,14 @@ describe("Paragraph", () => { paragraph.pageBreak(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{ - "w:pPr": [], - }, { - "w:r": [ - {"w:rPr": []}, - {"w:br": [{_attr: {"w:type": "page"}}]}, - ], - }], + "w:p": [ + { + "w:pPr": [], + }, + { + "w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }], + }, + ], }); }); }); @@ -160,23 +166,32 @@ describe("Paragraph", () => { it("should add list paragraph style to JSON", () => { paragraph.bullet(); const tree = new Formatter().format(paragraph); - expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); - expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); + expect(tree) + .to.have.property("w:p") + .which.is.an("array") + .which.has.length.at.least(1); + expect(tree["w:p"][0]) + .to.have.property("w:pPr") + .which.is.an("array") + .which.has.length.at.least(1); expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ - "w:pStyle": [{_attr: {"w:val": "ListParagraph"}}], + "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }], }); }); it("it should add numbered properties", () => { paragraph.bullet(); const tree = new Formatter().format(paragraph); - expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); - expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2); + expect(tree) + .to.have.property("w:p") + .which.is.an("array") + .which.has.length.at.least(1); + expect(tree["w:p"][0]) + .to.have.property("w:pPr") + .which.is.an("array") + .which.has.length.at.least(2); expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({ - "w:numPr": [ - {"w:ilvl": [{_attr: {"w:val": 0}}]}, - {"w:numId": [{_attr: {"w:val": 1}}]}, - ], + "w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 0 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }], }); }); }); @@ -190,10 +205,16 @@ describe("Paragraph", () => { paragraph.setNumbering(letterNumbering, 0); const tree = new Formatter().format(paragraph); - expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); - expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); + expect(tree) + .to.have.property("w:p") + .which.is.an("array") + .which.has.length.at.least(1); + expect(tree["w:p"][0]) + .to.have.property("w:pPr") + .which.is.an("array") + .which.has.length.at.least(1); expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ - "w:pStyle": [{_attr: {"w:val": "ListParagraph"}}], + "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }], }); }); @@ -209,11 +230,11 @@ describe("Paragraph", () => { "w:p": [ { "w:pPr": [ - {"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}]}, + { "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }] }, { "w:numPr": [ - {"w:ilvl": [{_attr: {"w:val": 0}}]}, - {"w:numId": [{_attr: {"w:val": letterNumbering.id}}]}, + { "w:ilvl": [{ _attr: { "w:val": 0 } }] }, + { "w:numId": [{ _attr: { "w:val": letterNumbering.id } }] }, ], }, ], @@ -230,9 +251,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [ - {"w:pStyle": [{_attr: {"w:val": "myFancyStyle"}}]}, - ], + "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "myFancyStyle" } }] }], }, ], }); @@ -246,9 +265,7 @@ describe("Paragraph", () => { expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [ - {"w:ind": [{_attr: {"w:left": 720}}]}, - ], + "w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }], }, ], }); @@ -257,14 +274,12 @@ describe("Paragraph", () => { describe("#spacing", () => { it("should set the paragraph spacing to the given values", () => { - paragraph.spacing({before: 90, line: 50}); + paragraph.spacing({ before: 90, line: 50 }); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ "w:p": [ { - "w:pPr": [ - {"w:spacing": [{_attr: {"w:before": 90, "w:line": 50}}]}, - ], + "w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 90, "w:line": 50 } }] }], }, ], }); @@ -276,7 +291,7 @@ describe("Paragraph", () => { paragraph.keepLines(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{"w:pPr": [{"w:keepLines": []}]}], + "w:p": [{ "w:pPr": [{ "w:keepLines": [] }] }], }); }); }); @@ -286,7 +301,7 @@ describe("Paragraph", () => { paragraph.keepNext(); const tree = new Formatter().format(paragraph); expect(tree).to.deep.equal({ - "w:p": [{"w:pPr": [{"w:keepNext": []}]}], + "w:p": [{ "w:pPr": [{ "w:keepNext": [] }] }], }); }); }); diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 7b54f23350..93fba4ce31 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; export class ParagraphProperties extends XmlComponent { - constructor() { super("w:pPr"); } diff --git a/src/file/paragraph/run/break.ts b/src/file/paragraph/run/break.ts index a40abea558..293071773b 100644 --- a/src/file/paragraph/run/break.ts +++ b/src/file/paragraph/run/break.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; export class Break extends XmlComponent { - constructor() { super("w:br"); } diff --git a/src/file/paragraph/run/caps.ts b/src/file/paragraph/run/caps.ts index bc12d6e256..0b9fb510be 100644 --- a/src/file/paragraph/run/caps.ts +++ b/src/file/paragraph/run/caps.ts @@ -1,14 +1,12 @@ import { XmlComponent } from "file/xml-components"; export class SmallCaps extends XmlComponent { - constructor() { super("w:smallCaps"); } } export class Caps extends XmlComponent { - constructor() { super("w:caps"); } diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index f6abf1a770..16fb744e5d 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -4,111 +4,122 @@ export { SubScript, SuperScript } from "./script"; export { RunFonts } from "./run-fonts"; export class Bold extends XmlComponent { - constructor() { super("w:b"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Italics extends XmlComponent { - constructor() { super("w:i"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Caps extends XmlComponent { - constructor() { super("w:caps"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Color extends XmlComponent { - constructor(color: string) { super("w:color"); - this.root.push(new Attributes({ - val: color, - })); + this.root.push( + new Attributes({ + val: color, + }), + ); } } export class DoubleStrike extends XmlComponent { - constructor() { super("w:dstrike"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Emboss extends XmlComponent { - constructor() { super("w:emboss"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Imprint extends XmlComponent { - constructor() { super("w:imprint"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Shadow extends XmlComponent { - constructor() { super("w:shadow"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class SmallCaps extends XmlComponent { - constructor() { super("w:smallCaps"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Strike extends XmlComponent { - constructor() { super("w:strike"); - this.root.push(new Attributes({ - val: true, - })); + this.root.push( + new Attributes({ + val: true, + }), + ); } } export class Size extends XmlComponent { - constructor(size: number) { super("w:sz"); - this.root.push(new Attributes({ - val: size, - })); + this.root.push( + new Attributes({ + val: size, + }), + ); } } diff --git a/src/file/paragraph/run/picture-run.ts b/src/file/paragraph/run/picture-run.ts index c211adcaeb..b949dc023e 100644 --- a/src/file/paragraph/run/picture-run.ts +++ b/src/file/paragraph/run/picture-run.ts @@ -3,7 +3,6 @@ import { IMediaData } from "../../media/data"; import { Run } from "../run"; export class PictureRun extends Run { - constructor(imageData: IMediaData) { super(); diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 191aaf715c..0a112b35cb 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class RunProperties extends XmlComponent { - constructor() { super("w:rPr"); } diff --git a/src/file/paragraph/run/run-components/text.spec.ts b/src/file/paragraph/run/run-components/text.spec.ts index 56c6643adc..02bd2c702d 100644 --- a/src/file/paragraph/run/run-components/text.spec.ts +++ b/src/file/paragraph/run/run-components/text.spec.ts @@ -8,16 +8,15 @@ describe("Text", () => { it("creates an empty text run if no text is given", () => { const t = new Text(""); const f = new Formatter().format(t); - expect(f).to.deep.equal({"w:t": [{_attr: {"xml:space": "preserve"}}]}); + expect(f).to.deep.equal({ "w:t": [{ _attr: { "xml:space": "preserve" } }] }); }); it("adds the passed in text to the component", () => { const t = new Text(" this is\n text"); const f = new Formatter().format(t); - expect(f).to.deep.equal({"w:t": [ - {_attr: {"xml:space": "preserve"}}, - " this is\n text", - ]}); + expect(f).to.deep.equal({ + "w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"], + }); }); }); }); diff --git a/src/file/paragraph/run/run-components/text.ts b/src/file/paragraph/run/run-components/text.ts index 36bd17c507..894afad170 100644 --- a/src/file/paragraph/run/run-components/text.ts +++ b/src/file/paragraph/run/run-components/text.ts @@ -1,13 +1,13 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class TextAttributes extends XmlAttributeComponent<{space: "default" | "preserve"}> { - protected xmlKeys = {space: "xml:space"}; +class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { + protected xmlKeys = { space: "xml:space" }; } export class Text extends XmlComponent { constructor(text: string) { super("w:t"); - this.root.push(new TextAttributes({space: "preserve"})); + this.root.push(new TextAttributes({ space: "preserve" })); if (text) { this.root.push(text); } diff --git a/src/file/paragraph/run/run-fonts.spec.ts b/src/file/paragraph/run/run-fonts.spec.ts index 359635d22b..54a84f2c9e 100644 --- a/src/file/paragraph/run/run-fonts.spec.ts +++ b/src/file/paragraph/run/run-fonts.spec.ts @@ -4,19 +4,18 @@ import { Formatter } from "../../../export/formatter"; import { RunFonts } from "./run-fonts"; describe("RunFonts", () => { - describe("#constructor()", () => { it("uses the font name for both ascii and hAnsi", () => { const tree = new Formatter().format(new RunFonts("Times")); expect(tree).to.deep.equal({ - "w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}], + "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }], }); }); it("uses hint if given", () => { const tree = new Formatter().format(new RunFonts("Times", "default")); expect(tree).to.deep.equal({ - "w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}], + "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default" } }], }); }); }); diff --git a/src/file/paragraph/run/run-fonts.ts b/src/file/paragraph/run/run-fonts.ts index 61f8e8758e..0b6b8f9806 100644 --- a/src/file/paragraph/run/run-fonts.ts +++ b/src/file/paragraph/run/run-fonts.ts @@ -15,13 +15,14 @@ class RunFontAttributes extends XmlAttributeComponent { run.underline(); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:u": [{_attr: {"w:val": "single"}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }] }], }); }); @@ -48,9 +46,7 @@ describe("Run", () => { run.underline("double", "990011"); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:u": [{_attr: {"w:val": "double", "w:color": "990011"}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "990011" } }] }] }], }); }); }); @@ -112,9 +108,7 @@ describe("Run", () => { run.font("Times"); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] }], }); }); }); @@ -124,9 +118,7 @@ describe("Run", () => { run.color("001122"); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:color": [{_attr: {"w:val": "001122"}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:color": [{ _attr: { "w:val": "001122" } }] }] }], }); }); }); @@ -136,9 +128,7 @@ describe("Run", () => { run.size(24); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:sz": [{_attr: {"w:val": 24}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }] }], }); }); }); @@ -148,9 +138,7 @@ describe("Run", () => { run.style("myRunStyle"); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [ - {"w:rPr": [{"w:rStyle": [{_attr: {"w:val": "myRunStyle"}}]}]}, - ], + "w:r": [{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "myRunStyle" } }] }] }], }); }); }); diff --git a/src/file/paragraph/run/script.ts b/src/file/paragraph/run/script.ts index 88f0dbddda..b0b4862c16 100644 --- a/src/file/paragraph/run/script.ts +++ b/src/file/paragraph/run/script.ts @@ -1,24 +1,23 @@ import { Attributes, XmlComponent } from "file/xml-components"; export abstract class VerticalAlign extends XmlComponent { - constructor(type: string) { super("w:vertAlign"); - this.root.push(new Attributes({ - val: type, - })); + this.root.push( + new Attributes({ + val: type, + }), + ); } } export class SuperScript extends VerticalAlign { - constructor() { super("superscript"); } } export class SubScript extends VerticalAlign { - constructor() { super("subscript"); } diff --git a/src/file/paragraph/run/style.ts b/src/file/paragraph/run/style.ts index 5382724eb7..7e67205990 100644 --- a/src/file/paragraph/run/style.ts +++ b/src/file/paragraph/run/style.ts @@ -1,13 +1,12 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class StyleAttributes extends XmlAttributeComponent<{val: string}> { - protected xmlKeys = {val: "w:val"}; +class StyleAttributes extends XmlAttributeComponent<{ val: string }> { + protected xmlKeys = { val: "w:val" }; } export class Style extends XmlComponent { - constructor(styleId: string) { super("w:rStyle"); - this.root.push(new StyleAttributes({val: styleId})); + this.root.push(new StyleAttributes({ val: styleId })); } } diff --git a/src/file/paragraph/run/tab.ts b/src/file/paragraph/run/tab.ts index c6c4a2f0d7..55893862af 100644 --- a/src/file/paragraph/run/tab.ts +++ b/src/file/paragraph/run/tab.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; export class Tab extends XmlComponent { - constructor() { super("w:tab"); } diff --git a/src/file/paragraph/run/text-run.spec.ts b/src/file/paragraph/run/text-run.spec.ts index 7fe1b7c3d4..2ed219631d 100644 --- a/src/file/paragraph/run/text-run.spec.ts +++ b/src/file/paragraph/run/text-run.spec.ts @@ -7,14 +7,12 @@ describe("TextRun", () => { let run: TextRun; describe("#constructor()", () => { - it("should add text into run", () => { run = new TextRun("test"); const f = new Formatter().format(run); - expect(f).to.deep.equal({"w:r": [ - {"w:rPr": []}, - {"w:t": [{_attr: {"xml:space": "preserve"}}, "test"]}, - ]}); + expect(f).to.deep.equal({ + "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }], + }); }); }); }); diff --git a/src/file/paragraph/run/text-run.ts b/src/file/paragraph/run/text-run.ts index c285b5fe82..4b0474edc6 100644 --- a/src/file/paragraph/run/text-run.ts +++ b/src/file/paragraph/run/text-run.ts @@ -2,7 +2,6 @@ import { Run } from "../run"; import { Text } from "./run-components/text"; export class TextRun extends Run { - constructor(text: string) { super(); this.root.push(new Text(text)); diff --git a/src/file/paragraph/run/underline.spec.ts b/src/file/paragraph/run/underline.spec.ts index 386892a750..c9943bb5c5 100644 --- a/src/file/paragraph/run/underline.spec.ts +++ b/src/file/paragraph/run/underline.spec.ts @@ -5,9 +5,7 @@ import { Utility } from "../../../tests/utility"; import * as u from "./underline"; describe("Underline", () => { - describe("#constructor()", () => { - it("should create a new Underline object with u:u as the rootKey", () => { const underline = new u.Underline(); const newJson = Utility.jsonify(underline); @@ -18,7 +16,7 @@ describe("Underline", () => { const underline = new u.Underline(); const tree = new Formatter().format(underline); expect(tree).to.deep.equal({ - "w:u": [{_attr: {"w:val": "single"}}], + "w:u": [{ _attr: { "w:val": "single" } }], }); }); @@ -26,14 +24,13 @@ describe("Underline", () => { const underline = new u.Underline("double", "FF00CC"); const tree = new Formatter().format(underline); expect(tree).to.deep.equal({ - "w:u": [{_attr: {"w:val": "double", "w:color": "FF00CC"}}], + "w:u": [{ _attr: { "w:val": "double", "w:color": "FF00CC" } }], }); }); }); }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should have u:u as the rootKey", () => { const underline = new u.DashDotDotHeavyUnderline(); @@ -50,7 +47,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashDotHeavyUnderline(); @@ -61,7 +57,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashLongHeavyUnderline(); @@ -72,7 +67,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashLongUnderline(); @@ -83,7 +77,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DashUnderline(); @@ -94,7 +87,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DotDashUnderline(); @@ -105,7 +97,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DotDotDashUnderline(); @@ -116,7 +107,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DottedHeavyUnderline(); @@ -127,7 +117,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DottedUnderline(); @@ -138,7 +127,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.DoubleUnderline(); @@ -149,7 +137,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.SingleUnderline(); @@ -160,7 +147,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.ThickUnderline(); @@ -171,7 +157,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WaveUnderline(); @@ -182,7 +167,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WavyDoubleUnderline(); @@ -193,7 +177,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WavyHeavyUnderline(); @@ -204,7 +187,6 @@ describe("DashDotDotHeavyUnderline", () => { }); describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { it("should put value in attribute", () => { const underline = new u.WordsUnderline(); diff --git a/src/file/paragraph/run/underline.ts b/src/file/paragraph/run/underline.ts index f83b5479f9..bb994e040b 100644 --- a/src/file/paragraph/run/underline.ts +++ b/src/file/paragraph/run/underline.ts @@ -1,130 +1,114 @@ import { Attributes, XmlComponent } from "file/xml-components"; export abstract class BaseUnderline extends XmlComponent { - constructor(underlineType: string, color?: string) { super("w:u"); - this.root.push(new Attributes({ - val: underlineType, - color: color, - })); + this.root.push( + new Attributes({ + val: underlineType, + color: color, + }), + ); } } export class Underline extends BaseUnderline { - constructor(underlineType: string = "single", color?: string) { super(underlineType, color); } } export class DashUnderline extends BaseUnderline { - constructor() { super("dash"); } } export class DashDotDotHeavyUnderline extends BaseUnderline { - constructor() { super("dashDotDotHeavy"); } } export class DashDotHeavyUnderline extends BaseUnderline { - constructor() { super("dashDotHeavy"); } } export class DashLongUnderline extends BaseUnderline { - constructor() { super("dashLong"); } } export class DashLongHeavyUnderline extends BaseUnderline { - constructor() { super("dashLongHeavy"); } } export class DotDashUnderline extends BaseUnderline { - constructor() { super("dotDash"); } } export class DotDotDashUnderline extends BaseUnderline { - constructor() { super("dotDotDash"); } } export class DottedUnderline extends BaseUnderline { - constructor() { super("dotted"); } } export class DottedHeavyUnderline extends BaseUnderline { - constructor() { super("dottedHeavy"); } } export class DoubleUnderline extends BaseUnderline { - constructor() { super("double"); } } export class SingleUnderline extends BaseUnderline { - constructor() { super("single"); } } export class ThickUnderline extends BaseUnderline { - constructor() { super("thick"); } } export class WaveUnderline extends BaseUnderline { - constructor() { super("wave"); } } export class WavyDoubleUnderline extends BaseUnderline { - constructor() { super("wavyDouble"); } } export class WavyHeavyUnderline extends BaseUnderline { - constructor() { super("wavyHeavy"); } } export class WordsUnderline extends BaseUnderline { - constructor() { super("words"); } diff --git a/src/file/properties/components.ts b/src/file/properties/components.ts index f4dbd8fd9a..4a7d0a2795 100644 --- a/src/file/properties/components.ts +++ b/src/file/properties/components.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; import { DocumentAttributes } from "../document/document-attributes"; export class Title extends XmlComponent { - constructor(value: string) { super("dc:title"); this.root.push(value); @@ -10,7 +9,6 @@ export class Title extends XmlComponent { } export class Subject extends XmlComponent { - constructor(value: string) { super("dc:subject"); this.root.push(value); @@ -18,7 +16,6 @@ export class Subject extends XmlComponent { } export class Creator extends XmlComponent { - constructor(value: string) { super("dc:creator"); this.root.push(value); @@ -26,7 +23,6 @@ export class Creator extends XmlComponent { } export class Keywords extends XmlComponent { - constructor(value: string) { super("cp:keywords"); this.root.push(value); @@ -34,7 +30,6 @@ export class Keywords extends XmlComponent { } export class Description extends XmlComponent { - constructor(value: string) { super("dc:description"); this.root.push(value); @@ -42,7 +37,6 @@ export class Description extends XmlComponent { } export class LastModifiedBy extends XmlComponent { - constructor(value: string) { super("cp:lastModifiedBy"); this.root.push(value); @@ -50,7 +44,6 @@ export class LastModifiedBy extends XmlComponent { } export class Revision extends XmlComponent { - constructor(value: string) { super("cp:revision"); this.root.push(value); @@ -72,23 +65,25 @@ export abstract class DateComponent extends XmlComponent { } export class Created extends DateComponent { - constructor() { super("dcterms:created"); - this.root.push(new DocumentAttributes({ - type: "dcterms:W3CDTF", - })); + this.root.push( + new DocumentAttributes({ + type: "dcterms:W3CDTF", + }), + ); this.root.push(this.getCurrentDate()); } } export class Modified extends DateComponent { - constructor() { super("dcterms:modified"); - this.root.push(new DocumentAttributes({ - type: "dcterms:W3CDTF", - })); + this.root.push( + new DocumentAttributes({ + type: "dcterms:W3CDTF", + }), + ); this.root.push(this.getCurrentDate()); } } diff --git a/src/file/properties/properties.spec.ts b/src/file/properties/properties.spec.ts index d938873b56..16ee15e4a3 100644 --- a/src/file/properties/properties.spec.ts +++ b/src/file/properties/properties.spec.ts @@ -4,7 +4,6 @@ import { Formatter } from "../../export/formatter"; import { Properties } from "./properties"; describe("Properties", () => { - describe("#constructor()", () => { it("sets the appropriate attributes on the top-level", () => { const properties = new Properties({}); @@ -23,14 +22,12 @@ describe("Properties", () => { }); it("should create properties with a title", () => { - const properties = new Properties({title: "test document"}); + const properties = new Properties({ title: "test document" }); const tree = new Formatter().format(properties); expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]); expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array); expect(Object.keys(tree["cp:coreProperties"][0])).to.deep.equal(["_attr"]); - expect(tree["cp:coreProperties"][1]).to.deep.equal( - {"dc:title": ["test document"]}, - ); + expect(tree["cp:coreProperties"][1]).to.deep.equal({ "dc:title": ["test document"] }); }); it("should create properties with all the attributes given", () => { @@ -60,14 +57,14 @@ describe("Properties", () => { "dcterms:created", "dcterms:modified", ]); - expect(tree["cp:coreProperties"].slice(1, -2).sort((a, b) => key(a) < key(b) ? -1 : 1)).to.deep.equal([ - {"cp:keywords": ["test docx"]}, - {"cp:lastModifiedBy": ["the author"]}, - {"cp:revision": ["123"]}, - {"dc:creator": ["me"]}, - {"dc:description": ["testing document"]}, - {"dc:subject": ["test subject"]}, - {"dc:title": ["test document"]}, + expect(tree["cp:coreProperties"].slice(1, -2).sort((a, b) => (key(a) < key(b) ? -1 : 1))).to.deep.equal([ + { "cp:keywords": ["test docx"] }, + { "cp:lastModifiedBy": ["the author"] }, + { "cp:revision": ["123"] }, + { "dc:creator": ["me"] }, + { "dc:description": ["testing document"] }, + { "dc:subject": ["test subject"] }, + { "dc:title": ["test document"] }, ]); }); }); diff --git a/src/file/properties/properties.ts b/src/file/properties/properties.ts index ca01056fb2..8334826f1f 100644 --- a/src/file/properties/properties.ts +++ b/src/file/properties/properties.ts @@ -13,16 +13,17 @@ export interface IPropertiesOptions { } export class Properties extends XmlComponent { - constructor(options: IPropertiesOptions) { super("cp:coreProperties"); - this.root.push(new DocumentAttributes({ - cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", - dc: "http://purl.org/dc/elements/1.1/", - dcterms: "http://purl.org/dc/terms/", - dcmitype: "http://purl.org/dc/dcmitype/", - xsi: "http://www.w3.org/2001/XMLSchema-instance", - })); + this.root.push( + new DocumentAttributes({ + cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", + dc: "http://purl.org/dc/elements/1.1/", + dcterms: "http://purl.org/dc/terms/", + dcmitype: "http://purl.org/dc/dcmitype/", + xsi: "http://www.w3.org/2001/XMLSchema-instance", + }), + ); if (options.title) { this.root.push(new Title(options.title)); } diff --git a/src/file/relationships/relationship/relationship.ts b/src/file/relationships/relationship/relationship.ts index a19536b09c..e40d43bc5b 100644 --- a/src/file/relationships/relationship/relationship.ts +++ b/src/file/relationships/relationship/relationship.ts @@ -14,10 +14,12 @@ export class Relationship extends XmlComponent { constructor(id: string, type: RelationshipType, target: string) { super("Relationship"); - this.root.push(new RelationshipAttributes({ - id, - type, - target, - })); + this.root.push( + new RelationshipAttributes({ + id, + type, + target, + }), + ); } } diff --git a/src/file/relationships/relationships.ts b/src/file/relationships/relationships.ts index a38d85f828..f338bdd736 100644 --- a/src/file/relationships/relationships.ts +++ b/src/file/relationships/relationships.ts @@ -3,12 +3,13 @@ import { RelationshipsAttributes } from "./attributes"; import { Relationship, RelationshipType } from "./relationship/relationship"; export class Relationships extends XmlComponent { - constructor() { super("Relationships"); - this.root.push(new RelationshipsAttributes({ - xmlns: "http://schemas.openxmlformats.org/package/2006/relationships", - })); + this.root.push( + new RelationshipsAttributes({ + xmlns: "http://schemas.openxmlformats.org/package/2006/relationships", + }), + ); this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"); this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml"); diff --git a/src/file/styles/defaults/index.ts b/src/file/styles/defaults/index.ts index 93211ac5ec..811eb0aa1d 100644 --- a/src/file/styles/defaults/index.ts +++ b/src/file/styles/defaults/index.ts @@ -3,7 +3,6 @@ import { ParagraphPropertiesDefaults } from "./paragraph-properties"; import { RunPropertiesDefaults } from "./run-properties"; export class DocumentDefaults extends XmlComponent { - private runPropertiesDefaults: RunPropertiesDefaults; private paragraphPropertiesDefaults: ParagraphPropertiesDefaults; diff --git a/src/file/styles/defaults/paragraph-properties.ts b/src/file/styles/defaults/paragraph-properties.ts index 4fe9c341ce..536ba316ab 100644 --- a/src/file/styles/defaults/paragraph-properties.ts +++ b/src/file/styles/defaults/paragraph-properties.ts @@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components"; import { ParagraphProperties } from "../../paragraph/properties"; export class ParagraphPropertiesDefaults extends XmlComponent { - constructor() { super("w:pPrDefault"); this.root.push(new ParagraphProperties()); diff --git a/src/file/styles/factory.ts b/src/file/styles/factory.ts index aeb06bedf6..0b5faf048d 100644 --- a/src/file/styles/factory.ts +++ b/src/file/styles/factory.ts @@ -3,12 +3,17 @@ import { Color, Italics, Size } from "../paragraph/run/formatting"; import { Styles } from "./"; // import { DocumentDefaults } from "./defaults"; import { - Heading1Style, Heading2Style, Heading3Style, Heading4Style, Heading5Style, Heading6Style, - ListParagraph, TitleStyle, + Heading1Style, + Heading2Style, + Heading3Style, + Heading4Style, + Heading5Style, + Heading6Style, + ListParagraph, + TitleStyle, } from "./style"; export class DefaultStylesFactory { - public newInstance(): Styles { const styles = new Styles(); styles.createDocumentDefaults(); diff --git a/src/file/styles/index.ts b/src/file/styles/index.ts index 9c54752998..5d8e89ee10 100644 --- a/src/file/styles/index.ts +++ b/src/file/styles/index.ts @@ -4,18 +4,18 @@ import { DocumentDefaults } from "./defaults"; import { ParagraphStyle } from "./style"; export class Styles extends XmlComponent { - constructor() { super("w:styles"); - this.root.push(new DocumentAttributes({ - mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", - r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", - w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", - w14: "http://schemas.microsoft.com/office/word/2010/wordml", - w15: "http://schemas.microsoft.com/office/word/2012/wordml", - Ignorable: "w14 w15", - })); - + this.root.push( + new DocumentAttributes({ + mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", + r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + w14: "http://schemas.microsoft.com/office/word/2010/wordml", + w15: "http://schemas.microsoft.com/office/word/2012/wordml", + Ignorable: "w14 w15", + }), + ); } public push(style: XmlComponent): Styles { diff --git a/src/file/styles/latent-styles/exceptions.ts b/src/file/styles/latent-styles/exceptions.ts index 9bede8257f..4695df55a0 100644 --- a/src/file/styles/latent-styles/exceptions.ts +++ b/src/file/styles/latent-styles/exceptions.ts @@ -19,7 +19,6 @@ export class LatentStyleExceptionAttributes extends XmlAttributeComponent { - protected xmlKeys = {val: "w:val"}; + protected xmlKeys = { val: "w:val" }; } export class Name extends XmlComponent { - constructor(value: string) { super("w:name"); - this.root.push(new ComponentAttributes({val: value})); + this.root.push(new ComponentAttributes({ val: value })); } } export class BasedOn extends XmlComponent { - constructor(value: string) { super("w:basedOn"); - this.root.push(new ComponentAttributes({val: value})); + this.root.push(new ComponentAttributes({ val: value })); } } export class Next extends XmlComponent { - constructor(value: string) { super("w:next"); - this.root.push(new ComponentAttributes({val: value})); + this.root.push(new ComponentAttributes({ val: value })); } } export class Link extends XmlComponent { - constructor(value: string) { super("w:link"); - this.root.push(new ComponentAttributes({val: value})); + this.root.push(new ComponentAttributes({ val: value })); } } export class UiPriority extends XmlComponent { - constructor(value: string) { super("w:uiPriority"); // TODO: this value should be a ST_DecimalNumber - this.root.push(new ComponentAttributes({val: value})); + this.root.push(new ComponentAttributes({ val: value })); } } -export class UnhideWhenUsed extends XmlComponent { - -} +export class UnhideWhenUsed extends XmlComponent {} export class QuickFormat extends XmlComponent { - constructor() { super("w:qFormat"); } } -export class TableProperties extends XmlComponent { +export class TableProperties extends XmlComponent {} -} +export class RsId extends XmlComponent {} -export class RsId extends XmlComponent { - -} - -export class SemiHidden extends XmlComponent { - -} +export class SemiHidden extends XmlComponent {} diff --git a/src/file/styles/style/index.ts b/src/file/styles/style/index.ts index 3f45c5805c..50265f182a 100644 --- a/src/file/styles/style/index.ts +++ b/src/file/styles/style/index.ts @@ -22,7 +22,6 @@ class StyleAttributes extends XmlAttributeComponent { } export class Style extends XmlComponent { - constructor(attributes: IStyleAttributes, name?: string) { super("w:style"); this.root.push(new StyleAttributes(attributes)); @@ -37,12 +36,11 @@ export class Style extends XmlComponent { } export class ParagraphStyle extends Style { - private paragraphProperties: paragraph.ParagraphProperties; private runProperties: RunProperties; constructor(styleId: string, name?: string) { - super({type: "paragraph", styleId: styleId}, name); + super({ type: "paragraph", styleId: styleId }, name); this.paragraphProperties = new paragraph.ParagraphProperties(); this.runProperties = new RunProperties(); this.root.push(this.paragraphProperties); @@ -193,7 +191,6 @@ export class ParagraphStyle extends Style { } export class HeadingStyle extends ParagraphStyle { - constructor(styleId: string, name: string) { super(styleId, name); this.basedOn("Normal"); @@ -203,56 +200,48 @@ export class HeadingStyle extends ParagraphStyle { } export class TitleStyle extends HeadingStyle { - constructor() { super("Title", "Title"); } } export class Heading1Style extends HeadingStyle { - constructor() { super("Heading1", "Heading 1"); } } export class Heading2Style extends HeadingStyle { - constructor() { super("Heading2", "Heading 2"); } } export class Heading3Style extends HeadingStyle { - constructor() { super("Heading3", "Heading 3"); } } export class Heading4Style extends HeadingStyle { - constructor() { super("Heading4", "Heading 4"); } } export class Heading5Style extends HeadingStyle { - constructor() { super("Heading5", "Heading 5"); } } export class Heading6Style extends HeadingStyle { - constructor() { super("Heading6", "Heading 6"); } } export class ListParagraph extends ParagraphStyle { - constructor() { super("ListParagraph"); this.root.push(new Name("List Paragraph")); diff --git a/src/file/styles/styles.spec.ts b/src/file/styles/styles.spec.ts index 40e87b8d9b..e8c7bc6f92 100644 --- a/src/file/styles/styles.spec.ts +++ b/src/file/styles/styles.spec.ts @@ -22,26 +22,26 @@ describe("Styles", () => { it("should create a new paragraph style and push it onto this collection", () => { styles.createParagraphStyle("pStyleId"); const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr); - expect(tree).to.deep.equal([{ - "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, - {"w:pPr": []}, - {"w:rPr": []}, - ], - }]); + expect(tree).to.deep.equal([ + { + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }], + }, + ]); }); it("should set the paragraph name if given", () => { styles.createParagraphStyle("pStyleId", "Paragraph Style"); const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr); - expect(tree).to.deep.equal([{ - "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, - {"w:name": [{_attr: {"w:val": "Paragraph Style"}}]}, - {"w:pPr": []}, - {"w:rPr": []}, - ], - }]); + expect(tree).to.deep.equal([ + { + "w:style": [ + { _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } }, + { "w:name": [{ _attr: { "w:val": "Paragraph Style" } }] }, + { "w:pPr": [] }, + { "w:rPr": [] }, + ], + }, + ]); }); }); }); @@ -56,22 +56,23 @@ describe("Style", () => { }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true}}, - ], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } }], }); }); it("should set the name of the style, if given", () => { - const style = new Style({ - type: "paragraph", - styleId: "myStyleId", - }, "Style Name"); + const style = new Style( + { + type: "paragraph", + styleId: "myStyleId", + }, + "Style Name", + ); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:name": [{_attr: {"w:val": "Style Name"}}]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:name": [{ _attr: { "w:val": "Style Name" } }] }, ], }); }); @@ -82,31 +83,31 @@ describe("Style components", () => { it("Name#constructor", () => { const style = new components.Name("Style Name"); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({"w:name": [{_attr: {"w:val": "Style Name"}}]}); + expect(tree).to.deep.equal({ "w:name": [{ _attr: { "w:val": "Style Name" } }] }); }); it("BasedOn#constructor", () => { const style = new components.BasedOn("otherId"); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({"w:basedOn": [{_attr: {"w:val": "otherId"}}]}); + expect(tree).to.deep.equal({ "w:basedOn": [{ _attr: { "w:val": "otherId" } }] }); }); it("Next#constructor", () => { const style = new components.Next("otherId"); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({"w:next": [{_attr: {"w:val": "otherId"}}]}); + expect(tree).to.deep.equal({ "w:next": [{ _attr: { "w:val": "otherId" } }] }); }); it("Link#constructor", () => { const style = new components.Link("otherId"); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({"w:link": [{_attr: {"w:val": "otherId"}}]}); + expect(tree).to.deep.equal({ "w:link": [{ _attr: { "w:val": "otherId" } }] }); }); it("UiPriority#constructor", () => { const style = new components.UiPriority("123"); const tree = new Formatter().format(style); - expect(tree).to.deep.equal({"w:uiPriority": [{_attr: {"w:val": "123"}}]}); + expect(tree).to.deep.equal({ "w:uiPriority": [{ _attr: { "w:val": "123" } }] }); }); }); @@ -116,11 +117,7 @@ describe("ParagraphStyle", () => { const style = new ParagraphStyle("myStyleId"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": []}, - ], + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }], }); }); @@ -129,10 +126,10 @@ describe("ParagraphStyle", () => { const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:name": [{_attr: {"w:val": "Style Name"}}]}, - {"w:pPr": []}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:name": [{ _attr: { "w:val": "Style Name" } }] }, + { "w:pPr": [] }, + { "w:rPr": [] }, ], }); }); @@ -140,43 +137,40 @@ describe("ParagraphStyle", () => { describe("formatting methods: style attributes", () => { it("#basedOn", () => { - const style = new ParagraphStyle("myStyleId") - .basedOn("otherId"); + const style = new ParagraphStyle("myStyleId").basedOn("otherId"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": []}, - {"w:basedOn": [{_attr: {"w:val": "otherId"}}]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { "w:rPr": [] }, + { "w:basedOn": [{ _attr: { "w:val": "otherId" } }] }, ], }); }); it("#quickFormat", () => { - const style = new ParagraphStyle("myStyleId") - .quickFormat(); + const style = new ParagraphStyle("myStyleId").quickFormat(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": []}, - {"w:qFormat": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { "w:rPr": [] }, + { "w:qFormat": [] }, ], }); }); it("#next", () => { - const style = new ParagraphStyle("myStyleId") - .next("otherId"); + const style = new ParagraphStyle("myStyleId").next("otherId"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": []}, - {"w:next": [{_attr: {"w:val": "otherId"}}]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { "w:rPr": [] }, + { "w:next": [{ _attr: { "w:val": "otherId" } }] }, ], }); }); @@ -184,171 +178,176 @@ describe("ParagraphStyle", () => { describe("formatting methods: paragraph properties", () => { it("#indent", () => { - const style = new ParagraphStyle("myStyleId") - .indent({ left: 720 }); + const style = new ParagraphStyle("myStyleId").indent({ left: 720 }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:ind": [{_attr: {"w:left": 720}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#spacing", () => { - const style = new ParagraphStyle("myStyleId") - .spacing({before: 50, after: 150}); + const style = new ParagraphStyle("myStyleId").spacing({ before: 50, after: 150 }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#center", () => { - const style = new ParagraphStyle("myStyleId") - .center(); + const style = new ParagraphStyle("myStyleId").center(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:jc": [{_attr: {"w:val": "center"}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#left", () => { - const style = new ParagraphStyle("myStyleId") - .left(); + const style = new ParagraphStyle("myStyleId").left(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:jc": [{_attr: {"w:val": "left"}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#right", () => { - const style = new ParagraphStyle("myStyleId") - .right(); + const style = new ParagraphStyle("myStyleId").right(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:jc": [{_attr: {"w:val": "right"}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#justified", () => { - const style = new ParagraphStyle("myStyleId") - .justified(); + const style = new ParagraphStyle("myStyleId").justified(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:jc": [{_attr: {"w:val": "both"}}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }], + }, + { "w:rPr": [] }, ], }); }); it("#thematicBreak", () => { - const style = new ParagraphStyle("myStyleId") - .thematicBreak(); + const style = new ParagraphStyle("myStyleId").thematicBreak(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:pBdr": [{"w:bottom": [{_attr: { - "w:color": "auto", - "w:space": "1", - "w:val": "single", - "w:sz": "6", - }}]}]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [ + { + "w:pBdr": [ + { + "w:bottom": [ + { + _attr: { + "w:color": "auto", + "w:space": "1", + "w:val": "single", + "w:sz": "6", + }, + }, + ], + }, + ], + }, + ], + }, + { "w:rPr": [] }, ], }); }); it("#leftTabStop", () => { - const style = new ParagraphStyle("myStyleId") - .leftTabStop(1200); + const style = new ParagraphStyle("myStyleId").leftTabStop(1200); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:tabs": [ - {"w:tab": [{_attr: {"w:val": "left", "w:pos": 1200}}]}, - ]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [ + { + "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }], + }, + ], + }, + { "w:rPr": [] }, ], }); }); it("#maxRightTabStop", () => { - const style = new ParagraphStyle("myStyleId") - .maxRightTabStop(); + const style = new ParagraphStyle("myStyleId").maxRightTabStop(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [ - {"w:tabs": [ - {"w:tab": [{_attr: {"w:val": "right", "w:pos": 9026}}]}, - ]}, - ]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:pPr": [ + { + "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }], + }, + ], + }, + { "w:rPr": [] }, ], }); }); it("#keepLines", () => { - const style = new ParagraphStyle("myStyleId") - .keepLines(); + const style = new ParagraphStyle("myStyleId").keepLines(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [{"w:keepLines": []}]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [{ "w:keepLines": [] }] }, + { "w:rPr": [] }, ], }); }); it("#keepNext", () => { - const style = new ParagraphStyle("myStyleId") - .keepNext(); + const style = new ParagraphStyle("myStyleId").keepNext(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": [{"w:keepNext": []}]}, - {"w:rPr": []}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [{ "w:keepNext": [] }] }, + { "w:rPr": [] }, ], }); }); @@ -356,211 +355,197 @@ describe("ParagraphStyle", () => { describe("formatting methods: run properties", () => { it("#size", () => { - const style = new ParagraphStyle("myStyleId") - .size(24); + const style = new ParagraphStyle("myStyleId").size(24); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:sz": [{_attr: {"w:val": 24}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }], + }, ], }); }); it("#smallCaps", () => { - const style = new ParagraphStyle("myStyleId") - .smallCaps(); + const style = new ParagraphStyle("myStyleId").smallCaps(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:smallCaps": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }], + }, ], }); }); it("#allCaps", () => { - const style = new ParagraphStyle("myStyleId") - .allCaps(); + const style = new ParagraphStyle("myStyleId").allCaps(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:caps": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }], + }, ], }); }); it("#strike", () => { - const style = new ParagraphStyle("myStyleId") - .strike(); + const style = new ParagraphStyle("myStyleId").strike(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:strike": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }], + }, ], }); }); it("#doubleStrike", () => { - const style = new ParagraphStyle("myStyleId") - .doubleStrike(); + const style = new ParagraphStyle("myStyleId").doubleStrike(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:dstrike": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }], + }, ], }); }); it("#subScript", () => { - const style = new ParagraphStyle("myStyleId") - .subScript(); + const style = new ParagraphStyle("myStyleId").subScript(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:vertAlign": [{_attr: {"w:val": "subscript"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }], + }, ], }); }); it("#superScript", () => { - const style = new ParagraphStyle("myStyleId") - .superScript(); + const style = new ParagraphStyle("myStyleId").superScript(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:vertAlign": [{_attr: {"w:val": "superscript"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }], + }, ], }); }); it("#font", () => { - const style = new ParagraphStyle("myStyleId") - .font("Times"); + const style = new ParagraphStyle("myStyleId").font("Times"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] }, ], }); }); it("#bold", () => { - const style = new ParagraphStyle("myStyleId") - .bold(); + const style = new ParagraphStyle("myStyleId").bold(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:b": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }], + }, ], }); }); it("#italics", () => { - const style = new ParagraphStyle("myStyleId") - .italics(); + const style = new ParagraphStyle("myStyleId").italics(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:i": [{_attr: {"w:val": true}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }], + }, ], }); }); describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { - const style = new ParagraphStyle("myStyleId") - .underline(); + const style = new ParagraphStyle("myStyleId").underline(); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:u": [{_attr: {"w:val": "single"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }], + }, ], }); }); it("should set the style if given", () => { - const style = new ParagraphStyle("myStyleId") - .underline("double"); + const style = new ParagraphStyle("myStyleId").underline("double"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:u": [{_attr: {"w:val": "double"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }], + }, ], }); }); it("should set the style and color if given", () => { - const style = new ParagraphStyle("myStyleId") - .underline("double", "005599"); + const style = new ParagraphStyle("myStyleId").underline("double", "005599"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }], + }, ], }); }); }); it("#color", () => { - const style = new ParagraphStyle("myStyleId") - .color("123456"); + const style = new ParagraphStyle("myStyleId").color("123456"); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ - {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, - {"w:pPr": []}, - {"w:rPr": [ - {"w:color": [{_attr: {"w:val": "123456"}}]}, - ]}, + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }], + }, ], }); }); diff --git a/src/file/table/grid.spec.ts b/src/file/table/grid.spec.ts index b032ec16db..d8ace5ccef 100644 --- a/src/file/table/grid.spec.ts +++ b/src/file/table/grid.spec.ts @@ -9,14 +9,14 @@ describe("GridCol", () => { const grid = new GridCol(1234); const tree = new Formatter().format(grid); expect(tree).to.deep.equal({ - "w:gridCol": [{_attr: {"w:w": 1234}}], + "w:gridCol": [{ _attr: { "w:w": 1234 } }], }); }); it("does not set a width attribute if not given", () => { const grid = new GridCol(); const tree = new Formatter().format(grid); - expect(tree).to.deep.equal({"w:gridCol": []}); + expect(tree).to.deep.equal({ "w:gridCol": [] }); }); }); }); @@ -28,9 +28,9 @@ describe("TableGrid", () => { const tree = new Formatter().format(grid); expect(tree).to.deep.equal({ "w:tblGrid": [ - {"w:gridCol": [{_attr: {"w:w": 1234}}]}, - {"w:gridCol": [{_attr: {"w:w": 321}}]}, - {"w:gridCol": [{_attr: {"w:w": 123}}]}, + { "w:gridCol": [{ _attr: { "w:w": 1234 } }] }, + { "w:gridCol": [{ _attr: { "w:w": 321 } }] }, + { "w:gridCol": [{ _attr: { "w:w": 123 } }] }, ], }); }); diff --git a/src/file/table/grid.ts b/src/file/table/grid.ts index 16bab3fa75..d9338e7dc4 100644 --- a/src/file/table/grid.ts +++ b/src/file/table/grid.ts @@ -7,15 +7,15 @@ export class TableGrid extends XmlComponent { } } -class GridColAttributes extends XmlAttributeComponent<{w: number}> { - protected xmlKeys = {w: "w:w"}; +class GridColAttributes extends XmlAttributeComponent<{ w: number }> { + protected xmlKeys = { w: "w:w" }; } export class GridCol extends XmlComponent { constructor(width?: number) { super("w:gridCol"); if (width !== undefined) { - this.root.push(new GridColAttributes({w: width})); + this.root.push(new GridColAttributes({ w: width })); } } } diff --git a/src/file/table/properties.spec.ts b/src/file/table/properties.spec.ts index d095a636a3..b6336c1411 100644 --- a/src/file/table/properties.spec.ts +++ b/src/file/table/properties.spec.ts @@ -8,7 +8,7 @@ describe("TableProperties", () => { it("creates an initially empty property object", () => { const tp = new TableProperties(); const tree = new Formatter().format(tp); - expect(tree).to.deep.equal({"w:tblPr": []}); + expect(tree).to.deep.equal({ "w:tblPr": [] }); }); }); @@ -17,9 +17,7 @@ describe("TableProperties", () => { const tp = new TableProperties().setWidth("dxa", 1234); const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ - "w:tblPr": [ - {"w:tblW": [{_attr: {"w:type": "dxa", "w:w": 1234}}]}, - ], + "w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }], }); }); }); @@ -29,9 +27,7 @@ describe("TableProperties", () => { const tp = new TableProperties().fixedWidthLayout(); const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ - "w:tblPr": [ - {"w:tblLayout": [{_attr: {"w:type": "fixed"}}]}, - ], + "w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }], }); }); }); diff --git a/src/file/table/properties.ts b/src/file/table/properties.ts index c11797c1fd..2321429551 100644 --- a/src/file/table/properties.ts +++ b/src/file/table/properties.ts @@ -24,25 +24,25 @@ interface ITableWidth { } class TableWidthAttributes extends XmlAttributeComponent { - protected xmlKeys = {type: "w:type", w: "w:w"}; + protected xmlKeys = { type: "w:type", w: "w:w" }; } class PreferredTableWidth extends XmlComponent { constructor(type: WidthTypes, w: number | string) { super("w:tblW"); - this.root.push(new TableWidthAttributes({type, w})); + this.root.push(new TableWidthAttributes({ type, w })); } } type TableLayoutOptions = "autofit" | "fixed"; -class TableLayoutAttributes extends XmlAttributeComponent<{type: TableLayoutOptions}> { - protected xmlKeys = {type: "w:type"}; +class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutOptions }> { + protected xmlKeys = { type: "w:type" }; } class TableLayout extends XmlComponent { constructor(type: TableLayoutOptions) { super("w:tblLayout"); - this.root.push(new TableLayoutAttributes({type})); + this.root.push(new TableLayoutAttributes({ type })); } } diff --git a/src/file/table/table.spec.ts b/src/file/table/table.spec.ts index 8d4302249f..fc42be5164 100644 --- a/src/file/table/table.spec.ts +++ b/src/file/table/table.spec.ts @@ -10,17 +10,16 @@ describe("Table", () => { it("creates a table with the correct number of rows and columns", () => { const table = new Table(3, 2); const tree = new Formatter().format(table); - const cell = {"w:tc": [{"w:tcPr": []}, {"w:p": [{"w:pPr": []}]}]}; + const cell = { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] }; expect(tree).to.deep.equal({ "w:tbl": [ - {"w:tblPr": []}, - {"w:tblGrid": [ - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - ]}, - {"w:tr": [{"w:trPr": []}, cell, cell]}, - {"w:tr": [{"w:trPr": []}, cell, cell]}, - {"w:tr": [{"w:trPr": []}, cell, cell]}, + { "w:tblPr": [] }, + { + "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], + }, + { "w:tr": [{ "w:trPr": [] }, cell, cell] }, + { "w:tr": [{ "w:trPr": [] }, cell, cell] }, + { "w:tr": [{ "w:trPr": [] }, cell, cell] }, ], }); }); @@ -29,27 +28,39 @@ describe("Table", () => { describe("#getRow and Row#getCell", () => { it("returns the correct row", () => { const table = new Table(2, 2); - table.getRow(0).getCell(0).addContent(new Paragraph("A1")); - table.getRow(0).getCell(1).addContent(new Paragraph("B1")); - table.getRow(1).getCell(0).addContent(new Paragraph("A2")); - table.getRow(1).getCell(1).addContent(new Paragraph("B2")); + table + .getRow(0) + .getCell(0) + .addContent(new Paragraph("A1")); + table + .getRow(0) + .getCell(1) + .addContent(new Paragraph("B1")); + table + .getRow(1) + .getCell(0) + .addContent(new Paragraph("A2")); + table + .getRow(1) + .getCell(1) + .addContent(new Paragraph("B2")); const tree = new Formatter().format(table); - const cell = (c) => ({"w:tc": [ - {"w:tcPr": []}, - {"w:p": [ - {"w:pPr": []}, - {"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]}, - ]}, - ]}); + const cell = (c) => ({ + "w:tc": [ + { "w:tcPr": [] }, + { + "w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }], + }, + ], + }); expect(tree).to.deep.equal({ "w:tbl": [ - {"w:tblPr": []}, - {"w:tblGrid": [ - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - ]}, - {"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]}, - {"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]}, + { "w:tblPr": [] }, + { + "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], + }, + { "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] }, + { "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] }, ], }); }); @@ -63,22 +74,22 @@ describe("Table", () => { table.getCell(1, 0).addContent(new Paragraph("A2")); table.getCell(1, 1).addContent(new Paragraph("B2")); const tree = new Formatter().format(table); - const cell = (c) => ({"w:tc": [ - {"w:tcPr": []}, - {"w:p": [ - {"w:pPr": []}, - {"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]}, - ]}, - ]}); + const cell = (c) => ({ + "w:tc": [ + { "w:tcPr": [] }, + { + "w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }], + }, + ], + }); expect(tree).to.deep.equal({ "w:tbl": [ - {"w:tblPr": []}, - {"w:tblGrid": [ - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - {"w:gridCol": [{_attr: {"w:w": 1}}]}, - ]}, - {"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]}, - {"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]}, + { "w:tblPr": [] }, + { + "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }], + }, + { "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] }, + { "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] }, ], }); }); @@ -88,11 +99,12 @@ describe("Table", () => { it("sets the preferred width on the table", () => { const table = new Table(2, 2).setWidth("pct", 1000); const tree = new Formatter().format(table); - expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array") + .with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [ - {"w:tblW": [{_attr: {"w:type": "pct", "w:w": 1000}}]}, - ], + "w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }], }); }); }); @@ -101,11 +113,12 @@ describe("Table", () => { it("sets the table to fixed width layout", () => { const table = new Table(2, 2).fixedWidthLayout(); const tree = new Formatter().format(table); - expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array") + .with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [ - {"w:tblLayout": [{_attr: {"w:type": "fixed"}}]}, - ], + "w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }], }); }); }); @@ -115,15 +128,16 @@ describe("Table", () => { it("inserts a paragraph at the end of the cell if it is empty", () => { const table = new Table(1, 1); const tree = new Formatter().format(table); - expect(tree).to.have.property("w:tbl").which.is.an("array"); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array"); const row = tree["w:tbl"].find((x) => x["w:tr"]); expect(row).not.to.be.undefined; - expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); + expect(row["w:tr"]) + .to.be.an("array") + .which.has.length.at.least(1); expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ - "w:tc": [ - {"w:tcPr": []}, - {"w:p": [{"w:pPr": []}]}, - ], + "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }], }); }); @@ -131,14 +145,18 @@ describe("Table", () => { const parentTable = new Table(1, 1); parentTable.getCell(0, 0).addContent(new Table(1, 1)); const tree = new Formatter().format(parentTable); - expect(tree).to.have.property("w:tbl").which.is.an("array"); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array"); const row = tree["w:tbl"].find((x) => x["w:tr"]); expect(row).not.to.be.undefined; - expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); + expect(row["w:tr"]) + .to.be.an("array") + .which.has.length.at.least(1); const cell = row["w:tr"].find((x) => x["w:tc"]); expect(cell).not.to.be.undefined; expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({ - "w:p": [{"w:pPr": []}], + "w:p": [{ "w:pPr": [] }], }); }); @@ -146,17 +164,23 @@ describe("Table", () => { const parentTable = new Table(1, 1); parentTable.getCell(0, 0).addContent(new Paragraph("Hello")); const tree = new Formatter().format(parentTable); - expect(tree).to.have.property("w:tbl").which.is.an("array"); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array"); const row = tree["w:tbl"].find((x) => x["w:tr"]); expect(row).not.to.be.undefined; - expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); + expect(row["w:tr"]) + .to.be.an("array") + .which.has.length.at.least(1); expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ "w:tc": [ - {"w:tcPr": []}, - {"w:p": [ - {"w:pPr": []}, - {"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, "Hello"]}]}, - ]}, + { "w:tcPr": [] }, + { + "w:p": [ + { "w:pPr": [] }, + { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Hello"] }] }, + ], + }, ], }); }); @@ -168,20 +192,25 @@ describe("Table", () => { const para = table.getCell(0, 0).createParagraph("Test paragraph"); expect(para).to.be.an.instanceof(Paragraph); const tree = new Formatter().format(table); - expect(tree).to.have.property("w:tbl").which.is.an("array"); + expect(tree) + .to.have.property("w:tbl") + .which.is.an("array"); const row = tree["w:tbl"].find((x) => x["w:tr"]); expect(row).not.to.be.undefined; - expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); + expect(row["w:tr"]) + .to.be.an("array") + .which.has.length.at.least(1); expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ "w:tc": [ - {"w:tcPr": []}, - {"w:p": [ - {"w:pPr": []}, - {"w:r": [ - {"w:rPr": []}, - {"w:t": [{_attr: {"xml:space": "preserve"}}, "Test paragraph"]}, - ]}, - ]}, + { "w:tcPr": [] }, + { + "w:p": [ + { "w:pPr": [] }, + { + "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Test paragraph"] }], + }, + ], + }, ], }); }); diff --git a/src/file/xml-components/attribute.spec.ts b/src/file/xml-components/attribute.spec.ts index 723ea7df0d..a8962307ab 100644 --- a/src/file/xml-components/attribute.spec.ts +++ b/src/file/xml-components/attribute.spec.ts @@ -4,7 +4,6 @@ import { Attributes } from "./"; describe("Attribute", () => { describe("#constructor()", () => { - it("should have val as defined with populated constructor", () => { const newAttrs = new Attributes({ val: "test", diff --git a/src/file/xml-components/default-attributes.ts b/src/file/xml-components/default-attributes.ts index 60b58f330f..2415124584 100644 --- a/src/file/xml-components/default-attributes.ts +++ b/src/file/xml-components/default-attributes.ts @@ -1,7 +1,7 @@ import { BaseXmlComponent } from "./base"; import { IXmlableObject } from "./xmlable-object"; -export type AttributeMap = {[P in keyof T]: string}; +export type AttributeMap = { [P in keyof T]: string }; export abstract class XmlAttributeComponent extends BaseXmlComponent { protected root: T; @@ -21,6 +21,6 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent { attrs[newKey] = value; } }); - return {_attr: attrs}; + return { _attr: attrs }; } } diff --git a/src/file/xml-components/xml-component.spec.ts b/src/file/xml-components/xml-component.spec.ts index 9bcaa7470a..17d3d4d1cb 100644 --- a/src/file/xml-components/xml-component.spec.ts +++ b/src/file/xml-components/xml-component.spec.ts @@ -3,9 +3,7 @@ import { assert } from "chai"; import { Utility } from "../../tests/utility"; import { XmlComponent } from "./"; -class TestComponent extends XmlComponent { - -} +class TestComponent extends XmlComponent {} describe("XmlComponent", () => { let xmlComponent: TestComponent; @@ -15,7 +13,6 @@ describe("XmlComponent", () => { }); describe("#constructor()", () => { - it("should create an Xml Component which has the correct rootKey", () => { const newJson = Utility.jsonify(xmlComponent); assert.equal(newJson.rootKey, "w:test"); diff --git a/src/file/xml-components/xml-component.ts b/src/file/xml-components/xml-component.ts index ebfbbbc485..d3705478cb 100644 --- a/src/file/xml-components/xml-component.ts +++ b/src/file/xml-components/xml-component.ts @@ -11,12 +11,14 @@ export abstract class XmlComponent extends BaseXmlComponent { } public prepForXml(): IXmlableObject { - const children = this.root.map((comp) => { - if (comp instanceof BaseXmlComponent) { - return comp.prepForXml(); - } - return comp; - }).filter((comp) => comp); // Exclude null, undefined, and empty strings + const children = this.root + .map((comp) => { + if (comp instanceof BaseXmlComponent) { + return comp.prepForXml(); + } + return comp; + }) + .filter((comp) => comp); // Exclude null, undefined, and empty strings return { [this.rootKey]: children, }; diff --git a/src/file/xml-components/xmlable-object.ts b/src/file/xml-components/xmlable-object.ts index b180cab89d..de6d2090da 100644 --- a/src/file/xml-components/xmlable-object.ts +++ b/src/file/xml-components/xmlable-object.ts @@ -1,3 +1,3 @@ export interface IXmlableObject extends Object { - _attr?: { [key: string]: (string | number | boolean) }; + _attr?: { [key: string]: string | number | boolean }; }