Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #230 from natergj/do-not-install-all-of-lodash
Browse files Browse the repository at this point in the history
reduce package size by installing specific lodash utilities
  • Loading branch information
natergj authored Sep 9, 2018
2 parents 42ea732 + 4c1b428 commit 3a69127
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 118 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
"deepmerge": "2.1.1",
"image-size": "0.6.3",
"jszip": "3.1.5",
"lodash": "4.17.10",
"lodash.get": "4.4.2",
"lodash.isequal": "4.5.0",
"lodash.isundefined": "3.0.1",
"lodash.reduce": "4.6.0",
"lodash.uniqueid": "4.0.1",
"mime": "2.3.1",
"xmlbuilder": "10.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions source/lib/cell/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const deepmerge = require('deepmerge');
const Cell = require('./cell.js');
const Row = require('../row/row.js');
const Column = require('../column/column.js');
Expand Down Expand Up @@ -167,7 +167,7 @@ function styleSetter(val) {
c.style(thisCellStyle.ids.cellXfs);
} else {
let curStyle = this.ws.wb.styles[c.s];
let newStyleOpts = _.merge({}, curStyle.toObject(), thisStyle);
let newStyleOpts = deepmerge(curStyle.toObject(), thisStyle);
let mergedStyle = this.ws.wb.createStyle(newStyleOpts);
c.style(mergedStyle.ids.cellXfs);
}
Expand Down
8 changes: 3 additions & 5 deletions source/lib/column/column.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const utils = require('../utils.js');
const _ = require('lodash');


