t-comm
Version:
专业、稳定、纯粹的工具库
21 lines (20 loc) • 702 B
TypeScript
type IDeps = Record<string, Array<string>>;
/**
* 将嵌套的依赖关系打平为一维映射
* 递归遍历依赖关系图,将每个节点的所有直接和间接依赖打平为数组,并去重
* @param {Record<string, Array<string>>} deps 依赖关系映射,key 为节点名,value 为其直接依赖的节点数组
* @returns {Record<string, Array<string>>} 打平后的依赖关系映射
* @example
* ```ts
* const deps = {
* a: ['b', 'c'],
* b: ['d'],
* c: [],
* d: [],
* };
* const result = getFlattenedDeps(deps);
* // { a: ['b', 'c', 'd'], b: ['d'], c: [], d: [] }
* ```
*/
export declare function getFlattenedDeps(deps: IDeps): Record<string, any>;
export {};