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

feat(utilities): add getDeepObjectKeys #413

Merged
merged 3 commits into from
Aug 4, 2022
Merged

Conversation

favna
Copy link
Member

@favna favna commented Aug 4, 2022

Function I wrote for work and I figured I should port it over, improve the types and write unit tests for it

Copy link
Member

@kyranet kyranet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, there should be a private generator function that yields values, it's a lot more efficient than creating an array per level, specially since you can do yield* to efficiently defer other generators.

The exported method can do return [...privateGeneratorFunction(obj)] to get the array.

): string[] {
const keys: string[] = [];

for (const [key, value] of Object.entries(obj)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should support top-level arrays too.

@favna favna merged commit b8b0883 into main Aug 4, 2022
@favna favna deleted the feat/add-getDeepObjectKeys branch August 4, 2022 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants