Skip to content

Commit

Permalink
Use rest args instead of slicing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbe committed May 27, 2020
1 parent 406c18d commit f715d96
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
5 changes: 2 additions & 3 deletions lib/doc/row.js
Expand Up @@ -3,7 +3,7 @@
const _ = require('../utils/under-dash');

const Enums = require('./enums');
const colCache = require('./../utils/col-cache');
const colCache = require('../utils/col-cache');
const Cell = require('./cell');

class Row {
Expand Down Expand Up @@ -74,8 +74,7 @@ class Row {
}

// remove cell(s) and shift all higher cells down by count
splice(start, count) {
const inserts = Array.prototype.slice.call(arguments, 2);
splice(start, count, ...inserts) {
const nKeep = start + count;
const nExpand = inserts.length - count;
const nEnd = this._cells.length;
Expand Down
19 changes: 8 additions & 11 deletions lib/doc/worksheet.js
Expand Up @@ -211,9 +211,7 @@ class Worksheet {
return this._columns[c - 1];
}

spliceColumns(start, count) {
// each member of inserts is a column of data.
const inserts = Array.prototype.slice.call(arguments, 2);
spliceColumns(start, count, ...inserts) {
const rows = this._rows;
const nRows = rows.length;
if (inserts.length > 0) {
Expand Down Expand Up @@ -368,9 +366,8 @@ class Worksheet {
}
}

spliceRows(start, count) {
spliceRows(start, count, ...inserts) {
// same problem as row.splice, except worse.
const inserts = Array.prototype.slice.call(arguments, 2);
const nKeep = start + count;
const nExpand = inserts.length - count;
const nEnd = this._rows.length;
Expand Down Expand Up @@ -476,13 +473,13 @@ class Worksheet {
// Merge

// convert the range defined by ['tl:br'], [tl,br] or [t,l,b,r] into a single 'merged' cell
mergeCells() {
const dimensions = new Range(Array.prototype.slice.call(arguments, 0)); // convert arguments into Array
mergeCells(...cells) {
const dimensions = new Range(cells);
this._mergeCellsInternal(dimensions);
}

mergeCellsWithoutStyle() {
const dimensions = new Range(Array.prototype.slice.call(arguments, 0)); // convert arguments into Array
mergeCellsWithoutStyle(...cells) {
const dimensions = new Range(cells);
this._mergeCellsInternal(dimensions, true);
}

Expand Down Expand Up @@ -530,8 +527,8 @@ class Worksheet {
// scan the range defined by ['tl:br'], [tl,br] or [t,l,b,r] and if any cell is part of a merge,
// un-merge the group. Note this function can affect multiple merges and merge-blocks are
// atomic - either they're all merged or all un-merged.
unMergeCells() {
const dimensions = new Range(Array.prototype.slice.call(arguments, 0)); // convert arguments into Array
unMergeCells(...cells) {
const dimensions = new Range(cells);

// find any cells in that range and unmerge them
for (let i = dimensions.top; i <= dimensions.bottom; i++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/stream/xlsx/worksheet-writer.js
Expand Up @@ -420,9 +420,9 @@ class WorksheetWriter {
return row.getCellEx(address);
}

mergeCells() {
mergeCells(...cells) {
// may fail if rows have been comitted
const dimensions = new Dimensions(Array.prototype.slice.call(arguments, 0)); // convert arguments into Array
const dimensions = new Dimensions(cells);

// check cells aren't already merged
this._merges.forEach(merge => {
Expand Down
20 changes: 8 additions & 12 deletions lib/utils/under-dash.js
Expand Up @@ -3,7 +3,7 @@ const {toString} = Object.prototype;
const _ = {
each: function each(obj, cb) {
if (obj) {
if (_.isArray(obj)) {
if (Array.isArray(obj)) {
obj.forEach(cb);
} else {
Object.keys(obj).forEach(key => {
Expand All @@ -15,7 +15,7 @@ const _ = {

some: function some(obj, cb) {
if (obj) {
if (_.isArray(obj)) {
if (Array.isArray(obj)) {
return obj.some(cb);
}
return Object.keys(obj).some(key => cb(obj[key], key));
Expand All @@ -25,7 +25,7 @@ const _ = {

every: function every(obj, cb) {
if (obj) {
if (_.isArray(obj)) {
if (Array.isArray(obj)) {
return obj.every(cb);
}
return Object.keys(obj).every(key => cb(obj[key], key));
Expand All @@ -35,7 +35,7 @@ const _ = {

map: function map(obj, cb) {
if (obj) {
if (_.isArray(obj)) {
if (Array.isArray(obj)) {
return obj.map(cb);
}
return Object.keys(obj).map(key => cb(obj[key], key));
Expand All @@ -53,8 +53,8 @@ const _ = {
isEqual: function isEqual(a, b) {
const aType = typeof a;
const bType = typeof b;
const aArray = _.isArray(a);
const bArray = _.isArray(b);
const aArray = Array.isArray(a);
const bArray = Array.isArray(b);

if (aType !== bType) {
return false;
Expand Down Expand Up @@ -102,10 +102,6 @@ const _ = {
return toString.call(val) === '[object Undefined]';
},

isArray(val) {
return toString.call(val) === '[object Array]';
},

isObject(val) {
return toString.call(val) === '[object Object]';
},
Expand All @@ -118,11 +114,11 @@ const _ = {

function assignValue(val, key) {
src = target[key];
copyIsArray = _.isArray(val);
copyIsArray = Array.isArray(val);
if (_.isObject(val) || copyIsArray) {
if (copyIsArray) {
copyIsArray = false;
clone = src && _.isArray(src) ? src : [];
clone = src && Array.isArray(src) ? src : [];
} else {
clone = src && _.isObject(src) ? src : {};
}
Expand Down
3 changes: 1 addition & 2 deletions lib/xlsx/xform/comment/vml-textbox-xform.js
@@ -1,5 +1,4 @@
const BaseXform = require('../base-xform');
const _ = require('../../../utils/under-dash');

class VmlTextboxXform extends BaseXform {
get tag() {
Expand All @@ -22,7 +21,7 @@ class VmlTextboxXform extends BaseXform {
};
if (model && model.note) {
let {inset} = model.note && model.note.margins;
if (_.isArray(inset)) {
if (Array.isArray(inset)) {
inset = inset
.map(margin => {
return this.conversionUnit(margin, 10, 'mm');
Expand Down
3 changes: 1 addition & 2 deletions spec/utils/tools.js
Expand Up @@ -23,8 +23,7 @@ const tools = {
return clone;
},

concatenateFormula() {
const args = Array.prototype.slice.call(arguments);
concatenateFormula(...args) {
const values = args.map(value => `"${value}"`);
return {
formula: `CONCATENATE(${values.join(',')})`,
Expand Down

0 comments on commit f715d96

Please sign in to comment.