Skip to content

Commit c787644

Browse files
author
Philipp Alferov
committed
Update readme & examples
1 parent a3bb38d commit c787644

File tree

5 files changed

+50
-42
lines changed

5 files changed

+50
-42
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ saveAs() FileSaver interface in browsers that do not natively support it.
1111
- [FileSaver.js](https://github.com/eligrey/FileSaver.js/)
1212
- [Blob.js](https://github.com/eligrey/Blob.js/)
1313

14-
## Installation
14+
File `dist/angular-file-saver.bundle.js` contains all required dependencies and
15+
grants access to both `Blob.js` and `FileSaver.js` polyfills via `Blob` and
16+
`SaveAs` services.
17+
18+
## Installationand grants access to both `Blob.js` and `FileSaver.js`
19+
polyfills via `Blob` and `SaveAs` services
1520
Using bower:
1621
```
1722
$ bower install angular-file-saver
@@ -21,20 +26,20 @@ Using npm:
2126
$ npm install angular-file-saver
2227
```
2328

24-
`dist/angular-file-saver.bundle.js` contains all required dependencies and grants access to both `Blob.js` and `FileSaver.js` polyfills via `Blob` and `SaveAs` services (include `ngFileSaver` module as a dependency first).
25-
2629
## Basic usage
2730
- Include the `ngFileSaver` module to your project;
28-
- Pass `FileSaver` service as a dependency;
29-
- Invoke `FileSaver.saveAs` and pass an object with the following set of options:
30-
- `data` - data, represented as an array or a [Blob object](https://developer.mozilla.org/en/docs/Web/API/Blob);
31+
- Pass both `FileSaver` and `Blob` services as dependencies;
32+
- Create a [Blob object](https://developer.mozilla.org/en/docs/Web/API/Blob)
33+
passing an array with data as a first argument and an object with set of options
34+
as the second one: `new Blob(['text'], { type: 'text/plain;charset=utf-8' })`;
35+
- Invoke `FileSaver.saveAs` with the following arguments:
36+
- `data` - a Blob object instance;
3137
- `filename`;
32-
- `options` - a set of options for the [Blob constructor](https://developer.mozilla.org/en/docs/Web/API/Blob)(optional attribute);
3338

3439
## Example
3540
**JS**
3641
```
37-
function ExampleCtrl(FileSaver) {
42+
function ExampleCtrl(FileSaver, Blob) {
3843
var vm = this;
3944
4045
vm.val = {
@@ -43,12 +48,11 @@ function ExampleCtrl(FileSaver) {
4348
4449
vm.download = function(text) {
4550
51+
var data = new Blob(['text'], { type: 'text/plain;charset=utf-8' });
52+
4653
var config = {
47-
data: [text],
48-
filename: 'textfile.txt',
49-
options: {
50-
type: 'text/plain;charset=utf-8'
51-
}
54+
data: data,
55+
filename: 'textfile.txt'
5256
};
5357
5458
FileSaver.saveAs(config);
@@ -57,7 +61,7 @@ function ExampleCtrl(FileSaver) {
5761
5862
angular
5963
.module('fileSaverExample', ['ngFileSaver'])
60-
.controller('ExampleCtrl', [FileSaver', ExampleCtrl]);
64+
.controller('ExampleCtrl', ['FileSaver', 'Blob', ExampleCtrl]);
6165
```
6266

6367
**HTML**

docs/assets/js/custom.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
'use strict'
1+
'use strict';
2+
23
var angular = require('angular');
34
require('../../../src/angular-file-saver-bundle.module');
45

@@ -11,12 +12,11 @@ function DownloadText(FileSaver) {
1112

1213
vm.download = function(text) {
1314

15+
var data = new Blob([text], { type: 'text/plain;charset=utf-8' });
16+
1417
var config = {
15-
data: [text],
16-
filename: 'textfile.txt',
17-
options: {
18-
type: 'text/plain;charset=utf-8'
19-
}
18+
data: data,
19+
filename: 'textfile.txt'
2020
};
2121

2222
FileSaver.saveAs(config);

docs/dist/examples.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2-
'use strict'
2+
'use strict';
3+
34
var angular = require('angular');
45
require('../../../src/angular-file-saver-bundle.module');
56

@@ -12,12 +13,11 @@ function DownloadText(FileSaver) {
1213

1314
vm.download = function(text) {
1415

16+
var data = new Blob([text], { type: 'text/plain;charset=utf-8' });
17+
1518
var config = {
16-
data: [text],
17-
filename: 'textfile.txt',
18-
options: {
19-
type: 'text/plain;charset=utf-8'
20-
}
19+
data: data,
20+
filename: 'textfile.txt'
2121
};
2222

2323
FileSaver.saveAs(config);

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.

docs/index.html

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,31 @@ <h2 id="dependencies">Dependencies</h2>
3333
<li><a href="https://github.com/eligrey/FileSaver.js/">FileSaver.js</a></li>
3434
<li><a href="https://github.com/eligrey/Blob.js/">Blob.js</a></li>
3535
</ul>
36-
<h2 id="installation">Installation</h2>
37-
<p>Using bower:</p>
36+
<p>File <code>dist/angular-file-saver.bundle.js</code> contains all required dependencies and
37+
grants access to both <code>Blob.js</code> and <code>FileSaver.js</code> polyfills via <code>Blob</code> and
38+
<code>SaveAs</code> services.</p>
39+
<h2 id="installationand-grants-access-to-both-blob-js-and-filesaver-js-">Installationand grants access to both <code>Blob.js</code> and <code>FileSaver.js</code></h2>
40+
<p>polyfills via <code>Blob</code> and <code>SaveAs</code> services
41+
Using bower:</p>
3842
<pre><code>$ bower install angular-file-saver
3943
</code></pre><p>Using npm:</p>
4044
<pre><code>$ npm install angular-file-saver
41-
</code></pre><p><code>dist/angular-file-saver.bundle.js</code> contains all required dependencies and grants access to both <code>Blob.js</code> and <code>FileSaver.js</code> polyfills via <code>Blob</code> and <code>SaveAs</code> services (include <code>ngFileSaver</code> module as a dependency first).</p>
42-
<h2 id="basic-usage">Basic usage</h2>
45+
</code></pre><h2 id="basic-usage">Basic usage</h2>
4346
<ul>
4447
<li>Include the <code>ngFileSaver</code> module to your project;</li>
45-
<li>Pass <code>FileSaver</code> service as a dependency;</li>
46-
<li>Invoke <code>FileSaver.saveAs</code> and pass an object with the following set of options:<ul>
47-
<li><code>data</code> - data, represented as an array or a <a href="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob object</a>;</li>
48+
<li>Pass both <code>FileSaver</code> and <code>Blob</code> services as dependencies;</li>
49+
<li>Create a <a href="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob object</a>
50+
passing an array with data as a first argument and an object with set of options
51+
as the second one: <code>new Blob([&#39;text&#39;], { type: &#39;text/plain;charset=utf-8&#39; })</code>;</li>
52+
<li>Invoke <code>FileSaver.saveAs</code> with the following arguments:<ul>
53+
<li><code>data</code> - a Blob object instance;</li>
4854
<li><code>filename</code>;</li>
49-
<li><code>options</code> - a set of options for the <a href="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob constructor</a>(optional attribute);</li>
5055
</ul>
5156
</li>
5257
</ul>
5358
<h2 id="example">Example</h2>
5459
<p><strong>JS</strong></p>
55-
<pre><code>function ExampleCtrl(FileSaver) {
60+
<pre><code>function ExampleCtrl(FileSaver, Blob) {
5661
var vm = this;
5762

5863
vm.val = {
@@ -61,12 +66,11 @@ <h2 id="example">Example</h2>
6166

6267
vm.download = function(text) {
6368

69+
var data = new Blob([&#39;text&#39;], { type: &#39;text/plain;charset=utf-8&#39; });
70+
6471
var config = {
65-
data: [text],
66-
filename: &#39;textfile.txt&#39;,
67-
options: {
68-
type: &#39;text/plain;charset=utf-8&#39;
69-
}
72+
data: data,
73+
filename: &#39;textfile.txt&#39;
7074
};
7175

7276
FileSaver.saveAs(config);
@@ -75,7 +79,7 @@ <h2 id="example">Example</h2>
7579

7680
angular
7781
.module(&#39;fileSaverExample&#39;, [&#39;ngFileSaver&#39;])
78-
.controller(&#39;ExampleCtrl&#39;, [FileSaver&#39;, ExampleCtrl]);
82+
.controller(&#39;ExampleCtrl&#39;, [&#39;FileSaver&#39;, &#39;Blob&#39;, ExampleCtrl]);
7983
</code></pre><p><strong>HTML</strong></p>
8084
<pre><code>&lt;div class=&quot;wrapper&quot; ng-controller=&quot;ExampleCtrl as vm&quot;&gt;
8185
&lt;textarea

0 commit comments

Comments
 (0)