Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

type-is

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-is - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

8

HISTORY.md

@@ -0,2 +1,10 @@

1.2.0 / 2014-05-11
==================
* support suffix matching:
- `+json` matches `application/vnd+json`
- `*/vnd+json` matches `application/vnd+json`
- `application/*+json` matches `application/vnd+json`
1.1.0 / 2014-04-12

@@ -3,0 +11,0 @@ ==================

47

index.js

@@ -38,5 +38,9 @@

var type;
for (var i = 0; i < types.length; i++)
if (mimeMatch(normalize(type = types[i]), value))
return ~type.indexOf('*') ? value : type;
for (var i = 0; i < types.length; i++) {
if (mimeMatch(normalize(type = types[i]), value)) {
return type[0] === '+' || ~type.indexOf('*')
? value
: type
}
}

@@ -124,3 +128,5 @@ // no matches

return ~type.indexOf('/') ? type : mime.lookup(type);
return type[0] === '+' || ~type.indexOf('/')
? type
: mime.lookup(type)
}

@@ -131,3 +137,3 @@

* matches `actual` mime type with
* wildcard support.
* wildcard and +suffix support.
*

@@ -143,10 +149,33 @@ * @param {String} expected

actual = actual.split('/');
if (expected[0] === '+') {
// support +suffix
return Boolean(actual[1])
&& expected.length <= actual[1].length
&& expected === actual[1].substr(0 - expected.length)
}
if (!~expected.indexOf('*')) return false;
actual = actual.split('/');
expected = expected.split('/');
if ('*' === expected[0] && expected[1] === actual[1]) return true;
if ('*' === expected[1] && expected[0] === actual[0]) return true;
return false;
if (expected[0] === '*') {
// support */yyy
return expected[1] === actual[1]
}
if (expected[1] === '*') {
// support xxx/*
return expected[0] === actual[0]
}
if (expected[1][0] === '*' && expected[1][1] === '+') {
// support xxx/*+zzz
return expected[0] === actual[0]
&& expected[1].length <= actual[1].length + 1
&& expected[1].substr(1) === actual[1].substr(1 - expected[1].length)
}
return false
}
{
"name": "type-is",
"description": "Infer the content type if a request",
"version": "1.1.0",
"version": "1.2.0",
"author": {

@@ -11,6 +11,12 @@ "name": "Jonathan Ong",

},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"repository": "expressjs/type-is",
"dependencies": {
"mime": "~1.2.11"
"mime": "1.2.11"
},

@@ -21,2 +27,5 @@ "devDependencies": {

},
"engines": {
"node": ">= 0.8"
},
"scripts": {

@@ -23,0 +32,0 @@ "test": "mocha --require should --reporter spec --bail"

3

README.md

@@ -1,2 +0,2 @@

# Type Is [![Build Status](https://travis-ci.org/expressjs/type-is.png)](https://travis-ci.org/expressjs/type-is)
# type-is [![Build Status](https://travis-ci.org/expressjs/type-is.svg?branch=master)](https://travis-ci.org/expressjs/type-is) [![NPM version](https://badge.fury.io/js/type-is.svg)](https://badge.fury.io/js/type-is)

@@ -51,2 +51,3 @@ Infer the content type of a request.

- A mime type with a wildcard such as `*/json` or `application/*`. The full mime type will be returned if matched
- A suffix such as `+json`. This can be combined with a wildcard such as `*/vnd+json` or `application/*+json`. The full mime type will be returned if matched.

@@ -53,0 +54,0 @@ `false` will be returned if no type matches.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc