diff --git a/humanize-duration.js b/humanize-duration.js index 90cf42d..4681646 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,6 +187,7 @@ ), { delimiter: " ﻭ ", + _hideCountIf2: true, _digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"] } ), @@ -1668,19 +1670,25 @@ : Math.floor(unitCount * Math.pow(10, maxDecimalPoints)) / Math.pow(10, maxDecimalPoints); var countStr = normalizedUnitCount.toString(); - if (digitReplacements) { + + if (language._hideCountIf2 && unitCount === 2) { 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]; + spacer = ""; + } else { + 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 = countStr.replace(".", decimal); } var languageWord = language[unitName]; diff --git a/test/definitions/ar.tsv b/test/definitions/ar.tsv index 4d8d21c..46e0c34 100644 --- a/test/definitions/ar.tsv +++ b/test/definitions/ar.tsv @@ -1,20 +1,20 @@ -0 ۰ جزء من الثانية -1 ١ جزء من الثانية -1.2 ١,٢ جزء من الثانية -2 ٢ جزآن من الثانية -1000 ١ ثانية -2000 ٢ ثانيتان -60000 ١ دقيقة -120000 ٢ دقيقتان -1200000 ٢۰ دقيقة -300000 ٥ دقائق -3600000 ١ ساعة -7200000 ٢ ساعتين -86400000 ١ يوم -172800000 ٢ يومين -604800000 ١ أسبوع -1209600000 ٢ أسبوعين -2629800000 ١ شهر -5259600000 ٢ شهران -31557600000 ١ سنة -63115200000 ٢ سنتان +0 ۰ جزء من الثانية +1 ١ جزء من الثانية +1.2 ١,٢ جزء من الثانية +2 جزآن من الثانية +1000 ١ ثانية +2000 ثانيتان +60000 ١ دقيقة +120000 دقيقتان +1200000 ٢۰ دقيقة +300000 ٥ دقائق +3600000 ١ ساعة +7200000 ساعتين +86400000 ١ يوم +172800000 يومين +604800000 ١ أسبوع +1209600000 أسبوعين +2629800000 ١ شهر +5259600000 شهران +31557600000 ١ سنة +63115200000 سنتان