Skip to content

Instantly share code, notes, and snippets.

@liranh85
liranh85 / convert-to-csv-and-download.js
Created June 29, 2019 11:38
Utility functions to convert to CSV (using json2csv) and download the csv as a file
import JSON2CSV from 'json2csv';
export const convertToCSV = (arr: Array<any>) => {
const json2csvParser = new JSON2CSV.Parser();
const csv = json2csvParser.parse(arr);
return csv;
};
export const downloadCSV = (csv: string, fileName = 'download.csv') => {
var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
@liranh85
liranh85 / broadcast-channel-polyfill.js
Created June 29, 2019 11:17
A custom polyfill to BroadcastChannel, falling back on localStorage if not supported by the browser
(function BroadcastChannelPolyfill() {
if (!('BroadcastChannel' in window)) {
console.log('Using BroadcastChannel polyfill')
window.BroadcastChannel = function(name) {
this.channelName = name
this.onmessage = function() {}
var self = this
window.addEventListener("storage", function(event) {
// create-react-app v2.1.8, webpack.config.js, line 69
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
isEnvDevelopment && {
loader: require.resolve('style-loader'),
options: {
insertInto: () => document.getElementById('root').shadowRoot,
}
},
// ...