Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ export const toCSV = (data, headers, separator) => {
throw new TypeError(`Data should be a "String", "Array of arrays" OR "Array of objects" `);
};

export const buildURI = ((data, uFEFF, headers, separator) => encodeURI(
`data:text/csv;charset=utf-8,${uFEFF ? '\uFEFF' : ''}${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 URL = window.URL || window.webkitURL;

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