-
-
Notifications
You must be signed in to change notification settings - Fork 295
Open
Description
Problem with the type declaration of the first parameter of the decode method in index.d.ts?
export function decode(buffer: Buffer, encoding: string, options?: Options): string;
The first parameter of decode is declared as Buffer , but it is also possible to pass in string and number, but the correct result is not obtained. This will mislead developers, especially when the string type is used, the implementation code is as follows:
iconv.decode = function decode(buf, encoding, options) {
if (typeof buf === 'string') {
if (!iconv.skipDecodeWarning) {
......
iconv.skipDecodeWarning = true;
}
buf = Buffer.from("" + (buf || ""), "binary"); // Ensure buffer.
}
..........................................
}
The string is processed by default binary-encoded Buffer, and there is no description in the declaration file. I hope you can modify the declaration file, for example, change it to:
/**
* @description [Buffer | string] content If the incoming string type, it will be processed with binary encoded Buffer
*/
export function decode(content: Buffer | string, encoding: string, options?: Options): string;
In this way, the developer will clearly know what type of parameters to pass, and also know what the decode method does by default.
Metadata
Metadata
Assignees
Labels
No labels