本文整理汇总了TypeScript中content-type.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: safeParseContentType
/**
* wrap parse content type, as it may throw exception
*/
function safeParseContentType(req: Request) {
try {
return just(parseContentType(req));
} catch {
return nothing;
}
}
示例2: getCharset
function getCharset (req:Request) {
try {
return contentType.parse(req).parameters.charset.toLowerCase()
} catch (e) {
return undefined
}
}
示例3: scrapeResponse
export async function scrapeResponse (res: Response, plugin?: Plugin) {
const { url, headers } = res
const encodingFormat = headers['content-type'] ? parse(String(headers['content-type'])).type : undefined
const contentSize = Number(headers['content-length']) || undefined
return scrapeStream(res.stream, { url, encodingFormat, contentSize }, res.abort, plugin)
}
示例4: handle
export function handle (url: string, headers: Headers, stream: Readable, abort: AbortFn): Result {
// Immediately abort streaming image data.
abort()
return {
type: 'image',
contentUrl: url,
contentSize: headers['content-length'] ? Number(headers['content-length']) : undefined,
encodingFormat: parse(headers['content-type']).type.substr(6),
uploadDate: headers['last-modified'] ? new Date(headers['last-modified'] as string) : undefined
}
}
示例5: injectCustomElementsEs5Adapter
export function injectCustomElementsEs5Adapter(forceCompile: boolean):
RequestHandler {
return transformResponse({
shouldTransform(request: Request, response: Response): boolean {
const contentTypeHeader = response.get('Content-Type');
const contentType =
contentTypeHeader && parseContentType(contentTypeHeader).type;
// We only need to inject the adapter if we are compiling to ES5.
return contentType === 'text/html' &&
(forceCompile ||
!browserCapabilities(request.get('user-agent')).has('es2015'));
},
transform(_request: Request, _response: Response, body: string): string {
// TODO(aomarks) This function will make no changes if the body does
// not find a web components polyfill script tag. This is the heuristic
// we use to determine if a file is the entry point. We would instead
// be able to check explicitly for the entry point in `shouldTransform`
// if we had the project config available.
return addCustomElementsEs5Adapter(body);
},
});
}
示例6: supported
export function supported (url: string, headers: Headers) {
return headers['content-type'] ?
/^video\//.test(parse(headers['content-type']).type) :
false
}
示例7: supported
export function supported (url: string, headers: Headers) {
return headers['content-type'] ?
parse(headers['content-type']).type === 'text/html' :
false
}
示例8: require
/// <reference path="bundle.d.ts" />
/// <reference path="typings/index.d.ts" />
import { parse } from 'content-type';
import assert = require('assert');
assert.equal(parse('text/html; charset=utf-8').type, 'text/html');
示例9:
http.createServer((req, res) => {
contentType.parse(req);
contentType.parse(res);
});