本文整理汇总了TypeScript中lodash.defaultsdeep.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript defaultsdeep.default方法的具体用法?TypeScript defaultsdeep.default怎么用?TypeScript defaultsdeep.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lodash.defaultsdeep
的用法示例。
在下文中一共展示了defaultsdeep.default方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: serializeResponseFactory
// 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,
};
};
}
示例2: ensureSchemaMiddlewareFactory
// 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();
};
}
示例3: requestLoggerMiddlewareFactory
// 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',
);
}
};
}
示例4: serializeRequestFactory
// 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,
};
};
}