本文整理汇总了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;
};
示例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();
示例3:
server.initialize((err) => {
Hoek.assert(!err, err);
});
示例4:
server.start((err) => {
Hoek.assert(!err, err!);
console.log('Server started at: ' + server.info!.uri);
});