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;
fork icon49
star icon183
watch icon0

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');
fork icon38
star icon55
watch icon0

+ 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');
fork icon38
star icon55
watch icon0

+ 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');

fork icon16
star icon13
watch icon34

+ 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:
    //
fork icon6
star icon8
watch icon0

+ 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) {
fork icon6
star icon8
watch icon0

+ 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,
fork icon6
star icon8
watch icon0

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) {
fork icon13
star icon7
watch icon42

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;
fork icon3
star icon3
watch icon0

+ 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;
fork icon248
star icon0
watch icon0

+ 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;
fork icon20
star icon11
watch icon0

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 = [];

fork icon20
star icon11
watch icon0

+ 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 = {};
fork icon17
star icon5
watch icon0

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,
fork icon6
star icon2
watch icon0

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).
fork icon0
star icon0
watch icon1

+ 9 other calls in file