How to use the assert-plus.number function in assert-plus

To help you get started, we’ve selected a few assert-plus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joyent / node-ip6addr / ip6addr.js View on Github external
function parseLong(input) {
  assert.number(input);
  if (input !== Math.floor(input)) {
    throw new Error('Value must be integer');
  }
  if (input < 0 || input > 0xffffffff) {
    throw new Error('Value must be 32 bit');
  }
  var out = new Addr();
  out._fields[7] = input & 0xffff;
  out._fields[6] = (input >>> 16);
  /* this is ipv4-mapped */
  out._fields[5] = 0xffff;
  out._attrs.ipv4Bare = true;
  out._attrs.ipv4Mapped = true;
  return out;
}
github joyent / sdc-docker / lib / triton-tags.js View on Github external
'triton._test.number': function validateTritonTestNumber(val) {
        assert.number(val, 'val');
        return null;
    },
    'triton._test.boolean': function validateTritonTestBoolean(val) {
github joyent / sdc-docker / lib / moray.js View on Github external
function reindexBucket(moray, bucket, callback) {
    assert.object(moray, 'moray');
    assert.object(bucket, 'bucket');
    assert.string(bucket.desc, 'bucket.desc');
    assert.string(bucket.name, 'bucket.name');
    assert.object(bucket.schema, 'bucket.schema');
    assert.number(bucket.version, 'bucket.version');

    var rowsPerCall = 100;
    var processed = rowsPerCall;

    async.whilst(
        function () { return processed > 0; },
        function (cb) {
            moray.reindexObjects(bucket.name, rowsPerCall, { noCache: true },
            function (err, res) {
                if (err) {
                    return cb(err);
                }

                processed = res.processed;
                cb();
            });
github restify / node-restify / lib / upgrade.js View on Github external
ServerUpgradeResponse.prototype.status = function status(code) {
    assert.number(code, 'code');
    this.statusCode = code;
    return code;
};
github joyent / dragnet / lib / config-common.js View on Github external
function loadConfig(input)
{
	var dc, error;

	mod_assertplus.object(input);
	error = mod_jsprim.validateJsonObject(dnConfigSchemaBase, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	mod_assertplus.number(input.vmaj);
	mod_assertplus.number(input.vmin);
	if (input.vmaj !== dnConfigMajor)
		return (new VError('failed to load config: major ' +
		    'version ("%s") not supported', input.vmaj));

	error = mod_jsprim.validateJsonObject(dnConfigSchemaCurrent, input);
	if (error instanceof Error)
		return (new VError(error, 'failed to load config'));

	dc = new DragnetConfig();

	input.datasources.forEach(function (dsconfig) {
		dc.dc_datasources[dsconfig.name] = {
		    'ds_backend': dsconfig.backend,
		    'ds_backend_config': dsconfig.backend_config,
		    'ds_filter': dsconfig.filter,
		    'ds_format': dsconfig.dataFormat
github splunk / splunk-aws-project-trumpet / cloudtrail-serverless / lambda_code / cloudtrail_logger / node_modules / jsprim / lib / jsprim.js View on Github external
function parseInteger(str, uopts)
{
	mod_assert.string(str, 'str');
	mod_assert.optionalObject(uopts, 'options');

	var baseOverride = false;
	var options = PI_DEFAULTS;

	if (uopts) {
		baseOverride = hasKey(uopts, 'base');
		options = mergeObjects(options, uopts);
		mod_assert.number(options.base, 'options.base');
		mod_assert.ok(options.base >= 2, 'options.base >= 2');
		mod_assert.ok(options.base <= 36, 'options.base <= 36');
		mod_assert.bool(options.allowSign, 'options.allowSign');
		mod_assert.bool(options.allowPrefix, 'options.allowPrefix');
		mod_assert.bool(options.allowTrailing,
		    'options.allowTrailing');
		mod_assert.bool(options.allowImprecise,
		    'options.allowImprecise');
		mod_assert.bool(options.trimWhitespace,
		    'options.trimWhitespace');
		mod_assert.bool(options.leadingZeroIsOctal,
		    'options.leadingZeroIsOctal');

		if (options.leadingZeroIsOctal) {
			mod_assert.ok(!baseOverride,
			    '"base" and "leadingZeroIsOctal" are ' +
github joyent / node-aperture / types / number.js View on Github external
function le(context, policy) {
    assert.number(context, 'context');
    return (context <= +policy);
}
github joyent / sdc-docker / lib / models / image.js View on Github external
function Image(params) {
    assert.object(params, 'image params');
    assert.number(params.created, 'params.created');
    assert.string(params.docker_id, 'params.docker_id');
    assert.string(params.image_uuid, 'params.image_uuid');
    assert.string(params.owner_uuid, 'params.owner_uuid');
    assert.optionalArrayOfString(params.heads, 'params.heads');
    assert.number(params.size, 'params.size');
    assert.number(params.virtual_size, 'params.virtual_size');
    assert.optionalString(params.architecture, 'params.architecture');
    assert.optionalString(params.comment, 'params.comment');
    assert.optionalObject(params.config, 'params.config');
    assert.optionalObject(params.container_config, 'params.container_config');
    assert.optionalString(params.parent, 'params.parent');
    assert.optionalBool(params.private, 'params.private');
    assert.optionalString(params.author, 'params.author');

    this.params = params;
    if (!this.params.heads)
        this.params.heads = [];
    if (this.params.architecture === undefined) {
        this.params.architecture = '';
    }
    if (this.params.comment === undefined) {
        this.params.comment = '';
github Andyliwr / FE-learning-load / task08 / lidikang / styles / node_modules / sshpk / lib / utils.js View on Github external
function opensslKeyDeriv(cipher, salt, passphrase, count) {
	assert.buffer(salt, 'salt');
	assert.buffer(passphrase, 'passphrase');
	assert.number(count, 'iteration count');

	var clen = CIPHER_LEN[cipher];
	assert.object(clen, 'supported cipher');

	salt = salt.slice(0, PKCS5_SALT_LEN);

	var D, D_prev, bufs;
	var material = new Buffer(0);
	while (material.length < clen.key + clen.iv) {
		bufs = [];
		if (D_prev)
			bufs.push(D_prev);
		bufs.push(passphrase);
		bufs.push(salt);
		D = Buffer.concat(bufs);
		for (var j = 0; j < count; ++j)
github sx1989827 / DOClever / node_modules / sshpk / lib / utils.js View on Github external
function zeroPadToLength(buf, len) {
	assert.buffer(buf);
	assert.number(len);
	while (buf.length > len) {
		assert.equal(buf[0], 0x00);
		buf = buf.slice(1);
	}
	while (buf.length < len) {
		var b = Buffer.alloc(buf.length + 1);
		b[0] = 0x00;
		buf.copy(b, 1);
		buf = b;
	}
	return (buf);
}