diff --git a/AUTHORS b/AUTHORS index 4e1c4877..9a64ea11 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,6 +20,7 @@ Colin Rudd (https://github.com/cnrudd) Damien Cassou (https://github.com/DamienCassou) Dan Ristic (https://github.com/dristic) Dave Clayton (https://github.com/davedx) +David Gölzhäuser (https://github.com/idoodler) Dieter Luypaert (https://github.com/moeriki) Diogo Resende (https://github.com/dresende) Dominik Bulaj (https://github.com/dominikbulaj) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f30fcaa..0150cc37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ### Next +- Added ca (Catalan) localization. + ### 2.3.6 - Fix spacing issue with en-GB currency. Thanks @DamienCassou diff --git a/languages/ca.js b/languages/ca.js new file mode 100644 index 00000000..b7b46640 --- /dev/null +++ b/languages/ca.js @@ -0,0 +1,61 @@ +/*! + * numbro.js language configuration + * language : Catalan + * author : David Gölzhäuser : https://github.com/idoodler + */ + +module.exports = { + languageTag: "ca", + delimiters: { + thousands: ".", + decimal: "," + }, + abbreviations: { + thousand: "k", + million: "mm", + billion: "b", + trillion: "t" + }, + ordinal: (number) => { + if (number >= 5) { + return "è"; + } + let b = number % 10; + return (b === 1 | b === 3) ? "r" : (b === 2) ? "n" : (b === 4) ? "t" : "è"; + }, + currency: { + symbol: "€", + position: "postfix", + code: "EUR" + }, + currencyFormat: { + thousandSeparated: true, + totalLength: 4, + spaceSeparated: true, + spaceSeparatedCurrency: true, + average: true + }, + formats: { + fourDigits: { + totalLength: 4, + spaceSeparated: true, + average: true + }, + fullWithTwoDecimals: { + output: "currency", + mantissa: 2, + spaceSeparated: true, + thousandSeparated: true + }, + fullWithTwoDecimalsNoCurrency: { + mantissa: 2, + thousandSeparated: true + }, + fullWithNoDecimals: { + output: "currency", + spaceSeparated: true, + thousandSeparated: true, + mantissa: 0 + } + } +}; diff --git a/tests/languages/ca-tests.js b/tests/languages/ca-tests.js new file mode 100644 index 00000000..66b2c163 --- /dev/null +++ b/tests/languages/ca-tests.js @@ -0,0 +1,91 @@ +const numbro = require("../../src/numbro"); +const ca = require("../../languages/ca"); + +describe("ca", () => { + beforeAll(() => { + numbro.registerLanguage(ca, true); + }); + + afterAll(() => { + numbro.setLanguage("en-US"); + }); + + it("formats correctly", () => { + let data = [ + [10000, "0,0.0000", "10.000,0000"], + [10000.23, "0,0", "10.000,23"], + [-10000, "0,0.0", "-10.000,0"], + [10000.1234, "0.000", "10000,123"], + [-10000, "(0,0.0000)", "(10.000,0000)"], + [-0.23, ".00", "-,23"], + [-0.23, "(.00)", "(,23)"], + [0.23, "0.00000", "0,23000"], + [1230974, "0.0a", "1,2mm"], + [1460, "0a", "1k"], + [-104000, "0a", "-104k"], + [1, "0o", "1r"], + [2, "0o", "2n"], + [3, "0o", "3r"], + [4, "0o", "4t"], + [5, "0o", "5è"], + [10, "0o", "10è"], + [12, "0o", "12è"], + [109, "0o", "109è"], + [153, "0o", "153è"], + [1, "0[.]0", "1"] + ]; + + data.forEach(([input, format, expectedResult]) => { + let result = numbro(input).format(format); + expect(result).toBe(expectedResult, `Should format correctly ${input} with ${format}`); + }); + }); + + it("formats currency correctly", () => { + let data = [ + [1000.234, "$", "1,000 k€"], + [1000.234, "$0,0.00", "1.000,23€"], + [-1000.234, "($0,0)", "(1.000,234)€"], + [-1000.234, "$0.00", "-1000,23€"], + [1230974, "($0.00a)", "1,23mm€"] + ]; + + data.forEach(([input, format, expectedResult]) => { + let result = numbro(input).format(format); + expect(result).toBe(expectedResult, `Should format currency correctly ${input} with ${format}`); + }); + }); + + it("formats percentage correctly", () => { + let data = [ + [1, "0%", "100%"], + [0.974878234, "0.000%", "97,488%"], + [-0.43, "0%", "-43%"], + [0.43, "(0.000%)", "43,000%"] + ]; + + data.forEach(([input, format, expectedResult]) => { + let result = numbro(input).format(format); + expect(result).toBe(expectedResult, `Should format percentage correctly ${input} with ${format}`); + }); + }); + + it("unformats correctly", () => { + let data = [ + ["10.000,123", 10000.123], + ["(0,12345)", -0.12345], + ["(1,23mm€)", -1230000], + ["10k", 10000], + ["-10k", -10000], + ["23è", 23], + ["10.000,00€", 10000], + ["-76%", -0.76], + ["2:23:57", 8637] + ]; + + data.forEach(([input, expectedResult]) => { + let result = numbro.unformat(input); + expect(result).toBe(expectedResult, `Should unformat correctly ${input}`); + }); + }); +});