@@ -93,6 +93,7 @@ export interface IMarkdownDocumenterOptions {
9393 outputFolder : string ;
9494 addFileNameSuffix : boolean ;
9595 projectName : string ;
96+ shouldSortFunctions : boolean ;
9697}
9798
9899/**
@@ -108,13 +109,15 @@ export class MarkdownDocumenter {
108109 private readonly _pluginLoader : PluginLoader ;
109110 private readonly _addFileNameSuffix : boolean ;
110111 private readonly _projectName : string ;
112+ private readonly _shouldSortFunctions : boolean ;
111113
112114 public constructor ( options : IMarkdownDocumenterOptions ) {
113115 this . _apiModel = options . apiModel ;
114116 this . _documenterConfig = options . documenterConfig ;
115117 this . _outputFolder = options . outputFolder ;
116118 this . _addFileNameSuffix = options . addFileNameSuffix ;
117119 this . _projectName = options . projectName ;
120+ this . _shouldSortFunctions = options . shouldSortFunctions ;
118121 this . _tsdocConfiguration = CustomDocNodes . configuration ;
119122 this . _markdownEmitter = new CustomMarkdownEmitter ( this . _apiModel ) ;
120123
@@ -834,11 +837,13 @@ page_type: reference
834837 headerTitles : [ 'Enumeration' , 'Description' ]
835838 } ) ;
836839
837- const functionsTable : DocTable = new DocTable ( {
840+ const finalFunctionsTable : DocTable = new DocTable ( {
838841 configuration,
839842 headerTitles : [ 'Function' , 'Description' ]
840843 } ) ;
841844
845+ const functionsRowGroup : Record < string , DocTableRow [ ] > = { } ;
846+
842847 const interfacesTable : DocTable = new DocTable ( {
843848 configuration,
844849 headerTitles : [ 'Interface' , 'Description' ]
@@ -859,7 +864,8 @@ page_type: reference
859864 headerTitles : [ 'Type Alias' , 'Description' ]
860865 } ) ;
861866
862- const functionsDefinitions : DocNode [ ] = [ ] ;
867+ const functionsDefinitionsGroup : Record < string , DocNode [ ] > = { } ;
868+ const finalFunctionsDefinitions : DocNode [ ] = [ ] ;
863869 const variablesDefinitions : DocNode [ ] = [ ] ;
864870 const typeAliasDefinitions : DocNode [ ] = [ ] ;
865871 const enumsDefinitions : DocNode [ ] = [ ] ;
@@ -899,10 +905,24 @@ page_type: reference
899905 break ;
900906
901907 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+ }
906926 break ;
907927
908928 case ApiItemKind . TypeAlias :
@@ -921,9 +941,30 @@ page_type: reference
921941 }
922942 }
923943
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 ) {
925966 output . push ( new DocHeading ( { configuration, title : 'Functions' } ) ) ;
926- output . push ( functionsTable ) ;
967+ output . push ( finalFunctionsTable ) ;
927968 }
928969
929970 if ( classesTable . rows . length > 0 ) {
@@ -956,8 +997,8 @@ page_type: reference
956997 output . push ( typeAliasesTable ) ;
957998 }
958999
959- if ( functionsDefinitions . length > 0 ) {
960- output . push ( ...functionsDefinitions ) ;
1000+ if ( finalFunctionsDefinitions . length > 0 ) {
1001+ output . push ( ...finalFunctionsDefinitions ) ;
9611002 }
9621003
9631004 if ( variablesDefinitions . length > 0 ) {
0 commit comments