• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript underscore.last函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript underscore.map函数代码示例发布时间:2022-05-25
下一篇:
TypeScript underscore.keys函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap