How to use the underscore.pick function in underscore

To help you get started, we’ve selected a few underscore 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 hacksalot / HackMyResume / test / scripts / test-fresh-sheet.js View on Github external
it('should have one or more of each section', function() {
        var newObj = _.pick( _sheet, opts.sections );
        expect( Object.keys(newObj).length ).to.equal( opts.sections.length );
      });
github Createdd / votingApp / app / routes / user.routes.js View on Github external
router.post('/', (req,res) => {
    let validAttributes = _.pick(req.body, 'username', 'email', 'password');
    let newUser = new User (validAttributes);
    newUser.save((err,user) => {
      if(err){
        if(err.code === 11000) {
          if(/username/.test(err.message) || /lowercase_name/.test(err.message)) {
            return res.status(500).json({
              success: false,
              message: 'Name is taken :('});
          } else {
            return res.status(500).json({
              success: false,
              message: 'Mail is taken :(',
              error: err.message
            });
          }
        } else {
github wayfair / tungstenjs / adaptors / backbone / base_model.js View on Github external
_.each(attributes, function(attributeValue, attributeKey) {
        var mergeProps = {};
        if (_.keys(attributeValue).length) {

          var specialProps = _.pick(attributeValue, specialPropNamesKeys);
          _.each(specialProps, function(specialProp, specialPropName) {
            var localMergeProp = {};
            var protoName = specialPropNames[specialPropName];
            protoProps[protoName] = protoProps[protoName] || {};
            localMergeProp[attributeKey] = specialProp;
            protoProps[protoName] = _.defaults(protoProps[protoName], localMergeProp);

          });

          var filteredProps = _.omit(attributeValue, specialPropNamesKeys);
          if (!_.isEmpty(filteredProps)) {
            mergeProps[attributeKey] = filteredProps;
            _.defaults(protoProps, mergeProps);
          }
        } else {
          mergeProps[attributeKey] = attributeValue;
github xjchenhao / egg-admin-service / app / controller / auth / user.js View on Github external
const result = await ctx.service.auth.user.edit(query.id);

    if (!result) {
      this.failure({
        data: {
          id: query.id,
        },
        state: 404,
      });

      return false;
    }


    this.success(_.pick(result, ...[ 'id', 'account', 'name', 'sex', 'mobile', 'email', 'remark' ]));
  }
github oroinc / platform / src / Oro / Bundle / DataAuditBundle / Resources / public / js / audit-filter.js View on Github external
initialize: function(options) {
            _.extend(this, _.pick(options, 'auditFilterType'));
            AuditFilter.__super__.initialize.call(this, options);
        },
github RocketChat / Rocket.Chat / app / api / server / v1 / settings.js View on Github external
get() {
		if (!hasPermission(this.userId, 'view-privileged-setting')) {
			return API.v1.unauthorized();
		}

		return API.v1.success(_.pick(Settings.findOneNotHiddenById(this.urlParams._id), '_id', 'value'));
	},
	post() {
github CartoDB / cartodb / lib / assets / javascripts / cartodb3 / editor / layers / layer-content-views / legend / legend-content-view.js View on Github external
_pickAttrs: function (legendDefinitionModel) {
    var attrs = _.pick(legendDefinitionModel.attributes, 'title', 'prefix', 'suffix', 'leftLabel', 'rightLabel', 'topLabel', 'bottomLabel', 'items');
    return attrs;
  },
github restberry / restberry / lib / obj.js View on Github external
RestberryObj.prototype._save = function(next) {
    var _lockedFields = this._lockedFields;
    var obj = _.pick(this, function(val, key) {
        return !_.contains(_lockedFields, key);
    });
    for (var key in obj) {
        this._obj[key] = obj[key];
    }
    this.restberry.odm.save(this._obj, next);
};
github brave / browser-laptop / app / browser / api / userModel.js View on Github external
const campaignId = campaign.campaignId
    if (campaigns[campaignId]) return oops('duplicated campaignId: ' + campaignId)

    const startTimestamp = new Date(campaign.startAt).getTime()
    if (isNaN(startTimestamp)) return oops('invalid startAt for campaignId: ' + campaignId)
    const stopTimestamp = new Date(campaign.endAt).getTime()
    if (isNaN(stopTimestamp)) return oops('invalid endAt for campaignId: ' + campaignId)
    if (stopTimestamp <= now) return

    const regions = []
    if (campaign.geoTargets) {
      campaign.geoTargets.forEach((region) => { regions.push(region.code) })
    }
    campaigns[campaignId] = underscore.extend({ startTimestamp, stopTimestamp, creativeSets: 0, regions: regions },
                                              underscore.pick(campaign, [ 'name', 'dailyCap', 'budget' ]))

    campaign.creativeSets.forEach((creativeSet) => {
      if (failP) return

      if (creativeSet.execution !== 'per_click') return oops('creativeSet with unknown execution: ' + creativeSet.execution)

      const creativeSetId = creativeSet.creativeSetId
      if (creativeSets[creativeSetId]) return oops('duplicated creativeSetId: ' + creativeSetId)

      let hierarchy = []
      creativeSet.segments.forEach((segment) => {
        const name = segment.name.toLowerCase()

        if (hierarchy.indexOf(name) === -1) hierarchy.push(name)
      })
      if (hierarchy.length === 0) return oops('creativeSet with no segments: ' + creativeSetId)