@alienkarma/exceljs 4.4.0-fork.5 → 4.4.0-fork.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,23 @@
1
- const fs = require('fs');
2
- const Archiver = require('archiver');
1
+ const fs = require("fs");
2
+ const Archiver = require("@alienkarma/archiver");
3
3
 
4
- const StreamBuf = require('../../utils/stream-buf');
4
+ const StreamBuf = require("../../utils/stream-buf");
5
5
 
6
- const RelType = require('../../xlsx/rel-type');
7
- const StylesXform = require('../../xlsx/xform/style/styles-xform');
8
- const SharedStrings = require('../../utils/shared-strings');
9
- const DefinedNames = require('../../doc/defined-names');
6
+ const RelType = require("../../xlsx/rel-type");
7
+ const StylesXform = require("../../xlsx/xform/style/styles-xform");
8
+ const SharedStrings = require("../../utils/shared-strings");
9
+ const DefinedNames = require("../../doc/defined-names");
10
10
 
11
- const CoreXform = require('../../xlsx/xform/core/core-xform');
12
- const RelationshipsXform = require('../../xlsx/xform/core/relationships-xform');
13
- const ContentTypesXform = require('../../xlsx/xform/core/content-types-xform');
14
- const AppXform = require('../../xlsx/xform/core/app-xform');
15
- const WorkbookXform = require('../../xlsx/xform/book/workbook-xform');
16
- const SharedStringsXform = require('../../xlsx/xform/strings/shared-strings-xform');
11
+ const CoreXform = require("../../xlsx/xform/core/core-xform");
12
+ const RelationshipsXform = require("../../xlsx/xform/core/relationships-xform");
13
+ const ContentTypesXform = require("../../xlsx/xform/core/content-types-xform");
14
+ const AppXform = require("../../xlsx/xform/core/app-xform");
15
+ const WorkbookXform = require("../../xlsx/xform/book/workbook-xform");
16
+ const SharedStringsXform = require("../../xlsx/xform/strings/shared-strings-xform");
17
17
 
18
- const WorksheetWriter = require('./worksheet-writer');
18
+ const WorksheetWriter = require("./worksheet-writer");
19
19
 
20
- const theme1Xml = require('../../xlsx/xml/theme1.js');
20
+ const theme1Xml = require("../../xlsx/xml/theme1.js");
21
21
 
