diff --git a/lib/mixins/annotations.js b/lib/mixins/annotations.js index 0f5ca45..783a178 100644 --- a/lib/mixins/annotations.js +++ b/lib/mixins/annotations.js @@ -26,10 +26,7 @@ export default { return this; }, - note(x, y, w, h, contents, options) { - if (options == null) { - options = {}; - } + note(x, y, w, h, contents, options = {}) { options.Subtype = 'Text'; options.Contents = new String(contents); options.Name = 'Comment'; @@ -39,10 +36,7 @@ export default { return this.annotate(x, y, w, h, options); }, - link(x, y, w, h, url, options) { - if (options == null) { - options = {}; - } + link(x, y, w, h, url, options = {}) { options.Subtype = 'Link'; if (typeof url === 'number') { @@ -69,20 +63,14 @@ export default { return this.annotate(x, y, w, h, options); }, - _markup(x, y, w, h, options) { - if (options == null) { - options = {}; - } + _markup(x, y, w, h, options = {}) { const [x1, y1, x2, y2] = this._convertRect(x, y, w, h); options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1]; options.Contents = new String(); return this.annotate(x, y, w, h, options); }, - highlight(x, y, w, h, options) { - if (options == null) { - options = {}; - } + highlight(x, y, w, h, options = {}) { options.Subtype = 'Highlight'; if (options.color == null) { options.color = [241, 238, 148]; @@ -90,54 +78,36 @@ export default { return this._markup(x, y, w, h, options); }, - underline(x, y, w, h, options) { - if (options == null) { - options = {}; - } + underline(x, y, w, h, options = {}) { options.Subtype = 'Underline'; return this._markup(x, y, w, h, options); }, - strike(x, y, w, h, options) { - if (options == null) { - options = {}; - } + strike(x, y, w, h, options = {}) { options.Subtype = 'StrikeOut'; return this._markup(x, y, w, h, options); }, - lineAnnotation(x1, y1, x2, y2, options) { - if (options == null) { - options = {}; - } + lineAnnotation(x1, y1, x2, y2, options = {}) { options.Subtype = 'Line'; options.Contents = new String(); options.L = [x1, this.page.height - y1, x2, this.page.height - y2]; return this.annotate(x1, y1, x2, y2, options); }, - rectAnnotation(x, y, w, h, options) { - if (options == null) { - options = {}; - } + rectAnnotation(x, y, w, h, options = {}) { options.Subtype = 'Square'; options.Contents = new String(); return this.annotate(x, y, w, h, options); }, - ellipseAnnotation(x, y, w, h, options) { - if (options == null) { - options = {}; - } + ellipseAnnotation(x, y, w, h, options = {}) { options.Subtype = 'Circle'; options.Contents = new String(); return this.annotate(x, y, w, h, options); }, - textAnnotation(x, y, w, h, text, options) { - if (options == null) { - options = {}; - } + textAnnotation(x, y, w, h, text, options = {}) { options.Subtype = 'FreeText'; options.Contents = new String(text); options.DA = new String(); diff --git a/lib/mixins/images.js b/lib/mixins/images.js index 021ad21..30ce126 100644 --- a/lib/mixins/images.js +++ b/lib/mixins/images.js @@ -6,11 +6,8 @@ export default { return (this._imageCount = 0); }, - image(src, x, y, options) { + image(src, x, y, options = {}) { let bh, bp, bw, image, ip, left, left1; - if (options == null) { - options = {}; - } if (typeof x === 'object') { options = x; x = null; diff --git a/lib/mixins/text.js b/lib/mixins/text.js index 1a00db2..d9a58c2 100644 --- a/lib/mixins/text.js +++ b/lib/mixins/text.js @@ -70,10 +70,7 @@ export default { return this._text(text, x, y, options, this._line); }, - widthOfString(string, options) { - if (options == null) { - options = {}; - } + widthOfString(string, options = {}) { return ( this._font.widthOfString(string, this._fontSize, options.features) + (options.characterSpacing || 0) * (string.length - 1) @@ -189,13 +186,7 @@ export default { return this; }, - _initOptions(x, y, options) { - if (x == null) { - x = {}; - } - if (options == null) { - options = {}; - } + _initOptions(x = {}, y, options = {}) { if (typeof x === 'object') { options = x; x = null; @@ -241,10 +232,7 @@ export default { return result; }, - _line(text, options, wrapper) { - if (options == null) { - options = {}; - } + _line(text, options = {}, wrapper) { this._fragment(text, this.x, this.y, options); const lineGap = options.lineGap || this._lineGap || 0; diff --git a/lib/mixins/vector.js b/lib/mixins/vector.js index 1c657e5..61dbac4 100644 --- a/lib/mixins/vector.js +++ b/lib/mixins/vector.js @@ -61,11 +61,8 @@ export default { return this.addContent(`${number(m)} M`); }, - dash(length, options) { + dash(length, options = {}) { let phase; - if (options == null) { - options = {}; - } if (length == null) { return this; } @@ -308,11 +305,8 @@ export default { return this.transform(1, 0, 0, 1, x, y); }, - rotate(angle, options) { + rotate(angle, options = {}) { let y; - if (options == null) { - options = {}; - } const rad = (angle * Math.PI) / 180; const cos = Math.cos(rad); const sin = Math.sin(rad); @@ -329,14 +323,11 @@ export default { return this.transform(cos, sin, -sin, cos, x, y); }, - scale(xFactor, yFactor, options) { + scale(xFactor, yFactor, options = {}) { let y; if (yFactor == null) { yFactor = xFactor; } - if (options == null) { - options = {}; - } if (typeof yFactor === 'object') { options = yFactor; yFactor = xFactor; diff --git a/lib/outline.js b/lib/outline.js index c0d0c8b..8dc709d 100644 --- a/lib/outline.js +++ b/lib/outline.js @@ -1,9 +1,6 @@ class PDFOutline { - constructor(document, parent, title, dest, options) { + constructor(document, parent, title, dest, options = { expanded: false }) { this.document = document; - if (options == null) { - options = { expanded: false }; - } this.options = options; this.outlineData = {}; @@ -23,10 +20,7 @@ class PDFOutline { this.children = []; } - addItem(title, options) { - if (options == null) { - options = { expanded: false }; - } + addItem(title, options = { expanded: false }) { const result = new PDFOutline( this.document, this.dictionary, diff --git a/lib/page.js b/lib/page.js index 7dde532..9c2fe77 100644 --- a/lib/page.js +++ b/lib/page.js @@ -64,11 +64,8 @@ const SIZES = { }; class PDFPage { - constructor(document, options) { + constructor(document, options = {}) { this.document = document; - if (options == null) { - options = {}; - } this.size = options.size || 'letter'; this.layout = options.layout || 'portrait'; diff --git a/lib/reference.js b/lib/reference.js index 04b9485..7c20c61 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -8,13 +8,10 @@ import PDFAbstractReference from './abstract_reference'; import PDFObject from './object'; class PDFReference extends PDFAbstractReference { - constructor(document, id, data) { + constructor(document, id, data = {}) { super(); this.document = document; this.id = id; - if (data == null) { - data = {}; - } this.data = data; this.gen = 0; this.compress = this.document.compress && !this.data.Filter;