本文整理汇总了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));
});
示例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,
}
}
示例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));
}
}
});
示例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));
}
示例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);
});
示例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)
)
示例7: ngOnChanges
ngOnChanges() {
if (this.userData) {
this.usersSorted = _.orderBy(this.userData, function(u){return Number(u.score)}, ['desc']);
this.usersSorted =_.take(this.usersSorted,5);
}
}
示例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;
})