Skip to content

Commit

Permalink
change max-len value, lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Siemienik committed Sep 28, 2020
1 parent 51cfe07 commit 8ec8baa
Show file tree
Hide file tree
Showing 46 changed files with 585 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"default-case": ["off"],
"func-names": ["off", "never"],
"global-require": ["off"],
"max-len": ["error", {"code": 160, "ignoreComments": true, "ignoreStrings": true}],
"max-len": ["error", {"code": 100, "ignoreComments": true, "ignoreStrings": true}],
"no-console": ["error", { "allow": ["warn"] }],
"no-continue": ["off"],
"no-mixed-operators": ["error", {"allowSamePrecedence": true}],
Expand Down
2 changes: 1 addition & 1 deletion .prettier
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bracketSpacing": false,
"printWidth": 160,
"printWidth": 100,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
Expand Down
34 changes: 27 additions & 7 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const runs = 3;
await runProfiling('huge xlsx file streams', () => {
return new Promise((resolve, reject) => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('./spec/integration/data/huge.xlsx');
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
'./spec/integration/data/huge.xlsx'
);
workbookReader.read();

let worksheetCount = 0;
Expand All @@ -32,7 +34,9 @@ const runs = 3;

await runProfiling('huge xlsx file async iteration', async () => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader('spec/integration/data/huge.xlsx');
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(
'spec/integration/data/huge.xlsx'
);
let worksheetCount = 0;
let rowCount = 0;
for await (const worksheetReader of workbookReader) {
Expand All @@ -55,13 +59,21 @@ const runs = 3;
async function runProfiling(name, run) {
console.log('');
console.log('####################################################');
console.log(`WARMUP: Current memory usage: ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`WARMUP: Current memory usage: ${currentMemoryUsage({runGarbageCollector: true})} MB`
);
console.log(`WARMUP: ${name} profiling started`);
const warmupStartTime = Date.now();
await run();
console.log(`WARMUP: ${name} profiling finished in ${Date.now() - warmupStartTime}ms`);
console.log(`WARMUP: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`WARMUP: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`WARMUP: Current memory usage (before GC): ${currentMemoryUsage({
runGarbageCollector: false,
})} MB`
);
console.log(
`WARMUP: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`
);

for (let i = 1; i <= runs; i += 1) {
console.log('');
Expand All @@ -70,8 +82,16 @@ async function runProfiling(name, run) {
const startTime = Date.now();
await run(); // eslint-disable-line no-await-in-loop
console.log(`RUN ${i}: ${name} profiling finished in ${Date.now() - startTime}ms`);
console.log(`RUN ${i}: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`RUN ${i}: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(
`RUN ${i}: Current memory usage (before GC): ${currentMemoryUsage({
runGarbageCollector: false,
})} MB`
);
console.log(
`RUN ${i}: Current memory usage (after GC): ${currentMemoryUsage({
runGarbageCollector: true,
})} MB`
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

if (parseInt(process.versions.node.split('.')[0], 10) < 10) {
throw new Error('For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports');
throw new Error(
'For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports'
);
}

module.exports = require('./lib/exceljs.nodejs.js');
11 changes: 9 additions & 2 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ class CSV {
return new Promise((resolve, reject) => {
const worksheet = this.workbook.addWorksheet(options.sheetName);

const dateFormats = options.dateFormats || ['YYYY-MM-DD[T]HH:mm:ssZ', 'YYYY-MM-DD[T]HH:mm:ss', 'MM-DD-YYYY', 'YYYY-MM-DD'];
const dateFormats = options.dateFormats || [
'YYYY-MM-DD[T]HH:mm:ssZ',
'YYYY-MM-DD[T]HH:mm:ss',
'MM-DD-YYYY',
'YYYY-MM-DD',
];
const map =
options.map ||
function(datum) {
Expand Down Expand Up @@ -130,7 +135,9 @@ class CSV {
}
if (value instanceof Date) {
if (dateFormat) {
return dateUTC ? dayjs.utc(value).format(dateFormat) : dayjs(value).format(dateFormat);
return dateUTC
? dayjs.utc(value).format(dateFormat)
: dayjs(value).format(dateFormat);
}
return dateUTC ? dayjs.utc(value).format() : dayjs(value).format();
}
Expand Down
6 changes: 5 additions & 1 deletion lib/csv/stream-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ class StreamConverter {
this.writeStarted = true;
}

this.inner.write(this.convertInwards(data), encoding ? this.innerEncoding : undefined, callback);
this.inner.write(
this.convertInwards(data),
encoding ? this.innerEncoding : undefined,
callback
);
}

read() {
Expand Down
8 changes: 6 additions & 2 deletions lib/doc/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ class Anchor {
}

get colWidth() {
return this.worksheet && this.worksheet.getColumn(this.nativeCol + 1) && this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth
return this.worksheet &&
this.worksheet.getColumn(this.nativeCol + 1) &&
this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth
? Math.floor(this.worksheet.getColumn(this.nativeCol + 1).width * 10000)
: 640000;
}

get rowHeight() {
return this.worksheet && this.worksheet.getRow(this.nativeRow + 1) && this.worksheet.getRow(this.nativeRow + 1).height
return this.worksheet &&
this.worksheet.getRow(this.nativeRow + 1) &&
this.worksheet.getRow(this.nativeRow + 1).height
? Math.floor(this.worksheet.getRow(this.nativeRow + 1).height * 10000)
: 180000;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/doc/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ class FormulaValue {
get dependencies() {
// find all the ranges and cells mentioned in the formula
const ranges = this.formula.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g);
const cells = this.formula.replace(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g, '').match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}/g);
const cells = this.formula
.replace(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g, '')
.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}/g);
return {
ranges,
cells,
Expand Down Expand Up @@ -860,7 +862,8 @@ class FormulaValue {
if (!this._translatedFormula && this.model.sharedFormula) {
const {worksheet} = this.cell;
const master = worksheet.findCell(this.model.sharedFormula);
this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address);
this._translatedFormula =
master && slideFormula(master.formula, master.address, this.model.address);
}
return this._translatedFormula;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/doc/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class Column {
}

get collapsed() {
return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
return !!(
this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol
);
}

toString() {
Expand All @@ -134,7 +136,12 @@ class Column {
}

equivalentTo(other) {
return this.width === other.width && this.hidden === other.hidden && this.outlineLevel === other.outlineLevel && _.isEqual(this.style, other.style);
return (
this.width === other.width &&
this.hidden === other.hidden &&
this.outlineLevel === other.outlineLevel &&
_.isEqual(this.style, other.style)
);
}

get isDefault() {
Expand Down
8 changes: 6 additions & 2 deletions lib/doc/defined-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class DefinedNames {
}

getNamesEx(address) {
return _.map(this.matrixMap, (matrix, name) => matrix.findCellEx(address) && name).filter(Boolean);
return _.map(this.matrixMap, (matrix, name) => matrix.findCellEx(address) && name).filter(
Boolean
);
}

_explore(matrix, cell) {
Expand Down Expand Up @@ -172,7 +174,9 @@ class DefinedNames {

get model() {
// To get names per cell - just iterate over all names finding cells if they exist
return _.map(this.matrixMap, (matrix, name) => this.getRanges(name, matrix)).filter(definedName => definedName.ranges.length);
return _.map(this.matrixMap, (matrix, name) => this.getRanges(name, matrix)).filter(
definedName => definedName.ranges.length
);
}

set model(value) {
Expand Down
7 changes: 6 additions & 1 deletion lib/doc/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ class Range {

containsEx(address) {
if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) return false;
return address.row >= this.top && address.row <= this.bottom && address.col >= this.left && address.col <= this.right;
return (
address.row >= this.top &&
address.row <= this.bottom &&
address.col >= this.left &&
address.col <= this.right
);
}

forEachAddress(cb) {
Expand Down
4 changes: 3 additions & 1 deletion lib/doc/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class Row {
}

get collapsed() {
return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow);
return !!(
this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow
);
}

// =========================================================================
Expand Down
13 changes: 10 additions & 3 deletions lib/doc/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ class Workbook {
if (options) {
if (typeof options === 'string') {
// eslint-disable-next-line no-console
console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }');
console.trace(
'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }'
);
options = {
properties: {
tabColor: {argb: options},
},
};
} else if (options.argb || options.theme || options.indexed) {
// eslint-disable-next-line no-console
console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }');
console.trace(
'tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }'
);
options = {
properties: {
tabColor: options,
Expand All @@ -76,7 +80,10 @@ class Workbook {
}
}

const lastOrderNo = this._worksheets.reduce((acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc), 0);
const lastOrderNo = this._worksheets.reduce(
(acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc),
0
);
const worksheetOptions = Object.assign({}, options, {
id,
name,
Expand Down
28 changes: 22 additions & 6 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class Worksheet {
orientation: 'portrait',
horizontalDpi: 4294967295,
verticalDpi: 4294967295,
fitToPage: !!(options.pageSetup && (options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) && !options.pageSetup.scale),
fitToPage: !!(
options.pageSetup &&
(options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) &&
!options.pageSetup.scale
),
pageOrder: 'downThenOver',
blackAndWhite: false,
draft: false,
Expand Down Expand Up @@ -693,13 +697,21 @@ class Worksheet {
};
if (options && 'spinCount' in options) {
// force spinCount to be integer >= 0
options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
options.spinCount = Number.isFinite(options.spinCount)
? Math.round(Math.max(0, options.spinCount))
: 100000;
}
if (password) {
this.sheetProtection.algorithmName = 'SHA-512';
this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64');
this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', this.sheetProtection.saltValue, this.sheetProtection.spinCount);
this.sheetProtection.spinCount =
options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(
password,
'SHA512',
this.sheetProtection.saltValue,
this.sheetProtection.spinCount
);
}
if (options) {
this.sheetProtection = Object.assign(this.sheetProtection, options);
Expand Down Expand Up @@ -755,13 +767,17 @@ class Worksheet {
// Deprecated
get tabColor() {
// eslint-disable-next-line no-console
console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
console.trace(
'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'
);
return this.properties.tabColor;
}

set tabColor(value) {
// eslint-disable-next-line no-console
console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
console.trace(
'worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor'
);
this.properties.tabColor = value;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/stream/xlsx/sheet-rels-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class SheetRelsWriter {
'/>'
);
} else {
this.stream.write(`<Relationship Id="${rId}" Type="${relationship.Type}" Target="${relationship.Target}"/>`);
this.stream.write(
`<Relationship Id="${rId}" Type="${relationship.Type}" Target="${relationship.Target}"/>`
);
}

return rId;
Expand Down
14 changes: 12 additions & 2 deletions lib/stream/xlsx/workbook-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,25 @@ class WorkbookReader extends EventEmitter {

*_parseWorksheet(iterator, sheetNo) {
this._emitEntry({type: 'worksheet', id: sheetNo});
const worksheetReader = new WorksheetReader({workbook: this, id: sheetNo, iterator, options: this.options});
const worksheetReader = new WorksheetReader({
workbook: this,
id: sheetNo,
iterator,
options: this.options,
});
if (this.options.worksheets === 'emit') {
yield {eventType: 'worksheet', value: worksheetReader};
}
}

*_parseHyperlinks(iterator, sheetNo) {
this._emitEntry({type: 'hyperlinks', id: sheetNo});
const hyperlinksReader = new HyperlinkReader({workbook: this, id: sheetNo, iterator, options: this.options});
const hyperlinksReader = new HyperlinkReader({
workbook: this,
id: sheetNo,
iterator,
options: this.options,
});
if (this.options.hyperlinks === 'emit') {
yield {eventType: 'hyperlinks', value: hyperlinksReader};
}
Expand Down
Loading

0 comments on commit 8ec8baa

Please sign in to comment.