Skip to content

Commit e629780

Browse files
waldyriousagnivade
authored andcommitted
index.js: various documentation fixes
1 parent 59df8f0 commit e629780

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

lib/index.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const shortIndexFile = path.join(pagesPath, 'shortIndex.json');
1313
function findPlatform(page, preferredPlatform, done) {
1414
// Load the index
1515
getShortIndex((idx) => {
16-
// First checking whether page is there or not
16+
// First, check whether page is in the index
1717
if (! (page in idx)) {
1818
return done(null);
1919
}
20-
// Getting the platforms
20+
// Get the platforms
2121
let platforms = idx[page];
2222
if (platforms.indexOf(preferredPlatform) >= 0) {
2323
return done(preferredPlatform);
@@ -28,29 +28,32 @@ function findPlatform(page, preferredPlatform, done) {
2828
});
2929
}
3030

31-
// hasPage is always called after index is created, hence just return the variable
32-
// in memory. There is no need to re-read the index file again.
31+
// hasPage is always called after the index is created,
32+
// hence just return the variable in memory.
33+
// There is no need to re-read the index file again.
3334
function hasPage(page) {
3435
if (!shortIndex) {
3536
return false;
3637
}
3738
return page in shortIndex;
3839
}
3940

40-
// This returns all commands available in the local cache
41+
// Return all commands available in the local cache.
4142
function commands(done) {
4243
getShortIndex((idx) => {
4344
return done(Object.keys(idx).sort());
4445
});
4546
}
4647

47-
// This returns all commands for a given platform.
48+
// Return all commands for a given platform.
4849
// P.S. - The platform 'common' is always included.
4950
function commandsFor(platform, done) {
5051
getShortIndex((idx) => {
5152
let commands = Object.keys(idx)
5253
.filter((cmd) => {
53-
/* eslint-disable */ // To allow using -1 to check if it contains in the array
54+
// ESLint is disabled for this statement, to allow using -1
55+
// to check if a command is contained in the array.
56+
/* eslint-disable */
5457
return idx[cmd].indexOf(platform) !== -1
5558
|| idx[cmd].indexOf('common') !== -1 ;
5659
/* eslint-enable */
@@ -60,15 +63,15 @@ function commandsFor(platform, done) {
6063
});
6164
}
6265

63-
// Delete the index file
66+
// Delete the index file.
6467
function clearPagesIndex(done) {
6568
fs.unlink(shortIndexFile, () => {
6669
clearRuntimeIndex();
6770
done();
6871
});
6972
}
7073

71-
// Set the variable to null
74+
// Set the shortIndex variable to null.
7275
function clearRuntimeIndex() {
7376
shortIndex = null;
7477
}
@@ -82,21 +85,21 @@ function rebuildPagesIndex(done) {
8285
}
8386

8487
// If the variable is not set, read the file and set it.
85-
// Else, just return the variable
88+
// Else, just return the variable.
8689
function getShortIndex(done) {
8790
if (!shortIndex) {
8891
return readShortPagesIndex(done);
8992
}
9093
return done(shortIndex);
9194
}
9295

93-
// Reads the index file, and loads it into memory.
94-
// If the file is not created, create the data structure, write the file, and load
95-
// it into memory
96+
// Read the index file, and load it into memory.
97+
// If the file does not exist, create the data structure, write the file,
98+
// and load it into memory.
9699
function readShortPagesIndex(done) {
97100
fs.readFile(shortIndexFile, 'utf8', (err, idx) => {
98-
// file is not present, need to create the index
99101
if (err) {
102+
// File is not present; we need to create the index.
100103
idx = buildShortPagesIndex();
101104
if (Object.keys(idx).length > 0) {
102105
fs.writeFile(shortIndexFile, JSON.stringify(idx), (err) => {
@@ -109,7 +112,9 @@ function readShortPagesIndex(done) {
109112
} else {
110113
return done(idx);
111114
}
112-
} else { // Just parse and set shortIndex variable, then return the value
115+
} else {
116+
// File is present, so just parse and set the shortIndex variable,
117+
// then return the value.
113118
idx = JSON.parse(idx);
114119
shortIndex = idx;
115120
return done(idx);

0 commit comments

Comments
 (0)