Compare commits
54 Commits
Author | SHA1 | Date | |
---|---|---|---|
77255c9d5e | |||
e10b8889f7 | |||
744b16b753 | |||
77824ce1d2 | |||
d2f777c4e5 | |||
946a222d37 | |||
279a5a93f1 | |||
0e89606ec9 | |||
72683ea990 | |||
88cf5f5065 | |||
540518bd54 | |||
03b34915c6 | |||
f6eb412357 | |||
ca769cc849 | |||
727471b7e3 | |||
1a37242a3d | |||
81e0d56918 | |||
237be76d33 | |||
a454ff9643 | |||
f7b90d4ff3 | |||
cee515e43f | |||
0e9532d835 | |||
4b300e4def | |||
1fe7ab90f2 | |||
a3d2323254 | |||
0b2de737de | |||
0a70d932a0 | |||
6b702c4bd6 | |||
709ff25702 | |||
82998d4f6b | |||
6e6a06eba4 | |||
ae70c2dfde | |||
28e11a9b08 | |||
f5e81f1dfc | |||
38138049fe | |||
5511024ca6 | |||
ef1407e640 | |||
f822bbb26f | |||
52c4e3cabd | |||
9ced196678 | |||
ef6e195e89 | |||
a77d520f41 | |||
8eb11bca29 | |||
660a81633f | |||
a917247b60 | |||
f492b3fe04 | |||
96a8942455 | |||
bca478bb81 | |||
f5de5fef4d | |||
0e9301c0b5 | |||
b0869567c6 | |||
0585a25a5a | |||
9804091f6a | |||
9c3023019f |
2
.gitignore
vendored
2
.gitignore
vendored
@ -37,4 +37,4 @@ build
|
||||
build-tests
|
||||
|
||||
# vscode
|
||||
ts/.vscode
|
||||
.vscode
|
||||
|
40
.npmignore
Normal file
40
.npmignore
Normal 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
|
16
README.md
16
README.md
@ -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.
|
||||
|
||||
[](https://nodei.co/npm/docx/)
|
||||
|
||||

|
||||
|
||||
# Table of Contents
|
||||
- [Install](#)
|
||||
- [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
|
||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
||||
[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
|
25
package.json
25
package.json
@ -1,13 +1,19 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "1.0.1",
|
||||
"version": "1.2.1",
|
||||
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
"pretest": "rimraf ./build-tests && tsc -p ts/test-tsconfig.json",
|
||||
"test": "mocha ./build-tests --recursive",
|
||||
"prepublish": "tsc -p ts"
|
||||
"prepublishOnly": "npm run build",
|
||||
"lint": "tslint --project ./ts",
|
||||
"build": "rimraf ./build && tsc -p ts"
|
||||
},
|
||||
"files": [
|
||||
"ts",
|
||||
"build"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/dolanmiu/docx.git"
|
||||
@ -16,17 +22,21 @@
|
||||
"office",
|
||||
"generate",
|
||||
"document",
|
||||
"doc"
|
||||
"doc",
|
||||
"officegen",
|
||||
"clippy"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/archiver": "^0.15.37",
|
||||
"@types/express": "^4.0.35",
|
||||
"@types/lodash": "^4.14.54",
|
||||
"app-root-path": "^2.0.1",
|
||||
"archiver": "^1.3.0",
|
||||
"install": "^0.8.7",
|
||||
"lodash": "^4.6.1",
|
||||
"npm": "^4.3.0",
|
||||
"xml": "^1.0.1"
|
||||
},
|
||||
"typescript": {
|
||||
"definition": "ts/typings/index.d.ts"
|
||||
},
|
||||
"author": "Dolan Miu",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
@ -34,9 +44,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/dolanmiu/docx#readme",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^3.4.35",
|
||||
"@types/mocha": "^2.2.39",
|
||||
"chai": "^3.5.0",
|
||||
"mocha": "^3.2.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"tslint": "^4.5.1",
|
||||
"typescript": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
|
||||
export class Columns extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:cols");
|
||||
this.root.push(new Attributes({
|
||||
space: "708"
|
||||
space: "708",
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
|
||||
export class DocumentGrid extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:docGrid");
|
||||
this.root.push(new Attributes({
|
||||
linePitch: "360"
|
||||
linePitch: "360",
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
import { SectionProperties } from "./section-properties";
|
||||
|
||||
export class Body extends XmlComponent {
|
||||
@ -8,7 +8,7 @@ export class Body extends XmlComponent {
|
||||
// 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.push(component);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
|
||||
export class PageMargin extends XmlComponent {
|
||||
|
||||
@ -11,7 +11,7 @@ export class PageMargin extends XmlComponent {
|
||||
left: "1440",
|
||||
header: "708",
|
||||
footer: "708",
|
||||
gutter: "0"
|
||||
gutter: "0",
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
|
||||
export class PageSize extends XmlComponent {
|
||||
|
||||
@ -6,7 +6,7 @@ export class PageSize extends XmlComponent {
|
||||
super("w:pgSz");
|
||||
this.root.push(new Attributes({
|
||||
w: "11906",
|
||||
h: "16838"
|
||||
h: "16838",
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import {XmlComponent, Attributes} from "../../xml-components";
|
||||
import {PageSize} from "./page-size";
|
||||
import {PageMargin} from "./page-margin";
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
import { Columns } from "./columns";
|
||||
import { DocumentGrid } from "./doc-grid";
|
||||
import { PageMargin } from "./page-margin";
|
||||
import { PageSize } from "./page-size";
|
||||
|
||||
export class SectionProperties extends XmlComponent {
|
||||
|
||||
@ -11,7 +11,7 @@ export class SectionProperties extends XmlComponent {
|
||||
this.root.push(new Attributes({
|
||||
rsidR: "00B64E8F",
|
||||
rsidRPr: "00D842E4",
|
||||
rsidSect: "000A6AD0"
|
||||
rsidSect: "000A6AD0",
|
||||
}));
|
||||
this.root.push(new PageSize());
|
||||
this.root.push(new PageMargin());
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { XmlAttributeComponent } from "../xml-components";
|
||||
|
||||
interface DocumentAttributesProperties {
|
||||
interface IDocumentAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
@ -28,7 +28,7 @@ interface DocumentAttributesProperties {
|
||||
|
||||
export class DocumentAttributes extends XmlAttributeComponent {
|
||||
|
||||
constructor(properties?: DocumentAttributesProperties) {
|
||||
constructor(properties?: IDocumentAttributesProperties) {
|
||||
super({
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
@ -52,7 +52,7 @@ export class DocumentAttributes extends XmlAttributeComponent {
|
||||
dcterms: "xmlns:dcterms",
|
||||
dcmitype: "xmlns:dcmitype",
|
||||
xsi: "xmlns:xsi",
|
||||
type: "xsi:type"
|
||||
type: "xsi:type",
|
||||
}, properties);
|
||||
|
||||
this.root = properties;
|
||||
|
@ -1,8 +1,7 @@
|
||||
import {XmlComponent} from "../xml-components";
|
||||
import {DocumentAttributes} from "./document-attributes";
|
||||
import {Body} from "./body";
|
||||
import { Paragraph } from "../paragraph";
|
||||
|
||||
import { XmlComponent } from "../xml-components";
|
||||
import { Body } from "./body";
|
||||
import { DocumentAttributes } from "./document-attributes";
|
||||
export class Document extends XmlComponent {
|
||||
private body: Body;
|
||||
|
||||
@ -25,17 +24,17 @@ export class Document extends XmlComponent {
|
||||
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
||||
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
|
||||
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
|
||||
Ignorable: "w14 w15 wp14"
|
||||
Ignorable: "w14 w15 wp14",
|
||||
}));
|
||||
this.body = new Body();
|
||||
this.root.push(this.body);
|
||||
}
|
||||
|
||||
addParagraph(paragraph: Paragraph): void {
|
||||
public addParagraph(paragraph: Paragraph): void {
|
||||
this.body.push(paragraph);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
public clearVariables(): void {
|
||||
this.body.clearVariables();
|
||||
delete this.body;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export { Document } from "./document";
|
||||
export { Paragraph } from "./paragraph";
|
||||
export {Run} from "./run"
|
||||
export {TextRun} from "./run/text-run"
|
||||
export { Run } from "./run";
|
||||
export { TextRun } from "./run/text-run";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
class Border extends XmlComponent {
|
||||
|
||||
@ -8,7 +8,7 @@ class Border extends XmlComponent {
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6"
|
||||
sz: "6",
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -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 { PageBreak } from "./page-break";
|
||||
import {TextRun} from "../run/text-run";
|
||||
import { ParagraphProperties } from "./properties";
|
||||
import {MaxRightTabStop, LeftTabStop} from "./tab-stop";
|
||||
import { Style } from "./style";
|
||||
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
||||
import { NumberProperties } from "./unordered-list";
|
||||
|
||||
class Alignment extends XmlComponent {
|
||||
@ -12,7 +13,7 @@ class Alignment extends XmlComponent {
|
||||
constructor(type: string) {
|
||||
super("w:jc");
|
||||
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);
|
||||
return this;
|
||||
}
|
||||
|
||||
heading1(): Paragraph {
|
||||
public heading1(): Paragraph {
|
||||
this.properties.push(new Style("Heading1"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading2(): Paragraph {
|
||||
public heading2(): Paragraph {
|
||||
this.properties.push(new Style("Heading2"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading3(): Paragraph {
|
||||
public heading3(): Paragraph {
|
||||
this.properties.push(new Style("Heading3"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading4(): Paragraph {
|
||||
public heading4(): Paragraph {
|
||||
this.properties.push(new Style("Heading4"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading5(): Paragraph {
|
||||
public heading5(): Paragraph {
|
||||
this.properties.push(new Style("Heading5"));
|
||||
return this;
|
||||
}
|
||||
|
||||
title(): Paragraph {
|
||||
public title(): Paragraph {
|
||||
this.properties.push(new Style("Title"));
|
||||
return this;
|
||||
}
|
||||
|
||||
center(): Paragraph {
|
||||
public center(): Paragraph {
|
||||
this.properties.push(new Alignment("center"));
|
||||
return this;
|
||||
}
|
||||
|
||||
left(): Paragraph {
|
||||
public left(): Paragraph {
|
||||
this.properties.push(new Alignment("left"));
|
||||
return this;
|
||||
}
|
||||
|
||||
right(): Paragraph {
|
||||
public right(): Paragraph {
|
||||
this.properties.push(new Alignment("right"));
|
||||
return this;
|
||||
}
|
||||
|
||||
justified(): Paragraph {
|
||||
public justified(): Paragraph {
|
||||
this.properties.push(new Alignment("both"));
|
||||
return this;
|
||||
}
|
||||
|
||||
thematicBreak(): Paragraph {
|
||||
public thematicBreak(): Paragraph {
|
||||
this.properties.push(new ThematicBreak());
|
||||
return this;
|
||||
}
|
||||
|
||||
pageBreak(): Paragraph {
|
||||
public pageBreak(): Paragraph {
|
||||
this.properties.push(new PageBreak());
|
||||
return this;
|
||||
}
|
||||
|
||||
maxRightTabStop(): Paragraph {
|
||||
public maxRightTabStop(): Paragraph {
|
||||
this.properties.push(new MaxRightTabStop());
|
||||
return this;
|
||||
}
|
||||
|
||||
leftTabStop(position: number): Paragraph {
|
||||
public leftTabStop(position: number): Paragraph {
|
||||
this.properties.push(new LeftTabStop(position));
|
||||
return this;
|
||||
}
|
||||
|
||||
bullet(): Paragraph {
|
||||
public bullet(): Paragraph {
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Run } from "../run";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
class Break extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:br");
|
||||
this.root.push(new Attributes({
|
||||
type: "page"
|
||||
type: "page",
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
export class ParagraphProperties extends XmlComponent {
|
||||
|
||||
@ -7,7 +7,7 @@ export class ParagraphProperties extends XmlComponent {
|
||||
this.root.push(new Attributes());
|
||||
}
|
||||
|
||||
push(item: XmlComponent): void {
|
||||
public push(item: XmlComponent): void {
|
||||
this.root.push(item);
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
|
||||
constructor(type: string) {
|
||||
super("w:pStyle");
|
||||
this.root.push(new Attributes({
|
||||
val: type
|
||||
val: type,
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
class TabStop extends XmlComponent {
|
||||
|
||||
@ -14,7 +14,7 @@ class Tab extends XmlComponent {
|
||||
super("w:tab");
|
||||
this.root.push(new Attributes({
|
||||
val: value,
|
||||
pos: position
|
||||
pos: position,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
import { Style } from "./style";
|
||||
|
||||
export class NumberProperties extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
constructor(numberId: number, indentLevel: number) {
|
||||
super("w:numPr");
|
||||
this.root.push(new IndentLevel(0));
|
||||
this.root.push(new NumberId(1));
|
||||
this.root.push(new IndentLevel(indentLevel));
|
||||
this.root.push(new NumberId(numberId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ class IndentLevel extends XmlComponent {
|
||||
constructor(level: number) {
|
||||
super("w:ilvl");
|
||||
this.root.push(new Attributes({
|
||||
val: level
|
||||
val: level,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ class NumberId extends XmlComponent {
|
||||
constructor(id: number) {
|
||||
super("w:numId");
|
||||
this.root.push(new Attributes({
|
||||
val: id
|
||||
val: id,
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
export class Bold extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:b");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,7 @@ export class Italics extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:i");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ export class Caps extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:caps");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,7 @@ export class Color extends XmlComponent {
|
||||
constructor(color: string) {
|
||||
super("w:color");
|
||||
this.root.push(new Attributes({
|
||||
val: color
|
||||
val: color,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -45,7 +45,7 @@ export class DoubleStrike extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:dstrike");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ export class Emboss extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:emboss");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ export class Imprint extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:imprint");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ export class Shadow extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:shadow");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,7 @@ export class SmallCaps extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:smallCaps");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ export class Strike extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:strike");
|
||||
this.root.push(new Attributes({
|
||||
val: true
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ export class Size extends XmlComponent {
|
||||
constructor(size: number) {
|
||||
super("w:sz");
|
||||
this.root.push(new Attributes({
|
||||
val: size
|
||||
val: size,
|
||||
}));
|
||||
}
|
||||
}
|
@ -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 {SmallCaps, Caps} from "./caps";
|
||||
import {Strike, DoubleStrike} from "./strike";
|
||||
import { Caps, SmallCaps } from "./caps";
|
||||
import { Bold, Italics } from "./formatting";
|
||||
import { RunProperties } from "./properties";
|
||||
import { RunFonts } from "./run-fonts";
|
||||
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 {
|
||||
private properties: RunProperties;
|
||||
|
||||
|
||||
constructor() {
|
||||
super("w:r");
|
||||
this.properties = new RunProperties();
|
||||
this.root.push(this.properties);
|
||||
}
|
||||
|
||||
bold(): Run {
|
||||
public bold(): Run {
|
||||
this.properties.push(new Bold());
|
||||
return this;
|
||||
}
|
||||
|
||||
italic(): Run {
|
||||
public italic(): Run {
|
||||
this.properties.push(new Italics());
|
||||
return this;
|
||||
}
|
||||
|
||||
underline(): Run {
|
||||
public underline(): Run {
|
||||
this.properties.push(new Underline());
|
||||
return this;
|
||||
}
|
||||
|
||||
break(): Run {
|
||||
public break(): Run {
|
||||
this.root.splice(1, 0, new Break());
|
||||
return this;
|
||||
}
|
||||
|
||||
tab(): Run {
|
||||
public tab(): Run {
|
||||
this.root.splice(1, 0, new Tab());
|
||||
return this;
|
||||
}
|
||||
|
||||
smallCaps(): Run {
|
||||
public smallCaps(): Run {
|
||||
this.properties.push(new SmallCaps());
|
||||
return this;
|
||||
}
|
||||
|
||||
allCaps(): Run {
|
||||
public allCaps(): Run {
|
||||
this.properties.push(new Caps());
|
||||
return this;
|
||||
}
|
||||
|
||||
strike(): Run {
|
||||
public strike(): Run {
|
||||
this.properties.push(new Strike());
|
||||
return this;
|
||||
}
|
||||
|
||||
doubleStrike(): Run {
|
||||
public doubleStrike(): Run {
|
||||
this.properties.push(new DoubleStrike());
|
||||
return this;
|
||||
}
|
||||
|
||||
subScript(): Run {
|
||||
public subScript(): Run {
|
||||
this.properties.push(new SubScript());
|
||||
return this;
|
||||
}
|
||||
|
||||
superScript(): Run {
|
||||
public superScript(): Run {
|
||||
this.properties.push(new SuperScript());
|
||||
return this;
|
||||
}
|
||||
|
||||
public font(fontName: string): Run {
|
||||
this.properties.push(new RunFonts(fontName));
|
||||
return this;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ export class RunProperties extends XmlComponent {
|
||||
super("w:rPr");
|
||||
}
|
||||
|
||||
push(item: XmlComponent): void {
|
||||
public push(item: XmlComponent): void {
|
||||
this.root.push(item);
|
||||
}
|
||||
}
|
||||
|
30
ts/docx/run/run-fonts.ts
Normal file
30
ts/docx/run/run-fonts.ts
Normal 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,
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
abstract class VerticalAlign extends XmlComponent {
|
||||
|
||||
constructor(type: string) {
|
||||
super("w:vertAlign");
|
||||
this.root.push(new Attributes({
|
||||
val: type
|
||||
val: type,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Text} from "./text";
|
||||
import { Run } from "../run";
|
||||
import { Text } from "./text";
|
||||
|
||||
export class TextRun extends Run {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {XmlUnitComponent} from "../xml-components"
|
||||
import { XmlUnitComponent } from "../xml-components";
|
||||
|
||||
export class Text extends XmlUnitComponent {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { Attributes, XmlComponent } from "../xml-components";
|
||||
|
||||
abstract class BaseUnderline extends XmlComponent {
|
||||
|
||||
@ -6,7 +6,7 @@ abstract class BaseUnderline extends XmlComponent {
|
||||
super("w:u");
|
||||
this.root.push(new Attributes({
|
||||
val: underlineType,
|
||||
color: color
|
||||
color: color,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -88,7 +88,6 @@ export class DoubleUnderline extends BaseUnderline {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class SingleUnderline extends BaseUnderline {
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { XmlAttributeComponent } from "./default-attributes";
|
||||
|
||||
interface AttributesProperties {
|
||||
val?: any;
|
||||
interface IAttributesProperties {
|
||||
val?: string | number | boolean;
|
||||
color?: string;
|
||||
space?: string;
|
||||
sz?: string;
|
||||
@ -24,7 +24,7 @@ interface AttributesProperties {
|
||||
|
||||
export class Attributes extends XmlAttributeComponent {
|
||||
|
||||
constructor(properties?: AttributesProperties) {
|
||||
constructor(properties?: IAttributesProperties) {
|
||||
super({
|
||||
val: "w:val",
|
||||
color: "w:color",
|
||||
@ -44,7 +44,7 @@ export class Attributes extends XmlAttributeComponent {
|
||||
footer: "w:footer",
|
||||
gutter: "w:gutter",
|
||||
linePitch: "w:linePitch",
|
||||
pos: "w:pos"
|
||||
pos: "w:pos",
|
||||
}, properties);
|
||||
}
|
||||
}
|
@ -5,7 +5,9 @@ export abstract class BaseXmlComponent {
|
||||
this.rootKey = rootKey;
|
||||
}
|
||||
|
||||
abstract replaceKey(): void;
|
||||
clearVariables(): void {
|
||||
};
|
||||
public abstract replaceKey(): void;
|
||||
|
||||
public clearVariables(): void {
|
||||
// Do Nothing
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import {BaseXmlComponent} from "./base";
|
||||
import * as _ from "lodash";
|
||||
import { BaseXmlComponent } from "./base";
|
||||
|
||||
export abstract class XmlAttributeComponent extends BaseXmlComponent {
|
||||
protected root: Object;
|
||||
@ -16,10 +16,10 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
replaceKey(): void {
|
||||
public replaceKey(): void {
|
||||
if (this.root !== undefined) {
|
||||
_.forOwn(this.root, (value, key) => {
|
||||
let newKey = this.xmlKeys[key];
|
||||
const newKey = this.xmlKeys[key];
|
||||
this.root[newKey] = value;
|
||||
delete this.root[key];
|
||||
});
|
||||
|
@ -2,18 +2,18 @@ import * as _ from "lodash";
|
||||
import { BaseXmlComponent } from "./base";
|
||||
|
||||
export abstract class XmlComponent extends BaseXmlComponent {
|
||||
protected root: Array<BaseXmlComponent>;
|
||||
protected root: BaseXmlComponent[];
|
||||
|
||||
constructor(rootKey: string) {
|
||||
super(rootKey);
|
||||
this.root = new Array<BaseXmlComponent>();
|
||||
}
|
||||
|
||||
replaceKey(): void {
|
||||
public replaceKey(): void {
|
||||
// console.log(this.rootKey);
|
||||
// console.log(this.root);
|
||||
if (this.root !== undefined) {
|
||||
this.root.forEach(root => {
|
||||
this.root.forEach((root) => {
|
||||
if (root && root instanceof BaseXmlComponent) {
|
||||
root.replaceKey();
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
import {XmlComponent} from "./";
|
||||
import { ParagraphProperties } from "../paragraph/properties";
|
||||
import { RunProperties } from "../run/properties";
|
||||
import { XmlComponent } from "./";
|
||||
|
||||
export class ParagraphPropertyXmlComponent extends XmlComponent {
|
||||
private paragraphProperties: ParagraphProperties;
|
||||
|
||||
constructor(rootKey) {
|
||||
constructor(rootKey: string) {
|
||||
super(rootKey);
|
||||
this.paragraphProperties = new ParagraphProperties();
|
||||
this.root.push(this.paragraphProperties);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
public clearVariables(): void {
|
||||
this.paragraphProperties.clearVariables();
|
||||
|
||||
delete this.paragraphProperties;
|
||||
@ -21,13 +21,13 @@ export class ParagraphPropertyXmlComponent extends XmlComponent {
|
||||
export class RunPropertyXmlComponent extends XmlComponent {
|
||||
private runProperties: RunProperties;
|
||||
|
||||
constructor(rootKey) {
|
||||
constructor(rootKey: string) {
|
||||
super(rootKey);
|
||||
this.runProperties = new RunProperties();
|
||||
this.root.push(this.runProperties);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
public clearVariables(): void {
|
||||
this.runProperties.clearVariables();
|
||||
|
||||
delete this.runProperties;
|
||||
@ -38,7 +38,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
|
||||
private runProperties: RunProperties;
|
||||
private paragraphProperties: ParagraphProperties;
|
||||
|
||||
constructor(rootKey) {
|
||||
constructor(rootKey: string) {
|
||||
super(rootKey);
|
||||
this.runProperties = new RunProperties();
|
||||
this.root.push(this.runProperties);
|
||||
@ -47,7 +47,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
|
||||
this.root.push(this.paragraphProperties);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
public clearVariables(): void {
|
||||
this.runProperties.clearVariables();
|
||||
this.paragraphProperties.clearVariables();
|
||||
|
||||
|
@ -7,7 +7,7 @@ export abstract class XmlUnitComponent extends BaseXmlComponent {
|
||||
super(rootKey);
|
||||
}
|
||||
|
||||
replaceKey(): void {
|
||||
public replaceKey(): void {
|
||||
if (this.root !== undefined) {
|
||||
this[this.rootKey] = this.root;
|
||||
delete this.root;
|
||||
|
@ -3,10 +3,10 @@ import {XmlComponent} from "../docx/xml-components";
|
||||
|
||||
export class Formatter {
|
||||
|
||||
format(input: any): Object {
|
||||
public format(input: any): Object {
|
||||
input.clearVariables();
|
||||
this.replaceKeys(input);
|
||||
let newJson = this.clense(input);
|
||||
const newJson = this.clense(input);
|
||||
// console.log(JSON.stringify(newJson, null, " "));
|
||||
return newJson;
|
||||
}
|
||||
@ -18,7 +18,7 @@ export class Formatter {
|
||||
}
|
||||
|
||||
private clense(input: any): Object {
|
||||
let newJson = this.jsonify(input);
|
||||
const newJson = this.jsonify(input);
|
||||
|
||||
this.deepTraverseJson(newJson, (parent, value, key) => {
|
||||
if (key === "properties") {
|
||||
|
@ -1,9 +1,10 @@
|
||||
import {Packer} from "./packer";
|
||||
import * as fs from "fs";
|
||||
import * as express from "express";
|
||||
import * as fs from "fs";
|
||||
import { Document } from "../../docx/document";
|
||||
import {Properties} from "../../properties";
|
||||
import { Numbering } from "../../numbering";
|
||||
import { Properties } from "../../properties";
|
||||
import { Packer } from "./packer";
|
||||
|
||||
|
||||
export class ExpressPacker extends Packer {
|
||||
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");
|
||||
super.pack(this.res);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import {Packer} from "./packer";
|
||||
import * as fs from "fs";
|
||||
import { Document } from "../../docx/document";
|
||||
import {Properties} from "../../properties";
|
||||
import { Numbering } from "../../numbering";
|
||||
import { Properties } from "../../properties";
|
||||
import { Packer } from "./packer";
|
||||
|
||||
|
||||
export class LocalPacker extends Packer {
|
||||
private stream: fs.WriteStream;
|
||||
@ -11,7 +12,7 @@ export class LocalPacker extends Packer {
|
||||
super(document, styles, properties, numbering);
|
||||
}
|
||||
|
||||
pack(path: string): void {
|
||||
public pack(path: string): void {
|
||||
this.stream = fs.createWriteStream(path);
|
||||
super.pack(this.stream);
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
import * as archiver from "archiver";
|
||||
import * as fs from "fs";
|
||||
import * as xml from "xml";
|
||||
import {Formatter} from "../formatter";
|
||||
import { Document } from "../../docx";
|
||||
import {Styles} from "../../styles";
|
||||
import {Properties} from "../../properties";
|
||||
import { Numbering } from "../../numbering";
|
||||
import { Properties } from "../../properties";
|
||||
import { Styles } from "../../styles";
|
||||
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 {
|
||||
protected archive: any;
|
||||
private formatter: Formatter;
|
||||
protected document: Document;
|
||||
private formatter: Formatter;
|
||||
private style: Styles;
|
||||
private properties: Properties;
|
||||
private numbering: Numbering;
|
||||
@ -27,7 +27,7 @@ export abstract class Packer {
|
||||
this.archive = archiver.create("zip", {});
|
||||
|
||||
if (!style) {
|
||||
let stylesFactory = new DefaultStylesFactory();
|
||||
const stylesFactory = new DefaultStylesFactory();
|
||||
this.style = stylesFactory.newInstance();
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ export abstract class Packer {
|
||||
this.properties = new Properties({
|
||||
creator: "Un-named",
|
||||
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);
|
||||
console.log(appRoot.path + "/template");
|
||||
this.archive.glob("**", {
|
||||
@ -69,26 +69,26 @@ export abstract class Packer {
|
||||
name: "/root/g.txt",
|
||||
prefix: "root"
|
||||
});*/
|
||||
let xmlDocument = xml(this.formatter.format(this.document));
|
||||
let xmlStyles = xml(this.formatter.format(this.style));
|
||||
let xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
|
||||
let xmlNumbering = xml(this.formatter.format(this.numbering));
|
||||
const xmlDocument = xml(this.formatter.format(this.document));
|
||||
const xmlStyles = xml(this.formatter.format(this.style));
|
||||
const xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
|
||||
const xmlNumbering = xml(this.formatter.format(this.numbering));
|
||||
// console.log(JSON.stringify(this.numbering, null, " "));
|
||||
console.log(xmlNumbering);
|
||||
this.archive.append(xmlDocument, {
|
||||
name: "word/document.xml"
|
||||
name: "word/document.xml",
|
||||
});
|
||||
|
||||
this.archive.append(xmlStyles, {
|
||||
name: "word/styles.xml"
|
||||
name: "word/styles.xml",
|
||||
});
|
||||
|
||||
this.archive.append(xmlProperties, {
|
||||
name: "docProps/core.xml"
|
||||
name: "docProps/core.xml",
|
||||
});
|
||||
|
||||
this.archive.append(xmlNumbering, {
|
||||
name: "word/numbering.xml"
|
||||
name: "word/numbering.xml",
|
||||
});
|
||||
|
||||
this.archive.finalize();
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from "./docx";
|
||||
export * from "./export";
|
||||
export { Numbering } from "./numbering";
|
||||
|
@ -1,42 +1,50 @@
|
||||
import {XmlComponent} from "../docx/xml-components";
|
||||
import {XmlAttributeComponent} from "../docx/xml-components";
|
||||
import * as _ from "lodash";
|
||||
import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
||||
import { Level } from "./level";
|
||||
import { MultiLevelType } from "./multi-level-type";
|
||||
import * as _ from "lodash";
|
||||
|
||||
interface AbstractNumberingAttributesProperties {
|
||||
interface IAbstractNumberingAttributesProperties {
|
||||
abstractNumId?: number;
|
||||
restartNumberingAfterBreak?: number;
|
||||
}
|
||||
|
||||
class AbstractNumberingAttributes extends XmlAttributeComponent {
|
||||
|
||||
constructor(properties: AbstractNumberingAttributesProperties) {
|
||||
constructor(properties: IAbstractNumberingAttributesProperties) {
|
||||
super({
|
||||
abstractNumId: "w:abstractNumId",
|
||||
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak"
|
||||
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak",
|
||||
}, properties);
|
||||
}
|
||||
}
|
||||
|
||||
export class AbstractNumbering extends XmlComponent {
|
||||
public id: number;
|
||||
|
||||
constructor(id: number) {
|
||||
super("w:abstractNum");
|
||||
this.root.push(new AbstractNumberingAttributes({
|
||||
abstractNumId: id,
|
||||
restartNumberingAfterBreak: 0
|
||||
restartNumberingAfterBreak: 0,
|
||||
}));
|
||||
this.root.push(new MultiLevelType("hybridMultilevel"));
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
addLevel(level: Level): void {
|
||||
public addLevel(level: Level): void {
|
||||
this.root.push(level);
|
||||
}
|
||||
|
||||
clearVariables() {
|
||||
_.forEach(this.root, element => {
|
||||
public createLevel(num: number, format: string, text: string, align: string = "start"): Level {
|
||||
const level = new Level(num, format, text, align);
|
||||
this.addLevel(level);
|
||||
return level;
|
||||
}
|
||||
|
||||
public clearVariables(): void {
|
||||
_.forEach(this.root, (element) => {
|
||||
element.clearVariables();
|
||||
});
|
||||
delete this.id;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
|
||||
import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
||||
|
||||
interface IndentAttributesProperties {
|
||||
left: number;
|
||||
@ -10,7 +10,7 @@ class IndentAttributes extends XmlAttributeComponent {
|
||||
constructor(properties: IndentAttributesProperties) {
|
||||
super({
|
||||
left: "w:left",
|
||||
hanging: "w:hanging"
|
||||
hanging: "w:hanging",
|
||||
}, properties);
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ export class Indent extends XmlComponent {
|
||||
super("w:ind");
|
||||
this.root.push(new IndentAttributes({
|
||||
left: left,
|
||||
hanging: hanging
|
||||
hanging: hanging,
|
||||
}));
|
||||
}
|
||||
}
|
@ -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 { 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 {
|
||||
private nextId: number;
|
||||
|
||||
constructor() {
|
||||
super("w:numbering");
|
||||
@ -28,65 +29,69 @@ export class Numbering extends MultiPropertyXmlComponent {
|
||||
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
||||
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
|
||||
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");
|
||||
level0.addParagraphProperty(new Indent(720, 360));
|
||||
level0.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
abstractNumbering.addLevel(level0);
|
||||
const abstractNumbering = this.createAbstractNumbering();
|
||||
|
||||
let level1 = new Level(1, "bullet", "o", "left");
|
||||
level1.addParagraphProperty(new Indent(1440, 360));
|
||||
level1.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
abstractNumbering.addLevel(level1);
|
||||
abstractNumbering.createLevel(0, "bullet", "•", "left")
|
||||
.addParagraphProperty(new Indent(720, 360))
|
||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
|
||||
let level2 = new Level(2, "bullet", "•", "left");
|
||||
level2.addParagraphProperty(new Indent(2160, 360));
|
||||
level2.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||
abstractNumbering.addLevel(level2);
|
||||
abstractNumbering.createLevel(1, "bullet", "o", "left")
|
||||
.addParagraphProperty(new Indent(1440, 360))
|
||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
|
||||
let level3 = new Level(3, "bullet", "•", "left");
|
||||
level3.addParagraphProperty(new Indent(2880, 360));
|
||||
level3.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
abstractNumbering.addLevel(level3);
|
||||
abstractNumbering.createLevel(2, "bullet", "•", "left")
|
||||
.addParagraphProperty(new Indent(2160, 360))
|
||||
.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||
|
||||
let level4 = new Level(4, "bullet", "o", "left");
|
||||
level4.addParagraphProperty(new Indent(3600, 360));
|
||||
level4.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
abstractNumbering.addLevel(level4);
|
||||
abstractNumbering.createLevel(3, "bullet", "•", "left")
|
||||
.addParagraphProperty(new Indent(2880, 360))
|
||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
|
||||
let level5 = new Level(5, "bullet", "•", "left");
|
||||
level5.addParagraphProperty(new Indent(4320, 360));
|
||||
level5.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||
abstractNumbering.addLevel(level5);
|
||||
abstractNumbering.createLevel(4, "bullet", "o", "left")
|
||||
.addParagraphProperty(new Indent(3600, 360))
|
||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
|
||||
let level6 = new Level(6, "bullet", "•", "left");
|
||||
level6.addParagraphProperty(new Indent(5040, 360));
|
||||
level6.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
abstractNumbering.addLevel(level6);
|
||||
abstractNumbering.createLevel(5, "bullet", "•", "left")
|
||||
.addParagraphProperty(new Indent(4320, 360))
|
||||
.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||
|
||||
let level7 = new Level(4, "bullet", "o", "left");
|
||||
level7.addParagraphProperty(new Indent(5760, 360));
|
||||
level7.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
abstractNumbering.addLevel(level7);
|
||||
abstractNumbering.createLevel(6, "bullet", "•", "left")
|
||||
.addParagraphProperty(new Indent(5040, 360))
|
||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||
|
||||
let level8 = new Level(5, "bullet", "•", "left");
|
||||
level8.addParagraphProperty(new Indent(6480, 360));
|
||||
level8.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||
abstractNumbering.addLevel(level8);
|
||||
abstractNumbering.createLevel(7, "bullet", "o", "left")
|
||||
.addParagraphProperty(new Indent(5760, 360))
|
||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||
|
||||
this.root.push(abstractNumbering);
|
||||
this.root.push(new Num(1, 0));
|
||||
abstractNumbering.createLevel(8, "bullet", "•", "left")
|
||||
.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();
|
||||
_.forEach(this.root, element => {
|
||||
console.log(element);
|
||||
_.forEach(this.root, (element) => {
|
||||
element.clearVariables();
|
||||
});
|
||||
delete this.nextId;
|
||||
}
|
||||
}
|
@ -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 { RunProperties } from "../docx/run/properties";
|
||||
import { Attributes, MultiPropertyXmlComponent, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
||||
|
||||
interface LevelAttributesProperties {
|
||||
interface ILevelAttributesProperties {
|
||||
ilvl?: number;
|
||||
tentative?: number;
|
||||
}
|
||||
|
||||
class LevelAttributes extends XmlAttributeComponent {
|
||||
|
||||
constructor(properties: LevelAttributesProperties) {
|
||||
constructor(properties: ILevelAttributesProperties) {
|
||||
super({
|
||||
ilvl: "w:ilvl",
|
||||
tentative: "w15:tentative"
|
||||
tentative: "w15:tentative",
|
||||
}, properties);
|
||||
}
|
||||
}
|
||||
@ -23,7 +22,7 @@ class Start extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:start");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -33,7 +32,7 @@ class NumberFormat extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:numFmt");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -43,7 +42,7 @@ class LevelText extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:lvlText");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -53,7 +52,7 @@ class LevelJc extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:lvlJc");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -66,7 +65,7 @@ export class Level extends XmlComponent {
|
||||
super("w:lvl");
|
||||
this.root.push(new LevelAttributes({
|
||||
ilvl: level,
|
||||
tentative: 1
|
||||
tentative: 1,
|
||||
}));
|
||||
|
||||
this.root.push(new Start(1));
|
||||
@ -81,7 +80,7 @@ export class Level extends XmlComponent {
|
||||
this.root.push(this.runProperties);
|
||||
}
|
||||
|
||||
clearVariables(): void {
|
||||
public clearVariables(): void {
|
||||
this.paragraphProperties.clearVariables();
|
||||
this.runProperties.clearVariables();
|
||||
|
||||
@ -89,11 +88,13 @@ export class Level extends XmlComponent {
|
||||
delete this.runProperties;
|
||||
}
|
||||
|
||||
addParagraphProperty(property: XmlComponent): void {
|
||||
public addParagraphProperty(property: XmlComponent): Level {
|
||||
this.paragraphProperties.push(property);
|
||||
return this;
|
||||
}
|
||||
|
||||
addRunProperty(property: XmlComponent): void {
|
||||
public addRunProperty(property: XmlComponent): Level {
|
||||
this.runProperties.push(property);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import {XmlComponent, Attributes} from "../docx/xml-components";
|
||||
import { Attributes, XmlComponent } from "../docx/xml-components";
|
||||
|
||||
export class MultiLevelType extends XmlComponent {
|
||||
|
||||
constructor(value: string) {
|
||||
super("w:multiLevelType");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,35 +1,42 @@
|
||||
import {XmlComponent, Attributes, XmlAttributeComponent} from "../docx/xml-components";
|
||||
import { Attributes, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
||||
|
||||
class AbstractNumId extends XmlComponent {
|
||||
|
||||
constructor(value: number) {
|
||||
super("w:abstractNumId");
|
||||
this.root.push(new Attributes({
|
||||
val: value
|
||||
val: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
interface NumAttributesProperties {
|
||||
interface INumAttributesProperties {
|
||||
numId: number;
|
||||
}
|
||||
|
||||
class NumAttributes extends XmlAttributeComponent {
|
||||
|
||||
constructor(properties: NumAttributesProperties) {
|
||||
constructor(properties: INumAttributesProperties) {
|
||||
super({
|
||||
numId: "w:numId"
|
||||
numId: "w:numId",
|
||||
}, properties);
|
||||
}
|
||||
}
|
||||
|
||||
export class Num extends XmlComponent {
|
||||
public id: number;
|
||||
|
||||
constructor(numId: number, abstractNumId: number) {
|
||||
super("w:num");
|
||||
this.root.push(new NumAttributes({
|
||||
numId: numId
|
||||
numId: numId,
|
||||
}));
|
||||
this.root.push(new AbstractNumId(abstractNumId));
|
||||
this.id = numId;
|
||||
}
|
||||
|
||||
public clearVariables(): void {
|
||||
super.clearVariables();
|
||||
delete this.id;
|
||||
}
|
||||
}
|
@ -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
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { DocumentAttributes } from "../docx/document/document-attributes";
|
||||
import { XmlUnitComponent } from "../docx/xml-components";
|
||||
import { XmlComponent } from "../docx/xml-components";
|
||||
import {DocumentAttributes} from "../docx/document/document-attributes";
|
||||
|
||||
export class Title extends XmlUnitComponent {
|
||||
|
||||
@ -54,20 +54,20 @@ export class Revision extends XmlUnitComponent {
|
||||
|
||||
constructor(value: string) {
|
||||
super("cp:revision");
|
||||
let revision = value;
|
||||
const revision = value;
|
||||
this.root = value;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DateComponent extends XmlComponent {
|
||||
protected getCurrentDate(): any {
|
||||
let date = new Date(),
|
||||
year = date.getFullYear(),
|
||||
month = ("0" + (date.getMonth() + 1)).slice(-2),
|
||||
day = ("0" + date.getDate()).slice(-2),
|
||||
hours = ("0" + date.getHours()).slice(-2),
|
||||
minutes = ("0" + date.getMinutes()).slice(-2),
|
||||
seconds = ("0" + date.getSeconds()).slice(-2);
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = ("0" + (date.getMonth() + 1)).slice(-2);
|
||||
const day = ("0" + date.getDate()).slice(-2);
|
||||
const hours = ("0" + date.getHours()).slice(-2);
|
||||
const minutes = ("0" + date.getMinutes()).slice(-2);
|
||||
const seconds = ("0" + date.getSeconds()).slice(-2);
|
||||
|
||||
return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
|
||||
}
|
||||
@ -78,7 +78,7 @@ export class Created extends DateComponent {
|
||||
constructor() {
|
||||
super("dcterms:created");
|
||||
this.root.push(new DocumentAttributes({
|
||||
type: "dcterms:W3CDTF"
|
||||
type: "dcterms:W3CDTF",
|
||||
}));
|
||||
this.root.push(this.getCurrentDate());
|
||||
}
|
||||
@ -89,7 +89,7 @@ export class Modified extends DateComponent {
|
||||
constructor() {
|
||||
super("dcterms:modified");
|
||||
this.root.push(new DocumentAttributes({
|
||||
type: "dcterms:W3CDTF"
|
||||
type: "dcterms:W3CDTF",
|
||||
}));
|
||||
this.root.push(this.getCurrentDate());
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import {XmlComponent} from "../docx/xml-components";
|
||||
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;
|
||||
subject?: string;
|
||||
creator?: string;
|
||||
@ -14,14 +14,14 @@ interface PropertiesOptions {
|
||||
|
||||
export class Properties extends XmlComponent {
|
||||
|
||||
constructor(options: PropertiesOptions) {
|
||||
constructor(options: IPropertiesOptions) {
|
||||
super("cp:coreProperties");
|
||||
this.root.push(new DocumentAttributes({
|
||||
cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
||||
dc: "http://purl.org/dc/elements/1.1/",
|
||||
dcterms: "http://purl.org/dc/terms/",
|
||||
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 Subject(options.subject));
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* tslint:disable */
|
||||
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
|
||||
'use strict';
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
|
||||
import { assert } from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
|
@ -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 { assert } from "chai";
|
||||
import { SectionProperties } from "../../../docx/document/body/section-properties";
|
||||
|
@ -1,6 +1,3 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
import * as docx from "../../../docx";
|
||||
import { assert } from "chai";
|
||||
|
||||
|
@ -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 { assert } from "chai";
|
||||
|
||||
|
@ -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 { assert } from "chai";
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
/// <reference path="../../../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../../../typings/chai/chai.d.ts" />
|
||||
|
||||
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) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
@ -116,4 +115,44 @@ describe("Paragraph", () => {
|
||||
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}}]}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
@ -10,7 +10,7 @@ describe("NumberProperties", () => {
|
||||
let numberProperties: NumberProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
numberProperties = new NumberProperties();
|
||||
numberProperties = new NumberProperties(5, 10);
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
@ -22,11 +22,13 @@ describe("NumberProperties", () => {
|
||||
it("should create a Page Break with a Indent Level inside", () => {
|
||||
let newJson = jsonify(numberProperties);
|
||||
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", () => {
|
||||
let newJson = jsonify(numberProperties);
|
||||
assert.equal(newJson.root[1].rootKey, "w:numId");
|
||||
assert.equal(newJson.root[1].root[0].root.val, 5);
|
||||
});
|
||||
});
|
||||
});
|
22
ts/tests/docx/run/fontTests.ts
Normal file
22
ts/tests/docx/run/fontTests.ts
Normal 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"}}],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,10 +1,10 @@
|
||||
import { assert, expect } from "chai";
|
||||
import { Run } from "../../../docx/run";
|
||||
import { TextRun } from "../../../docx/run/text-run";
|
||||
import {assert} from "chai";
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
function jsonify(obj: object) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
describe("Run", () => {
|
||||
@ -17,7 +17,7 @@ describe("Run", () => {
|
||||
describe("#bold()", () => {
|
||||
it("it should add bold to the properties", () => {
|
||||
run.bold();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
|
||||
});
|
||||
});
|
||||
@ -25,7 +25,7 @@ describe("Run", () => {
|
||||
describe("#italic()", () => {
|
||||
it("it should add italics to the properties", () => {
|
||||
run.italic();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
|
||||
});
|
||||
});
|
||||
@ -33,7 +33,7 @@ describe("Run", () => {
|
||||
describe("#underline()", () => {
|
||||
it("it should add underline to the properties", () => {
|
||||
run.underline();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
|
||||
});
|
||||
});
|
||||
@ -41,7 +41,7 @@ describe("Run", () => {
|
||||
describe("#smallCaps()", () => {
|
||||
it("it should add smallCaps to the properties", () => {
|
||||
run.smallCaps();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
|
||||
});
|
||||
});
|
||||
@ -49,7 +49,7 @@ describe("Run", () => {
|
||||
describe("#caps()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.allCaps();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
|
||||
});
|
||||
});
|
||||
@ -57,7 +57,7 @@ describe("Run", () => {
|
||||
describe("#strike()", () => {
|
||||
it("it should add strike to the properties", () => {
|
||||
run.strike();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
|
||||
});
|
||||
});
|
||||
@ -65,26 +65,40 @@ describe("Run", () => {
|
||||
describe("#doubleStrike()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.doubleStrike();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#break()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
let run = new Run();
|
||||
run.break();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
assert.equal(newJson.root[1].rootKey, "w:br");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#tab()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
let run = new Run();
|
||||
run.tab();
|
||||
let newJson = jsonify(run);
|
||||
const newJson = jsonify(run);
|
||||
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"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -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 * as docx from "../../docx";
|
||||
import { Attributes } from "../../docx/xml-components";
|
||||
|
@ -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 { LocalPacker } from "../../export/packer/local";
|
||||
import {assert} from "chai";
|
||||
import { Document } from "../../docx/document";
|
||||
import { Properties } from "../../properties";
|
||||
import { DefaultStyle } from "../../styles/sample";
|
||||
import { Paragraph } from "../../docx/paragraph";
|
||||
import { DefaultStylesFactory } from "../../styles/factory";
|
||||
import { assert } from "chai";
|
||||
|
||||
describe("Packer", () => {
|
||||
let packer: LocalPacker;
|
||||
|
@ -1,24 +1,109 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
|
||||
import {assert} from "chai";
|
||||
import { expect } from "chai";
|
||||
import { Formatter } from "../export/formatter";
|
||||
import { Numbering } from "../numbering";
|
||||
import { AbstractNumbering } from "../numbering/abstract-numbering";
|
||||
import { Num } from "../numbering/num";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
let stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
function jsonify(obj: object) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
describe("", () => {
|
||||
describe("Numbering", () => {
|
||||
|
||||
let numbering = new Numbering;
|
||||
let numbering: Numbering;
|
||||
beforeEach(() => {
|
||||
numbering = new Numbering();
|
||||
});
|
||||
|
||||
describe("#methodName()", () => {
|
||||
it("should ", () => {
|
||||
describe("#constructor", () => {
|
||||
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)"}}]})
|
||||
});
|
||||
});
|
||||
});
|
@ -1,5 +1,3 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
import { Properties } from "../properties";
|
||||
import { assert } from "chai";
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
|
||||
import { Styles } from "../styles";
|
||||
import { assert } from "chai";
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
"sourceMap": true,
|
||||
"removeComments": true,
|
||||
"preserveConstEnums": true,
|
||||
//"outFile": "../build/build.js",
|
||||
"outDir": "../build",
|
||||
"sourceRoot": "./",
|
||||
"rootDir": "./",
|
||||
|
39
ts/tsd.json
39
ts/tsd.json
@ -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
35
ts/tslint.json
Normal 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
|
||||
]
|
||||
}
|
||||
}
|
42
ts/typings/archiver/archiver.d.ts
vendored
42
ts/typings/archiver/archiver.d.ts
vendored
@ -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;
|
||||
}
|
15
ts/typings/assertion-error/assertion-error.d.ts
vendored
15
ts/typings/assertion-error/assertion-error.d.ts
vendored
@ -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;
|
||||
}
|
401
ts/typings/chai/chai.d.ts
vendored
401
ts/typings/chai/chai.d.ts
vendored
@ -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
54
ts/typings/express/express.d.ts
vendored
54
ts/typings/express/express.d.ts
vendored
@ -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;
|
||||
}
|
19172
ts/typings/lodash/lodash.d.ts
vendored
19172
ts/typings/lodash/lodash.d.ts
vendored
File diff suppressed because it is too large
Load Diff
20
ts/typings/mime/mime.d.ts
vendored
20
ts/typings/mime/mime.d.ts
vendored
@ -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;
|
||||
}
|
236
ts/typings/mocha/mocha.d.ts
vendored
236
ts/typings/mocha/mocha.d.ts
vendored
@ -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;
|
||||
}
|
2329
ts/typings/node/node.d.ts
vendored
2329
ts/typings/node/node.d.ts
vendored
File diff suppressed because it is too large
Load Diff
86
ts/typings/serve-static/serve-static.d.ts
vendored
86
ts/typings/serve-static/serve-static.d.ts
vendored
@ -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
12
ts/typings/tsd.d.ts
vendored
@ -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" />
|
8
ts/typings/xml/xml.d.ts
vendored
8
ts/typings/xml/xml.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
declare module "xml" {
|
||||
function xml(xmlObject: any, options?: any): string;
|
||||
|
||||
namespace xml {
|
||||
|
||||
}
|
||||
export = xml;
|
||||
}
|
Reference in New Issue
Block a user