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: add support for Arrays #12

Closed
niftylettuce opened this issue Jun 17, 2019 · 3 comments
Closed

feat: add support for Arrays #12

niftylettuce opened this issue Jun 17, 2019 · 3 comments

Comments

@niftylettuce
Copy link

Right now you can't pass an Array to sortKeys(...) - ideally we should be able to pass an Array (e.g. an Array of objects) or a plain Object to the method exported.

Related: #10

@sindresorhus
Copy link
Owner

sindresorhus commented Jul 21, 2019

Why? Do you have any actual use-cases for this? This module is about sorting the keys of objects. Feels weird to support array as an input, even if it's an array of objects.

@coreyfarrell
Copy link
Contributor

If you know you're dealing with an array of objects you can do the following:

const sorted = arrayOfObjects.map(item => sortKeys(item, {deep: true}));

@jamestalmage
Copy link
Contributor

This would improve the experience for hash-obj, which breaks on arrays because of this module.

This would be a useful addition for any number of libraries that need a consistent scan order of an arbitrary object (i.e. I don't know if the user is giving me an array, or a plain obj).

Additionally, it is not trivial to wrap this for Array's as @coreyfarrell suggests, as you would miss out on circular reference when deep-sorting

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

4 participants