How to use the assert-plus.optionalNumber 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 restify / node-restify / lib / bunyan_helper.js View on Github external
function RequestCaptureStream(opts) {
    assert.object(opts, 'options');
    assert.optionalObject(opts.stream, 'options.stream');
    assert.optionalArrayOfObject(opts.streams, 'options.streams');
    assert.optionalNumber(opts.level, 'options.level');
    assert.optionalNumber(opts.maxRecords, 'options.maxRecords');
    assert.optionalNumber(opts.maxRequestIds, 'options.maxRequestIds');
    assert.optionalBool(opts.dumpDefault, 'options.dumpDefault');

    var self = this;
    Stream.call(this);

    this.level = opts.level ? bunyan.resolveLevel(opts.level) : bunyan.WARN;
    this.limit = opts.maxRecords || 100;
    this.maxRequestIds = opts.maxRequestIds || 1000;
    // eslint-disable-next-line new-cap
    this.requestMap = LRU({
        max: self.maxRequestIds
    });
    this.dumpDefault = opts.dumpDefault;
github trentm / node-dashdash / lib / dashdash.js View on Github external
Parser.prototype.help = function help(config) {
    config = config || {};
    assert.object(config, 'config');

    var indent = makeIndent(config.indent, 4, 'config.indent');
    var headingIndent = makeIndent(config.headingIndent,
        Math.round(indent.length / 2), 'config.headingIndent');

    assert.optionalString(config.nameSort, 'config.nameSort');
    var nameSort = config.nameSort || 'length';
    assert.ok(~['length', 'none'].indexOf(nameSort),
        'invalid "config.nameSort"');
    assert.optionalNumber(config.maxCol, 'config.maxCol');
    assert.optionalNumber(config.maxHelpCol, 'config.maxHelpCol');
    assert.optionalNumber(config.minHelpCol, 'config.minHelpCol');
    assert.optionalNumber(config.helpCol, 'config.helpCol');
    assert.optionalBool(config.includeEnv, 'config.includeEnv');
    assert.optionalBool(config.includeDefault, 'config.includeDefault');
    assert.optionalBool(config.helpWrap, 'config.helpWrap');
    var maxCol = config.maxCol || 80;
    var minHelpCol = config.minHelpCol || 20;
    var maxHelpCol = config.maxHelpCol || 40;

    var lines = [];
    var maxWidth = 0;
    this.options.forEach(function (o) {
        if (o.hidden) {
            return;
        }
        if (o.group !== undefined && o.group !== null) {
            // We deal with groups in the next pass
github restify / conductor / lib / clients / index.js View on Github external
function create(model) {
    assert.string(model.host, 'model.host');
    assert.optionalNumber(model.port, 'model.port');
    assert.optionalObject(model.headers, 'model.headers');

    var remoteHost = new Urijs(model.host)
        .port(model.port || 80)
        .protocol(model.secure ? 'https' : 'http')
        .toString();

    return restify.createJsonClient({
        url: remoteHost,
        // TODO: this doesn't seem to log anything?!
        log: logHelpers.child({ component: 'jsonClient' })
    });
}
github joyent / smartos-live / src / img / node_modules / sdc-clients / lib / imgapi.js View on Github external
if (err) {
                    callback(err, null, res);
                } else {
                    callback(null, image, res);
                }
            });
        });
        return;
    }

    // Normal file/stream AddImageFile
    assert.string(options.compression, 'options.compression');
    assert.ok(['string', 'object'].indexOf(typeof (options.file)) !== -1,
        'options.file');
    assert.optionalString(options.sha1, 'options.sha1');
    assert.optionalNumber(options.size, 'options.size');
    assert.optionalString(account, 'account');
    var file = options.file;

    function getFileStreamAndSize(next) {
        if (typeof (file) === 'object') {
            assert.number(options.size, 'options.size');
            return next(null, file, options.size);
        } else if (options.size) {
            var stream = fs.createReadStream(file);
            pauseStream(stream);
            return next(null, stream, options.size);
        } else {
            return fs.stat(file, function (statErr, stats) {
                if (statErr) {
                    return next(statErr);
                }
github splunk / splunk-aws-project-trumpet / cloudtrail-serverless / lambda_code / cloudtrail_logger / node_modules / dashdash / lib / dashdash.js View on Github external
Parser.prototype.help = function help(config) {
    config = config || {};
    assert.object(config, 'config');

    var indent = makeIndent(config.indent, 4, 'config.indent');
    var headingIndent = makeIndent(config.headingIndent,
        Math.round(indent.length / 2), 'config.headingIndent');

    assert.optionalString(config.nameSort, 'config.nameSort');
    var nameSort = config.nameSort || 'length';
    assert.ok(~['length', 'none'].indexOf(nameSort),
        'invalid "config.nameSort"');
    assert.optionalNumber(config.maxCol, 'config.maxCol');
    assert.optionalNumber(config.maxHelpCol, 'config.maxHelpCol');
    assert.optionalNumber(config.minHelpCol, 'config.minHelpCol');
    assert.optionalNumber(config.helpCol, 'config.helpCol');
    assert.optionalBool(config.includeEnv, 'config.includeEnv');
    assert.optionalBool(config.includeDefault, 'config.includeDefault');
    assert.optionalBool(config.helpWrap, 'config.helpWrap');
    var maxCol = config.maxCol || 80;
    var minHelpCol = config.minHelpCol || 20;
    var maxHelpCol = config.maxHelpCol || 40;

    var lines = [];
    var maxWidth = 0;
    this.options.forEach(function (o) {
        if (o.hidden) {
            return;
        }
        if (o.group !== undefined && o.group !== null) {
github joyent / smartos-live / src / img / lib / errors.js View on Github external
function ImgadmError(options) {
    assert.object(options, 'options');
    assert.string(options.message, 'options.message');
    assert.string(options.code, 'options.code');
    assert.optionalObject(options.cause, 'options.cause');
    assert.optionalNumber(options.statusCode, 'options.statusCode');
    var self = this;

    var args = [];
    if (options.cause) args.push(options.cause);
    if (options.message) {
        args.push('%s');
        args.push(options.message);
    }
    WError.apply(this, args);

    var extra = Object.keys(options).filter(
        function (k) { return ['cause', 'message'].indexOf(k) === -1; });
    extra.forEach(function (k) {
        self[k] = options[k];
    });
}
github joyent / node-bunyan-syslog / lib / sys.js View on Github external
function SyslogStream(opts) {
        assert.object(opts, 'options');
        assert.optionalNumber(opts.facility, 'options.facility');
        assert.optionalString(opts.name, 'options.name');

        Stream.call(this);

        this.facility = opts.facility || 1;
        this.name = opts.name || process.title || process.argv[0];
        this.writable = true;

        if (this.constructor.name === 'SyslogStream') {
                binding.openlog(this.name, binding.LOG_CONS, 0);
                process.nextTick(this.emit.bind(this, 'connect'));
        }
}
util.inherits(SyslogStream, Stream);
github trentm / node-dashdash / lib / dashdash.js View on Github external
Parser.prototype.help = function help(config) {
    config = config || {};
    assert.object(config, 'config');

    var indent = makeIndent(config.indent, 4, 'config.indent');
    var headingIndent = makeIndent(config.headingIndent,
        Math.round(indent.length / 2), 'config.headingIndent');

    assert.optionalString(config.nameSort, 'config.nameSort');
    var nameSort = config.nameSort || 'length';
    assert.ok(~['length', 'none'].indexOf(nameSort),
        'invalid "config.nameSort"');
    assert.optionalNumber(config.maxCol, 'config.maxCol');
    assert.optionalNumber(config.maxHelpCol, 'config.maxHelpCol');
    assert.optionalNumber(config.minHelpCol, 'config.minHelpCol');
    assert.optionalNumber(config.helpCol, 'config.helpCol');
    assert.optionalBool(config.includeEnv, 'config.includeEnv');
    assert.optionalBool(config.includeDefault, 'config.includeDefault');
    assert.optionalBool(config.helpWrap, 'config.helpWrap');
    var maxCol = config.maxCol || 80;
    var minHelpCol = config.minHelpCol || 20;
    var maxHelpCol = config.maxHelpCol || 40;

    var lines = [];
    var maxWidth = 0;
    this.options.forEach(function (o) {
        if (o.hidden) {
            return;
        }
        if (o.group !== undefined && o.group !== null) {
github joyent / buildymcbuildface / lib / imgadm / lib / common.js View on Github external
function vmWaitForState(uuid, options, callback) {
    assert.string(uuid, 'uuid');
    assert.object(options, 'options');
    assert.string(options.state, 'options.state');
    assert.optionalNumber(options.timeout, 'options.timeout');
    assert.optionalNumber(options.interval, 'options.interval');
    assert.object(options.log, 'options.log');
    assert.func(callback);
    var interval = options.interval || 1000;

    var start = Date.now();
    var vm;
    async.doUntil(
        function getIt(next) {
            setTimeout(function () {
                vmGet(uuid, options, function (err, vm_) {
                    vm = vm_;
                    next(err);
                });
            }, interval);
        },
        function testIt() {