Save a JavaScript object, value, or JSON string to a file in browser environment.
npm install save-as-json
import saveAsJSON from 'save-as-json';
const data = { key: 'value' };
// Default options
const options = {
filename: '%timestamp',
isJSON: false,
replacer: null,
space: 0,
};
saveAsJSON(data, options);
A string or number value.
- %timestamp -
Date.now()
- %title -
document.title
- %date - yyyymmdd
- %time - hhmmss
Set to true
if data
is already a JSON string.
JSON.stringify()
parameters.