From 324aecb42ebd5594dcd1a607522cbbf1c512baff Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 20 Jan 2022 15:34:29 +0300 Subject: [PATCH] fix: types (#661) --- README.md | 4 ++-- src/index.js | 1 + types/index.d.ts | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0b97979..a8230bb 100644 --- a/README.md +++ b/README.md @@ -549,10 +549,10 @@ Type: ```ts type transform = | { - transformer: (input: string, absoluteFilename: string) => string; + transformer: (input: string, absoluteFilename: string) => string | Buffer; cache?: boolean | TransformerCacheObject | undefined; } - | ((input: string, absoluteFilename: string) => string); + | ((input: string, absoluteFilename: string) => string | Buffer); ``` Default: `undefined` diff --git a/src/index.js b/src/index.js index a1ff362..efb4505 100644 --- a/src/index.js +++ b/src/index.js @@ -74,6 +74,7 @@ const template = /\[\\*([\w:]+)\\*\]/i; * @callback TransformerFunction * @param {Buffer} input * @param {string} absoluteFilename + * @returns {string | Buffer} */ /** diff --git a/types/index.d.ts b/types/index.d.ts index 51a1723..9d310be 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -49,6 +49,7 @@ export = CopyPlugin; * @callback TransformerFunction * @param {Buffer} input * @param {string} absoluteFilename + * @returns {string | Buffer} */ /** * @typedef {{ keys: { [key: string]: any } } | { keys: ((defaultCacheKeys: { [key: string]: any }, absoluteFilename: string) => Promise<{ [key: string]: any }>) }} TransformerCacheObject @@ -229,7 +230,10 @@ type ToFunction = (pathData: { }) => string; type To = string | ToFunction; type ToType = "dir" | "file" | "template"; -type TransformerFunction = (input: Buffer, absoluteFilename: string) => any; +type TransformerFunction = ( + input: Buffer, + absoluteFilename: string +) => string | Buffer; type TransformerCacheObject = | { keys: {