How to use the arrayOfObject function from assert-plus
Find comprehensive JavaScript assert-plus.arrayOfObject code examples handpicked from public code repositorys.
assert-plus.arrayOfObject is a function that verifies whether the given argument is an array of objects or not, throwing an error if the condition is not met.
65 66 67 68 69 70 71 72 73 74
var log = api.log; return function filterOwnerListNetworks(opts, networks) { assert.object(opts, 'opts'); assert.object(opts.account, 'opts.account'); assert.arrayOfObject(networks, 'networks'); log.debug('Running ' + filterOwnerListNetworks.name); var accountUuid = opts.account.uuid;
93 94 95 96 97 98 99 100 101 102
assert.object(opts, 'opts'); assert.string(opts.type, 'opts.type'); assert.optionalString(opts.desc, 'opts.desc'); assert.string(opts.idField, 'opts.idField'); assert.arrayOfObject(opts.have, 'opts.have'); assert.arrayOfObject(opts.want, 'opts.want'); assert.optionalFunc(opts.crudChangesForCreate, 'opts.crudChangesForCreate'); assert.optionalFunc(opts.crudChangesForDelete, 'opts.crudChangesForDelete'); assert.optionalFunc(opts.normThing, 'opts.normThing'); assert.optionalFunc(opts.crudChangesForUpdate, 'opts.crudChangesForUpdate');
+ 2 other calls in file
How does assert-plus.arrayOfObject work?
assert-plus.arrayOfObject
is a function provided by the assert-plus library in Node.js that checks if a given value is an array of objects, throwing an error if the value fails this check. It takes in a value as its argument, and checks whether the value is an array containing only objects, throwing an AssertionError if the check fails. If the check passes, it simply returns without any errors.
3610 3611 3612 3613 3614 3615 3616 3617 3618 3619
CloudApi.prototype.waitForDiskCreate = function waitForDiskCreate(opts, cb) { var self = this; assert.object(opts, 'opts'); assert.uuid(opts.id, 'opts.id'); assert.arrayOfObject(opts.disks, 'opts.disks'); assert.ok(opts.size, 'opts.size'); assert.optionalNumber(opts.waitTimeout, 'opts.waitTimeout'); assert.optionalNumber(opts.interval, 'opts.interval'); assert.func(cb, 'cb');
+ 6 other calls in file
217 218 219 220 221 222 223 224 225 226
// Ensure the RBAC settings (subusers, policies, roles) on the given account // are set as given. function _ensureRbacSettings(opts, cb) { assert.object(opts.t, 'opts.t'); assert.object(opts.account, 'opts.account'); assert.arrayOfObject(opts.subusers, 'opts.subusers'); assert.arrayOfObject(opts.policies, 'opts.policies'); assert.arrayOfObject(opts.roles, 'opts.roles'); assert.func(cb, 'cb');
+ 5 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const assert = require("assert-plus"); function printNames(names) { assert.arrayOfObject(names, "names"); names.forEach((name) => { console.log(name.first + " " + name.last); }); } const people = [ { first: "John", last: "Doe" }, { first: "Jane", last: "Doe" }, { first: "Bob", last: "Smith" }, ]; printNames(people);
In this example, we define a printNames function that expects an array of objects representing people's names. We use assert-plus.arrayOfObject to ensure that the names parameter is an array of objects, and throw an error if it isn't.
986 987 988 989 990 991 992 993 994 995 996 997 998
return pkgSizeGiB + ' GiB'; } function formatVolumeSizes(volumePkgs) { assert.arrayOfObject(volumePkgs, 'volumePkgs'); // // return an array of: //
+ 3 other calls in file
999 1000 1001 1002 1003 1004 1005 1006 1007 1008
} catch (parseErr) { next(parseErr); return; } mod_assert.arrayOfObject(parsedVmVolumesInternalMetadata, 'parsedVmVolumesInternalMetadiata'); volumeNames = parsedVmVolumesInternalMetadata.map( function getVolNames(volume) {
+ 3 other calls in file
101 102 103 104 105 106 107 108 109 110 111 112 113
} util.inherits(VolumeInUseError, restify.RestError); function ValidationError(causes) { assert.arrayOfObject(causes, 'causes'); restify.RestError.call(this, { restCode: 'ValidationError', statusCode: 409,
GitHub: TritonDataCenter/sdc-manta
2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
args.columnsSelected, 'args.columnsSelected' ); assertplus.arrayOfString(args.columnsDefault, 'args.columnsDefault'); assertplus.object(args.columnMetadata, 'args.columnMetadata'); assertplus.arrayOfObject(args.rows, 'args.rows'); assertplus.optionalBool(args.omitHeader, 'args.omitHeader'); colnames = args.columnsSelected || args.columnsDefault; columns = colnames.map(function(colname) {
1148 1149 1150 1151 1152 1153 1154 1155 1156
assert.object(vmobj, 'vmobj'); assert.object(opts, 'opts'); assert.func(handler, 'handler'); if (evtName === 'modify') { assert.arrayOfObject(opts.changes, 'opts.changes'); } var handlerObj;
+ 3 other calls in file
671 672 673 674 675 676 677 678 679 680
* a list of changes of the form `{type: <type>, url: <url>}` where * `type` is one of 'reorder', 'add', 'del'. */ IMGADM.prototype.updateSources = function updateSources( sourcesInfo, skipPingCheck, callback) { assert.arrayOfObject(sourcesInfo, 'sourcesInfo'); assert.bool(skipPingCheck, 'skipPingCheck'); assert.func(callback, 'callback'); var self = this; var i, j;
+ 5 other calls in file
55 56 57 58 59 60 61 62 63 64 65 66
function runValidTestCase(t, testCase, callback) { assert.object(t, 't'); assert.object(testCase, 'testCase'); assert.arrayOfString(testCase.queryStrings, 'testCase.queryStrings'); assert.arrayOfObject(testCase.vmsToCreate, 'testCase.vmsToCreate'); assert.func(callback, 'callback'); var createdVmUuids = []; var vmsToCreate = testCase.vmsToCreate;
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
* filters. An empty list is returned if a filter is not required for the * corresponding marker and sortOptions. */ function _buildFiltersFromMarker(marker, sortOptions) { assert.object(marker, 'marker must be an object'); assert.arrayOfObject(sortOptions, 'sortOptions must be an array of objects'); var markerFilters = [];
+ 2 other calls in file
57 58 59 60 61 62 63 64 65 66
*/ function channelInfoFromConfig(config) { if (!config.channels) { return null; } assert.arrayOfObject(config.channels, 'config.channels'); if (config.channels.length === 0) { assert.ok(false, 'empty "config.channels" array'); } var channelFromName = {};
378 379 380 381 382 383 384 385 386 387
'options.contentDisposition'); assert.number(options.contentLength, 'options.contentLength'); assert.string(options.contentMD5, 'options.contentMD5'); assert.string(options.contentType, 'options.contentType'); assert.string(options.objectId, 'options.objectId'); assert.arrayOfObject(options.sharks, 'options.sharks'); if (!process.env.NODE_NDEBUG) { options.sharks.forEach(function validateShark(s) { assert.string(s.manta_storage_id,
263 264 265 266 267 268 269 270 271 272 273
* the presence of '--' will stop option parsing, as all good * option parsers should. */ function Parser(config) { assert.object(config, 'config'); assert.arrayOfObject(config.options, 'config.options'); assert.optionalBool(config.interspersed, 'config.interspersed'); var self = this; // Allow interspersed arguments (true by default).
+ 9 other calls in file
assert-plus.object is the most popular function in assert-plus (2295 examples)