How to use idx - 10 common examples

To help you get started, we’ve selected a few idx 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 DestinyItemManager / DIM / src / app / inventory / d2-stores.ts View on Github external
defs: D2ManifestDefinitions,
    buckets: InventoryBuckets,
    characterId: string,
    profileInfo: DestinyProfileResponse,
    mergedCollectibles: {
      [hash: number]: DestinyCollectibleComponent;
    },
    previousItems: Set,
    newItems: Set,
    itemInfoService: ItemInfoSource,
    lastPlayedDate: Date
  ): D2Store {
    const character = profileInfo.characters.data![characterId];
    const characterInventory =
      idx(profileInfo.characterInventories.data, (data) => data[characterId].items) || [];
    const profileInventory = idx(profileInfo.profileInventory.data, (data) => data.items) || [];
    const characterEquipment =
      idx(profileInfo.characterEquipment.data, (data) => data[characterId].items) || [];
    const itemComponents = profileInfo.itemComponents;
    const progressions =
      idx(profileInfo.characterProgressions.data, (data) => data[characterId].progressions) || [];
    const uninstancedItemObjectives =
      idx(
        profileInfo.characterProgressions.data,
        (data) => data[characterId].uninstancedItemObjectives
      ) || [];

    const store = makeCharacter(defs, character, lastPlayedDate);

    // This is pretty much just needed for the xp bar under the character header
    store.progression = progressions ? { progressions: Object.values(progressions) } : null;
github kiwicom / mobile / app / MMB / src / scenes / tripServices / transportationMenuItem / TransportationMenuItem.js View on Github external
openPopup = () => {
    const relevantLocations =
      idx(this.props, _ => _.data.transportation.relevantLocations) || [];
    if (relevantLocations.length === 1) {
      // do not open the modal for only one whitelabel URL (open it directly)
      const whitelabelURL =
        idx(relevantLocations, _ => _[0].whitelabelURL) || '';

      const location = idx(relevantLocations, _ => _[0].location.location);

      if (location != null) {
        this.openTransportationMap({ location, whitelabelURL });
      } else {
        navigator.geolocation.getCurrentPosition(position => {
          this.openTransportationMap({
            location: {
              lat: position.coords.latitude,
              lng: position.coords.longitude,
            },
github VinSpee / react-gcal-events-list / src / index.js View on Github external
dateTime={
                    idx(event, _ => _.start.dateTime) ||
                    idx(event, _ => _.start.date)
                  }
                >
                  <span>
                    {event.start.dateTime
                      ? formatDate(
                          idx(event, _ =&gt; _.start.dateTime.split('T')[0]),
                        )
                      : formatDate(idx(event, _ =&gt; _.start.date))}
                  </span>
                  {idx(event, _ =&gt; _.start.dateTime) &amp;&amp; (
                    <span>
                      {formatTime(
                        idx(event, _ =&gt; _.start.dateTime.split('T')[1]),
                      )}
                    </span>
                  )}
                
              
            
          ))}
github VinSpee / react-gcal-events-list / src / index.js View on Github external
{currentEvents.map(event =&gt; (
            <div>
              <dt data-test="event-summary">
                {event.summary}
              </dt>
              {event.location &amp;&amp; (
                <span>
                  <span>{event.location}</span>
                </span>
              )}
              <dd>
                <time datetime="{"> _.start.dateTime) ||
                    idx(event, _ =&gt; _.start.date)
                  }
                &gt;
                  <span>
                    {event.start.dateTime
                      ? formatDate(
                          idx(event, _ =&gt; _.start.dateTime.split('T')[0]),
                        )
                      : formatDate(idx(event, _ =&gt; _.start.date))}
                  </span>
                  {idx(event, _ =&gt; _.start.dateTime) &amp;&amp; (
                    <span>
                      {formatTime(
                        idx(event, _ =&gt; _.start.dateTime.split('T')[1]),
                      )}
                    </span></time></dd></div>
github VinSpee / react-gcal-events-list / src / index.js View on Github external
{currentEvents.map(event =&gt; (
            <div>
              <dt data-test="event-summary">
                {event.summary}
              </dt>
              {event.location &amp;&amp; (
                <span>
                  <span>{event.location}</span>
                </span>
              )}
              <dd>
                <time datetime="{"> _.start.dateTime) ||
                    idx(event, _ =&gt; _.start.date)
                  }
                &gt;
                  <span>
                    {event.start.dateTime
                      ? formatDate(
                          idx(event, _ =&gt; _.start.dateTime.split('T')[0]),
                        )
                      : formatDate(idx(event, _ =&gt; _.start.date))}
                  </span>
                  {idx(event, _ =&gt; _.start.dateTime) &amp;&amp; (
                    <span>
                      {formatTime(
                        idx(event, _ =&gt; _.start.dateTime.split('T')[1]),
                      )}
                    </span>
                  )}</time></dd></div>
github facebookarchive / flow-language-server / src / flow-versions / flowBinForRoot.js View on Github external
export async function _flowSemverForRootPath(rootPath: string, reporter: Reporter): Promise {
  const configDir = await flowConfigCache.getConfigDir(rootPath);
  reporter.info('Determining the version of flow for your project...');
  if (!configDir) {
    reporter.error('No valid .flowconfig was found. Use `flow init` in the root of your project to create one.');
    return;
  }
  const configPath = path.join(configDir, '.flowconfig');
  const {pkg, path: pkgPath} = await readPkgUp({cwd: rootPath});

  let packageFlowVersion;
  const depRange = idx(pkg, _ =&gt; _.dependencies['flow-bin']);
  const devDepRange = idx(pkg, _ =&gt; _.devDependencies['flow-bin']);
  if (depRange &amp;&amp; semver.validRange(depRange)) {
    packageFlowVersion = depRange;
  } else if (devDepRange &amp;&amp; semver.validRange(devDepRange)) {
    packageFlowVersion = devDepRange;
  }
  if (packageFlowVersion) {
    reporter.info(`Found flow version requirement ${packageFlowVersion} in your package.json`);
  }

  let configFlowVersion;
  if (configDir) {
    try {
      const configFileStr = await fs.readFile(configPath, 'utf-8');
      const flowConfig = ini.parse(configFileStr);
      if (typeof flowConfig.version === 'object') {
        const rawConfigVersion = Object.keys(flowConfig.version)[0];
github rai-project / mlmodelscope / src / components / App / Snackbar.js View on Github external
const process = error =&gt; {
  if (_.isNil(error)) {
    return
  }
  const name = idx(error, _ =&gt; _.body.name) || idx(error, _ =&gt; _.response.result.name) || idx(error, _ =&gt; _.name)
  let code = idx(error, _ =&gt; _.response.result.status) || idx(error, _ =&gt; _.body.code) || idx(error, _ =&gt; _.code)
  let message =
    idx(error, _ =&gt; _.response.result.message) || idx(error, _ =&gt; _.body.message) || idx(error, _ =&gt; _.message)
  let stack = idx(error, _ =&gt; _.response.result.stack) || idx(error, _ =&gt; _.body.stack) || idx(error, _ =&gt; _.stack)

  if (_.isString(stack)) {
    stack = [stack]
  }

  if (!_.isNil(code)) {
    code = {code} :: &nbsp;
  }
  if (!_.isNil(message)) {
    message = <b>{message}</b>
  }
  if (!_.isNil(stack)) {
github expo / expo-cli / packages / xdl / src / ApiV2.ts View on Github external
reqOptions.data = options.body;
    }

    if (!extraRequestOptions.hasOwnProperty('timeout') && ConnectionStatus.isOffline()) {
      reqOptions.timeout = 1;
    }

    reqOptions = merge({}, reqOptions, extraRequestOptions, uploadOptions);

    let response;
    let result;
    try {
      response = await axios.request(reqOptions);
      result = response.data;
    } catch (e) {
      const maybeErrorData = idx(e, _ => _.response.data.errors.length);
      if (maybeErrorData) {
        result = e.response.data;
      } else {
        throw e;
      }
    }

    if (result.errors && result.errors.length) {
      let responseError = result.errors[0];
      let error = new ApiV2Error(responseError.message, responseError.code);
      error.serverStack = responseError.stack;
      error.details = responseError.details;
      throw error;
    }

    return returnEntireResponse ? response : result.data;
github DestinyItemManager / DIM / src / app / collections / Record.tsx View on Github external
function getIntervals(
  definition: DestinyRecordDefinition,
  record: DestinyRecordComponent
): RecordInterval[] {
  const intervalDefinitions = idx(definition, (d) =&gt; d.intervalInfo.intervalObjectives) || [];
  const intervalObjectives = idx(record, (r) =&gt; r.intervalObjectives) || [];
  if (intervalDefinitions.length !== intervalObjectives.length) {
    return [];
  }

  const intervals: RecordInterval[] = [];
  let isPrevIntervalComplete = true;
  let prevIntervalProgress = 0;
  for (let i = 0; i &lt; intervalDefinitions.length; i++) {
    const def = intervalDefinitions[i];
    const data = intervalObjectives[i];

    intervals.push({
      objective: data,
      score: def.intervalScoreValue,
      percentCompleted: isPrevIntervalComplete
github facebookarchive / flow-language-server / src / flow-versions / flowBinForRoot.js View on Github external
reporter: Reporter,
): Promise {
  const configDir = await flowConfigCache.getConfigDir(rootPath);
  reporter.info('Determining the version of flow for your project...');
  if (!configDir) {
    reporter.error(
      'No valid .flowconfig was found. Use `flow init` in the root of your project to create one.',
    );
    return null;
  }
  const configPath = path.join(configDir, '.flowconfig');
  const {pkg} = await readPkgUp({cwd: rootPath});

  let packageFlowVersion;
  const depRange = idx(pkg, _ =&gt; _.dependencies['flow-bin']);
  const devDepRange = idx(pkg, _ =&gt; _.devDependencies['flow-bin']);
  if (depRange &amp;&amp; semver.validRange(depRange)) {
    packageFlowVersion = depRange;
  } else if (devDepRange &amp;&amp; semver.validRange(devDepRange)) {
    packageFlowVersion = devDepRange;
  }
  if (packageFlowVersion) {
    reporter.info(
      `Found flow version requirement ${packageFlowVersion} in your package.json`,
    );
  }

  let configFlowVersion;
  if (configDir) {
    try {
      const configFileStr = await fs.readFile(configPath, 'utf-8');
      const flowConfig = ini.parse(configFileStr);

idx

Utility function for traversing properties on objects and arrays.

MIT
Latest version published 12 months ago

Package Health Score

59 / 100
Full package analysis

Popular idx functions