本文整理汇总了TypeScript中JSONPath.nodes函数的典型用法代码示例。如果您正苦于以下问题:TypeScript nodes函数的具体用法?TypeScript nodes怎么用?TypeScript nodes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nodes函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: matches
export function nodes<T>(obj: T, jsonQuery: string): { path: JsonPath, value: any }[] {
// jsonpath only accepts objects
if (obj instanceof Object) {
return jsonpath.nodes(obj, jsonQuery).map(x => { return { path: x.path.slice(1), value: x.value }; });
} else {
return matches(jsonQuery, []) ? [{ path: [], value: obj }] : [];
}
}
示例2: GetDefinitionLocations
/**
* Retrieves all locations in the entire OpenAPI definition (and corresponding values) matching given JSON query.
*/
public * GetDefinitionLocations(jsonQuery: string): Iterable<{ value: any, jsonPath: string }> {
for (const path of nodes(this.fullyResolvedAndMergedDefinition, jsonQuery)) {
yield {
value: path.value,
jsonPath: stringify(path.path)
};
}
}
示例3: matches
export function nodes<T>(obj: T, jsonQuery: string): { path: JsonPath, value: any }[] {
// jsonpath only accepts objects
if (obj instanceof Object) {
let result = jsonpath.nodes(obj, jsonQuery).map(x => { return { path: x.path.slice(1), value: x.value }; });
const comp = (a: string, b: string) => a < b ? -1 : (a > b ? 1 : 0);
result = result.sort((a, b) => comp(JSON.stringify(a.path), JSON.stringify(b.path)));
result = result.filter((x, i) => i === 0 || JSON.stringify(x.path) !== JSON.stringify(result[i - 1].path));
return result;
} else {
return matches(jsonQuery, []) ? [{ path: [], value: obj }] : [];
}
}
示例4:
export function nodes<T>(obj: T, jsonQuery: string): { path: JsonPath, value: any }[] {
return jsonpath.nodes(obj, jsonQuery).map(x => { return { path: x.path.slice(1), value: x.value }; });
}
示例5: nodes
Object.keys(queries).forEach((identifier) => results[identifier] = nodes(document, queries[identifier]));