MCPcopy
hub / github.com/expressjs/body-parser / normalizeOptions

Function normalizeOptions

lib/utils.js:54–88  ·  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

52 * @private
53 */
54function normalizeOptions (options, defaultType) {
55 if (!defaultType) {
56 // Parsers must define a default content type
57 throw new TypeError('defaultType must be provided')
58 }
59
60 const inflate = options?.inflate !== false
61 const limit = typeof options?.limit === 'undefined' || options?.limit === null
62 ? 102400 // 100kb default
63 : bytes.parse(options.limit)
64 const type = options?.type || defaultType
65 const verify = options?.verify || false
66 const defaultCharset = options?.defaultCharset || 'utf-8'
67
68 if (limit === null) {
69 throw new TypeError(`option limit "${String(options.limit)}" is invalid`)
70 }
71
72 if (verify !== false && typeof verify !== 'function') {
73 throw new TypeError('option verify must be function')
74 }
75
76 // create the appropriate type checking function
77 const shouldParse = typeof type !== 'function'
78 ? typeChecker(type)
79 : type
80
81 return {
82 inflate,
83 limit,
84 verify,
85 defaultCharset,
86 shouldParse
87 }
88}
89
90/**
91 * 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…