Compare commits

...

53 Commits
1.0.1 ... 1.2.0

Author SHA1 Message Date
e10b8889f7 version bump 2017-03-08 23:27:55 +00:00
744b16b753 tslinting 2017-03-08 21:59:27 +00:00
77824ce1d2 tslinting fixes 2017-03-08 21:56:19 +00:00
d2f777c4e5 more listing 2017-03-08 21:54:52 +00:00
946a222d37 linting fixes 2017-03-08 21:49:41 +00:00
279a5a93f1 fixed failing test 2017-03-08 21:40:21 +00:00
0e89606ec9 lots of tslinting 2017-03-08 21:36:09 +00:00
72683ea990 fixed bug where snky badge wasn’t displaying 2017-03-08 20:42:56 +00:00
88cf5f5065 added vulnerability checker 2017-03-08 20:37:21 +00:00
540518bd54 more tslinting 2017-03-08 20:35:26 +00:00
03b34915c6 tslinting 2017-03-08 20:32:30 +00:00
f6eb412357 removed numbering.md in favour of Wiki 2017-03-08 20:26:08 +00:00
ca769cc849 Merge pull request #11 from felipeochoa/fonts
Fonts cleanup
2017-03-08 20:16:17 +00:00
727471b7e3 fix linter warnings in docx/run/index.ts 2017-03-08 20:52:37 +01:00
1a37242a3d add #font method to Run 2017-03-08 20:47:36 +01:00
81e0d56918 fix linter warnings in runTest.ts 2017-03-08 20:47:35 +01:00
237be76d33 move run-fonts to docx/run and add a test 2017-03-08 20:47:35 +01:00
a454ff9643 Merge pull request #10 from felipeochoa/numbering
Numbering
2017-03-08 19:30:21 +00:00
f7b90d4ff3 add default argument "start" to createLevel 2017-03-08 19:18:24 +01:00
cee515e43f added Numbering to top-level exports and added docs on usage 2017-03-08 19:07:44 +01:00
0e9532d835 added #setNumbering method to paragraph 2017-03-08 18:23:00 +01:00
4b300e4def add fluent interface for defining abstract numbering levels 2017-03-08 18:03:39 +01:00
1fe7ab90f2 add createLevel method to AbstractNumbering 2017-03-08 18:03:24 +01:00
a3d2323254 rename methods from addXXX to createXXX
addXXX sounds like the argument should be XXX
2017-03-08 17:49:41 +01:00
0b2de737de fix linter warnings in numbering/index.ts 2017-03-08 17:45:29 +01:00
0a70d932a0 fix numberingTest linter warnings 2017-03-08 17:45:29 +01:00
6b702c4bd6 add ID property to Num and test Numbering methods 2017-03-08 17:45:29 +01:00
709ff25702 add #addAbstractNumbering and #addConcreteNumbering to Numbering 2017-03-08 17:45:29 +01:00
82998d4f6b record ID in AbstractNumbering 2017-03-08 17:45:29 +01:00
6e6a06eba4 fix numbering/num.ts linter warnings 2017-03-08 17:45:29 +01:00
ae70c2dfde fix numbering/indent.ts linter warnings 2017-03-08 17:45:29 +01:00
28e11a9b08 fix numbering/multi-level-type linter warnings 2017-03-08 17:45:29 +01:00
f5e81f1dfc fix numbering/level linter warnings 2017-03-08 17:45:29 +01:00
38138049fe fix abstract-number linter warnings 2017-03-08 17:45:29 +01:00
5511024ca6 fix run-fonts for new numbering test (and linter warnings) 2017-03-08 17:45:29 +01:00
ef1407e640 add a test for numbering 2017-03-08 17:45:29 +01:00
f822bbb26f fix typos in default numbering definition 2017-03-08 17:45:29 +01:00
52c4e3cabd allow NumberProperties to specify custom id/level
This change allows callers to create custom numbering styles and
attach them to paragraphs
2017-03-08 16:20:44 +01:00
9ced196678 Merge pull request #8 from felipeochoa/npm-fix
Npm fixes - prepublish and files
2017-03-08 15:11:58 +00:00
ef6e195e89 add an .npmignore file which does not exclude the build dir
Per https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package,
npm automatically uses .gitignore if there is no .npmignore, which may
have been keeping the build dir out of the package
2017-03-08 14:17:46 +01:00
a77d520f41 add the build files to the npm package 2017-03-08 12:05:47 +01:00
8eb11bca29 fix npm prepublish-on-install warnings 2017-03-08 12:05:47 +01:00
660a81633f removed copy and paste description 2017-03-07 23:15:26 +00:00
a917247b60 removed inverted comma 2017-03-07 23:13:04 +00:00
f492b3fe04 fixed pages bug 2017-03-07 23:12:08 +00:00
96a8942455 updated readme 2017-03-07 23:10:35 +00:00
bca478bb81 updated tslint and ignored some files 2017-03-07 23:05:09 +00:00
f5de5fef4d added tslint support 2017-03-07 22:56:59 +00:00
0e9301c0b5 clean up comment 2017-03-07 22:48:25 +00:00
b0869567c6 used more generic .vscode gitignore 2017-03-07 22:48:12 +00:00
0585a25a5a removed typescript 2017-03-07 22:37:40 +00:00
9804091f6a removed random semi colon 2017-03-07 22:35:20 +00:00
9c3023019f huge clean up of project. Now uses @types, and removed committed typings.
Formatted the imports too
2017-03-07 22:15:53 +00:00
94 changed files with 761 additions and 23968 deletions

2
.gitignore vendored
View File

@ -37,4 +37,4 @@ build
build-tests build-tests
# vscode # vscode
ts/.vscode .vscode

40
.npmignore Normal file
View File

@ -0,0 +1,40 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# build
# build <-- we want this in the package
build-tests
# vscode
.vscode

View File

@ -1,11 +1,19 @@
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] <p align="center">
<img alt="clippy the assistant" src="http://i60.tinypic.com/339pvtt.png">
</p>
<p align="center">
Generate .docx files with JS/TS very easily
</p>
---
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Known Vulnerabilities][snky-image]][snky-url]
# docx
> A tool to create Word Documents (.docx) with JS or TS, written in TS. > A tool to create Word Documents (.docx) with JS or TS, written in TS.
[![NPM](https://nodei.co/npm/docx.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/docx/) [![NPM](https://nodei.co/npm/docx.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/docx/)
![Clippy in Microsoft Office](http://i60.tinypic.com/339pvtt.png "Clippy in Microsoft Office")
# Table of Contents # Table of Contents
- [Install](#) - [Install](#)
- [Usage](#) - [Usage](#)
@ -380,3 +388,5 @@ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[travis-url]: https://travis-ci.org/dolanmiu/docx [travis-url]: https://travis-ci.org/dolanmiu/docx
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io [daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/dolanmiu/docx [daviddm-url]: https://david-dm.org/dolanmiu/docx
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
[snky-url]: https://snyk.io/test/github/dolanmiu/docx

View File

@ -1,13 +1,18 @@
{ {
"name": "docx", "name": "docx",
"version": "1.0.1", "version": "1.2.0",
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)", "description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
"pretest": "rimraf ./build-tests && tsc -p ts/test-tsconfig.json", "pretest": "rimraf ./build-tests && tsc -p ts/test-tsconfig.json",
"test": "mocha ./build-tests --recursive", "test": "mocha ./build-tests --recursive",
"prepublish": "tsc -p ts" "prepublishOnly": "tsc -p ts",
"lint": "tslint --project ./ts"
}, },
"files": [
"ts",
"build"
],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/dolanmiu/docx.git" "url": "git+https://github.com/dolanmiu/docx.git"
@ -16,17 +21,21 @@
"office", "office",
"generate", "generate",
"document", "document",
"doc" "doc",
"officegen",
"clippy"
], ],
"dependencies": { "dependencies": {
"@types/archiver": "^0.15.37",
"@types/express": "^4.0.35",
"@types/lodash": "^4.14.54",
"app-root-path": "^2.0.1", "app-root-path": "^2.0.1",
"archiver": "^1.3.0", "archiver": "^1.3.0",
"install": "^0.8.7",
"lodash": "^4.6.1", "lodash": "^4.6.1",
"npm": "^4.3.0",
"xml": "^1.0.1" "xml": "^1.0.1"
}, },
"typescript": {
"definition": "ts/typings/index.d.ts"
},
"author": "Dolan Miu", "author": "Dolan Miu",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
@ -34,9 +43,12 @@
}, },
"homepage": "https://github.com/dolanmiu/docx#readme", "homepage": "https://github.com/dolanmiu/docx#readme",
"devDependencies": { "devDependencies": {
"@types/chai": "^3.4.35",
"@types/mocha": "^2.2.39",
"chai": "^3.5.0", "chai": "^3.5.0",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"rimraf": "^2.5.2", "rimraf": "^2.5.2",
"tslint": "^4.5.1",
"typescript": "^2.2.1" "typescript": "^2.2.1"
} }
} }

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
export class Columns extends XmlComponent { export class Columns extends XmlComponent {
constructor() { constructor() {
super("w:cols"); super("w:cols");
this.root.push(new Attributes({ this.root.push(new Attributes({
space: "708" space: "708",
})); }));
} }
} }

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
export class DocumentGrid extends XmlComponent { export class DocumentGrid extends XmlComponent {
constructor() { constructor() {
super("w:docGrid"); super("w:docGrid");
this.root.push(new Attributes({ this.root.push(new Attributes({
linePitch: "360" linePitch: "360",
})); }));
} }
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
import { SectionProperties } from "./section-properties"; import { SectionProperties } from "./section-properties";
export class Body extends XmlComponent { export class Body extends XmlComponent {
@ -8,7 +8,7 @@ export class Body extends XmlComponent {
// this.root.push(new SectionProperties()); not actually needed // this.root.push(new SectionProperties()); not actually needed
} }
push(component: XmlComponent) { public push(component: XmlComponent): void {
// this.root.splice(this.body.length - 1, 0, component); // this.root.splice(this.body.length - 1, 0, component);
this.root.push(component); this.root.push(component);
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
export class PageMargin extends XmlComponent { export class PageMargin extends XmlComponent {
@ -11,7 +11,7 @@ export class PageMargin extends XmlComponent {
left: "1440", left: "1440",
header: "708", header: "708",
footer: "708", footer: "708",
gutter: "0" gutter: "0",
})); }));
} }
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
export class PageSize extends XmlComponent { export class PageSize extends XmlComponent {
@ -6,7 +6,7 @@ export class PageSize extends XmlComponent {
super("w:pgSz"); super("w:pgSz");
this.root.push(new Attributes({ this.root.push(new Attributes({
w: "11906", w: "11906",
h: "16838" h: "16838",
})); }));
} }
} }

View File

