本文整理匯總了TypeScript中lodash/fp.has函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript has函數的具體用法?TypeScript has怎麽用?TypeScript has使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了has函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: has
const getHostFieldValue = (fieldName: string, bucket: HostAggEsItem): string | string[] | null => {
const aggField = hostFieldsMap[fieldName]
? hostFieldsMap[fieldName].replace(/\./g, '_')
: fieldName.replace(/\./g, '_');
if (
[
'host.ip',
'host.mac',
'cloud.instance.id',
'cloud.machine.type',
'cloud.provider',
'cloud.region',
].includes(fieldName) &&
has(aggField, bucket)
) {
const data: HostBuckets = get(aggField, bucket);
return data.buckets.map(obj => obj.key);
} else if (has(`${aggField}.buckets`, bucket)) {
return getFirstItem(get(`${aggField}`, bucket));
} else if (has(aggField, bucket)) {
const valueObj: HostValue = get(aggField, bucket);
return valueObj.value_as_string;
}
return null;
};
示例2: merge
export const mergeFieldsWithHit = <T>(
fieldName: string,
flattenedFields: T,
fieldMap: Readonly<Record<string, string>>,
hit: { _source: {} }
) => {
if (fieldMap[fieldName] != null) {
const esField = fieldMap[fieldName];
if (has(esField, hit._source)) {
const objectWithProperty = {
node: {
...get('node', flattenedFields),
...fieldName
.split('.')
.reduceRight((obj, next) => ({ [next]: obj }), get(esField, hit._source)),
},
};
return merge(flattenedFields, objectWithProperty);
} else {
return flattenedFields;
}
} else {
return flattenedFields;
}
};
示例3: set
Object.keys(timelineInput).reduce<TimelineInput>((acc, key) => {
if (has(key, timeline)) {
if (key === 'kqlQuery') {
return set(`${key}.filterQuery`, get(`${key}.filterQuery`, timeline), acc);
} else if (key === 'dateRange') {
return set(`${key}`, { start: timelineTimeRange.from, end: timelineTimeRange.to }, acc);
} else if (key === 'columns' && get(key, timeline) != null) {
return set(
key,
get(key, timeline).map((col: ColumnHeader) => omit(['width', '__typename'], col)),
acc
);
}
return set(key, get(key, timeline), acc);
}
return acc;
}, timelineInput);