From 73147544ec1579d8f1775ecd9c8d1dad65878004 Mon Sep 17 00:00:00 2001 From: Ken Eucker Date: Fri, 15 Dec 2023 10:11:21 -0800 Subject: [PATCH] fix(client): small fixes to various parts of the client --- examples/node/index.js | 2 +- readme.md | 1 + src/common/getters.ts | 3 +++ src/common/methods.ts | 2 +- src/imgur/helpers.ts | 6 +++++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/node/index.js b/examples/node/index.js index 585cd90..18cca52 100644 --- a/examples/node/index.js +++ b/examples/node/index.js @@ -171,7 +171,7 @@ const runTests = async (out = false) => { // await queueTagAsync("Imgur", bikeTagImgurInstance, out) // await getQueueAsync("Imgur", bikeTagImgurInstance, out) // await getCurrentTagAsync("Imgur", bikeTagImgurInstance, out) - await get10TagsAsync("Imgur", bikeTagImgurInstance, out) + // await get10TagsAsync("Imgur", bikeTagImgurInstance, out) // await get10PlayersAsync("Imgur", bikeTagImgurInstance, out) } diff --git a/readme.md b/readme.md index 2d0f9c2..3e92432 100644 --- a/readme.md +++ b/readme.md @@ -160,6 +160,7 @@ Support the BikeTag Project on [GitHub][github], [Patreon][patreon], or directly [sanity]: https://www.sanity.io/docs/api-versioning [imgur]: https://www.npmjs.com/package/imgur/v/next +![Alt](https://repobeats.axiom.co/api/embed/efea76b8d7f37062fcded362417a369dc9a3a401.svg "Repobeats analytics image")
diff --git a/src/common/getters.ts b/src/common/getters.ts index 989af06..f7d8b47 100644 --- a/src/common/getters.ts +++ b/src/common/getters.ts @@ -58,6 +58,8 @@ export const getTagNumbersFromText = ( if (!tagNumberText) return fallback || [] const tagNumbers = tagNumberText.reduce((numbers, text) => { + if (!text) return numbers + const tagNumberMatches = text.match(/\d+/) const tagNumber = tagNumberMatches && tagNumberMatches.length ? tagNumberMatches[0] : null @@ -217,6 +219,7 @@ export const getGPSLocationFromText = ( ): geopoint => { const gpsString = getGpsStringLocationFromText(inputText, '', cache) + /// Encode/decode the GPS string here if (gpsString.length) { const gpsPair = gpsString.split(',') const gpsLocation = { diff --git a/src/common/methods.ts b/src/common/methods.ts index 16202ce..35b6c41 100644 --- a/src/common/methods.ts +++ b/src/common/methods.ts @@ -474,7 +474,7 @@ export const getGameAlbumFromCache = async ( gameAlbumHash: string, cache?: typeof TinyCache, fallback?: any -) => { +): Promise => { const cacheKey = `imgur::${cacheKeys.albumHash}${gameAlbumHash}` const existsInCache = getCacheIfExists(cacheKey, cache) if (existsInCache) { diff --git a/src/imgur/helpers.ts b/src/imgur/helpers.ts index cb297fd..bbc31bf 100644 --- a/src/imgur/helpers.ts +++ b/src/imgur/helpers.ts @@ -56,6 +56,8 @@ export function getTagNumbersFromText( fallback: number[] | null = null, cache?: typeof TinyCache ): number[] { + if (!inputText?.length) return fallback + const cacheKey = `${cacheKeys.tagNumberText}${inputText}` const existingParsed = getCacheIfExists(cacheKey) if (existingParsed) return existingParsed @@ -64,8 +66,10 @@ export function getTagNumbersFromText( if (!tagNumberText) return fallback ?? [] const tagNumbers = tagNumberText.reduce((numbers, text) => { + if (!text) return numbers + let tagNumber: any = text.match(/\d+/) - tagNumber = tagNumber && tagNumber.length ? tagNumber[0] : null + tagNumber = tagNumber?.length ? tagNumber[0] : null if (!tagNumber) return numbers