-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typings: add typing for string decoder #38229
typings: add typing for string decoder #38229
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the line violates the maximum line length, but I couldn’t come up with a good idea to fix it. 🤔
lib/string_decoder.js
Outdated
/** | ||
* | ||
* @param {string} enc | ||
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | "base64" | "latin1" | "base64url"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | "base64" | "latin1" | "base64url"} | |
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | |
* | "base64" | "latin1" | "base64url"} |
What about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it works
Co-authored-by: Michaël Zasso <targos@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest adding function descriptions in the jsdoc comments.
@@ -84,6 +99,11 @@ StringDecoder.prototype.write = function write(buf) { | |||
return decode(this[kNativeDecoder], buf); | |||
}; | |||
|
|||
/** | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* Returns any remaining input stored in the internal buffer as a string. | |
* After end() is called, the stringDecoder object can be reused for new input. |
@@ -68,12 +74,21 @@ for (let i = 0; i < encodings.length; ++i) | |||
// StringDecoder provides an interface for efficiently splitting a series of | |||
// buffers into a series of JS strings without breaking apart multi-byte | |||
// characters. | |||
/** | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the above description inside the comment?
function StringDecoder(encoding) { | ||
this.encoding = normalizeEncoding(encoding); | ||
this[kNativeDecoder] = Buffer.alloc(kSize); | ||
this[kNativeDecoder][kEncodingField] = encodingsMap[this.encoding]; | ||
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* Returns a decoded string, omitting any incomplete multibyte | |
* characters at the end of the Buffer, or TypedArray, or DataView |
Co-authored-by: marsonya <akhil.marsonya27@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark optional params as such and assign default value using JSDoc conventions.
Kindly ignore it incase this is too much detailing. I know we don't want to duplicate the documentation here using JSDoc. I just feel that it would be important information for core developers to know whether a param is optional or not and what it's default value would be.
Good idea, I will address optional arugment issue |
Co-authored-by: Akhil Marsonya <akhil.marsonya27@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSLGTM
Commit Queue failed- Loading data for nodejs/node/pull/38229 ✔ Done loading data for nodejs/node/pull/38229 ----------------------------------- PR info ------------------------------------ Title typings: add typing for string decoder (#38229) Author Qingyu Deng (@Ayase-252) Branch Ayase-252:feature/typing-lib-internal-cipher -> nodejs:master Labels string_decoder, typings, commit-queue-squash Commits 4 - typings: add typing for internal/string_decoder - fixup: typings: add typing for internal/string_decoder - fixup: add function description - fixup: mark optional parameters Committers 1 - Qingyu Deng PR-URL: https://github.com/nodejs/node/pull/38229 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/38229 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 13 Apr 2021 15:40:00 GMT ✔ Approvals: 2 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/38229#pullrequestreview-640365320 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/38229#pullrequestreview-842115810 ✔ Last GitHub CI successful ✖ No Jenkins CI runs detected -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/1639087835 |
Landed in a100a93 |
PR-URL: #38229 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: #38229 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#38229 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: #38229 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This PR adds some JSDoc typings for internal/string_decoder.
Screenshots from my VS code:
normalizeEncoding
StringDecoder
StringDecoder.prototype.write
StringDecoder.prototype.end
StringDecoder.prototype.text