Files
docx-js/ts/docx/xml-components/default-attributes.ts

27 lines
739 B
TypeScript
Raw Normal View History

2017-03-08 21:49:41 +00:00
import { BaseXmlComponent } from "./base";
import { IXmlableObject } from "./xmlable-object";
export type AttributeMap<T> = {[P in keyof T]: string};
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
protected root: T;
protected xmlKeys: AttributeMap<T>;
constructor(properties: T) {
super("_attr");
2016-05-26 15:08:34 +01:00
this.root = properties;
}
public prepForXml(): IXmlableObject {
const attrs = {};
Object.keys(this.root).forEach((key) => {
const value = this.root[key];
if (value !== undefined) {
const newKey = this.xmlKeys[key];
attrs[newKey] = value;
}
});
return {_attr: attrs};
}
2017-03-08 21:49:41 +00:00
}