ljharb / js-traverse

MIT License
45 stars 8 forks source link

Feature suggestion, upstream path #7

Open chrisjameslennon opened 4 months ago

chrisjameslennon commented 4 months ago

Sometimes it is helpful to go up the tree as well as down it. Would you consider a method like .upstreamPath() that returns the path, upwards until the root node

To be honest I am not sure it is as simple as that :-) But this feature would be useful I think

ljharb commented 4 months ago

Separate from the technical implementation - which i suspect would be tricky - what's the use case?

chrisjameslennon commented 4 months ago

I am writing a json model generation (with schema validation) library

ljharb commented 4 months ago

can you elaborate? when you're traversing down, you can easily keep references to the parents; when is it necessary to not do that such that you'd need the path?

chrisjameslennon commented 4 months ago

I thought you might ask me that :-) I make several traversals, and gather data on the object. However keeping references to parents may be sufficient. I'll pursue that approach