I'm just getting started with writing CodeMods with jscodeshift
. I noticed that the find
method seems to always return a Collection
. If there is only one node path in the collection is there an easy way to extract that node path?
For example, I can easily get the default export, of which there will only ever be one:
j(file.source).find(j.ExportDefaultDeclaration)
However, this returns a collection, which I then need to call forEach
on to process the one and only node.
Is there a better way?