How to use the jsprim.pluck function in jsprim

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 joyent / node-skinner / lib / skinner.js View on Github external
* tree.  If we need a node that doesn't exist, we create it here.
	 *
	 * In each iteration, "o" denotes where we are currently in the tree,
	 * and "prev" refers to its parent.  At the end of this loop, "o" refers
	 * to the leaf value that we'd like to update.  (We wouldn't need "prev"
	 * at all if we could update numbers by reference, but we need it to
	 * update the leaf by updating the corresponding property of its
	 * parent.)
	 */
	prev = null;
	o = this.sa_value;
	for (i = 0; i < this.sa_decomps.length; i++) {
		mod_assert.equal(typeof (o), 'object');
		mod_assert.ok(o !== null);
		field = this.sa_decomps[i];
		fieldvalue = mod_jsprim.pluck(datapt['fields'], field);
		prev = o;

		if (this.sa_bucketizers.hasOwnProperty(field)) {
			if (typeof (fieldvalue) == 'string') {
				this.sa_nparsed++;
				fieldvalue = parseFloat(fieldvalue);
			}

			if (typeof (fieldvalue) != 'number' ||
			    isNaN(fieldvalue)) {
				this.sa_nnonnumeric++;
				this.emit('invalid_object', datapt, new VError(
				    'value for field "%s" is not a number',
				    field), this.sa_nrecords);
				return;
			}
github joyent / node-aperture / lib / evaluator.js View on Github external
throw new errors.UnknownTypeError('unknown type "%s"', lhs.type);
    }

    if (typeof (self.types[lhs.type][op]) !== 'function') {
        throw new errors.UnsupportedOperationError('unsupported '+
            'operation "%s" on type "%s"', op, lhs.type);
    }

    if (typeof (context[lhs.name]) === 'undefined' ||
        context[lhs.name] === null) {

        throw new errors.MissingConditionError(
            'missing condition in context: "%s"', lhs.name);
    }

    return (self.types[lhs.type][op](pluck(context, lhs.name), rhs));
};
github joyent / daggr / lib / daggr.js View on Github external
outputs.forEach(function (o, i) {
			var val;
			if (json) {
				if (o == 'this')
					val = row[0];
				else {
					val = mod_jsprim.pluck(row[1], o);
					if (val === undefined)
						val = 'undefined';
					else
						val = JSON.stringify(val);
				}
			} else {
				val = mod_jsprim.pluck(row, o);
			}
			outstream.write((i === 0 ? '' : ' ') + val.toString());
		});
		outstream.write('\n');
github joyent / daggr / lib / daggr.js View on Github external
DataAggregator.prototype.extractField = function (row, field)
{
	/*
	 * This works for both JSON mode, where "row" is an object and "field"
	 * may include nested references, as well as text mode, where "row" is
	 * an array and "field" is a number.
	 */
	return (mod_jsprim.pluck(row, field));
};
github joyent / daggr / lib / daggr.js View on Github external
outputs.forEach(function (o, i) {
			var val;
			if (json) {
				if (o == 'this')
					val = row[0];
				else {
					val = mod_jsprim.pluck(row[1], o);
					if (val === undefined)
						val = 'undefined';
					else
						val = JSON.stringify(val);
				}
			} else {
				val = mod_jsprim.pluck(row, o);
			}
			outstream.write((i === 0 ? '' : ' ') + val.toString());
		});
		outstream.write('\n');
github joyent / node-krill / lib / krill.js View on Github external
krillPrimWalk(function (subpred, key) {
		var field = subpred[key][0];
		var value = mod_jsprim.pluck(xlate, field);
		if (value === undefined)
			throw (new VError('subpredicate "%j": ' +
			    'no translation for field "%s"',
			    subpred, field));
		subpred[key][0] = value;
	}, newpred);
	return (new Predicate(newpred, this.p_types));
github joyent / moray / lib / pg.js View on Github external
client: function _serializeClient(c) {
        return ({
            id: c._moray_id,
            currentQuery: jsprim.pluck(c, 'client.activeQuery.text'),
            timeout: c._queryTimeout,
            txn: c._moray_txn
        });
    },
    err: bunyan.stdSerializers.err
github joyent / dragnet / lib / stream-synthetic.js View on Github external
this.st_query.qc_synthetic.forEach(function (fieldconf) {
		var val, parsed;

		mod_assertplus.ok(fieldconf.hasOwnProperty('date'));
		val = mod_jsprim.pluck(chunk.fields, fieldconf.field);
		if (val === undefined) {
			if (nerrors === 0) {
				self.vsWarn(new VError(
				    'field "%s" is undefined', fieldconf.field),
				    'undef');
			}
			nerrors++;
			return;
		}

		if (typeof (val) == 'number') {
			/*
			 * For convenience, we allow people to specify "date"
			 * fields that are already parsed dates.  We just pass
			 * these through.
			 */
github joyent / manatee-state-machine / lib / validation.js View on Github external
function validatePromoteRequest(clusterState)
{
	var promote, error, expireTime;
	promote = mod_jsprim.pluck(clusterState, 'promote');

	if (!promote)
		return (undefined);

	error = validateAndCopy(schemas.promote, promote);
	if (error instanceof Error)
		return (error);

	expireTime = mod_jsprim.parseDateTime(promote.expireTime);
	if (isNaN(expireTime.getTime())) {
		return (new VError('expireTime is not parseable (found "%s")',
		    promote.expireTime));
	}

	if (promote.generation !== clusterState.generation) {
		return (new VError('generation does not match (expected %d, ' +