@@ -265,6 +265,15 @@ function getSorter(ascending) {
265265 }
266266}
267267
268+ function swapCase ( input ) {
269+ let result = ''
270+ for ( let i = 0 ; i < input . length ; i ++ ) {
271+ const lower = input [ i ] . toLowerCase ( )
272+ result += input [ i ] === lower ? input [ i ] . toUpperCase ( ) : lower
273+ }
274+ return result
275+ }
276+
268277function mutateRanksToAlphabetize ( imported , alphabetizeOptions ) {
269278 const groupedByRanks = imported . reduce ( function ( acc , importedItem ) {
270279 if ( ! Array . isArray ( acc [ importedItem . rank ] ) ) {
@@ -277,7 +286,10 @@ function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
277286 const groupRanks = Object . keys ( groupedByRanks )
278287
279288 const sorterFn = getSorter ( alphabetizeOptions . order === 'asc' )
280- const comparator = alphabetizeOptions . caseInsensitive ? ( a , b ) => sorterFn ( String ( a ) . toLowerCase ( ) , String ( b ) . toLowerCase ( ) ) : ( a , b ) => sorterFn ( a , b )
289+ const comparator =
290+ alphabetizeOptions . caseInsensitive === 'invert' ? ( a , b ) => sorterFn ( swapCase ( String ( a ) ) , swapCase ( String ( b ) ) )
291+ : alphabetizeOptions . caseInsensitive ? ( a , b ) => sorterFn ( String ( a ) . toLowerCase ( ) , String ( b ) . toLowerCase ( ) )
292+ : ( a , b ) => sorterFn ( a , b )
281293 // sort imports locally within their group
282294 groupRanks . forEach ( function ( groupRank ) {
283295 groupedByRanks [ groupRank ] . sort ( comparator )
@@ -544,8 +556,10 @@ module.exports = {
544556 type : 'object' ,
545557 properties : {
546558 caseInsensitive : {
547- type : 'boolean' ,
548- default : false ,
559+ anyOf : [
560+ { type : 'boolean' , default : false } ,
561+ { type : 'string' , enum : [ 'invert' ] } ,
562+ ] ,
549563 } ,
550564 order : {
551565 enum : [ 'ignore' , 'asc' , 'desc' ] ,
0 commit comments