How to use the media-typer.parse function in media-typer

To help you get started, we’ve selected a few media-typer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Lapple / ErrorBoard / node_modules / express / lib / utils.js View on Github external
exports.setCharset = function(type, charset){
  if (!type || !charset) return type;

  // parse type
  var parsed = typer.parse(type);

  // set charset
  parsed.parameters.charset = charset;

  // format type
  return typer.format(parsed);
};
github apiaryio / gavel.js / lib / mixins / validatable-http-message.js View on Github external
isJsonContentType(contentTypeValue) {
    if (!contentTypeValue) {
      return false;
    }
    try {
      const { type } = contentType.parse(`${contentTypeValue}`);
      const parsed = mediaTyper.parse(type);
      return (
        (parsed.type === 'application' && parsed.subtype === 'json') ||
        parsed.suffix === 'json'
      );
    } catch (e) {
      // The Content-Type value is basically a user input, it can be any
      // kind of rubbish, and it is neither this function's nor Gavel's problem
      // if it's invalid
      return false;
    }
  }
}
github alex-cory / fasthacks / Dev_Notes / JavaScript / nodejs / nodeJS examples / node_modules / express / lib / utils.js View on Github external
exports.setCharset = function(type, charset){
  if (!type || !charset) return type;

  // parse type
  var parsed = typer.parse(type);

  // set charset
  parsed.parameters.charset = charset;

  // format type
  return typer.format(parsed);
};
github stimulant / ampm / node_modules / express / lib / utils.js View on Github external
exports.setCharset = function(type, charset){
  if (!type || !charset) return type;

  // parse type
  var parsed = typer.parse(type);

  // set charset
  parsed.parameters.charset = charset;

  // format type
  return typer.format(parsed);
};
github ethereum / meteor-dapp-whisper-chat-client / dist / bundle / programs / server / npm / iron:router / node_modules / body-parser / lib / types / urlencoded.js View on Github external
return function urlencodedParser(req, res, next) {
    if (req._body) return next();
    req.body = req.body || {}

    if (!typeis(req, type)) return next();

    var charset = typer.parse(req).parameters.charset || 'utf-8'
    if (charset.toLowerCase() !== 'utf-8') {
      var err = new Error('unsupported charset')
      err.status = 415
      next(err)
      return
    }

    // read
    read(req, res, next, parse, {
      encoding: charset,
      inflate: inflate,
      limit: limit,
      verify: verify
    })
  }
}
github adonisjs / adonis-framework / packages / bodyparser / src / Multipart / File.ts View on Github external
private _parseContentType () {
    try {
      const parsed = mediaTyper.parse(this._data.headers['content-type'])
      this.type = parsed.type
      this.subtype = parsed.subtype
    } catch (error) {
    }
  }
github zeit / micro / lib / server.js View on Github external
Promise.resolve().then(() => {
    const type = req.headers['content-type'] || 'text/plain'
    const length = req.headers['content-length']
    encoding = encoding === undefined
      ? typer.parse(type).parameters.charset
      : encoding

    const body = rawBodyMap.get(req)

    if (body) {
      return body
    }

    return getRawBody(req, { limit, length, encoding })
      .then(buf => {
        rawBodyMap.set(req, buf)
        return buf
      })
      .catch(err => {
        if (err.type === 'entity.too.large') {
          throw createError(413, `Body exceeded ${limit} limit`, err)
github Borewit / music-metadata / lib / ParserFactory.ts View on Github external
export function parseHttpContentType(contentType: string): { type: string, subtype: string, suffix?: string, parameters: { [id: string]: string; } } {
  const type = ContentType.parse(contentType);
  const mime = MimeType.parse(type.type);
  return {
    type: mime.type,
    subtype: mime.subtype,
    suffix: mime.suffix,
    parameters: type.parameters
  };
}
github jeromeetienne / better.js / contribs / tmp-to-remove / connectBetterjs / node_modules / express / node_modules / type-is / index.js View on Github external
function typenormalize(value) {
  try {
    var type = typer.parse(value)
    delete type.parameters
    return typer.format(type)
  } catch (err) {
    return null
  }
}

media-typer

Simple RFC 6838 media type parser and formatter

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular media-typer functions