Compare commits

...

17 Commits
6.0.0 ... 6.0.2

Author SHA1 Message Date
ed409ac1b7 Version bump 2021-03-25 02:55:45 +00:00
4842630e09 Merge pull request #852 from dolanmiu/feat/fix-numbering
#851 Use predictive unique id generation
2021-03-24 03:16:46 +00:00
d29286ab6d Fix tests 2021-03-24 03:09:01 +00:00
ebaf0dfbf0 #851 Use predictive unique id generation 2021-03-24 03:02:58 +00:00
72389e25a1 Merge pull request #850 from dolanmiu/dependabot/npm_and_yarn/sinon-10.0.0
build(deps-dev): bump sinon from 9.2.4 to 10.0.0
2021-03-23 14:34:56 +00:00
799bdcc2f0 build(deps-dev): bump sinon from 9.2.4 to 10.0.0
Bumps [sinon](https://github.com/sinonjs/sinon) from 9.2.4 to 10.0.0.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v9.2.4...v10.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-23 11:42:01 +00:00
9ec7b4969d Version bump 2021-03-23 01:52:49 +00:00
e78696fbac Add README picture psd 2021-03-23 01:51:25 +00:00
f4102d2e30 Update README.md 2021-03-22 17:09:58 +00:00
658814d9ca Merge pull request #845 from dolanmiu/dependabot/npm_and_yarn/typedoc-0.20.33
build(deps-dev): bump typedoc from 0.20.32 to 0.20.33
2021-03-22 11:47:23 +00:00
fd86122881 Merge pull request #846 from dolanmiu/dependabot/npm_and_yarn/types/mocha-8.2.2
build(deps-dev): bump @types/mocha from 8.2.1 to 8.2.2
2021-03-22 11:47:12 +00:00
ce335c7a3d Merge pull request #844 from dolanmiu/feat/fix-styles-xml
#842 Move table styles to the top
2021-03-22 11:46:12 +00:00
bd456d3864 build(deps-dev): bump @types/mocha from 8.2.1 to 8.2.2
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 8.2.1 to 8.2.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-22 08:27:13 +00:00
2414c7c356 build(deps-dev): bump typedoc from 0.20.32 to 0.20.33
Bumps [typedoc](https://github.com/TypeStrong/TypeDoc) from 0.20.32 to 0.20.33.
- [Release notes](https://github.com/TypeStrong/TypeDoc/releases)
- [Commits](https://github.com/TypeStrong/TypeDoc/compare/v0.20.32...v0.20.33)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-22 08:26:45 +00:00
bc6644be0b #842 Move table styles to the top 2021-03-22 05:54:48 +00:00
46846b6e6c Fix imports 2021-03-22 05:23:30 +00:00
ac4b5839c2 Update README.md 2021-03-21 18:36:15 +00:00
9 changed files with 142 additions and 30 deletions

View File

@ -19,7 +19,7 @@
[![codecov][codecov-image]][codecov-url] [![codecov][codecov-image]][codecov-url]
<p align="center"> <p align="center">
<img src="https://i.imgur.com/tBO0XBR.png" alt="drawing"/> <img src="https://i.imgur.com/QeL1HuU.png" alt="drawing"/>
</p> </p>
# Demo # Demo
@ -29,7 +29,7 @@
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment: Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
* https://codepen.io/dolanmiu/pen/RwNeObg * https://codepen.io/dolanmiu/pen/RwNeObg
* https://jsfiddle.net/dolanmiu/kqxrj35u/1/ * https://jsfiddle.net/dolanmiu/onadx1gu/
Here is an example of `docx` working in `Angular`: Here is an example of `docx` working in `Angular`:

View File

@ -0,0 +1,111 @@
// Numbered lists - With complex number text
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, LevelFormat } from "../build";
const doc = new Document({
numbering: {
config: [
{
reference: "ref1",
levels: [
{
level: 0,
format: LevelFormat.DECIMAL,
text: "%1",
},
{
level: 1,
format: LevelFormat.DECIMAL,
text: "%1.%2",
},
{
level: 2,
format: LevelFormat.DECIMAL,
text: "%1.%2.%3",
},
],
},
],
},
sections: [
{
children: [
new Paragraph({
text: "REF1 - lvl:0",
numbering: {
reference: "ref1",
level: 0,
},
}),
new Paragraph({
text: "REF1 - lvl:1",
numbering: {
reference: "ref1",
level: 1,
},
}),
new Paragraph({
text: "REF1 - lvl:2",
numbering: {
reference: "ref1",
level: 2,
},
}),
new Paragraph({
text: "REF1 - lvl:0",
numbering: {
reference: "ref1",
level: 0,
},
}),
new Paragraph({
text: "REF1 - lvl:0",
numbering: {
reference: "ref1",
level: 0,
},
}),
new Paragraph({
text: "REF1 - lvl:0",
numbering: {
reference: "ref1",
level: 0,
},
}),
new Paragraph({
text: "Random text",
}),
new Paragraph({
text: "REF1 - inst:1 - lvl:0",
numbering: {
reference: "ref1",
instance: 1,
level: 0,
},
}),
new Paragraph({
text: "REF1 - inst:0 - lvl:0",
numbering: {
reference: "ref1",
instance: 0,
level: 0,
},
}),
new Paragraph({
text: "REF1 - inst:0 - lvl:0",
numbering: {
reference: "ref1",
instance: 0,
level: 0,
},
}),
],
},
],
});
// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("6-numbering.docx", buffer);
});

BIN
logo/readme-demo.psd Normal file

Binary file not shown.

34
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "docx", "name": "docx",
"version": "5.5.0", "version": "6.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -560,9 +560,9 @@
} }
}, },
"@types/mocha": { "@types/mocha": {
"version": "8.2.1", "version": "8.2.2",
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.1.tgz", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.2.tgz",
"integrity": "sha512-NysN+bNqj6E0Hv4CTGWSlPzMW6vTKjDpOteycDkV4IWBsO+PU48JonrPzV9ODjiI2XrjmA05KInLgF5ivZ/YGQ==", "integrity": "sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==",
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
@ -5640,9 +5640,9 @@
"dev": true "dev": true
}, },
"nise": { "nise": {
"version": "4.0.4", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz", "resolved": "https://registry.npmjs.org/nise/-/nise-4.1.0.tgz",
"integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==", "integrity": "sha512-eQMEmGN/8arp0xsvGoQ+B1qvSkR73B1nWSCh7nOt5neMCtwcQVYQGdzQMhcNscktTsWB54xnlSQFzOAPJD8nXA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@sinonjs/commons": "^1.7.0", "@sinonjs/commons": "^1.7.0",
@ -7361,16 +7361,16 @@
"dev": true "dev": true
}, },
"sinon": { "sinon": {
"version": "9.2.4", "version": "10.0.0",
"resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", "resolved": "https://registry.npmjs.org/sinon/-/sinon-10.0.0.tgz",
"integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==", "integrity": "sha512-XAn5DxtGVJBlBWYrcYKEhWCz7FLwZGdyvANRyK06419hyEpdT0dMc5A8Vcxg5SCGHc40CsqoKsc1bt1CbJPfNw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@sinonjs/commons": "^1.8.1", "@sinonjs/commons": "^1.8.1",
"@sinonjs/fake-timers": "^6.0.1", "@sinonjs/fake-timers": "^6.0.1",
"@sinonjs/samsam": "^5.3.1", "@sinonjs/samsam": "^5.3.1",
"diff": "^4.0.2", "diff": "^4.0.2",
"nise": "^4.0.4", "nise": "^4.1.0",
"supports-color": "^7.1.0" "supports-color": "^7.1.0"
}, },
"dependencies": { "dependencies": {
@ -8106,9 +8106,9 @@
} }
}, },
"typedoc": { "typedoc": {
"version": "0.20.32", "version": "0.20.33",
"resolved": "http://registry.npmjs.org/typedoc/-/typedoc-0.20.32.tgz", "resolved": "http://registry.npmjs.org/typedoc/-/typedoc-0.20.33.tgz",
"integrity": "sha512-GSopd/tiqoKE3fEdvhoaEpR9yrEPsR9tknAjkoeSPL6p1Rq5aVsKxBhhF6cwoDJ7oWjpvnm8vs0rQN0BxEHuWQ==", "integrity": "sha512-jzNdHmjZRQKwguhpXjIPuIjz+TpdgG2AVY8ta+qpAukv+3rBhTs4AAVd+mkonrHVYlC0EAbuAJ4urkfnn42Hwg==",
"dev": true, "dev": true,
"requires": { "requires": {
"colors": "^1.4.0", "colors": "^1.4.0",
@ -8173,9 +8173,9 @@
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.13.1", "version": "3.13.2",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.1.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.2.tgz",
"integrity": "sha512-EWhx3fHy3M9JbaeTnO+rEqzCe1wtyQClv6q3YWq0voOj4E+bMZBErVS1GAHPDiRGONYq34M1/d8KuQMgvi6Gjw==", "integrity": "sha512-SbMu4D2Vo95LMC/MetNaso1194M1htEA+JrqE9Hk+G2DhI+itfS9TRu9ZKeCahLDNa/J3n4MqUJ/fOHMzQpRWw==",
"dev": true, "dev": true,
"optional": true "optional": true
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "docx", "name": "docx",
"version": "6.0.0", "version": "6.0.2",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.", "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
@ -85,7 +85,7 @@
"request-promise": "^4.2.2", "request-promise": "^4.2.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"shelljs": "^0.8.4", "shelljs": "^0.8.4",
"sinon": "^9.0.2", "sinon": "^10.0.0",
"ts-node": "^9.0.0", "ts-node": "^9.0.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-immutable": "^6.0.1", "tslint-immutable": "^6.0.1",

View File

@ -20,7 +20,7 @@ describe("Utility", () => {
describe("#uniqueNumericId", () => { describe("#uniqueNumericId", () => {
it("should generate a unique ID", () => { it("should generate a unique ID", () => {
// tslint:disable-next-line: no-unused-expression // tslint:disable-next-line: no-unused-expression
expect(uniqueNumericId()).to.not.be.empty; expect(uniqueNumericId()).to.not.be.undefined;
}); });
}); });

View File

@ -1,6 +1,6 @@
import { customAlphabet, nanoid } from "nanoid/non-secure"; import { nanoid } from "nanoid/non-secure";
const numericNanoId = customAlphabet("0123456789", 15); let currentCount = 0;
// Twip - twentieths of a point // Twip - twentieths of a point
export const convertMillimetersToTwip = (millimeters: number): number => { export const convertMillimetersToTwip = (millimeters: number): number => {
@ -12,7 +12,7 @@ export const convertInchesToTwip = (inches: number): number => {
}; };
export const uniqueNumericId = (): number => { export const uniqueNumericId = (): number => {
return parseFloat(numericNanoId()); return currentCount++;
}; };
export const uniqueId = (): string => { export const uniqueId = (): string => {

View File

@ -1,10 +1,11 @@
import { uniqueId } from "convenience-functions"; import { uniqueId } from "convenience-functions";
import { IContext, IXmlableObject } from "file/xml-components";
import { Drawing, IFloating } from "../../drawing"; import { Drawing, IFloating } from "../../drawing";
import { IMediaTransformation } from "../../media"; import { IMediaTransformation } from "../../media";
import { IMediaData } from "../../media/data"; import { IMediaData } from "../../media/data";
import { Run } from "../run"; import { Run } from "../run";
import { IContext, IXmlableObject } from "/file/xml-components";
export interface IImageOptions { export interface IImageOptions {
readonly data: Buffer | string | Uint8Array | ArrayBuffer; readonly data: Buffer | string | Uint8Array | ArrayBuffer;

View File

@ -31,6 +31,10 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
constructor(options: ITablePropertiesOptions) { constructor(options: ITablePropertiesOptions) {
super("w:tblPr"); super("w:tblPr");
if (options.style) {
this.root.push(new TableStyle(options.style));
}
this.root.push(new TableCellMargin(options.cellMargin || {})); this.root.push(new TableCellMargin(options.cellMargin || {}));
if (options.borders) { if (options.borders) {
@ -60,9 +64,5 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
if (options.visuallyRightToLeft) { if (options.visuallyRightToLeft) {
this.root.push(new VisuallyRightToLeft()); this.root.push(new VisuallyRightToLeft());
} }
if (options.style) {
this.root.push(new TableStyle(options.style));
}
} }
} }