type-is
3.0.0 · 21 Sep 2026MIT211.4M / weekRepositoryHomepagenpmAtom feed
In short
5 changed
Release note
This version switches the package to ESM and node >= 22.
Changed:
Publish the package as ESM and bump to node 22 (#106)
Publishes built-in types using TypeScript (#94)
Refactors the API shape to a class (#103)
2-4x faster by initializing the class once (instead of every request)
20% faster by initializing inline (e.g. every request)
Added support for matching parameters too (e.g.
text/html; charset=utf-8)Returns the original input string not the matched MIME type
Previously
text/*would return e.g.text/htmlon match, now it returns the originaltext/*
Returns
undefinedinstead offalseon no matchReturns
undefinedwhen no input types are definedThrows on invalid MIME type used to construct the matcher (e.g.
new TypeIs(["invalid"]), it does not error if the header is invalid)
Matches return the original input string (#109)
Removed:
Removes
mime-typesfrom the package, only has 3 built in "shortcuts" (e.g.json->application/json)Pass
mime-types.lookupas an option to override
Before:
const isText = typeis(req, ['text/*'])
After:
const isText = new TypeIs(['text/*']).request(req);
If you are upgrading an upstream dependency (e.g. express), and want maximum compatibility, something like this can help with compatibility for the extension aliases:
import * as mimeTypes from 'mime-types';
import { TypeIs, DEFAULT_LOOKUP } from 'type-is';
function lookup (value) {
return mimeTypes.lookup(value) || DEFAULT_LOOKUP(value);
}
req.is = function (types) {
const matcher = new TypeIs(types, { lookup });
return matcher.request(this);
};However the returned string has changed. Backward compatibility with the old string is achievable by mimicking the old behavior -- parse the MIME type yourself (example) and use the matcher.contentType method. This is not recommended though.