How to use the underscore.find 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 buildreactnative / assemblies / application / groups / create_event.js View on Github external
onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true
              if (DEV) {console.log(data);}
              if (DEV) {console.log(details);}
              this.setState({
                location: _.extend({}, details.geometry.location, {
                  city: _.find(details.address_components, (c) => c.types[0] == 'locality'),
                  state: _.find(details.address_components, (c) => c.types[0] == 'administrative_area_level_1'),
                  county: _.find(details.address_components, (c) => c.types[0] == 'administrative_area_level_2'),
                  formattedAddress: details.formatted_address,
                })
              });
              this.refs.name.focus();
            }}
            getDefaultValue={() => {
github nrkno / tv-automation-server-core / meteor / server / api / ingest / mosDevice / ingest.ts View on Github external
studio: Studio,
	rundown: Rundown,
	ingestRundown: IngestRundown,
	ingestParts: AnnotatedIngestPart[]
) {
	// Save the new parts list
	const groupedParts = groupIngestParts(ingestParts)
	const ingestSegments = groupedPartsToSegments(rundown._id, groupedParts)

	const oldSegmentEntries = compileSegmentEntries(ingestRundown.segments)
	const newSegmentEntries = compileSegmentEntries(ingestSegments)
	const segmentDiff = diffSegmentEntries(oldSegmentEntries, newSegmentEntries)

	// Check if operation affect currently playing Part:
	if (rundown.active && rundown.currentPartId) {
		const currentPart = _.find(ingestParts, (ingestPart) => {
			const partId = getPartId(rundown._id, ingestPart.externalId)
			return partId === rundown.currentPartId
		})
		if (!currentPart) {
			// Looks like the currently playing part has been removed.
			logger.warn(`Currently playing part "${rundown.currentPartId}" was removed during ingestData. Unsyncing the rundown!`)
			ServerRundownAPI.unsyncRundown(rundown._id)
			return
		} else {
			// TODO: add logic for determining whether to allow changes to the currently playing Part.
		}
	}


	// Save new cache
	const newIngestRundown = _.clone(ingestRundown)
github 2600hz / monster-ui / js / lib / monster.apps.js View on Github external
_loadApp: function(name, callback, options){
			var self = this,
				appPath = 'apps/' + name,
				customKey = 'app-' + name,
				requirePaths = {},
				options = options || {},
				externalUrl = options.sourceUrl || false,
				apiUrl = monster.config.api.default;

			/* If source_url is defined for an app, we'll load the templates, i18n and js from this url instead of localhost */
			if('auth' in monster.apps && 'installedApps' in monster.apps.auth) {
				var storedApp = _.find(monster.apps.auth.installedApps, function(installedApp) {
					return name === installedApp.name;
				});

				if(storedApp && 'source_url' in storedApp) {
					externalUrl = storedApp.source_url;
                                        if(externalUrl.substr(externalUrl.length-1) !== "/") {
                                                externalUrl += "/";
                                        }
				}

				if(storedApp && storedApp.hasOwnProperty('api_url')) {
					apiUrl = storedApp.api_url;
					if(apiUrl.substr(apiUrl.length-1) !== "/") {
                                                apiUrl += "/";
                                        }
				}
github KiLMaN / T411-Torznab / server.js View on Github external
T411Categories.forEach(function(category)
			{
				if(category.pid == 0) // Root Category
				{
					categoriesXml.push({'category':[
						{_attr:{'id':category.id,'name':category.name}}]
					});
				}
				else
				{ // sub Category
					_.find(categoriesXml, function(obj) {
						return _.find(obj.category,function(objc) {
							return objc._attr != undefined && objc._attr.id == category.pid;
						}) != undefined;
					})['category'].push(
						{'subcat':[
							{_attr:{'id':category.id,'name':category.name}}]
						});
				}
			});
github jsonresume / theme-utils / basics.js View on Github external
function getProfile(resume, network) {
    var profiles = resume.basics.profiles;

    return _.find(profiles, function(profile) {
        return profile.network.toLowerCase() === network.toLowerCase();
    });
}
github brave-intl / bat-ledger / ledger / controllers / grants.js View on Github external
throw boom.badGateway('not configured for promotions')
    }

    const code = request.headers['fastly-geoip-countrycode']
    const adsAvailable = await adsGrantsAvailable(code)

    if (runtime.config.forward.grants) {
      const platformQp = protocolVersion === 3 ? 'android' : 'desktop'
      const { grants } = runtime.config.wreck
      const payload = await braveHapi.wreck.get(grants.baseUrl + '/v1/promotions?legacy=true&paymentId=' + paymentId + '&platform=' + platformQp, {
        headers: grants.headers,
        useProxyP: true
      })
      const promotions = JSON.parse(payload.toString()).promotions

      const newPromo = underscore.find(promotions, (promotion) => { return promotion.id === promotionId })
      if (!newPromo) {
        throw boom.notFound('no such promotion: ' + promotionId)
      }

      const { available, expiresAt, type, platform } = newPromo
      promotion = {
        active: available,
        expiresAt,
        type: legacyTypeFromTypeAndPlatform(type, platform),
        protocolVersion: 4
      }
    } else {
      const promotionQuery = { promotionId, protocolVersion }

      if (protocolVersion === 3) {
        underscore.extend(promotionQuery, { protocolVersion: 4, type: { $in: ['ads', 'android'] } })
github juttle / juttle-viewer / src / apps / components / log-explorer / log-explorer.js View on Github external
_moveToPrevMatch(matches) {
        let pos = this.state.cursorPosition;
        let match = _.find(matches.slice().reverse(), function(match) {
            return match < pos;
        });

        if (match !== undefined) {
            this.setState({
                cursorPosition : match
            });

            if (match < this.state.windowStart) {
                this.setState({
                    windowStart : match
                });
            }
        }
    }
    _goToStart() {
github walmartlabs / generator-release / lib / git.js View on Github external
function listHasSha(list, sha) {
  return _.find(list, function(commit) {
    commit = commit.sha || commit;

    if (commit.length < sha.length) {
      return sha.indexOf(commit) === 0;
    } else {
      return commit.indexOf(sha) === 0;
    }
  });
}
github ebi-uniprot / ProtVista / src / TooltipFactory.js View on Github external
evidenceText = publications + (publications > 1 ? ' Publications' : ' Publication');
    } else if (acronym === 'IC') {
        evidenceText = publications === 0
            ? 'Curated'
            : publications + (publications > 1 ? ' Publications' : ' Publication');
    } else if (acronym === 'ISS') {
        evidenceText = 'By similarity';
    } else if (acronym === 'ISM') {
        evidenceText = !sources || sources.length === 0 ? 'Sequence Analysis': sources[0].name + ' annotation';
    } else if ((acronym === 'MIXM') || (acronym === 'MIXA')) {
        evidenceText = 'Combined sources';
    } else if ((acronym === 'MI') || (acronym === 'AI')){
        evidenceText = 'Imported';
    } else if (acronym === 'AA') {
        var unirule = sources
            ? _.find(sources, function(source) {
                return source.url && (source.url.indexOf('unirule') !== -1);
            })
            : false;
        var saas = sources
            ? _.find(sources, function(source) {
                return source.url && (source.url.indexOf('SAAS') !== -1);
            })
            : false;
        var interpro = sources
            ? _.find(sources, function(source) {
                return source.name === 'Pfam';
            })
            : false;
        evidenceText =  unirule ? 'UniRule annotation'
            : saas ? 'SAAS annotation'
            : interpro ? 'InterPro annotation'
github ebi-uniprot / ProtVista / src / CategoryFilterDialog.js View on Github external
_.each(Constants.getCategoryNamesInOrder(), function(category) {
        var catKey = category.name;
        var dataCategory = _.find(fv.data, function(catArray) {
            return catArray[0] === catKey;
        });
        if (dataCategory && (dataCategory[1].length !== 0)) {
            var div = wrapper.append('div');
            div.append('input')
                .attr('type', 'checkbox')
                .property('checked', true)
                .attr('index', index)
                .on('click', function() {
                    var elem = d3.select(this);
                    var myIndex = +elem.attr('index');
                    var allCategory = d3.selectAll('.up_pftv_category');
                    if (elem.property('checked')) {
                        d3.select(allCategory[0][myIndex]).style('display', 'block');
                        wrapper.selectAll('input:disabled').attr('disabled', null);
                    } else {