Skip to content

Commit

Permalink
refactor: apply JavaScript standard style (#64)
Browse files Browse the repository at this point in the history
Fixes: #61
  • Loading branch information
connium authored Feb 18, 2019
1 parent 60ac1bb commit a76d7d6
Show file tree
Hide file tree
Showing 68 changed files with 1,239 additions and 1,205 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- **meta:** Use `Date` instead of `number` when dealing with dates
- **style:** Always use millimeter as unit, except for font size
- **refactor:** Split API and serialization logic, closes [#60](https://github.com/connium/simple-odf/issues/60)
- **refactor:** Apply JavaScript Standard Style, closes [#61](https://github.com/connium/simple-odf/issues/61)
- **chore:** Update dev dependencies, place test code next to production code, mention contributors in package.json

## [0.6.0] (2018-10-12)
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Open Document Format made easy using pure JavaScript and Node.js

[![Build Status](https://travis-ci.com/connium/simple-odf.svg?branch=master)](https://travis-ci.com/connium/simple-odf)
[![Version](https://img.shields.io/npm/v/simple-odf.svg)](https://www.npmjs.com/package/simple-odf)
[![codecov](https://codecov.io/gh/connium/simple-odf/branch/master/graph/badge.svg)](https://codecov.io/gh/connium/simple-odf)
[![Dependencies](https://david-dm.org/connium/simple-odf.svg)](https://david-dm.org/connium/simple-odf)
[![Known Vulnerabilities](https://snyk.io/test/github/connium/simple-odf/badge.svg)](https://snyk.io/test/github/connium/simple-odf)
[![Version](https://img.shields.io/npm/v/simple-odf.svg)](https://www.npmjs.com/package/simple-odf)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Getting Started

Expand All @@ -19,20 +20,20 @@ npm install --save simple-odf
Create your first document.

```javascript
const simpleOdf = require("simple-odf");
const simpleOdf = require('simple-odf');

const document = new simpleOdf.TextDocument();
const body = document.getBody();

const image = body.addParagraph().addImage("/home/homer/myself.png");
const image = body.addParagraph().addImage('/home/homer/myself.png');
image.getStyle().setAnchorType(simpleOdf.AnchorType.AsChar);
image.getStyle().setSize(29.4, 36.5);

body.addHeading("Welcome to simple-odf");
body.addHeading('Welcome to simple-odf');

const p1 = body.addParagraph("The quick, brown fox jumps over a lazy dog.");
p1.addText("\nThe five boxing wizards jump quickly.\n\n");
p1.addHyperlink("Visit me", "http://example.org/");
const p1 = body.addParagraph('The quick, brown fox jumps over a lazy dog.');
p1.addText('\nThe five boxing wizards jump quickly.\n\n');
p1.addHyperlink('Visit me', 'http://example.org/');
const style1 = new simpleOdf.ParagraphStyle();
// text formatting
style1.setColor(simpleOdf.Color.fromRgb(255, 0, 0));
Expand All @@ -45,20 +46,20 @@ style1.setPageBreakBefore();
style1.setKeepTogether();
p1.setStyle(style1);
// font usage
document.declareFont("Open Sans", "Open Sans", simpleOdf.FontPitch.Variable);
const p2 = body.addParagraph("It always seems impossible until it's done.");
document.declareFont('Open Sans', 'Open Sans', simpleOdf.FontPitch.Variable);
const p2 = body.addParagraph('It always seems impossible until it\'s done.');
const style2 = new simpleOdf.ParagraphStyle();
style1.setFontName("Open Sans");
style1.setFontName('Open Sans');

body.addHeading("Credits", 2);
body.addHeading('Credits', 2);

body.addParagraph("This was quite easy. Do you want to know why?");
body.addParagraph('This was quite easy. Do you want to know why?');

const list = body.addList();
list.addItem("one-liner setup");
list.addItem("just write like you would do in a full-blown editor");
list.addItem('one-liner setup');
list.addItem('just write like you would do in a full-blown editor');

document.saveFlat("/home/homer/My_first_document.fodf");
document.saveFlat('/home/homer/My_first_document.fodf');
```

## Documentation
Expand Down
141 changes: 93 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@
"Thomas Parisot",
"Koen Verheyen"
],

"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"preversion": "npm test",
"postversion": "git push && git push --tags",
"prepublishOnly": "tsc",
"pretest": "npm run lint",
"posttest": "npm run lint",
"test": "jest",
"watch-test": "jest --watch",
"coverage": "jest --coverage",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"lint": "tslint --project tslint.json src/**/*.ts",
"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/api/**/*.js ./lib/style/**/*.js > ./docs/API.md"
},
"dependencies": {
Expand All @@ -48,7 +47,8 @@
"jest": "^24.1.0",
"jsdoc-to-markdown": "^4.0.1",
"ts-jest": "^23.10.5",
"ts-lint": "^4.5.1",
"tslint": "^5.12.1",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.3.3"
},
"engines": {
Expand Down
14 changes: 7 additions & 7 deletions src/api/OdfElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class OdfElement {
* Constructor.
* @since 0.1.0
*/
public constructor() {
public constructor () {
this.children = [];
}

Expand All @@ -20,7 +20,7 @@ export class OdfElement {
* @returns {OdfElement[]} A copy of the list of child elements
* @since 0.2.0
*/
public getAll(): OdfElement[] {
public getAll (): OdfElement[] {
return Array.from(this.children);
}

Expand All @@ -30,7 +30,7 @@ export class OdfElement {
* @param {OdfElement} element The element to append
* @since 0.1.0
*/
protected append(element: OdfElement): void {
protected append (element: OdfElement): void {
this.children.push(element);
}

Expand All @@ -43,7 +43,7 @@ export class OdfElement {
* @param {OdfElement} element The element to insert
* @since 0.2.0
*/
protected insert(position: number, element: OdfElement): void {
protected insert (position: number, element: OdfElement): void {
let index = position;

if (position < 0) {
Expand All @@ -63,7 +63,7 @@ export class OdfElement {
* or undefined if there is no element at the specified position
* @since 0.2.0
*/
protected get(position: number): OdfElement | undefined {
protected get (position: number): OdfElement | undefined {
if (position < 0) {
return undefined;
}
Expand All @@ -82,7 +82,7 @@ export class OdfElement {
* or undefined if there is no element at the specified position
* @since 0.2.0
*/
protected removeAt(position: number): OdfElement | undefined {
protected removeAt (position: number): OdfElement | undefined {
const oldElement = this.get(position);

if (oldElement !== undefined) {
Expand All @@ -98,7 +98,7 @@ export class OdfElement {
* @returns {boolean} TRUE if the there is any child element, FALSE otherwise
* @since 0.2.0
*/
protected hasChildren(): boolean {
protected hasChildren (): boolean {
return this.children.length > 0;
}
}
Loading

0 comments on commit a76d7d6

Please sign in to comment.