@@ -10,6 +10,12 @@ let shortIndex = null;
1010const pagesPath = path . join ( config . get ( ) . cache , 'cache' ) ;
1111const shortIndexFile = path . join ( pagesPath , 'shortIndex.json' ) ;
1212
13+ /**
14+ * @param {string } page
15+ * @param {string|undefined } preferredPlatform
16+ * @param {string } preferredLanguage
17+ * @returns {Promise<?string> }
18+ */
1319function findPage ( page , preferredPlatform , preferredLanguage ) {
1420 // Load the index
1521 return getShortIndex ( )
@@ -33,7 +39,7 @@ function findPage(page, preferredPlatform, preferredLanguage) {
3339 ll = preferredLanguage . substring ( 0 , preferredLanguage . indexOf ( '_' ) ) ;
3440 }
3541 if ( ! hasLang ( targets , preferredLanguage ) ) {
36- preferredLanguage = ll ;
42+ preferredLanguage = /** @type { string } */ ( ll ) ;
3743 }
3844
3945 // Page resolution logic:
@@ -91,25 +97,38 @@ function hasLang(targets, preferredLanguage) {
9197 } ) ;
9298}
9399
94- // hasPage is always called after the index is created,
95- // hence just return the variable in memory.
96- // There is no need to re-read the index file again.
100+ /**
101+ * Check if a page is in the index.
102+ *
103+ * @returns {boolean } The presence of the page in the index.
104+ */
97105function hasPage ( page ) {
106+ // hasPage is always called after the index is created,
107+ // hence just return the variable in memory.
108+ // There is no need to re-read the index file again.
98109 if ( ! shortIndex ) {
99110 return false ;
100111 }
101112 return page in shortIndex ;
102113}
103114
104- // Return all commands available in the local cache.
115+ /**
116+ * Return all commands available in the local index.
117+ * @returns {Promise<string[]> } A promise with the commands from the index.
118+ */
105119function commands ( ) {
106120 return getShortIndex ( ) . then ( ( idx ) => {
107121 return Object . keys ( idx ) . sort ( ) ;
108122 } ) ;
109123}
110124
111- // Return all commands for a given platform.
112- // P.S. - The platform 'common' is always included.
125+ /**
126+ * Return all commands for a given platform. The 'common' platform is always
127+ * included.
128+ *
129+ * @param {string } platform The desired platform.
130+ * @returns {Promise<string[]> } The commands for a given platform.
131+ */
113132function commandsFor ( platform ) {
114133 return getShortIndex ( )
115134 . then ( ( idx ) => {
@@ -124,7 +143,11 @@ function commandsFor(platform) {
124143 } ) ;
125144}
126145
127- // Delete the index file.
146+ /**
147+ * Delete the index file.
148+ *
149+ * @returns {Promise<any> } A promise when the remove is completed.
150+ */
128151function clearPagesIndex ( ) {
129152 return fs . unlink ( shortIndexFile )
130153 . then ( ( ) => {
@@ -139,7 +162,9 @@ function clearPagesIndex() {
139162 } ) ;
140163}
141164
142- // Set the shortIndex variable to null.
165+ /**
166+ * Set the shortIndex variable to null.
167+ */
143168function clearRuntimeIndex ( ) {
144169 shortIndex = null ;
145170}
@@ -150,18 +175,26 @@ function rebuildPagesIndex() {
150175 } ) ;
151176}
152177
153- // If the variable is not set, read the file and set it.
154- // Else, just return the variable.
178+ /**
179+ * Return the index, that contains all available commands with their target os
180+ * and platform. If the index is not loaded, read the file and load it.
181+ *
182+ * @returns {Promise<any> } The index entries.
183+ */
155184function getShortIndex ( ) {
156185 if ( shortIndex ) {
157186 return Promise . resolve ( shortIndex ) ;
158187 }
159188 return readShortPagesIndex ( ) ;
160189}
161190
162- // Read the index file, and load it into memory.
163- // If the file does not exist, create the data structure, write the file,
164- // and load it into memory.
191+ /**
192+ * Read the index file, and load it into memory.
193+ *
194+ * If the file does not exist, create the data structure, write the file,
195+ * and load it into memory.
196+ * @returns {Promise<any> } The index entries.
197+ */
165198function readShortPagesIndex ( ) {
166199 return fs . readJson ( shortIndexFile )
167200 . then ( ( idx ) => {
0 commit comments