當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.last函數代碼示例

本文整理匯總了TypeScript中underscore.last函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript last函數的具體用法?TypeScript last怎麽用?TypeScript last使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了last函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: removeMajority

    private removeMajority(objectName: string): string {
        if (_.last(objectName, 3).join("").toUpperCase() === "IES") {
            return objectName.substring(0, objectName.length - 3) + "y";
        } else if (_.last(objectName).toUpperCase() === "S") {
            return objectName.substring(0, objectName.length - 1);
        }

        return objectName;
    }
開發者ID:lafe,項目名稱:VSCode-json2ts,代碼行數:9,代碼來源:Json2Ts.ts

示例2: if

 format: (key: string, ...args: any[]) => {
   let value = key.toLocaleString();
   // Try to find a soft match
   // These conditions check if there was a change in the string (meaning toLocaleString found a match). If there was no
   // match, try another format.
   if (value == key) {
     const tryTranslationInUpperCase = key.toUpperCase().toLocaleString();
     const tryTranslationInLowerCase = key.toLowerCase().toLocaleString();
     const tryTranslationAfterCapitalization = (key.charAt(0).toUpperCase() + key.toLowerCase().slice(1)).toLocaleString();
     if (tryTranslationInUpperCase != key.toUpperCase().toLocaleString()) {
       value = tryTranslationInUpperCase;
     } else if (tryTranslationInLowerCase != key.toLowerCase().toLocaleString()) {
       value = tryTranslationInLowerCase;
     } else if (tryTranslationAfterCapitalization != key.charAt(0).toUpperCase() + key.toLowerCase().slice(1)) {
       value = tryTranslationAfterCapitalization;
     }
   }
   if (args.length > 0) {
     let last = _.last(args);
     // Last argument is either the count or a boolean forcing plural (true) or singular (false)
     if (_.isBoolean(last) || _.isNumber(last)) {
       args.pop();
       value = L10N.formatPlSn(value, last);
     }
     _.each(args, (arg, i) => (value = value.replace(`{${i}}`, arg)));
   } else {
     // If there was no parameters passed, we try to cleanup the possible parameters in the translated string.
     value = value.replace(/{[0-9]}|<pl>[a-zA-Z]+<\/pl>|<sn>|<\/sn>/g, '').trim();
   }
   return value;
 },
開發者ID:coveo,項目名稱:search-ui,代碼行數:31,代碼來源:L10N.ts

示例3: topCardsOfDeck

    // May trigger a shuffle
    topCardsOfDeck(game: Game, n: number) : CardInPlay[] {
        if (this.deck.count < n) {
            const reorderedDiscard = _.shuffle<CardInPlay>(this.discard.cards);
            game.moveCardsToBottom(reorderedDiscard, this.deck);

            game.log(`${this.name} shuffles`);
        }

        return _.last(this.deck.cards, n);
    }
開發者ID:scottostler,項目名稱:conspirator,代碼行數:11,代碼來源:player.ts

示例4: it

        it('should not place a selected tab inside the dropdown', () => {
          const lastTab = last(tabs);
          lastTab.addClass('coveo-selected');
          const lastId = lastTab.getAttribute('data-id');

          responsiveTabs.handleResizeEvent();
          const container = openTabContainer();

          const selectedTabInDropdown = container.find(`div[data-id="${lastId}"]`);
          expect(selectedTabInDropdown).toBeNull();
        });
開發者ID:coveo,項目名稱:search-ui,代碼行數:11,代碼來源:ResponsiveTabsTest.ts

示例5: switch

export const loadouts: Reducer<LoadoutsState, LoadoutsAction | AccountsAction> = (
  state: LoadoutsState = initialLoadoutsState,
  action: LoadoutsAction
) => {
  switch (action.type) {
    case getType(actions.loaded):
      return {
        ...state,
        loadouts: action.payload
      };

    case getType(actions.deleteLoadout):
      return {
        ...state,
        loadouts: state.loadouts.filter((l) => l.id !== action.payload)
      };

    case getType(actions.updateLoadout):
      const loadout = action.payload;
      return {
        ...state,
        loadouts: [...state.loadouts.filter((l) => l.id !== loadout.id), loadout]
      };

    case getType(actions.savePreviousLoadout):
      const { storeId, loadoutId, previousLoadout } = action.payload;
      let previousLoadouts = state.previousLoadouts[storeId] || [];
      const lastPreviousLoadout = _.last(previousLoadouts);
      previousLoadouts =
        lastPreviousLoadout && loadoutId === lastPreviousLoadout.id
          ? // Pop the previous loadout since we're reapplying it
            previousLoadouts.filter((l) => l.id !== loadoutId)
          : // Push the previous loadout
            [...previousLoadouts, previousLoadout];
      return {
        ...state,
        previousLoadouts: {
          ...state.previousLoadouts,
          [storeId]: previousLoadouts
        }
      };

    default:
      return state;
  }
};
開發者ID:bhollis,項目名稱:DIM,代碼行數:46,代碼來源:reducer.ts

