Skip to content

Commit ea1f25e

Browse files
Phillip9587Copilot
andauthored
docs: use standard jsdoc tags everywhere (#677)
* docs: use standard jsdoc tags everywhere * docs: fix jsdoc function return type annotation Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d7deef8 commit ea1f25e

File tree

7 files changed

+54
-70
lines changed

7 files changed

+54
-70
lines changed

index.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77
'use strict'
88

99
/**
10-
* @typedef Parsers
11-
* @type {function}
12-
* @property {function} json
13-
* @property {function} raw
14-
* @property {function} text
15-
* @property {function} urlencoded
10+
* @typedef {Object} Parsers
11+
* @property {Function} json JSON parser
12+
* @property {Function} raw Raw parser
13+
* @property {Function} text Text parser
14+
* @property {Function} urlencoded URL-encoded parser
1615
*/
1716

1817
/**
1918
* Module exports.
20-
* @type {Parsers}
19+
* @type {Function & Parsers}
2120
*/
22-
2321
exports = module.exports = bodyParser
2422

2523
/**
2624
* JSON parser.
2725
* @public
2826
*/
29-
3027
Object.defineProperty(exports, 'json', {
3128
configurable: true,
3229
enumerable: true,
@@ -37,7 +34,6 @@ Object.defineProperty(exports, 'json', {
3734
* Raw parser.
3835
* @public
3936
*/
40-
4137
Object.defineProperty(exports, 'raw', {
4238
configurable: true,
4339
enumerable: true,
@@ -48,7 +44,6 @@ Object.defineProperty(exports, 'raw', {
4844
* Text parser.
4945
* @public
5046
*/
51-
5247
Object.defineProperty(exports, 'text', {
5348
configurable: true,
5449
enumerable: true,
@@ -59,7 +54,6 @@ Object.defineProperty(exports, 'text', {
5954
* URL-encoded parser.
6055
* @public
6156
*/
62-
6357
Object.defineProperty(exports, 'urlencoded', {
6458
configurable: true,
6559
enumerable: true,
@@ -69,12 +63,9 @@ Object.defineProperty(exports, 'urlencoded', {
6963
/**
7064
* Create a middleware to parse json and urlencoded bodies.
7165
*
72-
* @param {object} [options]
73-
* @return {function}
7466
* @deprecated
7567
* @public
7668
*/
77-
7869
function bodyParser () {
7970
throw new Error('The bodyParser() generic has been split into individual middleware to use instead.')
8071
}

lib/read.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ module.exports = read
2828
/**
2929
* Read a request into a buffer and parse.
3030
*
31-
* @param {object} req
32-
* @param {object} res
33-
* @param {function} next
34-
* @param {function} parse
35-
* @param {function} debug
36-
* @param {object} options
31+
* @param {Object} req
32+
* @param {Object} res
33+
* @param {Function} next
34+
* @param {Function} parse
35+
* @param {Function} debug
36+
* @param {Object} options
3737
* @private
3838
*/
39-
4039
function read (req, res, next, parse, debug, options) {
4140
if (onFinished.isFinished(req)) {
4241
debug('body already parsed')
@@ -176,13 +175,12 @@ function read (req, res, next, parse, debug, options) {
176175
/**
177176
* Get the content stream of the request.
178177
*
179-
* @param {object} req
180-
* @param {function} debug
181-
* @param {boolean} [inflate=true]
182-
* @return {object}
183-
* @api private
178+
* @param {Object} req
179+
* @param {Function} debug
180+
* @param {boolean} inflate
181+
* @returns {Object}
182+
* @private
184183
*/
185-
186184
function contentstream (req, debug, inflate) {
187185
var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
188186
var length = req.headers['content-length']
@@ -209,9 +207,9 @@ function contentstream (req, debug, inflate) {
209207
/**
210208
* Create a decompression stream for the given encoding.
211209
* @param {string} encoding
212-
* @param {function} debug
213-
* @return {object}
214-
* @api private
210+
* @param {Function} debug
211+
* @returns {Object}
212+
* @private
215213
*/
216214
function createDecompressionStream (encoding, debug) {
217215
switch (encoding) {
@@ -235,11 +233,10 @@ function createDecompressionStream (encoding, debug) {
235233
/**
236234
* Dump the contents of a request.
237235
*
238-
* @param {object} req
239-
* @param {function} callback
240-
* @api private
236+
* @param {Object} req
237+
* @param {Function} callback
238+
* @private
241239
*/
242-
243240
function dump (req, callback) {
244241
if (onFinished.isFinished(req)) {
245242
callback(null)

lib/types/json.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = json
3333
* %x0A / ; Line feed or New line
3434
* %x0D ) ; Carriage return
3535
*/
36-
3736
var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex
3837

3938
var JSON_SYNTAX_CHAR = '#'
@@ -42,11 +41,10 @@ var JSON_SYNTAX_REGEXP = /#+/g
4241
/**
4342
* Create a middleware to parse JSON bodies.
4443
*
45-
* @param {object} [options]
46-
* @return {function}
44+
* @param {Object} [options]
45+
* @returns {Function}
4746
* @public
4847
*/
49-
5048
function json (options) {
5149
const normalizedOptions = normalizeOptions(options, 'application/json')
5250

@@ -96,10 +94,9 @@ function json (options) {
9694
*
9795
* @param {string} str
9896
* @param {string} char
99-
* @return {Error}
97+
* @returns {Error}
10098
* @private
10199
*/
102-
103100
function createStrictSyntaxError (str, char) {
104101
var index = str.indexOf(char)
105102
var partial = ''
@@ -128,10 +125,9 @@ function createStrictSyntaxError (str, char) {
128125
* Get the first non-whitespace character in a string.
129126
*
130127
* @param {string} str
131-
* @return {function}
128+
* @returns {string|undefined}
132129
* @private
133130
*/
134-
135131
function firstchar (str) {
136132
var match = FIRST_CHAR_REGEXP.exec(str)
137133

@@ -144,10 +140,10 @@ function firstchar (str) {
144140
* Normalize a SyntaxError for JSON.parse.
145141
*
146142
* @param {SyntaxError} error
147-
* @param {object} obj
148-
* @return {SyntaxError}
143+
* @param {Object} obj
144+
* @returns {SyntaxError}
145+
* @private
149146
*/
150-
151147
function normalizeJsonSyntaxError (error, obj) {
152148
var keys = Object.getOwnPropertyNames(error)
153149

lib/types/raw.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ module.exports = raw
2323
/**
2424
* Create a middleware to parse raw bodies.
2525
*
26-
* @param {object} [options]
27-
* @return {function}
28-
* @api public
26+
* @param {Object} [options]
27+
* @returns {Function}
28+
* @public
2929
*/
30-
3130
function raw (options) {
3231
const normalizedOptions = normalizeOptions(options, 'application/octet-stream')
3332

lib/types/text.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ module.exports = text
2323
/**
2424
* Create a middleware to parse text bodies.
2525
*
26-
* @param {object} [options]
27-
* @return {function}
28-
* @api public
26+
* @param {Object} [options]
27+
* @returns {Function}
28+
* @public
2929
*/
30-
3130
function text (options) {
3231
const normalizedOptions = normalizeOptions(options, 'text/plain')
3332

lib/types/urlencoded.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ module.exports = urlencoded
2727
/**
2828
* Create a middleware to parse urlencoded bodies.
2929
*
30-
* @param {object} [options]
31-
* @return {function}
30+
* @param {Object} [options]
31+
* @returns {Function}
3232
* @public
3333
*/
34-
3534
function urlencoded (options) {
3635
const normalizedOptions = normalizeOptions(options, 'application/x-www-form-urlencoded')
3736

@@ -62,9 +61,10 @@ function urlencoded (options) {
6261
/**
6362
* Get the extended query parser.
6463
*
65-
* @param {object} options
64+
* @param {Object} options
65+
* @returns {Function}
66+
* @private
6667
*/
67-
6868
function createQueryParser (options) {
6969
var extended = Boolean(options?.extended)
7070
var parameterLimit = options?.parameterLimit !== undefined
@@ -127,8 +127,8 @@ function createQueryParser (options) {
127127
*
128128
* @param {string} body
129129
* @param {number} limit
130-
* @return {number|undefined} Returns undefined if limit exceeded
131-
* @api private
130+
* @returns {number|undefined} Returns undefined if limit exceeded
131+
* @private
132132
*/
133133
function parameterCount (body, limit) {
134134
let count = 0

lib/utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ module.exports = {
2020
/**
2121
* Get the charset of a request.
2222
*
23-
* @param {object} req
24-
* @api private
23+
* @param {Object} req
24+
* @returns {string | undefined}
25+
* @private
2526
*/
26-
2727
function getCharset (req) {
2828
try {
2929
return (contentType.parse(req).parameters.charset || '').toLowerCase()
@@ -36,9 +36,9 @@ function getCharset (req) {
3636
* Get the simple type checker.
3737
*
3838
* @param {string | string[]} type
39-
* @return {function}
39+
* @returns {Function}
40+
* @private
4041
*/
41-
4242
function typeChecker (type) {
4343
return function checkType (req) {
4444
return Boolean(typeis(req, type))
@@ -48,9 +48,10 @@ function typeChecker (type) {
4848
/**
4949
* Normalizes the common options for all parsers.
5050
*
51-
* @param {object} options options to normalize
52-
* @param {string | string[] | function} defaultType default content type(s) or a function to determine it
53-
* @returns {object}
51+
* @param {Object} options options to normalize
52+
* @param {string | string[] | Function} defaultType default content type(s) or a function to determine it
53+
* @returns {Object}
54+
* @private
5455
*/
5556
function normalizeOptions (options, defaultType) {
5657
if (!defaultType) {
@@ -89,7 +90,8 @@ function normalizeOptions (options, defaultType) {
8990
* Used by parsers that don't need to transform the data.
9091
*
9192
* @param {*} value
92-
* @return {*}
93+
* @returns {*}
94+
* @private
9395
*/
9496
function passthrough (value) {
9597
return value

0 commit comments

Comments
 (0)