How to use jsprim - 10 common examples

To help you get started, we’ve selected a few jsprim 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 OriginTrail / ot-node / test / bdd / steps / network.js View on Github external
// Expect DV to have data.
    expect(
        dv.state.purchasedDatasets,
        `Data-set ${dataSetId} was not purchased.`,
    ).to.have.key(dataSetId);

    // Get original import info.
    const dcImportInfo =
        await httpApiHelper.apiImportInfo(dc.state.node_rpc_url, this.state.lastImport.data_set_id);
    const dvImportInfo =
        await httpApiHelper.apiImportInfo(dv.state.node_rpc_url, this.state.lastImport.data_set_id);

    // TODO: fix different root hashes error.
    dvImportInfo.root_hash = dcImportInfo.root_hash;
    if (!deepEqual(dcImportInfo, dvImportInfo)) {
        throw Error(`Objects not equal: ${JSON.stringify(dcImportInfo)} and ${JSON.stringify(dvImportInfo)}`);
    }
    expect(dcImportInfo.transaction, 'DC transaction hash should be defined').to.not.be.undefined;
    expect(dvImportInfo.transaction, 'DV/DV2 transaction hash should be defined').to.not.be.undefined;
});
github OriginTrail / ot-node / test / bdd / steps / network.js View on Github external
promises.push(new Promise(async (accept, reject) => {
                const dhImportInfo =
                    await httpApiHelper.apiImportInfo(
                        node.state.node_rpc_url,
                        this.state.lastImport.data_set_id,
                    );
                expect(dhImportInfo.transaction, 'DH transaction hash should be defined').to.not.be.undefined;
                // TODO: fix different root hashes error.
                dhImportInfo.root_hash = dcImportInfo.root_hash;
                if (deepEqual(dcImportInfo, dhImportInfo)) {
                    accept();
                } else {
                    reject(Error(`Objects not equal: ${JSON.stringify(dcImportInfo)} ` +
                        `and ${JSON.stringify(dhImportInfo)}`));
                }
            }));
        }
