feat: add support for Arrays
niftylettuce opened this issue · 3 comments
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
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.
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}));
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