|
| 1 | +'use strict'; |
| 2 | + |
1 | 3 | /* angular-file-saver |
2 | 4 | * |
3 | 5 | * A AngularJS service that implements the HTML5 W3C saveAs() in browsers that |
|
8 | 10 | * |
9 | 11 | */ |
10 | 12 |
|
11 | | -(function() { |
12 | | - 'use strict'; |
13 | | - |
14 | | - angular |
15 | | - .module('fileSaver', []) |
16 | | - .factory('SaveAs', SaveAs); |
| 13 | +angular |
| 14 | + .module('fileSaver', []) |
| 15 | + .factory('SaveAs', SaveAs); |
17 | 16 |
|
18 | | - function SaveAs() { |
| 17 | + function SaveAs() { |
19 | 18 |
|
20 | | - function isBlobInstance (data) { |
21 | | - return data instanceof Blob; |
22 | | - } |
| 19 | + function isBlobInstance (data) { |
| 20 | + return data instanceof Blob; |
| 21 | + } |
23 | 22 |
|
24 | | - function save(blob, filename) { |
25 | | - try { |
26 | | - saveAs(blob, filename); |
27 | | - } catch(err) { |
28 | | - console.error(err.message); |
29 | | - } |
| 23 | + function save(blob, filename) { |
| 24 | + try { |
| 25 | + saveAs(blob, filename); |
| 26 | + } catch(err) { |
| 27 | + console.error(err.message); |
30 | 28 | } |
| 29 | + } |
31 | 30 |
|
32 | | - return { |
33 | | - |
34 | | - /** |
35 | | - * saveFile - Immediately starts saving a file, returns undefined. |
36 | | - * |
37 | | - * @param {array|Blob} data Represented as an array or a Blob object |
38 | | - * @param {string} filename |
39 | | - * @param {object} options Set of Blob constructor options. |
40 | | - * Optional parameter, if Blob object is passed as first argument |
41 | | - * @return {undefined} |
42 | | - */ |
| 31 | + return { |
43 | 32 |
|
44 | | - download: function (data, filename, options) { |
45 | | - var blob; |
46 | | - data = data instanceof Array ? data : [data]; |
| 33 | + /** |
| 34 | + * saveFile - Immediately starts saving a file, returns undefined. |
| 35 | + * |
| 36 | + * @param {array|Blob} data Represented as an array or a Blob object |
| 37 | + * @param {string} filename |
| 38 | + * @param {object} options Set of Blob constructor options. |
| 39 | + * Optional parameter, if Blob object is passed as first argument |
| 40 | + * @return {undefined} |
| 41 | + */ |
47 | 42 |
|
48 | | - if (isBlobInstance(data)) { |
49 | | - save(data, filename); |
50 | | - } |
| 43 | + download: function (data, filename, options) { |
| 44 | + var blob; |
| 45 | + data = data instanceof Array ? data : [data]; |
51 | 46 |
|
52 | | - blob = new Blob(data, options); |
53 | | - save(blob, filename); |
| 47 | + if (isBlobInstance(data)) { |
| 48 | + save(data, filename); |
54 | 49 | } |
55 | | - }; |
56 | | - } |
57 | 50 |
|
58 | | -})(); |
| 51 | + blob = new Blob(data, options); |
| 52 | + save(blob, filename); |
| 53 | + } |
| 54 | + }; |
| 55 | + } |
0 commit comments