本文整理汇总了TypeScript中lodash.toPairs函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toPairs函数的具体用法?TypeScript toPairs怎么用?TypeScript toPairs使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toPairs函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Date
.then(rows => {
let total = 0
const totalChannel = {}
const result = {}
const min = dates.format(moment(new Date(dates.min)).subtract(1, 'day'))
result[min] = Object.assign({}, statsBase)
rows.map(row => {
const date = dates.format(row.date)
if (!result[date]) {
result[date] = Object.assign({}, statsBase)
}
if (!totalChannel[row.channel]) {
totalChannel[row.channel] = 0
}
const count = parseInt(row.count)
totalChannel[row.channel] += count
result[date].total = total += count
result[date][row.channel] = totalChannel[row.channel]
})
const max = dates.format(moment(new Date(dates.max)).add(1, 'hour'))
result[max] = Object.assign({}, statsBase, { total: total }, totalChannel)
return _.toPairs(result).map(([k, v]) => {
v['name'] = k
return v
})
})
示例2: function
_.forEach(input.cells, function (cell) {
let index = _.pick(cell, drilldowns);
let indexPairs = _.toPairs(index);
let already = _.find(results, function (result) {
return _.every(indexPairs, function (indexPair) {
return result[indexPair[0]] == indexPair[1];
});
});
if(already==undefined){
already = index;
results.push(already);
}
_.forEach(aggregates, function (aggregate) {
if(!already[aggregate]) {
already[aggregate] = cell[aggregate];
}
else{
already[aggregate] *= cell[aggregate];
}
});
})
示例3: createMetricLabel
createMetricLabel(md, target, groupByTags, options) {
if (target.alias) {
const scopedVars = _.clone(options.scopedVars || {});
_.each(md.tags, (value, key) => {
scopedVars['tag_' + key] = { value: value };
});
return this.templateSrv.replace(target.alias, scopedVars);
}
let label = md.metric;
const tagData = [];
if (!_.isEmpty(md.tags)) {
_.each(_.toPairs(md.tags), tag => {
if (_.has(groupByTags, tag[0])) {
tagData.push(tag[0] + '=' + tag[1]);
}
});
}
if (!_.isEmpty(tagData)) {
label += '{' + tagData.join(', ') + '}';
}
return label;
}
示例4: getOriginalMetricName
getOriginalMetricName(labelData) {
const metricName = labelData.__name__ || '';
delete labelData.__name__;
const labelPart = _.map(_.toPairs(labelData), label => {
return label[0] + '="' + label[1] + '"';
}).join(',');
return metricName + '{' + labelPart + '}';
}
示例5: function
this.getOriginalMetricName = function(labelData) {
var metricName = labelData.__name__ || '';
delete labelData.__name__;
var labelPart = _.map(_.toPairs(labelData), function(label) {
return label[0] + '="' + label[1] + '"';
}).join(',');
return metricName + '{' + labelPart + '}';
};
示例6:
calculated: (state, dependencies) => {
let resources = state.values || [];
let resourceTypes = _.toPairs(
_.groupBy(state.values, 'kind')).map(val => ({ name: val[0], value: val[1].length})
);
return { resources, resourceTypes };
}
示例7: formatSubj
private formatSubj(cnf: OpenSSLConfig) {
const subjNames = new Map([
['countryName', 'C'],
['stateOrProvinceName', 'ST'],
['localityName', 'L'],
['organizationName', 'O'],
['commonName', 'CN'],
]);
return '/' + lodash.toPairs(cnf).filter(([k]) => subjNames.has(k)).map(([k, v]) => `${subjNames.get(k)}=${v}`).join('/');
}
示例8: memoize
export const groupByDomains = memoize((measures: T.MeasureEnhanced[]) => {
const domains = toPairs(groupBy(measures, measure => measure.metric.domain)).map(r => ({
name: r[0],
measures: r[1]
}));
return sortBy(domains, [
(domain: { name: string; measures: T.MeasureEnhanced[] }) => {
const idx = KNOWN_DOMAINS.indexOf(domain.name);
return idx >= 0 ? idx : KNOWN_DOMAINS.length;
},
'name'
]);
});
示例9: Error
export function getCollectionLinksSorted<D extends Tyr.Document>(
plugin: GraclPlugin,
col: Tyr.CollectionInstance<D>,
opts: { direction: string; relate?: string } = { direction: 'outgoing' }
): Tyr.FieldInstance[] {
const collectionFieldCache = plugin.sortedLinkCache;
const hash = `${col.def.name}:${_.toPairs(opts)
.map(e => e.join('='))
.sort()
.join(':')}`;
if (collectionFieldCache[hash]) {
return collectionFieldCache[hash];
}
const linkFields = col.links(opts);
// sort fields by link collection name
const links = _.chain(linkFields)
.groupBy(field => field.link!.def.name)
.map((colLinks: Tyr.FieldInstance[], colName: string) => {
/**
* multiple links to collection?
*/
if (colLinks.length > 1) {
const filtered = colLinks.filter(
field =>
!!(field.def as Tyr.FieldDefinition & {
graclTypes?: string[] | string;
}).graclTypes
);
/**
* no graclType links? use first available...
*
* TODO: multiple?
*/
if (filtered.length === 0) {
return colLinks.slice(0, 1);
/**
* one? use it
*/
} else if (filtered.length === 1) {
return filtered;
} else {
throw new Error(
`Multiple links to ${colName} for collection ${
col.def.name
} have graclTypes`
);
}
} else {
return colLinks;
}
})
.flatten()
.sortBy((field: Tyr.FieldInstance) => field.link && field.link.def.name)
.value() as Tyr.FieldInstance[];
return (collectionFieldCache[hash] = links);
}
示例10: toPairs
.subscribe(album => {
this.album = album
this.trackGroups = toPairs(groupBy(album.tracks, 'group'))
this.albumImageUrl = this.nmlService.signResourceUrl(album.artwork, {w: 50, h: 50})
})