"Attributes" not working as expected
Current default output includes type, size, and extension. It is impossible to remove these attributes, though they are cluttering the JSON since they are unnecessary for my purposes.
const output = dirTree(
mypath,
{attributes: ["extension", "type", "size"]}
);
By adding those three attributes to the call, it does the following:
- toggles off
extensionfrom files - toggles off
typefrom files - toggles on
typefor directories - toggles on
sizefor directories - keeps
sizeon files
This is very inconsistent behavior so I'm unsure how to proceed.
Thanks in advance.
Indeed, there are a few attrs that are always present - https://github.com/mihneadb/node-directory-tree/blob/master/lib/directory-tree.js#L76-L78 and https://github.com/mihneadb/node-directory-tree/blob/master/lib/directory-tree.js#L102-L103.
Should be easy to fix. Probably extension, type and size can become optional as well. What are your thoughts?
Thanks for the quick response, @mihneadb , appreciate it! In my opinion, only "name", "path" and "children" are necessary fields that should be toggled by default. If you think other attributes need to be on by default, I would argue it would be preferable for those attributes to be consistent across both files and directories (all nodes get "extension", all nodes get "size", etc) so they could be easily disabled within the attributes option rather than produce unexpected behavior (turned off for files, turned on for directories). The last option would be to have fileAttributes and directoryAttributes separate objects in options. To summarize, three courses of action would solve the issue:
- Option 1: Default attributes only "name", "path" and "children"
- Option 2: Any number of default attributes, but same default attributes for files and directories
- Option 3: Separate attribute options into "fileAttributes" and "directoryAttributes".
My vote would be for Option 1. Leaner is better. What do you think?
Sorry about the extremely slow response this time. Indeed, option 1 sounds best. PR is welcome if you want to contribute!
Hi. It is good to have the option to exclude default attributes! I am looking for it too.