How to use the assert function from hoek
Find comprehensive JavaScript hoek.assert code examples handpicked from public code repositorys.
52 53 54 55 56 57 58 59 60 61
internals.Alternatives.prototype.try = function (/* schemas */) { var schemas = Hoek.flatten(Array.prototype.slice.call(arguments)); Hoek.assert(schemas.length, 'Cannot add other alternatives without at least one schema'); var obj = this.clone(); for (var i = 0, il = schemas.length; i < il; ++i) {
813
0
2
+ 53 other calls in file
GitHub: devinivy/dogwater
40 41 42 43 44 45 46 47 48 49
const collector = rootState.collector; const defaults = options.defaults || {}; Object.keys(defaults).forEach((key) => { Hoek.assert(!collector.defaults[key], `Default for "${key}" has already been set.`); collector.defaults[key] = defaults[key]; }); // Decide whether server stop should teardown
14
102
9
+ 9 other calls in file
GitHub: olistic/joi-extended
48 49 50 51 52 53 54 55 56 57
if (Array.isArray(opt)) { type = opt[0]; values = opt.slice(1); } Hoek.assert(type, 'unknown key ' + key); Hoek.assert(typeof options[key] === type, key + ' should be of type ' + type); if (values) { Hoek.assert(values.indexOf(options[key]) >= 0, key + ' should be one of ' + values.join(', ')); }
0
2
0
+ 13 other calls in file
GitHub: bevacqua/even-better
131 132 133 134 135 136 137 138 139
// If the supply a path or module node, try to load it if (typeof item.reporter === 'string') { item.reporter = require(item.reporter); } Hoek.assert(typeof item.reporter === 'function', 'reporter key must be a constructor function'); Hoek.assert(typeof item.events === 'object', 'reporter must specify events to filter on'); var Reporter = item.reporter;
165
1
2
+ 9 other calls in file
GitHub: Marsup/catbox
11 12 13 14 15 16 17 18 19 20
}; exports = module.exports = internals.Policy = function (options, cache, segment) { Hoek.assert(this.constructor === internals.Policy, 'Cache Policy must be instantiated using new'); this._cache = cache; this._pendings = {}; // id -> [callbacks] this.rules(options);
74
0
2
+ 3 other calls in file
11 12 13 14 15 16 17 18 19
} } class Connection { constructor (options) { Hoek.assert( this.constructor === Connection, 'Redis cache client must be instantiated using new' )
62
49
28
113 114 115 116 117 118 119 120 121
viewContext ); }, async sendInviteEmail(user, client, hoursTilExpiration, templateOverride, query, saveOptions) { Hoek.assert(Hoek.contain( Object.keys(query), ['client_id', 'redirect_uri', 'scope', 'response_type'], ), new Error('query must contain client_id, redirect_uri, response_type, and scope'));
5
18
29
11 12 13 14 15 16 17 18 19
name: 'hapi-auth-cookie-jwt' }; internals.implementation = (server, options) => { Hoek.assert(options, 'Missing jwt auth strategy options'); Hoek.assert(options.key, 'Missing required private key in configuration'); const settings = Hoek.clone(options);
2
6
1
+ 3 other calls in file
GitHub: ferlores/good
33 34 35 36 37 38 39 40 41 42
module.exports = internals.Monitor = function (plugin, options) { options = options || {}; Hoek.assert(this.constructor === internals.Monitor, 'Monitor must be instantiated using new'); Hoek.assert(plugin, 'plugin required to create monitor'); options = Hoek.applyToDefaultsWithShallow(internals.defaults, options, ['reporters', 'httpAgents', 'httpsAgents']); // Force them to be arrays
165
1
2
+ 7 other calls in file
82 83 84 85 86 87 88 89 90 91
// Determine the submission status const submission = await Submission.getSubmissionForEaIdAndYear(userContext.eaId.id, userContext.year); const submissionStatus = submission ? submission.status : Submission.submissionStatusCodes.INCOMPLETE; Hoek.assert(Object.values(Submission.submissionStatusCodes).includes(submissionStatus), `Unknown submission status: ${submissionStatus}`); if (editSubmission.includes(request.path)) { if (submissionStatus === Submission.submissionStatusCodes.INCOMPLETE) {
1
1
6
98 99 100 101 102 103 104 105 106 107
continue; } const securityDefinition = api.securityDefinitions[securityDefinitionName]; Hoek.assert(securityDefinition, 'Security scheme not defined.'); options.auth = options.auth || { access: {}, mode: 'required' }; options.auth.access.scope = options.auth.access.scope || []; options.auth.access.scope.push(...secdef[securityDefinitionName]);
75
0
1
GitHub: WesTyler/hapi
45 46 47 48 49 50 51 52 53 54
return request; } decorate(property, method, options) { Hoek.assert(internals.properties.indexOf(property) === -1, 'Cannot override built-in request interface decoration:', property); this._decorations = this._decorations || {}; this._decorations[property] = { method, apply: options.apply }; }
0
1
2
+ 15 other calls in file
GitHub: jmonster/good
13 14 15 16 17 18 19 20 21 22
* * @api public */ module.exports.Monitor = internals.OSMonitor = function () { Hoek.assert(this.constructor === internals.OSMonitor, 'OSMonitor must be instantiated using new'); this.builtins = ['loadavg', 'uptime', 'freemem', 'totalmem', 'cpus']; // Expose Node os functions as async fns
165
0
1
GitHub: jmonster/good
13 14 15 16 17 18 19 20 21
* * @api public */ module.exports.Monitor = internals.ProcessMonitor = function (options) { Hoek.assert(this.constructor === internals.ProcessMonitor, 'ProcessMonitor must be instantiated using new'); options = options || {}; this.builtins = ['uptime', 'memoryUsage'];
165
0
1
GitHub: dominykas/nes
211 212 213 214 215 216 217 218 219
}); internals.Listener.subscription = function (path, options) { Hoek.assert(path, 'Subscription missing path'); Joi.assert(options, internals.subSchema, 'Invalid subscription options: ' + path); const settings = Hoek.clone(options || {});
86
0
2
+ 3 other calls in file
GitHub: firstandthird/catbox
56 57 58 59 60 61 62 63 64 65
}; exports = module.exports = internals.Policy = function (options, cache, segment) { Hoek.assert(this instanceof internals.Policy, 'Cache Policy must be instantiated using new'); this._cache = cache; this._pendings = Object.create(null); // id -> PendingResponse this._pendingGenerateCall = Object.create(null); // id -> boolean
74
0
3
+ 3 other calls in file
GitHub: rluba/bell
98 99 100 101 102 103 104 105 106 107
settings.name = settings.provider; settings.provider = Providers[settings.provider].call(null, settings.config); } const results = Joi.validate(settings, internals.schema); Hoek.assert(!results.error, results.error); // Passed validation, use Joi converted settings settings = results.value;
210
0
2
GitHub: codedebug/wreck
76 77 78 79 80 81 82 83 84 85
'options.agent cannot be set to an Agent at the same time as options.rejectUnauthorized is set'); Hoek.assert(options.beforeRedirect === undefined || options.beforeRedirect === null || typeof options.beforeRedirect === 'function', 'options.beforeRedirect must be a function'); Hoek.assert(options.redirected === undefined || options.redirected === null || typeof options.redirected === 'function', 'options.redirected must be a function'); if (options.baseUrl) { url = internals.resolveUrl(options.baseUrl, url);
107
0
2
+ 7 other calls in file
GitHub: devinivy/gert
6 7 8 9 10 11 12 13 14 15
var internals = {}; exports = module.exports = internals.Graph = function (definition) { var validated = Joi.validate(definition, Schema.definition); Hoek.assert(!validated.error, validated.error); definition = internals.normalizeDefinition(validated.value); this.directed = definition.directed;
3
19
6
+ 11 other calls in file
GitHub: isNan909/joi
47 48 49 50 51 52 53 54 55
const test = ([name, initFn, testFn]) => { const [schema, valid, invalid] = initFn(); Hoek.assert(valid === undefined || testFn(schema, valid).error === null, 'validation must not fail for: ' + name); Hoek.assert(invalid === undefined || testFn(schema, invalid).error !== null, 'validation must fail for: ' + name); Suite.add(name + (valid !== undefined ? ' (valid)' : ''), () => {
0
1
2
hoek.assert is the most popular function in hoek (1712 examples)