Clean up API
This commit is contained in:
@ -12,8 +12,8 @@ var footer = doc.createFooter();
|
|||||||
footer.createParagraph("Footer on another page");
|
footer.createParagraph("Footer on another page");
|
||||||
|
|
||||||
doc.addSection({
|
doc.addSection({
|
||||||
headerId: header.Header.referenceId,
|
headerId: header.Header.ReferenceId,
|
||||||
footerId: footer.Footer.referenceId,
|
footerId: footer.Footer.ReferenceId,
|
||||||
pageNumberStart: 1,
|
pageNumberStart: 1,
|
||||||
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
||||||
});
|
});
|
||||||
@ -21,8 +21,8 @@ doc.addSection({
|
|||||||
doc.createParagraph("hello");
|
doc.createParagraph("hello");
|
||||||
|
|
||||||
doc.addSection({
|
doc.addSection({
|
||||||
headerId: header.Header.referenceId,
|
headerId: header.Header.ReferenceId,
|
||||||
footerId: footer.Footer.referenceId,
|
footerId: footer.Footer.ReferenceId,
|
||||||
pageNumberStart: 1,
|
pageNumberStart: 1,
|
||||||
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
||||||
orientation: docx.PageOrientation.LANDSCAPE,
|
orientation: docx.PageOrientation.LANDSCAPE,
|
||||||
|
@ -6,7 +6,7 @@ const table = doc.createTable(4, 4);
|
|||||||
table
|
table
|
||||||
.getCell(2, 2)
|
.getCell(2, 2)
|
||||||
.addContent(new docx.Paragraph("Hello"))
|
.addContent(new docx.Paragraph("Hello"))
|
||||||
.cellProperties.borders.addTopBorder(docx.BorderStyle.DASH_DOT_STROKED, 3, "red")
|
.CellProperties.Borders.addTopBorder(docx.BorderStyle.DASH_DOT_STROKED, 3, "red")
|
||||||
.addBottomBorder(docx.BorderStyle.DOUBLE, 3, "blue")
|
.addBottomBorder(docx.BorderStyle.DOUBLE, 3, "blue")
|
||||||
.addStartBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "green")
|
.addStartBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "green")
|
||||||
.addEndBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
.addEndBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||||
|
@ -15,12 +15,12 @@ const image5 = docx.Media.addImage(doc, "./demo/images/pizza.gif");
|
|||||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx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LxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`
|
||||||
const image6 = docx.Media.addImageFromBuffer(doc, Buffer.from(imageBase64Data, 'base64'), 100, 100);
|
const image6 = docx.Media.addImageFromBuffer(doc, Buffer.from(imageBase64Data, 'base64'), 100, 100);
|
||||||
|
|
||||||
doc.insertImage(image);
|
doc.addImage(image);
|
||||||
doc.insertImage(image2);
|
doc.addImage(image2);
|
||||||
doc.insertImage(image3);
|
doc.addImage(image3);
|
||||||
doc.insertImage(image4);
|
doc.addImage(image4);
|
||||||
doc.insertImage(image5);
|
doc.addImage(image5);
|
||||||
doc.insertImage(image6);
|
doc.addImage(image6);
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
var exporter = new docx.LocalPacker(doc);
|
||||||
exporter.pack("My Document");
|
exporter.pack("My Document");
|
||||||
|
@ -12,6 +12,51 @@
|
|||||||
|
|
||||||
* Follow the `TSLint` rules
|
* Follow the `TSLint` rules
|
||||||
|
|
||||||
|
## Add vs Create
|
||||||
|
|
||||||
|
This is just a guideline, and the rules can sometimes be broken.
|
||||||
|
|
||||||
|
* Use `create` if the method `new`'s up an element inside:
|
||||||
|
|
||||||
|
```js
|
||||||
|
public createParagraph() {
|
||||||
|
const paragraph = new Paragraph();
|
||||||
|
this.root.push(paragraph);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* Use `add` if you add the element into the method as a parameter:
|
||||||
|
|
||||||
|
```js
|
||||||
|
public createParagraph(paragraph: Paragraph) {
|
||||||
|
this.root.push(paragraph);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getters and Setters
|
||||||
|
|
||||||
|
Getters and Setters are done with a capital letter like so:
|
||||||
|
|
||||||
|
```js
|
||||||
|
public get Level() {
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly `_`:
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```js
|
||||||
|
private get _level: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do**
|
||||||
|
|
||||||
|
```js
|
||||||
|
private get level: string;
|
||||||
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
Please write a test of every file you make and suffix it with `.spec.ts`.
|
Please write a test of every file you make and suffix it with `.spec.ts`.
|
||||||
|
@ -37,8 +37,8 @@ Also all the supported section properties are implemented according to: http://o
|
|||||||
|
|
||||||
// Add new section with another header and footer
|
// Add new section with another header and footer
|
||||||
doc.addSection({
|
doc.addSection({
|
||||||
headerId: header.Header.referenceId,
|
headerId: header.Header.ReferenceId,
|
||||||
footerId: footer.Footer.referenceId,
|
footerId: footer.Footer.ReferenceId,
|
||||||
pageNumberStart: 1,
|
pageNumberStart: 1,
|
||||||
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ export class Compiler {
|
|||||||
name: "_rels/.rels",
|
name: "_rels/.rels",
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const data of this.file.Media.array) {
|
for (const data of this.file.Media.Array) {
|
||||||
this.archive.append(data.stream, {
|
this.archive.append(data.stream, {
|
||||||
name: `word/media/${data.fileName}`,
|
name: `word/media/${data.fileName}`,
|
||||||
});
|
});
|
||||||
|
@ -98,12 +98,12 @@ export class File {
|
|||||||
sectionPropertiesOptions = {
|
sectionPropertiesOptions = {
|
||||||
footerType: FooterReferenceType.DEFAULT,
|
footerType: FooterReferenceType.DEFAULT,
|
||||||
headerType: HeaderReferenceType.DEFAULT,
|
headerType: HeaderReferenceType.DEFAULT,
|
||||||
headerId: header.Header.referenceId,
|
headerId: header.Header.ReferenceId,
|
||||||
footerId: footer.Footer.referenceId,
|
footerId: footer.Footer.ReferenceId,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
sectionPropertiesOptions.headerId = header.Header.referenceId;
|
sectionPropertiesOptions.headerId = header.Header.ReferenceId;
|
||||||
sectionPropertiesOptions.footerId = footer.Footer.referenceId;
|
sectionPropertiesOptions.footerId = footer.Footer.ReferenceId;
|
||||||
}
|
}
|
||||||
this.document = new Document(sectionPropertiesOptions);
|
this.document = new Document(sectionPropertiesOptions);
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ export class File {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public insertImage(image: Image): File {
|
public addImage(image: Image): File {
|
||||||
this.document.addParagraph(image);
|
this.document.addParagraph(image);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ export class File {
|
|||||||
const header = new HeaderWrapper(this.media, this.currentRelationshipId++);
|
const header = new HeaderWrapper(this.media, this.currentRelationshipId++);
|
||||||
this.headerWrapper.push(header);
|
this.headerWrapper.push(header);
|
||||||
this.docRelationships.createRelationship(
|
this.docRelationships.createRelationship(
|
||||||
header.Header.referenceId,
|
header.Header.ReferenceId,
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
|
||||||
`header${this.headerWrapper.length}.xml`,
|
`header${this.headerWrapper.length}.xml`,
|
||||||
);
|
);
|
||||||
@ -193,7 +193,7 @@ export class File {
|
|||||||
const footer = new FooterWrapper(this.media, this.currentRelationshipId++);
|
const footer = new FooterWrapper(this.media, this.currentRelationshipId++);
|
||||||
this.footerWrapper.push(footer);
|
this.footerWrapper.push(footer);
|
||||||
this.docRelationships.createRelationship(
|
this.docRelationships.createRelationship(
|
||||||
footer.Footer.referenceId,
|
footer.Footer.ReferenceId,
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
|
||||||
`footer${this.footerWrapper.length}.xml`,
|
`footer${this.footerWrapper.length}.xml`,
|
||||||
);
|
);
|
||||||
@ -207,7 +207,7 @@ export class File {
|
|||||||
this.document.Body.DefaultSection.addChildElement(
|
this.document.Body.DefaultSection.addChildElement(
|
||||||
new HeaderReference({
|
new HeaderReference({
|
||||||
headerType: HeaderReferenceType.FIRST,
|
headerType: HeaderReferenceType.FIRST,
|
||||||
headerId: headerWrapper.Header.referenceId,
|
headerId: headerWrapper.Header.ReferenceId,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ export class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HeaderByRefNumber(refId: number): HeaderWrapper {
|
public HeaderByRefNumber(refId: number): HeaderWrapper {
|
||||||
const entry = this.headerWrapper.find((h) => h.Header.referenceId === refId);
|
const entry = this.headerWrapper.find((h) => h.Header.ReferenceId === refId);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ export class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FooterByRefNumber(refId: number): FooterWrapper {
|
public FooterByRefNumber(refId: number): FooterWrapper {
|
||||||
const entry = this.footerWrapper.find((h) => h.Footer.referenceId === refId);
|
const entry = this.footerWrapper.find((h) => h.Footer.ReferenceId === refId);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ export class FooterWrapper {
|
|||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||||
`media/${mediaData.fileName}`,
|
`media/${mediaData.fileName}`,
|
||||||
);
|
);
|
||||||
this.insertImage(new Image(mediaData));
|
this.addImage(new Image(mediaData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public insertImage(image: Image): FooterWrapper {
|
public addImage(image: Image): FooterWrapper {
|
||||||
this.footer.addParagraph(image);
|
this.footer.addParagraph(image);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ export class Footer extends XmlComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get referenceId(): number {
|
public get ReferenceId(): number {
|
||||||
return this.refId;
|
return this.refId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ export class HeaderWrapper {
|
|||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||||
`media/${mediaData.fileName}`,
|
`media/${mediaData.fileName}`,
|
||||||
);
|
);
|
||||||
this.insertImage(new Image(mediaData));
|
this.addImage(new Image(mediaData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public insertImage(image: Image): HeaderWrapper {
|
public addImage(image: Image): HeaderWrapper {
|
||||||
this.header.addParagraph(image);
|
this.header.addParagraph(image);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ export class Header extends XmlComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get referenceId(): number {
|
public get ReferenceId(): number {
|
||||||
return this.refId;
|
return this.refId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ export class Media {
|
|||||||
return imageData;
|
return imageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get array(): IMediaData[] {
|
public get Array(): IMediaData[] {
|
||||||
const array = new Array<IMediaData>();
|
const array = new Array<IMediaData>();
|
||||||
|
|
||||||
this.map.forEach((data) => {
|
this.map.forEach((data) => {
|
||||||
|
@ -56,7 +56,7 @@ export class LevelOverride extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get level(): LevelForOverride {
|
public get Level(): LevelForOverride {
|
||||||
let lvl: LevelForOverride;
|
let lvl: LevelForOverride;
|
||||||
if (!this.lvl) {
|
if (!this.lvl) {
|
||||||
lvl = new LevelForOverride(this.levelNum);
|
lvl = new LevelForOverride(this.levelNum);
|
||||||
|
@ -387,9 +387,9 @@ describe("concrete numbering", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets the lvl element if overrideLevel.level is accessed", () => {
|
it("sets the lvl element if overrideLevel.Level is accessed", () => {
|
||||||
const ol = concreteNumbering.overrideLevel(1);
|
const ol = concreteNumbering.overrideLevel(1);
|
||||||
expect(ol.level).to.be.instanceof(LevelForOverride);
|
expect(ol.Level).to.be.instanceof(LevelForOverride);
|
||||||
const tree = new Formatter().format(concreteNumbering);
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
expect(tree["w:num"]).to.include({
|
expect(tree["w:num"]).to.include({
|
||||||
"w:lvlOverride": [
|
"w:lvlOverride": [
|
||||||
|
@ -22,9 +22,9 @@ describe("TableProperties", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#fixedWidthLayout", () => {
|
describe("#setFixedWidthLayout", () => {
|
||||||
it("sets the table to fixed width layout", () => {
|
it("sets the table to fixed width layout", () => {
|
||||||
const tp = new TableProperties().fixedWidthLayout();
|
const tp = new TableProperties().setFixedWidthLayout();
|
||||||
const tree = new Formatter().format(tp);
|
const tree = new Formatter().format(tp);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
|
||||||
|
@ -12,7 +12,7 @@ export class TableProperties extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public fixedWidthLayout(): TableProperties {
|
public setFixedWidthLayout(): TableProperties {
|
||||||
this.root.push(new TableLayout("fixed"));
|
this.root.push(new TableLayout("fixed"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -186,9 +186,9 @@ describe("Table", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#fixedWidthLayout", () => {
|
describe("#setFixedWidthLayout", () => {
|
||||||
it("sets the table to fixed width layout", () => {
|
it("sets the table to fixed width layout", () => {
|
||||||
const table = new Table(2, 2).fixedWidthLayout();
|
const table = new Table(2, 2).setFixedWidthLayout();
|
||||||
const tree = new Formatter().format(table);
|
const tree = new Formatter().format(table);
|
||||||
expect(tree)
|
expect(tree)
|
||||||
.to.have.property("w:tbl")
|
.to.have.property("w:tbl")
|
||||||
|
@ -72,8 +72,8 @@ export class Table extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public fixedWidthLayout(): Table {
|
public setFixedWidthLayout(): Table {
|
||||||
this.properties.fixedWidthLayout();
|
this.properties.setFixedWidthLayout();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ export class TableRow extends XmlComponent {
|
|||||||
|
|
||||||
public addGridSpan(ix: number, cellSpan: number): TableCell {
|
public addGridSpan(ix: number, cellSpan: number): TableCell {
|
||||||
const remainCell = this.cells[ix];
|
const remainCell = this.cells[ix];
|
||||||
remainCell.cellProperties.addGridSpan(cellSpan);
|
remainCell.CellProperties.addGridSpan(cellSpan);
|
||||||
this.cells.splice(ix + 1, cellSpan - 1);
|
this.cells.splice(ix + 1, cellSpan - 1);
|
||||||
this.root.splice(ix + 2, cellSpan - 1);
|
this.root.splice(ix + 2, cellSpan - 1);
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ export class TableCell extends XmlComponent {
|
|||||||
return para;
|
return para;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get cellProperties(): TableCellProperties {
|
public get CellProperties(): TableCellProperties {
|
||||||
return this.properties;
|
return this.properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ export class TableCellProperties extends XmlComponent {
|
|||||||
this.root.push(this.cellBorder);
|
this.root.push(this.cellBorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get borders(): TableCellBorders {
|
public get Borders(): TableCellBorders {
|
||||||
return this.cellBorder;
|
return this.cellBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,8 +167,8 @@ export class TableCellProperties extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setVerticalAlign(vAlignType: VerticalAlign): TableCellProperties {
|
public setVerticalAlign(type: VerticalAlign): TableCellProperties {
|
||||||
this.root.push(new VAlign(vAlignType));
|
this.root.push(new VAlign(type));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ export abstract class BaseXmlComponent {
|
|||||||
|
|
||||||
public abstract prepForXml(): IXmlableObject;
|
public abstract prepForXml(): IXmlableObject;
|
||||||
|
|
||||||
public get isDeleted(): boolean {
|
public get IsDeleted(): boolean {
|
||||||
return this.deleted;
|
return this.deleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
|||||||
const children = this.root
|
const children = this.root
|
||||||
.filter((c) => {
|
.filter((c) => {
|
||||||
if (c instanceof BaseXmlComponent) {
|
if (c instanceof BaseXmlComponent) {
|
||||||
return !c.isDeleted;
|
return !c.IsDeleted;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
],
|
],
|
||||||
"no-implicit-dependencies": false,
|
"no-implicit-dependencies": false,
|
||||||
"no-submodule-imports": false,
|
"no-submodule-imports": false,
|
||||||
"no-null-keyword": true
|
"no-null-keyword": true,
|
||||||
|
"return-undefined": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user