Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Attributes" not working as expected #74

Open
clse opened this issue Mar 31, 2020 · 4 comments
Open

"Attributes" not working as expected #74

clse opened this issue Mar 31, 2020 · 4 comments

Comments

@clse
Copy link

clse commented Mar 31, 2020

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 extension from files
  • toggles off type from files
  • toggles on type for directories
  • toggles on size for directories
  • keeps size on files

This is very inconsistent behavior so I'm unsure how to proceed.

Thanks in advance.

@mihneadb
Copy link
Owner

mihneadb commented Apr 2, 2020

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?

@clse
Copy link
Author

clse commented Apr 6, 2020

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:

  1. Option 1: Default attributes only "name", "path" and "children"
  2. Option 2: Any number of default attributes, but same default attributes for files and directories
  3. Option 3: Separate attribute options into "fileAttributes" and "directoryAttributes".

My vote would be for Option 1. Leaner is better. What do you think?

@mihneadb
Copy link
Owner

Sorry about the extremely slow response this time.
Indeed, option 1 sounds best. PR is welcome if you want to contribute!

@ApayRus
Copy link

ApayRus commented Feb 3, 2021

Hi. It is good to have the option to exclude default attributes! I am looking for it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants