MCPcopy Create free account
hub / github.com/expressjs/body-parser / normalizeOptions

Function normalizeOptions

lib/utils.js:39–73  ·  view source on GitHub ↗

* Normalizes the common options for all parsers. * * @param {Object} options options to normalize * @param {string | string[] | Function} defaultType default content type(s) or a function to determine it * @returns {Object} * @private

(options, defaultType)

Source from the content-addressed store, hash-verified

37 * @private
38 */
39function normalizeOptions (options, defaultType) {
40 if (!defaultType) {
41 // Parsers must define a default content type
42 throw new TypeError('defaultType must be provided')
43 }
44
45 const inflate = options?.inflate !== false
46 const limit = typeof options?.limit === 'undefined' || options?.limit === null
47 ? 102400 // 100kb default
48 : bytes.parse(options.limit)
49 const type = options?.type || defaultType
50 const verify = options?.verify || false
51 const defaultCharset = options?.defaultCharset || 'utf-8'
52
53 if (limit === null) {
54 throw new TypeError(`option limit "${String(options.limit)}" is invalid`)
55 }
56
57 if (verify !== false && typeof verify !== 'function') {
58 throw new TypeError('option verify must be function')
59 }
60
61 // create the appropriate type checking function
62 const shouldParse = typeof type !== 'function'
63 ? typeChecker(type)
64 : type
65
66 return {
67 inflate,
68 limit,
69 verify,
70 defaultCharset,
71 shouldParse
72 }
73}
74
75/**
76 * Passthrough function that returns input unchanged.

Callers 5

jsonFunction · 0.85
textFunction · 0.85
rawFunction · 0.85
urlencodedFunction · 0.85
utils.jsFile · 0.85

Calls 1

typeCheckerFunction · 0.85

Tested by

no test coverage detected