github joyent / node-ip6addr / ip6addr.js View on Github external
}
  }

  /* Parse integer values */
  var field, num;
  for (i = 0; i < ip6Fields.length; i++) {
    field = ip6Fields[i];
    num = jsprim.parseInteger(field, { base: 16, allowSign: false });
    if (num instanceof Error || num < 0 || num > 65535) {
      throw new ParseError(input, 'Invalid field value: ' + field);
    }
    ip6Fields[i] = num;
  }
  for (i = 0; i < ip4Fields.length; i++) {
    field = ip4Fields[i];
    num = jsprim.parseInteger(field, { base: 10, allowSign: false });
    if (num instanceof Error || num < 0 || num > 255) {
      throw new ParseError(input, 'Invalid field value: ' + field);
    }
    ip4Fields[i] = num;
  }

  /* Collapse IPv4 portion, if necessary */
  if (ip4Fields.length !== 0) {
    ip6Fields.push((ip4Fields[0]*256) + ip4Fields[1]);
    ip6Fields.push((ip4Fields[2]*256) + ip4Fields[3]);
  }

  /* Expand '::' delimiter into implied 0s */
  if (ip6Fields.length < 8 && expIndex !== null) {
    var filler = [];
    for (i = 0; i < (8 - ip6Fields.length); i++) {
github joyent / node-ip6addr / ip6addr.js View on Github external
ip6Fields = ['ffff'];
      expIndex = 0;
    }

    if (ip6Fields.length > 6) {
      throw new ParseError(input, 'Too many fields');
    } else if (ip6Fields.length < 6 && expIndex === null) {
      throw new ParseError(input, 'Too few fields');
    }
  }

  /* Parse integer values */
  var field, num;
  for (i = 0; i < ip6Fields.length; i++) {
    field = ip6Fields[i];
    num = jsprim.parseInteger(field, { base: 16, allowSign: false });
    if (num instanceof Error || num < 0 || num > 65535) {
      throw new ParseError(input, 'Invalid field value: ' + field);
    }
    ip6Fields[i] = num;
  }
  for (i = 0; i < ip4Fields.length; i++) {
    field = ip4Fields[i];
    num = jsprim.parseInteger(field, { base: 10, allowSign: false });
    if (num instanceof Error || num < 0 || num > 255) {
      throw new ParseError(input, 'Invalid field value: ' + field);
    }
    ip4Fields[i] = num;
  }

  /* Collapse IPv4 portion, if necessary */
  if (ip4Fields.length !== 0) {
github joyent / manatee / lib / postgresMgr.js View on Github external
function PostgresMgr(options) {
    assert.object(options, 'options');
    assert.object(options.log, 'options.log');
    assert.ifError(mod_jsprim.validateJsonObject(CONFIG_SCHEMA, options));

    EventEmitter.call(this);

    /** @type {Bunyan} The bunyan log object */
    this._log = options.log.child({component: 'PostgresMgr'}, true);
    var log = this._log;
    var self = this;

    self._postgres = null; /* The child postgres process */

    self._defaultVersion = options.defaultVersion;
    self._pgBaseDir = options.pgBaseDir;
    self._versions = options.versions;
    self._dataConf = path.resolve(options.dataConfig);

    /*
github joyent / sdc-docker / lib / backends / sdc / build.js View on Github external
var matchedImgs = imgs.filter(function _cachedImgFilter(img) {
            // Images must have the same Cmd entry.
            if (opts.cmd !== img.container_config.Cmd.join(' ')) {
                return false;
            }
            // Some fields (like Labels) can also be set from the client, check
            // that these fields are the same.
            if (!(jsprim.deepEqual(opts.labels, img.image.config.Labels))) {
                return false;
            }

            return true;
        });
github joyent / sdc-docker / lib / wfapi / index.js View on Github external
Wfapi.prototype.createPushImageJob = function (options, cb) {
    var self = this;
    assert.object(options, 'options');
    assert.string(options.account_uuid, 'opts.account_uuid');
    assert.object(options.image, 'options.image');
    assert.optionalString(options.regAuth, 'opts.regAuth');
    assert.string(options.repoAndTag, 'options.repoAndTag');
    assert.string(options.req_id, 'options.req_id');

    // Combine the push opts and the workflow opts.
    var params = jsprim.mergeObjects(options, {
        target: format('/push-image-%s', options.repoAndTag),
        task: 'push-image'
    });

    var jobOpts = { headers: { 'x-request-id': options.req_id } };

    self.client.createJob(params.task, params, jobOpts, function (err, job) {
        if (err) {
            return cb(err);
        }
        params.job_uuid = job.uuid;
        self.log.debug(params, 'Push image => job params');
        return cb(null, job.uuid);
    });
};
github joyent / manatee-state-machine / test / tst.basic.js View on Github external
'async': [],
	    'deposed': [],
	    'initWal': '0/0000001e'
	},
	'zkpeers': [ 'node1', 'node3' ],
	'pg': {
	    'online': true,
	    'config': {
	        'role': 'primary',
		'upstream': null,
		'downstream': node3url
	    }
	}
};

primState4 = mod_jsprim.deepCopy(primState3);
primState4.zkpeers.push('node2');
primState4.zkstate.async.push('node2');

deposedState = {
	'role': 'deposed',
	'zkstate': {
	    'generation': 5,
	    'primary': 'node3',
	    'sync': 'node2',
	    'async': [],
	    'deposed': [ 'node1' ],
	    'initWal': '0/00000028'
	},
	'zkpeers': [ 'node1', 'node3', 'node2' ],
	'pg': {
	    'online': false,
github joyent / kang / test / tst.lib.js View on Github external
/*
 * tst.lib.js: test low-level library functions
 */

var mod_assert = require('assert');
var mod_jsprim = require('jsprim');
var mod_kang = require('../lib/kang');
var mod_nutil = require('../lib/nodeutil');

mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa'));
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa/'));
mod_assert.ok(mod_jsprim.startsWith('grampa', 'grampa'));
mod_assert.ok(!mod_jsprim.startsWith('grampa', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('abe', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('grampa/simpson', 'abe'));

mod_assert.equal(mod_nutil.chopSlashes('edna'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna/'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna//'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna//'), '/edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab/'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab//'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab///'), '/edna/krab');
github joyent / kang / test / tst.lib.js View on Github external
/*
 * tst.lib.js: test low-level library functions
 */

var mod_assert = require('assert');
var mod_jsprim = require('jsprim');
var mod_kang = require('../lib/kang');
var mod_nutil = require('../lib/nodeutil');

mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa'));
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa/'));
mod_assert.ok(mod_jsprim.startsWith('grampa', 'grampa'));
mod_assert.ok(!mod_jsprim.startsWith('grampa', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('abe', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('grampa/simpson', 'abe'));

mod_assert.equal(mod_nutil.chopSlashes('edna'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna/'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna//'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna//'), '/edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab/'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab//'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab///'), '/edna/krab');