MCPcopy
hub / github.com/exceljs/exceljs / read

Method read

lib/csv/csv.js:43–98  ·  view source on GitHub ↗
(stream, options)

Source from the content-addressed store, hash-verified

41 }
42
43 read(stream, options) {
44 options = options || {};
45
46 return new Promise((resolve, reject) => {
47 const worksheet = this.workbook.addWorksheet(options.sheetName);
48
49 const dateFormats = options.dateFormats || [
50 'YYYY-MM-DD[T]HH:mm:ssZ',
51 'YYYY-MM-DD[T]HH:mm:ss',
52 'MM-DD-YYYY',
53 'YYYY-MM-DD',
54 ];
55 const map =
56 options.map ||
57 function(datum) {
58 if (datum === '') {
59 return null;
60 }
61 const datumNumber = Number(datum);
62 if (!Number.isNaN(datumNumber) && datumNumber !== Infinity) {
63 return datumNumber;
64 }
65 const dt = dateFormats.reduce((matchingDate, currentDateFormat) => {
66 if (matchingDate) {
67 return matchingDate;
68 }
69 const dayjsObj = dayjs(datum, currentDateFormat, true);
70 if (dayjsObj.isValid()) {
71 return dayjsObj;
72 }
73 return null;
74 }, null);
75 if (dt) {
76 return new Date(dt.valueOf());
77 }
78 const special = SpecialValues[datum];
79 if (special !== undefined) {
80 return special;
81 }
82 return datum;
83 };
84
85 const csvStream = fastCsv
86 .parse(options.parserOptions)
87 .on('data', data => {
88 worksheet.addRow(data.map(map));
89 })
90 .on('end', () => {
91 csvStream.emit('worksheet', worksheet);
92 });
93
94 csvStream.on('worksheet', resolve).on('error', reject);
95
96 stream.pipe(csvStream);
97 });
98 }
99
100 /**

Callers 1

readFileMethod · 0.95

Calls 7

onMethod · 0.80
emitMethod · 0.80
addRowMethod · 0.65
mapMethod · 0.65
addWorksheetMethod · 0.45
parseMethod · 0.45
pipeMethod · 0.45

Tested by

no test coverage detected