UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

16 lines (14 loc) 512 B
import FileSaver from 'file-saver'; /** * A function that saves a string into a downloadable file * The download will be a json file and will start automatically * @param content string to be saved * @param filename optional the name of the file to be saved */ export const downloadJson = (content: string, filename?: string) => { const blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); const date = new Date().toString(); FileSaver.saveAs(blob, filename || `${date}.json`); };