本文整理匯總了TypeScript中underscore.first函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript first函數的具體用法?TypeScript first怎麽用?TypeScript first使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了first函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: shellExecuteNpmInstall
/**
* Executes the 'npm install' command for the packages specified in the registry package map.
*
* @param packagePath The folder of the package that is to be installed.
* @param registryMap The map of registry and packages that should be installed.
*/
public shellExecuteNpmInstall(packagePath: string, registryMap: IDictionary<Array<string>>): void {
const INSTALLABLE_PACKAGE_CHUNKSIZE: number = 50;
for (let registry in registryMap) {
let packages = registryMap[registry];
if (!packages || packages.length === 0) continue;
// Install packages in bundles because command line lengths aren't infinite. Windows for example has
// a command line limit of 8192 characters. It's variable on *nix and OSX but will in the 100,000s
let installablePackages = _.first(packages, INSTALLABLE_PACKAGE_CHUNKSIZE);
packages = _.rest(packages, INSTALLABLE_PACKAGE_CHUNKSIZE);
while (installablePackages && installablePackages.length > 0) {
var installArgs = ["install"].concat(installablePackages);
if (packagePath === process.cwd()) {
installArgs.push("--ignore-scripts");
}
if (registry !== "*") {
installArgs.push("--registry");
installArgs.push(registry);
}
this.shellExecuteNpm(packagePath, installArgs);
installablePackages = _.first(packages, INSTALLABLE_PACKAGE_CHUNKSIZE);
packages = _.rest(packages, INSTALLABLE_PACKAGE_CHUNKSIZE);
}
}
}
示例2:
_.each(postmasterItemCountsByType, (count, bucket) => {
if (count > 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 = {
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(..._.first(candidates, numNeededToMove));
}
}
});
示例3: formatError
export function formatError(
e: Error,
apiErrorPrefix?: string
): LocalizedString {
const re = asRequestError(e);
if (re && re.rpcError) {
const { code, data } = re.rpcError;
if (data && data.apiError && apiErrorPrefix) {
const { messages } = data.apiError;
const message = first(messages) as string;
if (message) {
const snakeCaseMessage = message.replace(/\s/g, "_").toLowerCase();
return [
`errors.api.${apiErrorPrefix}.${snakeCaseMessage}`,
{
defaultValue: `{message}`,
message,
},
];
}
}
const { message } = re.rpcError;
return [
`butlerd.codes.${code}`,
{
defaultValue: `{message}`,
message,
},
];
}
return e.message;
}
示例4:
const itemsByType = _.mapObject(_.groupBy(engrams, '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 _.first(items, 9);
});
示例5: limitToBucketSize
function limitToBucketSize(items: DimItem[], isVault) {
if (!items.length) {
return [];
}
const item = items[0];
if (!item.bucket) {
return isVault ? items : _.first(items, 9);
}
const bucket = isVault ? item.bucket.vaultBucket : item.bucket;
if (!bucket) {
return isVault ? items : _.first(items, 9);
}
// TODO: this doesn't take into account stacks that need to split
return _.first(items, bucket.capacity - (item.equipment ? 1 : 0));
}
示例6: it
it('when default path is specified, sends the correct path in the query', () => {
test = Mock.optionsComponentSetup<CategoryFacet, ICategoryFacetOptions>(CategoryFacet, {
field: '@field',
basePath: ['base', 'path']
});
const { queryBuilder } = Simulate.query(test.env, simulateQueryData);
expect(first(queryBuilder.categoryFacets[0].path, 2)).toEqual(['base', 'path']);
});
示例7: setExpandedAndCollapsed
private setExpandedAndCollapsed() {
if (this.facetValues.length > this.facet.options.numberOfValuesInBreadcrumb) {
this.collapsed = _.rest(this.facetValues, this.facet.options.numberOfValuesInBreadcrumb - 1);
this.expanded = _.first(this.facetValues, this.facet.options.numberOfValuesInBreadcrumb - 1);
} else {
this.collapsed = [];
this.expanded = this.facetValues;
}
}
示例8: build
public async build(sources: Record<string, ITableDataSource>[], table: Dom, gridOptions = defaultGridOptions) {
const firstData = first(sources) || {};
const mapToAgGridFormat = (value: agGridModule.ColDef & agGridModule.ColGroupDef, key: string): any => {
if (value.children) {
return {
field: key,
headerName: key,
marryChildren: true,
children: flatten(
value.children.map((child: any) => {
return map(child, mapToAgGridFormat);
})
)
};
} else {
return {
field: key,
headerName: key,
...value
};
}
};
const columnDefs = map(firstData as any, mapToAgGridFormat) as agGridModule.ColDef[];
const rowData = map(sources, source => {
const merged: any = {};
const extractContent = (value: ITableDataSource & agGridModule.ColGroupDef, key: string) => {
if (value.content) {
merged[key] = value.content;
} else if (value.children) {
each(value.children, (child: any) => {
each(child, extractContent);
});
}
};
each(source, extractContent as any);
return merged;
});
this.gridOptions = {
...defaultGridOptions,
columnDefs,
rowData,
...gridOptions
};
await loadAgGridLibrary();
const grid = new agGrid.Grid(table.el, this.gridOptions);
return { grid, gridOptions: this.gridOptions };
}
示例9: getRelativePathLeadingCharacters
private static getRelativePathLeadingCharacters(toNormalize: IUrlNormalize) {
let leadingRelativeUrlCharacters = '';
const relativeUrlLeadingCharactersRegex = /^(([\/])+)/;
const firstPath = first(this.toArray(toNormalize.paths));
if (firstPath) {
const match = relativeUrlLeadingCharactersRegex.exec(firstPath);
if (match) {
leadingRelativeUrlCharacters = match[0];
}
}
return leadingRelativeUrlCharacters;
}
示例10: function
topWordList: function (objectList, options) {
let topN = options.topN || 50;
var tags = analyseAll(objectList);
let words = _(Object.keys(tags))
.map((w) => {
return {
word: w,
plaqueCount: tags[w]
};
});
let sorted = _.sortBy(words, (w: any) => w.plaqueCount * -1);
let topList = _.first(sorted, topN).map((w: any) => w.word);
return topList;
},