fixed all tslint errors

This commit is contained in:
Dolan Miu
2016-05-26 15:08:34 +01:00
parent f075d3b719
commit a2284df881
42 changed files with 253 additions and 254 deletions

View File

@ -5,11 +5,11 @@ export class Body extends XmlComponent {
constructor() { constructor() {
super("w:body"); super("w:body");
//this.root.push(new SectionProperties()); not actually needed // this.root.push(new SectionProperties()); not actually needed
} }
push(component: XmlComponent) { push(component: XmlComponent) {
//this.root.splice(this.body.length - 1, 0, component); // this.root.splice(this.body.length - 1, 0, component);
this.root.push(component); this.root.push(component);
} }
} }

View File

@ -54,8 +54,8 @@ export class DocumentAttributes extends XmlAttributeComponent {
xsi: "xmlns:xsi", xsi: "xmlns:xsi",
type: "xsi:type" type: "xsi:type"
}, properties); }, properties);
this.root = properties this.root = properties;
if (!properties) { if (!properties) {
this.root = {}; this.root = {};

View File

@ -1,5 +1,5 @@
import {XmlComponent} from "../xml-components"; import {XmlComponent} from "../xml-components";
import {DocumentAttributes} from "./document-attributes" import {DocumentAttributes} from "./document-attributes";
import {Body} from "./body"; import {Body} from "./body";
import {Paragraph} from "../paragraph"; import {Paragraph} from "../paragraph";
@ -34,7 +34,7 @@ export class Document extends XmlComponent {
addParagraph(paragraph: Paragraph): void { addParagraph(paragraph: Paragraph): void {
this.body.push(paragraph); this.body.push(paragraph);
} }
clearVariables(): void { clearVariables(): void {
this.body.clearVariables(); this.body.clearVariables();
delete this.body; delete this.body;

View File

@ -14,7 +14,7 @@ class Border extends XmlComponent {
} }
export class ThematicBreak extends XmlComponent { export class ThematicBreak extends XmlComponent {
constructor() { constructor() {
super("w:pBdr"); super("w:pBdr");
this.root.push(new Border()); this.root.push(new Border());

View File

@ -98,9 +98,9 @@ export class Paragraph extends XmlComponent {
this.properties.push(new MaxRightTabStop()); this.properties.push(new MaxRightTabStop());
return this; return this;
} }
leftTabStop(position: number): Paragraph { leftTabStop(position: number): Paragraph {
this.properties.push(new LeftTabStop(position)) this.properties.push(new LeftTabStop(position));
return this; return this;
} }

View File

@ -2,7 +2,7 @@ import {XmlComponent, Attributes} from "../xml-components";
import {Style} from "./style"; import {Style} from "./style";
export class NumberProperties extends XmlComponent { export class NumberProperties extends XmlComponent {
constructor() { constructor() {
super("w:numPr"); super("w:numPr");
this.root.push(new IndentLevel(0)); this.root.push(new IndentLevel(0));

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes} from "../xml-components"; import {XmlComponent, Attributes} from "../xml-components";
export class Bold extends XmlComponent { export class Bold extends XmlComponent {
constructor() { constructor() {
super("w:b"); super("w:b");
this.root.push(new Attributes({ this.root.push(new Attributes({
@ -20,7 +20,7 @@ export class Italics extends XmlComponent {
} }
} }
// needs work. add more types of underline // TODO needs work. add more types of underline
export class Underline extends XmlComponent { export class Underline extends XmlComponent {
constructor() { constructor() {
@ -121,7 +121,7 @@ export class Size extends XmlComponent {
} }
} }
// needs work. Add more types of vertical align // TODO needs work. Add more types of vertical align
export class VerticalAlign extends XmlComponent { export class VerticalAlign extends XmlComponent {
constructor() { constructor() {

View File

@ -4,7 +4,7 @@ import {Bold, Italics, Underline} from "./formatting";
export class Run extends XmlComponent { export class Run extends XmlComponent {
private properties: RunProperties; private properties: RunProperties;
constructor() { constructor() {
super("w:r"); super("w:r");
@ -26,12 +26,12 @@ export class Run extends XmlComponent {
this.properties.push(new Underline()); this.properties.push(new Underline());
return this; return this;
} }
break(): Run { break(): Run {
// TODO // TODO
return this; return this;
} }
tab(): Run { tab(): Run {
// TODO // TODO
return this; return this;

View File

@ -9,7 +9,7 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
super("_attr"); super("_attr");
this.xmlKeys = xmlKeys; this.xmlKeys = xmlKeys;
this.root = properties this.root = properties;
if (!properties) { if (!properties) {
this.root = {}; this.root = {};
@ -19,7 +19,7 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
replaceKey(): void { replaceKey(): void {
if (this.root !== undefined) { if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => { _.forOwn(this.root, (value, key) => {
var newKey = this.xmlKeys[key]; let newKey = this.xmlKeys[key];
this.root[newKey] = value; this.root[newKey] = value;
delete this.root[key]; delete this.root[key];
}); });

View File

@ -10,8 +10,8 @@ export abstract class XmlComponent extends BaseXmlComponent {
} }
replaceKey(): void { replaceKey(): void {
//console.log(this.rootKey); // console.log(this.rootKey);
//console.log(this.root); // console.log(this.root);
if (this.root !== undefined) { if (this.root !== undefined) {
this.root.forEach(root => { this.root.forEach(root => {
if (root && root instanceof BaseXmlComponent) { if (root && root instanceof BaseXmlComponent) {

View File

@ -1,4 +1,4 @@
import {XmlComponent} from "./" import {XmlComponent} from "./";
import {ParagraphProperties} from "../paragraph/properties"; import {ParagraphProperties} from "../paragraph/properties";
import {RunProperties} from "../run/properties"; import {RunProperties} from "../run/properties";
@ -42,7 +42,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
super(rootKey); super(rootKey);
this.runProperties = new RunProperties(); this.runProperties = new RunProperties();
this.root.push(this.runProperties); this.root.push(this.runProperties);
this.paragraphProperties = new ParagraphProperties(); this.paragraphProperties = new ParagraphProperties();
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
} }

View File

@ -6,8 +6,8 @@ export class Formatter {
format(input: any): Object { format(input: any): Object {
input.clearVariables(); input.clearVariables();
this.replaceKeys(input); this.replaceKeys(input);
var newJson = this.clense(input); let newJson = this.clense(input);
//console.log(JSON.stringify(newJson, null, " ")); // console.log(JSON.stringify(newJson, null, " "));
return newJson; return newJson;
} }
@ -18,7 +18,7 @@ export class Formatter {
} }
private clense(input: any): Object { private clense(input: any): Object {
var newJson = this.jsonify(input); let newJson = this.jsonify(input);
this.deepTraverseJson(newJson, (parent, value, key) => { this.deepTraverseJson(newJson, (parent, value, key) => {
if (key === "properties") { if (key === "properties") {
@ -36,13 +36,13 @@ export class Formatter {
} }
private jsonify(obj: Object): Object { private jsonify(obj: Object): Object {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
private deepTraverseJson(json: Object, lambda: (json: any, value: any, key: any) => void): void { private deepTraverseJson(json: Object, lambda: (json: any, value: any, key: any) => void): void {
_.forOwn(json, (value, key) => { _.forOwn(json, (value, key) => {
if (_.isObject(value) && key !== "xmlKeys" && key != "rootKey") { if (_.isObject(value) && key !== "xmlKeys" && key !== "rootKey") {
this.deepTraverseJson(value, lambda); this.deepTraverseJson(value, lambda);
} }
lambda(json, value, key); lambda(json, value, key);

View File

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as express from "express"; import * as express from "express";
import {Document} from "../../docx/document"; import {Document} from "../../docx/document";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
import {DefaultStylesFactory} from "../../styles/factory" import {DefaultStylesFactory} from "../../styles/factory";
import {Numbering} from "../../numbering"; import {Numbering} from "../../numbering";
export class ExpressPacker extends Packer { export class ExpressPacker extends Packer {
@ -11,8 +11,8 @@ export class ExpressPacker extends Packer {
constructor(document: Document, res: express.Response, styles?: any, properties?: Properties, numbering?: Numbering) { constructor(document: Document, res: express.Response, styles?: any, properties?: Properties, numbering?: Numbering) {
if (!styles) { if (!styles) {
var stylesFactory = new DefaultStylesFactory(); let stylesFactory = new DefaultStylesFactory();
styles = stylesFactory.newInstance() styles = stylesFactory.newInstance();
} }
if (!properties) { if (!properties) {
@ -22,7 +22,7 @@ export class ExpressPacker extends Packer {
lastModifiedBy: "Shan Fu" lastModifiedBy: "Shan Fu"
}); });
} }
if (!numbering) { if (!numbering) {
numbering = new Numbering(); numbering = new Numbering();
} }
@ -30,8 +30,8 @@ export class ExpressPacker extends Packer {
super(document, styles, properties, numbering); super(document, styles, properties, numbering);
this.res = res; this.res = res;
this.res.on('close', () => { this.res.on("close", () => {
return res.status(200).send('OK').end(); return res.status(200).send("OK").end();
}); });
} }

View File

@ -1,23 +1,23 @@
import {Packer} from "./packer"; import {Packer} from "./packer";
import * as fs from 'fs'; import * as fs from "fs";
import {Document} from "../../docx/document"; import {Document} from "../../docx/document";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
import {Numbering} from "../../numbering"; import {Numbering} from "../../numbering";
export class LocalPacker extends Packer { export class LocalPacker extends Packer {
private stream: fs.WriteStream private stream: fs.WriteStream;
constructor(document: Document, style: any, properties: Properties, path: string, numbering?: Numbering) { constructor(document: Document, style: any, properties: Properties, path: string, numbering?: Numbering) {
if (!numbering) { if (!numbering) {
numbering = new Numbering(); numbering = new Numbering();
} }
super(document, style, properties, numbering); super(document, style, properties, numbering);
this.stream = fs.createWriteStream(path); this.stream = fs.createWriteStream(path);
} }
pack(): void { pack(): void {
super.pack(this.stream); super.pack(this.stream);
} }
} }

View File

@ -7,7 +7,7 @@ import {Styles} from "../../styles";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
import {Numbering} from "../../numbering"; import {Numbering} from "../../numbering";
var appRoot = require('app-root-path'); let appRoot = require("app-root-path");
export abstract class Packer { export abstract class Packer {
protected archive: any; protected archive: any;
@ -16,7 +16,7 @@ export abstract class Packer {
private style: Styles; private style: Styles;
private properties: Properties; private properties: Properties;
private numbering: Numbering; private numbering: Numbering;
constructor(document: Document, style: any, properties: Properties, numbering: Numbering) { constructor(document: Document, style: any, properties: Properties, numbering: Numbering) {
this.formatter = new Formatter(); this.formatter = new Formatter();
this.document = document; this.document = document;
@ -25,7 +25,7 @@ export abstract class Packer {
this.numbering = numbering; this.numbering = numbering;
this.archive = archiver.create("zip", {}); this.archive = archiver.create("zip", {});
this.archive.on('error', (err) => { this.archive.on("error", (err) => {
throw err; throw err;
}); });
} }
@ -37,39 +37,39 @@ export abstract class Packer {
{ {
expand: true, expand: true,
cwd: appRoot.path + "/template", cwd: appRoot.path + "/template",
src: ['**', '**/.rels'] src: ["**", "**/.rels"]
} }
]); ]);
//this.archive.file(appRoot.path + "/template/[Content_Types].xml", { name: "[Content_Types].xml" }); // this.archive.file(appRoot.path + "/template/[Content_Types].xml", { name: "[Content_Types].xml" });
//console.log(__dirname + "/packer.js"); // console.log(__dirname + "/packer.js");
//this.archive.file(__dirname + "/packer.js", { name: "/[Content_Types].xml" }); // this.archive.file(__dirname + "/packer.js", { name: "/[Content_Types].xml" });
/*this.archive.directory(appRoot.path + "/template", { /*this.archive.directory(appRoot.path + "/template", {
name: "/root/g.txt", name: "/root/g.txt",
prefix: "root" prefix: "root"
});*/ });*/
var xmlDocument = xml(this.formatter.format(this.document)); let xmlDocument = xml(this.formatter.format(this.document));
var xmlStyles = xml(this.formatter.format(this.style)); let xmlStyles = xml(this.formatter.format(this.style));
var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } }); let xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
var xmlNumbering = xml(this.formatter.format(this.numbering)); let xmlNumbering = xml(this.formatter.format(this.numbering));
//console.log(JSON.stringify(this.numbering, null, " ")); // console.log(JSON.stringify(this.numbering, null, " "));
console.log(xmlNumbering); console.log(xmlNumbering);
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: 'word/document.xml' name: "word/document.xml"
}); });
this.archive.append(xmlStyles, { this.archive.append(xmlStyles, {
name: 'word/styles.xml' name: "word/styles.xml"
}); });
this.archive.append(xmlProperties, { this.archive.append(xmlProperties, {
name: 'docProps/core.xml' name: "docProps/core.xml"
}); });
this.archive.append(xmlNumbering, { this.archive.append(xmlNumbering, {
name: 'word/numbering.xml' name: "word/numbering.xml"
}) });
this.archive.finalize(); this.archive.finalize();
} }

View File

@ -5,12 +5,12 @@ import {MultiLevelType} from "./multi-level-type";
import * as _ from "lodash"; import * as _ from "lodash";
interface AbstractNumberingAttributesProperties { interface AbstractNumberingAttributesProperties {
abstractNumId?: Number, abstractNumId?: number;
restartNumberingAfterBreak?: Number restartNumberingAfterBreak?: number;
} }
class AbstractNumberingAttributes extends XmlAttributeComponent { class AbstractNumberingAttributes extends XmlAttributeComponent {
constructor(properties: AbstractNumberingAttributesProperties) { constructor(properties: AbstractNumberingAttributesProperties) {
super({ super({
abstractNumId: "w:abstractNumId", abstractNumId: "w:abstractNumId",
@ -29,11 +29,11 @@ export class AbstractNumbering extends XmlComponent {
})); }));
this.root.push(new MultiLevelType("hybridMultilevel")); this.root.push(new MultiLevelType("hybridMultilevel"));
} }
addLevel(level: Level): void { addLevel(level: Level): void {
this.root.push(level); this.root.push(level);
} }
clearVariables() { clearVariables() {
_.forEach(this.root, element => { _.forEach(this.root, element => {
element.clearVariables(); element.clearVariables();

View File

@ -1,12 +1,12 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components"; import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
interface IndentAttributesProperties { interface IndentAttributesProperties {
left: number; left: number;
hanging: number; hanging: number;
} }
class IndentAttributes extends XmlAttributeComponent { class IndentAttributes extends XmlAttributeComponent {
constructor(properties: IndentAttributesProperties) { constructor(properties: IndentAttributesProperties) {
super({ super({
left: "w:left", left: "w:left",
@ -16,7 +16,7 @@ class IndentAttributes extends XmlAttributeComponent {
} }
export class Indent extends XmlComponent { export class Indent extends XmlComponent {
constructor(left: number, hanging: number) { constructor(left: number, hanging: number) {
super("w:ind"); super("w:ind");
this.root.push(new IndentAttributes({ this.root.push(new IndentAttributes({

View File

@ -1,5 +1,5 @@
import {MultiPropertyXmlComponent} from "../docx/xml-components"; import {MultiPropertyXmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes" import {DocumentAttributes} from "../docx/document/document-attributes";
import {AbstractNumbering} from "./abstract-numbering"; import {AbstractNumbering} from "./abstract-numbering";
import {Level} from "./level"; import {Level} from "./level";
import {Indent} from "./indent"; import {Indent} from "./indent";
@ -8,7 +8,7 @@ import {Num} from "./num";
import * as _ from "lodash"; import * as _ from "lodash";
export class Numbering extends MultiPropertyXmlComponent { export class Numbering extends MultiPropertyXmlComponent {
constructor() { constructor() {
super("w:numbering"); super("w:numbering");
this.root.push(new DocumentAttributes({ this.root.push(new DocumentAttributes({
@ -30,58 +30,58 @@ export class Numbering extends MultiPropertyXmlComponent {
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14" Ignorable: "w14 w15 wp14"
})); }));
var abstractNumbering = new AbstractNumbering(0); let abstractNumbering = new AbstractNumbering(0);
var level0 = new Level(0, "bullet", "", "left"); let level0 = new Level(0, "bullet", "", "left");
level0.addParagraphProperty(new Indent(720, 360)); level0.addParagraphProperty(new Indent(720, 360));
level0.addRunProperty(new RunFonts("Symbol", "default")); level0.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level0); abstractNumbering.addLevel(level0);
var level1 = new Level(1, "bullet", "o", "left"); let level1 = new Level(1, "bullet", "o", "left");
level1.addParagraphProperty(new Indent(1440, 360)); level1.addParagraphProperty(new Indent(1440, 360));
level1.addRunProperty(new RunFonts("Courier New", "default")); level1.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level1); abstractNumbering.addLevel(level1);
var level2 = new Level(2, "bullet", "", "left"); let level2 = new Level(2, "bullet", "", "left");
level2.addParagraphProperty(new Indent(2160, 360)); level2.addParagraphProperty(new Indent(2160, 360));
level2.addRunProperty(new RunFonts("Wingdings", "default")); level2.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level2); abstractNumbering.addLevel(level2);
var level3 = new Level(3, "bullet", "", "left"); let level3 = new Level(3, "bullet", "", "left");
level3.addParagraphProperty(new Indent(2880, 360)); level3.addParagraphProperty(new Indent(2880, 360));
level3.addRunProperty(new RunFonts("Symbol", "default")); level3.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level3); abstractNumbering.addLevel(level3);
var level4 = new Level(4, "bullet", "o", "left"); let level4 = new Level(4, "bullet", "o", "left");
level4.addParagraphProperty(new Indent(3600, 360)); level4.addParagraphProperty(new Indent(3600, 360));
level4.addRunProperty(new RunFonts("Courier New", "default")); level4.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level4); abstractNumbering.addLevel(level4);
var level5 = new Level(5, "bullet", "", "left"); let level5 = new Level(5, "bullet", "", "left");
level5.addParagraphProperty(new Indent(4320, 360)); level5.addParagraphProperty(new Indent(4320, 360));
level5.addRunProperty(new RunFonts("Wingdings", "default")); level5.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level5); abstractNumbering.addLevel(level5);
var level6 = new Level(6, "bullet", "", "left"); let level6 = new Level(6, "bullet", "", "left");
level6.addParagraphProperty(new Indent(5040, 360)); level6.addParagraphProperty(new Indent(5040, 360));
level6.addRunProperty(new RunFonts("Symbol", "default")); level6.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level6); abstractNumbering.addLevel(level6);
var level7 = new Level(4, "bullet", "o", "left"); let level7 = new Level(4, "bullet", "o", "left");
level7.addParagraphProperty(new Indent(5760, 360)); level7.addParagraphProperty(new Indent(5760, 360));
level7.addRunProperty(new RunFonts("Courier New", "default")); level7.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level7); abstractNumbering.addLevel(level7);
var level8 = new Level(5, "bullet", "", "left"); let level8 = new Level(5, "bullet", "", "left");
level8.addParagraphProperty(new Indent(6480, 360)); level8.addParagraphProperty(new Indent(6480, 360));
level8.addRunProperty(new RunFonts("Wingdings", "default")); level8.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level8); abstractNumbering.addLevel(level8);
this.root.push(abstractNumbering); this.root.push(abstractNumbering);
this.root.push(new Num(1, 0)); this.root.push(new Num(1, 0));
} }
clearVariables() { clearVariables() {
super.clearVariables(); super.clearVariables();
_.forEach(this.root, element => { _.forEach(this.root, element => {

View File

@ -4,8 +4,8 @@ import {RunProperties} from "../docx/run/properties";
import {ParagraphProperties} from "../docx/paragraph/properties"; import {ParagraphProperties} from "../docx/paragraph/properties";
interface LevelAttributesProperties { interface LevelAttributesProperties {
ilvl?: number, ilvl?: number;
tentative?: number tentative?: number;
} }
class LevelAttributes extends XmlAttributeComponent { class LevelAttributes extends XmlAttributeComponent {

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes} from "../docx/xml-components"; import {XmlComponent, Attributes} from "../docx/xml-components";
export class MultiLevelType extends XmlComponent { export class MultiLevelType extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:multiLevelType"); super("w:multiLevelType");
this.root.push(new Attributes({ this.root.push(new Attributes({

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes, XmlAttributeComponent} from "../docx/xml-components"; import {XmlComponent, Attributes, XmlAttributeComponent} from "../docx/xml-components";
class AbstractNumId extends XmlComponent { class AbstractNumId extends XmlComponent {
constructor(value: number) { constructor(value: number) {
super("w:abstractNumId"); super("w:abstractNumId");
this.root.push(new Attributes({ this.root.push(new Attributes({
@ -11,11 +11,11 @@ class AbstractNumId extends XmlComponent {
} }
interface NumAttributesProperties { interface NumAttributesProperties {
numId: number numId: number;
} }
class NumAttributes extends XmlAttributeComponent { class NumAttributes extends XmlAttributeComponent {
constructor(properties: NumAttributesProperties) { constructor(properties: NumAttributesProperties) {
super({ super({
numId: "w:numId" numId: "w:numId"
@ -24,7 +24,7 @@ class NumAttributes extends XmlAttributeComponent {
} }
export class Num extends XmlComponent { export class Num extends XmlComponent {
constructor(numId: number, abstractNumId: number) { constructor(numId: number, abstractNumId: number) {
super("w:num"); super("w:num");
this.root.push(new NumAttributes({ this.root.push(new NumAttributes({

View File

@ -1,13 +1,13 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components"; import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
interface RunFontAttributesProperties { interface RunFontAttributesProperties {
ascii: string; ascii: string;
hAnsi: string; hAnsi: string;
hint: string; hint: string;
} }
class RunFontAttributes extends XmlAttributeComponent { class RunFontAttributes extends XmlAttributeComponent {
constructor(properties: RunFontAttributesProperties) { constructor(properties: RunFontAttributesProperties) {
super({ super({
left: "w:left", left: "w:left",
@ -17,7 +17,7 @@ class RunFontAttributes extends XmlAttributeComponent {
} }
export class RunFonts extends XmlComponent { export class RunFonts extends XmlComponent {
constructor(ascii: string, hint: string) { constructor(ascii: string, hint: string) {
super("w:ind"); super("w:ind");
this.root.push(new RunFontAttributes({ this.root.push(new RunFontAttributes({

View File

@ -43,7 +43,7 @@ export class Description extends XmlUnitComponent {
} }
export class LastModifiedBy extends XmlUnitComponent { export class LastModifiedBy extends XmlUnitComponent {
constructor(value: string) { constructor(value: string) {
super("cp:lastModifiedBy"); super("cp:lastModifiedBy");
this.root = value; this.root = value;
@ -54,22 +54,22 @@ export class Revision extends XmlUnitComponent {
constructor(value: string) { constructor(value: string) {
super("cp:revision"); super("cp:revision");
var revision = value; let revision = value;
this.root = value; this.root = value;
} }
} }
abstract class DateComponent extends XmlComponent { abstract class DateComponent extends XmlComponent {
protected getCurrentDate(): any { protected getCurrentDate(): any {
var date = new Date(), let date = new Date(),
year = date.getFullYear(), year = date.getFullYear(),
month = ('0' + (date.getMonth() + 1)).slice(-2), month = ("0" + (date.getMonth() + 1)).slice(-2),
day = ('0' + date.getDate()).slice(-2), day = ("0" + date.getDate()).slice(-2),
hours = ('0' + date.getHours()).slice(-2), hours = ("0" + date.getHours()).slice(-2),
minutes = ('0' + date.getMinutes()).slice(-2), minutes = ("0" + date.getMinutes()).slice(-2),
seconds = ('0' + date.getSeconds()).slice(-2); seconds = ("0" + date.getSeconds()).slice(-2);
return year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds + 'Z'; return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
} }
} }

View File

@ -3,10 +3,10 @@ import {ParagraphPropertiesDefaults} from "./paragraph-properties";
import {RunPropertiesDefaults} from "./run-properties"; import {RunPropertiesDefaults} from "./run-properties";
export class DocumentDefaults extends XmlComponent { export class DocumentDefaults extends XmlComponent {
private runPropertiesDefaults: RunPropertiesDefaults; private runPropertiesDefaults: RunPropertiesDefaults;
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults; private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
constructor() { constructor() {
super("w:docDefaults"); super("w:docDefaults");
this.runPropertiesDefaults = new RunPropertiesDefaults(); this.runPropertiesDefaults = new RunPropertiesDefaults();
@ -14,7 +14,7 @@ export class DocumentDefaults extends XmlComponent {
this.root.push(this.runPropertiesDefaults); this.root.push(this.runPropertiesDefaults);
this.root.push(this.paragraphPropertiesDefaults); this.root.push(this.paragraphPropertiesDefaults);
} }
clearVariables(): void { clearVariables(): void {
this.runPropertiesDefaults.clearVariables(); this.runPropertiesDefaults.clearVariables();
this.paragraphPropertiesDefaults.clearVariables(); this.paragraphPropertiesDefaults.clearVariables();

View File

@ -5,6 +5,6 @@ export class RunPropertiesDefaults extends XmlComponent {
constructor() { constructor() {
super("w:rPrDefault"); super("w:rPrDefault");
this.root.push(new RunProperties()); this.root.push(new RunProperties());
} }
} }

View File

@ -3,7 +3,7 @@ import {DocumentDefaults} from "./defaults";
import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties"; import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties";
import {RunPropertiesDefaults} from "./defaults/run-properties"; import {RunPropertiesDefaults} from "./defaults/run-properties";
import {Heading1Style, Heading2Style, TitleStyle, Heading3Style, Heading4Style, Heading5Style, Heading6Style, ListParagraph} from "./style"; import {Heading1Style, Heading2Style, TitleStyle, Heading3Style, Heading4Style, Heading5Style, Heading6Style, ListParagraph} from "./style";
//import {StyleAttributes} from "./style/attributes"; // import {StyleAttributes} from "./style/attributes";
import {ParagraphProperties} from "../docx/paragraph/properties"; import {ParagraphProperties} from "../docx/paragraph/properties";
import {RunProperties} from "../docx/run/properties"; import {RunProperties} from "../docx/run/properties";
import {Color, Size, Italics} from "../docx/run/formatting"; import {Color, Size, Italics} from "../docx/run/formatting";
@ -11,46 +11,46 @@ import {Color, Size, Italics} from "../docx/run/formatting";
export class DefaultStylesFactory { export class DefaultStylesFactory {
newInstance(): Styles { newInstance(): Styles {
var styles = new Styles(); let styles = new Styles();
styles.push(new DocumentDefaults()); styles.push(new DocumentDefaults());
var titleStyle = new TitleStyle(); let titleStyle = new TitleStyle();
titleStyle.addRunProperty(new Size(56)); titleStyle.addRunProperty(new Size(56));
styles.push(titleStyle); styles.push(titleStyle);
var heading1Style = new Heading1Style(); let heading1Style = new Heading1Style();
heading1Style.addRunProperty(new Color("2E74B5")); heading1Style.addRunProperty(new Color("2E74B5"));
heading1Style.addRunProperty(new Size(32)); heading1Style.addRunProperty(new Size(32));
styles.push(heading1Style); styles.push(heading1Style);
var heading2Style = new Heading2Style(); let heading2Style = new Heading2Style();
heading2Style.addRunProperty(new Color("2E74B5")); heading2Style.addRunProperty(new Color("2E74B5"));
heading2Style.addRunProperty(new Size(26)); heading2Style.addRunProperty(new Size(26));
styles.push(heading2Style); styles.push(heading2Style);
var heading3Style = new Heading3Style(); let heading3Style = new Heading3Style();
heading3Style.addRunProperty(new Color("1F4D78")); heading3Style.addRunProperty(new Color("1F4D78"));
heading3Style.addRunProperty(new Size(24)); heading3Style.addRunProperty(new Size(24));
styles.push(heading3Style); styles.push(heading3Style);
var heading4Style = new Heading4Style(); let heading4Style = new Heading4Style();
heading4Style.addRunProperty(new Color("2E74B5")); heading4Style.addRunProperty(new Color("2E74B5"));
heading4Style.addRunProperty(new Italics()); heading4Style.addRunProperty(new Italics());
styles.push(heading4Style); styles.push(heading4Style);
var heading5Style = new Heading5Style(); let heading5Style = new Heading5Style();
heading5Style.addRunProperty(new Color("2E74B5")); heading5Style.addRunProperty(new Color("2E74B5"));
styles.push(heading5Style); styles.push(heading5Style);
var heading6Style = new Heading6Style(); let heading6Style = new Heading6Style();
heading6Style.addRunProperty(new Color("1F4D78")); heading6Style.addRunProperty(new Color("1F4D78"));
styles.push(heading6Style); styles.push(heading6Style);
var listParagraph = new ListParagraph(); let listParagraph = new ListParagraph();
//listParagraph.addParagraphProperty(); // listParagraph.addParagraphProperty();
styles.push(listParagraph); styles.push(listParagraph);
//console.log(JSON.stringify(styles, null, " ")); // console.log(JSON.stringify(styles, null, " "));
return styles; return styles;
} }
} }

View File

@ -1,5 +1,5 @@
import {XmlComponent} from "../docx/xml-components"; import {XmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes" import {DocumentAttributes} from "../docx/document/document-attributes";
import {DocumentDefaults} from "./defaults"; import {DocumentDefaults} from "./defaults";
import {LatentStyles} from "./latent-styles"; import {LatentStyles} from "./latent-styles";
import {LatentStyleException} from "./latent-styles/exceptions"; import {LatentStyleException} from "./latent-styles/exceptions";
@ -16,21 +16,21 @@ export class Styles extends XmlComponent {
w14: "http://schemas.microsoft.com/office/word/2010/wordml", w14: "http://schemas.microsoft.com/office/word/2010/wordml",
w15: "http://schemas.microsoft.com/office/word/2012/wordml", w15: "http://schemas.microsoft.com/office/word/2012/wordml",
Ignorable: "w14 w15" Ignorable: "w14 w15"
})) }));
//var latentStyles = new LatentStyles(); // let latentStyles = new LatentStyles();
//latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({ // latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
// name: "Normal" // name: "Normal"
//}))); // })));
//this.root.push(latentStyles); // this.root.push(latentStyles);
} }
push(style: XmlComponent): void { push(style: XmlComponent): void {
this.root.push(style); this.root.push(style);
} }
clearVariables() { clearVariables() {
this.root.forEach(element => { this.root.forEach(element => {
element.clearVariables(); element.clearVariables();
}) });
} }
} }

View File

@ -2,10 +2,10 @@ import {XmlComponent} from "../../../docx/xml-components";
interface LatentStyleExceptionAttributesProperties { interface LatentStyleExceptionAttributesProperties {
name?: string; name?: string;
uiPriority?: string, uiPriority?: string;
qFormat?: string, qFormat?: string;
semiHidden?: string, semiHidden?: string;
unhideWhenUsed?: string unhideWhenUsed?: string;
} }
export class LatentStyleExceptionAttributes extends XmlComponent { export class LatentStyleExceptionAttributes extends XmlComponent {
@ -21,7 +21,7 @@ export class LatentStyleExceptionAttributes extends XmlComponent {
constructor(properties?: LatentStyleExceptionAttributesProperties) { constructor(properties?: LatentStyleExceptionAttributesProperties) {
super("_attr"); super("_attr");
this._attr = properties this._attr = properties;
if (!properties) { if (!properties) {
this._attr = {}; this._attr = {};

View File

@ -2,11 +2,11 @@ import {XmlComponent} from "../../docx/xml-components";
import {LatentStyleException} from "./exceptions"; import {LatentStyleException} from "./exceptions";
export class LatentStyles extends XmlComponent { export class LatentStyles extends XmlComponent {
constructor() { constructor() {
super("w:latentStyles"); super("w:latentStyles");
} }
push(latentException: LatentStyleException): void { push(latentException: LatentStyleException): void {
this.root.push(latentException); this.root.push(latentException);
} }

View File

@ -57,7 +57,7 @@ export class UnhideWhenUsed extends XmlComponent {
} }
export class QuickFormat extends XmlComponent { export class QuickFormat extends XmlComponent {
constructor() { constructor() {
super("w:qFormat"); super("w:qFormat");
} }

View File

@ -23,7 +23,7 @@ export class ParagraphStyle extends Style {
constructor(styleId: string) { constructor(styleId: string) {
var attributes = new StyleAttributes({ let attributes = new StyleAttributes({
type: "paragraph", type: "paragraph",
styleId: styleId styleId: styleId
}); });
@ -111,7 +111,7 @@ export class Heading6Style extends HeadingStyle {
} }
export class ListParagraph extends ParagraphStyle { export class ListParagraph extends ParagraphStyle {
constructor() { constructor() {
super("ListParagraph"); super("ListParagraph");
this.root.push(new Name("List Paragraph")); this.root.push(new Name("List Paragraph"));

View File

@ -4,36 +4,36 @@ import {Attributes} from "../docx/xml-components";
import {assert} from "chai"; import {assert} from "chai";
describe("Attribute", () => { describe("Attribute", () => {
var attributes: Attributes; let attributes: Attributes;
beforeEach(() => { beforeEach(() => {
attributes = new Attributes(); attributes = new Attributes();
}); });
describe('#constructor()', () => { describe("#constructor()", () => {
it("should not add val with empty constructor", () => { it("should not add val with empty constructor", () => {
var newAttrs = new Attributes(); let newAttrs = new Attributes();
var stringifiedJson = JSON.stringify(newAttrs); let stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); let newJson = JSON.parse(stringifiedJson);
assert.isUndefined(newJson.root.val); assert.isUndefined(newJson.root.val);
}); });
it("should have val as defined with populated constructor", () => { it("should have val as defined with populated constructor", () => {
var newAttrs = new Attributes({ let newAttrs = new Attributes({
val: "test" val: "test"
}); });
var stringifiedJson = JSON.stringify(newAttrs); let stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.val, "test"); assert.equal(newJson.root.val, "test");
}); });
it("should have space value as defined with populated constructor", () => { it("should have space value as defined with populated constructor", () => {
var newAttrs = new Attributes({ let newAttrs = new Attributes({
space: "spaceTest" space: "spaceTest"
}); });
var stringifiedJson = JSON.stringify(newAttrs); let stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson); let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.space, "spaceTest"); assert.equal(newJson.root.space, "spaceTest");
}); });
}); });

View File

@ -9,12 +9,12 @@ import {Columns} from "../docx/document/body/columns";
import {DocumentGrid} from "../docx/document/body/doc-grid"; import {DocumentGrid} from "../docx/document/body/doc-grid";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Body", () => { describe("Body", () => {
var body: Body; let body: Body;
beforeEach(() => { beforeEach(() => {
body = new Body(); body = new Body();
@ -28,27 +28,27 @@ describe("Body", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create the Section Properties", () => { it("should create the Section Properties", () => {
var newJson = jsonify(body); let newJson = jsonify(body);
assert.equal(newJson.root[0].rootKey, "w:sectPr"); assert.equal(newJson.root[0].rootKey, "w:sectPr");
}); });
it("should create the Page Size", () => { it("should create the Page Size", () => {
var newJson = jsonify(body); let newJson = jsonify(body);
assert.equal(newJson.root[1].rootKey, "w:pgSz"); assert.equal(newJson.root[1].rootKey, "w:pgSz");
}); });
it("should create the Page Margin", () => { it("should create the Page Margin", () => {
var newJson = jsonify(body); let newJson = jsonify(body);
assert.equal(newJson.root[2].rootKey, "w:pgMar"); assert.equal(newJson.root[2].rootKey, "w:pgMar");
}); });
it("should create the Columns", () => { it("should create the Columns", () => {
var newJson = jsonify(body); let newJson = jsonify(body);
assert.equal(newJson.root[3].rootKey, "w:cols"); assert.equal(newJson.root[3].rootKey, "w:cols");
}); });
it("should create the Document Grid", () => { it("should create the Document Grid", () => {
var newJson = jsonify(body); let newJson = jsonify(body);
assert.equal(newJson.root[4].rootKey, "w:docGrid"); assert.equal(newJson.root[4].rootKey, "w:docGrid");
}); });
}); });

View File

@ -4,7 +4,7 @@ import {ThematicBreak} from "../docx/paragraph/border";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
@ -13,7 +13,7 @@ describe("Border", () => {
}); });
describe("ThematicBreak", () => { describe("ThematicBreak", () => {
var thematicBreak: ThematicBreak; let thematicBreak: ThematicBreak;
beforeEach(() => { beforeEach(() => {
thematicBreak = new ThematicBreak(); thematicBreak = new ThematicBreak();
@ -21,8 +21,8 @@ describe("ThematicBreak", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a Thematic Break with correct border properties", () => { it("should create a Thematic Break with correct border properties", () => {
var newJson = jsonify(thematicBreak); let newJson = jsonify(thematicBreak);
var attributes = { let attributes = {
color: "auto", color: "auto",
space: "1", space: "1",
val: "single", val: "single",
@ -30,5 +30,5 @@ describe("ThematicBreak", () => {
}; };
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes)); assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
}); });
}) });
}); });

View File

@ -4,18 +4,17 @@ import * as docx from "../docx";
import {assert} from "chai"; import {assert} from "chai";
describe("Document", () => { describe("Document", () => {
var document: docx.Document; let document: docx.Document;
beforeEach(() => { beforeEach(() => {
document = new docx.Document(); document = new docx.Document();
}); });
describe('#constructor()', () => { describe("#constructor()", () => {
it("should create valid JSON", () => { it("should create valid JSON", () => {
//console.log(JSON.stringify(document, null, " ")); let stringifiedJson = JSON.stringify(document);
var stringifiedJson = JSON.stringify(document); let newJson;
var newJson;
try { try {
newJson = JSON.parse(stringifiedJson); newJson = JSON.parse(stringifiedJson);

View File

@ -10,70 +10,70 @@ import {Properties} from "../properties";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Formatter", () => { describe("Formatter", () => {
var formatter: Formatter; let formatter: Formatter;
beforeEach(() => { beforeEach(() => {
formatter = new Formatter(); formatter = new Formatter();
}); });
describe('#format()', () => { describe("#format()", () => {
it("should format simple paragraph", () => { it("should format simple paragraph", () => {
var paragraph = new docx.Paragraph(); let paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph); let newJson = formatter.format(paragraph);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["w:p"]); assert.isDefined(newJson["w:p"]);
}); });
it("should remove xmlKeys", () => { it("should remove xmlKeys", () => {
var paragraph = new docx.Paragraph(); let paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph); let newJson = formatter.format(paragraph);
var stringifiedJson = JSON.stringify(newJson); let stringifiedJson = JSON.stringify(newJson);
assert(stringifiedJson.indexOf("xmlKeys") < 0); assert(stringifiedJson.indexOf("xmlKeys") < 0);
}); });
it("should format simple paragraph with bold text", () => { it("should format simple paragraph with bold text", () => {
var paragraph = new docx.Paragraph(); let paragraph = new docx.Paragraph();
paragraph.addText(new docx.TextRun("test").bold()); paragraph.addText(new docx.TextRun("test").bold());
var newJson = formatter.format(paragraph); let newJson = formatter.format(paragraph);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]); assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
}); });
it("should format attributes (rsidSect)", () => { it("should format attributes (rsidSect)", () => {
var attributes = new Attributes({ let attributes = new Attributes({
rsidSect: "test2" rsidSect: "test2"
}); });
var newJson = formatter.format(attributes); let newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["_attr"]["w:rsidSect"]); assert.isDefined(newJson["_attr"]["w:rsidSect"]);
}); });
it("should format attributes (val)", () => { it("should format attributes (val)", () => {
var attributes = new Attributes({ let attributes = new Attributes({
val: "test" val: "test"
}); });
var newJson = formatter.format(attributes); let newJson = formatter.format(attributes);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["_attr"]["w:val"]); assert.isDefined(newJson["_attr"]["w:val"]);
}); });
it("should should change 'p' tag into 'w:p' tag", () => { it("should should change 'p' tag into 'w:p' tag", () => {
var paragraph = new docx.Paragraph(); let paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph); let newJson = formatter.format(paragraph);
assert.isDefined(newJson["w:p"]); assert.isDefined(newJson["w:p"]);
}); });
it("should format Properties object correctly", () => { it("should format Properties object correctly", () => {
var properties = new Properties({ let properties = new Properties({
title: "test document", title: "test document",
creator: "Dolan" creator: "Dolan"
}); });
var newJson = formatter.format(properties); let newJson = formatter.format(properties);
newJson = jsonify(newJson); newJson = jsonify(newJson);
assert.isDefined(newJson["cp:coreProperties"]); assert.isDefined(newJson["cp:coreProperties"]);
}); });

View File

@ -5,35 +5,35 @@
import {LocalPacker} from "../export/packer/local"; import {LocalPacker} from "../export/packer/local";
import {assert} from "chai"; import {assert} from "chai";
import {Document} from "../docx/document" import {Document} from "../docx/document";
import {Properties} from "../properties" import {Properties} from "../properties";
import {DefaultStyle} from "../styles/sample" import {DefaultStyle} from "../styles/sample";
import {Paragraph} from "../docx/paragraph" import {Paragraph} from "../docx/paragraph";
import {DefaultStylesFactory} from "../styles/factory" import {DefaultStylesFactory} from "../styles/factory";
describe.only("Packer", () => { describe.only("Packer", () => {
var packer: LocalPacker; let packer: LocalPacker;
var stylesFactory: DefaultStylesFactory; let stylesFactory: DefaultStylesFactory;
beforeEach(() => { beforeEach(() => {
var document = new Document(); let document = new Document();
var paragraph = new Paragraph("test text"); let paragraph = new Paragraph("test text");
var heading = new Paragraph("Hello world").heading1(); let heading = new Paragraph("Hello world").heading1();
document.addParagraph(new Paragraph("title").title()); document.addParagraph(new Paragraph("title").title());
document.addParagraph(heading); document.addParagraph(heading);
document.addParagraph(new Paragraph("heading 2").heading2()); document.addParagraph(new Paragraph("heading 2").heading2());
document.addParagraph(paragraph); document.addParagraph(paragraph);
var properties = new Properties({ let properties = new Properties({
creator: "Shan Fu", creator: "Shan Fu",
revision: "1", revision: "1",
lastModifiedBy: "Shan Fu" lastModifiedBy: "Shan Fu"
}); });
stylesFactory = new DefaultStylesFactory(); stylesFactory = new DefaultStylesFactory();
packer = new LocalPacker(document, stylesFactory.newInstance(), properties, "build/tests/test.docx"); packer = new LocalPacker(document, stylesFactory.newInstance(), properties, "build/tests/test.docx");
//packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx"); // packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
}); });
describe('#pack()', () => { describe("#pack()", () => {
it("should create a standard docx file", (done) => { it("should create a standard docx file", (done) => {
packer.pack(); packer.pack();

View File

@ -4,23 +4,23 @@ import {Style} from "../docx/paragraph/style";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("ParagraphStyle", () => { describe("ParagraphStyle", () => {
var style: Style; let style: Style;
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a style with given value", () => { it("should create a style with given value", () => {
style = new Style("test"); style = new Style("test");
var newJson = jsonify(style); let newJson = jsonify(style);
assert.equal(newJson.root[0].root.val, "test"); assert.equal(newJson.root[0].root.val, "test");
}); });
it("should create a style with blank val", () => { it("should create a style with blank val", () => {
style = new Style(""); style = new Style("");
var newJson = jsonify(style); let newJson = jsonify(style);
assert.equal(newJson.root[0].root.val, ""); assert.equal(newJson.root[0].root.val, "");
}); });
}); });

View File

@ -4,22 +4,22 @@ import * as docx from "../docx";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Paragraph", () => { describe("Paragraph", () => {
var paragraph: docx.Paragraph; let paragraph: docx.Paragraph;
beforeEach(() => { beforeEach(() => {
paragraph = new docx.Paragraph(); paragraph = new docx.Paragraph();
}); });
describe('#constructor()', () => { describe("#constructor()", () => {
it("should create valid JSON", () => { it("should create valid JSON", () => {
var stringifiedJson = JSON.stringify(paragraph); let stringifiedJson = JSON.stringify(paragraph);
var newJson; let newJson;
try { try {
newJson = JSON.parse(stringifiedJson); newJson = JSON.parse(stringifiedJson);
@ -30,8 +30,8 @@ describe("Paragraph", () => {
}); });
it("should create have valid properties", () => { it("should create have valid properties", () => {
var stringifiedJson = JSON.stringify(paragraph); let stringifiedJson = JSON.stringify(paragraph);
var newJson = JSON.parse(stringifiedJson); let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root[0].rootKey, "w:pPr"); assert.equal(newJson.root[0].rootKey, "w:pPr");
}); });
}); });
@ -39,7 +39,7 @@ describe("Paragraph", () => {
describe("#heading1()", () => { describe("#heading1()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading1(); paragraph.heading1();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1"); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
}); });
}); });
@ -47,7 +47,7 @@ describe("Paragraph", () => {
describe("#heading2()", () => { describe("#heading2()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading2(); paragraph.heading2();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2"); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
}); });
@ -56,7 +56,7 @@ describe("Paragraph", () => {
describe("#heading3()", () => { describe("#heading3()", () => {
it("should add heading style to JSON", () => { it("should add heading style to JSON", () => {
paragraph.heading3(); paragraph.heading3();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3"); assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
}); });
@ -65,7 +65,7 @@ describe("Paragraph", () => {
describe("#title()", () => { describe("#title()", () => {
it("should add title style to JSON", () => { it("should add title style to JSON", () => {
paragraph.title(); paragraph.title();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title"); assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
}); });
@ -74,7 +74,7 @@ describe("Paragraph", () => {
describe("#center()", () => { describe("#center()", () => {
it("should add center alignment to JSON", () => { it("should add center alignment to JSON", () => {
paragraph.center(); paragraph.center();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "center"); assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
}); });
@ -83,7 +83,7 @@ describe("Paragraph", () => {
describe("#thematicBreak()", () => { describe("#thematicBreak()", () => {
it("should add thematic break to JSON", () => { it("should add thematic break to JSON", () => {
paragraph.thematicBreak(); paragraph.thematicBreak();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr"); assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
}); });
}); });
@ -91,13 +91,13 @@ describe("Paragraph", () => {
describe("#pageBreak()", () => { describe("#pageBreak()", () => {
it("should add page break to JSON", () => { it("should add page break to JSON", () => {
paragraph.pageBreak(); paragraph.pageBreak();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br"); assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
}); });
it("should add page break with 'page' type", () => { it("should add page break with 'page' type", () => {
paragraph.pageBreak(); paragraph.pageBreak();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page"); assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
}); });
}); });
@ -105,13 +105,13 @@ describe("Paragraph", () => {
describe("#bullet()", () => { describe("#bullet()", () => {
it("should add list paragraph style to JSON", () => { it("should add list paragraph style to JSON", () => {
paragraph.bullet(); paragraph.bullet();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph"); assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
}); });
it("it should add numbered properties", () => { it("it should add numbered properties", () => {
paragraph.bullet(); paragraph.bullet();
var newJson = jsonify(paragraph); let newJson = jsonify(paragraph);
assert.isDefined(newJson.root[0].root[2]); assert.isDefined(newJson.root[0].root[2]);
}); });
}); });

View File

@ -4,12 +4,12 @@ import {Properties} from "../properties";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Properties", () => { describe("Properties", () => {
var properties: Properties; let properties: Properties;
beforeEach(() => { beforeEach(() => {
@ -20,8 +20,8 @@ describe("Properties", () => {
properties = new Properties({ properties = new Properties({
title: "test document" title: "test document"
}); });
var newJson = jsonify(properties); let newJson = jsonify(properties);
assert(newJson.root[1].root === "test document"); assert(newJson.root[1].root === "test document");
}); });
}) });
}); });

View File

@ -1,54 +1,54 @@
/// <reference path="../typings/mocha/mocha.d.ts" /> /// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" /> /// <reference path="../typings/chai/chai.d.ts" />
import {Run} from "../docx/run"; import {Run} from "../docx/run";
import {TextRun} from "../docx//run/text-run" import {TextRun} from "../docx//run/text-run";
import {assert} from "chai"; import {assert} from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson); return JSON.parse(stringifiedJson);
} }
describe("Run", () => { describe("Run", () => {
var run: Run; let run: Run;
beforeEach(() => { beforeEach(() => {
run = new Run(); run = new Run();
}); });
describe('#bold()', () => { describe("#bold()", () => {
it("it should add bold to the properties", () => { it("it should add bold to the properties", () => {
run.bold(); run.bold();
var newJson = jsonify(run); let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b"); assert.equal(newJson.root[0].root[0].rootKey, "w:b");
}); });
}); });
describe('#italic()', () => { describe("#italic()", () => {
it("it should add italics to the properties", () => { it("it should add italics to the properties", () => {
run.italic(); run.italic();
var newJson = jsonify(run); let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i"); assert.equal(newJson.root[0].root[0].rootKey, "w:i");
}); });
}); });
describe('#underline()', () => { describe("#underline()", () => {
it("it should add underline to the properties", () => { it("it should add underline to the properties", () => {
run.underline(); run.underline();
var newJson = jsonify(run); let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:u"); assert.equal(newJson.root[0].root[0].rootKey, "w:u");
}); });
}); });
}); });
describe('TextRun', () => { describe("TextRun", () => {
var run: TextRun; let run: TextRun;
describe('#constructor()', () => { describe("#constructor()", () => {
it("should add text into run", () => { it("should add text into run", () => {
run = new TextRun("test"); run = new TextRun("test");
var newJson = jsonify(run); let newJson = jsonify(run);
assert.equal(newJson.root[1].root, "test"); assert.equal(newJson.root[1].root, "test");
}); });
}); });

View File

@ -4,19 +4,19 @@ import {Styles} from "../styles";
import {assert} from "chai"; import {assert} from "chai";
describe("Styles", () => { describe("Styles", () => {
var styles: Styles; let styles: Styles;
beforeEach(() => { beforeEach(() => {
styles = new Styles(); styles = new Styles();
}); });
describe('#constructor()', () => { describe("#constructor()", () => {
it("should create styles with correct rootKey", () => { it("should create styles with correct rootKey", () => {
var styles = new Styles(); let styles = new Styles();
var stringifiedJson = JSON.stringify(styles); let stringifiedJson = JSON.stringify(styles);
var newJson = JSON.parse(stringifiedJson); let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.rootKey, "w:styles"); assert.equal(newJson.rootKey, "w:styles");
}); });
}); });