diff --git a/types/formidable/formidable-tests.ts b/types/formidable/formidable-tests.ts index 0d37e8618feaed..3f3585371bbcec 100644 --- a/types/formidable/formidable-tests.ts +++ b/types/formidable/formidable-tests.ts @@ -25,7 +25,7 @@ import * as http from "http"; // arrange const options: Options = { allowEmptyFiles: true, - enabledPlugins: [], + enabledPlugins: [json, querystring], encoding: "utf-8", fileWriteStreamHandler: undefined, hashAlgorithm: false, diff --git a/types/formidable/index.d.ts b/types/formidable/index.d.ts index 709bb1aee1b12b..4e20d493a59373 100644 --- a/types/formidable/index.d.ts +++ b/types/formidable/index.d.ts @@ -193,7 +193,7 @@ declare namespace formidable { */ filename?: (name: string, ext: string, part: Part, form: Formidable) => string; - enabledPlugins?: string[] | undefined; + enabledPlugins?: formidable.PluginFunction[] | undefined; filter?: (part: Part) => boolean; } diff --git a/types/node-bzip2/.npmignore b/types/node-bzip2/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/node-bzip2/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/node-bzip2/index.d.ts b/types/node-bzip2/index.d.ts new file mode 100644 index 00000000000000..a408a2f6a8eb19 --- /dev/null +++ b/types/node-bzip2/index.d.ts @@ -0,0 +1,20 @@ +/// +export interface CompressOptions { + /** Compression level from 1 (fastest) to 9 (best). Default is 9. */ + level?: number; + /** Buffering behavior, e.g., 'auto'. */ + buffering?: "auto" | string; +} + +export interface DecompressOptions { + /** Use less memory during decompression at the cost of speed. */ + small?: boolean; +} + +export function compress(input: string | Buffer | Uint8Array, options?: CompressOptions): Buffer; + +export function decompress(input: Buffer | Uint8Array, options?: DecompressOptions): Buffer; + +export function compressAsync(input: string | Buffer | Uint8Array, options?: CompressOptions): Promise; + +export function decompressAsync(input: Buffer | Uint8Array, options?: DecompressOptions): Promise; diff --git a/types/node-bzip2/node-bzip2-tests.ts b/types/node-bzip2/node-bzip2-tests.ts new file mode 100644 index 00000000000000..7c6ae0f85d36b5 --- /dev/null +++ b/types/node-bzip2/node-bzip2-tests.ts @@ -0,0 +1,39 @@ +import * as bzip2 from "node-bzip2"; + +interface Result { + data: Buffer | null; + error: Error | null; +} + +async function doCompress(): Promise { + try { + const input = "Hello, world!"; + const compressed = await bzip2.compressAsync(input, { level: 9 }); + return { data: compressed, error: null }; + } catch (e) { + return { data: null, error: e as Error }; + } +} + +async function doDecompress(cResult: Result): Promise { + if (cResult.error || !cResult.data) return cResult; + try { + const decompressed = await bzip2.decompressAsync(cResult.data); + return { data: decompressed, error: null }; + } catch (e) { + return { data: null, error: e as Error }; + } +} + +async function doTest() { + const cResult = await doCompress(); + const dResult = await doDecompress(cResult); + + if (!dResult.error && dResult.data?.toString() === "Hello, world!") { + console.log("Success"); + } else { + console.log("Failure", dResult.error); + } +} + +doTest(); diff --git a/types/node-bzip2/package.json b/types/node-bzip2/package.json new file mode 100644 index 00000000000000..7f0b0796d9e4e0 --- /dev/null +++ b/types/node-bzip2/package.json @@ -0,0 +1,20 @@ +{ + "private": true, + "name": "@types/node-bzip2", + "version": "1.0.9999", + "projects": [ + "https://github.com/WilliamVenner/node-bzip2" + ], + "dependencies": { + "@types/node": "*" + }, + "devDependencies": { + "@types/node-bzip2": "workspace:." + }, + "owners": [ + { + "name": "Sheryl Gavin", + "githubUsername": "shadowslasher410" + } + ] +} diff --git a/types/node-bzip2/tsconfig.json b/types/node-bzip2/tsconfig.json new file mode 100644 index 00000000000000..4344a2566d6787 --- /dev/null +++ b/types/node-bzip2/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "node-bzip2": ["./index.d.ts"] + } + }, + "files": [ + "index.d.ts", + "node-bzip2-tests.ts" + ] +}