type-is
- Version 3.0.0
- Published
- 27.7 kB
- 1 dependency
- MIT license
Install
npm i type-isyarn add type-ispnpm add type-isOverview
Infer the content-type of a request.
Index
Functions
function DEFAULT_LOOKUP
DEFAULT_LOOKUP: (value: string) => string | string[] | undefined;The default behavior of
lookuphandles only a few common shorthands.
function DEFAULT_PARAMETER_VALUE
DEFAULT_PARAMETER_VALUE: (key: string, value: string) => string;Normalize a parameter value for comparison.
function hasBody
hasBody: (req: RequestLike) => boolean;Check if a request has a request body. A request with a body must either have
transfer-encodingorcontent-lengthheaders set.
function match
match: (expected: string) => (actual: string) => boolean;Compile an expected mime type into a reusable matcher.
function normalize
normalize: (value: string, options?: NormalizeOptions) => string | string[];Normalize MIME type by:
- If the string contains a
/, then it is returned as the type. - If the string starts with+(so it is a+suffixshorthand like+json), then it is expanded to contain the complete wildcard notation of*\/*+suffix. - Else the string is assumed to be a file extension and the mapped media type is returned, or the original input if there is no mapping.
Classes
class TypeIs
class TypeIs {}constructor
constructor(types: readonly string[], options?: TypeIsOptions);Compile a list of expected mime types into a reusable matcher.
method contentType
contentType: ( contentType: Pick<ContentType, 'type' | 'parameters'>) => string | undefined;method is
is: (value: string) => string | undefined;Check whether a content type matches one of the configured types.
method request
request: (req: RequestLike) => string | undefined;Check whether a request body matches one of the configured types.
Interfaces
interface NormalizeOptions
interface NormalizeOptions {}property lookup
lookup?: (value: string) => string | string[] | undefined;interface RequestLike
interface RequestLike {}Node.js HTTP request shape.
property headers
headers: Record<string, string | string[] | undefined>;interface TypeIsOptions
interface TypeIsOptions extends NormalizeOptions {}property parameterValue
parameterValue?: ParameterValue;Type Aliases
type ParameterValue
type ParameterValue = (key: string, value: string) => string;Package Files (1)
Dependencies (1)
Dev Dependencies (5)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/type-is.
- Markdown[](https://www.jsdocs.io/package/type-is)
- HTML<a href="https://www.jsdocs.io/package/type-is"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1331 ms. - Missing or incorrect documentation? Open an issue for this package.
