@@ -93,6 +93,7 @@ export interface IMarkdownDocumenterOptions {
93
93
outputFolder : string ;
94
94
addFileNameSuffix : boolean ;
95
95
projectName : string ;
96
+ shouldSortFunctions : boolean ;
96
97
}
97
98
98
99
/**
@@ -108,13 +109,15 @@ export class MarkdownDocumenter {
108
109
private readonly _pluginLoader : PluginLoader ;
109
110
private readonly _addFileNameSuffix : boolean ;
110
111
private readonly _projectName : string ;
112
+ private readonly _shouldSortFunctions : boolean ;
111
113
112
114
public constructor ( options : IMarkdownDocumenterOptions ) {
113
115
this . _apiModel = options . apiModel ;
114
116
this . _documenterConfig = options . documenterConfig ;
115
117
this . _outputFolder = options . outputFolder ;
116
118
this . _addFileNameSuffix = options . addFileNameSuffix ;
117
119
this . _projectName = options . projectName ;
120
+ this . _shouldSortFunctions = options . shouldSortFunctions ;
118
121
this . _tsdocConfiguration = CustomDocNodes . configuration ;
119
122
this . _markdownEmitter = new CustomMarkdownEmitter ( this . _apiModel ) ;
120
123
@@ -834,11 +837,13 @@ page_type: reference
834
837
headerTitles : [ 'Enumeration' , 'Description' ]
835
838
} ) ;
836
839
837
- const functionsTable : DocTable = new DocTable ( {
840
+ const finalFunctionsTable : DocTable = new DocTable ( {
838
841
configuration,
839
842
headerTitles : [ 'Function' , 'Description' ]
840
843
} ) ;
841
844
845
+ const functionsRowGroup : Record < string , DocTableRow [ ] > = { } ;
846
+
842
847
const interfacesTable : DocTable = new DocTable ( {
843
848
configuration,
844
849
headerTitles : [ 'Interface' , 'Description' ]
@@ -859,7 +864,8 @@ page_type: reference
859
864
headerTitles : [ 'Type Alias' , 'Description' ]
860
865
} ) ;
861
866
862
- const functionsDefinitions : DocNode [ ] = [ ] ;
867
+ const functionsDefinitionsGroup : Record < string , DocNode [ ] > = { } ;
868
+ const finalFunctionsDefinitions : DocNode [ ] = [ ] ;
863
869
const variablesDefinitions : DocNode [ ] = [ ] ;
864
870
const typeAliasDefinitions : DocNode [ ] = [ ] ;
865
871
const enumsDefinitions : DocNode [ ] = [ ] ;
@@ -899,10 +905,24 @@ page_type: reference
899
905
break ;
900
906
901
907
case ApiItemKind . Function :
902
- functionsTable . addRow ( row ) ;
903
- functionsDefinitions . push (
904
- ...this . _createCompleteOutputForApiItem ( apiMember )
905
- ) ;
908
+ if ( this . _shouldSortFunctions ) {
909
+ const firstParam = ( apiMember as ApiParameterListMixin ) . parameters [ 0 ] || { name : '' } ;
910
+ if ( ! functionsRowGroup [ firstParam . name ] ) {
911
+ functionsRowGroup [ firstParam . name ] = [ ] ;
912
+ }
913
+ if ( ! functionsDefinitionsGroup [ firstParam . name ] ) {
914
+ functionsDefinitionsGroup [ firstParam . name ] = [ ] ;
915
+ }
916
+ functionsRowGroup [ firstParam . name ] . push ( row ) ;
917
+ functionsDefinitionsGroup [ firstParam . name ] . push (
918
+ ...this . _createCompleteOutputForApiItem ( apiMember )
919
+ ) ;
920
+ } else {
921
+ finalFunctionsTable . addRow ( row ) ;
922
+ finalFunctionsDefinitions . push (
923
+ ...this . _createCompleteOutputForApiItem ( apiMember )
924
+ ) ;
925
+ }
906
926
break ;
907
927
908
928
case ApiItemKind . TypeAlias :
@@ -921,9 +941,30 @@ page_type: reference
921
941
}
922
942
}
923
943
924
- if ( functionsTable . rows . length > 0 ) {
944
+ if ( this . _shouldSortFunctions ) {
945
+ const sortedFunctionsFirstParamKeys = Object . keys ( functionsRowGroup ) . sort ( ( a , b ) => {
946
+ if ( a === 'app' ) {
947
+ return - 1 ;
948
+ }
949
+ return ( a . localeCompare ( b ) ) ;
950
+ } ) ;
951
+
952
+ for ( const paramKey of sortedFunctionsFirstParamKeys ) {
953
+ if ( finalFunctionsTable . rows . length > 0 ) {
954
+ finalFunctionsTable . createAndAddRow ( ) ;
955
+ }
956
+ for ( const functionsRow of functionsRowGroup [ paramKey ] ) {
957
+ finalFunctionsTable . addRow ( functionsRow ) ;
958
+ }
959
+ for ( const functionDefinition of functionsDefinitionsGroup [ paramKey ] ) {
960
+ finalFunctionsDefinitions . push ( functionDefinition ) ;
961
+ }
962
+ }
963
+ }
964
+
965
+ if ( finalFunctionsTable . rows . length > 0 ) {
925
966
output . push ( new DocHeading ( { configuration, title : 'Functions' } ) ) ;
926
- output . push ( functionsTable ) ;
967
+ output . push ( finalFunctionsTable ) ;
927
968
}
928
969
929
970
if ( classesTable . rows . length > 0 ) {
@@ -956,8 +997,8 @@ page_type: reference
956
997
output . push ( typeAliasesTable ) ;
957
998
}
958
999
959
- if ( functionsDefinitions . length > 0 ) {
960
- output . push ( ...functionsDefinitions ) ;
1000
+ if ( finalFunctionsDefinitions . length > 0 ) {
1001
+ output . push ( ...finalFunctionsDefinitions ) ;
961
1002
}
962
1003
963
1004
if ( variablesDefinitions . length > 0 ) {
0 commit comments