-1

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?

linuxdan
  • 4,476
  • 4
  • 30
  • 41

1 Answers1

0

It looks like .get(0) will get the first Node Path in a Collection, so

j(file.source).find(j.ExportDefaultDeclaration).get(0);

would return the Node Path in question.

linuxdan
  • 4,476
  • 4
  • 30
  • 41