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

32 lines
838 B
TypeScript
Raw Normal View History

2016-05-23 22:23:05 +01:00
import * as _ from "lodash";
2017-03-08 21:49:41 +00:00
import { BaseXmlComponent } from "./base";
export abstract class XmlAttributeComponent extends BaseXmlComponent {
protected root: object;
private xmlKeys: object;
constructor(xmlKeys: object, properties: object) {
super("_attr");
this.xmlKeys = xmlKeys;
2016-05-26 15:08:34 +01:00
this.root = properties;
if (!properties) {
this.root = {};
}
}
public prepForXml(): {_attr: {[key: string]: (string | number | boolean)}} {
const attrs = {};
2017-03-09 22:56:08 +00:00
if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => {
2017-03-09 22:56:08 +00:00
if (value !== undefined) {
const newKey = this.xmlKeys[key];
attrs[newKey] = value;
}
});
}
return {_attr: attrs};
}
2017-03-08 21:49:41 +00:00
}