class Column {
/**
Expand Down Expand Up @@ -92,7 +90,7 @@ class Column {
throw new TypeError('Column group collapse flag must be a boolean');
}

return this;
return this;
}

/**
Expand All @@ -108,8 +106,8 @@ class Column {
o.state = 'frozen';
o.xSplit = this.min;
o.activePane = 'bottomRight';
o.ySplit === null ?
o.topLeftCell = utils.getExcelCellRef(1, jumpTo) :
o.ySplit === null ?
o.topLeftCell = utils.getExcelCellRef(1, jumpTo) :
o.topLeftCell = utils.getExcelCellRef(utils.getExcelRowCol(o.topLeftCell).row, jumpTo);
return this;
}
Expand Down
1 change: 0 additions & 1 deletion source/lib/column/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const _ = require('lodash');
const Cell = require('../cell/cell.js');
const Row = require('../row/row.js');
const Column = require('../column/column.js');
Expand Down
16 changes: 8 additions & 8 deletions source/lib/drawing/picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Drawing = require('./drawing.js');
const path = require('path');
const imgsz = require('image-size');
const mime = require('mime');
const uniqueId = require('lodash').uniqueId;
const uniqueId = require('lodash.uniqueid');

const EMU = require('../classes/emu.js');
const xmlbuilder = require('xmlbuilder');
Expand Down Expand Up @@ -37,18 +37,18 @@ class Picture extends Drawing {
this.imagePath = opts.path;
this.image = opts.image;

this._name = this.image
? opts.name || uniqueId('image-')
: opts.name || path.basename(this.imagePath);
this._name = this.image ?
opts.name || uniqueId('image-') :
opts.name || path.basename(this.imagePath);

const size = imgsz(this.imagePath || this.image);

this._pxWidth = size.width;
this._pxHeight = size.height;

this._extension = this.image
? size.type
: path.extname(this.imagePath).substr(1);
this._extension = this.image ?
size.type :
path.extname(this.imagePath).substr(1);

this.contentType = mime.getType(this._extension);

Expand Down Expand Up @@ -155,7 +155,7 @@ class Picture extends Drawing {
atEle.ele('xdr:col').text(at.col);
atEle.ele('xdr:colOff').text(at.colOff);
atEle.ele('xdr:row').text(at.row);
atEle.ele('xdr:rowOff').text(at.rowOff);
atEle.ele('xdr:rowOff').text(at.rowOff);
}

if (this.anchorType === 'oneCellAnchor' || this.anchorType === 'absoluteAnchor') {
Expand Down
1 change: 0 additions & 1 deletion source/lib/row/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const _ = require('lodash');
const Row = require('../row/row.js');

/**
Expand Down
9 changes: 4 additions & 5 deletions source/lib/row/row.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const utils = require('../utils.js');
const _ = require('lodash');

class Row {
/**
Expand Down Expand Up @@ -93,7 +92,7 @@ class Row {
return utils.getExcelAlpha(utils.getExcelRowCol(this.cellRefs[0]).col);
} else {
return 'A';
}
}
}

get lastColumn() {
Expand All @@ -109,7 +108,7 @@ class Row {
return utils.getExcelAlpha(utils.getExcelRowCol(this.cellRefs[this.cellRefs.length - 1]).col);
} else {
return 'A';
}
}
}

/**
Expand Down Expand Up @@ -196,8 +195,8 @@ class Row {
o.state = 'frozen';
o.ySplit = this.r;
o.activePane = 'bottomRight';
o.xSplit === null ?
o.topLeftCell = utils.getExcelCellRef(jumpTo, 1) :
o.xSplit === null ?
o.topLeftCell = utils.getExcelCellRef(jumpTo, 1) :
o.topLeftCell = utils.getExcelCellRef(jumpTo, utils.getExcelRowCol(o.topLeftCell).col);
return this;
}
Expand Down
20 changes: 9 additions & 11 deletions source/lib/style/classes/alignment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const utils = require('../../utils.js');
const types = require('../../types/index.js');
const _ = require('lodash');
const xmlbuilder = require('xmlbuilder');

class Alignment { // §18.8.1 alignment (Alignment)
Expand All @@ -23,55 +21,55 @@ class Alignment { // §18.8.1 alignment (Alignment)
if (opts.horizontal !== undefined) {
this.horizontal = types.alignment.horizontal.validate(opts.horizontal) === true ? opts.horizontal : null;
}

if (opts.vertical !== undefined) {
this.vertical = types.alignment.vertical.validate(opts.vertical) === true ? opts.vertical : null;
}

if (opts.readingOrder !== undefined) {
this.readingOrder = types.alignment.readingOrder.validate(opts.readingOrder) === true ? opts.readingOrder : null;
}

if (opts.indent !== undefined) {
if (typeof opts.indent === 'number' && parseInt(opts.indent) === opts.indent && opts.indent > 0) {
this.indent = opts.indent;
} else {
throw new TypeError('alignment indent must be a positive integer.');
}
}

if (opts.justifyLastLine !== undefined) {
if (typeof opts.justifyLastLine === 'boolean') {
this.justifyLastLine = opts.justifyLastLine;
} else {
throw new TypeError('justifyLastLine alignment option must be of type boolean');
}
}

if (opts.relativeIndent !== undefined) {
if (typeof opts.relativeIndent === 'number' && parseInt(opts.relativeIndent) === opts.relativeIndent && opts.relativeIndent > 0) {
this.relativeIndent = opts.relativeIndent;
} else {
throw new TypeError('alignment indent must be a positive integer.');
}
}

if (opts.shrinkToFit !== undefined) {
if (typeof opts.shrinkToFit === 'boolean') {
this.shrinkToFit = opts.shrinkToFit;
} else {
throw new TypeError('justifyLastLine alignment option must be of type boolean');
}
}

if (opts.textRotation !== undefined) {
if (typeof opts.textRotation === 'number' && parseInt(opts.textRotation) === opts.textRotation) {
this.textRotation = opts.textRotation;
} else if (opts.textRotation !== undefined) {
throw new TypeError('alignment indent must be an integer.');
}
}

if (opts.wrapText !== undefined) {
if (typeof opts.wrapText === 'boolean') {
this.wrapText = opts.wrapText;
Expand Down Expand Up @@ -100,7 +98,7 @@ class Alignment { // §18.8.1 alignment (Alignment)
this.wrapText !== undefined ? obj.wrapText = this.wrapText : null;

return obj;
}
}

/**
* @alias Alignment.addToXMLele
Expand Down
4 changes: 1 addition & 3 deletions source/lib/style/classes/border.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const utils = require('../../utils.js');
const types = require('../../types/index.js');
const _ = require('lodash');
const xmlbuilder = require('xmlbuilder');
const CTColor = require('./ctColor.js');

Expand Down Expand Up @@ -70,7 +68,7 @@ class Border {
} else {
throw new TypeError('Border outline option must be of type Boolean');
}
} else if (['left', 'right', 'top', 'bottom', 'diagonal'].indexOf(opt) < 0) { //TODO: move logic to types folder
} else if (['left', 'right', 'top', 'bottom', 'diagonal'].indexOf(opt) < 0) { //TODO: move logic to types folder
throw new TypeError(`Invalid key for border declaration ${opt}. Must be one of left, right, top, bottom, diagonal`);
} else {
this[opt] = new BorderOrdinal(opts[opt]);
Expand Down
2 changes: 0 additions & 2 deletions source/lib/style/classes/ctColor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const utils = require('../../utils.js');
const types = require('../../types/index.js');
const _ = require('lodash');
const xmlbuilder = require('xmlbuilder');

class CTColor { //§18.8.3 && §18.8.19
Expand Down
112 changes: 55 additions & 57 deletions source/lib/style/classes/fill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const utils = require('../../utils.js');
const types = require('../../types/index.js');
const _ = require('lodash');
const xmlbuilder = require('xmlbuilder');
const CTColor = require('./ctColor.js');

Expand Down Expand Up @@ -55,77 +53,77 @@ class Fill { //§18.8.20 fill (Fill)
}

switch (this.type) {
case 'gradient': //§18.8.24
if (opts.bottom !== undefined) {
if (opts.bottom < 0 || opts.bottom > 1) {
throw new TypeError('Values for gradient fill bottom attribute must be a decimal between 0 and 1');
} else {
this.bottom = opts.bottom;
case 'gradient': //§18.8.24
if (opts.bottom !== undefined) {
if (opts.bottom < 0 || opts.bottom > 1) {
throw new TypeError('Values for gradient fill bottom attribute must be a decimal between 0 and 1');
} else {
this.bottom = opts.bottom;
}
}
}

if (opts.degree !== undefined) {
if (typeof opts.degree === 'number') {
this.degree = opts.degree;
} else {
throw new TypeError('Values of gradient fill degree must be of type number.');
if (opts.degree !== undefined) {
if (typeof opts.degree === 'number') {
this.degree = opts.degree;
} else {
throw new TypeError('Values of gradient fill degree must be of type number.');
}
}
}


if (opts.left !== undefined) {
if (opts.left < 0 || opts.left > 1) {
throw new TypeError('Values for gradient fill left attribute must be a decimal between 0 and 1');
} else {
this.left = opts.left;
if (opts.left !== undefined) {
if (opts.left < 0 || opts.left > 1) {
throw new TypeError('Values for gradient fill left attribute must be a decimal between 0 and 1');
} else {
this.left = opts.left;
}
}
}

if (opts.right !== undefined) {
if (opts.right < 0 || opts.right > 1) {
throw new TypeError('Values for gradient fill right attribute must be a decimal between 0 and 1');
} else {
this.right = opts.right;
if (opts.right !== undefined) {
if (opts.right < 0 || opts.right > 1) {
throw new TypeError('Values for gradient fill right attribute must be a decimal between 0 and 1');
} else {
this.right = opts.right;
}
}
}

if (opts.top !== undefined) {
if (opts.top < 0 || opts.top > 1) {
throw new TypeError('Values for gradient fill top attribute must be a decimal between 0 and 1');
} else {
this.top = opts.top;
if (opts.top !== undefined) {
if (opts.top < 0 || opts.top > 1) {
throw new TypeError('Values for gradient fill top attribute must be a decimal between 0 and 1');
} else {
this.top = opts.top;
}
}
}

if (opts.stops !== undefined) {
if (opts.stops instanceof Array) {
opts.stops.forEach((s, i) => {
this.stops.push(new Stop(s, i));
});
} else {
throw new TypeError('Stops for gradient fills must be sent as an Array');

if (opts.stops !== undefined) {
if (opts.stops instanceof Array) {
opts.stops.forEach((s, i) => {
this.stops.push(new Stop(s, i));
});
} else {
throw new TypeError('Stops for gradient fills must be sent as an Array');
}
}
}

break;
break;

case 'pattern': //§18.8.32
if (opts.bgColor !== undefined) {
this.bgColor = new CTColor(opts.bgColor);
}
case 'pattern': //§18.8.32
if (opts.bgColor !== undefined) {
this.bgColor = new CTColor(opts.bgColor);
}

if (opts.fgColor !== undefined) {
this.fgColor = new CTColor(opts.fgColor);
}
if (opts.fgColor !== undefined) {
this.fgColor = new CTColor(opts.fgColor);
}

if (opts.patternType !== undefined) {
types.fillPattern.validate(opts.patternType) === true ? this.patternType = opts.patternType : null;
}
break;
if (opts.patternType !== undefined) {
types.fillPattern.validate(opts.patternType) === true ? this.patternType = opts.patternType : null;
}
break;

case 'none':
this.patternType = 'none';
break;
case 'none':
this.patternType = 'none';
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions source/lib/style/classes/font.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const utils = require('../../utils.js');
const _ = require('lodash');
const xmlbuilder = require('xmlbuilder');
const types = require('../../types/index.js');

Expand Down
Loading

0 comments on commit 3a69127

Please sign in to comment.