Skip to content

Commit

Permalink
chore: improve project setup (#58)
Browse files Browse the repository at this point in the history
* update dependencies and remove obsolete npm scripts
* place test code next to production code
* mention contributors in package.json
  • Loading branch information
connium authored Feb 9, 2019
1 parent 996b4fa commit e72019c
Show file tree
Hide file tree
Showing 19 changed files with 1,868 additions and 3,465 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## [Unreleased] (2018-??-??)
## [Unreleased] (2019-??-??)
### Added
- **docs:** Add automatically created API documentation, closes [#16](https://github.com/connium/simple-odf/issues/16)

### Changed
- **meta:** Use `Date` instead of `number` when dealing with dates
- **chore:** Update dev dependencies, place test code next to production code, mention contributors in package.json

## [0.6.0] (2018-10-12)
### Added
Expand Down
5,003 changes: 1,689 additions & 3,314 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 34 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@
"name": "simple-odf",
"version": "0.6.0",
"description": "Open Document Format made easy using pure JavaScript and Node.js",
"keywords": [
"open",
"document",
"format",
"odf",
"odt",
"office"
],
"homepage": "https://github.com/connium/simple-odf#readme",
"bugs": {
"url": "https://github.com/connium/simple-odf/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/connium/simple-odf.git"
},
"license": "MIT",
"contributors": [
"Christoph Nölke",
"Thomas Parisot",
"Koen Verheyen"
],

"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
Expand All @@ -12,53 +35,34 @@
"test": "jest",
"watch-test": "jest --watch",
"coverage": "jest --coverage",
"jest": "jest",
"lint": "tslint -c tslint.json 'src/**/*.ts', 'test/**/*.ts'",
"tsc": "tsc",
"docs": "rm -r ./lib && tsc && jsdoc2md --name-format --param-list-format list --separators --partial ./jsdoc2md/body.hbs ./jsdoc2md/params-list.hbs ./jsdoc2md/returns.hbs ./jsdoc2md/scope.hbs --files ./lib/**/*.js ./lib/*.js > ./docs/API.md"
},
"repository": {
"type": "git",
"url": "git+https://github.com/connium/simple-odf.git"
},
"keywords": [
"open",
"document",
"format",
"odf",
"odt",
"office"
],
"author": "Christoph Nölke",
"license": "MIT",
"bugs": {
"url": "https://github.com/connium/simple-odf/issues"
},
"homepage": "https://github.com/connium/simple-odf#readme",
"engines": {
"node": "^8.9.4"
},
"dependencies": {
"xmldom": "^0.1.27"
},
"devDependencies": {
"@types/jest": "^22.2.3",
"@types/jest": "^24.0.0",
"@types/node": "^8.10.35",
"@types/xmldom": "^0.1.29",
"jest": "^22.4.4",
"jest": "^24.1.0",
"jsdoc-to-markdown": "^4.0.1",
"ts-jest": "^22.4.6",
"tslint": "^5.11.0",
"typescript": "^2.9.2"
"ts-jest": "^23.10.5",
"ts-lint": "^4.5.1",
"typescript": "^3.3.3"
},
"engines": {
"node": "^8.9.4"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "test/.*.*\\.spec\\.ts$",
"testRegex": "src/.*\\.spec\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"js"
]
],
"collectCoverage": true
}
}
12 changes: 6 additions & 6 deletions test/TextDocument.spec.ts → src/TextDocument.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readFile, unlink } from "fs";
import { promisify } from "util";
import { Meta } from "../src/meta/Meta";
import { FontPitch } from "../src/style/FontPitch";
import { Heading } from "../src/text/Heading";
import { List } from "../src/text/List";
import { Paragraph } from "../src/text/Paragraph";
import { TextDocument, XML_DECLARATION } from "../src/TextDocument";
import { Meta } from "./meta/Meta";
import { FontPitch } from "./style/FontPitch";
import { Heading } from "./text/Heading";
import { List } from "./text/List";
import { Paragraph } from "./text/Paragraph";
import { TextDocument, XML_DECLARATION } from "./TextDocument";

const FILEPATH = "./test.fodt";

Expand Down
14 changes: 6 additions & 8 deletions test/draw/Image.spec.ts → src/draw/Image.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { join } from "path";
import { Image } from "../../src/draw/Image";
import { AnchorType } from "../../src/style/AnchorType";
import { ImageStyle } from "../../src/style/ImageStyle";
import { TextDocument } from "../../src/TextDocument";
import { Image } from "./Image";
import { AnchorType } from "../style/AnchorType";
import { ImageStyle } from "../style/ImageStyle";
import { TextDocument } from "../TextDocument";

