From b5955ff783d403e307a076caa2112199ca6570a0 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Thu, 9 Apr 2020 13:42:28 +0200 Subject: [PATCH] fix duplicate emits --- bin/ops.js | 3 ++- index.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/ops.js b/bin/ops.js index e89bee5..0ca224d 100644 --- a/bin/ops.js +++ b/bin/ops.js @@ -10,7 +10,8 @@ const main = async () => { name: 'name', message: 'Name of the module to search', default: 'express' - }, { + }, + { type: 'input', name: 'limit', message: 'How many modules to display at most', diff --git a/index.js b/index.js index 58198d6..2f942c9 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const cheerio = require('cheerio') module.exports = name => { const dependants = [] + const visited = new Set() let offset = 0 const next = async () => { @@ -14,8 +15,9 @@ module.exports = name => { const dependant = $(el) .attr('href') .slice('/package/'.length) - if (dependant !== name && !dependants.includes(dependant)) { + if (dependant !== name && !visited.has(dependant)) { dependants.push(dependant) + visited.add(dependant) } }) offset += 36