当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript content-type.parse函数代码示例

本文整理汇总了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;
  }
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:parser.ts

示例2: getCharset

function getCharset (req:Request) {
  try {
    return contentType.parse(req).parameters.charset.toLowerCase()
  } catch (e) {
    return undefined
  }
}
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:7,代码来源:yaml-parser.ts

示例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)
}
开发者ID:blakeembrey,项目名称:node-scrappy,代码行数:7,代码来源:index.ts

示例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
  }
}
开发者ID:abdulhannanali,项目名称:node-scrappy,代码行数:12,代码来源:image.ts

示例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);
    },
  });
}
开发者ID:iblancasa,项目名称:polyserve,代码行数:23,代码来源:custom-elements-es5-adapter-middleware.ts

示例6: supported

export function supported (url: string, headers: Headers) {
  return headers['content-type'] ?
    /^video\//.test(parse(headers['content-type']).type) :
    false
}
开发者ID:abdulhannanali,项目名称:node-scrappy,代码行数:5,代码来源:video.ts

示例7: supported

export function supported (url: string, headers: Headers) {
  return headers['content-type'] ?
    parse(headers['content-type']).type === 'text/html' :
    false
}
开发者ID:abdulhannanali,项目名称:node-scrappy,代码行数:5,代码来源:html.ts

示例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');
开发者ID:types,项目名称:npm-content-type,代码行数:7,代码来源:test.ts

示例9:

http.createServer((req, res) => {
    contentType.parse(req);
    contentType.parse(res);
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:4,代码来源:content-type-tests.ts


注:本文中的content-type.parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。