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


TypeScript hoek.assert函数代码示例

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


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

示例1: function

internals['implementation'] = function(server, options) {
	const results = Joi.validate(options, internals['schema']);
	Hoek.assert(!results.error, results.error);

	const settings = results.value;

	const scheme = {
		authenticate: function(request, reply) {
			const validate = function() {
				// Check session
				const session = request.yar.get(settings.session);
				if (!session) {
					return reply(Boom.unauthorized(null, 'session'));
				}

				if (!settings.validateFunc) {
					if (settings.keepAlive) {
						request.yar.set(settings.session, session);
					}
					return reply.continue({ credentials: session, artifacts: session });
				}

				settings.validateFunc(request, session, (err, isValid, userData) => {
					if (err || !isValid) {
						if (settings.clearInvalid) {
							request.yar.clear(settings.session);
						}
						return reply(Boom.unauthorized('Invalid session'), { credentials: userData || session, artifacts: session });
					}

					if (settings.keepAlive) {
						request.yar.set(settings.session, session);
					}

					return reply.continue({ credentials: userData || session, artifacts: session });
				});
			}
			validate();
		}
	}
	return scheme;
};
开发者ID:starlightslo,项目名称:hapi-ts-gulp-mvc-example,代码行数:42,代码来源:hapi-auth-local.ts

示例2: Error

const escapedString = Hoek.escapeHtml(string); // returns <html> hey </html>

// escapeHeaderAttribute(attribute)

a = Hoek.escapeHeaderAttribute('I said "go w\\o me"');  // returns I said \"go w\\o me\"

// escapeRegex(string)

a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\/`"(>)[<]d{}s,');  // returns 4\^f\$s\.4\*5\+\-_\?%\=#\!\:@\|~\\\/`"\(>\)\[<\]d\{\}s\,

// assert(condition, message)

const x = 1;
const y = 2 as number;

Hoek.assert(x === y, 'x should equal y');  // Throws 'x should equal y'

Hoek.assert(x === y, new Error('x should equal y')); // Throws the given error object

// abort(message)

Hoek.abort("Error message");

// displayStack(slice)

const stack = Hoek.displayStack();
console.log(stack);

// callStack(slice)

const stack2 = Hoek.callStack();
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:31,代码来源:hoek-tests.ts

示例3:

server.initialize((err) => {

    Hoek.assert(!err, err);
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:4,代码来源:initialize.ts

示例4:

server.start((err) => {

    Hoek.assert(!err, err!);
    console.log('Server started at: ' + server.info!.uri);
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:5,代码来源:start.ts


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