@@ -45,6 +45,15 @@ type CacheEntry = {
4545
4646const docsCache = new Map < string , CacheEntry > ( ) ;
4747
48+ /**
49+ * Fetch a documentation page for a specific query
50+ *
51+ * @param _package - The package name
52+ * @param version - The package version
53+ * @param itemName - The item name
54+ * @param itemKind - The type of the item as per the docs API
55+ * @returns The documentation item
56+ */
4857export async function fetchDocItem (
4958 _package : string ,
5059 version : string ,
@@ -74,6 +83,13 @@ export async function fetchDocItem(
7483 }
7584}
7685
86+ /**
87+ * Resolve item kind to the respective Discord app emoji
88+ *
89+ * @param itemKind - The type of item as per the docs API
90+ * @param dev - Whether the item is from the dev branch (main)
91+ * @returns
92+ */
7793function itemKindEmoji ( itemKind : string , dev = false ) : [ string , string ] {
7894 const lowerItemKind = itemKind . toLowerCase ( ) ;
7995 switch ( itemKind ) {
@@ -107,13 +123,30 @@ function itemKindEmoji(itemKind: string, dev = false): [string, string] {
107123 }
108124}
109125
126+ /**
127+ * Build a discord.js documentation link
128+ *
129+ * @param item - The item to generate the link for
130+ * @param _package - The package name
131+ * @param version - The package version
132+ * @param attribute - The attribute to link to, if any
133+ * @returns The formatted link
134+ */
110135function docsLink ( item : any , _package : string , version : string , attribute ?: string ) {
111136 return `${ DJS_DOCS_BASE } /packages/${ _package } /${ version } /${ item . displayName } :${ item . kind } ${
112137 attribute ? `#${ attribute } ` : ''
113138 } `;
114139}
115140
116- function preparePotential ( potential : any , member : any , topLevelDisplayName : string ) : any | null {
141+ /**
142+ * Enriches item members of type "method" with a dynamically generated displayName property
143+ *
144+ * @param potential - The item to check and enrich
145+ * @param member - The member to access
146+ * @param topLevelDisplayName - The display name of the top level parent
147+ * @returns The enriched item
148+ */
149+ function enrichItem ( potential : any , member : any , topLevelDisplayName : string ) : any | null {
117150 const isMethod = potential . kind === 'Method' ;
118151 if ( potential . displayName ?. toLowerCase ( ) === member . toLowerCase ( ) ) {
119152 return {
@@ -125,6 +158,13 @@ function preparePotential(potential: any, member: any, topLevelDisplayName: stri
125158 return null ;
126159}
127160
161+ /**
162+ * Resolve an items specific member, if required.
163+ *
164+ * @param item - The base item to check
165+ * @param member - The name of the member to access
166+ * @returns The relevant item
167+ */
128168function effectiveItem ( item : any , member ?: string ) {
129169 if ( ! member ) {
130170 return item ;
@@ -133,15 +173,15 @@ function effectiveItem(item: any, member?: string) {
133173 const iterable = Array . isArray ( item . members ) ;
134174 if ( Array . isArray ( item . members ) ) {
135175 for ( const potential of item . members ) {
136- const hit = preparePotential ( potential , member , item . displayName ) ;
176+ const hit = enrichItem ( potential , member , item . displayName ) ;
137177 if ( hit ) {
138178 return hit ;
139179 }
140180 }
141181 } else {
142182 for ( const category of Object . values ( item . members ) ) {
143183 for ( const potential of category as any ) {
144- const hit = preparePotential ( potential , member , item . displayName ) ;
184+ const hit = enrichItem ( potential , member , item . displayName ) ;
145185 if ( hit ) {
146186 return hit ;
147187 }
@@ -152,6 +192,14 @@ function effectiveItem(item: any, member?: string) {
152192 return item ;
153193}
154194
195+ /**
196+ * Format documentation blocks to a summary string
197+ *
198+ * @param blocks - The documentation blocks to format
199+ * @param _package - The package name of the package the blocks belong to
200+ * @param version - The version of the package the blocks belong to
201+ * @returns The formatted summary string
202+ */
155203function formatSummary ( blocks : any [ ] , _package : string , version : string ) {
156204 return blocks
157205 . map ( ( block ) => {
@@ -166,6 +214,12 @@ function formatSummary(blocks: any[], _package: string, version: string) {
166214 . join ( '' ) ;
167215}
168216
217+ /**
218+ * Format documentation blocks to a code example string
219+ *
220+ * @param blocks - The documentation blocks to format
221+ * @returns The formatted code example string
222+ */
169223function formatExample ( blocks ?: any [ ] ) {
170224 const comments : string [ ] = [ ] ;
171225
@@ -185,6 +239,15 @@ function formatExample(blocks?: any[]) {
185239 }
186240}
187241
242+ /**
243+ * Format a documentation item to a string
244+ *
245+ * @param _item - The docs item to format
246+ * @param _package - The package name of the packge the item belongs to
247+ * @param version - The version of the package the item belongs to
248+ * @param member - The specific item member to access, if any
249+ * @returns The formatted documentation string for the provided item
250+ */
188251function formatItem ( _item : any , _package : string , version : string , member ?: string ) {
189252 const itemLink = docsLink ( _item , _package , version , member ) ;
190253 const item = effectiveItem ( _item , member ) ;
0 commit comments