How to use the type-is.is function in type-is

To help you get started, we’ve selected a few type-is 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 eggjs / egg-security / lib / middlewares / csrf.js View on Github external
// ensure csrf token exists
    if (utils.checkCsrfType(options.type).shouldCheckCtoken) {
      ctx.ensureCsrfSecret();
    }

    // ignore requests: get, head, options and trace
    const method = ctx.method;
    if (method === 'GET' ||
      method === 'HEAD' ||
      method === 'OPTIONS' ||
      method === 'TRACE') {
      return next();
    }

    if (options.ignoreJSON && typeis.is(ctx.get('content-type'), 'json')) {
      return next();
    }

    const body = ctx.request.body || {};
    debug('%s %s, got %j', ctx.method, ctx.url, body);
    ctx.assertCsrf();
    return next();
  };
};
github ynnjs / ynn / lib / rsc.js View on Github external
options.headers[ name.toLowerCase() ] = headers[ name ];
        }

        // params can be set to null and to set full options for request in options
        if( params ) {

            params = Object.assign( {}, config.params || {}, api.params || {}, params );

            if( options.method === 'GET' || options.method === 'HEAD' ) {
                options.qs = Object.assign( rscqs( this ), params );
            } else {
                const ct = options.headers[ 'content-type' ];

                if( typeis.is( ct, 'application/json' ) ) {
                    options.body = params;
                } else if( typeis.is( ct, 'multipart/form-data' ) ) {
                    options.formData = params;
                } else if( typeis.is( ct, 'multipart/related' ) ) {
                    options.multipart = params;
                } else if( typeis.is( ct, 'text/xml' ) ) {
                    options.body = params.body;
                } else {
                    options.form = params;
                }
                options.qs = rscqs( this );
            }
        }
        if( opt.qs ) {
            Object.assign( options.qs, opt.qs );
        }
        options.json = is.undefined( opt.json ) ? true : opt.json;
        return options;
github stoplightio / prism / test-harness / helpers.ts View on Github external
test: (contentType: string, content: string) => {
    const doesContentTypeMatch = !!typeIs.is(contentType, [
      'application/xml',
      'application/*+xml',
      'text/xml',
    ]);
    const isContentXML = parser.validate(content) === true;

    return doesContentTypeMatch || isContentXML;
  },
  validate: (expected: Result, output: Result) => {
github toajs / toa / lib / response.js View on Github external
is: function (types) {
    let type = this.type
    if (!types) return type || false
    if (!Array.isArray(types)) types = [].slice.call(arguments)
    return typeis(type, types)
  },
github thenables / requisition / lib / response.js View on Github external
Response.prototype.is = function (types) {
  var type = this.headers['content-type'];
  if (!type) return false;
  if (!Array.isArray(types)) types = slice.call(arguments);
  return typeis(type, types);
}
github bda-research / node-crawler / lib / crawler.js View on Github external
try{
		self._doEncoding(options,response);
	}catch(e){
		log('error',e);
		return options.callback(e,{options:options},options.release);
	}

	response.options = options;

	if(options.method === 'HEAD' || !options.jQuery){
		return options.callback(null,response,options.release);
	}

	var injectableTypes = ['html','xhtml','text/xml', 'application/xml', '+xml'];
	if (!options.html && !typeis(contentType(response), injectableTypes)){
		log('warn','response body is not HTML, skip injecting. Set jQuery to false to suppress this message');
		return options.callback(null,response,options.release);
	}

	log('debug','Injecting');

	self._inject(response, options, self._injected.bind(self));
};
github ehmicky / autoserver / src / formats / get.js View on Github external
  return mimes.some(mimeA => isType(mime, mimeA) || isType(mimeA, mime))
}
github dazejs / daze / packages / framework / src / request / index.ts View on Github external
is(...types: any[]) {
    return typeIs(this.getHeader('content-type') as string, types);
  }
github ynnjs / ynn / lib / rsc.js View on Github external
if( params ) {

            params = Object.assign( {}, config.params || {}, api.params || {}, params );

            if( options.method === 'GET' || options.method === 'HEAD' ) {
                options.qs = Object.assign( rscqs( this ), params );
            } else {
                const ct = options.headers[ 'content-type' ];

                if( typeis.is( ct, 'application/json' ) ) {
                    options.body = params;
                } else if( typeis.is( ct, 'multipart/form-data' ) ) {
                    options.formData = params;
                } else if( typeis.is( ct, 'multipart/related' ) ) {
                    options.multipart = params;
                } else if( typeis.is( ct, 'text/xml' ) ) {
                    options.body = params.body;
                } else {
                    options.form = params;
                }
                options.qs = rscqs( this );
            }
        }
        if( opt.qs ) {
            Object.assign( options.qs, opt.qs );
        }
        options.json = is.undefined( opt.json ) ? true : opt.json;
        return options;
    }
github stoplightio / prism / packages / http / src / utils / parseResponse.ts View on Github external
() =>
      typeIs(response.headers.get('content-type') || '', ['application/json', 'application/*+json'])
        ? response.json()
        : response.text(),
    E.toError

type-is

Infer the content-type of a request.

MIT
Latest version published 6 years ago

Package Health Score

76 / 100
Full package analysis

Popular type-is functions