How to use the object function from assert-plus

Find comprehensive JavaScript assert-plus.object code examples handpicked from public code repositorys.

assert-plus.object is a method provided by the assert-plus module in Node.js that can be used to validate if a given value is a plain object.

56
57
58
59
60
61
62
63
64
65
66
 * 'networks' so that it only contains networks or network pools which have the
 * account UUID in their owner_uuids.
 */
function filterListNetworks(api, cfg) {
    assert.object(api, 'api');
    assert.object(api.log, 'api.log');
    assert.object(cfg, 'cfg');
    assert.arrayOfUuid(cfg.accounts, 'cfg.accounts');


    var log = api.log;
fork icon49
star icon183
watch icon0

+ 19 other calls in file

184
185
186
187
188
189
190
191
192
193
194
195
196




function createOptions(opts, userOpts) {
    assert.object(opts, 'options');
    assert.string(opts.path, 'options.path');
    assert.object(userOpts, 'userOptions');


    var id = opts.req_id || libuuid.v4();
    var options = {
        headers: normalizeHeaders(userOpts.headers),
fork icon41
star icon75
watch icon0

+ 59 other calls in file

How does assert-plus.object work?

assert-plus.object is a function provided by the assert-plus module in Node.js that checks if a value is an object or not, and if it's not, it throws an error with a customizable error message. If the value is an object, the function does nothing and returns undefined. It can also check if the object is empty or not and throw an error if it is empty.

166
167
168
169
170
171
172
173
174
175
// GetJob(Errors|Failures|Inputs|Outputs) all have the same logic
// So this is just a generic handler for those
function jobDataCommon(opts, callback) {
    assert.object(opts, 'options');
    assert.arrayOfString(opts.args, 'options.args');
    assert.object(opts.client, 'options.client');
    assert.string(opts.func, 'options.func');
    assert.finite(opts.parallel, 'options.parallel');
    assert.string(opts.type, 'options.type');
    assert.string(opts.user, 'options.user');
fork icon41
star icon75
watch icon57

+ 21 other calls in file

126
127
128
129
130
131
132
133
134
135
    }
    assert.func(options.sign, 'options.sign');
    this.principal.sign = options.sign;
} else {
    assert.string(this.principal.account, 'principal.account');
    assert.object(this.principal.keyPair, 'principal.keyPair');
    assert.optionalString(this.principal.user, 'principal.user');
}

this.url = options.url;
fork icon38
star icon55
watch icon41

+ 664 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const assert = require("assert");

function validateUser(user) {
  assert(typeof user === "object", "User must be an object");
  assert(typeof user.name === "string", "Name must be a string");
  assert(typeof user.age === "number", "Age must be a number");
}

const validUser = { name: "John Doe", age: 30 };
validateUser(validUser); // passes assertions

const invalidUser = { name: 123, age: "thirty" };
validateUser(invalidUser); // throws assertion error with specific message

770
771
772
773
774
775
776
777
778
779
function PGPool(options) {
    assert.object(options, 'options');
    assert.number(options.checkInterval, 'options.checkInterval');
    assert.number(options.connectTimeout, 'options.connectTimeout');
    assert.object(options.log, 'options.log');
    assert.object(options.resolver, 'options.resolver');
    assert.number(options.maxConnections, 'options.maxConnections');
    assert.number(options.minSpareConnections, 'options.minSpareConnections');
    assert.number(options.targetClaimDelay, 'options.targetClaimDelay');
    assert.number(options.queryTimeout, 'options.queryTimeout');
fork icon21
star icon60
watch icon0

+ 25 other calls in file

34
35
36
37
38
39
40
41
42
43
44
45
46
47




// ---- support stuff


function objCopy(obj, target) {
    assert.object(obj, 'obj');
    assert.optionalObject(obj, 'target');


    if (target === undefined) {
        target = {};
fork icon38
star icon55
watch icon41

+ 23 other calls in file

50
51
52
53
54
55
56
57
58
59
 * "size" GBs. Calls "callback" when done with an error object and the newly
 * created package as parameters.
 */
function addSharedVolumePackage(cli, packageSettings, callback) {
    assert.object(cli, 'cli');
    assert.object(packageSettings, 'packageSettings');
    assert.number(packageSettings.size, 'size');
    assert.arrayOfUuid(packageSettings.owner_uuids,
        'packageSettings.owner_uuids');
    assert.func(callback, 'callback');
fork icon19
star icon13
watch icon0

+ 7 other calls in file

62
63
64
65
66
67
68
69
70
71
72
73
    return (log);
}




function mantaClientFromAccountInfo(accountInfo) {
    assert.object(accountInfo, 'accountInfo');
    assert.string(accountInfo.login, 'accountInfo.login');
    assert.string(accountInfo.fp, 'accountInfo.fp');
    assert.string(accountInfo.privKey, 'accountInfo.privKey');
    assert.string(process.env.MANTA_URL, 'process.env.MANTA_URL');
fork icon16
star icon13
watch icon0

+ 17 other calls in file

73
74
75
76
77
78
79
80
81
82
function _buildStorageVMPayload(version, volumeParams, storageVmUuid,
        billingPackage, affinity) {
    assert.number(version, 'version');
    assert.object(volumeParams, 'volumeParams');
    assert.uuid(storageVmUuid, 'storageVmUuid');
    assert.object(billingPackage, 'billingPackage');
    assert.string(billingPackage.uuid, 'billingPackage.uuid');
    assert.optionalArray(affinity, 'affinity');
    assert.uuid(CONFIG.nfsServerImageUuid, 'CONFIG.nfsServerImageUuid');
    assert.uuid(CONFIG.nfsServerImageUuid2, 'CONFIG.nfsServerImageUuid2');
fork icon6
star icon8
watch icon0

+ 181 other calls in file

25
26
27
28
29
30
31
32
33
34
35
36


    return err;
}


function validateFabricNetworkOwnership(napiClient, volumeParams, callback) {
    assert.object(napiClient, 'napiClient');
    assert.object(volumeParams, 'volumeParams');
    assert.arrayOfUuid(volumeParams.networks, 'volumeParams.networks');
    assert.uuid(volumeParams.owner_uuid, 'volumeParams.owner_uuid');
    assert.func(callback, 'callback');
fork icon6
star icon8
watch icon0

+ 11 other calls in file

3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
if (remove instanceof Function) {
    callback = remove;
    remove = {};
}

assertplus.object(add, 'add');
assertplus.object(remove, 'remove');
assertplus.func(callback, 'callback');

var self = this;
fork icon13
star icon7
watch icon42

+ 79 other calls in file

282
283
284
285
286
287
288
289
290
291
 * Get a VM's firewall status from firewaller on a CN
 */
function getFwStatus(t, opts, callback) {
    assert.object(t, 't');
    assert.object(opts, 'opts');
    assert.object(opts.vm, 'opts.vm');
    assert.string(opts.vm.uuid, 'opts.vm.uuid');
    assert.string(opts.vm.server_uuid, 'opts.vm.server_uuid');
    assert.optionalBool(opts.exp, 'opts.exp');
    assert.optionalObject(opts.expErr, 'opts.expErr');
fork icon7
star icon4
watch icon0

+ 19 other calls in file

234
235
236
237
238
239
240
241
242
243
    name: 'vms-updater',
    level: 'info',
    stream: process.stderr
});

mod_assert.object(options.vmapiClient, 'options.vmapiClient');
this._vmapiClient = options.vmapiClient;

mod_assert.string(options.changefeedPublisherUrl,
    'options.changefeedPublisherUrl');
fork icon6
star icon8
watch icon0

+ 79 other calls in file

18
19
20
21
22
23
24
25
26
27
28
29
var JSON_FILENAME = 'plugin.json';


function PluginDirLoader(opts) {
    var self = this;


    mod_assert.object(opts, 'opts');
    mod_assert.number(opts.defaultTimeout, 'opts.defaultTimeout');
    mod_assert.number(opts.defaultTTL, 'opts.defaultTTL');
    mod_assert.optionalBool(opts.enforceRoot, 'opts.enforceRoot');
    mod_assert.object(opts.log, 'opts.log');
fork icon8
star icon3
watch icon0

+ 3 other calls in file

215
216
217
218
219
220
221
222
223
224
225
 * - `val` {Object} : keys to update in the object
 * @param cb {Function} `function (err, new RecoveryConfigurationTransition())`
 */
function updateRecoveryConfigurationTransition(opts, callback) {
    assert.object(opts, 'opts');
    assert.object(opts.val, 'opts.val');
    assert.optionalBool(opts.remove, 'opts.remove');
    assert.func(callback, 'callback');


    // None of the initially required properties of the object
fork icon6
star icon0
watch icon0

+ 17 other calls in file

92
93
94
95
96
97
98
99
100

assert.object(spanCtx, 'spanCtx');
assert.uuid(spanCtx._spanId, 'spanCtx._spanId');
assert.uuid(spanCtx._traceId, 'spanCtx._traceId');
assert.equal(format, opentracing.FORMAT_TEXT_MAP, 'Unsupported format');
assert.object(carrier, 'carrier');

// We only support "TextMap" format which we assume for now is a restify
// opts.headers object.
fork icon4
star icon0
watch icon0

+ 11 other calls in file

78
79
80
81
82
83
84
85
86
87
assert.object(config, 'config');
assert.optionalBool(
    config.handleUncaughtExceptions,
    'config.handleUncaughtExceptions'
);
assert.object(config.log, 'config.log');
assert.object(config.restify, 'config.restify');
assert.object(config.staticLabels, 'config.staticLabels');
assert.string(
    config.staticLabels.datacenter,
fork icon3
star icon0
watch icon0

+ 7 other calls in file

16
17
18
19
20
21
22
23
24
25
26
 */
function groupedCommits(commits) {
    const grouped = _.reduce(
        commits,
        function (acc, commit) {
            assert.object(commit, 'commit');


            if (!acc.hasOwnProperty(commit.type)) {
                acc[commit.type] = [];
            }
fork icon0
star icon2
watch icon0

1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
 *        e.g. passing console.log is legal.
 * @param cb {Function} `function (err)`
 */
IMGADM.prototype.importImage = function importImage(opts, cb) {
    assert.object(opts, 'opts');
    assert.object(opts.importInfo, 'opts.importInfo');
    assert.object(opts.importInfo.source, 'opts.importInfo.source');
    assert.string(opts.zpool, 'opts.zpool');
    assert.optionalBool(opts.zstream, 'opts.zstream');
    assert.optionalBool(opts.quiet, 'opts.quiet');
fork icon248
star icon0
watch icon0

+ 87 other calls in file

30
31
32
33
34
35
36
37
38
39
40
41
42
43




// ---- internal support stuff


function _rbacStateBasics(ctx, cb) {
    assert.object(ctx.cloudapi, 'ctx.cloudapi');
    assert.func(cb, 'cb');


    vasync.parallel({funcs: [
        function listUsers(next) {
fork icon38
star icon55
watch icon0

+ 8 other calls in file