sort-js-object-keys icon indicating copy to clipboard operation
sort-js-object-keys copied to clipboard

Feature: Only sort first N levels

Open Floriferous opened this issue 6 years ago • 0 comments

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.

Floriferous avatar Jun 11 '19 10:06 Floriferous