From e766a422355477e0d6580f8e803e014569ba55da Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 29 May 2023 16:48:01 +0100 Subject: [PATCH 1/4] Fix bug where the randomiser would pick -1 This was caused by the randomiser using the wrong brackets. We needed the maximum index of the length - 1, but the randomiser would take the 1 AFTER randomising, adding brackets made it do this BEFORE. --- .gitignore | 7 ++++--- src/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 65e3fd0..4915027 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -node_modules -dist -yarn-error.log \ No newline at end of file +node_modules/ +dist/ +coverage/ +yarn-error.log diff --git a/src/index.ts b/src/index.ts index bdd157d..400567e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,8 +41,8 @@ export default async function randomBunny(subreddit: string, sortBy?: string): P return { IsSuccess: false, }; - } else if (dataWithImages.length > 1) { - random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1) + } else { + random = Math.floor((Math.random() * (dataWithImages.length - 1)) + 0); // Between 0 and (size - 1) } const randomSelect = dataWithImages[random]; From d3d921b3c89e2e327dc0334edcf82d972db8ea5e Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 29 May 2023 16:52:13 +0100 Subject: [PATCH 2/4] v2.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2271ec1..1457448 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "random-bunny", - "version": "2.1.1", + "version": "2.1.2", "description": "Get a random subreddit image url", "license": "MIT", "author": "Vylpes", From 8e268a0cc3c9902edd7017efd5cad5449b3dd800 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 3 Jul 2023 17:54:05 +0100 Subject: [PATCH 3/4] Upgrade semver to 7.5.2 --- package.json | 3 ++- yarn.lock | 18 ++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 1457448..5b52a62 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,8 @@ "typescript": "^5.0.0" }, "resolutions": { - "np/**/got": "^11.8.5" + "np/**/got": "^11.8.5", + "**/semver": "^7.5.2" }, "files": [ "dist" diff --git a/yarn.lock b/yarn.lock index c007dfe..c94e10d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3841,23 +3841,13 @@ semver-diff@^3.1.1: dependencies: semver "^6.3.0" -"semver@2 || 3 || 4 || 5": - version "5.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== - -semver@7.x, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7: - version "7.5.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.1.tgz#c90c4d631cf74720e46b21c1d37ea07edfab91ec" - integrity sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw== +"semver@2 || 3 || 4 || 5", semver@7.x, semver@^6.0.0, semver@^6.2.0, semver@^6.3.0, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.5.2: + version "7.5.3" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e" + integrity sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ== dependencies: lru-cache "^6.0.0" -semver@^6.0.0, semver@^6.2.0, semver@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" - integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== - shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" From f67e001cf01b063166c28d54a54174c2e94235b0 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 3 Jul 2023 17:55:46 +0100 Subject: [PATCH 4/4] v2.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b52a62..cd7a8d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "random-bunny", - "version": "2.1.2", + "version": "2.1.3", "description": "Get a random subreddit image url", "license": "MIT", "author": "Vylpes",