describe(Image.name, () => {
let document: TextDocument;
Expand All @@ -13,7 +13,7 @@ describe(Image.name, () => {

describe("#setStyle", () => {
it("set text anchor attribute on frame", () => {
document.addParagraph().addImage(join(__dirname, "..", "data", "ODF.png"));
document.addParagraph().addImage(join(__dirname, "..", "..", "test", "data", "ODF.png"));

expect(document.toString()).toMatch(/<draw:frame text:anchor-type="paragraph">/);
});
Expand Down Expand Up @@ -41,10 +41,8 @@ describe(Image.name, () => {
});

describe("#toXml", () => {
let image: Image;

beforeEach(() => {
image = document.addParagraph().addImage(join(__dirname, "..", "data", "ODF.png"));
document.addParagraph().addImage(join(__dirname, "..", "..", "test", "data", "ODF.png"));
});

it("append a draw frame with image and base64 encoded image", () => {
Expand Down
25 changes: 12 additions & 13 deletions test/meta/Meta.spec.ts → src/meta/Meta.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { userInfo } from "os";
import { Meta } from "../../src/meta/Meta";
import { TextDocument } from "../../src/TextDocument";
import { Meta } from "./Meta";
import { TextDocument } from "../TextDocument";

describe(Meta.name, () => {
const timeOffset = 100;
const currentUserName = userInfo().username;

let meta: Meta;

Expand Down Expand Up @@ -40,7 +39,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setCreator(testCreator);
meta.setCreator(null);
meta.setCreator(<any>null);

expect(meta.getCreator()).toBe(testCreator);
});
Expand Down Expand Up @@ -68,7 +67,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setDate(testDate);
meta.setDate(null);
meta.setDate(<any>null);

expect(meta.getDate()).toBe(testDate);
});
Expand Down Expand Up @@ -103,7 +102,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setDescription(testDescription);
meta.setDescription(null);
meta.setDescription(<any>null);

expect(meta.getDescription()).toBe(testDescription);
});
Expand Down Expand Up @@ -143,7 +142,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setInitialCreator(testCreator);
meta.setInitialCreator(null);
meta.setInitialCreator(<any>null);

expect(meta.getInitialCreator()).toBe(testCreator);
});
Expand Down Expand Up @@ -174,11 +173,11 @@ describe(Meta.name, () => {
});

it("ignore invalid input", () => {
meta.addKeyword(undefined);
meta.addKeyword(<any>undefined);

expect(meta.getKeywords()).toEqual([]);

meta.addKeyword(null);
meta.addKeyword(<any>null);

expect(meta.getKeywords()).toEqual([]);
});
Expand Down Expand Up @@ -262,7 +261,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setPrintDate(testDate);
meta.setPrintDate(null);
meta.setPrintDate(<any>null);

expect(meta.getPrintDate()).toBe(testDate);
});
Expand Down Expand Up @@ -297,7 +296,7 @@ describe(Meta.name, () => {

it("return undefined if empty printed by is set", () => {
meta.setPrintedBy(testUsername);
meta.setPrintedBy(null);
meta.setPrintedBy(<any>null);

expect(meta.getPrintedBy()).toBe(testUsername);
});
Expand Down Expand Up @@ -325,7 +324,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setSubject(testSubject);
meta.setSubject(null);
meta.setSubject(<any>null);

expect(meta.getSubject()).toBe(testSubject);
});
Expand Down Expand Up @@ -353,7 +352,7 @@ describe(Meta.name, () => {

it("ignore invalid input", () => {
meta.setTitle(testTitle);
meta.setTitle(null);
meta.setTitle(<any>null);

expect(meta.getTitle()).toBe(testTitle);
});
Expand Down
40 changes: 11 additions & 29 deletions test/style/Color.spec.ts → src/style/Color.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color } from "../../src/style/Color";
import { Color } from "./Color";

describe(Color.name, () => {
const expectedHex = "336699";
Expand All @@ -16,22 +16,16 @@ describe(Color.name, () => {
expect(color.toHex()).toEqual("#" + expectedHex);
});

it("return undefined if string is too long", () => {
const color = Color.fromHex("123456789");

expect(color).toBeUndefined();
it("throw if string is too long", () => {
expect(() => Color.fromHex("123456789")).toThrow("color value");
});

it("return undefined if string is too short", () => {
const color = Color.fromHex("1234");

expect(color).toBeUndefined();
expect(() => Color.fromHex("1234")).toThrowError("color value");
});

it("return undefined if string contains non-hex characters", () => {
const color = Color.fromHex("23fx42");

expect(color).toBeUndefined();
expect(() => Color.fromHex("23fx42")).toThrowError("color value");
});
});

Expand All @@ -44,33 +38,21 @@ describe(Color.name, () => {
});

it("return undefined if red is out of range", () => {
let color = Color.fromRgb(-1, 0x66, 0x99);

expect(color).toBeUndefined();

color = Color.fromRgb(256, 0x66, 0x99);
expect(() => Color.fromRgb(-1, 0x66, 0x99)).toThrowError("color channel");

expect(color).toBeUndefined();
expect(() => Color.fromRgb(256, 0x66, 0x99)).toThrowError("color channel");
});

it("return undefined if green is out of range", () => {
let color = Color.fromRgb(0x33, -1, 0x99);
expect(() => Color.fromRgb(0x33, -1, 0x99)).toThrowError("color channel");

expect(color).toBeUndefined();

color = Color.fromRgb(0x33, 256, 0x99);

expect(color).toBeUndefined();
expect(() => Color.fromRgb(0x33, 256, 0x99)).toThrowError("color channel");
});

it("return undefined if blue is out of range", () => {
let color = Color.fromRgb(0x33, 0x66, -1);

expect(color).toBeUndefined();

color = Color.fromRgb(0x33, 0x66, 256);
expect(() => Color.fromRgb(0x33, 0x66, -1)).toThrowError("color channel");

expect(color).toBeUndefined();
expect(() => Color.fromRgb(0x33, 0x66, 256)).toThrowError("color channel");
});
});

Expand Down
16 changes: 8 additions & 8 deletions src/style/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export class Color {
* The string is expected to be in `#rrggbb` or `rrggbb` format.
*
* @param {string} value The value you want to parse
* @returns {Color | undefined} A color parsed from the given value.
* If the value cannot be converted to a color, `undefined` is returned.
* @returns {Color | never} A color parsed from the given value
* @throws {Error} If the value cannot be converted to a color
* @since 0.4.0
*/
public static fromHex(value: string): Color | undefined {
public static fromHex(value: string): Color | never {
const matches = value.match(/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/);
if (matches === null) {
return undefined;
throw new Error('Invalid color value');
}

return new Color(parseInt(matches[1], 16), parseInt(matches[2], 16), parseInt(matches[3], 16));
Expand All @@ -28,15 +28,15 @@ export class Color {
* @param {number} red The red channel of the color with a range of 0...255
* @param {number} green The green channel of the color with a range of 0...255
* @param {number} blue The blue channel of the color with a range of 0...255
* @returns {Color | undefined} A color parsed from the given value.
* If any channel is outside the allowable range, `undefined` is returned.
* @returns {Color | never} A color parsed from the given value
* @throws {Error} If any channel is outside the allowable range
* @since 0.4.0
*/
public static fromRgb(red: number, green: number, blue: number): Color | undefined {
public static fromRgb(red: number, green: number, blue: number): Color | never {
if (Color.checkRange(red) && Color.checkRange(green) && Color.checkRange(blue)) {
return new Color(red, green, blue);
}
return undefined;
throw new Error('Invalid value for a color channel');
}

/**
Expand Down
11 changes: 5 additions & 6 deletions test/style/ImageStyle.spec.ts → src/style/ImageStyle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { join } from "path";
import { Image } from "../../src/draw/Image";
import { AnchorType } from "../../src/style/AnchorType";
import { ImageStyle } from "../../src/style/ImageStyle";
import { Paragraph } from "../../src/text/Paragraph";
import { TextDocument } from "../../src/TextDocument";
import { Image } from "../draw/Image";
import { AnchorType } from "./AnchorType";
import { ImageStyle } from "./ImageStyle";
import { TextDocument } from "../TextDocument";

describe(ImageStyle.name, () => {
let document: TextDocument;
Expand Down Expand Up @@ -79,7 +78,7 @@ describe(ImageStyle.name, () => {
let image: Image;

beforeEach(() => {
image = document.addParagraph().addImage(join(__dirname, "..", "data", "ODF.png"));
image = document.addParagraph().addImage(join(__dirname, "..", "..", "test", "data", "ODF.png"));
});

it("set the anchor type", () => {
Expand Down
Loading

0 comments on commit e72019c

Please sign in to comment.