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


TypeScript lodash.defaultsdeep类代码示例

本文整理汇总了TypeScript中lodash.defaultsdeep的典型用法代码示例。如果您正苦于以下问题:TypeScript defaultsdeep类的具体用法?TypeScript defaultsdeep怎么用?TypeScript defaultsdeep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了defaultsdeep类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: serializeRequest

// Exports
export default function serializeResponseFactory(options: Partial<SerializeResponseOptions> = {}) {
  const opts = defaultsDeep({}, options, defaultOptions);
  return function serializeRequest(response: Koa.Response) {
    const includeBody = typeof opts.includeBody === 'function' ? opts.includeBody(response) : opts.includeBody;
    return {
      body: includeBody ? response.body : undefined,
      status: response.status,
      header: response.header,
      length: response.length,
      type: response.type,
    };
  };
}
开发者ID:komapijs,项目名称:komapi,代码行数:14,代码来源:serializeResponse.ts

示例2: validate

// Exports
export default function ensureSchemaMiddlewareFactory(
  jsonSchema: object,
  options?: {
    key: 'body' | 'params' | 'query';
    schemaValidator?: Schema;
  },
): Komapi.Middleware {
  const opts = defaultsDeep({}, options, defaultOptions);
  const validate = opts.schemaValidator.createValidator(jsonSchema);
  return async function ensureSchemaMiddleware(ctx, next) {
    const data = (ctx.request as any)[opts.key];
    await validate(data);
    return next();
  };
}
开发者ID:komapijs,项目名称:komapi,代码行数:16,代码来源:ensureSchema.ts

示例3: next

// Exports
export default function requestLoggerMiddlewareFactory(options: Partial<RequestLoggerOptions> = {}): Komapi.Middleware {
  const opts = defaultsDeep({}, options, defaultOptions);
  return async function requestLoggerMiddleware(ctx, next) {
    try {
      await next();
    } finally {
      ctx.request.log[opts.level](
        {
          latency: Math.ceil(Date.now() - ctx.request.startAt),
          request: ctx.request,
          response: ctx.response,
        },
        'Request handled',
      );
    }
  };
}
开发者ID:komapijs,项目名称:komapi,代码行数:18,代码来源:requestLogger.ts

示例4: serializeRequest

// Exports
export default function serializeRequestFactory(options: Partial<SerializeRequestOptions> = {}) {
  const opts = defaultsDeep({}, options, defaultOptions);
  return function serializeRequest(request: Koa.Request) {
    const includeBody = typeof opts.includeBody === 'function' ? opts.includeBody(request) : opts.includeBody;
    return {
      requestId: request.requestId,
      startAt: request.startAt,
      body: includeBody ? (request as { body?: any }).body : undefined,
      header: request.header,
      method: request.method,
      protocol: request.protocol,
      url: request.url,
      query: request.query,
      ip: request.ip,
      referrer: request.header.referer || request.header.referrer,
      userAgent: request.header['user-agent'],
      httpVersion: request.req.httpVersion,
      trailers: request.req.trailers,
    };
  };
}
开发者ID:komapijs,项目名称:komapi,代码行数:22,代码来源:serializeRequest.ts


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