Skip to content

feat: add .getAll() to get all config items#198

Closed
wy-luke wants to merge 8 commits intosindresorhus:mainfrom
wy-luke:main
Closed

feat: add .getAll() to get all config items#198
wy-luke wants to merge 8 commits intosindresorhus:mainfrom
wy-luke:main

Conversation

@wy-luke
Copy link

@wy-luke wy-luke commented May 18, 2025

Assuming that I have a config like below:

{
  "a": "a",
  "b": "b",
  "c": "c",
  "d": "d"
}

To get all configs, I must use get(xx) four times. I think maybe it's a good idea to use get() to retrieve all configs at one time.
When using electron, it can also get all configs with only one disk IO.

@sindresorhus
Copy link
Owner

This should be a separate method.

@wy-luke
Copy link
Author

wy-luke commented May 18, 2025

@sindresorhus How about this: 7019c7c

@wy-luke wy-luke changed the title feat: allow get to return entire store when no key is provided feat: add.getAll() to get all entire items May 18, 2025
@wy-luke wy-luke changed the title feat: add.getAll() to get all entire items feat: add .getAll() to get all entire items May 18, 2025
@wy-luke wy-luke changed the title feat: add .getAll() to get all entire items feat: add .getAll() to get all config items May 18, 2025
@sindresorhus
Copy link
Owner

Needs a test.

@wy-luke
Copy link
Author

wy-luke commented May 21, 2025

@sindresorhus All done. Take a look plz.

@sindresorhus
Copy link
Owner

I just realized, this already exists as config.store.

@wy-luke
Copy link
Author

wy-luke commented May 21, 2025

I just realized, this already exists as config.store.

I think getAll would be more clear and easy to know. Besides, getAll can return {} when config.store is null or undefined, right?

But still, it's up to you. ❤️

@sindresorhus
Copy link
Owner

Besides, getAll can return {} when config.store is null or undefined, right?

No, it always returns an object.

@sindresorhus
Copy link
Owner

I think .store is good enough.

@wy-luke
Copy link
Author

wy-luke commented May 22, 2025

@sindresorhus At least, adding this usage to the Readme is necessary. It's easy to use but too hard to know it, even you realize its existence later. 😂

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

Successfully merging this pull request may close these issues.

2 participants