Skip to content

Commit

Permalink
Merge pull request exceljs#808 from alubbe/prettier-refactoring2
Browse files Browse the repository at this point in the history
Apply prettier-eslint to whole codebase
  • Loading branch information
alubbe authored May 10, 2019
2 parents 957f069 + 3d97cbc commit 83cf728
Show file tree
Hide file tree
Showing 257 changed files with 13,889 additions and 9,307 deletions.
37 changes: 17 additions & 20 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ module.exports = function(grunt) {
grunt.initConfig({
babel: {
options: {
sourceMap: true
sourceMap: true,
},
dist: {
files: [
{
expand: true,
src: ['./lib/**/*.js', './spec/browser/*.js'],
dest: './build/'
}
]
}
dest: './build/',
},
],
},
},
browserify: {
bundle: {
src: ['./build/lib/exceljs.browser.js'],
dest: './dist/exceljs.js',
options: {
browserifyOptions: {
standalone: 'ExcelJS'
}
}
standalone: 'ExcelJS',
},
},
},
spec: {
src: ['./build/spec/browser/exceljs.spec.js'],
dest: './build/web/exceljs.spec.js'
dest: './build/web/exceljs.spec.js',
},
},
uglify: {
options: {
banner: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n'
banner: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n',
},
dist: {
files: {
'./dist/exceljs.min.js': ['./dist/exceljs.js']
}
'./dist/exceljs.min.js': ['./dist/exceljs.js'],
},
},
// es3: {
// files: [
Expand All @@ -64,20 +64,17 @@ module.exports = function(grunt) {

copy: {
dist: {
files: [
{ expand: true, src: ['**'], cwd: './build/lib', dest: './dist/es5' },
{ src: './build/lib/exceljs.nodejs.js', dest: './dist/es5/index.js'},
]
}
files: [{ expand: true, src: ['**'], cwd: './build/lib', dest: './dist/es5' }, { src: './build/lib/exceljs.nodejs.js', dest: './dist/es5/index.js' }],
},
},

jasmine: {
dev: {
src: ['./dist/exceljs.js'],
options: {
specs: './build/web/exceljs.spec.js'
}
}
specs: './build/web/exceljs.spec.js',
},
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion lib/config/set-value.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var PromishLib = require('../utils/promish');
const PromishLib = require('../utils/promish');