示例6: it

    it('2 ночь путана проголосует и это уже не имеет значения', (done) => {
        let unsubscribe;

        real_man = _.last(_.without(_.pluck(_.where(store.getState().players, {role: Roles.INHABITANT}), 'token'), mafia_target));

        unsubscribe = store.subscribe(() => {
            expect(store.getState().status).toBe(GameStatus.VOTE_WHORE);
            expect(store.getState().active_roles).toEqual([Roles.WHORE]);
            expect(store.getState().vote_variants).toEqual(_.pluck(store.getState().players.filter(player => player.token !== whore), 'token'));
            expect(store.getState().votes).toEqual([{who_token: whore, for_whom_token: real_man}]);

            // Отписываемся т. к. store общий для всех тестов
            unsubscribe();
            done();
        });

        store.dispatch(GameAction.vote(
            whore,
            real_man
        ));
    });
開發者ID:andreevWork,項目名稱:mafia,代碼行數:21,代碼來源:FirstScenario.ts

示例7: LoadoutPopupCtrl

function LoadoutPopupCtrl(
  this: LoadoutPopupCtrlVM,
  $rootScope,
  $scope,
  ngDialog: IDialogService,
  dimLoadoutService: LoadoutServiceType,
  dimItemService: ItemServiceType,
  toaster,
  dimFarmingService,
  D2FarmingService,
  $window,
  dimSearchService,
  $i18next,
  dimStoreService: StoreServiceType,
  D2StoresService: StoreServiceType,
  $stateParams
) {
  'ngInject';
  const vm = this;
  vm.previousLoadout = _.last(dimLoadoutService.previousLoadouts[vm.store.id]);

  vm.classTypeId = {
    warlock: 0,
    titan: 1,
    hunter: 2
  }[vm.store.class];
  if (vm.classTypeId === undefined) {
    vm.classTypeId = -1;
  }

  vm.numPostmasterItems = pullablePostmasterItems(this.store).length;

  vm.search = dimSearchService;

  const storeService: StoreServiceType = this.store.destinyVersion === 1 ? dimStoreService : D2StoresService;

  function initLoadouts() {
    dimLoadoutService.getLoadouts()
      .then((loadouts) => {
        const platform = getActivePlatform();
        if (!platform) {
          return;
        }

        vm.loadouts = _.sortBy(loadouts, 'name') || [];

        vm.loadouts = vm.loadouts.filter((loadout: Loadout) => {
          return (vm.store.destinyVersion === 2
            ? loadout.destinyVersion === 2 : loadout.destinyVersion !== 2) &&
            (_.isUndefined(loadout.platform) ||
                  loadout.platform === platform.platformLabel) &&
            (vm.classTypeId === -1 ||
             loadout.classType === -1 ||
             loadout.classType === vm.classTypeId);
        });
      });
  }
  $scope.$on('dim-save-loadout', initLoadouts);
  $scope.$on('dim-delete-loadout', initLoadouts);
  initLoadouts();

  vm.newLoadout = function newLoadout($event: IAngularEvent) {
    ngDialog.closeAll();
    vm.editLoadout({}, $event);
  };

  vm.newLoadoutFromEquipped = function newLoadoutFromEquipped($event: IAngularEvent) {
    ngDialog.closeAll();

    const loadout = filterLoadoutToEquipped(vm.store.loadoutFromCurrentlyEquipped(""));
    // We don't want to prepopulate the loadout with a bunch of cosmetic junk
    // like emblems and ships and horns.
    loadout.items = _.pick(loadout.items,
                           'class',
                           'kinetic',
                           'energy',
                           'power',
                           'primary',
                           'special',
                           'heavy',
                           'helmet',
                           'gauntlets',
                           'chest',
                           'leg',
                           'classitem',
                           'artifact',
                           'ghost');
    loadout.classType = vm.classTypeId;
    vm.editLoadout(loadout, $event);
  };

  vm.deleteLoadout = function deleteLoadout(loadout: Loadout) {
    if ($window.confirm($i18next.t('Loadouts.ConfirmDelete', { name: loadout.name }))) {
      dimLoadoutService.deleteLoadout(loadout)
        .catch((e) => {
          toaster.pop('error',
                      $i18next.t('Loadouts.DeleteErrorTitle'),
                      $i18next.t('Loadouts.DeleteErrorDescription', { loadoutName: vm.loadout.name, error: e.message }));
          console.error(e);
        });
//.........這裏部分代碼省略.........
開發者ID:delphiactual,項目名稱:DIM,代碼行數:101,代碼來源:loadout-popup.component.ts

示例8:

 dimLoadoutService.applyLoadout(vm.store, loadout, true).then(() => {
   vm.previousLoadout = _.last(dimLoadoutService.previousLoadouts[vm.store.id]);
 });
開發者ID:delphiactual,項目名稱:DIM,代碼行數:3,代碼來源:loadout-popup.component.ts

示例9: queueAction

    return queueAction(() => {
      if (allowUndo) {
        if (!_previousLoadouts[store.id]) {
          _previousLoadouts[store.id] = [];
        }

        if (!store.isVault) {
          const lastPreviousLoadout = _.last(_previousLoadouts[store.id]);
          if (lastPreviousLoadout && loadout.id === lastPreviousLoadout.id) {
            _previousLoadouts[store.id].pop();
          } else {
            const previousLoadout = store.loadoutFromCurrentlyEquipped($i18next.t('Loadouts.Before', { name: loadout.name }));
            _previousLoadouts[store.id].push(previousLoadout);
          }
        }
      }

      let items: DimItem[] = copy(_.flatten(Object.values(loadout.items)));

      const loadoutItemIds = items.map((i) => {
        return {
          id: i.id,
          hash: i.hash
        };
      });

      // Only select stuff that needs to change state
      let totalItems = items.length;
      items = items.filter((pseudoItem) => {
        const item = getLoadoutItem(pseudoItem, store);
        // provide a more accurate count of total items
        if (!item) {
          totalItems--;
          return true;
        }

        const notAlreadyThere = item.owner !== store.id ||
              item.location.inPostmaster ||
              // Needs to be equipped. Stuff not marked "equip" doesn't
              // necessarily mean to de-equip it.
              (pseudoItem.equipped && !item.equipped);

        return notAlreadyThere;
      });

      // only try to equip subclasses that are equippable, since we allow multiple in a loadout
      items = items.filter((item) => {
        const ok = item.type !== 'Class' || !item.equipped || item.canBeEquippedBy(store);
        if (!ok) {
          totalItems--;
        }
        return ok;
      });

      // vault can't equip
      if (store.isVault) {
        items.forEach((i) => { i.equipped = false; });
      }

      // We'll equip these all in one go!
      let itemsToEquip = items.filter((i) => i.equipped);
      if (itemsToEquip.length > 1) {
        // we'll use the equipItems function
        itemsToEquip.forEach((i) => { i.equipped = false; });
      }

      // Stuff that's equipped on another character. We can bulk-dequip these
      const itemsToDequip = items.filter((pseudoItem) => {
        const item = storeService.getItemAcrossStores(pseudoItem);
        return item && item.owner !== store.id && item.equipped;
      });

      const scope = {
        failed: 0,
        total: totalItems,
        successfulItems: [] as DimItem[]
      };

      let promise: IPromise<any> = $q.when();

      if (itemsToDequip.length > 1) {
        const realItemsToDequip = _.compact(itemsToDequip.map((i) => storeService.getItemAcrossStores(i)));
        const dequips = _.map(_.groupBy(realItemsToDequip, 'owner'), (dequipItems, owner) => {
          const equipItems = _.compact(dequipItems.map((i) => dimItemService.getSimilarItem(i, loadoutItemIds)));
          return dimItemService.equipItems(storeService.getStore(owner)!, equipItems);
        });
        promise = $q.all(dequips);
      }

      promise = promise
        .then(() => applyLoadoutItems(store, items, loadout, loadoutItemIds, scope))
        .then(() => {
          if (itemsToEquip.length > 1) {
            // Use the bulk equipAll API to equip all at once.
            itemsToEquip = itemsToEquip.filter((i) => scope.successfulItems.find((si) => si.id === i.id));
            const realItemsToEquip = _.compact(itemsToEquip.map((i) => getLoadoutItem(i, store)));
            return dimItemService.equipItems(store, realItemsToEquip);
          } else {
            return itemsToEquip;
          }
//.........這裏部分代碼省略.........
開發者ID:delphiactual,項目名稱:DIM,代碼行數:101,代碼來源:loadout.service.ts


注:本文中的underscore.last函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。