mihneadb / node-directory-tree

Convert a directory tree to a JS object.
MIT License
523 stars 106 forks source link

saving results of callback #51

Closed punund closed 6 years ago

punund commented 6 years ago

Would you consider adding the resut of callback function to the item? Patch would be trivial, something along the lines

-                       onEachFile(item, PATH);
+                       const results = onEachFile(item, PATH);
+                       if (results !== undefined)
+                               item.data = results;
mihneadb commented 6 years ago

You have access to item in the callback so you should be able to set an attribute from within it. I'm thinking that should be enough, since I don't know how popular a pattern this is. Wdyt?

punund commented 6 years ago

You are right, I can do that. Just seems a little un-functional having to modify a parameter.

mihneadb commented 6 years ago

I agree, it's not pure. I'd be OK with a variant of what you suggested as well if you think it's crucial at this point. Feel free to send a PR if so! :) 🥂