@ -1,8 +1,8 @@
import {XmlComponent, Attributes} from "../../xml-components"; import { Attributes, XmlComponent } from "../../xml-components";
import {PageSize} from "./page-size";
import {PageMargin} from "./page-margin";
import { Columns } from "./columns"; import { Columns } from "./columns";
import { DocumentGrid } from "./doc-grid"; import { DocumentGrid } from "./doc-grid";
import { PageMargin } from "./page-margin";
import { PageSize } from "./page-size";
export class SectionProperties extends XmlComponent { export class SectionProperties extends XmlComponent {
@ -11,7 +11,7 @@ export class SectionProperties extends XmlComponent {
this.root.push(new Attributes({ this.root.push(new Attributes({
rsidR: "00B64E8F", rsidR: "00B64E8F",
rsidRPr: "00D842E4", rsidRPr: "00D842E4",
rsidSect: "000A6AD0" rsidSect: "000A6AD0",
})); }));
this.root.push(new PageSize()); this.root.push(new PageSize());
this.root.push(new PageMargin()); this.root.push(new PageMargin());

View File

@ -1,6 +1,6 @@
import { XmlAttributeComponent } from "../xml-components"; import { XmlAttributeComponent } from "../xml-components";
interface DocumentAttributesProperties { interface IDocumentAttributesProperties {
wpc?: string; wpc?: string;
mc?: string; mc?: string;
o?: string; o?: string;
@ -28,7 +28,7 @@ interface DocumentAttributesProperties {
export class DocumentAttributes extends XmlAttributeComponent { export class DocumentAttributes extends XmlAttributeComponent {
constructor(properties?: DocumentAttributesProperties) { constructor(properties?: IDocumentAttributesProperties) {
super({ super({
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
@ -52,7 +52,7 @@ export class DocumentAttributes extends XmlAttributeComponent {
dcterms: "xmlns:dcterms", dcterms: "xmlns:dcterms",
dcmitype: "xmlns:dcmitype", dcmitype: "xmlns:dcmitype",
xsi: "xmlns:xsi", xsi: "xmlns:xsi",
type: "xsi:type" type: "xsi:type",
}, properties); }, properties);
this.root = properties; this.root = properties;

View File

@ -1,8 +1,7 @@
import {XmlComponent} from "../xml-components";
import {DocumentAttributes} from "./document-attributes";
import {Body} from "./body";
import { Paragraph } from "../paragraph"; import { Paragraph } from "../paragraph";
import { XmlComponent } from "../xml-components";
import { Body } from "./body";
import { DocumentAttributes } from "./document-attributes";
export class Document extends XmlComponent { export class Document extends XmlComponent {
private body: Body; private body: Body;
@ -25,17 +24,17 @@ export class Document extends XmlComponent {
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
wne: "http://schemas.microsoft.com/office/word/2006/wordml", wne: "http://schemas.microsoft.com/office/word/2006/wordml",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14" Ignorable: "w14 w15 wp14",
})); }));
this.body = new Body(); this.body = new Body();
this.root.push(this.body); this.root.push(this.body);
} }
addParagraph(paragraph: Paragraph): void { public addParagraph(paragraph: Paragraph): void {
this.body.push(paragraph); this.body.push(paragraph);
} }
clearVariables(): void { public clearVariables(): void {
this.body.clearVariables(); this.body.clearVariables();
delete this.body; delete this.body;
} }

View File

@ -1,4 +1,4 @@
export { Document } from "./document"; export { Document } from "./document";
export { Paragraph } from "./paragraph"; export { Paragraph } from "./paragraph";
export {Run} from "./run" export { Run } from "./run";
export {TextRun} from "./run/text-run" export { TextRun } from "./run/text-run";

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
class Border extends XmlComponent { class Border extends XmlComponent {
@ -8,7 +8,7 @@ class Border extends XmlComponent {
color: "auto", color: "auto",
space: "1", space: "1",
val: "single", val: "single",
sz: "6" sz: "6",
})); }));
} }
} }

View File

@ -1,10 +1,11 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Num } from "../../numbering/num";
import { TextRun } from "../run/text-run";
import { Attributes, XmlComponent } from "../xml-components";
import { ThematicBreak } from "./border"; import { ThematicBreak } from "./border";
import { PageBreak } from "./page-break"; import { PageBreak } from "./page-break";
import {TextRun} from "../run/text-run";
import { ParagraphProperties } from "./properties"; import { ParagraphProperties } from "./properties";
import {MaxRightTabStop, LeftTabStop} from "./tab-stop";
import { Style } from "./style"; import { Style } from "./style";
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
import { NumberProperties } from "./unordered-list"; import { NumberProperties } from "./unordered-list";
class Alignment extends XmlComponent { class Alignment extends XmlComponent {
@ -12,7 +13,7 @@ class Alignment extends XmlComponent {
constructor(type: string) { constructor(type: string) {
super("w:jc"); super("w:jc");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: type val: type,
})); }));
} }
} }
@ -29,84 +30,90 @@ export class Paragraph extends XmlComponent {
} }
} }
addText(run: TextRun): Paragraph { public addText(run: TextRun): Paragraph {
this.root.push(run); this.root.push(run);
return this; return this;
} }
heading1(): Paragraph { public heading1(): Paragraph {
this.properties.push(new Style("Heading1")); this.properties.push(new Style("Heading1"));
return this; return this;
} }
heading2(): Paragraph { public heading2(): Paragraph {
this.properties.push(new Style("Heading2")); this.properties.push(new Style("Heading2"));
return this; return this;
} }
heading3(): Paragraph { public heading3(): Paragraph {
this.properties.push(new Style("Heading3")); this.properties.push(new Style("Heading3"));
return this; return this;
} }
heading4(): Paragraph { public heading4(): Paragraph {
this.properties.push(new Style("Heading4")); this.properties.push(new Style("Heading4"));
return this; return this;
} }
heading5(): Paragraph { public heading5(): Paragraph {
this.properties.push(new Style("Heading5")); this.properties.push(new Style("Heading5"));
return this; return this;
} }
title(): Paragraph { public title(): Paragraph {
this.properties.push(new Style("Title")); this.properties.push(new Style("Title"));
return this; return this;
} }
center(): Paragraph { public center(): Paragraph {
this.properties.push(new Alignment("center")); this.properties.push(new Alignment("center"));
return this; return this;
} }
left(): Paragraph { public left(): Paragraph {
this.properties.push(new Alignment("left")); this.properties.push(new Alignment("left"));
return this; return this;
} }
right(): Paragraph { public right(): Paragraph {
this.properties.push(new Alignment("right")); this.properties.push(new Alignment("right"));
return this; return this;
} }
justified(): Paragraph { public justified(): Paragraph {
this.properties.push(new Alignment("both")); this.properties.push(new Alignment("both"));
return this; return this;
} }
thematicBreak(): Paragraph { public thematicBreak(): Paragraph {
this.properties.push(new ThematicBreak()); this.properties.push(new ThematicBreak());
return this; return this;
} }
pageBreak(): Paragraph { public pageBreak(): Paragraph {
this.properties.push(new PageBreak()); this.properties.push(new PageBreak());
return this; return this;
} }
maxRightTabStop(): Paragraph { public maxRightTabStop(): Paragraph {
this.properties.push(new MaxRightTabStop()); this.properties.push(new MaxRightTabStop());
return this; return this;
} }
leftTabStop(position: number): Paragraph { public leftTabStop(position: number): Paragraph {
this.properties.push(new LeftTabStop(position)); this.properties.push(new LeftTabStop(position));
return this; return this;
} }
bullet(): Paragraph { public bullet(): Paragraph {
this.properties.push(new Style("ListParagraph")); this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties()); this.properties.push(new NumberProperties(1, 0));
return this;
}
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(numbering.id, indentLevel));
return this; return this;
} }
} }

View File

@ -1,12 +1,12 @@
import {XmlComponent, Attributes} from "../xml-components";
import { Run } from "../run"; import { Run } from "../run";
import { Attributes, XmlComponent } from "../xml-components";
class Break extends XmlComponent { class Break extends XmlComponent {
constructor() { constructor() {
super("w:br"); super("w:br");
this.root.push(new Attributes({ this.root.push(new Attributes({
type: "page" type: "page",
})); }));
} }
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
export class ParagraphProperties extends XmlComponent { export class ParagraphProperties extends XmlComponent {
@ -7,7 +7,7 @@ export class ParagraphProperties extends XmlComponent {
this.root.push(new Attributes()); this.root.push(new Attributes());
} }
push(item: XmlComponent): void { public push(item: XmlComponent): void {
this.root.push(item); this.root.push(item);
} }
} }

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
export class Style extends XmlComponent { export class Style extends XmlComponent {
constructor(type: string) { constructor(type: string) {
super("w:pStyle"); super("w:pStyle");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: type val: type,
})); }));
} }
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
class TabStop extends XmlComponent { class TabStop extends XmlComponent {
@ -14,7 +14,7 @@ class Tab extends XmlComponent {
super("w:tab"); super("w:tab");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value, val: value,
pos: position pos: position,
})); }));
} }
} }

View File

@ -1,12 +1,12 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
import { Style } from "./style"; import { Style } from "./style";
export class NumberProperties extends XmlComponent { export class NumberProperties extends XmlComponent {
constructor() { constructor(numberId: number, indentLevel: number) {
super("w:numPr"); super("w:numPr");
this.root.push(new IndentLevel(0)); this.root.push(new IndentLevel(indentLevel));
this.root.push(new NumberId(1)); this.root.push(new NumberId(numberId));
} }
} }
@ -15,7 +15,7 @@ class IndentLevel extends XmlComponent {
constructor(level: number) { constructor(level: number) {
super("w:ilvl"); super("w:ilvl");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: level val: level,
})); }));
} }
} }
@ -24,7 +24,7 @@ class NumberId extends XmlComponent {
constructor(id: number) { constructor(id: number) {
super("w:numId"); super("w:numId");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: id val: id,
})); }));
} }
} }

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
export class Bold extends XmlComponent { export class Bold extends XmlComponent {
constructor() { constructor() {
super("w:b"); super("w:b");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -15,7 +15,7 @@ export class Italics extends XmlComponent {
constructor() { constructor() {
super("w:i"); super("w:i");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -25,7 +25,7 @@ export class Caps extends XmlComponent {
constructor() { constructor() {
super("w:caps"); super("w:caps");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -35,7 +35,7 @@ export class Color extends XmlComponent {
constructor(color: string) { constructor(color: string) {
super("w:color"); super("w:color");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: color val: color,
})); }));
} }
} }
@ -45,7 +45,7 @@ export class DoubleStrike extends XmlComponent {
constructor() { constructor() {
super("w:dstrike"); super("w:dstrike");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -55,7 +55,7 @@ export class Emboss extends XmlComponent {
constructor() { constructor() {
super("w:emboss"); super("w:emboss");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -65,7 +65,7 @@ export class Imprint extends XmlComponent {
constructor() { constructor() {
super("w:imprint"); super("w:imprint");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -75,7 +75,7 @@ export class Shadow extends XmlComponent {
constructor() { constructor() {
super("w:shadow"); super("w:shadow");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -85,7 +85,7 @@ export class SmallCaps extends XmlComponent {
constructor() { constructor() {
super("w:smallCaps"); super("w:smallCaps");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -95,7 +95,7 @@ export class Strike extends XmlComponent {
constructor() { constructor() {
super("w:strike"); super("w:strike");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: true val: true,
})); }));
} }
} }
@ -105,7 +105,7 @@ export class Size extends XmlComponent {
constructor(size: number) { constructor(size: number) {
super("w:sz"); super("w:sz");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: size val: size,
})); }));
} }
} }

View File

@ -1,75 +1,81 @@
import {XmlComponent, Attributes} from "../xml-components";
import {RunProperties} from "./properties";
import {Bold, Italics} from "./formatting";
import {Tab} from "./tab";
import { Break } from "./break"; import { Break } from "./break";
import {SmallCaps, Caps} from "./caps"; import { Caps, SmallCaps } from "./caps";
import {Strike, DoubleStrike} from "./strike"; import { Bold, Italics } from "./formatting";
import { RunProperties } from "./properties";
import { RunFonts } from "./run-fonts";
import { SubScript, SuperScript } from "./script"; import { SubScript, SuperScript } from "./script";
import {Underline} from "./underline" import { DoubleStrike, Strike } from "./strike";
import { Tab } from "./tab";
import { Underline } from "./underline";
import { Attributes, XmlComponent } from "../xml-components";
export class Run extends XmlComponent { export class Run extends XmlComponent {
private properties: RunProperties; private properties: RunProperties;
constructor() { constructor() {
super("w:r"); super("w:r");
this.properties = new RunProperties(); this.properties = new RunProperties();
this.root.push(this.properties); this.root.push(this.properties);
} }
bold(): Run { public bold(): Run {
this.properties.push(new Bold()); this.properties.push(new Bold());
return this; return this;
} }
italic(): Run { public italic(): Run {
this.properties.push(new Italics()); this.properties.push(new Italics());
return this; return this;
} }
underline(): Run { public underline(): Run {
this.properties.push(new Underline()); this.properties.push(new Underline());
return this; return this;
} }
break(): Run { public break(): Run {
this.root.splice(1, 0, new Break()); this.root.splice(1, 0, new Break());
return this; return this;
} }
tab(): Run { public tab(): Run {
this.root.splice(1, 0, new Tab()); this.root.splice(1, 0, new Tab());
return this; return this;
} }
smallCaps(): Run { public smallCaps(): Run {
this.properties.push(new SmallCaps()); this.properties.push(new SmallCaps());
return this; return this;
} }
allCaps(): Run { public allCaps(): Run {
this.properties.push(new Caps()); this.properties.push(new Caps());
return this; return this;
} }
strike(): Run { public strike(): Run {
this.properties.push(new Strike()); this.properties.push(new Strike());
return this; return this;
} }
doubleStrike(): Run { public doubleStrike(): Run {
this.properties.push(new DoubleStrike()); this.properties.push(new DoubleStrike());
return this; return this;
} }
subScript(): Run { public subScript(): Run {
this.properties.push(new SubScript()); this.properties.push(new SubScript());
return this; return this;
} }
superScript(): Run { public superScript(): Run {
this.properties.push(new SuperScript()); this.properties.push(new SuperScript());
return this; return this;
} }
public font(fontName: string): Run {
this.properties.push(new RunFonts(fontName));
return this;
}
} }

View File

@ -6,7 +6,7 @@ export class RunProperties extends XmlComponent {
super("w:rPr"); super("w:rPr");
} }
push(item: XmlComponent): void { public push(item: XmlComponent): void {
this.root.push(item); this.root.push(item);
} }
} }

30
ts/docx/run/run-fonts.ts Normal file
View File

@ -0,0 +1,30 @@
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
interface IRunFontAttributesProperties {
ascii: string;
hAnsi: string;
hint?: string;
}
class RunFontAttributes extends XmlAttributeComponent {
constructor(properties: IRunFontAttributesProperties) {
super({
ascii: "w:ascii",
hAnsi: "w:hAnsi",
hint: "w:hint",
}, properties);
}
}
export class RunFonts extends XmlComponent {
constructor(ascii: string, hint?: string) {
super("w:rFonts");
this.root.push(new RunFontAttributes({
ascii: ascii,
hAnsi: ascii,
hint: hint,
}));
}
}

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
abstract class VerticalAlign extends XmlComponent { abstract class VerticalAlign extends XmlComponent {
constructor(type: string) { constructor(type: string) {
super("w:vertAlign"); super("w:vertAlign");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: type val: type,
})); }));
} }
} }

