sort-js-object-keys
sort-js-object-keys copied to clipboard
Feature: Only sort first N levels
It would be useful if I could sort an object only at its first level, and not sort all the subkeys as well. And maybe some people would want to sort the first 2 levels, but not the next ones.
For example:
// Before sort
const countries = {
CH: {
name: 'Switzerland',
description: 'Chocolate and watches',
},
BE: {
name: 'Belgium',
description: 'Beer and fries',
},
};
// Output after sort, 1st level only
const countries = {
BE: {
name: 'Belgium',
description: 'Beer and fries',
},
CH: {
name: 'Switzerland',
description: 'Chocolate and watches',
},
};
In this case, I want the first level sorted, but not the second, because it makes more sense to keep the name key first for ease of reading.