22
22
  class WorkbookWriter {
23
23
  constructor(options) {
@@ -25,8 +25,8 @@ class WorkbookWriter {
25
25
 
26
26
  this.created = options.created || new Date();
27
27
  this.modified = options.modified || this.created;
28
- this.creator = options.creator || 'ExcelJS';
29
- this.lastModifiedBy = options.lastModifiedBy || 'ExcelJS';
28
+ this.creator = options.creator || "ExcelJS";
29
+ this.lastModifiedBy = options.lastModifiedBy || "ExcelJS";
30
30
  this.lastPrinted = options.lastPrinted;
31
31
 
32
32
  // using shared strings creates a smaller xlsx file but may use more memory
@@ -34,7 +34,9 @@ class WorkbookWriter {
34
34
  this.sharedStrings = new SharedStrings();
35
35
 
36
36
  // style manager
37
- this.styles = options.useStyles ? new StylesXform(true) : new StylesXform.Mock(true);
37
+ this.styles = options.useStyles
38
+ ? new StylesXform(true)
39
+ : new StylesXform.Mock(true);
38
40
 
39
41
  // defined names
40
42
  this._definedNames = new DefinedNames();
@@ -47,7 +49,7 @@ class WorkbookWriter {
47
49
  this.media = [];
48
50
  this.commentRefs = [];
49
51
 
50
- this.zip = Archiver('zip', this.zipOptions);
52
+ this.zip = Archiver("zip", this.zipOptions);
51
53
  if (options.stream) {
52
54
  this.stream = options.stream;
53
55
  } else if (options.filename) {
@@ -66,19 +68,19 @@ class WorkbookWriter {
66
68
  }
67
69
 
68
70
  _openStream(path) {
69
- const stream = new StreamBuf({bufSize: 65536, batch: true});
70
- this.zip.append(stream, {name: path});
71
- stream.on('finish', () => {
72
- stream.emit('zipped');
71
+ const stream = new StreamBuf({ bufSize: 65536, batch: true });
72
+ this.zip.append(stream, { name: path });
73
+ stream.on("finish", () => {
74
+ stream.emit("zipped");
73
75
  });
74
76
  return stream;
75
77
  }
76
78
 
77
79
  _commitWorksheets() {
78
- const commitWorksheet = function(worksheet) {
80
+ const commitWorksheet = function (worksheet) {
79
81
  if (!worksheet.committed) {
80
- return new Promise(resolve => {
81
- worksheet.stream.on('zipped', () => {
82
+ return new Promise((resolve) => {
83
+ worksheet.stream.on("zipped", () => {
82
84
  resolve();
83
85
  });
84
86
  worksheet.commit();
@@ -124,7 +126,10 @@ class WorkbookWriter {
124
126
 
125
127
  addImage(image) {
126
128
  const id = this.media.length;
127
- const medium = Object.assign({}, image, {type: 'image', name: `image${id}.${image.extension}`});
129
+ const medium = Object.assign({}, image, {
130
+ type: "image",
131
+ name: `image${id}.${image.extension}`,
132
+ });
128
133
  this.media.push(medium);
129
134
  return id;
130
135
  }
@@ -139,16 +144,20 @@ class WorkbookWriter {
139
144
  // in fact, it's even possible to switch it mid-sheet
140
145
  options = options || {};
141
146
  const useSharedStrings =
142
- options.useSharedStrings !== undefined ? options.useSharedStrings : this.useSharedStrings;
147
+ options.useSharedStrings !== undefined
148
+ ? options.useSharedStrings
149
+ : this.useSharedStrings;
143
150
 
144
151
  if (options.tabColor) {
145
152
  // eslint-disable-next-line no-console
146
- console.trace('tabColor option has moved to { properties: tabColor: {...} }');
153
+ console.trace(
154
+ "tabColor option has moved to { properties: tabColor: {...} }",
155
+ );
147
156
  options.properties = Object.assign(
148
157
  {
149
158
  tabColor: options.tabColor,
150
159
  },
151
- options.properties
160
+ options.properties,
152
161
  );
153
162
  }
154
163
 
@@ -176,44 +185,54 @@ class WorkbookWriter {
176
185
  if (id === undefined) {
177
186
  return this._worksheets.find(() => true);
178
187
  }
179
- if (typeof id === 'number') {
188
+ if (typeof id === "number") {
180
189
  return this._worksheets[id];
181
190
  }
182
- if (typeof id === 'string') {
183
- return this._worksheets.find(worksheet => worksheet && worksheet.name === id);
191
+ if (typeof id === "string") {
192
+ return this._worksheets.find(
193
+ (worksheet) => worksheet && worksheet.name === id,
194
+ );
184
195
  }
185
196
  return undefined;
186
197
  }
187
198
 
188
199
  addStyles() {
189
- return new Promise(resolve => {
190
- this.zip.append(this.styles.xml, {name: 'xl/styles.xml'});
200
+ return new Promise((resolve) => {
201
+ this.zip.append(this.styles.xml, { name: "xl/styles.xml" });
191
202
  resolve();
192
203
  });
193
204
  }
194
205
 
195
206
  addThemes() {
196
- return new Promise(resolve => {
197
- this.zip.append(theme1Xml, {name: 'xl/theme/theme1.xml'});
207
+ return new Promise((resolve) => {
208
+ this.zip.append(theme1Xml, { name: "xl/theme/theme1.xml" });
198
209
  resolve();
199
210
  });
200
211
  }
201
212
 
202
213
  addOfficeRels() {
203
- return new Promise(resolve => {
214
+ return new Promise((resolve) => {
204
215
  const xform = new RelationshipsXform();
205
216
  const xml = xform.toXml([
206
- {Id: 'rId1', Type: RelType.OfficeDocument, Target: 'xl/workbook.xml'},
207
- {Id: 'rId2', Type: RelType.CoreProperties, Target: 'docProps/core.xml'},
208
- {Id: 'rId3', Type: RelType.ExtenderProperties, Target: 'docProps/app.xml'},
217
+ { Id: "rId1", Type: RelType.OfficeDocument, Target: "xl/workbook.xml" },
218
+ {
219
+ Id: "rId2",
220
+ Type: RelType.CoreProperties,
221
+ Target: "docProps/core.xml",
222
+ },
223
+ {
224
+ Id: "rId3",
225
+ Type: RelType.ExtenderProperties,
226
+ Target: "docProps/app.xml",
227
+ },
209
228
  ]);
210
- this.zip.append(xml, {name: '/_rels/.rels'});
229
+ this.zip.append(xml, { name: "/_rels/.rels" });
211
230
  resolve();
212
231
  });
213
232
  }
214
233
 
215
234
  addContentTypes() {
216
- return new Promise(resolve => {
235
+ return new Promise((resolve) => {
217
236
  const model = {
218
237
  worksheets: this._worksheets.filter(Boolean),
219
238
  sharedStrings: this.sharedStrings,
@@ -222,60 +241,60 @@ class WorkbookWriter {
222
241
  };
223
242
  const xform = new ContentTypesXform();
224
243
  const xml = xform.toXml(model);
225
- this.zip.append(xml, {name: '[Content_Types].xml'});
244
+ this.zip.append(xml, { name: "[Content_Types].xml" });
226
245
  resolve();
227
246
  });
228
247
  }
229
248
 
230
249
  addMedia() {
231
250
  return Promise.all(
232
- this.media.map(medium => {
233
- if (medium.type === 'image') {
251
+ this.media.map((medium) => {
252
+ if (medium.type === "image") {
234
253
  const filename = `xl/media/${medium.name}`;
235
254
  if (medium.filename) {
236
- return this.zip.file(medium.filename, {name: filename});
255
+ return this.zip.file(medium.filename, { name: filename });
237
256
  }
238
257
  if (medium.buffer) {
239
- return this.zip.append(medium.buffer, {name: filename});
258
+ return this.zip.append(medium.buffer, { name: filename });
240
259
  }
241
260
  if (medium.base64) {
242
261
  const dataimg64 = medium.base64;
243
- const content = dataimg64.substring(dataimg64.indexOf(',') + 1);
244
- return this.zip.append(content, {name: filename, base64: true});
262
+ const content = dataimg64.substring(dataimg64.indexOf(",") + 1);
263
+ return this.zip.append(content, { name: filename, base64: true });
245
264
  }
246
265
  }
247
- throw new Error('Unsupported media');
248
- })
266
+ throw new Error("Unsupported media");
267
+ }),
249
268
  );
250
269
  }
251
270
 
252
271
  addApp() {
253
- return new Promise(resolve => {
272
+ return new Promise((resolve) => {
254
273
  const model = {
255
274
  worksheets: this._worksheets.filter(Boolean),
256
275
  };
257
276
  const xform = new AppXform();
258
277
  const xml = xform.toXml(model);
259
- this.zip.append(xml, {name: 'docProps/app.xml'});
278
+ this.zip.append(xml, { name: "docProps/app.xml" });
260
279
  resolve();
261
280
  });
262
281
  }
263
282
 
264
283
  addCore() {
265
- return new Promise(resolve => {
284
+ return new Promise((resolve) => {
266
285
  const coreXform = new CoreXform();
267
286
  const xml = coreXform.toXml(this);
268
- this.zip.append(xml, {name: 'docProps/core.xml'});
287
+ this.zip.append(xml, { name: "docProps/core.xml" });
269
288
  resolve();
270
289
  });
271
290
  }
272
291
 
273
292
  addSharedStrings() {
274
293
  if (this.sharedStrings.count) {
275
- return new Promise(resolve => {
294
+ return new Promise((resolve) => {
276
295
  const sharedStringsXform = new SharedStringsXform();
277
296
  const xml = sharedStringsXform.toXml(this.sharedStrings);
278
- this.zip.append(xml, {name: '/xl/sharedStrings.xml'});
297
+ this.zip.append(xml, { name: "/xl/sharedStrings.xml" });
279
298
  resolve();
280
299
  });
281
300
  }
@@ -285,17 +304,17 @@ class WorkbookWriter {
285
304
  addWorkbookRels() {
286
305
  let count = 1;
287
306
  const relationships = [
288
- {Id: `rId${count++}`, Type: RelType.Styles, Target: 'styles.xml'},
289
- {Id: `rId${count++}`, Type: RelType.Theme, Target: 'theme/theme1.xml'},
307
+ { Id: `rId${count++}`, Type: RelType.Styles, Target: "styles.xml" },
308
+ { Id: `rId${count++}`, Type: RelType.Theme, Target: "theme/theme1.xml" },
290
309
  ];
291
310
  if (this.sharedStrings.count) {
292
311
  relationships.push({
293
312
  Id: `rId${count++}`,
294
313
  Type: RelType.SharedStrings,
295
- Target: 'sharedStrings.xml',
314
+ Target: "sharedStrings.xml",
296
315
  });
297
316
  }
298
- this._worksheets.forEach(worksheet => {
317
+ this._worksheets.forEach((worksheet) => {
299
318
  if (worksheet) {
300
319
  worksheet.rId = `rId${count++}`;
301
320
  relationships.push({
@@ -305,16 +324,16 @@ class WorkbookWriter {
305
324
  });
306
325
  }
307
326
  });
308
- return new Promise(resolve => {
327
+ return new Promise((resolve) => {
309
328
  const xform = new RelationshipsXform();
310
329
  const xml = xform.toXml(relationships);
311
- this.zip.append(xml, {name: '/xl/_rels/workbook.xml.rels'});
330
+ this.zip.append(xml, { name: "/xl/_rels/workbook.xml.rels" });
312
331
  resolve();
313
332
  });
314
333
  }
315
334
 
316
335
  addWorkbook() {
317
- const {zip} = this;
336
+ const { zip } = this;
318
337
  const model = {
319
338
  worksheets: this._worksheets.filter(Boolean),
320
339
  definedNames: this._definedNames.model,
@@ -323,21 +342,21 @@ class WorkbookWriter {
323
342
  calcProperties: {},
324
343
  };
325
344
 
326
- return new Promise(resolve => {
345
+ return new Promise((resolve) => {
327
346
  const xform = new WorkbookXform();
328
347
  xform.prepare(model);
329
- zip.append(xform.toXml(model), {name: '/xl/workbook.xml'});
348
+ zip.append(xform.toXml(model), { name: "/xl/workbook.xml" });
330
349
  resolve();
331
350
  });
332
351
  }
333
352
 
334
353
  _finalize() {
335
354
  return new Promise((resolve, reject) => {
336
- this.stream.on('error', reject);
337
- this.stream.on('finish', () => {
355
+ this.stream.on("error", reject);
356
+ this.stream.on("finish", () => {
338
357
  resolve(this);
339
358
  });
340
- this.zip.on('error', reject);
359
+ this.zip.on("error", reject);
341
360
 
342
361
  this.zip.finalize();
343
362
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alienkarma/exceljs",
3
- "version": "4.4.0-fork.5",
3
+ "version": "4.4.0-fork.8",
4
4
  "description": "Excel Workbook Manager - Read and Write xlsx and csv Files.",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -96,16 +96,14 @@
96
96
  "pageSetup"
97
97
  ],
98
98
  "dependencies": {
99
- "archiver": "^7.0.1",
99
+ "@alienkarma/archiver": "^7.0.1-fork.2",
100
100
  "brace-expansion": "^2.0.2",
101
101
  "dayjs": "^1.8.34",
102
102
  "fast-csv": "^4.3.1",
103
- "glob": "^10.5.0",
104
103
  "jszip": "^3.10.1",
105
- "minimatch": "^10.2.1",
106
104
  "readable-stream": "^3.6.0",
107
105
  "saxes": "^5.0.1",
108
- "tmp": "^0.2.0",
106
+ "tmp": "^0.2.4",
109
107
  "unzipper": "^0.12.3",
110
108
  "uuid": "^8.3.0"
111
109
  },