artoo.js’ save module enables you to download various things from JavaScript.
If your browser warns you about the webpage trying to download several items, just tell him it’s gonna be ok and you should not be bothered again.
Note: every methods below can take the same parameters object as artoo.save
. They are just not documented each time.
Download data according to given parameters. This function should only be used if the next functions cannot satisfy your needs.
// Basic signature
artoo.save(data, [params]);
// Alternative signature
artoo.save(data, [filename]);
Note that if the second argument is a string it will be considered as params.filename
. This is true for every othe save method.
Arguments
json
, csv
text
and html
.true
] : whether you want the blob URL created to download your file revoked afterwards.Dowload a JavaScript variable or a JSON string as a JSON file.
artoo.saveJson(data, [params]);
Additional parameters
false
] : should the ouput JSON file be pretty-printed?2
] : By how many spaces should we indent the JSON file?Example
artoo.saveJson({hello: world}, {filename: 'hello-world.json'});
Dowload a JavaScript variable or a JSON string as a pretty-printed JSON file.
artoo.savePrettyJson(data, [params]);
This is the same as doing
artoo.saveJson(data, {pretty: true});
Download an array of array, an array of objects or a string as a CSV file.
artoo.saveCsv(data, [params]);
Additional parameters
,
] : the field delimiter."
] : the escape character.data
.Example
var persons =[
{
firstname: 'Caroline',
lastname: 'Williams'
},
{
filename: 'Steven',
lastname: 'Douglas'
}
];
artoo.saveCsv(persons);
For more precisions, refer to the artoo.writers.csv method.
This method is an alias of the saveCsv
one and simply overrides the delimiter with \t
.
artoo.saveTsv(data, [params]);
Dowload a JavaScript variable as a YAML file.
artoo.saveYaml(data, [params]);
Download a XML file from a string, a jQuery selector or a DOM document.
artoo.saveXml(htmlData, [params]);
Examples
artoo.saveXml($('#a_div_id'), {filename: 'div.html'});
artoo.saveXml(document);
Download a SVG file from a jQuery selector.
artoo.saveSvg(svgData, [params]);
This method is an alias of artoo.saveXml
.
Download a HTML file from a string, a jQuery selector or a DOM document.
artoo.saveHtml(htmlData, [params]);
This method is an alias of artoo.saveXml
.
Download the page’s current Html.
artoo.savePageHtml([params]);
Save the content of the local storage as a JSON file. You can also alternatively select to download only the part corresponding to a key.
artoo.saveStore([params]);
Additional Parameters
Example
artoo.saveStore({key: 'your-needed-key'});
Save the resource located at the given url.
artoo.saveResource(url, [params]);
Example
artoo.saveResource('http://url-of-a-random-audio-file.mp3', {
filename: 'MyAwesomeMusic.mp3'
});
artoo.saveResource('/public/css/style.css');
Save an image corresponding either to a css or a jQuery selector.
artoo will name your file [alt-attribute].extension
by default if you do not provide a filename
parameter.
artoo.saveImage(selector, [params]);
Example
artoo.saveImage('#an_image_id');