fvclaus / vsc-sort-json-array

Visual Studio Code extension that sorts arrays
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Feature Request: sort String arrays with Case Insensitive option #23

Closed samkatakouzinos closed 2 years ago

samkatakouzinos commented 2 years ago

I'm using this extension and works as intended. I'm assuming 'lexicographic order' sort Strings as Case Sensitive.

I would like the option to sort Strings as Case Insensitive. This would allow the JSON arrays to have Big and Small Strings together, instead of Big first and then Small last.

For example:

Rather than the default Case Sensitive sorts like; Able Bring Credit addict bought cash

I would like Case Insensitive sorts like; Able addict bought Bring cash Credit

May this be implemented in User Settings and /or another step in key selection? Thank you for your consideration.

fvclaus commented 2 years ago

Thanks for reporting this! The current string sort order is a bug, because it sorts by code point order and not by lexicographic order as stated in the Readme. Lexicographic order should be A, a, B, b or a, A, b, B, but not A, B, a, b. The new code uses the Intl.Collator for sorting. Because I don't think that the code point sort order is useful at all, the extension will only support the options of the Intl.Collator constructor. Its options are configurable through new settings of the extension. For example, caseFirst=upper would result in the A, a, B, b. There are other options such as numeric, ignorePunctuation and locale, which should cover all conceivable sorting requirements.

The code is part of version 3.1.0 which I just published.