Skip to content

Commit

Permalink
Convert to class and by conincidence fix bug in findMaxFileId which t…
Browse files Browse the repository at this point in the history
…ake only last file name (which can lead to problem if XLSX template was generated)
  • Loading branch information
kant2002 committed Mar 7, 2023
1 parent 300d4ef commit 0e1d14a
Show file tree
Hide file tree
Showing 6 changed files with 771 additions and 720 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ atlassian-ide-plugin.xml
.vs/
lib/*.js
lib/*.d.ts
!lib/index.d.ts
!lib/index.d.ts
*.map
9 changes: 1 addition & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@
}
},
"dependencies": {
"@kant2002/jszip": "2.7.1",
"elementtree": "^0.1.7",
"image-size": "^0.3.5",
"@kant2002/jszip": "2.7.1"
"image-size": "^0.3.5"
},
"devDependencies": {
"@types/jest": "^27.4.0",
"@types/jszip": "0.0.27",
"@types/node": "^14.0.27",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
Expand Down
193 changes: 193 additions & 0 deletions src/augment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Type definitions for JSZip
// Project: http://stuk.github.com/jszip/
// Definitions by: mzeiher <https://github.com/mzeiher>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

interface JSZip {
/**
* Get a file from the archive
*
* @param Path relative path to file
* @return File matching path, null if no file found
*/
file(path: string): JSZipObject;

/**
* Get files matching a RegExp from archive
*
* @param path RegExp to match
* @return Return all matching files or an empty array
*/
file(path: RegExp): JSZipObject[];

/**
* Add a file to the archive
*
* @param path Relative path to file
* @param content Content of the file
* @param options Optional information about the file
* @return JSZip object
*/
file(path: string, data: any, options?: JSZipFileOptions): JSZip;

files: JSZipObject[];

/**
* Return an new JSZip instance with the given folder as root
*
* @param name Name of the folder
* @return New JSZip object with the given folder as root or null
*/
folder(name: string): JSZip;

/**
* Returns new JSZip instances with the matching folders as root
*
* @param name RegExp to match
* @return New array of JSZipFile objects which match the RegExp
*/
folder(name: RegExp): JSZipObject[];

/**
* Get all files wchich match the given filter function
*
* @param predicate Filter function
* @return Array of matched elements
*/
filter(predicate: (relativePath: string, file: JSZipObject) => boolean): JSZipObject[];

/**
* Removes the file or folder from the archive
*
* @param path Relative path of file or folder
* @return Returns the JSZip instance
*/
remove(path: string): JSZip;

/**
* Generates a new archive
*
* @param options Optional options for the generator
* @return The serialized archive
*/
generate(options?: JSZipGeneratorOptions): any;

/**
* Deserialize zip file
*
* @param data Serialized zip file
* @param options Options for deserializing
* @return Returns the JSZip instance
*/
load(data: any, options: JSZipLoadOptions): JSZip;
}

interface JSZipObject {
name: string;
dir: boolean;
date: Date;
comment: string;
options: JSZipObjectOptions;

asText(): string;
asBinary(): string;
asArrayBuffer(): ArrayBuffer;
asUint8Array(): Uint8Array;
//asNodeBuffer(): Buffer;
}

interface JSZipFileOptions {
base64?: boolean;
binary?: boolean;
date?: Date;
compression?: string;
comment?: string;
optimizedBinaryString?: boolean;
createFolders?: boolean;
}

interface JSZipObjectOptions {
/** deprecated */
base64: boolean;
/** deprecated */
binary: boolean;
/** deprecated */
dir: boolean;
/** deprecated */
date: Date;
compression: string;
}

interface JSZipGeneratorOptions {
/** deprecated */
base64?: boolean;
/** DEFLATE or STORE */
compression?: string;
/** base64 (default), string, uint8array, blob */
type?: string;
comment?: string;
}

interface JSZipLoadOptions {
base64?: boolean;
checkCRC32?: boolean;
optimizedBinaryString?: boolean;
createFolders?: boolean;
}

interface JSZipSupport {
arraybuffer: boolean;
uint8array: boolean;
blob: boolean;
nodebuffer: boolean;
}

interface DEFLATE {
/** pako.deflateRaw, level:0-9 */
compress(input: string, compressionOptions: {level:number}): Uint8Array;
compress(input: number[], compressionOptions: {level:number}): Uint8Array;
compress(input: Uint8Array, compressionOptions: {level:number}): Uint8Array;

/** pako.inflateRaw */
uncompress(input: string): Uint8Array;
uncompress(input: number[]): Uint8Array;
uncompress(input: Uint8Array): Uint8Array;
}

declare var JSZip: {
/**
* Create JSZip instance
*/
(): JSZip;
/**
* Create JSZip instance
* If no parameters given an empty zip archive will be created
*
* @param data Serialized zip archive
* @param options Description of the serialized zip archive
*/
(data: any, options?: JSZipLoadOptions): JSZip;

/**
* Create JSZip instance
*/
new (): JSZip;
/**
* Create JSZip instance
* If no parameters given an empty zip archive will be created
*
* @param data Serialized zip archive
* @param options Description of the serialized zip archive
*/
new (data: any, options?: JSZipLoadOptions): JSZip;

prototype: JSZip;
support: JSZipSupport;
compressions: {
DEFLATE: DEFLATE;
}
}

declare module "@kant2002/jszip" {
export = JSZip;
}
Loading

0 comments on commit 0e1d14a

Please sign in to comment.