Socket
Socket
Sign inDemoInstall

docx

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docx - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

build/docx/run/strike.js

11

build/docx/document/document-attributes.js

@@ -5,5 +5,4 @@ "use strict";

class DocumentAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
constructor(properties) {
super({
wpc: "xmlns:wpc",

@@ -32,3 +31,7 @@ mc: "xmlns:mc",

type: "xsi:type",
};
}, properties);
this.root = properties;
if (!properties) {
this.root = {};
}
}

@@ -35,0 +38,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const paragraph_1 = require("../paragraph");
const table_1 = require("../table");
const xml_components_1 = require("../xml-components");

@@ -36,17 +34,8 @@ const body_1 = require("./body");

}
createParagraph(text) {
const para = new paragraph_1.Paragraph(text);
this.addParagraph(para);
return para;
clearVariables() {
this.body.clearVariables();
delete this.body;
}
addTable(table) {
this.body.push(table);
}
createTable(rows, cols) {
const table = new table_1.Table(rows, cols);
this.addTable(table);
return table;
}
}
exports.Document = Document;
//# sourceMappingURL=index.js.map

@@ -11,6 +11,2 @@ "use strict";

exports.TextRun = text_run_1.TextRun;
var picture_run_1 = require("./run/picture-run");
exports.PictureRun = picture_run_1.PictureRun;
var table_1 = require("./table");
exports.Table = table_1.Table;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const picture_run_1 = require("../run/picture-run");
const text_run_1 = require("../run/text-run");
const xml_components_1 = require("../xml-components");
const alignment_1 = require("./alignment");
const border_1 = require("./border");
const indent_1 = require("./indent");
const page_break_1 = require("./page-break");
const properties_1 = require("./properties");
const spacing_1 = require("./spacing");
const style_1 = require("./style");
const tab_stop_1 = require("./tab-stop");
const unordered_list_1 = require("./unordered-list");
class Alignment extends xml_components_1.XmlComponent {
constructor(type) {
super("w:jc");
this.root.push(new xml_components_1.Attributes({
val: type,
}));
}
}
class Paragraph extends xml_components_1.XmlComponent {

@@ -24,16 +28,6 @@ constructor(text) {

}
addRun(run) {
addText(run) {
this.root.push(run);
return this;
}
createTextRun(text) {
const run = new text_run_1.TextRun(text);
this.addRun(run);
return run;
}
createPictureRun(imageData) {
const run = new picture_run_1.PictureRun(imageData);
this.addRun(run);
return run;
}
heading1() {

@@ -64,15 +58,15 @@ this.properties.push(new style_1.Style("Heading1"));

center() {
this.properties.push(new alignment_1.Alignment("center"));
this.properties.push(new Alignment("center"));
return this;
}
left() {
this.properties.push(new alignment_1.Alignment("left"));
this.properties.push(new Alignment("left"));
return this;
}
right() {
this.properties.push(new alignment_1.Alignment("right"));
this.properties.push(new Alignment("right"));
return this;
}
justified() {
this.properties.push(new alignment_1.Alignment("both"));
this.properties.push(new Alignment("both"));
return this;

@@ -106,17 +100,4 @@ }

}
style(styleId) {
this.properties.push(new style_1.Style(styleId));
return this;
}
indent(start, hanging) {
this.properties.push(new indent_1.Indent(start, hanging));
return this;
}
spacing(params) {
this.properties.push(new spacing_1.Spacing(params));
return this;
}
;
}
exports.Paragraph = Paragraph;
//# sourceMappingURL=index.js.map

@@ -7,2 +7,3 @@ "use strict";

super("w:pPr");
this.root.push(new xml_components_1.Attributes());
}

