當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。