diff --git a/src/file/border/border.ts b/src/file/border/border.ts
index d494b48998..04e487ff61 100644
--- a/src/file/border/border.ts
+++ b/src/file/border/border.ts
@@ -24,8 +24,11 @@ import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "../va
export interface IBorderOptions {
readonly style: BorderStyle;
+ /** Border color, in hex (eg 'FF00AA') */
readonly color?: string;
+ /** Size of the border in 1/8 pt */
readonly size?: number;
+ /** Spacing offset. Values are specified in pt */
readonly space?: number;
}
diff --git a/src/file/core-properties/components.ts b/src/file/core-properties/components.ts
deleted file mode 100644
index 4a7d0a2795..0000000000
--- a/src/file/core-properties/components.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-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);
- }
-}
-
-export class Subject extends XmlComponent {
- constructor(value: string) {
- super("dc:subject");
- this.root.push(value);
- }
-}
-
-export class Creator extends XmlComponent {
- constructor(value: string) {
- super("dc:creator");
- this.root.push(value);
- }
-}
-
-export class Keywords extends XmlComponent {
- constructor(value: string) {
- super("cp:keywords");
- this.root.push(value);
- }
-}
-
-export class Description extends XmlComponent {
- constructor(value: string) {
- super("dc:description");
- this.root.push(value);
- }
-}
-
-export class LastModifiedBy extends XmlComponent {
- constructor(value: string) {
- super("cp:lastModifiedBy");
- this.root.push(value);
- }
-}
-
-export class Revision extends XmlComponent {
- constructor(value: string) {
- super("cp:revision");
- this.root.push(value);
- }
-}
-
-export abstract class DateComponent extends XmlComponent {
- protected getCurrentDate(): string {
- const date = new Date();
- const year = date.getFullYear();
- const month = ("0" + (date.getMonth() + 1)).slice(-2);
- const day = ("0" + date.getDate()).slice(-2);
- const hours = ("0" + date.getHours()).slice(-2);
- const minutes = ("0" + date.getMinutes()).slice(-2);
- const seconds = ("0" + date.getSeconds()).slice(-2);
-
- return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
- }
-}
-
-export class Created extends DateComponent {
- constructor() {
- super("dcterms:created");
- 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(this.getCurrentDate());
- }
-}
diff --git a/src/file/core-properties/properties.spec.ts b/src/file/core-properties/properties.spec.ts
index 92b2cd6139..4d0b57f0f4 100644
--- a/src/file/core-properties/properties.spec.ts
+++ b/src/file/core-properties/properties.spec.ts
@@ -27,8 +27,7 @@ describe("Properties", () => {
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"]).to.deep.include({ "dc:title": ["test document"] });
});
it("should create properties with all the attributes given", () => {
@@ -44,9 +43,9 @@ describe("Properties", () => {
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
+
const key = (obj) => Object.keys(obj)[0];
- const props = tree["cp:coreProperties"].map(key).sort();
- expect(props).to.deep.equal([
+ expect(tree["cp:coreProperties"].map(key)).to.include.members([
"_attr",
"cp:keywords",
"cp:lastModifiedBy",
@@ -58,7 +57,7 @@ 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([
+ expect(tree["cp:coreProperties"]).to.deep.include.members([
{ "cp:keywords": ["test docx"] },
{ "cp:lastModifiedBy": ["the author"] },
{ "cp:revision": ["123"] },
diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts
index 8a3012fe07..e7ce1f3779 100644
--- a/src/file/core-properties/properties.ts
+++ b/src/file/core-properties/properties.ts
@@ -1,4 +1,4 @@
-import { XmlComponent } from "file/xml-components";
+import { StringContainer, XmlComponent } from "file/xml-components";
import { ICustomPropertyOptions } from "../custom-properties";
import { IDocumentBackgroundOptions } from "../document";
@@ -7,7 +7,6 @@ import { ISectionOptions } from "../file";
import { INumberingOptions } from "../numbering";
import { Paragraph } from "../paragraph";
import { IStylesOptions } from "../styles";
-import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
export interface IPropertiesOptions {
readonly sections: ISectionOptions[];
@@ -36,6 +35,28 @@ export interface IPropertiesOptions {
readonly evenAndOddHeaderAndFooters?: boolean;
}
+//
+
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+
export class CoreProperties extends XmlComponent {
constructor(options: Omit) {
super("cp:coreProperties");
@@ -49,27 +70,39 @@ export class CoreProperties extends XmlComponent {
}),
);
if (options.title) {
- this.root.push(new Title(options.title));
+ this.root.push(new StringContainer("dc:title", options.title));
}
if (options.subject) {
- this.root.push(new Subject(options.subject));
+ this.root.push(new StringContainer("dc:subject", options.subject));
}
if (options.creator) {
- this.root.push(new Creator(options.creator));
+ this.root.push(new StringContainer("dc:creator", options.creator));
}
if (options.keywords) {
- this.root.push(new Keywords(options.keywords));
+ this.root.push(new StringContainer("cp:keywords", options.keywords));
}
if (options.description) {
- this.root.push(new Description(options.description));
+ this.root.push(new StringContainer("dc:description", options.description));
}
if (options.lastModifiedBy) {
- this.root.push(new LastModifiedBy(options.lastModifiedBy));
+ this.root.push(new StringContainer("cp:lastModifiedBy", options.lastModifiedBy));
}
if (options.revision) {
- this.root.push(new Revision(options.revision));
+ this.root.push(new StringContainer("cp:revision", options.revision));
}
- this.root.push(new Created());
- this.root.push(new Modified());
+ this.root.push(new TimestampElement("dcterms:created"));
+ this.root.push(new TimestampElement("dcterms:modified"));
+ }
+}
+
+class TimestampElement extends XmlComponent {
+ constructor(name: string) {
+ super(name);
+ this.root.push(
+ new DocumentAttributes({
+ type: "dcterms:W3CDTF",
+ }),
+ );
+ this.root.push(new Date().toISOString());
}
}
diff --git a/src/file/xml-components/simple-elements.ts b/src/file/xml-components/simple-elements.ts
index 07f188f622..02562e4c58 100644
--- a/src/file/xml-components/simple-elements.ts
+++ b/src/file/xml-components/simple-elements.ts
@@ -52,3 +52,14 @@ export class NumberValueElement extends XmlComponent {
this.root.push(new Attributes({ val }));
}
}
+
+// Simple nodes containing text.
+//
+// new StringContainer("hello", "world")
+// world
+export class StringContainer extends XmlComponent {
+ constructor(name: string, val: string) {
+ super(name);
+ this.root.push(val);
+ }
+}