Skip to content

Commit

Permalink
Fix safari download
Browse files Browse the repository at this point in the history
  • Loading branch information
gion committed Oct 10, 2018
1 parent dbc0467 commit 3ded01f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const isSafari = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

export const isJsons = ((array) => Array.isArray(array) && array.every(
row => (typeof row === 'object' && !(row instanceof Array))
));
Expand Down Expand Up @@ -53,12 +55,14 @@ export const toCSV = (data, headers, separator) => {

export const buildURI = ((data, uFEFF, headers, separator) => {
const csv = toCSV(data, headers, separator);
const blob = new Blob([uFEFF ? '\uFEFF' : '', csv], {type: 'text/csv'});
const dataURI = `data:text/csv;charset=utf-8,${uFEFF ? '\uFEFF' : ''}${csv}`;
const type = isSafari() ? 'application/csv' : 'text/csv';
const blob = new Blob([uFEFF ? '\uFEFF' : '', csv], {type});
const dataURI = `data:${type};charset=utf-8,${uFEFF ? '\uFEFF' : ''}${csv}`;

const URL = window.URL || window.webkitURL;

return (typeof URL.createObjectURL === 'undefined')
? dataURI
: URL.createObjectURL(blob);
});
});

0 comments on commit 3ded01f

Please sign in to comment.