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