From e87a55df386cfd70519e7d519a4df94a1450a8fc Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 23 Oct 2014 16:46:23 +0900 Subject: [PATCH 1/3] jszip: reformat jsdoc --- jszip/jszip.d.ts | 72 +++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/jszip/jszip.d.ts b/jszip/jszip.d.ts index 4c571dc95..2f05895bd 100644 --- a/jszip/jszip.d.ts +++ b/jszip/jszip.d.ts @@ -8,115 +8,105 @@ declare module jszip { /** * Get a file from the archive * - * @param path {string} relative path to file - * - * @return {JSZipFile} file matching path, null if no file found + * @param Path relative path to file + * @return File matching path, null if no file found */ file(path: string): JSZipFile; /** * Get files matching a RegExp from archive * - * @param path {RegExp} RegExp to match - * - * @return {JSZipFile[]} return all matching files or an empty array + * @param path RegExp to match + * @return Return all matching files or an empty array */ file(path: RegExp): JSZipFile[]; /** * Add a file to the archive * - * @param path {string} relative path to file - * @param content {any} content of the file - * @param options {JSZipOptions} optional information about the file - * - * @return {JSZip} JSZip object + * @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, content: any, options?: JSZipOptions): JSZip; /** * Return an new JSZip instance with the given folder as root * - * @param name {string} name of the folder - * - * @return {JSZip} new JSZip object with the given folder as root or null + * @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} RegExp to match - * - * @return {JSZipFile[]} new array of JSZipFile objects which match the RegExp + * @param name RegExp to match + * @return New array of JSZipFile objects which match the RegExp */ folder(name: RegExp): JSZipFile[]; /** * Removes the file or folder from the archive * - * @param path {string} relative path of file or folder - * - * @return {JSZip} returns the JSZip instance + * @param path Relative path of file or folder + * @return Returns the JSZip instance */ remove(path: string): JSZip; /** * Generates a new archive * - * @param options {JSZipGeneratorOptions} optional options for the generator - * - * @return {any} the serialized archive + * @param options Optional options for the generator + * @return The serialized archive */ generate(options?: JSZipGeneratorOptions): any; /** * Deserialize zip file * - * @param data {any} serialized zip file - * @param options {JSZipOptions} options for deserializing - * - * @return {JSZip} returns the JSZip instance + * @param data Serialized zip file + * @param options Options for deserializing + * @return Returns the JSZip instance */ load(data: any, options: JSZipOptions): JSZip; /** * Get all files wchich match the given filter function * - * @param {function} filter function - * - * @return {JSZipFile[]} array of matched elements + * @param predicate Filter function + * @return Array of matched elements */ filter(predicate: (relativePath: string, file: JSZipFile) => boolean): JSZipFile[]; /** * Calculate crc32 of given string * - * @param data {string} string to calculate crc32 from - * @param crc {number} optional: initializer for crc calc - * - * @return {number} calculated crc32 number + * @param data String to calculate crc32 from + * @param crc Optional: initializer for crc calc + * @return Calculated crc32 number */ crc32(data: string, crc?: number): number; /** * Clone JSSZip instance * - * return {JSZip} cloned instsance + * @return Cloned instsance */ clone(): JSZip; /** * UTF8 encode a string * - * @param data {string} string to encode + * @param data String to encode */ utf8encode(data: string): string; /** * UTF8 decode a string * - * @param data {string} string to decode + * @param data String to decode */ utf8decode(data: string): string; @@ -166,13 +156,13 @@ declare var JSZip: { * Create JSZip instance * If no parameters given an empty zip archive will be created * - * @param data {any} serialized zip archive - * @param options {JSZipOptions} description of the serialized zip archive + * @param data Serialized zip archive + * @param options Description of the serialized zip archive */ - new(data?: any, options?: jszip.JSZipOptions): jszip.JSZip; + new (data?: any, options?: jszip.JSZipOptions): jszip.JSZip; prototype: jszip.JSZip; - support : jszip.JSZipSupport; + support: jszip.JSZipSupport; } declare var JSZipBase64: { From 2d34cd049c239c91ed4409930944819abd175319 Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 23 Oct 2014 21:18:19 +0900 Subject: [PATCH 2/3] jszip: adjust to match current API --- jszip/jszip.d.ts | 277 +++++++++++++++++++++++------------------------ 1 file changed, 137 insertions(+), 140 deletions(-) diff --git a/jszip/jszip.d.ts b/jszip/jszip.d.ts index 2f05895bd..399fcb9a3 100644 --- a/jszip/jszip.d.ts +++ b/jszip/jszip.d.ts @@ -3,155 +3,146 @@ // Definitions by: mzeiher // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module jszip { - export 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): JSZipFile; +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): JSZipFile[]; + /** + * 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, content: any, options?: JSZipOptions): JSZip; + /** + * 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; - /** - * 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; + /** + * 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): JSZipFile[]; + /** + * 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[]; - /** - * 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; + /** + * 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[]; - /** - * Generates a new archive - * - * @param options Optional options for the generator - * @return The serialized archive - */ - generate(options?: JSZipGeneratorOptions): any; + /** + * 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; - /** - * Deserialize zip file - * - * @param data Serialized zip file - * @param options Options for deserializing - * @return Returns the JSZip instance - */ - load(data: any, options: JSZipOptions): JSZip; + /** + * Generates a new archive + * + * @param options Optional options for the generator + * @return The serialized archive + */ + generate(options?: JSZipGeneratorOptions): any; - /** - * Get all files wchich match the given filter function - * - * @param predicate Filter function - * @return Array of matched elements - */ - filter(predicate: (relativePath: string, file: JSZipFile) => boolean): JSZipFile[]; + /** + * Deserialize zip file + * + * @param data Serialized zip file + * @param options Options for deserializing + * @return Returns the JSZip instance + */ + load(data: any, options: JSZipLoadOptions): JSZip; +} - /** - * Calculate crc32 of given string - * - * @param data String to calculate crc32 from - * @param crc Optional: initializer for crc calc - * @return Calculated crc32 number - */ - crc32(data: string, crc?: number): number; +interface JSZipObject { + name: string; + data: any; + options: JSZipFileOptions; - /** - * Clone JSSZip instance - * - * @return Cloned instsance - */ - clone(): JSZip; + asText(): string; + asBinary(): string; + asArrayBuffer(): ArrayBuffer; + asUint8Array(): Uint8Array; + //asNodeBuffer(): Buffer; +} - /** - * UTF8 encode a string - * - * @param data String to encode - */ - utf8encode(data: string): string; +interface JSZipFileOptions { + base64?: boolean; + binary?: boolean; + date?: Date; + compression?: string; + comment?: string; + optimizedBinaryString?: boolean; + createFolders?: boolean; +} - /** - * UTF8 decode a string - * - * @param data String to decode - */ - utf8decode(data: string): string; +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; +} - export interface JSZipSupport { - arraybuffer: boolean; - uint8array: boolean; - blob: boolean; - } +interface JSZipLoadOptions { + base64?: boolean; + checkCRC32?: boolean; + optimizedBinaryString?: boolean; + createFolders?: boolean; +} - export interface JSZipGeneratorOptions { - base64?: boolean; //deprecated - compression: string; //DEFLATE or STORE - type: string; //base64 (default), string, uint8array, blob - } - - export interface JSZipOptions { - base64: boolean; - checkCRC32: boolean; - } - - export interface JSZipFile { - name: string; - data: any; - options: JSZipFileOptions; - - asText(): string; - asBinary(): any; - asArrayBuffer(): ArrayBuffer; - asUint8Array(): Uint8Array; - } - - export interface JSZipFileOptions { - base64: boolean; - binary: boolean; - dir: boolean; - date: Date; - } - - export interface JSZipBase64 { - } +interface JSZipSupport { + arraybuffer: boolean; + uint8array: boolean; + blob: boolean; + nodebuffer: boolean; } declare var JSZip: { + /** + * Create JSZip instance + */ + (): JSZip; /** * Create JSZip instance * If no parameters given an empty zip archive will be created @@ -159,15 +150,21 @@ declare var JSZip: { * @param data Serialized zip archive * @param options Description of the serialized zip archive */ - new (data?: any, options?: jszip.JSZipOptions): jszip.JSZip; + (data: any, options?: JSZipLoadOptions): JSZip; - prototype: jszip.JSZip; - support: jszip.JSZipSupport; -} + /** + * 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; -declare var JSZipBase64: { - encode(input: string, utf8?: any): string; - decode(input: string, utf8?: any): string; - - prototype: jszip.JSZipBase64; + prototype: JSZip; + support: JSZipSupport; } \ No newline at end of file From daf8112e3c826717f28d1ca22bf7f79517d2b527 Mon Sep 17 00:00:00 2001 From: SaschaNaz Date: Thu, 23 Oct 2014 21:58:24 +0900 Subject: [PATCH 3/3] jszip: update test suite --- jszip/jszip-tests.ts | 39 ++++++++++++++++----------------------- jszip/jszip.d.ts | 6 ++++-- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/jszip/jszip-tests.ts b/jszip/jszip-tests.ts index 9222cbb5b..97fd10450 100644 --- a/jszip/jszip-tests.ts +++ b/jszip/jszip-tests.ts @@ -1,4 +1,3 @@ -/// /// var SEVERITY = { @@ -10,30 +9,29 @@ var SEVERITY = { } function testJSZip() { - var newJszip = new JSZip(); newJszip.file("test.txt", "test string"); newJszip.file("test/test.txt", "test string"); - var serializedZip = newJszip.generate({compression: "DEFLATE", type:"base64"}); + var serializedZip = newJszip.generate({compression: "DEFLATE", type: "base64"}); newJszip = new JSZip(); newJszip.load(serializedZip, {base64: true, checkCRC32: true}); - if(newJszip.file("test.txt").data === "test string") { + if (newJszip.file("test.txt").asText() === "test string") { log(SEVERITY.INFO, "all ok"); } else { log(SEVERITY.ERROR, "no matching file found"); } - if(newJszip.file("test/test.txt").data === "test string") { + if (newJszip.file("test/test.txt").asText() === "test string") { log(SEVERITY.INFO, "all ok"); } else { log(SEVERITY.ERROR, "no matching file found"); } var folder = newJszip.folder("test"); - if(folder.file("test.txt").data == "test string") { + if(folder.file("test.txt").asText() == "test string") { log(SEVERITY.INFO, "all ok"); } else { @@ -44,7 +42,7 @@ function testJSZip() { if(folders.length == 1) { log(SEVERITY.INFO, "all ok"); - if(folders[0].options.dir == true) { + if(folders[0].dir == true) { log(SEVERITY.INFO, "all ok"); } else { @@ -57,7 +55,7 @@ function testJSZip() { var files = newJszip.file(new RegExp("^test")); if(files.length == 2) { log(SEVERITY.INFO, "all ok"); - if(files[0].data == "test string" && files[1].data == "test string") { + if (files[0].asText() == "test string" && files[1].asText() == "test string") { log(SEVERITY.INFO, "all ok"); } else { @@ -68,11 +66,11 @@ function testJSZip() { log(SEVERITY.ERROR, "wrong number of files"); } - var filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => { - if(file.data == "test string") { - return true; - } - return false; + var filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => { + if (file.asText() == "test string") { + return true; + } + return false; }); if(filterFiles.length == 2) { @@ -84,11 +82,11 @@ function testJSZip() { newJszip.remove("test/test.txt"); - filterFiles = newJszip.filter((relativePath: string, file: jszip.JSZipFile) => { - if(file.data == "test string") { - return true; - } - return false; + filterFiles = newJszip.filter((relativePath: string, file: JSZipObject) => { + if (file.asText() == "test string") { + return true; + } + return false; }); if(filterFiles.length == 1) { @@ -97,11 +95,6 @@ function testJSZip() { else { log(SEVERITY.ERROR, "wrong number of files"); } - - log(SEVERITY.INFO, newJszip.crc32("Test")); - log(SEVERITY.INFO, newJszip.utf8encode("Test")); - log(SEVERITY.INFO, newJszip.utf8decode("Test")); - newJszip.clone(); } function log(severity:number, message: any) { diff --git a/jszip/jszip.d.ts b/jszip/jszip.d.ts index 399fcb9a3..038b52957 100644 --- a/jszip/jszip.d.ts +++ b/jszip/jszip.d.ts @@ -82,8 +82,10 @@ interface JSZip { interface JSZipObject { name: string; - data: any; - options: JSZipFileOptions; + dir: boolean; + date: Date; + comment: string; + options: JSZipObjectOptions; asText(): string; asBinary(): string;