| 'use strict' |
|
|
| |
| |
| |
|
|
| var bytes = require('bytes') |
| var contentType = require('content-type') |
| var typeis = require('type-is') |
|
|
| |
| |
| |
| module.exports = { |
| getCharset, |
| normalizeOptions, |
| passthrough |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function getCharset (req) { |
| try { |
| return (contentType.parse(req).parameters.charset || '').toLowerCase() |
| } catch { |
| return undefined |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function typeChecker (type) { |
| return function checkType (req) { |
| return Boolean(typeis(req, type)) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function normalizeOptions (options, defaultType) { |
| if (!defaultType) { |
| |
| throw new TypeError('defaultType must be provided') |
| } |
|
|
| var inflate = options?.inflate !== false |
| var limit = typeof options?.limit !== 'number' |
| ? bytes.parse(options?.limit || '100kb') |
| : options?.limit |
| var type = options?.type || defaultType |
| var verify = options?.verify || false |
| var defaultCharset = options?.defaultCharset || 'utf-8' |
|
|
| if (verify !== false && typeof verify !== 'function') { |
| throw new TypeError('option verify must be function') |
| } |
|
|
| |
| var shouldParse = typeof type !== 'function' |
| ? typeChecker(type) |
| : type |
|
|
| return { |
| inflate, |
| limit, |
| verify, |
| defaultCharset, |
| shouldParse |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function passthrough (value) { |
| return value |
| } |
|
|