API to get list of dependencies


Let’s suppose I have a package.json “a” where dependencies: [“b”, “c”]

Then I have a package.json for “b” where dependencies: [“d”] and for “c” where dependencies: [“d”, “e”]

Is there an API that would give me the list of unique dependencies for “a”?
In this case I would expect: b, c, d, and e.

Do we have a mechanism that prevents circular dependencies?