本文整理汇总了TypeScript中lodash.set函数的典型用法代码示例。如果您正苦于以下问题:TypeScript set函数的具体用法?TypeScript set怎么用?TypeScript set使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setValue
public async setValue(opts: CommandOptions) {
// get value so we have a type
const splitted = opts.parameters.split(' ');
const pointer = splitted.shift();
let newValue = splitted.join(' ');
if (!pointer) {
return sendMessage(`$sender, settings does not exists`, opts.sender);
}
const currentValue = await get(global, pointer, undefined);
if (typeof currentValue !== 'undefined') {
if (isBoolean(currentValue)) {
newValue = newValue.toLowerCase().trim();
if (['true', 'false'].includes(newValue)) {
set(global, pointer, newValue === 'true');
sendMessage(`$sender, ${pointer} set to ${newValue}`, opts.sender);
} else {
sendMessage('$sender, !set error: bool is expected', opts.sender);
}
} else if (isNumber(currentValue)) {
if (isFinite(Number(newValue))) {
set(global, pointer, Number(newValue));
sendMessage(`$sender, ${pointer} set to ${newValue}`, opts.sender);
} else {
sendMessage('$sender, !set error: number is expected', opts.sender);
}
} else if (isString(currentValue)) {
set(global, pointer, newValue);
sendMessage(`$sender, ${pointer} set to '${newValue}'`, opts.sender);
} else {
sendMessage(`$sender, ${pointer} is not supported settings to change`, opts.sender);
}
} else {
sendMessage(`$sender, ${pointer} settings not exists`, opts.sender);
}
}
示例2: set
groupBy.forEach((grouping: InfraPathInput, index: number) => {
if (isGroupByTerms(grouping)) {
const termsAgg = {
aggs: {},
terms: {
field: grouping.field,
size: 10,
},
};
set(aggs, `path_${index}`, termsAgg);
aggs = termsAgg.aggs;
}
if (grouping && isGroupByFilters(grouping)) {
const filtersAgg = {
aggs: {},
filters: {
filters: grouping.filters!.map(
(filter: InfraPathFilterInput): InfraESQueryStringQuery => {
return {
query_string: {
analyze_wildcard: true,
query: (filter && filter.query) || '*',
},
};
}
),
},
};
set(aggs, `path_${index}`, filtersAgg);
aggs = filtersAgg.aggs;
}
});
示例3: return
return (doc: InfraESSearchBody) => {
const result = cloneDeep(doc);
const field = nodeTypeToField(options);
set(result, 'aggs.waffle.aggs.nodes.terms', {
field,
include: {
num_partitions: options.numberOfPartitions,
partition: options.partitionId,
},
order: { _key: 'asc' },
size: NODE_REQUEST_PARTITION_SIZE * NODE_REQUEST_PARTITION_FACTOR,
});
set(result, 'aggs.waffle.aggs.nodes.aggs', {
nodeDetails: {
top_hits: {
size: 1,
_source: { includes: [NAME_FIELDS[options.nodeType]] },
sort: [{ [fields.timestamp]: { order: 'desc' } }],
},
},
});
return result;
};
示例4: removeArtifactFromField
public static removeArtifactFromField(field: string, obj: { [key: string]: string | string[] }, artifactId: string) {
const reference = get(obj, field);
if (Array.isArray(reference)) {
set(obj, field, reference.filter((a: string) => a !== artifactId));
} else if (reference === artifactId) {
set(obj, field, null);
}
}
示例5: it
it("returns UTC when browser support is not there", () => {
const x = get(window, "Intl", undefined);
set(window, "Intl", undefined);
window.alert = jest.fn();
expect(inferTimezone(undefined)).toBe("UTC");
expect(window.alert).toHaveBeenCalledWith(expect.stringContaining("UTC"));
set(window, "Intl", x);
});
示例6: getIndexBoundsForPointData
export function getIndexBoundsForPointData(data: SeriesData, xValueBounds: Interval, xValuePath: string): IndexBounds {
const lowerBound = _.set({}, xValuePath, xValueBounds.min);
const upperBound = _.set({}, xValuePath, xValueBounds.max);
const firstIndex = _.sortedIndexBy(data, lowerBound, xValuePath);
const lastIndex = _.sortedLastIndexBy(data, upperBound, xValuePath);
return adjustBounds(firstIndex, lastIndex, data.length);
}
示例7: it
it("Does not crash if process.env.NODE_ENV is undefined", () => {
const old = get(process.env, "NODE_ENV", "development");
set(process.env, "NODE_ENV", "");
const result1 = configureStore();
expect(result1)
.toEqual(expect.objectContaining({ getState: expect.anything() }));
set(process.env, "NODE_ENV", old);
});
示例8: getBoundsForInstantaeousData
export function getBoundsForInstantaeousData(timestampedData: SeriesData, timeRange: Range, timestampPath: string = 'timestamp'): IndexBounds {
const lowerBound = _.set({}, timestampPath, timeRange.min);
const upperBound = _.set({}, timestampPath, timeRange.max);
const firstIndex = _.sortedIndexBy(timestampedData, lowerBound, timestampPath);
const lastIndex = _.sortedLastIndexBy(timestampedData, upperBound, timestampPath);
return adjustBounds(firstIndex, lastIndex, timestampedData.length);
}
示例9:
await Promise.all(tmpl2paths(template).map(async path => {
const val = await _.get(params, path);
if (val) {
if (typeof val === "object") {
const val_ = await val.toString();
_.set(params_, path + ".toString", () => val_);
} else {
_.set(params_, path, val);
}
}
}));