Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Run lint:fix and replace remaining var by hand
  • Loading branch information
alubbe committed Jan 18, 2019
commit cee23d41ead1931cfe800680400a1d59a49b708c
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
124 changes: 61 additions & 63 deletions lib/csv/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@

'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 @@ -34,89 +33,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);

var dateFormats = options.dateFormats || [
moment.ISO_8601,
'MM-DD-YYYY',
'YYYY-MM-DD'
];
var map = options.map || function(datum) {
const worksheet = this.workbook.addWorksheet(options.sheetName);

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 @@ -128,7 +129,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 @@ -140,16 +141,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 @@ -158,22 +159,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
Expand Up @@ -6,12 +6,11 @@

'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 @@ -20,18 +19,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 @@ -46,33 +45,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