Skip to content

Commit c0d76eb

Browse files
committed
0.1.1 - Fixed Picture.prototype, ExcelBuilder createFile() and createFileAsync() instanced instead of static, and typeof comparison bugs. Fixed and added TypeScript data types, switched all applicable string literals from single to double quotes.
1 parent 67ec7ee commit c0d76eb

34 files changed

+982
-921
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.1.0](N/A) - 2016-05-30
7+
### [0.1.1](N/A) - 2016-05-31
8+
#### Changed
9+
* Switched all applicable strings from single to double quotes
10+
* Added some missing and best guess data types
11+
12+
#### Fixed
13+
* Fixed some typeof comparison bugs
14+
* ExcelBuilder createFile() and createFileAsync() were mistakenly instance functions, now static
15+
* Picture prototype and constructor type are now correct
16+
* Workbook.Drawing interface had incorrect type
17+
* Workbook.addMedia() 'contentType' is now correctly optional
18+
19+
20+
--------
21+
### [0.1.0](https://github.com/TeamworkGuy2/excel-builder-ts/commit/67ec7eedbcb88d43ac4ad1c02130183c8b8126ef) - 2016-05-30
822
#### Added
923
Initial commit of TypeScript port of the [excel-builder.js](https://github.com/stephenliberty/excel-builder.js) library.
1024

Drawings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var Drawings = (function () {
88
function Drawings() {
99
this.drawings = [];
1010
this.relations = new RelationshipManager();
11-
this.id = Util._uniqueId('Drawings');
11+
this.id = Util._uniqueId("Drawings");
1212
}
1313
/**
1414
* Adds a drawing (more likely a subclass of a Drawing) to the 'Drawings' for a particular worksheet.
@@ -22,10 +22,10 @@ var Drawings = (function () {
2222
return this.drawings.length;
2323
};
2424
Drawings.prototype.toXML = function () {
25-
var doc = Util.createXmlDoc(Util.schemas.spreadsheetDrawing, 'xdr:wsDr');
25+
var doc = Util.createXmlDoc(Util.schemas.spreadsheetDrawing, "xdr:wsDr");
2626
var drawingsElem = doc.documentElement;
2727
//drawings.setAttribute('xmlns:xdr', util.schemas.spreadsheetDrawing);
28-
drawingsElem.setAttribute('xmlns:a', Util.schemas.drawing);
28+
drawingsElem.setAttribute("xmlns:a", Util.schemas.drawing);
2929
var existingRelationships = {};
3030
for (var i = 0, l = this.drawings.length; i < l; i++) {
3131
var rId = this.relations.getRelationshipId(this.drawings[i].getMediaData());

Drawings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Drawings {
1414
constructor() {
1515
this.drawings = [];
1616
this.relations = new RelationshipManager();
17-
this.id = Util._uniqueId('Drawings');
17+
this.id = Util._uniqueId("Drawings");
1818
}
1919

2020

@@ -23,7 +23,7 @@ class Drawings {
2323
*
2424
* @param {Drawing} drawing
2525
*/
26-
public addDrawing(drawing) {
26+
public addDrawing(drawing: Drawings.Drawing) {
2727
this.drawings.push(drawing);
2828
}
2929

@@ -34,10 +34,10 @@ class Drawings {
3434

3535

3636
public toXML() {
37-
var doc = Util.createXmlDoc(Util.schemas.spreadsheetDrawing, 'xdr:wsDr');
37+
var doc = Util.createXmlDoc(Util.schemas.spreadsheetDrawing, "xdr:wsDr");
3838
var drawingsElem = doc.documentElement;
3939
//drawings.setAttribute('xmlns:xdr', util.schemas.spreadsheetDrawing);
40-
drawingsElem.setAttribute('xmlns:a', Util.schemas.drawing);
40+
drawingsElem.setAttribute("xmlns:a", Util.schemas.drawing);
4141

4242
var existingRelationships = {};
4343

ExcelBuilder.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ var ExcelBuilder = (function () {
2121
/** Turns a workbook into a downloadable file.
2222
* @param {Excel/Workbook} workbook The workbook that is being converted
2323
* @param {Object} options
24-
* @param {Boolean} options.base64 Whether to 'return' the generated file as a base64 string
24+
* @param {boolean} options.base64 Whether to 'return' the generated file as a base64 string
2525
* @param {Function} options.success The callback function to run after workbook creation is successful.
2626
* @param {Function} options.error The callback function to run if there is an error creating the workbook.
27-
* @param {String} options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
27+
* @param {string} options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
2828
*/
29-
ExcelBuilder.prototype.createFileAsync = function (workbook, options, jszipPath, zipWorkerPath, worksheetExportWorkerPath) {
29+
ExcelBuilder.createFileAsync = function (workbook, options, jszipPath, zipWorkerPath, worksheetExportWorkerPath) {
3030
workbook.generateFilesAsync({
3131
requireJsPath: options.requireJsPath,
3232
success: function (files) {
3333
var worker = new Worker(zipWorkerPath); //require.toUrl('./Excel/ZipWorker.js')
34-
worker.addEventListener('message', function (event, data) {
35-
if (event.data.status == 'done') {
34+
worker.addEventListener("message", function (event) {
35+
if (event.data.status == "done") {
3636
options.success(event.data.data);
3737
}
3838
});
@@ -48,16 +48,17 @@ var ExcelBuilder = (function () {
4848
}, worksheetExportWorkerPath);
4949
};
5050
/** Turns a workbook into a downloadable file.
51+
* @param {JSZip} jszip A JSZip equivalent library to use to generate/zip the excel file
5152
* @param {Excel/Workbook} workbook The workbook that is being converted
5253
* @param {Object} options - options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
5354
*/
54-
ExcelBuilder.prototype.createFile = function (jszip, workbook, options) {
55+
ExcelBuilder.createFile = function (jszip, workbook, options) {
5556
var zip = new jszip();
5657
var files = workbook.generateFiles();
5758
Object.keys(files).forEach(function (path) {
5859
var content = files[path];
5960
path = path.substr(1);
60-
if (path.indexOf('.xml') !== -1 || path.indexOf('.rel') !== -1) {
61+
if (path.indexOf(".xml") !== -1 || path.indexOf(".rel") !== -1) {
6162
zip.file(path, content, { base64: false });
6263
}
6364
else {

ExcelBuilder.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ class ExcelBuilder {
2323
/** Turns a workbook into a downloadable file.
2424
* @param {Excel/Workbook} workbook The workbook that is being converted
2525
* @param {Object} options
26-
* @param {Boolean} options.base64 Whether to 'return' the generated file as a base64 string
26+
* @param {boolean} options.base64 Whether to 'return' the generated file as a base64 string
2727
* @param {Function} options.success The callback function to run after workbook creation is successful.
2828
* @param {Function} options.error The callback function to run if there is an error creating the workbook.
29-
* @param {String} options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
29+
* @param {string} options.requireJsPath (Optional) The path to requirejs. Will use the id 'requirejs' to look up the script if not specified.
3030
*/
31-
public createFileAsync(workbook: Workbook, options: { base64: boolean; error: () => void; requireJsPath?: string; success: (data: any) => void; }, jszipPath: string, zipWorkerPath: string, worksheetExportWorkerPath: string) {
31+
static createFileAsync(workbook: Workbook, options: { base64: boolean; error: () => void; requireJsPath?: string; success: (data: any) => void; }, jszipPath: string, zipWorkerPath: string, worksheetExportWorkerPath: string) {
3232

3333
workbook.generateFilesAsync({
3434
requireJsPath: options.requireJsPath,
3535
success: function (files) {
3636
var worker = new Worker(zipWorkerPath); //require.toUrl('./Excel/ZipWorker.js')
37-
worker.addEventListener('message', <any>function (event, data) {
38-
if (event.data.status == 'done') {
37+
worker.addEventListener("message", <any>function (event: MessageEvent) {
38+
if (event.data.status == "done") {
3939
options.success(event.data.data);
4040
}
4141
});
@@ -53,16 +53,17 @@ class ExcelBuilder {
5353

5454

5555
/** Turns a workbook into a downloadable file.
56+
* @param {JSZip} jszip A JSZip equivalent library to use to generate/zip the excel file
5657
* @param {Excel/Workbook} workbook The workbook that is being converted
5758
* @param {Object} options - options to modify how the excel doc is created. Only accepts a base64 boolean at the moment.
5859
*/
59-
public createFile(jszip: typeof JSZip, workbook: Workbook, options?: { base64?: boolean; }) {
60+
static createFile(jszip: typeof JSZip, workbook: Workbook, options?: { base64?: boolean; }) {
6061
var zip = new jszip();
6162
var files = workbook.generateFiles();
6263
Object.keys(files).forEach(function (path) {
6364
var content = files[path];
6465
path = path.substr(1);
65-
if (path.indexOf('.xml') !== -1 || path.indexOf('.rel') !== -1) {
66+
if (path.indexOf(".xml") !== -1 || path.indexOf(".rel") !== -1) {
6667
zip.file(path, content, { base64: false });
6768
} else {
6869
zip.file(path, content, { base64: true, binary: true });

RelationshipManager.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var Paths = require("./Paths");
77
var RelationshipManager = (function () {
88
function RelationshipManager() {
99
this.Cctor = (function () {
10-
Util._uniqueId('rId'); //priming
10+
Util._uniqueId("rId"); //priming
1111
}());
1212
this.relations = {};
1313
this.lastId = 1;
@@ -24,7 +24,7 @@ var RelationshipManager = (function () {
2424
};
2525
RelationshipManager.prototype.addRelation = function (object, type) {
2626
var newRelation = this.relations[object.id] = {
27-
id: Util._uniqueId('rId'),
27+
id: Util._uniqueId("rId"),
2828
schema: Util.schemas[type]
2929
};
3030
return newRelation.id;
@@ -33,15 +33,15 @@ var RelationshipManager = (function () {
3333
return this.relations[object.id] ? this.relations[object.id].id : null;
3434
};
3535
RelationshipManager.prototype.toXML = function () {
36-
var doc = Util.createXmlDoc(Util.schemas.relationshipPackage, 'Relationships');
36+
var doc = Util.createXmlDoc(Util.schemas.relationshipPackage, "Relationships");
3737
var relationships = doc.documentElement;
3838
var rels = this.relations;
3939
Object.keys(rels).forEach(function (id) {
4040
var data = rels[id];
41-
var relationship = Util.createElement(doc, 'Relationship', [
42-
['Id', data.id],
43-
['Type', data.schema],
44-
['Target', Paths[id]]
41+
var relationship = Util.createElement(doc, "Relationship", [
42+
["Id", data.id],
43+
["Type", data.schema],
44+
["Target", Paths[id]]
4545
]);
4646
relationships.appendChild(relationship);
4747
});

RelationshipManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Paths = require("./Paths");
77
class RelationshipManager {
88

99
private Cctor = (function () {
10-
Util._uniqueId('rId'); //priming
10+
Util._uniqueId("rId"); //priming
1111
}());
1212

1313

@@ -37,7 +37,7 @@ class RelationshipManager {
3737

3838
public addRelation(object: { id: string; schema?: string; }, type: string) {
3939
var newRelation = this.relations[object.id] = {
40-
id: Util._uniqueId('rId'),
40+
id: Util._uniqueId("rId"),
4141
schema: Util.schemas[type]
4242
};
4343
return newRelation.id;
@@ -50,16 +50,16 @@ class RelationshipManager {
5050

5151

5252
public toXML() {
53-
var doc = Util.createXmlDoc(Util.schemas.relationshipPackage, 'Relationships');
53+
var doc = Util.createXmlDoc(Util.schemas.relationshipPackage, "Relationships");
5454
var relationships = doc.documentElement;
5555

5656
var rels = this.relations;
5757
Object.keys(rels).forEach((id) => {
5858
var data = rels[id];
59-
var relationship = Util.createElement(doc, 'Relationship', [
60-
['Id', data.id],
61-
['Type', data.schema],
62-
['Target', Paths[id]]
59+
var relationship = Util.createElement(doc, "Relationship", [
60+
["Id", data.id],
61+
["Type", data.schema],
62+
["Target", Paths[id]]
6363
]);
6464
relationships.appendChild(relationship);
6565
});

SharedStrings.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var SharedStrings = (function () {
77
function SharedStrings() {
88
this.strings = {};
99
this.stringArray = [];
10-
this.id = Util._uniqueId('SharedStrings');
10+
this.id = Util._uniqueId("SharedStrings");
1111
}
1212
/** Adds a string to the shared string file, and returns the ID of the
1313
* string which can be used to reference it in worksheets.
@@ -24,15 +24,15 @@ var SharedStrings = (function () {
2424
return this.strings;
2525
};
2626
SharedStrings.prototype.toXML = function () {
27-
var doc = Util.createXmlDoc(Util.schemas.spreadsheetml, 'sst');
27+
var doc = Util.createXmlDoc(Util.schemas.spreadsheetml, "sst");
2828
var sharedStringTable = doc.documentElement;
2929
this.stringArray.reverse();
3030
var l = this.stringArray.length;
31-
sharedStringTable.setAttribute('count', l);
32-
sharedStringTable.setAttribute('uniqueCount', l);
33-
var template = doc.createElement('si');
34-
var templateValue = doc.createElement('t');
35-
templateValue.appendChild(doc.createTextNode('--placeholder--'));
31+
sharedStringTable.setAttribute("count", l);
32+
sharedStringTable.setAttribute("uniqueCount", l);
33+
var template = doc.createElement("si");
34+
var templateValue = doc.createElement("t");
35+
templateValue.appendChild(doc.createTextNode("--placeholder--"));
3636
template.appendChild(templateValue);
3737
var strings = this.stringArray;
3838
while (l--) {

SharedStrings.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SharedStrings {
1313
constructor() {
1414
this.strings = {};
1515
this.stringArray = [];
16-
this.id = Util._uniqueId('SharedStrings');
16+
this.id = Util._uniqueId("SharedStrings");
1717
}
1818

1919

@@ -36,16 +36,16 @@ class SharedStrings {
3636

3737

3838
public toXML() {
39-
var doc = Util.createXmlDoc(Util.schemas.spreadsheetml, 'sst');
39+
var doc = Util.createXmlDoc(Util.schemas.spreadsheetml, "sst");
4040
var sharedStringTable = doc.documentElement;
4141
this.stringArray.reverse();
4242
var l = this.stringArray.length;
43-
sharedStringTable.setAttribute('count', l);
44-
sharedStringTable.setAttribute('uniqueCount', l);
43+
sharedStringTable.setAttribute("count", l);
44+
sharedStringTable.setAttribute("uniqueCount", l);
4545

46-
var template = doc.createElement('si');
47-
var templateValue = doc.createElement('t');
48-
templateValue.appendChild(doc.createTextNode('--placeholder--'));
46+
var template = doc.createElement("si");
47+
var templateValue = doc.createElement("t");
48+
templateValue.appendChild(doc.createTextNode("--placeholder--"));
4949
template.appendChild(templateValue);
5050
var strings = this.stringArray;
5151

0 commit comments

Comments
 (0)