Skip to content

Commit f2ee707

Browse files
author
Philipp Alferov
committed
😇 Eslintify
1 parent 58e1c03 commit f2ee707

File tree

2 files changed

+79
-80
lines changed

2 files changed

+79
-80
lines changed

gulpfile.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*jslint node: true */
21
'use strict';
32
var gulp = require('gulp');
43
var $ = require('gulp-load-plugins')();
@@ -13,7 +12,7 @@ var spawn = require('child_process').spawn;
1312

1413
var config = {
1514
fileSaver: {
16-
scripts: './src/*.js',
15+
scripts: './src/*.js'
1716
},
1817
docs: {
1918
src: './docs/src',
@@ -70,7 +69,7 @@ function getUpdateType() {
7069
}
7170

7271
function getPackageJsonVersion() {
73-
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
72+
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
7473
}
7574

7675
/*
@@ -84,15 +83,7 @@ function buildScript() {
8483
cache: {},
8584
packageCache: {},
8685
fullPaths: false
87-
}, watchify.args);
88-
89-
// Watch files for changes and only rebuilds what it needs to
90-
if (!config.isProd) {
91-
bundler = watchify(bundler);
92-
bundler.on('update', function() {
93-
rebundle();
94-
});
95-
}
86+
});
9687

9788
function rebundle() {
9889
var stream = bundler.bundle();
@@ -114,6 +105,14 @@ function buildScript() {
114105
.pipe($.if(browserSync.active, browserSync.stream()));
115106
}
116107

108+
// Watch files for changes and only rebuilds what it needs to
109+
if (!config.isProd) {
110+
bundler = watchify(bundler);
111+
bundler.on('update', function() {
112+
rebundle();
113+
});
114+
}
115+
117116
return rebundle();
118117
}
119118

@@ -131,12 +130,12 @@ gulp.task('styles:docs', function() {
131130
.pipe($.if(browserSync.active, browserSync.stream()));
132131
});
133132

134-
gulp.task('serve', function () {
133+
gulp.task('serve', function() {
135134

136135
browserSync({
137136
port: config.browserSync.port,
138137
server: {
139-
baseDir: config.browserSync.server,
138+
baseDir: config.browserSync.server
140139
},
141140
logConnections: true,
142141
logFileChanges: true,
@@ -175,7 +174,7 @@ gulp.task('dev:docs', function() {
175174
});
176175

177176
gulp.task('watch:docs', ['serve'], function() {
178-
gulp.watch(config.docs.styles, ['styles:docs']);
177+
gulp.watch(config.docs.styles, ['styles:docs']);
179178
});
180179

181180
gulp.task('release:bump', function() {
@@ -185,22 +184,22 @@ gulp.task('release:bump', function() {
185184
.pipe(gulp.dest('./'));
186185
});
187186

188-
gulp.task('release:commit', ['release:bump'], function (cb) {
187+
gulp.task('release:commit', ['release:bump'], function(cb) {
189188
var version = getPackageJsonVersion();
190189

191190
return gulp.src('.')
192191
.pipe($.git.add())
193192
.pipe($.git.commit(':octocat: Bump to ' + version, cb));
194193
});
195194

196-
gulp.task('release:push', ['release:bump', 'release:commit'], function (cb) {
197-
return $.git.push('origin', 'master', cb);
195+
gulp.task('release:push', ['release:bump', 'release:commit'], function(cb) {
196+
return $.git.push('origin', 'master', cb);
198197
});
199198

200-
gulp.task('release:tag', ['release:bump', 'release:commit', 'release:push'], function (cb) {
199+
gulp.task('release:tag', ['release:bump', 'release:commit', 'release:push'], function(cb) {
201200
var version = getPackageJsonVersion();
202201

203-
return $.git.tag(version, 'Tag: ' + version, function (err) {
202+
return $.git.tag(version, 'Tag: ' + version, function(err) {
204203
if (err) {
205204
return cb(err);
206205
}
@@ -221,7 +220,7 @@ gulp.task('unit', function() {
221220
});
222221
});
223222

224-
gulp.task('release:npm', ['release:bump', 'release:commit', 'release:push', 'release:tag'], function (done) {
223+
gulp.task('release:npm', ['release:bump', 'release:commit', 'release:push', 'release:tag'], function(done) {
225224
spawn('npm', ['publish'], { stdio: 'inherit' }).on('close', done);
226225
});
227226

src/angular-file-saver.js

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,85 +10,85 @@
1010
*
1111
*/
1212

13-
function handleErrors (msg) {
13+
function handleErrors(msg) {
1414
throw new Error(msg);
1515
}
1616

17-
function isArray (obj) {
17+
function isArray(obj) {
1818
return Object.prototype.toString.call(obj) === '[object Array]';
1919
}
2020

21-
function isObject (obj) {
21+
function isObject(obj) {
2222
return obj !== null && typeof obj === 'object';
2323
}
2424

25-
function isString (obj) {
25+
function isString(obj) {
2626
return typeof obj === 'string' || obj instanceof String;
2727
}
2828

29-
function isUndefined (obj) {
30-
return typeof obj == "undefined";
29+
function isUndefined(obj) {
30+
return typeof obj === 'undefined';
3131
}
3232

33-
angular
34-
.module('fileSaver', [])
35-
.factory('SaveAs', ['$window', SaveAs]);
33+
function SaveAs($window) {
34+
var saveAs = $window.saveAs;
35+
var Blob = $window.Blob;
3636

37-
function SaveAs ($window) {
38-
var saveAs = $window.saveAs;
39-
var Blob = $window.Blob;
37+
if (isUndefined(saveAs)) {
38+
handleErrors('saveAs is not supported. Please include saveAs polyfill');
39+
}
4040

41-
if (isUndefined(saveAs)) {
42-
handleErrors('saveAs is not supported. Please include saveAs polyfill');
43-
}
41+
if (isUndefined(Blob)) {
42+
handleErrors('Blob is not supported. Please include blob polyfill');
43+
}
4444

45-
if (isUndefined(Blob)) {
46-
handleErrors('Blob is not supported. Please include blob polyfill');
47-
}
45+
function isBlobInstance(obj) {
46+
return obj instanceof Blob;
47+
}
4848

49-
function isBlobInstance (obj) {
50-
return obj instanceof Blob;
49+
function save(blob, filename) {
50+
try {
51+
saveAs(blob, filename);
52+
} catch(err) {
53+
handleErrors(err.message);
5154
}
55+
}
5256

53-
function save(blob, filename) {
54-
try {
55-
saveAs(blob, filename);
56-
} catch(err) {
57-
handleErrors(err.message);
57+
return {
58+
59+
/**
60+
* download - Immediately starts saving a file, returns undefined.
61+
*
62+
* @param {array|Blob} data Represented as an array or a Blob object
63+
* @param {string} filename
64+
* @param {object} options Set of Blob constructor options.
65+
* Optional parameter, if Blob object is passed as first argument
66+
* @return {undefined}
67+
*/
68+
69+
download: function(data, filename, options) {
70+
if (!isArray(data) || !isBlobInstance(data)) {
71+
handleErrors('Data argument should be represented as an array or Blob instance');
5872
}
59-
}
6073

61-
return {
62-
63-
/**
64-
* download - Immediately starts saving a file, returns undefined.
65-
*
66-
* @param {array|Blob} data Represented as an array or a Blob object
67-
* @param {string} filename
68-
* @param {object} options Set of Blob constructor options.
69-
* Optional parameter, if Blob object is passed as first argument
70-
* @return {undefined}
71-
*/
72-
73-
download: function (data, filename, options) {
74-
if (!isArray(data) || !isBlobInstance(data)) {
75-
handleErrors('Data argument should be represented as an array or Blob instance');
76-
}
77-
78-
if (!isString(filename)) {
79-
handleErrors('Filename argument should be a string');
80-
}
81-
82-
if (!isObject(options)) {
83-
handleErrors('Options argument should be an object');
84-
}
85-
86-
if (isBlobInstance(data)) {
87-
return save(data, filename);
88-
}
89-
90-
var blob = new Blob(data, options);
91-
return save(blob, filename);
74+
if (!isString(filename)) {
75+
handleErrors('Filename argument should be a string');
9276
}
93-
};
94-
}
77+
78+
if (!isObject(options)) {
79+
handleErrors('Options argument should be an object');
80+
}
81+
82+
if (isBlobInstance(data)) {
83+
return save(data, filename);
84+
}
85+
86+
var blob = new Blob(data, options);
87+
return save(blob, filename);
88+
}
89+
};
90+
}
91+
92+
angular
93+
.module('fileSaver', [])
94+
.factory('SaveAs', ['$window', SaveAs]);

0 commit comments

Comments
 (0)