@@ -9,0 +10,0 @@ push(item) {

@@ -10,12 +10,6 @@ "use strict";

}
class TabAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = { val: "w:val", pos: "w:pos" };
}
}
class Tab extends xml_components_1.XmlComponent {
constructor(value, position) {
super("w:tab");
this.root.push(new TabAttributes({
this.root.push(new xml_components_1.Attributes({
val: value,

@@ -22,0 +16,0 @@ pos: position,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const xml_components_1 = require("../xml-components");
var underline_1 = require("./underline");
exports.Underline = underline_1.Underline;
var script_1 = require("./script");
exports.SubScript = script_1.SubScript;
exports.SuperScript = script_1.SuperScript;
var run_fonts_1 = require("./run-fonts");
exports.RunFonts = run_fonts_1.RunFonts;
class Bold extends xml_components_1.XmlComponent {

@@ -12,0 +5,0 @@ constructor() {

@@ -9,3 +9,3 @@ "use strict";

const script_1 = require("./script");
const style_1 = require("./style");
const strike_1 = require("./strike");
const tab_1 = require("./tab");

@@ -28,14 +28,6 @@ const underline_1 = require("./underline");

}
underline(underlineType, color) {
this.properties.push(new underline_1.Underline(underlineType, color));
underline() {
this.properties.push(new underline_1.Underline());
return this;
}
color(color) {
this.properties.push(new formatting_1.Color(color));
return this;
}
size(size) {
this.properties.push(new formatting_1.Size(size));
return this;
}
break() {

@@ -58,7 +50,7 @@ this.root.splice(1, 0, new break_1.Break());

strike() {
this.properties.push(new formatting_1.Strike());
this.properties.push(new strike_1.Strike());
return this;
}
doubleStrike() {
this.properties.push(new formatting_1.DoubleStrike());
this.properties.push(new strike_1.DoubleStrike());
return this;

@@ -78,8 +70,4 @@ }

}
style(styleId) {
this.properties.push(new style_1.Style(styleId));
return this;
}
}
exports.Run = Run;
//# sourceMappingURL=index.js.map

@@ -5,9 +5,8 @@ "use strict";

class RunFontAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
constructor(properties) {
super({
ascii: "w:ascii",
hAnsi: "w:hAnsi",
hint: "w:hint",
};
}, properties);
}

@@ -14,0 +13,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const run_1 = require("../run");
const text_1 = require("./run-components/text");
const text_1 = require("./text");
class TextRun extends run_1.Run {

@@ -6,0 +6,0 @@ constructor(text) {

@@ -14,4 +14,4 @@ "use strict";

class Underline extends BaseUnderline {
constructor(underlineType = "single", color) {
super(underlineType, color);
constructor() {
super("");
}

@@ -18,0 +18,0 @@ }

@@ -5,5 +5,4 @@ "use strict";

class Attributes extends default_attributes_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
constructor(properties) {
super({
val: "w:val",

@@ -28,3 +27,3 @@ color: "w:color",

pos: "w:pos",
};
}, properties);
}

@@ -31,0 +30,0 @@ }

@@ -7,4 +7,6 @@ "use strict";

}
clearVariables() {
}
}
exports.BaseXmlComponent = BaseXmlComponent;
//# sourceMappingURL=base.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const base_1 = require("./base");
class XmlAttributeComponent extends base_1.BaseXmlComponent {
constructor(properties) {
constructor(xmlKeys, properties) {
super("_attr");
this.xmlKeys = xmlKeys;
this.root = properties;
if (!properties) {
this.root = {};
}
}
prepForXml() {
const attrs = {};
Object.keys(this.root).forEach((key) => {
const value = this.root[key];
if (value !== undefined) {
replaceKey() {
if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => {
const newKey = this.xmlKeys[key];
attrs[newKey] = value;
}
});
return { _attr: attrs };
this.root[newKey] = value;
delete this.root[key];
});
this[this.rootKey] = this.root;
delete this.root;
}
}

@@ -20,0 +25,0 @@ }

@@ -7,3 +7,2 @@ "use strict";

const base_1 = require("./base");
exports.BaseXmlComponent = base_1.BaseXmlComponent;
class XmlComponent extends base_1.BaseXmlComponent {

@@ -14,12 +13,12 @@ constructor(rootKey) {

}
prepForXml() {
const children = this.root.map((comp) => {
if (comp instanceof base_1.BaseXmlComponent) {
return comp.prepForXml();
}
return comp;
}).filter((comp) => comp);
return {
[this.rootKey]: children,
};
replaceKey() {
if (this.root !== undefined) {
this.root.forEach((root) => {
if (root && root instanceof base_1.BaseXmlComponent) {
root.replaceKey();
}
});
this[this.rootKey] = this.root;
delete this.root;
}
}

@@ -30,2 +29,4 @@ }

__export(require("./default-attributes"));
__export(require("./unit"));
__export(require("./property"));
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
class Formatter {
format(input) {
return input.prepForXml();
input.clearVariables();
this.replaceKeys(input);
const newJson = this.clense(input);
return newJson;
}
replaceKeys(input) {
input.replaceKey();
return input;
}
clense(input) {
const newJson = this.jsonify(input);
this.deepTraverseJson(newJson, (parent, value, key) => {
if (key === "properties") {
delete parent[key];
}
if (key === "xmlKeys") {
delete parent[key];
}
if (key === "rootKey") {
delete parent[key];
}
});
return newJson;
}
jsonify(obj) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
deepTraverseJson(json, lambda) {
_.forOwn(json, (value, key) => {
if (_.isObject(value) && key !== "xmlKeys" && key !== "rootKey") {
this.deepTraverseJson(value, lambda);
}
lambda(json, value, key);
});
}
}
exports.Formatter = Formatter;
//# sourceMappingURL=formatter.js.map

@@ -7,4 +7,2 @@ "use strict";

exports.ExpressPacker = express_1.ExpressPacker;
var packer_1 = require("./packer/packer");
exports.Packer = packer_1.Packer;
//# sourceMappingURL=index.js.map

@@ -5,4 +5,4 @@ "use strict";

class ExpressPacker extends packer_1.Packer {
constructor(document, res, styles, properties, numbering, media) {
super(document, styles, properties, numbering, media);
constructor(document, res, styles, properties, numbering) {
super(document, styles, properties, numbering);
this.res = res;

@@ -14,3 +14,3 @@ this.res.on("close", () => {

pack(name) {
this.res.attachment(`${name}.docx`);
this.res.attachment(name + ".docx");
super.pack(this.res);

@@ -17,0 +17,0 @@ }

@@ -6,8 +6,7 @@ "use strict";

class LocalPacker extends packer_1.Packer {
constructor(document, styles, properties, numbering, media) {
super(document, styles, properties, numbering, media);
constructor(document, styles, properties, numbering) {
super(document, styles, properties, numbering);
}
pack(path) {
path = path.replace(/.docx$/, "");
this.stream = fs.createWriteStream(`${path}.docx`);
this.stream = fs.createWriteStream(path);
super.pack(this.stream);

@@ -14,0 +13,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const archiver = require("archiver");
const path = require("path");
const xml = require("xml");
const media_1 = require("../../media");
const numbering_1 = require("../../numbering");

@@ -11,22 +9,25 @@ const properties_1 = require("../../properties");

const formatter_1 = require("../formatter");
const TEMPLATE_PATH = path.resolve(__dirname, "../../../template");
const appRoot = require("app-root-path");
class Packer {
constructor(document, style, properties = new properties_1.Properties({
creator: "Un-named",
revision: "1",
lastModifiedBy: "Un-named",
}), numbering = new numbering_1.Numbering(), media = new media_1.Media()) {
constructor(document, style, properties, numbering) {
this.formatter = new formatter_1.Formatter();
this.document = document;
this.style = style;
this.properties = properties;
this.numbering = numbering;
this.media = media;
this.formatter = new formatter_1.Formatter();
this.archive = archiver.create("zip", {});
if (style) {
this.style = style;
}
else {
if (!style) {
const stylesFactory = new factory_1.DefaultStylesFactory();
this.style = stylesFactory.newInstance();
}
if (!properties) {
this.properties = new properties_1.Properties({
creator: "Un-named",
revision: "1",
lastModifiedBy: "Un-named",
});
}
if (!numbering) {
this.numbering = new numbering_1.Numbering();
}
this.archive.on("error", (err) => {

@@ -38,19 +39,16 @@ throw err;

this.archive.pipe(output);
console.log(appRoot.path + "/template");
this.archive.glob("**", {
expand: true,
cwd: TEMPLATE_PATH,
cwd: appRoot.path + "/template",
});
this.archive.glob("**/.rels", {
expand: true,
cwd: TEMPLATE_PATH,
cwd: appRoot.path + "/template",
});
const xmlDocument = xml(this.formatter.format(this.document));
const xmlStyles = xml(this.formatter.format(this.style));
const xmlProperties = xml(this.formatter.format(this.properties), {
declaration: {
standalone: "yes",
encoding: "UTF-8",
},
});
const xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
const xmlNumbering = xml(this.formatter.format(this.numbering));
console.log(xmlNumbering);
this.archive.append(xmlDocument, {

@@ -68,7 +66,2 @@ name: "word/document.xml",

});
for (const data of this.media.array) {
this.archive.append(data.stream, {
name: `media/${data.fileName}`,
});
}
this.archive.finalize();

@@ -75,0 +68,0 @@ }

@@ -10,7 +10,2 @@ "use strict";

exports.Numbering = numbering_1.Numbering;
var styles_1 = require("./styles");
exports.Styles = styles_1.Styles;
var media_1 = require("./media");
exports.Media = media_1.Media;
__export(require("./export"));
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const xml_components_1 = require("../docx/xml-components");

@@ -7,8 +8,7 @@ const level_1 = require("./level");

class AbstractNumberingAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
constructor(properties) {
super({
abstractNumId: "w:abstractNumId",
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak",
};
}, properties);
}

@@ -34,4 +34,10 @@ }

}
clearVariables() {
_.forEach(this.root, (element) => {
element.clearVariables();
});
delete this.id;
}
}
exports.AbstractNumbering = AbstractNumbering;
//# sourceMappingURL=abstract-numbering.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const document_attributes_1 = require("../docx/document/document-attributes");
const indent_1 = require("../docx/paragraph/indent");
const run_fonts_1 = require("../docx/run/run-fonts");
const xml_components_1 = require("../docx/xml-components");
const abstract_numbering_1 = require("./abstract-numbering");
const indent_1 = require("./indent");
const num_1 = require("./num");
class Numbering extends xml_components_1.XmlComponent {
class Numbering extends xml_components_1.MultiPropertyXmlComponent {
constructor() {

@@ -72,4 +73,11 @@ super("w:numbering");

}
clearVariables() {
super.clearVariables();
_.forEach(this.root, (element) => {
element.clearVariables();
});
delete this.nextId;
}
}
exports.Numbering = Numbering;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const paragraph = require("../docx/paragraph/formatting");
const properties_1 = require("../docx/paragraph/properties");
const formatting = require("../docx/run/formatting");
const properties_2 = require("../docx/run/properties");
const xml_components_1 = require("../docx/xml-components");
class LevelAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
constructor(properties) {
super({
ilvl: "w:ilvl",
tentative: "w15:tentative",
};
}, properties);
}

@@ -65,2 +62,8 @@ }

}
clearVariables() {
this.paragraphProperties.clearVariables();
this.runProperties.clearVariables();
delete this.paragraphProperties;
delete this.runProperties;
}
addParagraphProperty(property) {

@@ -74,89 +77,4 @@ this.paragraphProperties.push(property);

}
size(twips) {
this.addRunProperty(new formatting.Size(twips));
return this;
}
bold() {
this.addRunProperty(new formatting.Bold());
return this;
}
italics() {
this.addRunProperty(new formatting.Italics());
return this;
}
smallCaps() {
this.addRunProperty(new formatting.SmallCaps());
return this;
}
allCaps() {
this.addRunProperty(new formatting.Caps());
return this;
}
strike() {
this.addRunProperty(new formatting.Strike());
return this;
}
doubleStrike() {
this.addRunProperty(new formatting.DoubleStrike());
return this;
}
subScript() {
this.addRunProperty(new formatting.SubScript());
return this;
}
superScript() {
this.addRunProperty(new formatting.SuperScript());
return this;
}
underline(underlineType, color) {
this.addRunProperty(new formatting.Underline(underlineType, color));
return this;
}
color(color) {
this.addRunProperty(new formatting.Color(color));
return this;
}
font(fontName) {
this.addRunProperty(new formatting.RunFonts(fontName));
return this;
}
center() {
this.addParagraphProperty(new paragraph.Alignment("center"));
return this;
}
left() {
this.addParagraphProperty(new paragraph.Alignment("left"));
return this;
}
right() {
this.addParagraphProperty(new paragraph.Alignment("right"));
return this;
}
justified() {
this.addParagraphProperty(new paragraph.Alignment("both"));
return this;
}
thematicBreak() {
this.addParagraphProperty(new paragraph.ThematicBreak());
return this;
}
maxRightTabStop() {
this.addParagraphProperty(new paragraph.MaxRightTabStop());
return this;
}
leftTabStop(position) {
this.addParagraphProperty(new paragraph.LeftTabStop(position));
return this;
}
indent(left, hanging) {
this.addParagraphProperty(new paragraph.Indent(left, hanging));
return this;
}
spacing(params) {
this.addParagraphProperty(new paragraph.Spacing(params));
return this;
}
;
}
exports.Level = Level;
//# sourceMappingURL=level.js.map

@@ -13,5 +13,6 @@ "use strict";

class NumAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = { numId: "w:numId" };
constructor(properties) {
super({
numId: "w:numId",
}, properties);
}

@@ -28,4 +29,8 @@ }

}
clearVariables() {
super.clearVariables();
delete this.id;
}
}
exports.Num = Num;
//# sourceMappingURL=num.js.map

@@ -5,52 +5,54 @@ "use strict";

const xml_components_1 = require("../docx/xml-components");
class Title extends xml_components_1.XmlComponent {
const xml_components_2 = require("../docx/xml-components");
class Title extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("dc:title");
this.root.push(value);
this.root = value;
}
}
exports.Title = Title;
class Subject extends xml_components_1.XmlComponent {
class Subject extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("dc:subject");
this.root.push(value);
this.root = value;
}
}
exports.Subject = Subject;
class Creator extends xml_components_1.XmlComponent {
class Creator extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("dc:creator");
this.root.push(value);
this.root = value;
}
}
exports.Creator = Creator;
class Keywords extends xml_components_1.XmlComponent {
class Keywords extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("cp:keywords");
this.root.push(value);
this.root = value;
}
}
exports.Keywords = Keywords;
class Description extends xml_components_1.XmlComponent {
class Description extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("dc:description");
this.root.push(value);
this.root = value;
}
}
exports.Description = Description;
class LastModifiedBy extends xml_components_1.XmlComponent {
class LastModifiedBy extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("cp:lastModifiedBy");
this.root.push(value);
this.root = value;
}
}
exports.LastModifiedBy = LastModifiedBy;
class Revision extends xml_components_1.XmlComponent {
class Revision extends xml_components_1.XmlUnitComponent {
constructor(value) {
super("cp:revision");
this.root.push(value);
const revision = value;
this.root = value;
}
}
exports.Revision = Revision;
class DateComponent extends xml_components_1.XmlComponent {
class DateComponent extends xml_components_2.XmlComponent {
getCurrentDate() {

@@ -57,0 +59,0 @@ const date = new Date();

@@ -16,23 +16,9 @@ "use strict";

}));
if (options.title) {
this.root.push(new components_1.Title(options.title));
}
if (options.subject) {
this.root.push(new components_1.Subject(options.subject));
}
if (options.creator) {
this.root.push(new components_1.Creator(options.creator));
}
if (options.keywords) {
this.root.push(new components_1.Keywords(options.keywords));
}
if (options.description) {
this.root.push(new components_1.Description(options.description));
}
if (options.lastModifiedBy) {
this.root.push(new components_1.LastModifiedBy(options.lastModifiedBy));
}
if (options.revision) {
this.root.push(new components_1.Revision(options.revision));
}
this.root.push(new components_1.Title(options.title));
this.root.push(new components_1.Subject(options.subject));
this.root.push(new components_1.Creator(options.creator));
this.root.push(new components_1.Keywords(options.keywords));
this.root.push(new components_1.Description(options.description));
this.root.push(new components_1.LastModifiedBy(options.lastModifiedBy));
this.root.push(new components_1.Revision(options.revision));
this.root.push(new components_1.Created());

@@ -39,0 +25,0 @@ this.root.push(new components_1.Modified());

@@ -14,4 +14,10 @@ "use strict";

}
clearVariables() {
this.runPropertiesDefaults.clearVariables();
this.paragraphPropertiesDefaults.clearVariables();
delete this.runPropertiesDefaults;
delete this.paragraphPropertiesDefaults;
}
}
exports.DocumentDefaults = DocumentDefaults;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const xml_components_1 = require("../../docx/xml-components");
const properties_1 = require("../../docx/paragraph/properties");
const xml_components_1 = require("../../docx/xml-components");
class ParagraphPropertiesDefaults extends xml_components_1.XmlComponent {

@@ -6,0 +6,0 @@ constructor() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const xml_components_1 = require("../../docx/xml-components");
const properties_1 = require("../../docx/run/properties");
const xml_components_1 = require("../../docx/xml-components");
class RunPropertiesDefaults extends xml_components_1.XmlComponent {

@@ -6,0 +6,0 @@ constructor() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const formatting_1 = require("../docx/run/formatting");
const _1 = require("./");
const defaults_1 = require("./defaults");
const style_1 = require("./style");
const formatting_1 = require("../docx/run/formatting");
class DefaultStylesFactory {
newInstance() {
const styles = new _1.Styles();
let styles = new _1.Styles();
styles.push(new defaults_1.DocumentDefaults());
const titleStyle = new style_1.TitleStyle();
let titleStyle = new style_1.TitleStyle();
titleStyle.addRunProperty(new formatting_1.Size(56));
styles.push(titleStyle);
const heading1Style = new style_1.Heading1Style();
let heading1Style = new style_1.Heading1Style();
heading1Style.addRunProperty(new formatting_1.Color("2E74B5"));
heading1Style.addRunProperty(new formatting_1.Size(32));
styles.push(heading1Style);
const heading2Style = new style_1.Heading2Style();
let heading2Style = new style_1.Heading2Style();
heading2Style.addRunProperty(new formatting_1.Color("2E74B5"));
heading2Style.addRunProperty(new formatting_1.Size(26));
styles.push(heading2Style);
const heading3Style = new style_1.Heading3Style();
let heading3Style = new style_1.Heading3Style();
heading3Style.addRunProperty(new formatting_1.Color("1F4D78"));
heading3Style.addRunProperty(new formatting_1.Size(24));
styles.push(heading3Style);
const heading4Style = new style_1.Heading4Style();
let heading4Style = new style_1.Heading4Style();
heading4Style.addRunProperty(new formatting_1.Color("2E74B5"));
heading4Style.addRunProperty(new formatting_1.Italics());
styles.push(heading4Style);
const heading5Style = new style_1.Heading5Style();
let heading5Style = new style_1.Heading5Style();
heading5Style.addRunProperty(new formatting_1.Color("2E74B5"));
styles.push(heading5Style);
const heading6Style = new style_1.Heading6Style();
let heading6Style = new style_1.Heading6Style();
heading6Style.addRunProperty(new formatting_1.Color("1F4D78"));
styles.push(heading6Style);
const listParagraph = new style_1.ListParagraph();
let listParagraph = new style_1.ListParagraph();
styles.push(listParagraph);

@@ -38,0 +38,0 @@ return styles;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const xml_components_1 = require("../docx/xml-components");
const document_attributes_1 = require("../docx/document/document-attributes");
const xml_components_1 = require("../docx/xml-components");
const style_1 = require("./style");
class Styles extends xml_components_1.XmlComponent {

@@ -15,3 +14,3 @@ constructor() {

w15: "http://schemas.microsoft.com/office/word/2012/wordml",
Ignorable: "w14 w15",
Ignorable: "w14 w15"
}));

@@ -21,8 +20,7 @@ }

this.root.push(style);
return this;
}
createParagraphStyle(styleId, name) {
const para = new style_1.ParagraphStyle(styleId, name);
this.push(para);
return para;
clearVariables() {
this.root.forEach(element => {
element.clearVariables();
});
}

@@ -29,0 +27,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const xml_components_1 = require("../../docx/xml-components");
class ComponentAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = { val: "w:val" };
}
}
const attributes_1 = require("./attributes");
class Name extends xml_components_1.XmlComponent {
constructor(value) {
super("w:name");
this.root.push(new ComponentAttributes({ val: value }));
this.root.push(new attributes_1.StyleAttributes({
val: value
}));
}

@@ -20,3 +17,5 @@ }

super("w:basedOn");
this.root.push(new ComponentAttributes({ val: value }));
this.root.push(new attributes_1.StyleAttributes({
val: value
}));
}

@@ -28,3 +27,6 @@ }

super("w:next");
this.root.push(new ComponentAttributes({ val: value }));
this.root.push(new attributes_1.StyleAttributes({
styleId: "1",
val: value
}));
}

@@ -36,3 +38,5 @@ }

