Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"ignorePatterns": ["vendor/*.js", "dist/*.js", "test/jquery-1.8.3.min.js"],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"curly": "error",
"eqeqeq": "error",
"no-new": "error",
"no-caller": "error",
"guard-for-in": "error",
"no-extend-native": "error",
"strict": [
"error",
"global"
],
}
};
1 change: 0 additions & 1 deletion .jshintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .jshintrc

This file was deleted.

93 changes: 36 additions & 57 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,46 @@
/*jshint node: true */
"use strict";

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

grunt.initConfig({
jshint: {
// see https://github.com/gruntjs/grunt-contrib-jshint/issues/198
// we can't override the options using the jshintrc path
options: grunt.file.readJSON('.jshintrc'),
production: ['./lib/**/*.js'],
test: ['./test/helpers/**/*.js', './test/asserts/**/*.js'],
documentation: {
options: {
// we include js files with jekyll, jshint can't see all
// variables and we can't declare all of them
undef: false,
// 'implied' still give false positives in our case
strict: false
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)
}
}
},
files: {
src: ['./documentation/**/*.js']
}
}
},
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
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-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-browserify");
grunt.loadNpmTasks("grunt-contrib-uglify");

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

module.exports = {
globals: {
$: false,
jQuery: false,
JSZip: false,
JSZipUtils: false,
// From FileSaver.js
saveAs: false,
},
};
2 changes: 1 addition & 1 deletion documentation/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Here are the interesting build commands :
* `npm run test-browser` will the tests in some browsers using SauceLabs, see
below.
* `npm run test` will run the tests in nodejs and in the browser.
* `npm run lint` will use jshint the check the source code.
* `npm run lint` will use eslint the check the source code.

#### Documentation

Expand Down
2 changes: 2 additions & 0 deletions documentation/examples/download-zip-file.inc/blob.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}));
});
Loading