demo/body-parser/lib/types/text.js
function text (options) {
  var opts = options || {}

  var defaultCharset = opts.defaultCharset || 'utf-8'
  var inflate = opts.inflate !== false
  var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit
  var type = opts.type || 'text/plain'
  var verify = opts.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  // create the appropriate type checking function
  var shouldParse = typeof type !== 'function'
    ? typeChecker(type)
    : type

  function parse (buf) {
    return buf
  }

  return function textParser (req, res, next) {
    if (req._body) {
      debug('body already parsed')
      next()
      return
    }

    req.body = req.body || {}

    // skip requests without bodies
    if (!typeis.hasBody(req)) {
      debug('skip empty body')
      next()
      return
    }

    debug('content-type %j', req.headers['content-type'])

    // determine if request should be parsed
    if (!shouldParse(req)) {
      debug('skip parsing')
      next()
      return
    }

    // get charset
    var charset = getCharset(req) || defaultCharset

    // read
    read(req, res, next, parse, debug, {
      encoding: charset,
      inflate: inflate,
      limit: limit,
      verify: verify
    })
  }
}
function text (options) {
  var opts = options || {}

  var defaultCharset = opts.defaultCharset || 'utf-8'
  var inflate = opts.inflate !== false
  var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit
  var type = opts.type || 'text/plain'
  var verify = opts.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  // create the appropriate type checking function
  var shouldParse = typeof type !== 'function'
    ? typeChecker(type)
    : type

  function parse (buf) {
    return buf
  }

  return function textParser (req, res, next) {
    if (req._body) {
      debug('body already parsed')
      next()
      return
    }

    req.body = req.body || {}

    // skip requests without bodies
    if (!typeis.hasBody(req)) {
      debug('skip empty body')
      next()
      return
    }

    debug('content-type %j', req.headers['content-type'])

    // determine if request should be parsed
    if (!shouldParse(req)) {
      debug('skip parsing')
      next()
      return
    }

    // get charset
    var charset = getCharset(req) || defaultCharset

    // read
    read(req, res, next, parse, debug, {
      encoding: charset,
      inflate: inflate,
      limit: limit,
      verify: verify
    })
  }
}
function text ( options ) { var opts = options || { } var defaultCharset = opts . defaultCharset || 'utf-8' var inflate = opts . inflate !== false var limit = typeof opts . limit !== 'number' ? bytes . parse ( opts . limit || '100kb' ) : opts . limit var type = opts . type || 'text/plain' var verify = opts . verify || false if ( verify !== false && typeof verify !== 'function' ) { throw new TypeError ( 'option verify must be function' ) } // create the appropriate type checking function var shouldParse = typeof type !== 'function' ? typeChecker ( type ) : type function parse ( buf ) { return buf } return function textParser ( req , res , next ) { if ( req . _body ) { debug ( 'body already parsed' ) next ( ) return } req . body = req . body || { } // skip requests without bodies if ( ! typeis . hasBody ( req ) ) { debug ( 'skip empty body' ) next ( ) return } debug ( 'content-type %j' , req . headers [ 'content-type' ] ) // determine if request should be parsed if ( ! shouldParse ( req ) ) { debug ( 'skip parsing' ) next ( ) return } // get charset var charset = getCharset ( req ) || defaultCharset // read read ( req , res , next , parse , debug , { encoding : charset , inflate : inflate , limit : limit , verify : verify } ) } }
Create a middleware to parse text bodies.

@param {object} [options]
@return {function}
@api public
Create a middleware to parse text bodies .