function setValue(key, value, overwrite) {
if (overwrite === undefined) {
Expand Down
122 changes: 60 additions & 62 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'use strict';

const fs = require('fs');
const csv = require('fast-csv');
const moment = require('moment');
const PromishLib = require('../utils/promish');
const StreamBuf = require('../utils/stream-buf');

var fs = require('fs');
var csv = require('fast-csv');
var moment = require('moment');
var PromishLib = require('../utils/promish');
var StreamBuf = require('../utils/stream-buf');
const utils = require('../utils/utils');

var utils = require('../utils/utils');

var CSV = module.exports = function(workbook) {
const CSV = (module.exports = function(workbook) {
this.workbook = workbook;
this.worksheet = null;
};
});

/* eslint-disable quote-props */
var SpecialValues = {
'true': true,
'false': false,
const SpecialValues = {
true: true,
false: false,
'#N/A': { error: '#N/A' },
'#REF!': { error: '#REF!' },
'#NAME?': { error: '#NAME?' },
Expand All @@ -28,89 +27,91 @@ var SpecialValues = {
};
/* eslint-ensable quote-props */


CSV.prototype = {
readFile: function(filename, options) {
var self = this;
readFile(filename, options) {
const self = this;
options = options || {};
var stream;
return utils.fs.exists(filename)
.then(function(exists) {
let stream;
return utils.fs
.exists(filename)
.then(exists => {
if (!exists) {
throw new Error('File not found: ' + filename);
throw new Error(`File not found: ${filename}`);
}
stream = fs.createReadStream(filename);
return self.read(stream, options);
})
.then(function(worksheet) {
.then(worksheet => {
stream.close();
return worksheet;
});
},
read: function(stream, options) {
read(stream, options) {
options = options || {};
return new PromishLib.Promish((resolve, reject) => {
var csvStream = this.createInputStream(options)
const csvStream = this.createInputStream(options)
.on('worksheet', resolve)
.on('error', reject);

stream.pipe(csvStream);
});
},
createInputStream: function(options) {
createInputStream(options) {
options = options || {};
var worksheet = this.workbook.addWorksheet(options.sheetName);
const worksheet = this.workbook.addWorksheet(options.sheetName);

var dateFormats = options.dateFormats || [
moment.ISO_8601,
'MM-DD-YYYY',
'YYYY-MM-DD'
];
var map = options.map || function(datum) {
const dateFormats = options.dateFormats || [moment.ISO_8601, 'MM-DD-YYYY', 'YYYY-MM-DD'];
const map =
options.map ||
function(datum) {
if (datum === '') {
return null;
}
if (!isNaN(datum)) {
return parseFloat(datum);
}
var dt = moment(datum, dateFormats, true);
const dt = moment(datum, dateFormats, true);
if (dt.isValid()) {
return new Date(dt.valueOf());
}
var special = SpecialValues[datum];
const special = SpecialValues[datum];
if (special !== undefined) {
return special;
}
return datum;
};

var csvStream = csv(options)
.on('data', function(data) {
const csvStream = csv(options)
.on('data', data => {
worksheet.addRow(data.map(map));
})
.on('end', function() {
.on('end', () => {
csvStream.emit('worksheet', worksheet);
});
return csvStream;
},

write: function(stream, options) {
write(stream, options) {
return new PromishLib.Promish((resolve, reject) => {
options = options || {};
// var encoding = options.encoding || 'utf8';
// var separator = options.separator || ',';
// var quoteChar = options.quoteChar || '\'';
// const encoding = options.encoding || 'utf8';
// const separator = options.separator || ',';
// const quoteChar = options.quoteChar || '\'';

var worksheet = this.workbook.getWorksheet(options.sheetName || options.sheetId);
const worksheet = this.workbook.getWorksheet(options.sheetName || options.sheetId);

var csvStream = csv.createWriteStream(options);
stream.on('finish', () => { resolve(); });
const csvStream = csv.createWriteStream(options);
stream.on('finish', () => {
resolve();
});
csvStream.on('error', reject);
csvStream.pipe(stream);

var dateFormat = options.dateFormat;
var dateUTC = options.dateUTC;
var map = options.map || (value => {
const dateFormat = options.dateFormat;
const dateUTC = options.dateUTC;
const map =
options.map ||
(value => {
if (value) {
if (value.text || value.hyperlink) {
return value.hyperlink || value.text || '';
Expand All @@ -122,7 +123,7 @@ CSV.prototype = {
if (dateFormat) {
dateUTC ? moment.utc(value).format(dateFormat) : moment(value).format(dateFormat);
}
return dateUTC ? moment.utc(value).format() : moment(value).format()
return dateUTC ? moment.utc(value).format() : moment(value).format();
}
if (value.error) {
return value.error;
Expand All @@ -134,16 +135,16 @@ CSV.prototype = {
return value;
});

var includeEmptyRows = (options.includeEmptyRows === undefined) || options.includeEmptyRows;
var lastRow = 1;
const includeEmptyRows = options.includeEmptyRows === undefined || options.includeEmptyRows;
let lastRow = 1;
if (worksheet) {
worksheet.eachRow(function(row, rowNumber) {
worksheet.eachRow((row, rowNumber) => {
if (includeEmptyRows) {
while (lastRow++ < rowNumber - 1) {
csvStream.write([]);
}
}
var values = row.values;
const values = row.values;
values.shift();
csvStream.write(values.map(map));
lastRow = rowNumber;
Expand All @@ -152,22 +153,19 @@ CSV.prototype = {
csvStream.end();
});
},
writeFile: function(filename, options) {
writeFile(filename, options) {
options = options || {};

var streamOptions = {
encoding: options.encoding || 'utf8'
const streamOptions = {
encoding: options.encoding || 'utf8',
};
var stream = fs.createWriteStream(filename, streamOptions);
const stream = fs.createWriteStream(filename, streamOptions);

return this.write(stream, options);
},
writeBuffer: function(options) {
var self = this;
var stream = new StreamBuf();
return self.write(stream, options)
.then(function() {
return stream.read();
});
}
writeBuffer(options) {
const self = this;
const stream = new StreamBuf();
return self.write(stream, options).then(() => stream.read());
},
};
27 changes: 13 additions & 14 deletions lib/csv/line-buffer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

var events = require('events');
const events = require('events');

var utils = require('../utils/utils');
const utils = require('../utils/utils');


var LineBuffer = module.exports = function(options) {
const LineBuffer = (module.exports = function(options) {
events.EventEmitter.call(this);
this.encoding = options.encoding;

Expand All @@ -14,18 +13,18 @@ var LineBuffer = module.exports = function(options) {
// part of cork/uncork
this.corked = false;
this.queue = [];
};
});

utils.inherits(LineBuffer, events.EventEmitter, {
// Events:
// line: here is a line
// done: all lines emitted

write: function(chunk) {
write(chunk) {
// find line or lines in chunk and emit them if not corked
// or queue them if corked
var data = this.buffer ? this.buffer + chunk : chunk;
var lines = data.split(/\r?\n/g);
const data = this.buffer ? this.buffer + chunk : chunk;
const lines = data.split(/\r?\n/g);

// save the last line
this.buffer = lines.pop();
Expand All @@ -40,33 +39,33 @@ utils.inherits(LineBuffer, events.EventEmitter, {

return !this.corked;
},
cork: function() {
cork() {
this.corked = true;
},
uncork: function() {
uncork() {
this.corked = false;
this._flush();

// tell the source I'm ready again
this.emit('drain');
},
setDefaultEncoding: function() {
setDefaultEncoding() {
// ?
},
end: function() {
end() {
if (this.buffer) {
this.emit('line', this.buffer);
this.buffer = null;
}
this.emit('done');
},

_flush: function() {
_flush() {
if (!this.corked) {
this.queue.forEach(function(line) {
this.emit('line', line);
});
this.queue = [];
}
}
},
});
Loading

0 comments on commit 83cf728

Please sign in to comment.