From 42cf7ba395e80d9769fcefddd9bc777ce1cbae6f Mon Sep 17 00:00:00 2001 From: Mohammed Date: Thu, 23 May 2024 19:24:11 +0300 Subject: [PATCH] add private language option: _hideCountIf2 --- humanize-duration.js | 57 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/humanize-duration.js b/humanize-duration.js index 1415c7a..771fef0 100644 --- a/humanize-duration.js +++ b/humanize-duration.js @@ -41,6 +41,7 @@ * @prop {string} [delimiter] * @prop {DigitReplacements} [_digitReplacements] * @prop {boolean} [_numberFirst] + * @prop {boolean} [_hideCountIf2] */ /** @@ -186,8 +187,8 @@ ), { delimiter: " ﻭ ", - hideUnitInDualForm: true, - _digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"], + _hideCountIf2: true, + _digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"] } ), bg: language( @@ -1656,21 +1657,10 @@ /** @type {undefined | DigitReplacements} */ var digitReplacements; if ("digitReplacements" in options) { - digitReplacements = options.digitReplacements; + digitReplacements = options.digitReplacements; } else if ("_digitReplacements" in language) { - digitReplacements = language._digitReplacements; + digitReplacements = language._digitReplacements; } - - /** @type {boolean} */ - var hideUnitInDualForm = false; - if (options.language === "ar") { - if ("arabic_hideUnitInDualForm" in options) { - hideUnitInDualForm = options.arabic_hideUnitInDualForm; - } else if ("hideUnitInDualForm" in language) { - hideUnitInDualForm = language.hideUnitInDualForm; - } - } - /** @type {string} */ var formattedCount; @@ -1680,24 +1670,25 @@ : Math.floor(unitCount * Math.pow(10, maxDecimalPoints)) / Math.pow(10, maxDecimalPoints); var countStr = normalizedUnitCount.toString(); - if (!hideUnitInDualForm || unitCount !== 2) { - if (digitReplacements) { - formattedCount = ""; - for (var i = 0; i < countStr.length; i++) { - var char = countStr[i]; - if (char === ".") { - formattedCount += decimal; - } else { - // @ts-ignore because `char` should always be 0-9 at this point. - formattedCount += digitReplacements[char]; - } - } - } else { - formattedCount = countStr.replace(".", decimal); - } - } else { - formattedCount = ""; - } + + if (!language._hideCountIf2 || unitCount !== 2) { + if (digitReplacements) { + formattedCount = ""; + for (var i = 0; i < countStr.length; i++) { + var char = countStr[i]; + if (char === ".") { + formattedCount += decimal; + } else { + // @ts-ignore because `char` should always be 0-9 at this point. + formattedCount += digitReplacements[char]; + } + } + } else { + formattedCount = countStr.replace(".", decimal); + } + } else { + formattedCount = ""; + } var languageWord = language[unitName]; var word;