本文整理汇总了TypeScript中lodash.mapValues函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapValues函数的具体用法?TypeScript mapValues怎么用?TypeScript mapValues使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapValues函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it(`${scenario.name}`, async () => {
switch (scenario.id) {
case 'nothing_space':
// Saved Objects Managment is not available when everything is disabled.
const nothingSpaceCapabilities = await uiCapabilitiesService.get({
spaceId: scenario.id,
});
expect(nothingSpaceCapabilities.success).to.be(true);
expect(nothingSpaceCapabilities.value).to.have.property('savedObjectsManagement');
const nothingSpaceExpected = mapValues(
nothingSpaceCapabilities.value!.savedObjectsManagement,
() => savedObjectsManagementBuilder.uiCapabilities('none')
);
expect(nothingSpaceCapabilities.value!.savedObjectsManagement).to.eql(
nothingSpaceExpected
);
break;
default:
// Otherwise it's available without restriction
const uiCapabilities = await uiCapabilitiesService.get({ spaceId: scenario.id });
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('savedObjectsManagement');
const expected = mapValues(uiCapabilities.value!.savedObjectsManagement, () =>
savedObjectsManagementBuilder.uiCapabilities('all')
);
expect(uiCapabilities.value!.savedObjectsManagement).to.eql(expected);
}
});
示例2: getAllOutcomesProfitLoss
export async function getAllOutcomesProfitLoss(db: Knex, params: GetProfitLossParamsType): Promise<AllOutcomesProfitLoss> {
const { profits, outcomeValues, buckets, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId } = await getProfitLossData(db, params);
const bucketedProfits = _.mapValues(profits, (pls, marketId) => {
return bucketAtTimestamps<ProfitLossTimeseries>(pls, buckets, Object.assign(getDefaultPLTimeseries(), { marketId }));
});
const bucketedOutcomeValues = _.mapValues(outcomeValues, (marketOutcomeValues) => {
return bucketAtTimestamps<OutcomeValueTimeseries>(marketOutcomeValues, buckets, getDefaultOVTimeseries());
});
const profit = _.mapValues(bucketedProfits, (pls, marketId) => {
return getProfitResultsForMarket(pls, bucketedOutcomeValues[marketId], buckets, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId);
});
const marketOutcomes = _.fromPairs(_.values(_.mapValues(profits, (pls) => {
const first = _.first(_.first(_.values(pls)))!;
return [first.marketId, first.numOutcomes];
})));
return {
profit,
marketOutcomes,
buckets,
};
}
示例3: run
async run(input: Input) {
this.logger.info(`Collating venues for ${this.academicYear} semester ${this.semester}`);
// Insert module code and flatten lessons
const venueLessons: LessonWithModuleCode[] = flatMap(input, (module) =>
module.semesterData.timetable.map(
(lesson: RawLesson): LessonWithModuleCode => ({
...lesson,
moduleCode: module.moduleCode,
}),
),
);
const venues = extractVenueAvailability(venueLessons);
// Get a mapping of module code to module title to help with module aliasing
const moduleCodeToTitle: { [moduleCode: string]: ModuleTitle } = {};
input.forEach((module) => {
moduleCodeToTitle[module.moduleCode] = module.module.title;
});
// Merge dual-coded modules and extract the aliases generated for use later
const allAliases: ModuleAliases = {};
for (const venue of values(venues)) {
for (const availability of venue) {
const { lessons, aliases } = mergeDualCodedModules(availability.classes);
availability.classes = lessons;
// Merge the alias mappings
for (const [moduleCode, alias] of entries(aliases)) {
// Only add the modules as alias if they have the same title
const title = moduleCodeToTitle[moduleCode];
const filteredAliases = Array.from(alias).filter(
(module) => title === moduleCodeToTitle[module],
);
if (filteredAliases.length) {
allAliases[moduleCode] = union(
allAliases[moduleCode] || new Set(),
new Set(filteredAliases),
);
}
}
}
}
// Save the results
const outputAliases = mapValues(allAliases, (moduleCodes) => Array.from(moduleCodes));
const venueList = Object.keys(venues);
await Promise.all([
this.io.venueInformation(this.semester, venues),
this.io.venueList(this.semester, venueList),
this.aliasCache.write(mapValues(outputAliases, (set): string[] => Array.from(set))),
]);
return { venues, aliases: allAliases };
}
示例4: it
it('undefined nested values in new settings should be ignored', () => {
const newSettings: SettingsPartial<any> = {
filterOptions: _.mapValues(allSettings.filterOptions, _.constant(undefined)),
dataOptions: _.mapValues(allSettings.dataOptions, _.constant(undefined)),
groupOptions: _.mapValues(allSettings.groupOptions, _.constant(undefined))
};
const actual = Settings.merge(allSettings, newSettings);
expect(actual).toEqualPlainObject(allSettings);
});
示例5: getRefPaths
function getRefPaths(obj: object, paths: { [key: string]: any }): { [key: string]: string } {
// pick because it's an object (map)
const singleRefsFiltered = pickBy(paths, schemaType => schemaType.options && schemaType.options.ref);
const singleRefs = mapValues(singleRefsFiltered, schemaType => schemaType.options.ref);
const arrayRefsFiltered = pickBy(paths, schemaType => schemaType.caster && schemaType.caster.instance && schemaType.caster.options && schemaType.caster.options.ref);
const arrayRefs = mapValues(arrayRefsFiltered, schemaType => schemaType.caster.options.ref);
return explodePaths(obj, singleRefs, arrayRefs);
}
示例6: locatonExtractor
export function locatonExtractor(text: string): any {
const allPhrases = createTokens(text);
// console.log('allPhrases', allPhrases);
const matchingCities = _.mapValues(locations, topic =>
_.pickBy(topic, (value: Array<string>, key: string) => {
const theseCities = value.map(location => location.toLowerCase());
// console.log(theseCities);
return _.intersection(allPhrases, theseCities).length > 0;
}));
// console.log('matchingCities', matchingCities);
const pickedTopics = _.pickBy(matchingCities, topic => _.keys(topic).length > 0);
const mapped = _.mapValues(pickedTopics, topic => _.keys(topic));
// console.log(matchingCities);
return mapped as locationMap;
}
示例7: fetch
async function fetch(
queries:IQuery[],
sampleFilterByProfile: SampleFilterByProfile
): Promise<AugmentedData<GenesetMolecularData[], IQuery>[]> {
const genesetIdsByProfile = _.mapValues(
_.groupBy(queries, q => q.molecularProfileId),
profileQueries => profileQueries.map(q => q.genesetId)
);
const params = Object.keys(genesetIdsByProfile)
.map(profileId => ({
geneticProfileId: profileId,
// the Swagger-generated type expected by the client method below
// incorrectly requires both samples and a sample list;
// use 'as' to tell TypeScript that this object really does fit.
// tslint:disable-next-line: no-object-literal-type-assertion
genesetDataFilterCriteria: {
genesetIds: genesetIdsByProfile[profileId],
...sampleFilterByProfile[profileId]
} as GenesetDataFilterCriteria
})
);
const dataPromises = params.map(param => client.fetchGeneticDataItemsUsingPOST(param));
const results: GenesetMolecularData[][] = await Promise.all(dataPromises);
return augmentQueryResults(queries, results);
}