How to use the lodash.find function in lodash

To help you get started, we’ve selected a few lodash 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 choerodon / agile-service-old / react / src / app / agile / containers / program / Board / BoardHome / components / BoardBody / Cell.js View on Github external
findCard = (id) => {
    const { data: { boardFeatures: issues } } = this.props;

    const issue = find(issues, { issueId: id });
    const index = findIndex(issues, { issueId: id });
    // console.log(id, issue, index);
    return {
      issue,
      index,
    };
  }
github algolia / youtube-captions-scraper / src / index.js View on Github external
// * ensure we have access to captions data
  if (!decodedData.includes('captionTracks'))
    throw new Error(`Could not find captions for video: ${videoID}`);

  const regex = /({"captionTracks":.*isTranslatable":(true|false)}])/;
  const [match] = regex.exec(decodedData);
  const { captionTracks } = JSON.parse(`${match}}`);

  const subtitle =
    find(captionTracks, {
      vssId: `.${lang}`,
    }) ||
    find(captionTracks, {
      vssId: `a.${lang}`,
    }) ||
    find(captionTracks, ({ vssId }) => vssId && vssId.match(`.${lang}`));

  // * ensure we have found the correct subtitle lang
  if (!subtitle || (subtitle && !subtitle.baseUrl))
    throw new Error(`Could not find ${lang} captions for ${videoID}`);

  const { data: transcript } = await axios.get(subtitle.baseUrl);
  const lines = transcript
    .replace('', '')
    .replace('', '')
    .split('')
    .filter(line => line && line.trim())
    .map(line => {
      const startRegex = /start="([\d.]+)"/;
      const durRegex = /dur="([\d.]+)"/;

      const [, start] = startRegex.exec(line);
github emmetio / emmet / lib / action / selectItem.js View on Github external
}

		// find matched and (possibly) overlapping ranges
		var nested = _.filter(ranges, function(item) {
			return item.inside(selRange.end);
		});

		if (nested.length) {
			return nested.sort(function(a, b) {
				return a.length() - b.length();
			})[0];
		}

		// return range next to caret
		var test = 
		r = _.find(ranges, isBackward 
			? function(item) {return item.end < selRange.start;}
			: function(item) {return item.end > selRange.start;}
		);

		if (!r) {
			// can’t find anything, just pick first one
			r = ranges[0];
		}

		return r;
	}
github 0xProject / 0x-monorepo / packages / website / ts / utils / utils.ts View on Github external
hasUniqueNameAndSymbol(tokens: Token[], token: Token): boolean {
        if (token.isRegistered) {
            return true; // Since it's registered, it is the canonical token
        }
        const registeredTokens = _.filter(tokens, t => t.isRegistered);
        const tokenWithSameNameIfExists = _.find(registeredTokens, {
            name: token.name,
        });
        const isUniqueName = tokenWithSameNameIfExists === undefined;
        const tokenWithSameSymbolIfExists = _.find(registeredTokens, {
            name: token.symbol,
        });
        const isUniqueSymbol = tokenWithSameSymbolIfExists === undefined;
        return isUniqueName && isUniqueSymbol;
    },
    zeroExErrToHumanReadableErrMsg(error: ContractWrappersError | ExchangeContractErrs, takerAddress: string): string {
github csenn / nn-visualizer / src / neuralNetwork / index.js View on Github external
const mapStateToProps = (state) => {
  const {
    isLoading,
    snapshotIndex,
    networkSummaries,
    selectedNetwork,
    selectedNetworkSummaryId,
    selectedDrawing
  } = state.neuralNetwork;

  const selectedSnapshot = selectedNetwork.snapshots
    && selectedNetwork.snapshots[String(snapshotIndex)];

  const selectedNetworkSummary = _.find(networkSummaries, {
    path: selectedNetworkSummaryId
  });

  let testResultsSummary = null;
  if (selectedSnapshot) {
    const { testResults } = selectedSnapshot;
    testResultsSummary = Object.keys(testResults).reduce((prev, curr) => {
      const wrongCount = _.values(testResults[curr].wrong)
        .reduce((prev1, curr2) => prev1 + curr2.length, 0);
      return Object.assign({}, prev, {
        [curr]: {
          wrongCount,
          correctCount: testResults[curr].correct.length
        }
      });
    }, {});
github bilibili-helper / bilibili-helper / src / js / modules / menu / UI / Menu.js View on Github external
}, (settings) => {
                const oldWatchPage = _.find(settings.options, {key: 'oldWatchPage'}).on;
                const link = !oldWatchPage ? 'https://t.bilibili.com/' : 'https://www.bilibili.com/account/dynamic';
                const menuOptions = {};
                _.each(settings.subPage.options, (option) => {
                    menuOptions[option.key] = option.on;
                });

                this.setState({
                    newWatchPageLink: link,
                    menuOptions: menuOptions,
                    options: settings.options,
                });
            });
github grafana / grafana / public / app / features / templating / variable_srv.ts View on Github external
setAdhocFilter(options: any) {
    let variable: any = _.find(this.variables, {
      type: 'adhoc',
      datasource: options.datasource,
    } as any);
    if (!variable) {
      variable = this.createVariableFromModel({
        name: 'Filters',
        type: 'adhoc',
        datasource: options.datasource,
      });
      this.addVariable(variable);
    }

    const filters = variable.filters;
    let filter: any = _.find(filters, { key: options.key, value: options.value });

    if (!filter) {
github DeekyJay / SoundwaveInteractive / src / containers / ProfileList.js View on Github external
_edit = (profile) => {
    const { profiles, profileId } = this.props
    let p
    if (!profile) p = _.find(profiles, p => p.id === profileId)
    else p = profile
    if (!p) return
    this.setState({
      ...this.state,
      editId: p.id,
      edit_inputs: {
        name: p.name
      }
    })
  }
github appnexus / lucid / src / components / SearchableMultiSelect / SearchableMultiSelect.jsx View on Github external
{_.map(selectedIndices, selectedIndex => {
								const selectedUngroupedOptionData = _.find(
									ungroupedOptionData,
									{ optionIndex: selectedIndex }
								);

								if (selectedUngroupedOptionData) {
									const { optionProps } = selectedUngroupedOptionData;
									const selectionProps = _.get(
										getFirst(
											optionProps,
											SearchableMultiSelect.Option.Selection
										),
										'props'
									);
									return (
github celo-org / celo-monorepo / packages / dappkit / src / index.ts View on Github external
const filteredContacts = contacts.data.filter((contact) => {
    return (
      contact.phoneNumbers && find(contact.phoneNumbers, (p) => isValidPhoneNumber(p) !== undefined)
    )
  })