当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.take函数代码示例

本文整理汇总了TypeScript中lodash.take函数的典型用法代码示例。如果您正苦于以下问题:TypeScript take函数的具体用法?TypeScript take怎么用?TypeScript take使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了take函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it('should return the same set of results after reset() is called', () => {

            let paginator = paginationService.getPaginatorInstance('/collection');

            // Get first page
            $httpBackend.expectGET('/api/collection', (headers) => {
                    return headers.Range == 'entities=0-9'
                })
                .respond(206, _.take(collection, 10));

            let results1 = paginator.getNext();

            paginator.reset(); //reset the counter

            $httpBackend.flush();

            // Get first page again
            $httpBackend.expectGET('/api/collection', (headers) => {
                    return headers.Range == 'entities=0-9'
                })
                .respond(206, _.take(collection, 10));

            let results2 = paginator.getNext();

            $httpBackend.flush();

            expect(results1).eventually.to.be.instanceof(Array);
            expect(results1).eventually.to.have.length(10);
            expect(results2).eventually.to.have.length(10);
            expect(results1).eventually.to.deep.equal(_.take(collection, 10));
            expect(results2).eventually.to.deep.equal(_.take(collection, 10));

        });
开发者ID:swordman1205,项目名称:angular-typescript-material,代码行数:33,代码来源:paginationService.spec.ts

示例2: getPageInfo

export function getPageInfo(): GitLabInfo {
    const host = window.location.hostname

    const projectLink = document.querySelector<HTMLAnchorElement>('.context-header a')
    if (!projectLink) {
        throw new Error('Unable to determine project name')
    }

    const projectName = new URL(projectLink.href).pathname.slice(1)

    const parts = projectName.split('/')

    const owner = take(parts, parts.length - 1).join('/')
    const repoName = last(parts)!

    let pageKind: GitLabPageKind
    if (window.location.pathname.includes(`${owner}/${repoName}/commit`)) {
        pageKind = GitLabPageKind.Commit
    } else if (window.location.pathname.includes(`${owner}/${repoName}/merge_requests`)) {
        pageKind = GitLabPageKind.MergeRequest
    } else {
        pageKind = GitLabPageKind.File
    }

    return {
        owner,
        repoName,
        repoPath: [host, owner, repoName].join('/'),
        pageKind,
    }
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:31,代码来源:scrape.ts

示例3:

 _.each(postmasterItemCountsByType, (count, bucket) => {
   if (count > 0 && store.buckets[bucket].length > 0) {
     const items: DimItem[] = store.buckets[bucket];
     const capacity = store.capacityForItem(items[0]);
     const numNeededToMove = Math.max(0, count + items.length - capacity);
     if (numNeededToMove > 0) {
       // We'll move the lowest-value item to the vault.
       const candidates = _.sortBy(items.filter((i) => !i.equipped && !i.notransfer), (i) => {
         let value: number = {
           Common: 0,
           Uncommon: 1,
           Rare: 2,
           Legendary: 3,
           Exotic: 4
         }[i.tier];
         // And low-stat
         if (i.primStat) {
           value += i.primStat.value / 1000;
         }
         return value;
       });
       itemsToMove.push(..._.take(candidates, numNeededToMove));
     }
   }
 });
开发者ID:w1cked,项目名称:DIM,代码行数:25,代码来源:postmaster.ts

示例4: limitToBucketSize

function limitToBucketSize(items: DimItem[], isVault) {
  if (!items.length) {
    return [];
  }
  const item = items[0];

  if (!item.bucket) {
    return isVault ? items : _.take(items, 9);
  }
  const bucket = isVault ? item.bucket.vaultBucket : item.bucket;

  if (!bucket) {
    return isVault ? items : _.take(items, 9);
  }
  // TODO: this doesn't take into account stacks that need to split
  return _.take(items, bucket.capacity - (item.equipment ? 1 : 0));
}
开发者ID:w1cked,项目名称:DIM,代码行数:17,代码来源:auto-loadouts.ts

示例5:

 const itemsByType = _.mapValues(_.groupBy(engrams, (e) => e.type), (items) => {
   // Sort exotic engrams to the end so they don't crowd out other types
   items = _.sortBy(items, (i) => {
     return i.isExotic ? 1 : 0;
   });
   // No more than 9 engrams of a type
   return _.take(items, 9);
 });
开发者ID:w1cked,项目名称:DIM,代码行数:8,代码来源:auto-loadouts.ts

示例6: runtime

const historicalDirectory = runtime(async (context) =>
    decorate(
        choice(
            _.take(["-", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"], context.historicalCurrentDirectoriesStack.size)
                .map(alias => decorate(string(alias), description(expandHistoricalDirectory(alias, context.historicalCurrentDirectoriesStack))))
        ),
        style(styles.directory)
    )
开发者ID:Alubatm,项目名称:black-screen,代码行数:8,代码来源:Cd.ts

示例7: ngOnChanges

  ngOnChanges() {

    if (this.userData) {

    this.usersSorted = _.orderBy(this.userData, function(u){return Number(u.score)}, ['desc']);
    this.usersSorted =_.take(this.usersSorted,5);
    }
  }
开发者ID:NaturalSolutions,项目名称:Validator-clientNG,代码行数:8,代码来源:ranking.component.ts

示例8: function

 .add<RpcBotLog>("BOT_LOG", function (state, { payload }) {
   if (isBotLog(payload)) {
     state.logQueue.unshift(payload);
     state.logQueue = _.take(state.logQueue, state.logQueueSize);
   } else {
     console.warn(i18next.t("Unexpected log message?"));
   }
   return state;
 })
开发者ID:roryaronson,项目名称:farmbot-web-frontend,代码行数:9,代码来源:reducer.ts


注:本文中的lodash.take函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。