Files
docx-js/src/file/core-properties/components.ts

90 lines
2.3 KiB
TypeScript
Raw Normal View History

import { XmlComponent } from "file/xml-components";
2017-12-20 00:58:24 +00:00
import { DocumentAttributes } from "../document/document-attributes";
2016-04-03 20:00:30 +01:00
export class Title extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:title");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class Subject extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:subject");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class Creator extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:creator");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class Keywords extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:keywords");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class Description extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("dc:description");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class LastModifiedBy extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:lastModifiedBy");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export class Revision extends XmlComponent {
2016-04-03 20:00:30 +01:00
constructor(value: string) {
2016-04-09 20:16:35 +01:00
super("cp:revision");
this.root.push(value);
2016-04-03 20:00:30 +01:00
}
}
export abstract class DateComponent extends XmlComponent {
protected getCurrentDate(): string {
2017-03-08 21:49:41 +00:00
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);
2016-04-03 20:00:30 +01:00
2016-05-26 15:08:34 +01:00
return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
2016-04-03 20:00:30 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Created extends DateComponent {
2016-04-03 20:00:30 +01:00
constructor() {
2016-04-09 20:16:35 +01:00
super("dcterms:created");
2018-01-23 01:33:12 +00:00
this.root.push(
new DocumentAttributes({
type: "dcterms:W3CDTF",
}),
);
2016-04-09 20:16:35 +01:00
this.root.push(this.getCurrentDate());
2016-04-03 20:00:30 +01:00
}
}
2016-05-02 00:00:45 +01:00
export class Modified extends DateComponent {
2016-04-03 20:00:30 +01:00
constructor() {
2016-04-09 20:16:35 +01:00
super("dcterms:modified");
2018-01-23 01:33:12 +00:00
this.root.push(
new DocumentAttributes({
type: "dcterms:W3CDTF",
}),
);
2016-04-09 20:16:35 +01:00
this.root.push(this.getCurrentDate());
2016-04-03 20:00:30 +01:00
}
2017-03-08 21:49:41 +00:00
}