Skip to content

Commit 6c963f8

Browse files
author
Philipp Alferov
committed
Build assets
1 parent 19b37e7 commit 6c963f8

File tree

4 files changed

+70
-20
lines changed

4 files changed

+70
-20
lines changed

dist/angular-file-saver.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,38 @@ angular
1717

1818
function SaveAs() {
1919

20-
function isBlobInstance (data) {
21-
return data instanceof Blob;
20+
function handleErrors (msg) {
21+
throw new Error(msg);
22+
}
23+
24+
function isArray (obj) {
25+
return Object.prototype.toString.call(obj) === '[object Array]';
26+
}
27+
28+
function isObject (obj) {
29+
return obj !== null && typeof obj === 'object';
30+
}
31+
32+
function isString (obj) {
33+
return typeof obj === 'string' || obj instanceof String;
34+
}
35+
36+
function isBlobInstance (obj) {
37+
return obj instanceof Blob;
2238
}
2339

2440
function save(blob, filename) {
2541
try {
2642
saveAs(blob, filename);
2743
} catch(err) {
28-
console.error(err.message);
44+
handleErrors(err.message);
2945
}
3046
}
3147

3248
return {
3349

3450
/**
35-
* saveFile - Immediately starts saving a file, returns undefined.
51+
* download - Immediately starts saving a file, returns undefined.
3652
*
3753
* @param {array|Blob} data Represented as an array or a Blob object
3854
* @param {string} filename
@@ -42,15 +58,24 @@ angular
4258
*/
4359

4460
download: function (data, filename, options) {
45-
var blob;
46-
data = data instanceof Array ? data : [data];
61+
if (!isArray(data) || !isBlobInstance(data)) {
62+
handleErrors('Data argument should be represented as an array or Blob instance');
63+
}
64+
65+
if (!isString(filename)) {
66+
handleErrors('Filename argument should be a string');
67+
}
68+
69+
if (!isObject(options)) {
70+
handleErrors('Options argument should be an object');
71+
}
4772

4873
if (isBlobInstance(data)) {
49-
save(data, filename);
74+
return save(data, filename);
5075
}
5176

52-
blob = new Blob(data, options);
53-
save(blob, filename);
77+
var blob = new Blob(data, options);
78+
return save(blob, filename);
5479
}
5580
};
5681
}

dist/angular-file-saver.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/examples.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28898,22 +28898,38 @@ angular
2889828898

2889928899
function SaveAs() {
2890028900

28901-
function isBlobInstance (data) {
28902-
return data instanceof Blob;
28901+
function handleErrors (msg) {
28902+
throw new Error(msg);
28903+
}
28904+
28905+
function isArray (obj) {
28906+
return Object.prototype.toString.call(obj) === '[object Array]';
28907+
}
28908+
28909+
function isObject (obj) {
28910+
return obj !== null && typeof obj === 'object';
28911+
}
28912+
28913+
function isString (obj) {
28914+
return typeof obj === 'string' || obj instanceof String;
28915+
}
28916+
28917+
function isBlobInstance (obj) {
28918+
return obj instanceof Blob;
2890328919
}
2890428920

2890528921
function save(blob, filename) {
2890628922
try {
2890728923
saveAs(blob, filename);
2890828924
} catch(err) {
28909-
console.error(err.message);
28925+
handleErrors(err.message);
2891028926
}
2891128927
}
2891228928

2891328929
return {
2891428930

2891528931
/**
28916-
* saveFile - Immediately starts saving a file, returns undefined.
28932+
* download - Immediately starts saving a file, returns undefined.
2891728933
*
2891828934
* @param {array|Blob} data Represented as an array or a Blob object
2891928935
* @param {string} filename
@@ -28923,15 +28939,24 @@ angular
2892328939
*/
2892428940

2892528941
download: function (data, filename, options) {
28926-
var blob;
28927-
data = data instanceof Array ? data : [data];
28942+
if (!isArray(data) || !isBlobInstance(data)) {
28943+
handleErrors('Data argument should be represented as an array or Blob instance');
28944+
}
28945+
28946+
if (!isString(filename)) {
28947+
handleErrors('Filename argument should be a string');
28948+
}
28949+
28950+
if (!isObject(options)) {
28951+
handleErrors('Options argument should be an object');
28952+
}
2892828953

2892928954
if (isBlobInstance(data)) {
28930-
save(data, filename);
28955+
return save(data, filename);
2893128956
}
2893228957

28933-
blob = new Blob(data, options);
28934-
save(blob, filename);
28958+
var blob = new Blob(data, options);
28959+
return save(blob, filename);
2893528960
}
2893628961
};
2893728962
}

docs/dist/examples.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)