From 8166b9a0514287e43f54eda596b3e89c03cefd01 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Mon, 5 Dec 2022 14:17:53 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20compiler=20=E2=80=9CType=20'number'=20is?= =?UTF-8?q?=20not=20assignable=20to=20type=20'string'=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/govuk/common/normalise-dataset.mjs | 2 +- src/govuk/i18n.mjs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/govuk/common/normalise-dataset.mjs b/src/govuk/common/normalise-dataset.mjs index 2b2f491fb8..338ee633ff 100644 --- a/src/govuk/common/normalise-dataset.mjs +++ b/src/govuk/common/normalise-dataset.mjs @@ -34,7 +34,7 @@ export function normaliseString (value) { // Empty / whitespace-only strings are considered finite so we need to check // the length of the trimmed string as well - if (trimmedValue.length > 0 && isFinite(trimmedValue)) { + if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) { return Number(trimmedValue) } diff --git a/src/govuk/i18n.mjs b/src/govuk/i18n.mjs index eb88e1c326..40050c1faa 100644 --- a/src/govuk/i18n.mjs +++ b/src/govuk/i18n.mjs @@ -33,9 +33,9 @@ I18n.prototype.t = function (lookupKey, options) { } // If the `count` option is set, determine which plural suffix is needed and - // change the lookupKey to match. We check to see if it's undefined instead of + // change the lookupKey to match. We check to see if it's numeric instead of // falsy, as this could legitimately be 0. - if (options && typeof options.count !== 'undefined') { + if (options && typeof options.count === 'number') { // Get the plural suffix lookupKey = lookupKey + '.' + this.getPluralSuffix(lookupKey, options.count) } @@ -87,8 +87,8 @@ I18n.prototype.replacePlaceholders = function (translationString, options) { } // If the placeholder's value is a number, localise the number formatting - if (typeof placeholderValue === 'number' && formatter) { - return formatter.format(placeholderValue) + if (typeof placeholderValue === 'number') { + return formatter ? formatter.format(placeholderValue) : placeholderValue.toString() } return placeholderValue