Skip to content

Commit

Permalink
tools: use Set instead of { [key]: true } object
Browse files Browse the repository at this point in the history
Refs: #41675

PR-URL: #41695
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen authored Jan 28, 2022
1 parent f98a785 commit 334fb38
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tools/doc/alljson.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ const results = {

// Identify files that should be skipped. As files are processed, they
// are added to this list to prevent dupes.
const seen = {
'all.json': true,
'index.json': true
};
const seen = new Set(['all.json', 'index.json']);

// Extract (and concatenate) the selected data from each document.
// Expand hrefs found in json to include source HTML file.
for (const link of toc.match(/<a.*?>/g)) {
const href = /href="(.*?)"/.exec(link)[1];
const json = href.replace('.html', '.json');
if (!jsonFiles.includes(json) || seen[json]) continue;
if (!jsonFiles.includes(json) || seen.has(json)) continue;
const data = JSON.parse(
fs.readFileSync(new URL(`./${json}`, source), 'utf8')
.replace(/<a href=\\"#/g, `<a href=\\"${href}#`)
Expand All @@ -49,7 +46,7 @@ for (const link of toc.match(/<a.*?>/g)) {
}

// Mark source as seen.
seen[json] = true;
seen.add(json);
}

// Write results.
Expand Down

0 comments on commit 334fb38

Please sign in to comment.