Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuk committed Jun 23, 2022
1 parent 85c2348 commit 5221202
Show file tree
Hide file tree
Showing 64 changed files with 1,269 additions and 1,266 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
@@ -1,3 +1,5 @@
"use strict";

module.exports = {
"env": {
"browser": true,
Expand All @@ -9,7 +11,7 @@ module.exports = {
"parserOptions": {
"ecmaVersion": "latest"
},
"ignorePatterns": ["vendor/*.js", "dist/*.js"],
"ignorePatterns": ["vendor/*.js", "dist/*.js", "test/jquery-1.8.3.min.js"],
"rules": {
"indent": [
"error",
Expand Down
72 changes: 36 additions & 36 deletions Gruntfile.js
@@ -1,46 +1,46 @@
"use strict";

module.exports = function(grunt) {
var version = require("./package.json").version;
var version = require("./package.json").version;

grunt.initConfig({
browserify: {
all: {
files: {
'dist/jszip.js': ['lib/index.js']
grunt.initConfig({
browserify: {
all: {
files: {
"dist/jszip.js": ["lib/index.js"]
},
options: {
browserifyOptions: {
standalone: "JSZip",
transform: ["package-json-versionify"],
insertGlobalVars: {
process: undefined,
Buffer: undefined,
__filename: undefined,
__dirname: undefined
},
builtins: false
},
banner: grunt.file.read("lib/license_header.js").replace(/__VERSION__/, version)
}
}
},
options: {
browserifyOptions: {
standalone: 'JSZip',
transform: ['package-json-versionify'],
insertGlobalVars: {
process: undefined,
Buffer: undefined,
__filename: undefined,
__dirname: undefined
uglify: {
options: {
mangle: true,
preserveComments: false,
banner: grunt.file.read("lib/license_header.js").replace(/__VERSION__/, version)
},
builtins: false
},
banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version)
all: {
src: "dist/jszip.js",
dest: "dist/jszip.min.js"
}
}
}
},
uglify: {
options: {
mangle: true,
preserveComments: false,
banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version)
},
all: {
src: 'dist/jszip.js',
dest: 'dist/jszip.min.js'
}
}
});
});

grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-browserify");
grunt.loadNpmTasks("grunt-contrib-uglify");

grunt.registerTask("build", ["browserify", "uglify"]);
grunt.registerTask("default", ["build"]);
grunt.registerTask("build", ["browserify", "uglify"]);
grunt.registerTask("default", ["build"]);
};
12 changes: 12 additions & 0 deletions documentation/.eslintrc.js
@@ -0,0 +1,12 @@
"use strict";

module.exports = {
globals: {
$: false,
jQuery: false,
JSZip: false,
JSZipUtils: false,
// From FileSaver.js
saveAs: false,
},
};
2 changes: 2 additions & 0 deletions documentation/examples/download-zip-file.inc/blob.js
@@ -1,3 +1,5 @@
"use strict";

var zip = new JSZip();
zip.file("Hello.txt", "Hello world\n");

Expand Down
2 changes: 2 additions & 0 deletions documentation/examples/download-zip-file.inc/data_uri.js
@@ -1,3 +1,5 @@
"use strict";

var zip = new JSZip();
zip.file("Hello.txt", "Hello world\n");

Expand Down
25 changes: 11 additions & 14 deletions documentation/examples/downloader.inc/downloader.js
@@ -1,8 +1,6 @@

var Promise = window.Promise;
if (!Promise) {
Promise = JSZip.external.Promise;
}
"use strict";
// From helpers.js:
/* global resetMessage, showMessage, showError, updatePercent */

/**
* Fetch the content and return the associated promise.
Expand All @@ -21,8 +19,7 @@ function urlToPromise(url) {
});
}

var $form = $("#download_form").on("submit", function () {

$("#download_form").on("submit", function () {
resetMessage();

var zip = new JSZip();
Expand All @@ -44,15 +41,15 @@ var $form = $("#download_form").on("submit", function () {
showMessage(msg);
updatePercent(metadata.percent|0);
})
.then(function callback(blob) {
.then(function callback(blob) {

// see FileSaver.js
saveAs(blob, "example.zip");
// see FileSaver.js
saveAs(blob, "example.zip");

showMessage("done !");
}, function (e) {
showError(e);
});
showMessage("done !");
}, function (e) {
showError(e);
});

return false;
});
28 changes: 15 additions & 13 deletions documentation/examples/downloader.inc/helpers.js
@@ -1,20 +1,23 @@
"use strict";

/**
* Reset the message.
*/
function resetMessage () {
$("#result")
.removeClass()
.text("");
.removeClass()
.text("");
}
/**
* show a successful message.
* @param {String} text the text to show.
*/
// eslint-disable-next-line no-unused-vars
function showMessage(text) {
resetMessage();
$("#result")
.addClass("alert alert-success")
.text(text);
.addClass("alert alert-success")
.text(text);
}
/**
* show an error message.
Expand All @@ -23,24 +26,23 @@ function showMessage(text) {
function showError(text) {
resetMessage();
$("#result")
.addClass("alert alert-danger")
.text(text);
.addClass("alert alert-danger")
.text(text);
}
/**
* Update the progress bar.
* @param {Integer} percent the current percent
*/
// eslint-disable-next-line no-unused-vars
function updatePercent(percent) {
$("#progress_bar").removeClass("hide")
.find(".progress-bar")
.attr("aria-valuenow", percent)
.css({
width : percent + "%"
});
.find(".progress-bar")
.attr("aria-valuenow", percent)
.css({
width : percent + "%"
});
}

if(!JSZip.support.blob) {
showError("This demo works only with a recent browser !");
return;
}

48 changes: 25 additions & 23 deletions documentation/examples/get-binary-files-ajax.inc/fetch_api.js
@@ -1,23 +1,25 @@
fetch('{{site.baseurl}}/test/ref/text.zip') // 1) fetch the url
.then(function (response) { // 2) filter on 200 OK
if (response.status === 200 || response.status === 0) {
return Promise.resolve(response.blob());
} else {
return Promise.reject(new Error(response.statusText));
}
})
.then(JSZip.loadAsync) // 3) chain with the zip promise
.then(function (zip) {
return zip.file("Hello.txt").async("string"); // 4) chain with the text content promise
})
.then(function success(text) { // 5) display the result
$("#fetch").append($("<p>", {
"class": "alert alert-success",
text: "loaded, content = " + text
}));
}, function error(e) {
$("#fetch").append($("<p>", {
"class": "alert alert-danger",
text: e
}));
});
"use strict";

fetch("{{site.baseurl}}/test/ref/text.zip") // 1) fetch the url
.then(function (response) { // 2) filter on 200 OK
if (response.status === 200 || response.status === 0) {
return Promise.resolve(response.blob());
} else {
return Promise.reject(new Error(response.statusText));
}
})
.then(JSZip.loadAsync) // 3) chain with the zip promise
.then(function (zip) {
return zip.file("Hello.txt").async("string"); // 4) chain with the text content promise
})
.then(function success(text) { // 5) display the result
$("#fetch").append($("<p>", {
"class": "alert alert-success",
text: "loaded, content = " + text
}));
}, function error(e) {
$("#fetch").append($("<p>", {
"class": "alert alert-danger",
text: e
}));
});
33 changes: 17 additions & 16 deletions documentation/examples/get-binary-files-ajax.inc/jszip_utils.js
@@ -1,6 +1,8 @@
"use strict";

// 1) get a promise of the content
var promise = new JSZip.external.Promise(function (resolve, reject) {
JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) {
JSZipUtils.getBinaryContent("{{site.baseurl}}/test/ref/text.zip", function(err, data) {
if (err) {
reject(err);
} else {
Expand All @@ -10,18 +12,17 @@ var promise = new JSZip.external.Promise(function (resolve, reject) {
});

promise.then(JSZip.loadAsync) // 2) chain with the zip promise
.then(function(zip) {
return zip.file("Hello.txt").async("string"); // 3) chain with the text content promise
})
.then(function success(text) { // 4) display the result
$("#jszip_utils").append($("<p>", {
"class": "alert alert-success",
text: "loaded, content = " + text
}));
}, function error(e) {
$("#jszip_utils").append($("<p>", {
"class": "alert alert-danger",
text: e
}));
});

.then(function(zip) {
return zip.file("Hello.txt").async("string"); // 3) chain with the text content promise
})
.then(function success(text) { // 4) display the result
$("#jszip_utils").append($("<p>", {
"class": "alert alert-success",
text: "loaded, content = " + text
}));
}, function error(e) {
$("#jszip_utils").append($("<p>", {
"class": "alert alert-danger",
text: e
}));
});
33 changes: 17 additions & 16 deletions documentation/examples/read-local-file-api.inc/read.js
@@ -1,3 +1,5 @@
"use strict";

var $result = $("#result");
$("#file").on("change", function(evt) {
// remove content
Expand All @@ -16,29 +18,28 @@ $("#file").on("change", function(evt) {

var dateBefore = new Date();
JSZip.loadAsync(f) // 1) read the Blob
.then(function(zip) {
var dateAfter = new Date();
$title.append($("<span>", {
"class": "small",
text:" (loaded in " + (dateAfter - dateBefore) + "ms)"
}));
.then(function(zip) {
var dateAfter = new Date();
$title.append($("<span>", {
"class": "small",
text:" (loaded in " + (dateAfter - dateBefore) + "ms)"
}));

zip.forEach(function (relativePath, zipEntry) { // 2) print entries
$fileContent.append($("<li>", {
text : zipEntry.name
zip.forEach(function (relativePath, zipEntry) { // 2) print entries
$fileContent.append($("<li>", {
text : zipEntry.name
}));
});
}, function (e) {
$result.append($("<div>", {
"class" : "alert alert-danger",
text : "Error reading " + f.name + ": " + e.message
}));
});
}, function (e) {
$result.append($("<div>", {
"class" : "alert alert-danger",
text : "Error reading " + f.name + ": " + e.message
}));
});
}

var files = evt.target.files;
for (var i = 0; i < files.length; i++) {
handleFile(files[i]);
}
});

8 changes: 4 additions & 4 deletions lib/base64.js
@@ -1,6 +1,6 @@
'use strict';
var utils = require('./utils');
var support = require('./support');
"use strict";
var utils = require("./utils");
var support = require("./support");
// private property
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

Expand Down Expand Up @@ -55,7 +55,7 @@ exports.decode = function(input) {
throw new Error("Invalid base64 input, it looks like a data url.");
}

input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
input = input.replace(/[^A-Za-z0-9+/=]/g, "");

var totalLength = input.length * 3 / 4;
if(input.charAt(input.length - 1) === _keyStr.charAt(64)) {
Expand Down

0 comments on commit 5221202

Please sign in to comment.