From c3d6387cf75c2a2e95790c06bfea07c2f41b1c9c Mon Sep 17 00:00:00 2001 From: Kuba Suder Date: Mon, 20 May 2024 16:16:45 +0200 Subject: [PATCH] make sure numbers are numbers --- models.js | 8 ++++---- utils.js | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/models.js b/models.js index f4bb9c4..871eb03 100644 --- a/models.js +++ b/models.js @@ -250,12 +250,12 @@ class Post extends ATProtoRecord { /** @returns {number} */ get likeCount() { - return this.data.likeCount; + return castToInt(this.data.likeCount); } /** @returns {number} */ get replyCount() { - return this.data.replyCount; + return castToInt(this.data.replyCount); } /** @returns {boolean} */ @@ -265,7 +265,7 @@ class Post extends ATProtoRecord { /** @returns {number} */ get repostCount() { - return this.data.repostCount; + return castToInt(this.data.repostCount); } /** @returns {boolean} */ @@ -356,7 +356,7 @@ class FeedGeneratorRecord extends ATProtoRecord { /** @returns {number} */ get likeCount() { - return this.data.likeCount; + return castToInt(this.data.likeCount); } /** @returns {string | undefined} */ diff --git a/utils.js b/utils.js index 277327a..b486dce 100644 --- a/utils.js +++ b/utils.js @@ -60,6 +60,14 @@ function atURI(uri) { return new AtURI(uri); } +function castToInt(value) { + if (value === undefined || value === null || typeof value == "number") { + return value; + } else { + return parseInt(value, 10); + } +} + /** @param {string} html, @returns {string} */ function escapeHTML(html) { -- 2.51.2