View File

@ -1,5 +1,5 @@
import {Text} from "./text";
import { Run } from "../run"; import { Run } from "../run";
import { Text } from "./text";
export class TextRun extends Run { export class TextRun extends Run {

View File

@ -1,4 +1,4 @@
import {XmlUnitComponent} from "../xml-components" import { XmlUnitComponent } from "../xml-components";
export class Text extends XmlUnitComponent { export class Text extends XmlUnitComponent {

View File

@ -1,4 +1,4 @@
import {XmlComponent, Attributes} from "../xml-components"; import { Attributes, XmlComponent } from "../xml-components";
abstract class BaseUnderline extends XmlComponent { abstract class BaseUnderline extends XmlComponent {
@ -6,7 +6,7 @@ abstract class BaseUnderline extends XmlComponent {
super("w:u"); super("w:u");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: underlineType, val: underlineType,
color: color color: color,
})); }));
} }
} }
@ -88,7 +88,6 @@ export class DoubleUnderline extends BaseUnderline {
} }
} }
export class SingleUnderline extends BaseUnderline { export class SingleUnderline extends BaseUnderline {
constructor() { constructor() {

View File

@ -1,7 +1,7 @@
import { XmlAttributeComponent } from "./default-attributes"; import { XmlAttributeComponent } from "./default-attributes";
interface AttributesProperties { interface IAttributesProperties {
val?: any; val?: string | number | boolean;
color?: string; color?: string;
space?: string; space?: string;
sz?: string; sz?: string;
@ -24,7 +24,7 @@ interface AttributesProperties {
export class Attributes extends XmlAttributeComponent { export class Attributes extends XmlAttributeComponent {
constructor(properties?: AttributesProperties) { constructor(properties?: IAttributesProperties) {
super({ super({
val: "w:val", val: "w:val",
color: "w:color", color: "w:color",
@ -44,7 +44,7 @@ export class Attributes extends XmlAttributeComponent {
footer: "w:footer", footer: "w:footer",
gutter: "w:gutter", gutter: "w:gutter",
linePitch: "w:linePitch", linePitch: "w:linePitch",
pos: "w:pos" pos: "w:pos",
}, properties); }, properties);
} }
} }

View File

@ -5,7 +5,9 @@ export abstract class BaseXmlComponent {
this.rootKey = rootKey; this.rootKey = rootKey;
} }
abstract replaceKey(): void; public abstract replaceKey(): void;
clearVariables(): void {
}; public clearVariables(): void {
// Do Nothing
}
} }

View File

@ -1,5 +1,5 @@
import {BaseXmlComponent} from "./base";
import * as _ from "lodash"; import * as _ from "lodash";
import { BaseXmlComponent } from "./base";
export abstract class XmlAttributeComponent extends BaseXmlComponent { export abstract class XmlAttributeComponent extends BaseXmlComponent {
protected root: Object; protected root: Object;
@ -16,10 +16,10 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
} }
} }
replaceKey(): void { public replaceKey(): void {
if (this.root !== undefined) { if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => { _.forOwn(this.root, (value, key) => {
let newKey = this.xmlKeys[key]; const newKey = this.xmlKeys[key];
this.root[newKey] = value; this.root[newKey] = value;
delete this.root[key]; delete this.root[key];
}); });

View File

@ -2,18 +2,18 @@ import * as _ from "lodash";
import { BaseXmlComponent } from "./base"; import { BaseXmlComponent } from "./base";
export abstract class XmlComponent extends BaseXmlComponent { export abstract class XmlComponent extends BaseXmlComponent {
protected root: Array<BaseXmlComponent>; protected root: BaseXmlComponent[];
constructor(rootKey: string) { constructor(rootKey: string) {
super(rootKey); super(rootKey);
this.root = new Array<BaseXmlComponent>(); this.root = new Array<BaseXmlComponent>();
} }
replaceKey(): void { public replaceKey(): void {
// console.log(this.rootKey); // console.log(this.rootKey);
// console.log(this.root); // console.log(this.root);
if (this.root !== undefined) { if (this.root !== undefined) {
this.root.forEach(root => { this.root.forEach((root) => {
if (root && root instanceof BaseXmlComponent) { if (root && root instanceof BaseXmlComponent) {
root.replaceKey(); root.replaceKey();
} }

View File

@ -1,17 +1,17 @@
import {XmlComponent} from "./";
import { ParagraphProperties } from "../paragraph/properties"; import { ParagraphProperties } from "../paragraph/properties";
import { RunProperties } from "../run/properties"; import { RunProperties } from "../run/properties";
import { XmlComponent } from "./";
export class ParagraphPropertyXmlComponent extends XmlComponent { export class ParagraphPropertyXmlComponent extends XmlComponent {
private paragraphProperties: ParagraphProperties; private paragraphProperties: ParagraphProperties;
constructor(rootKey) { constructor(rootKey: string) {
super(rootKey); super(rootKey);
this.paragraphProperties = new ParagraphProperties(); this.paragraphProperties = new ParagraphProperties();
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
} }
clearVariables(): void { public clearVariables(): void {
this.paragraphProperties.clearVariables(); this.paragraphProperties.clearVariables();
delete this.paragraphProperties; delete this.paragraphProperties;
@ -21,13 +21,13 @@ export class ParagraphPropertyXmlComponent extends XmlComponent {
export class RunPropertyXmlComponent extends XmlComponent { export class RunPropertyXmlComponent extends XmlComponent {
private runProperties: RunProperties; private runProperties: RunProperties;
constructor(rootKey) { constructor(rootKey: string) {
super(rootKey); super(rootKey);
this.runProperties = new RunProperties(); this.runProperties = new RunProperties();
this.root.push(this.runProperties); this.root.push(this.runProperties);
} }
clearVariables(): void { public clearVariables(): void {
this.runProperties.clearVariables(); this.runProperties.clearVariables();
delete this.runProperties; delete this.runProperties;
@ -38,7 +38,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
private runProperties: RunProperties; private runProperties: RunProperties;
private paragraphProperties: ParagraphProperties; private paragraphProperties: ParagraphProperties;
constructor(rootKey) { constructor(rootKey: string) {
super(rootKey); super(rootKey);
this.runProperties = new RunProperties(); this.runProperties = new RunProperties();
this.root.push(this.runProperties); this.root.push(this.runProperties);
@ -47,7 +47,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
} }
clearVariables(): void { public clearVariables(): void {
this.runProperties.clearVariables(); this.runProperties.clearVariables();
this.paragraphProperties.clearVariables(); this.paragraphProperties.clearVariables();

View File

@ -7,7 +7,7 @@ export abstract class XmlUnitComponent extends BaseXmlComponent {
super(rootKey); super(rootKey);
} }
replaceKey(): void { public replaceKey(): void {
if (this.root !== undefined) { if (this.root !== undefined) {
this[this.rootKey] = this.root; this[this.rootKey] = this.root;
delete this.root; delete this.root;

View File

@ -3,10 +3,10 @@ import {XmlComponent} from "../docx/xml-components";
export class Formatter { export class Formatter {
format(input: any): Object { public format(input: any): Object {
input.clearVariables(); input.clearVariables();
this.replaceKeys(input); this.replaceKeys(input);
let newJson = this.clense(input); const newJson = this.clense(input);
// console.log(JSON.stringify(newJson, null, " ")); // console.log(JSON.stringify(newJson, null, " "));
return newJson; return newJson;
} }
@ -18,7 +18,7 @@ export class Formatter {
} }
private clense(input: any): Object { private clense(input: any): Object {
let newJson = this.jsonify(input); const newJson = this.jsonify(input);
this.deepTraverseJson(newJson, (parent, value, key) => { this.deepTraverseJson(newJson, (parent, value, key) => {
if (key === "properties") { if (key === "properties") {

View File

@ -1,9 +1,10 @@
import {Packer} from "./packer";
import * as fs from "fs";
import * as express from "express"; import * as express from "express";
import * as fs from "fs";
import { Document } from "../../docx/document"; import { Document } from "../../docx/document";
import {Properties} from "../../properties";
import { Numbering } from "../../numbering"; import { Numbering } from "../../numbering";
import { Properties } from "../../properties";
import { Packer } from "./packer";
export class ExpressPacker extends Packer { export class ExpressPacker extends Packer {
private res: express.Response; private res: express.Response;
@ -17,7 +18,7 @@ export class ExpressPacker extends Packer {
}); });
} }
pack(name: string): void { public pack(name: string): void {
this.res.attachment(name + ".docx"); this.res.attachment(name + ".docx");
super.pack(this.res); super.pack(this.res);
} }

View File

@ -1,8 +1,9 @@
import {Packer} from "./packer";
import * as fs from "fs"; import * as fs from "fs";
import { Document } from "../../docx/document"; import { Document } from "../../docx/document";
import {Properties} from "../../properties";
import { Numbering } from "../../numbering"; import { Numbering } from "../../numbering";
import { Properties } from "../../properties";
import { Packer } from "./packer";
export class LocalPacker extends Packer { export class LocalPacker extends Packer {
private stream: fs.WriteStream; private stream: fs.WriteStream;
@ -11,7 +12,7 @@ export class LocalPacker extends Packer {
super(document, styles, properties, numbering); super(document, styles, properties, numbering);
} }
pack(path: string): void { public pack(path: string): void {
this.stream = fs.createWriteStream(path); this.stream = fs.createWriteStream(path);
super.pack(this.stream); super.pack(this.stream);
} }

View File

@ -1,19 +1,19 @@
import * as archiver from "archiver"; import * as archiver from "archiver";
import * as fs from "fs"; import * as fs from "fs";
import * as xml from "xml"; import * as xml from "xml";
import {Formatter} from "../formatter";
import { Document } from "../../docx"; import { Document } from "../../docx";
import {Styles} from "../../styles";
import {Properties} from "../../properties";
import { Numbering } from "../../numbering"; import { Numbering } from "../../numbering";
import { Properties } from "../../properties";
import { Styles } from "../../styles";
import { DefaultStylesFactory } from "../../styles/factory"; import { DefaultStylesFactory } from "../../styles/factory";
import { Formatter } from "../formatter";
let appRoot = require("app-root-path"); const appRoot = require("app-root-path");
export abstract class Packer { export abstract class Packer {
protected archive: any; protected archive: any;
private formatter: Formatter;
protected document: Document; protected document: Document;
private formatter: Formatter;
private style: Styles; private style: Styles;
private properties: Properties; private properties: Properties;
private numbering: Numbering; private numbering: Numbering;
@ -27,7 +27,7 @@ export abstract class Packer {
this.archive = archiver.create("zip", {}); this.archive = archiver.create("zip", {});
if (!style) { if (!style) {
let stylesFactory = new DefaultStylesFactory(); const stylesFactory = new DefaultStylesFactory();
this.style = stylesFactory.newInstance(); this.style = stylesFactory.newInstance();
} }
@ -35,7 +35,7 @@ export abstract class Packer {
this.properties = new Properties({ this.properties = new Properties({
creator: "Un-named", creator: "Un-named",
revision: "1", revision: "1",
lastModifiedBy: "Un-named" lastModifiedBy: "Un-named",
}); });
} }
@ -48,7 +48,7 @@ export abstract class Packer {
}); });
} }
pack(output: any): void { public pack(output: any): void {
this.archive.pipe(output); this.archive.pipe(output);
console.log(appRoot.path + "/template"); console.log(appRoot.path + "/template");
this.archive.glob("**", { this.archive.glob("**", {
@ -69,26 +69,26 @@ export abstract class Packer {
name: "/root/g.txt", name: "/root/g.txt",
prefix: "root" prefix: "root"
});*/ });*/
let xmlDocument = xml(this.formatter.format(this.document)); const xmlDocument = xml(this.formatter.format(this.document));
let xmlStyles = xml(this.formatter.format(this.style)); const xmlStyles = xml(this.formatter.format(this.style));
let 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" } });
let xmlNumbering = xml(this.formatter.format(this.numbering)); const xmlNumbering = xml(this.formatter.format(this.numbering));
// console.log(JSON.stringify(this.numbering, null, " ")); // console.log(JSON.stringify(this.numbering, null, " "));
console.log(xmlNumbering); console.log(xmlNumbering);
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: "word/document.xml" name: "word/document.xml",
}); });
this.archive.append(xmlStyles, { this.archive.append(xmlStyles, {
name: "word/styles.xml" name: "word/styles.xml",
}); });
this.archive.append(xmlProperties, { this.archive.append(xmlProperties, {
name: "docProps/core.xml" name: "docProps/core.xml",
}); });
this.archive.append(xmlNumbering, { this.archive.append(xmlNumbering, {
name: "word/numbering.xml" name: "word/numbering.xml",
}); });
this.archive.finalize(); this.archive.finalize();

View File

@ -1,2 +1,3 @@
export * from "./docx"; export * from "./docx";
export * from "./export"; export * from "./export";
export { Numbering } from "./numbering";

View File

@ -1,42 +1,50 @@
import {XmlComponent} from "../docx/xml-components"; import * as _ from "lodash";
import {XmlAttributeComponent} from "../docx/xml-components"; import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
import { Level } from "./level"; import { Level } from "./level";
import { MultiLevelType } from "./multi-level-type"; import { MultiLevelType } from "./multi-level-type";
import * as _ from "lodash";
interface AbstractNumberingAttributesProperties { interface IAbstractNumberingAttributesProperties {
abstractNumId?: number; abstractNumId?: number;
restartNumberingAfterBreak?: number; restartNumberingAfterBreak?: number;
} }
class AbstractNumberingAttributes extends XmlAttributeComponent { class AbstractNumberingAttributes extends XmlAttributeComponent {
constructor(properties: AbstractNumberingAttributesProperties) { constructor(properties: IAbstractNumberingAttributesProperties) {
super({ super({
abstractNumId: "w:abstractNumId", abstractNumId: "w:abstractNumId",
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak" restartNumberingAfterBreak: "w15:restartNumberingAfterBreak",
}, properties); }, properties);
} }
} }
export class AbstractNumbering extends XmlComponent { export class AbstractNumbering extends XmlComponent {
public id: number;
constructor(id: number) { constructor(id: number) {
super("w:abstractNum"); super("w:abstractNum");
this.root.push(new AbstractNumberingAttributes({ this.root.push(new AbstractNumberingAttributes({
abstractNumId: id, abstractNumId: id,
restartNumberingAfterBreak: 0 restartNumberingAfterBreak: 0,
})); }));
this.root.push(new MultiLevelType("hybridMultilevel")); this.root.push(new MultiLevelType("hybridMultilevel"));
this.id = id;
} }
addLevel(level: Level): void { public addLevel(level: Level): void {
this.root.push(level); this.root.push(level);
} }
clearVariables() { public createLevel(num: number, format: string, text: string, align: string = "start"): Level {
_.forEach(this.root, element => { const level = new Level(num, format, text, align);
this.addLevel(level);
return level;
}
public clearVariables(): void {
_.forEach(this.root, (element) => {
element.clearVariables(); element.clearVariables();
}); });
delete this.id;
} }
} }

View File

@ -1,4 +1,4 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components"; import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
interface IndentAttributesProperties { interface IndentAttributesProperties {
left: number; left: number;
@ -10,7 +10,7 @@ class IndentAttributes extends XmlAttributeComponent {
constructor(properties: IndentAttributesProperties) { constructor(properties: IndentAttributesProperties) {
super({ super({
left: "w:left", left: "w:left",
hanging: "w:hanging" hanging: "w:hanging",
}, properties); }, properties);
} }
} }
@ -21,7 +21,7 @@ export class Indent extends XmlComponent {
super("w:ind"); super("w:ind");
this.root.push(new IndentAttributes({ this.root.push(new IndentAttributes({
left: left, left: left,
hanging: hanging hanging: hanging,
})); }));
} }
} }

View File

@ -1,13 +1,14 @@
import {MultiPropertyXmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes";
import {AbstractNumbering} from "./abstract-numbering";
import {Level} from "./level";
import {Indent} from "./indent";
import {RunFonts} from "./run-fonts";
import {Num} from "./num";
import * as _ from "lodash"; import * as _ from "lodash";
import { DocumentAttributes } from "../docx/document/document-attributes";
import { RunFonts } from "../docx/run/run-fonts";
import { MultiPropertyXmlComponent } from "../docx/xml-components";
import { AbstractNumbering } from "./abstract-numbering";
import { Indent } from "./indent";
import { Level } from "./level";
import { Num } from "./num";
export class Numbering extends MultiPropertyXmlComponent { export class Numbering extends MultiPropertyXmlComponent {
private nextId: number;
constructor() { constructor() {
super("w:numbering"); super("w:numbering");
@ -28,65 +29,69 @@ export class Numbering extends MultiPropertyXmlComponent {
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
wne: "http://schemas.microsoft.com/office/word/2006/wordml", wne: "http://schemas.microsoft.com/office/word/2006/wordml",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14" Ignorable: "w14 w15 wp14",
})); }));
let abstractNumbering = new AbstractNumbering(0); this.nextId = 0;
let level0 = new Level(0, "bullet", "•", "left"); const abstractNumbering = this.createAbstractNumbering();
level0.addParagraphProperty(new Indent(720, 360));
level0.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level0);
let level1 = new Level(1, "bullet", "o", "left"); abstractNumbering.createLevel(0, "bullet", "", "left")
level1.addParagraphProperty(new Indent(1440, 360)); .addParagraphProperty(new Indent(720, 360))
level1.addRunProperty(new RunFonts("Courier New", "default")); .addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level1);
let level2 = new Level(2, "bullet", "", "left"); abstractNumbering.createLevel(1, "bullet", "o", "left")
level2.addParagraphProperty(new Indent(2160, 360)); .addParagraphProperty(new Indent(1440, 360))
level2.addRunProperty(new RunFonts("Wingdings", "default")); .addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level2);
let level3 = new Level(3, "bullet", "•", "left"); abstractNumbering.createLevel(2, "bullet", "•", "left")
level3.addParagraphProperty(new Indent(2880, 360)); .addParagraphProperty(new Indent(2160, 360))
level3.addRunProperty(new RunFonts("Symbol", "default")); .addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level3);
let level4 = new Level(4, "bullet", "o", "left"); abstractNumbering.createLevel(3, "bullet", "", "left")
level4.addParagraphProperty(new Indent(3600, 360)); .addParagraphProperty(new Indent(2880, 360))
level4.addRunProperty(new RunFonts("Courier New", "default")); .addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level4);
let level5 = new Level(5, "bullet", "", "left"); abstractNumbering.createLevel(4, "bullet", "o", "left")
level5.addParagraphProperty(new Indent(4320, 360)); .addParagraphProperty(new Indent(3600, 360))
level5.addRunProperty(new RunFonts("Wingdings", "default")); .addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level5);
let level6 = new Level(6, "bullet", "•", "left"); abstractNumbering.createLevel(5, "bullet", "•", "left")
level6.addParagraphProperty(new Indent(5040, 360)); .addParagraphProperty(new Indent(4320, 360))
level6.addRunProperty(new RunFonts("Symbol", "default")); .addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level6);
let level7 = new Level(4, "bullet", "o", "left"); abstractNumbering.createLevel(6, "bullet", "", "left")
level7.addParagraphProperty(new Indent(5760, 360)); .addParagraphProperty(new Indent(5040, 360))
level7.addRunProperty(new RunFonts("Courier New", "default")); .addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level7);
let level8 = new Level(5, "bullet", "", "left"); abstractNumbering.createLevel(7, "bullet", "o", "left")
level8.addParagraphProperty(new Indent(6480, 360)); .addParagraphProperty(new Indent(5760, 360))
level8.addRunProperty(new RunFonts("Wingdings", "default")); .addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level8);
this.root.push(abstractNumbering); abstractNumbering.createLevel(8, "bullet", "•", "left")
this.root.push(new Num(1, 0)); .addParagraphProperty(new Indent(6480, 360))
.addRunProperty(new RunFonts("Wingdings", "default"));
this.createConcreteNumbering(abstractNumbering);
} }
clearVariables() { public createAbstractNumbering(): AbstractNumbering {
const num = new AbstractNumbering(this.nextId++);
this.root.push(num);
return num;
}
public createConcreteNumbering(abstractNumbering: AbstractNumbering): Num {
const num = new Num(this.nextId++, abstractNumbering.id);
this.root.push(num);
return num;
}
public clearVariables(): void {
super.clearVariables(); super.clearVariables();
_.forEach(this.root, element => { _.forEach(this.root, (element) => {
console.log(element);
element.clearVariables(); element.clearVariables();
}); });
delete this.nextId;
} }
} }

View File

@ -1,19 +1,18 @@
import {XmlComponent, Attributes, MultiPropertyXmlComponent} from "../docx/xml-components";
import {XmlAttributeComponent} from "../docx/xml-components";
import {RunProperties} from "../docx/run/properties";
import { ParagraphProperties } from "../docx/paragraph/properties"; import { ParagraphProperties } from "../docx/paragraph/properties";
import { RunProperties } from "../docx/run/properties";
import { Attributes, MultiPropertyXmlComponent, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
interface LevelAttributesProperties { interface ILevelAttributesProperties {
ilvl?: number; ilvl?: number;
tentative?: number; tentative?: number;
} }
class LevelAttributes extends XmlAttributeComponent { class LevelAttributes extends XmlAttributeComponent {
constructor(properties: LevelAttributesProperties) { constructor(properties: ILevelAttributesProperties) {
super({ super({
ilvl: "w:ilvl", ilvl: "w:ilvl",
tentative: "w15:tentative" tentative: "w15:tentative",
}, properties); }, properties);
} }
} }
@ -23,7 +22,7 @@ class Start extends XmlComponent {
constructor(value: number) { constructor(value: number) {
super("w:start"); super("w:start");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }
@ -33,7 +32,7 @@ class NumberFormat extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:numFmt"); super("w:numFmt");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }
@ -43,7 +42,7 @@ class LevelText extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:lvlText"); super("w:lvlText");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }
@ -53,7 +52,7 @@ class LevelJc extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:lvlJc"); super("w:lvlJc");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }
@ -66,7 +65,7 @@ export class Level extends XmlComponent {
super("w:lvl"); super("w:lvl");
this.root.push(new LevelAttributes({ this.root.push(new LevelAttributes({
ilvl: level, ilvl: level,
tentative: 1 tentative: 1,
})); }));
this.root.push(new Start(1)); this.root.push(new Start(1));
@ -81,7 +80,7 @@ export class Level extends XmlComponent {
this.root.push(this.runProperties); this.root.push(this.runProperties);
} }
clearVariables(): void { public clearVariables(): void {
this.paragraphProperties.clearVariables(); this.paragraphProperties.clearVariables();
this.runProperties.clearVariables(); this.runProperties.clearVariables();
@ -89,11 +88,13 @@ export class Level extends XmlComponent {
delete this.runProperties; delete this.runProperties;
} }
addParagraphProperty(property: XmlComponent): void { public addParagraphProperty(property: XmlComponent): Level {
this.paragraphProperties.push(property); this.paragraphProperties.push(property);
return this;
} }
addRunProperty(property: XmlComponent): void { public addRunProperty(property: XmlComponent): Level {
this.runProperties.push(property); this.runProperties.push(property);
return this;
} }
} }

View File

@ -1,11 +1,11 @@
import {XmlComponent, Attributes} from "../docx/xml-components"; import { Attributes, XmlComponent } from "../docx/xml-components";
export class MultiLevelType extends XmlComponent { export class MultiLevelType extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:multiLevelType"); super("w:multiLevelType");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }

View File

@ -1,35 +1,42 @@
import {XmlComponent, Attributes, XmlAttributeComponent} from "../docx/xml-components"; import { Attributes, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
class AbstractNumId extends XmlComponent { class AbstractNumId extends XmlComponent {
constructor(value: number) { constructor(value: number) {
super("w:abstractNumId"); super("w:abstractNumId");
this.root.push(new Attributes({ this.root.push(new Attributes({
val: value val: value,
})); }));
} }
} }
interface NumAttributesProperties { interface INumAttributesProperties {
numId: number; numId: number;
} }
class NumAttributes extends XmlAttributeComponent { class NumAttributes extends XmlAttributeComponent {
constructor(properties: NumAttributesProperties) { constructor(properties: INumAttributesProperties) {
super({ super({
numId: "w:numId" numId: "w:numId",
}, properties); }, properties);
} }
} }
export class Num extends XmlComponent { export class Num extends XmlComponent {
public id: number;
constructor(numId: number, abstractNumId: number) { constructor(numId: number, abstractNumId: number) {
super("w:num"); super("w:num");
this.root.push(new NumAttributes({ this.root.push(new NumAttributes({
numId: numId numId: numId,
})); }));
this.root.push(new AbstractNumId(abstractNumId)); this.root.push(new AbstractNumId(abstractNumId));
this.id = numId;
}
public clearVariables(): void {
super.clearVariables();
delete this.id;
} }
} }

View File

@ -1,29 +0,0 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
interface RunFontAttributesProperties {
ascii: string;
hAnsi: string;
hint: string;
}
class RunFontAttributes extends XmlAttributeComponent {
constructor(properties: RunFontAttributesProperties) {
super({
left: "w:left",
hanging: "w:hanging"
}, properties);
}
}
export class RunFonts extends XmlComponent {
constructor(ascii: string, hint: string) {
super("w:ind");
this.root.push(new RunFontAttributes({
ascii: ascii,
hAnsi: ascii,
hint: hint
}));
}
}

View File

@ -1,6 +1,6 @@
import { DocumentAttributes } from "../docx/document/document-attributes";
import { XmlUnitComponent } from "../docx/xml-components"; import { XmlUnitComponent } from "../docx/xml-components";
import { XmlComponent } from "../docx/xml-components"; import { XmlComponent } from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes";
export class Title extends XmlUnitComponent { export class Title extends XmlUnitComponent {
@ -54,20 +54,20 @@ export class Revision extends XmlUnitComponent {
constructor(value: string) { constructor(value: string) {
super("cp:revision"); super("cp:revision");
let revision = value; const revision = value;
this.root = value; this.root = value;
} }
} }
abstract class DateComponent extends XmlComponent { abstract class DateComponent extends XmlComponent {
protected getCurrentDate(): any { protected getCurrentDate(): any {
let date = new Date(), const date = new Date();
year = date.getFullYear(), const year = date.getFullYear();
month = ("0" + (date.getMonth() + 1)).slice(-2), const month = ("0" + (date.getMonth() + 1)).slice(-2);
day = ("0" + date.getDate()).slice(-2), const day = ("0" + date.getDate()).slice(-2);
hours = ("0" + date.getHours()).slice(-2), const hours = ("0" + date.getHours()).slice(-2);
minutes = ("0" + date.getMinutes()).slice(-2), const minutes = ("0" + date.getMinutes()).slice(-2);
seconds = ("0" + date.getSeconds()).slice(-2); const seconds = ("0" + date.getSeconds()).slice(-2);
return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z"; return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
} }
@ -78,7 +78,7 @@ export class Created extends DateComponent {
constructor() { constructor() {
super("dcterms:created"); super("dcterms:created");
this.root.push(new DocumentAttributes({ this.root.push(new DocumentAttributes({
type: "dcterms:W3CDTF" type: "dcterms:W3CDTF",
})); }));
this.root.push(this.getCurrentDate()); this.root.push(this.getCurrentDate());
} }
@ -89,7 +89,7 @@ export class Modified extends DateComponent {
constructor() { constructor() {
super("dcterms:modified"); super("dcterms:modified");
this.root.push(new DocumentAttributes({ this.root.push(new DocumentAttributes({
type: "dcterms:W3CDTF" type: "dcterms:W3CDTF",
})); }));
this.root.push(this.getCurrentDate()); this.root.push(this.getCurrentDate());
} }

View File

@ -1,8 +1,8 @@
import {XmlComponent} from "../docx/xml-components";
import { DocumentAttributes } from "../docx/document/document-attributes"; import { DocumentAttributes } from "../docx/document/document-attributes";
import {Title, Subject, Creator, Keywords, Description, LastModifiedBy, Revision, Created, Modified} from "./components"; import { XmlComponent } from "../docx/xml-components";
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
interface PropertiesOptions { interface IPropertiesOptions {
title?: string; title?: string;
subject?: string; subject?: string;
creator?: string; creator?: string;
@ -14,14 +14,14 @@ interface PropertiesOptions {
export class Properties extends XmlComponent { export class Properties extends XmlComponent {
constructor(options: PropertiesOptions) { constructor(options: IPropertiesOptions) {
super("cp:coreProperties"); super("cp:coreProperties");
this.root.push(new DocumentAttributes({ this.root.push(new DocumentAttributes({
cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
dc: "http://purl.org/dc/elements/1.1/", dc: "http://purl.org/dc/elements/1.1/",
dcterms: "http://purl.org/dc/terms/", dcterms: "http://purl.org/dc/terms/",
dcmitype: "http://purl.org/dc/dcmitype/", dcmitype: "http://purl.org/dc/dcmitype/",
xsi: "http://www.w3.org/2001/XMLSchema-instance" xsi: "http://www.w3.org/2001/XMLSchema-instance",
})); }));
this.root.push(new Title(options.title)); this.root.push(new Title(options.title));
this.root.push(new Subject(options.subject)); this.root.push(new Subject(options.subject));

View File

@ -1,3 +1,4 @@
/* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) { function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
'use strict'; 'use strict';

View File

@ -1,6 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import { assert } from "chai"; import { assert } from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {

View File

@ -1,5 +1,3 @@
/// <reference path="../../../typings/mocha/mocha.d.ts" />
/// <reference path="../../../typings/chai/chai.d.ts" />
import { Body } from "../../../docx/document/body"; import { Body } from "../../../docx/document/body";
import { assert } from "chai"; import { assert } from "chai";
import { SectionProperties } from "../../../docx/document/body/section-properties"; import { SectionProperties } from "../../../docx/document/body/section-properties";

View File

@ -1,6 +1,3 @@
/// <reference path="../../../typings/mocha/mocha.d.ts" />
/// <reference path="../../../typings/chai/chai.d.ts" />
import * as docx from "../../../docx"; import * as docx from "../../../docx";
import { assert } from "chai"; import { assert } from "chai";

View File

@ -1,6 +1,3 @@
/// <reference path="../../../typings/mocha/mocha.d.ts" />
/// <reference path="../../../typings/chai/chai.d.ts" />
import { ThematicBreak } from "../../../docx/paragraph/border"; import { ThematicBreak } from "../../../docx/paragraph/border";
import { assert } from "chai"; import { assert } from "chai";

View File

@ -1,6 +1,3 @@
/// <reference path="../../../typings/mocha/mocha.d.ts" />
/// <reference path="../../../typings/chai/chai.d.ts" />
import { Style } from "../../../docx/paragraph/style"; import { Style } from "../../../docx/paragraph/style";
import { assert } from "chai"; import { assert } from "chai";

View File

@ -1,8 +1,7 @@
/// <reference path="../../../typings/mocha/mocha.d.ts" />
/// <reference path="../../../typings/chai/chai.d.ts" />
import * as docx from "../../../docx"; import * as docx from "../../../docx";
import {assert} from "chai"; import { Formatter } from "../../../export/formatter";
import { Numbering } from "../../../numbering";
import { assert, expect } from "chai";
function jsonify(obj: Object) { function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj); let stringifiedJson = JSON.stringify(obj);
@ -116,4 +115,44 @@ describe("Paragraph", () => {
assert.isDefined(newJson.root[0].root[2]); assert.isDefined(newJson.root[0].root[2]);
}); });
}); });
describe("#setNumbering", () => {
it("should add list paragraph style to JSON", () => {
const numbering = new Numbering();
const numberedAbstract = numbering.createAbstractNumbering();
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
paragraph.setNumbering(letterNumbering, 0);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
});
it("it should add numbered properties", () => {
const numbering = new Numbering();
const numberedAbstract = numbering.createAbstractNumbering();
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
paragraph.setNumbering(letterNumbering, 0);
const tree = new Formatter().format(paragraph);
console.log(JSON.stringify(tree, null, 2));
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"_attr": {}},
{"w:pStyle": [{"_attr": {"w:val": "ListParagraph"}}]},
{
"w:numPr": [
{"w:ilvl": [{"_attr": {"w:val": 0}}]},
{"w:numId": [{"_attr": {"w:val": letterNumbering.id}}]}
]
},
],
},
]
})
});
});
}); });

View File

@ -10,7 +10,7 @@ describe("NumberProperties", () => {
let numberProperties: NumberProperties; let numberProperties: NumberProperties;
beforeEach(() => { beforeEach(() => {
numberProperties = new NumberProperties(); numberProperties = new NumberProperties(5, 10);
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
@ -22,11 +22,13 @@ describe("NumberProperties", () => {
it("should create a Page Break with a Indent Level inside", () => { it("should create a Page Break with a Indent Level inside", () => {
let newJson = jsonify(numberProperties); let newJson = jsonify(numberProperties);
assert.equal(newJson.root[0].rootKey, "w:ilvl"); assert.equal(newJson.root[0].rootKey, "w:ilvl");
assert.equal(newJson.root[0].root[0].root.val, 10);
}); });
it("should create a Page Break with a Number Id inside", () => { it("should create a Page Break with a Number Id inside", () => {
let newJson = jsonify(numberProperties); let newJson = jsonify(numberProperties);
assert.equal(newJson.root[1].rootKey, "w:numId"); assert.equal(newJson.root[1].rootKey, "w:numId");
assert.equal(newJson.root[1].root[0].root.val, 5);
}); });
}); });
}); });

View File

@ -0,0 +1,22 @@
import { expect } from "chai";
import { RunFonts } from "../../../docx/run/run-fonts";
import { Formatter } from "../../../export/formatter";
describe("RunFonts", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
const tree = new Formatter().format(new RunFonts("Times"));
expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}],
});
});
it("uses hint if given", () => {
const tree = new Formatter().format(new RunFonts("Times", "default"));
expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}],
});
});
});
});

View File

@ -1,10 +1,10 @@
import { assert, expect } from "chai";
import { Run } from "../../../docx/run"; import { Run } from "../../../docx/run";
import { TextRun } from "../../../docx/run/text-run"; import { TextRun } from "../../../docx/run/text-run";
import {assert} from "chai"; import { Formatter } from "../../../export/formatter";
function jsonify(obj: Object) { function jsonify(obj: object) {
let stringifiedJson = JSON.stringify(obj); return JSON.parse(JSON.stringify(obj));
return JSON.parse(stringifiedJson);
} }
describe("Run", () => { describe("Run", () => {
@ -17,7 +17,7 @@ describe("Run", () => {
describe("#bold()", () => { describe("#bold()", () => {
it("it should add bold to the properties", () => { it("it should add bold to the properties", () => {
run.bold(); run.bold();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b"); assert.equal(newJson.root[0].root[0].rootKey, "w:b");
}); });
}); });
@ -25,7 +25,7 @@ describe("Run", () => {
describe("#italic()", () => { describe("#italic()", () => {
it("it should add italics to the properties", () => { it("it should add italics to the properties", () => {
run.italic(); run.italic();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i"); assert.equal(newJson.root[0].root[0].rootKey, "w:i");
}); });
}); });
@ -33,7 +33,7 @@ describe("Run", () => {
describe("#underline()", () => { describe("#underline()", () => {
it("it should add underline to the properties", () => { it("it should add underline to the properties", () => {
run.underline(); run.underline();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:u"); assert.equal(newJson.root[0].root[0].rootKey, "w:u");
}); });
}); });
@ -41,7 +41,7 @@ describe("Run", () => {
describe("#smallCaps()", () => { describe("#smallCaps()", () => {
it("it should add smallCaps to the properties", () => { it("it should add smallCaps to the properties", () => {
run.smallCaps(); run.smallCaps();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps"); assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
}); });
}); });
@ -49,7 +49,7 @@ describe("Run", () => {
describe("#caps()", () => { describe("#caps()", () => {
it("it should add caps to the properties", () => { it("it should add caps to the properties", () => {
run.allCaps(); run.allCaps();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:caps"); assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
}); });
}); });
@ -57,7 +57,7 @@ describe("Run", () => {
describe("#strike()", () => { describe("#strike()", () => {
it("it should add strike to the properties", () => { it("it should add strike to the properties", () => {
run.strike(); run.strike();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:strike"); assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
}); });
}); });
@ -65,26 +65,40 @@ describe("Run", () => {
describe("#doubleStrike()", () => { describe("#doubleStrike()", () => {
it("it should add caps to the properties", () => { it("it should add caps to the properties", () => {
run.doubleStrike(); run.doubleStrike();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike"); assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
}); });
}); });
describe("#break()", () => { describe("#break()", () => {
it("it should add break to the run", () => { it("it should add break to the run", () => {
let run = new Run();
run.break(); run.break();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[1].rootKey, "w:br"); assert.equal(newJson.root[1].rootKey, "w:br");
}); });
}); });
describe("#tab()", () => { describe("#tab()", () => {
it("it should add break to the run", () => { it("it should add break to the run", () => {
let run = new Run();
run.tab(); run.tab();
let newJson = jsonify(run); const newJson = jsonify(run);
assert.equal(newJson.root[1].rootKey, "w:tab"); assert.equal(newJson.root[1].rootKey, "w:tab");
}); });
}); });
describe("#font()", () => {
it("should allow chaining calls", () => {
expect(run.font("Times")).to.equal(run);
});
it("should set the font as named", () => {
run.font("Times");
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
{"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]},
],
});
});
});
}); });

View File

@ -1,7 +1,3 @@
/// <reference path="../../typings/mocha/mocha.d.ts" />
/// <reference path="../../typings/lodash/lodash.d.ts" />
/// <reference path="../../typings/chai/chai.d.ts" />
import { Formatter } from "../../export/formatter"; import { Formatter } from "../../export/formatter";
import * as docx from "../../docx"; import * as docx from "../../docx";
import { Attributes } from "../../docx/xml-components"; import { Attributes } from "../../docx/xml-components";

View File

@ -1,16 +1,11 @@
/// <reference path="../../typings/mocha/mocha.d.ts" />
/// <reference path="../../typings/chai/chai.d.ts" />
/// <reference path="../../typings/archiver/archiver.d.ts" />
/// <reference path="../../typings/xml/xml.d.ts" />
import * as fs from "fs"; import * as fs from "fs";
import { LocalPacker } from "../../export/packer/local"; import { LocalPacker } from "../../export/packer/local";
import {assert} from "chai";
import { Document } from "../../docx/document"; import { Document } from "../../docx/document";
import { Properties } from "../../properties"; import { Properties } from "../../properties";
import { DefaultStyle } from "../../styles/sample"; import { DefaultStyle } from "../../styles/sample";
import { Paragraph } from "../../docx/paragraph"; import { Paragraph } from "../../docx/paragraph";
import { DefaultStylesFactory } from "../../styles/factory"; import { DefaultStylesFactory } from "../../styles/factory";
import { assert } from "chai";
describe("Packer", () => { describe("Packer", () => {
let packer: LocalPacker; let packer: LocalPacker;

View File

@ -1,24 +1,109 @@
/// <reference path="../typings/mocha/mocha.d.ts" /> import { expect } from "chai";
/// <reference path="../typings/chai/chai.d.ts" /> import { Formatter } from "../export/formatter";
import {assert} from "chai";
import { Numbering } from "../numbering"; import { Numbering } from "../numbering";
import { AbstractNumbering } from "../numbering/abstract-numbering";
import { Num } from "../numbering/num";
function jsonify(obj: Object) { function jsonify(obj: object) {
let stringifiedJson = JSON.stringify(obj); return JSON.parse(JSON.stringify(obj));
return JSON.parse(stringifiedJson);
} }
describe("", () => { describe("Numbering", () => {
let numbering = new Numbering; let numbering: Numbering;
beforeEach(() => { beforeEach(() => {
numbering = new Numbering(); numbering = new Numbering();
}); });
describe("#methodName()", () => { describe("#constructor", () => {
it("should ", () => { it("creates a default numbering with one abstract and one concrete instance", () => {
const tree = new Formatter().format(numbering);
expect(Object.keys(tree)).to.deep.equal(["w:numbering"]);
const abstractNums = tree["w:numbering"].filter((el) => el["w:abstractNum"]);
expect(abstractNums).to.have.lengthOf(1);
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
{_attr: {"w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0}},
{"w:multiLevelType": [{_attr: {"w:val": "hybridMultilevel"}}]},
]);
abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => {
expect(Object.keys(el)).to.have.lengthOf(1);
expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal([
"_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr",
]);
expect(el["w:lvl"]).to.have.deep.members([
{_attr: {"w:ilvl": ix, "w15:tentative": 1}},
{"w:start": [{_attr: {"w:val": 1}}]},
{"w:lvlJc": [{_attr: {"w:val": "left"}}]},
{"w:numFmt": [{_attr: {"w:val": "bullet"}}]},
]);
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
// {"w:lvlText": [{"_attr": {"w:val": "•"}}]},
// {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]},
// {"w:pPr": [{"_attr": {}},
// {"w:ind": [{"_attr": {"w:left": 720, "w:hanging": 360}}]}]},
});
});
});
describe("#createAbstractNumbering", () => {
it("returns a new AbstractNumbering instance", () => {
const a2 = numbering.createAbstractNumbering();
expect(a2).to.be.instanceof(AbstractNumbering);
});
it("assigns a unique ID to each abstract numbering it creates", () => {
const a2 = numbering.createAbstractNumbering();
const a3 = numbering.createAbstractNumbering();
expect(a2.id).not.to.equal(a3.id);
});
});
describe("#createConcreteNumbering", () => {
it("returns a new Num instance with its abstract ID set to the AbstractNumbering's ID", () => {
const a2 = numbering.createAbstractNumbering();
const n = numbering.createConcreteNumbering(a2);
expect(n).to.be.instanceof(Num);
const tree = new Formatter().format(numbering);
expect(n.id).to.equal(a2.id);
});
it("assigns a unique ID to each concrete numbering it creates", () => {
const a2 = numbering.createAbstractNumbering();
const n = numbering.createConcreteNumbering(a2);
const n2 = numbering.createConcreteNumbering(a2);
expect(n.id).not.to.equal(n2.id);
});
});
});
describe("AbstractNumbering", () => {
it("stores its ID at its .id property", () => {
const abstractNumbering = new AbstractNumbering(5);
expect(abstractNumbering.id).to.equal(5);
});
describe("#createLevel", () => {
it("creates a level with the given characteristics", () => {
const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "end");
const tree = new Formatter().format(level);
expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}})
expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]})
expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "end"}}]})
expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]})
expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]})
});
it("uses 'start' as the default alignment", () => {
const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)");
const tree = new Formatter().format(level);
expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}})
expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]})
expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "start"}}]})
expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]})
expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]})
}); });
}); });
}); });

View File

@ -1,5 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import { Properties } from "../properties"; import { Properties } from "../properties";
import { assert } from "chai"; import { assert } from "chai";

View File

@ -1,6 +1,3 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import { Styles } from "../styles"; import { Styles } from "../styles";
import { assert } from "chai"; import { assert } from "chai";

View File

@ -4,7 +4,6 @@
"sourceMap": true, "sourceMap": true,
"removeComments": true, "removeComments": true,
"preserveConstEnums": true, "preserveConstEnums": true,
//"outFile": "../build/build.js",
"outDir": "../build", "outDir": "../build",
"sourceRoot": "./", "sourceRoot": "./",
"rootDir": "./", "rootDir": "./",

View File

@ -1,39 +0,0 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"mocha/mocha.d.ts": {
"commit": "299b5caa22876ef27dc8e9a5b7fd7bf93457b6f4"
},
"lodash/lodash.d.ts": {
"commit": "299b5caa22876ef27dc8e9a5b7fd7bf93457b6f4"
},
"chai/chai.d.ts": {
"commit": "80057d687aefa736511e434cd2a6c0e9a6bb02bc"
},
"assertion-error/assertion-error.d.ts": {
"commit": "80057d687aefa736511e434cd2a6c0e9a6bb02bc"
},
"archiver/archiver.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
},
"node/node.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
},
"express/express.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
},
"express-serve-static-core/express-serve-static-core.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
},
"serve-static/serve-static.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
},
"mime/mime.d.ts": {
"commit": "e937b3e64af586d19f2ea29fdf771e9dc4feecc8"
}
}
}

35
ts/tslint.json Normal file
View File

@ -0,0 +1,35 @@
{
"extends": "tslint:latest",
"rules": {
"curly": true,
"one-variable-per-declaration": [
true
],
"no-any": true,
"no-consecutive-blank-lines": [
true
],
"no-require-imports": true,
"member-access": [
true
],
"indent": [
true,
"spaces"
],
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"typedef": [
true,
"call-signature",
"parameter",
"property-declaration"
],
"max-line-length": [
false
],
"max-classes-per-file": [
false
]
}
}

View File

@ -1,42 +0,0 @@
// Type definitions for archiver v0.15.0
// Project: https://github.com/archiverjs/node-archiver
// Definitions by: Esri <https://github.com/archiverjs/node-archiver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/* =================== USAGE ===================
import Archiver = require('archiver);
var archiver = Archiver.create('zip');
archiver.pipe(FS.createWriteStream('xxx'));
archiver.append(FS.createReadStream('xxx'));
archiver.finalize();
=============================================== */
/// <reference path="../node/node.d.ts" />
declare module "archiver" {
import * as FS from 'fs';
import * as STREAM from 'stream';
interface nameInterface {
name?: string;
}
interface Archiver extends STREAM.Transform {
pipe(writeStream: FS.WriteStream): void;
append(readStream: FS.ReadStream, name: nameInterface): void;
finalize(): void;
}
interface Options {
}
function archiver(format: string, options?: Options): Archiver;
namespace archiver {
function create(format: string, options?: Options): Archiver;
}
export = archiver;
}

View File

@ -1,15 +0,0 @@
// Type definitions for assertion-error 1.0.0
// Project: https://github.com/chaijs/assertion-error
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'assertion-error' {
class AssertionError implements Error {
constructor(message: string, props?: any, ssf?: Function);
name: string;
message: string;
showDiff: boolean;
stack: string;
}
export = AssertionError;
}

View File

@ -1,401 +0,0 @@
// Type definitions for chai 3.4.0
// Project: http://chaijs.com/
// Definitions by: Jed Mao <https://github.com/jedmao/>,
// Bart van der Schoor <https://github.com/Bartvds>,
// Andrew Brown <https://github.com/AGBrown>,
// Olivier Chevet <https://github.com/olivr70>,
// Matt Wistrand <https://github.com/mwistrand>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// <reference path="../assertion-error/assertion-error.d.ts"/>
declare namespace Chai {
interface ChaiStatic {
expect: ExpectStatic;
should(): Should;
/**
* Provides a way to extend the internals of Chai
*/
use(fn: (chai: any, utils: any) => void): ChaiStatic;
assert: AssertStatic;
config: Config;
AssertionError: typeof AssertionError;
}
export interface ExpectStatic extends AssertionStatic {
fail(actual?: any, expected?: any, message?: string, operator?: string): void;
}
export interface AssertStatic extends Assert {
}
export interface AssertionStatic {
(target: any, message?: string): Assertion;
}
interface ShouldAssertion {
equal(value1: any, value2: any, message?: string): void;
Throw: ShouldThrow;
throw: ShouldThrow;
exist(value: any, message?: string): void;
}
interface Should extends ShouldAssertion {
not: ShouldAssertion;
fail(actual: any, expected: any, message?: string, operator?: string): void;
}
interface ShouldThrow {
(actual: Function): void;
(actual: Function, expected: string|RegExp, message?: string): void;
(actual: Function, constructor: Error|Function, expected?: string|RegExp, message?: string): void;
}
interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
not: Assertion;
deep: Deep;
any: KeyFilter;
all: KeyFilter;
a: TypeComparison;
an: TypeComparison;
include: Include;
includes: Include;
contain: Include;
contains: Include;
ok: Assertion;
true: Assertion;
false: Assertion;
null: Assertion;
undefined: Assertion;
NaN: Assertion;
exist: Assertion;
empty: Assertion;
arguments: Assertion;
Arguments: Assertion;
equal: Equal;
equals: Equal;
eq: Equal;
eql: Equal;
eqls: Equal;
property: Property;
ownProperty: OwnProperty;
haveOwnProperty: OwnProperty;
ownPropertyDescriptor: OwnPropertyDescriptor;
haveOwnPropertyDescriptor: OwnPropertyDescriptor;
length: Length;
lengthOf: Length;
match: Match;
matches: Match;
string(string: string, message?: string): Assertion;
keys: Keys;
key(string: string): Assertion;
throw: Throw;
throws: Throw;
Throw: Throw;
respondTo: RespondTo;
respondsTo: RespondTo;
itself: Assertion;
satisfy: Satisfy;
satisfies: Satisfy;
closeTo: CloseTo;
approximately: CloseTo;
members: Members;
increase: PropertyChange;
increases: PropertyChange;
decrease: PropertyChange;
decreases: PropertyChange;
change: PropertyChange;
changes: PropertyChange;
extensible: Assertion;
sealed: Assertion;
frozen: Assertion;
oneOf(list: any[], message?: string): Assertion;
}
interface LanguageChains {
to: Assertion;
be: Assertion;
been: Assertion;
is: Assertion;
that: Assertion;
which: Assertion;
and: Assertion;
has: Assertion;
have: Assertion;
with: Assertion;
at: Assertion;
of: Assertion;
same: Assertion;
}
interface NumericComparison {
above: NumberComparer;
gt: NumberComparer;
greaterThan: NumberComparer;
least: NumberComparer;
gte: NumberComparer;
below: NumberComparer;
lt: NumberComparer;
lessThan: NumberComparer;
most: NumberComparer;
lte: NumberComparer;
within(start: number, finish: number, message?: string): Assertion;
}
interface NumberComparer {
(value: number, message?: string): Assertion;
}
interface TypeComparison {
(type: string, message?: string): Assertion;
instanceof: InstanceOf;
instanceOf: InstanceOf;
}
interface InstanceOf {
(constructor: Object, message?: string): Assertion;
}
interface CloseTo {
(expected: number, delta: number, message?: string): Assertion;
}
interface Deep {
equal: Equal;
include: Include;
property: Property;
members: Members;
}
interface KeyFilter {
keys: Keys;
}
interface Equal {
(value: any, message?: string): Assertion;
}
interface Property {
(name: string, value?: any, message?: string): Assertion;
}
interface OwnProperty {
(name: string, message?: string): Assertion;
}
interface OwnPropertyDescriptor {
(name: string, descriptor: PropertyDescriptor, message?: string): Assertion;
(name: string, message?: string): Assertion;
}
interface Length extends LanguageChains, NumericComparison {
(length: number, message?: string): Assertion;
}
interface Include {
(value: Object, message?: string): Assertion;
(value: string, message?: string): Assertion;
(value: number, message?: string): Assertion;
keys: Keys;
members: Members;
any: KeyFilter;
all: KeyFilter;
}
interface Match {
(regexp: RegExp|string, message?: string): Assertion;
}
interface Keys {
(...keys: string[]): Assertion;
(keys: any[]): Assertion;
(keys: Object): Assertion;
}
interface Throw {
(): Assertion;
(expected: string, message?: string): Assertion;
(expected: RegExp, message?: string): Assertion;
(constructor: Error, expected?: string, message?: string): Assertion;
(constructor: Error, expected?: RegExp, message?: string): Assertion;
(constructor: Function, expected?: string, message?: string): Assertion;
(constructor: Function, expected?: RegExp, message?: string): Assertion;
}
interface RespondTo {
(method: string, message?: string): Assertion;
}
interface Satisfy {
(matcher: Function, message?: string): Assertion;
}
interface Members {
(set: any[], message?: string): Assertion;
}
interface PropertyChange {
(object: Object, prop: string, msg?: string): Assertion;
}
export interface Assert {
/**
* @param expression Expression to test for truthiness.
* @param message Message to display on error.
*/
(expression: any, message?: string): void;
fail(actual?: any, expected?: any, msg?: string, operator?: string): void;
ok(val: any, msg?: string): void;
isOk(val: any, msg?: string): void;
notOk(val: any, msg?: string): void;
isNotOk(val: any, msg?: string): void;
equal(act: any, exp: any, msg?: string): void;
notEqual(act: any, exp: any, msg?: string): void;
strictEqual(act: any, exp: any, msg?: string): void;
notStrictEqual(act: any, exp: any, msg?: string): void;
deepEqual(act: any, exp: any, msg?: string): void;
notDeepEqual(act: any, exp: any, msg?: string): void;
isTrue(val: any, msg?: string): void;
isFalse(val: any, msg?: string): void;
isNotTrue(val: any, msg?: string): void;
isNotFalse(val: any, msg?: string): void;
isNull(val: any, msg?: string): void;
isNotNull(val: any, msg?: string): void;
isUndefined(val: any, msg?: string): void;
isDefined(val: any, msg?: string): void;
isNaN(val: any, msg?: string): void;
isNotNaN(val: any, msg?: string): void;
isAbove(val: number, abv: number, msg?: string): void;
isBelow(val: number, blw: number, msg?: string): void;
isAtLeast(val: number, atlst: number, msg?: string): void;
isAtMost(val: number, atmst: number, msg?: string): void;
isFunction(val: any, msg?: string): void;
isNotFunction(val: any, msg?: string): void;
isObject(val: any, msg?: string): void;
isNotObject(val: any, msg?: string): void;
isArray(val: any, msg?: string): void;
isNotArray(val: any, msg?: string): void;
isString(val: any, msg?: string): void;
isNotString(val: any, msg?: string): void;
isNumber(val: any, msg?: string): void;
isNotNumber(val: any, msg?: string): void;
isBoolean(val: any, msg?: string): void;
isNotBoolean(val: any, msg?: string): void;
typeOf(val: any, type: string, msg?: string): void;
notTypeOf(val: any, type: string, msg?: string): void;
instanceOf(val: any, type: Function, msg?: string): void;
notInstanceOf(val: any, type: Function, msg?: string): void;
include(exp: string, inc: any, msg?: string): void;
include(exp: any[], inc: any, msg?: string): void;
notInclude(exp: string, inc: any, msg?: string): void;
notInclude(exp: any[], inc: any, msg?: string): void;
match(exp: any, re: RegExp, msg?: string): void;
notMatch(exp: any, re: RegExp, msg?: string): void;
property(obj: Object, prop: string, msg?: string): void;
notProperty(obj: Object, prop: string, msg?: string): void;
deepProperty(obj: Object, prop: string, msg?: string): void;
notDeepProperty(obj: Object, prop: string, msg?: string): void;
propertyVal(obj: Object, prop: string, val: any, msg?: string): void;
propertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
deepPropertyVal(obj: Object, prop: string, val: any, msg?: string): void;
deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
lengthOf(exp: any, len: number, msg?: string): void;
//alias frenzy
throw(fn: Function, msg?: string): void;
throw(fn: Function, regExp: RegExp): void;
throw(fn: Function, errType: Function, msg?: string): void;
throw(fn: Function, errType: Function, regExp: RegExp): void;
throws(fn: Function, msg?: string): void;
throws(fn: Function, regExp: RegExp): void;
throws(fn: Function, errType: Function, msg?: string): void;
throws(fn: Function, errType: Function, regExp: RegExp): void;
Throw(fn: Function, msg?: string): void;
Throw(fn: Function, regExp: RegExp): void;
Throw(fn: Function, errType: Function, msg?: string): void;
Throw(fn: Function, errType: Function, regExp: RegExp): void;
doesNotThrow(fn: Function, msg?: string): void;
doesNotThrow(fn: Function, regExp: RegExp): void;
doesNotThrow(fn: Function, errType: Function, msg?: string): void;
doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void;
operator(val: any, operator: string, val2: any, msg?: string): void;
closeTo(act: number, exp: number, delta: number, msg?: string): void;
approximately(act: number, exp: number, delta: number, msg?: string): void;
sameMembers(set1: any[], set2: any[], msg?: string): void;
sameDeepMembers(set1: any[], set2: any[], msg?: string): void;
includeMembers(superset: any[], subset: any[], msg?: string): void;
ifError(val: any, msg?: string): void;
isExtensible(obj: {}, msg?: string): void;
extensible(obj: {}, msg?: string): void;
isNotExtensible(obj: {}, msg?: string): void;
notExtensible(obj: {}, msg?: string): void;
isSealed(obj: {}, msg?: string): void;
sealed(obj: {}, msg?: string): void;
isNotSealed(obj: {}, msg?: string): void;
notSealed(obj: {}, msg?: string): void;
isFrozen(obj: Object, msg?: string): void;
frozen(obj: Object, msg?: string): void;
isNotFrozen(obj: Object, msg?: string): void;
notFrozen(obj: Object, msg?: string): void;
oneOf(inList: any, list: any[], msg?: string): void;
}
export interface Config {
includeStack: boolean;
}
export class AssertionError {
constructor(message: string, _props?: any, ssf?: Function);
name: string;
message: string;
showDiff: boolean;
stack: string;
}
}
declare var chai: Chai.ChaiStatic;
declare module "chai" {
export = chai;
}
interface Object {
should: Chai.Assertion;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,54 +0,0 @@
// Type definitions for Express 4.x
// Project: http://expressjs.com
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/* =================== USAGE ===================
import * as express from "express";
var app = express();
=============================================== */
/// <reference path="../serve-static/serve-static.d.ts" />
/// <reference path="../express-serve-static-core/express-serve-static-core.d.ts" />
declare module "express" {
import * as serveStatic from "serve-static";
import * as core from "express-serve-static-core";
/**
* Creates an Express application. The express() function is a top-level function exported by the express module.
*/
function e(): core.Express;
namespace e {
/**
* This is the only built-in middleware function in Express. It serves static files and is based on serve-static.
*/
var static: typeof serveStatic;
export function Router(options?: any): core.Router;
interface Application extends core.Application { }
interface CookieOptions extends core.CookieOptions { }
interface Errback extends core.Errback { }
interface ErrorRequestHandler extends core.ErrorRequestHandler { }
interface Express extends core.Express { }
interface Handler extends core.Handler { }
interface IRoute extends core.IRoute { }
interface IRouter<T> extends core.IRouter<T> { }
interface IRouterMatcher<T> extends core.IRouterMatcher<T> { }
interface MediaType extends core.MediaType { }
interface NextFunction extends core.NextFunction { }
interface Request extends core.Request { }
interface RequestHandler extends core.RequestHandler { }
interface RequestParamHandler extends core.RequestParamHandler { }
export interface Response extends core.Response { }
interface Router extends core.Router { }
interface Send extends core.Send { }
}
export = e;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +0,0 @@
// Type definitions for mime
// Project: https://github.com/broofa/node-mime
// Definitions by: Jeff Goddard <https://github.com/jedigo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts
declare module "mime" {
export function lookup(path: string): string;
export function extension(mime: string): string;
export function load(filepath: string): void;
export function define(mimes: Object): void;
interface Charsets {
lookup(mime: string): string;
}
export var charsets: Charsets;
export var default_type: string;
}

View File

@ -1,236 +0,0 @@
// Type definitions for mocha 2.2.5
// Project: http://mochajs.org/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>, jt000 <https://github.com/jt000>, Vadim Macagon <https://github.com/enlight>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface MochaSetupOptions {
//milliseconds to wait before considering a test slow
slow?: number;
// timeout in milliseconds
timeout?: number;
// ui name "bdd", "tdd", "exports" etc
ui?: string;
//array of accepted globals
globals?: any[];
// reporter instance (function or string), defaults to `mocha.reporters.Spec`
reporter?: any;
// bail on the first test failure
bail?: boolean;
// ignore global leaks
ignoreLeaks?: boolean;
// grep string or regexp to filter tests with
grep?: any;
}
interface MochaDone {
(error?: Error): void;
}
declare var mocha: Mocha;
declare var describe: Mocha.IContextDefinition;
declare var xdescribe: Mocha.IContextDefinition;
// alias for `describe`
declare var context: Mocha.IContextDefinition;
// alias for `describe`
declare var suite: Mocha.IContextDefinition;
declare var it: Mocha.ITestDefinition;
declare var xit: Mocha.ITestDefinition;
// alias for `it`
declare var test: Mocha.ITestDefinition;
declare function before(action: () => void): void;
declare function before(action: (done: MochaDone) => void): void;
declare function before(description: string, action: () => void): void;
declare function before(description: string, action: (done: MochaDone) => void): void;
declare function setup(action: () => void): void;
declare function setup(action: (done: MochaDone) => void): void;
declare function after(action: () => void): void;
declare function after(action: (done: MochaDone) => void): void;
declare function after(description: string, action: () => void): void;
declare function after(description: string, action: (done: MochaDone) => void): void;
declare function teardown(action: () => void): void;
declare function teardown(action: (done: MochaDone) => void): void;
declare function beforeEach(action: () => void): void;
declare function beforeEach(action: (done: MochaDone) => void): void;
declare function beforeEach(description: string, action: () => void): void;
declare function beforeEach(description: string, action: (done: MochaDone) => void): void;
declare function suiteSetup(action: () => void): void;
declare function suiteSetup(action: (done: MochaDone) => void): void;
declare function afterEach(action: () => void): void;
declare function afterEach(action: (done: MochaDone) => void): void;
declare function afterEach(description: string, action: () => void): void;
declare function afterEach(description: string, action: (done: MochaDone) => void): void;
declare function suiteTeardown(action: () => void): void;
declare function suiteTeardown(action: (done: MochaDone) => void): void;
declare class Mocha {
constructor(options?: {
grep?: RegExp;
ui?: string;
reporter?: string;
timeout?: number;
bail?: boolean;
});
/** Setup mocha with the given options. */
setup(options: MochaSetupOptions): Mocha;
bail(value?: boolean): Mocha;
addFile(file: string): Mocha;
/** Sets reporter by name, defaults to "spec". */
reporter(name: string): Mocha;
/** Sets reporter constructor, defaults to mocha.reporters.Spec. */
reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;
ui(value: string): Mocha;
grep(value: string): Mocha;
grep(value: RegExp): Mocha;
invert(): Mocha;
ignoreLeaks(value: boolean): Mocha;
checkLeaks(): Mocha;
/**
* Function to allow assertion libraries to throw errors directly into mocha.
* This is useful when running tests in a browser because window.onerror will
* only receive the 'message' attribute of the Error.
*/
throwError(error: Error): void;
/** Enables growl support. */
growl(): Mocha;
globals(value: string): Mocha;
globals(values: string[]): Mocha;
useColors(value: boolean): Mocha;
useInlineDiffs(value: boolean): Mocha;
timeout(value: number): Mocha;
slow(value: number): Mocha;
enableTimeouts(value: boolean): Mocha;
asyncOnly(value: boolean): Mocha;
noHighlighting(value: boolean): Mocha;
/** Runs tests and invokes `onComplete()` when finished. */
run(onComplete?: (failures: number) => void): Mocha.IRunner;
}
// merge the Mocha class declaration with a module
declare namespace Mocha {
/** Partial interface for Mocha's `Runnable` class. */
interface IRunnable {
title: string;
fn: Function;
async: boolean;
sync: boolean;
timedOut: boolean;
}
/** Partial interface for Mocha's `Suite` class. */
interface ISuite {
parent: ISuite;
title: string;
fullTitle(): string;
}
/** Partial interface for Mocha's `Test` class. */
interface ITest extends IRunnable {
parent: ISuite;
pending: boolean;
fullTitle(): string;
}
/** Partial interface for Mocha's `Runner` class. */
interface IRunner {}
interface IContextDefinition {
(description: string, spec: () => void): ISuite;
only(description: string, spec: () => void): ISuite;
skip(description: string, spec: () => void): void;
timeout(ms: number): void;
}
interface ITestDefinition {
(expectation: string, assertion?: () => void): ITest;
(expectation: string, assertion?: (done: MochaDone) => void): ITest;
only(expectation: string, assertion?: () => void): ITest;
only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
skip(expectation: string, assertion?: () => void): void;
skip(expectation: string, assertion?: (done: MochaDone) => void): void;
timeout(ms: number): void;
}
export module reporters {
export class Base {
stats: {
suites: number;
tests: number;
passes: number;
pending: number;
failures: number;
};
constructor(runner: IRunner);
}
export class Doc extends Base {}
export class Dot extends Base {}
export class HTML extends Base {}
export class HTMLCov extends Base {}
export class JSON extends Base {}
export class JSONCov extends Base {}
export class JSONStream extends Base {}
export class Landing extends Base {}
export class List extends Base {}
export class Markdown extends Base {}
export class Min extends Base {}
export class Nyan extends Base {}
export class Progress extends Base {
/**
* @param options.open String used to indicate the start of the progress bar.
* @param options.complete String used to indicate a complete test on the progress bar.
* @param options.incomplete String used to indicate an incomplete test on the progress bar.
* @param options.close String used to indicate the end of the progress bar.
*/
constructor(runner: IRunner, options?: {
open?: string;
complete?: string;
incomplete?: string;
close?: string;
});
}
export class Spec extends Base {}
export class TAP extends Base {}
export class XUnit extends Base {
constructor(runner: IRunner, options?: any);
}
}
}
declare module "mocha" {
export = Mocha;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,86 +0,0 @@
// Type definitions for serve-static 1.7.1
// Project: https://github.com/expressjs/serve-static
// Definitions by: Uros Smolnik <https://github.com/urossmolnik/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/* =================== USAGE ===================
import * as serveStatic from "serve-static";
app.use(serveStatic("public/ftp", {"index": ["default.html", "default.htm"]}))
=============================================== */
/// <reference path="../express-serve-static-core/express-serve-static-core.d.ts" />
/// <reference path="../mime/mime.d.ts" />
declare module "serve-static" {
import * as express from "express-serve-static-core";
/**
* Create a new middleware function to serve files from within a given root directory.
* The file to serve will be determined by combining req.url with the provided root directory.
* When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.
*/
function serveStatic(root: string, options?: {
/**
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
* Note this check is done on the path itself without checking if the path actually exists on the disk.
* If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny").
* The default value is 'ignore'.
* 'allow' No special treatment for dotfiles
* 'deny' Send a 403 for any request for a dotfile
* 'ignore' Pretend like the dotfile does not exist and call next()
*/
dotfiles?: string;
/**
* Enable or disable etag generation, defaults to true.
*/
etag?: boolean;
/**
* Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.
* The first that exists will be served. Example: ['html', 'htm'].
* The default value is false.
*/
extensions?: string[];
/**
* By default this module will send "index.html" files in response to a request on a directory.
* To disable this set false or to supply a new index pass a string or an array in preferred order.
*/
index?: boolean|string|string[];
/**
* Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.
*/
lastModified?: boolean;
/**
* Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.
*/
maxAge?: number|string;
/**
* Redirect to trailing "/" when the pathname is a dir. Defaults to true.
*/
redirect?: boolean;
/**
* Function to set custom headers on response. Alterations to the headers need to occur synchronously.
* The function is called as fn(res, path, stat), where the arguments are:
* res the response object
* path the file path that is being sent
* stat the stat object of the file that is being sent
*/
setHeaders?: (res: express.Response, path: string, stat: any) => any;
}): express.Handler;
import * as m from "mime";
namespace serveStatic {
var mime: typeof m;
}
export = serveStatic;
}

12
ts/typings/tsd.d.ts vendored
View File

@ -1,12 +0,0 @@
/// <reference path="mocha/mocha.d.ts" />
/// <reference path="lodash/lodash.d.ts" />
/// <reference path="assertion-error/assertion-error.d.ts" />
/// <reference path="chai/chai.d.ts" />
/// <reference path="archiver/archiver.d.ts" />
/// <reference path="node/node.d.ts" />
/// <reference path="express-serve-static-core/express-serve-static-core.d.ts" />
/// <reference path="express/express.d.ts" />
/// <reference path="mime/mime.d.ts" />
/// <reference path="serve-static/serve-static.d.ts" />
/// <reference path="xml/xml.d.ts" />

View File

@ -1,8 +0,0 @@
declare module "xml" {
function xml(xmlObject: any, options?: any): string;
namespace xml {
}
export = xml;
}