Skip to content

Commit 094cb1a

Browse files
committed
add native endings to the save method
1 parent ef2b6f1 commit 094cb1a

File tree

9 files changed

+18
-12
lines changed

9 files changed

+18
-12
lines changed

.DS_Store

6 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
Version 0.3.1 (May 11th 2022)
2+
-----------------------------
3+
- add native endings to the save method
4+
15
Version 0.3.0 (May 10th 2022)
26
-----------------------------
3-
- Added "save" option to get prompted on file save instead of a direct download
7+
- Add "save" option to get prompted on file save instead of a direct download
48

59
Version 0.2.5 (March 03rd 2021)
610
-----------------------------

dist/csvx.iife.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ var CSVx = (function (exports) {
941941
while (1) {
942942
switch (_context2.prev = _context2.next) {
943943
case 0:
944-
encodedTable = "data:" + this.options.data + ";charset=" + this.options.charset + "," + escape(table);
944+
encodedTable = table;
945945
_context2.next = 3;
946946
return window.showSaveFilePicker({
947947
suggestedName: filename + '.csv'
@@ -956,7 +956,8 @@ var CSVx = (function (exports) {
956956
fileStream = _context2.sent;
957957
_context2.next = 9;
958958
return fileStream.write(new Blob([encodedTable], {
959-
type: 'text/csv'
959+
type: this.options.data + ";charset=" + this.options.charset,
960+
endings: 'native'
960961
}));
961962

962963
case 9:

dist/csvx.iife.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/csvx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ class Export {
9292
}
9393
static save(table, filename) {
9494
return __awaiter(this, void 0, void 0, function* () {
95-
let encodedTable = `data:${this.options.data};charset=${this.options.charset},${escape(table)}`;
95+
let encodedTable = table;
9696
const fileHandle = yield window.showSaveFilePicker({
9797
suggestedName: filename + '.csv'
9898
});
9999
const fileStream = yield fileHandle.createWritable();
100-
yield fileStream.write(new Blob([encodedTable], { type: 'text/csv' }));
100+
yield fileStream.write(new Blob([encodedTable], { type: `${this.options.data};charset=${this.options.charset}`, endings: 'native' }));
101101
yield fileStream.close();
102102
});
103103
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dwtechs/csvx",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "CSV Export library written in TypeScript.",
55
"keywords": [],
66
"homepage": "https://github.com/DWTechs/CSVx.js",

src/export.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ export class Export {
7878
}
7979

8080
private static async save(table: string, filename: string ): Promise<void> {
81-
let encodedTable = `data:${this.options.data};charset=${this.options.charset},${escape(table)}`;
81+
let encodedTable = table;
8282
const fileHandle = await (window as any).showSaveFilePicker({
8383
suggestedName: filename+'.csv'
8484
});
8585
const fileStream = await fileHandle.createWritable();
86-
await fileStream.write(new Blob([encodedTable], { type: 'text/csv' }));
86+
await fileStream.write(new Blob([encodedTable], { type: `${this.options.data};charset=${this.options.charset}`, endings:'native' }));
8787
await fileStream.close();
8888
};
8989

web/js/csvx.iife.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ var CSVx = (function (exports) {
916916
while (1) {
917917
switch (_context2.prev = _context2.next) {
918918
case 0:
919-
encodedTable = "data:" + this.options.data + ";charset=" + this.options.charset + "," + escape(table);
919+
encodedTable = table;
920920
_context2.next = 3;
921921
return window.showSaveFilePicker({
922922
suggestedName: filename + '.csv'
@@ -931,7 +931,8 @@ var CSVx = (function (exports) {
931931
fileStream = _context2.sent;
932932
_context2.next = 9;
933933
return fileStream.write(new Blob([encodedTable], {
934-
type: 'text/csv'
934+
type: this.options.data + ";charset=" + this.options.charset,
935+
endings: 'native'
935936
}));
936937

937938
case 9:

web/js/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var customLabels = {
3030
};
3131
var exportButton = document.getElementById('csv');
3232
exportButton.addEventListener('click', function() {
33-
CSVx.Export.data('scientists',array, {separator:';', customLabels: customLabels });
33+
CSVx.Export.data('scientists',array, {separator:';', customLabels: customLabels, save: true });
3434
});
3535

3636
var data = '"Firstname";"Lastname";"Born";"Died"\r\n\

0 commit comments

Comments
 (0)