Skip to content

Commit

Permalink
eslint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chunyenHuang committed Jan 10, 2020
1 parent 1e91dcf commit 84ea99c
Show file tree
Hide file tree
Showing 30 changed files with 1,809 additions and 1,684 deletions.
8 changes: 4 additions & 4 deletions lib/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Recipe {
this.options = Object.assign({}, options, this.encryptOptions);
this.current = {};
this.current.defaultFontSize = 14;

if (this.isBufferSrc) {
this.outStream = new streams.WritableStream();
this.output = output;
Expand Down Expand Up @@ -282,7 +282,7 @@ class Recipe {
// Assume simply registering a function which will have an embedded name
if (typeof key !== 'string') {
if (!key.name) {
throw `Cannot register unnamed callback function. Provide 'name' as first argument, then callback function.`
throw 'Cannot register unnamed callback function. Provide \'name\' as first argument, then callback function.';
}
callback = key;
key = key.name;
Expand All @@ -291,9 +291,9 @@ class Recipe {
if (this.__proto__[key]){
throw `Found conflict in Recipe prototypes. ${key} already exists.`;
}

if (typeof callback !== 'function') {
throw `${key} expecting callback to be of type function.`
throw `${key} expecting callback to be of type function.`;
}

this.__proto__[key] = callback;
Expand Down
2 changes: 1 addition & 1 deletion lib/appendPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.appendPage = function appendPage(pdfSrc, pages = []) {
if (!Array.isArray(pages) && !isNaN(pages)) {
pages = [pages];
}
// Using stream so it can be closed to release reader resource (Issue #61)
// Using stream so it can be closed to release reader resource (Issue #61)
const instream = new hummus.PDFRStreamForFile(pdfSrc);
const pdfReader = hummus.createReader(instream);
const pageCount = pdfReader.getPagesCount();
Expand Down
2 changes: 1 addition & 1 deletion lib/coordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports._centrify = function _centrify(x, y, pageNumber) {
}

return [x,y];
}
};

exports._calibrateCoordinate = function _calibrateCoordinate(x, y, offsetX = 0, offsetY = 0, pageNumber) {
pageNumber = pageNumber || this.pageNumber;
Expand Down
54 changes: 27 additions & 27 deletions lib/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ exports._loadFonts = function _loadFonts(fontSrcPath) {
for (let fpath of fontPaths) {
if (fs.existsSync(fpath)) { // only process when directory exists
fs
.readdirSync(fpath)
.filter((file) => {
return fontTypes.includes(path.extname(file).toLowerCase());
})
.forEach((file) => {
let fontName = path.basename(file, path.extname(file)).toLowerCase();
// simple heuristics to make sure library fonts behave as expected
const hasBold = (fontName.indexOf('bold') !== -1);
const hasItalic = (fontName.indexOf('italic') !== -1);
let type = 'r';
if (hasBold&&hasItalic) {
fontName = fontName.replace(/-*bold/,'');
fontName = fontName.replace(/-*italic/,'');
type = 'bi';
} else if (hasBold) {
fontName = fontName.replace(/-*bold/,'');
type = 'b';
} else if (hasItalic) {
fontName = fontName.replace(/-*italic/,'');
type = 'i';
}
return this._registerFont(fontName, path.join(fpath, file), type);
});
.readdirSync(fpath)
.filter((file) => {
return fontTypes.includes(path.extname(file).toLowerCase());
})
.forEach((file) => {
let fontName = path.basename(file, path.extname(file)).toLowerCase();
// simple heuristics to make sure library fonts behave as expected
const hasBold = (fontName.indexOf('bold') !== -1);
const hasItalic = (fontName.indexOf('italic') !== -1);
let type = 'r';
if (hasBold&&hasItalic) {
fontName = fontName.replace(/-*bold/,'');
fontName = fontName.replace(/-*italic/,'');
type = 'bi';
} else if (hasBold) {
fontName = fontName.replace(/-*bold/,'');
type = 'b';
} else if (hasItalic) {
fontName = fontName.replace(/-*italic/,'');
type = 'i';
}
return this._registerFont(fontName, path.join(fpath, file), type);
});
}
}
};
Expand Down Expand Up @@ -78,9 +78,9 @@ function _getFontFile(self, options = {}) {
// Need to choose appropriate file based on bold/italic considerations
// Note, if this is not done explicitly, the font dimensions will be incorrect.
let type =
((options.bold || options.isBold) && (options.italic || options.isItalic)) ? 'bi' :
(options.italic || options.isItalic) ? 'i' :
(options.bold || options.isBold) ? 'b' : 'r';
((options.bold || options.isBold) && (options.italic || options.isItalic)) ? 'bi' :
(options.italic || options.isItalic) ? 'i' :
(options.bold || options.isBold) ? 'b' : 'r';

if (options.font) {
const fontFamily = self.fonts[options.font.toLowerCase()];
Expand Down Expand Up @@ -111,4 +111,4 @@ exports._getFont = function _getFont(options) {
}

return this.current[fontFile];
}
};
12 changes: 6 additions & 6 deletions lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.info = function info(options) {

if (! options) {
result = this._readInfo();

} else {
this.toWriteInfo_ = this.toWriteInfo_ || {};
Object.assign(this.toWriteInfo_, options);
Expand All @@ -34,11 +34,11 @@ exports._readInfo = function _readInfo() {
const infoDict = copyCtx.getSourceDocumentParser().queryDictionaryObject(
copyCtx.getSourceDocumentParser().getTrailer(), 'Info'
);

const oldInfo = (infoDict && infoDict.toJSObject) ? infoDict.toJSObject() : null;

if (oldInfo) {
this.infoDictionary = {}
this.infoDictionary = {};
Object.getOwnPropertyNames(oldInfo).forEach((key) => {
if (!oldInfo[key]) {
return;
Expand Down Expand Up @@ -83,7 +83,7 @@ exports._readInfo = function _readInfo() {
}

return this.infoDictionary;
}
};

exports._writeInfo = function _writeInfo() {
const options = this.toWriteInfo_ || {};
Expand All @@ -93,7 +93,7 @@ exports._writeInfo = function _writeInfo() {
This issue is due to the unhandled process exit from HummusJS.
I have to disable this part before it gets fixed in HummusJS.
*/

const infoDictionary = this.writer.getDocumentContext().getInfoDictionary();
const fields = [{
key: 'author',
Expand Down
6 changes: 3 additions & 3 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ exports.createPage = function createPage(pageWidth, pageHeight, margins) {

if (!pageWidth && !pageHeight) {
[pageWidth, pageHeight] = this.default.pageSize;

} else if (pageWidth && !isNaN(pageWidth) && pageHeight && !isNaN(pageHeight)) {
pageWidth = pageWidth || this.default.pageSize[0];
pageHeight = pageHeight || this.default.pageSize[1];

} else if (typeof pageWidth === 'string') {
const rotate = pageHeight;
const pageType = pageWidth.toLowerCase().replace('-size','');
Expand Down Expand Up @@ -257,4 +257,4 @@ exports.margins = function margins(left, right, top, bottom)
}

return this;
}
};
Loading

0 comments on commit 84ea99c

Please sign in to comment.