Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Catalan Language #672

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Colin Rudd (https://github.com/cnrudd)
Damien Cassou <damien@cassou.me> (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)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Next

- Added ca (Catalan) localization.

### 2.3.6

- Fix spacing issue with en-GB currency. Thanks @DamienCassou
Expand Down
61 changes: 61 additions & 0 deletions languages/ca.js
Original file line number Diff line number Diff line change
@@ -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
}
}
};
91 changes: 91 additions & 0 deletions tests/languages/ca-tests.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
});
});