{“ast”:null,“code”:“'use strict';nnvar utf8 = require('./utf8');nnvar utils = require('./utils');nnvar GenericWorker = require('./stream/GenericWorker');nnvar StreamHelper = require('./stream/StreamHelper');nnvar defaults = require('./defaults');nnvar CompressedObject = require('./compressedObject');nnvar ZipObject = require('./zipObject');nnvar generate = require("./generate");nnvar nodejsUtils = require("./nodejsUtils");nnvar NodejsStreamInputAdapter = require("./nodejs/NodejsStreamInputAdapter");n/**n * Add a file in the current folder.n * @privaten * @param {string} name the name of the filen * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the filen * @param {Object} originalOptions the options of the filen * @return {Object} the new file.n */nnnvar fileAdd = function fileAdd(name, data, originalOptions) {n // be sure sub folders existn var dataType = utils.getTypeOf(data),n parent;n /*n * Correct options.n */nn var o = utils.extend(originalOptions || {}, defaults);n o.date = o.date || new Date();nn if (o.compression !== null) {n o.compression = o.compression.toUpperCase();n }nn if (typeof o.unixPermissions === "string") {n o.unixPermissions = parseInt(o.unixPermissions, 8);n } // UNX_IFDIR 0040000 see zipinfo.cnnn if (o.unixPermissions && o.unixPermissions & 0x4000) {n o.dir = true;n } // Bit 4 Directorynnn if (o.dosPermissions && o.dosPermissions & 0x0010) {n o.dir = true;n }nn if (o.dir) {n name = forceTrailingSlash(name);n }nn if (o.createFolders && (parent = parentFolder(name))) {n folderAdd.call(this, parent, true);n }nn var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;nn if (!originalOptions || typeof originalOptions.binary === "undefined") {n o.binary = !isUnicodeString;n }nn var isCompressedEmpty = data instanceof CompressedObject && data.uncompressedSize === 0;nn if (isCompressedEmpty || o.dir || !data || data.length === 0) {n o.base64 = false;n o.binary = true;n data = "";n o.compression = "STORE";n dataType = "string";n }n /*n * Convert content to fit.n */nnn var zipObjectContent = null;nn if (data instanceof CompressedObject || data instanceof GenericWorker) {n zipObjectContent = data;n } else if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {n zipObjectContent = new NodejsStreamInputAdapter(name, data);n } else {n zipObjectContent = utils.prepareContent(name, data, o.binary, o.optimizedBinaryString, o.base64);n }nn var object = new ZipObject(name, zipObjectContent, o);n this.files = object;n /*n TODO: we can't throw an exception because we have async promisesn (we can have a promise of a Date() for example) but returning an promise is useless because file(name, data) returns the JSZipn object for chaining. Should we break that to allow the usern to catch the error ?n return external.Promise.resolve(zipObjectContent)n .then(function () {n return object;n });n */n};n/**n * Find the parent folder of the path.n * @privaten * @param {string} path the path to usen * @return {string} the parent folder, or ""n */nnnvar parentFolder = function parentFolder(path) {n if (path.slice(-1) === '/') {n path = path.substring(0, path.length - 1);n }nn var lastSlash = path.lastIndexOf('/');n return lastSlash > 0 ? path.substring(0, lastSlash) : "";n};n/**n * Returns the path with a slash at the end.n * @privaten * @param {String} path the path to check.n * @return {String} the path with a trailing slash.n */nnnvar forceTrailingSlash = function forceTrailingSlash(path) {n // Check the name ends with a /n if (path.slice(-1) !== "/") {n path += "/"; // IE doesn't like substr(-1)n }nn return path;n};n/**n * Add a (sub) folder in the current folder.n * @privaten * @param {string} name the folder's namen * @param {boolean=} [createFolders] If true, automatically create subn * folders. Defaults to false.n * @return {Object} the new folder.n */nnnvar folderAdd = function folderAdd(name, createFolders) {n createFolders = typeof createFolders !== 'undefined' ? createFolders : defaults.createFolders;n name = forceTrailingSlash(name); // Does this folder already exist?nn if (!this.files) {n fileAdd.call(this, name, null, {n dir: true,n createFolders: createFoldersn });n }nn return this.files;n};n/*n Cross-window, cross-Node-context regular expression detectionn* @param {Object} object Anythingn* @return {Boolean} true if the object is a regular expression,n* false otherwisen*/nnnfunction isRegExp(object) {n return Object.prototype.toString.call(object) === "[object RegExp]";n} // return the actual prototype of JSZipnnnvar out = {n /**n * @see loadAsyncn */n load: function load() {n throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");n },nn /**n * Call a callback function for each entry at this folder level.n * @param {Function} cb the callback function:n * function (relativePath, file) {…}n * It takes 2 arguments : the relative path and the file.n */n forEach: function forEach(cb) {n var filename, relativePath, file;nn for (filename in this.files) {n if (!this.files.hasOwnProperty(filename)) {n continue;n }nn file = this.files;n relativePath = filename.slice(this.root.length, filename.length);nn if (relativePath && filename.slice(0, this.root.length) === this.root) {n // the file is in the current rootn cb(relativePath, file); // TODO reverse the parameters ? need to be clean AND consistent with the filter search fn…n }n }n },nn /**n * Filter nested files/folders with the specified function.n * @param {Function} search the predicate to use :n * function (relativePath, file) {…}n * It takes 2 arguments : the relative path and the file.n * @return {Array} An array of matching elements.n */n filter: function filter(search) {n var result = [];n this.forEach(function (relativePath, entry) {n if (search(relativePath, entry)) {n // the file matches the functionn result.push(entry);n }n });n return result;n },nn /**n * Add a file to the zip file, or search a file.n * @param {string|RegExp} name The name of the file to add (if data is defined),n * the name of the file to find (if no data) or a regex to match files.n * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encodedn * @param {Object} o File optionsn * @return {JSZip|Object|Array} this JSZip object (when adding a file),n * a file (when searching by string) or an array of files (when searching by regex).n */n file: function file(name, data, o) {n if (arguments.length === 1) {n if (isRegExp(name)) {n var regexp = name;n return this.filter(function (relativePath, file) {n return !file.dir && regexp.test(relativePath);n });n } else {n // textn var obj = this.files[this.root + name];nn if (obj && !obj.dir) {n return obj;n } else {n return null;n }n }n } else {n // more than one argument : we have data !n name = this.root + name;n fileAdd.call(this, name, data, o);n }nn return this;n },nn /**n * Add a directory to the zip file, or search.n * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.n * @return {JSZip} an object with the new directory as the root, or an array containing matching folders.n */n folder: function folder(arg) {n if (!arg) {n return this;n }nn if (isRegExp(arg)) {n return this.filter(function (relativePath, file) {n return file.dir && arg.test(relativePath);n });n } // else, name is a new foldernnn var name = this.root + arg;n var newFolder = folderAdd.call(this, name); // Allow chaining by returning a new object with this folder as the rootnn var ret = this.clone();n ret.root = newFolder.name;n return ret;n },nn /**n * Delete a file, or a directory and all sub-files, from the zipn * @param {string} name the name of the file to deleten * @return {JSZip} this JSZip objectn */n remove: function remove(name) {n name = this.root + name;n var file = this.files;nn if (!file) {n // Look for any foldersn if (name.slice(-1) !== "/") {n name += "/";n }nn file = this.files;n }nn if (file && !file.dir) {n // filen delete this.files;n } else {n // maybe a folder, delete recursivelyn var kids = this.filter(function (relativePath, file) {n return file.name.slice(0, name.length) === name;n });nn for (var i = 0; i < kids.length; i++) {n delete this.files[kids.name];n }n }nn return this;n },nn /**n * Generate the complete zip filen * @param {Object} options the options to generate the zip file :n * - compression, "STORE" by default.n * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.n * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip filen */n generate: function generate(options) {n throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");n },nn /**n * Generate the complete zip file as an internal stream.n * @param {Object} options the options to generate the zip file :n * - compression, "STORE" by default.n * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.n * @return {StreamHelper} the streamed zip file.n */n generateInternalStream: function generateInternalStream(options) {n var worker,n opts = {};nn try {n opts = utils.extend(options || {}, {n streamFiles: false,n compression: "STORE",n compressionOptions: null,n type: "",n platform: "DOS",n comment: null,n mimeType: 'application/zip',n encodeFileName: utf8.utf8encoden });n opts.type = opts.type.toLowerCase();n opts.compression = opts.compression.toUpperCase(); // "binarystring" is prefered but the internals use "string".nn if (opts.type === "binarystring") {n opts.type = "string";n }nn if (!opts.type) {n throw new Error("No output type specified.");n }nn utils.checkSupport(opts.type); // accept nodejs `process.platform`nn if (opts.platform === 'darwin' || opts.platform === 'freebsd' || opts.platform === 'linux' || opts.platform === 'sunos') {n opts.platform = "UNIX";n }nn if (opts.platform === 'win32') {n opts.platform = "DOS";n }nn var comment = opts.comment || this.comment || "";n worker = generate.generateWorker(this, opts, comment);n } catch (e) {n worker = new GenericWorker("error");n worker.error(e);n }nn return new StreamHelper(worker, opts.type || "string", opts.mimeType);n },nn /**n * Generate the complete zip file asynchronously.n * @see generateInternalStreamn */n generateAsync: function generateAsync(options, onUpdate) {n return this.generateInternalStream(options).accumulate(onUpdate);n },nn /**n * Generate the complete zip file asynchronously.n * @see generateInternalStreamn */n generateNodeStream: function generateNodeStream(options, onUpdate) {n options = options || {};nn if (!options.type) {n options.type = "nodebuffer";n }nn return this.generateInternalStream(options).toNodejsStream(onUpdate);n }n};nmodule.exports = out;”,“map”:null,“metadata”:{},“sourceType”:“module”}