super("w:link");
this.root.push(new ComponentAttributes({ val: value }));
this.root.push(new attributes_1.StyleAttributes({
val: value
}));
}

@@ -44,3 +48,5 @@ }

super("w:uiPriority");
this.root.push(new ComponentAttributes({ val: value }));
this.root.push(new attributes_1.StyleAttributes({
val: value
}));
}

@@ -47,0 +53,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const paragraph = require("../../docx/paragraph/formatting");
const formatting = require("../../docx/run/formatting");
const properties_1 = require("../../docx/run/properties");
const xml_components_1 = require("../../docx/xml-components");
const attributes_1 = require("./attributes");
const properties_1 = require("../../docx/paragraph/properties");
const properties_2 = require("../../docx/run/properties");
const components_1 = require("./components");
class StyleAttributes extends xml_components_1.XmlAttributeComponent {
constructor() {
super(...arguments);
this.xmlKeys = {
type: "w:type",
styleId: "w:styleId",
default: "w:default",
customStyle: "w:customStyle",
};
}
}
class Style extends xml_components_1.XmlComponent {
constructor(attributes, name) {
constructor(attributes) {
super("w:style");
this.root.push(new StyleAttributes(attributes));
if (name) {
this.root.push(new components_1.Name(name));
}
this.root.push(attributes);
}

@@ -33,9 +19,19 @@ push(styleSegment) {

class ParagraphStyle extends Style {
constructor(styleId, name) {
super({ type: "paragraph", styleId: styleId }, name);
this.paragraphProperties = new paragraph.ParagraphProperties();
this.runProperties = new properties_1.RunProperties();
constructor(styleId) {
let attributes = new attributes_1.StyleAttributes({
type: "paragraph",
styleId: styleId
});
super(attributes);
this.paragraphProperties = new properties_1.ParagraphProperties();
this.runProperties = new properties_2.RunProperties();
this.root.push(this.paragraphProperties);
this.root.push(this.runProperties);
}
clearVariables() {
this.paragraphProperties.clearVariables();
this.runProperties.clearVariables();
delete this.paragraphProperties;
delete this.runProperties;
}
addParagraphProperty(property) {

@@ -47,99 +43,2 @@ this.paragraphProperties.push(property);

}
basedOn(parentId) {
this.root.push(new components_1.BasedOn(parentId));
return this;
}
quickFormat() {
this.root.push(new components_1.QuickFormat());
return this;
}
next(nextId) {
this.root.push(new components_1.Next(nextId));
return this;
}
size(twips) {
this.addRunProperty(new formatting.Size(twips));
return this;
}
bold() {
this.addRunProperty(new formatting.Bold());
return this;
}
italics() {
this.addRunProperty(new formatting.Italics());
return this;
}
smallCaps() {
this.addRunProperty(new formatting.SmallCaps());
return this;
}
allCaps() {
this.addRunProperty(new formatting.Caps());
return this;
}
strike() {
this.addRunProperty(new formatting.Strike());
return this;
}
doubleStrike() {
this.addRunProperty(new formatting.DoubleStrike());
return this;
}
subScript() {
this.addRunProperty(new formatting.SubScript());
return this;
}
superScript() {
this.addRunProperty(new formatting.SuperScript());
return this;
}
underline(underlineType, color) {
this.addRunProperty(new formatting.Underline(underlineType, color));
return this;
}
color(color) {
this.addRunProperty(new formatting.Color(color));
return this;
}
font(fontName) {
this.addRunProperty(new formatting.RunFonts(fontName));
return this;
}
center() {
this.addParagraphProperty(new paragraph.Alignment("center"));
return this;
}
left() {
this.addParagraphProperty(new paragraph.Alignment("left"));
return this;
}
right() {
this.addParagraphProperty(new paragraph.Alignment("right"));
return this;
}
justified() {
this.addParagraphProperty(new paragraph.Alignment("both"));
return this;
}
thematicBreak() {
this.addParagraphProperty(new paragraph.ThematicBreak());
return this;
}
maxRightTabStop() {
this.addParagraphProperty(new paragraph.MaxRightTabStop());
return this;
}
leftTabStop(position) {
this.addParagraphProperty(new paragraph.LeftTabStop(position));
return this;
}
indent(left, hanging) {
this.addParagraphProperty(new paragraph.Indent(left, hanging));
return this;
}
spacing(params) {
this.addParagraphProperty(new paragraph.Spacing(params));
return this;
}
;
}

@@ -149,6 +48,7 @@ exports.ParagraphStyle = ParagraphStyle;

constructor(styleId, name) {
super(styleId, name);
this.basedOn("Normal");
this.next("Normal");
this.quickFormat();
super(styleId);
this.root.push(new components_1.Name(name));
this.root.push(new components_1.BasedOn("Normal"));
this.root.push(new components_1.Next("Normal"));
this.root.push(new components_1.QuickFormat());
}

@@ -155,0 +55,0 @@ }

{
"name": "docx",
"version": "2.0.0",
"version": "2.0.1",
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",

@@ -12,3 +12,4 @@ "main": "build/index.js",

"build": "rimraf ./build && tsc -p ts",
"demo": "npm run build && node ./demo/demo.js"
"demo": "npm run build && node ./demo/demo.js",
"demo2": "npm run build && node ./demo/demo2.js"
},

@@ -15,0 +16,0 @@ "files": [

@@ -59,7 +59,7 @@ import * as paragraph from "../docx/paragraph/formatting";

export class Level extends XmlComponent {
class LevelBase extends XmlComponent {
private paragraphProperties: ParagraphProperties;
private runProperties: RunProperties;
constructor(level: number, numberFormat: string, levelText: string, lvlJc: string) {
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
super("w:lvl");

@@ -71,6 +71,14 @@ this.root.push(new LevelAttributes({

this.root.push(new Start(1));
this.root.push(new NumberFormat(numberFormat));
this.root.push(new LevelText(levelText));
this.root.push(new LevelJc(lvlJc));
if (start !== undefined) {
this.root.push(new Start(start));
}
if (numberFormat !== undefined) {
this.root.push(new NumberFormat(numberFormat));
}
if (levelText !== undefined) {
this.root.push(new LevelText(levelText));
}
if (lvlJc !== undefined) {
this.root.push(new LevelJc(lvlJc));
}

@@ -203,1 +211,11 @@ this.paragraphProperties = new ParagraphProperties();

}
export class Level extends LevelBase {
// This is the level that sits under abstractNum. We make a
// handful of properties required
constructor(level: number, numberFormat: string, levelText: string, lvlJc: string) {
super(level, 1, numberFormat, levelText, lvlJc);
}
}
export class LevelForOverride extends LevelBase {}
import { Attributes, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
import { LevelForOverride } from "./level";

@@ -32,2 +33,49 @@ class AbstractNumId extends XmlComponent {

}
public overrideLevel(num: number, start?: number): LevelOverride {
const olvl = new LevelOverride(num, start);
this.root.push(olvl);
return olvl;
}
}
class LevelOverrideAttributes extends XmlAttributeComponent<{ilvl: number}> {
protected xmlKeys = {ilvl: "w:ilvl"};
}
class LevelOverride extends XmlComponent {
private levelNum: number;
private lvl?: LevelForOverride;
constructor(levelNum: number, start?: number) {
super("w:lvlOverride");
this.root.push(new LevelOverrideAttributes({ilvl: levelNum}));
if (start !== undefined) {
this.root.push(new StartOverride(start));
}
this.levelNum = levelNum;
}
get level(): LevelForOverride {
let lvl: LevelForOverride;
if (!this.lvl) {
lvl = new LevelForOverride(this.levelNum);
this.root.push(lvl);
this.lvl = lvl;
} else {
lvl = this.lvl;
}
return lvl;
}
}
class StartOverrideAttributes extends XmlAttributeComponent<{val: number}> {
protected xmlKeys = {val: "w:val"};
}
class StartOverride extends XmlComponent {
constructor(start: number) {
super("w:startOverride");
this.root.push(new StartOverrideAttributes({val: start}));
}
}

@@ -5,2 +5,3 @@ import { expect } from "chai";

import { AbstractNumbering } from "../numbering/abstract-numbering";
import { LevelForOverride } from "../numbering/level";
import { Num } from "../numbering/num";

@@ -398,1 +399,48 @@

});
describe("concrete numbering", () => {
describe("#overrideLevel", () => {
let numbering;
let abstractNumbering;
let concreteNumbering;
beforeEach(() => {
numbering = new Numbering();
abstractNumbering = numbering.createAbstractNumbering();
concreteNumbering = numbering.createConcreteNumbering(abstractNumbering);
});
it("sets a new override level for the given level number", () => {
concreteNumbering.overrideLevel(3);
const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({"w:lvlOverride": [{_attr: {"w:ilvl": 3}}]});
});
it("sets the startOverride element if start is given", () => {
concreteNumbering.overrideLevel(1, 9);
const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({
"w:lvlOverride": [
{_attr: {"w:ilvl": 1}},
{"w:startOverride": [{_attr: {"w:val": 9}}]},
],
});
});
it("sets the lvl element if overrideLevel.level is accessed", () => {
const ol = concreteNumbering.overrideLevel(1);
expect(ol.level).to.be.instanceof(LevelForOverride);
const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({
"w:lvlOverride": [
{_attr: {"w:ilvl": 1}},
{"w:lvl": [
{_attr: {"w15:tentative": 1, "w:ilvl": 1}},
{"w:pPr": []},
{"w:rPr": []},
]},
],
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc