Skip to content

Commit 95d5da6

Browse files
authored
Remove the @messageformat/core library (#699)
1 parent e18ba6f commit 95d5da6

File tree

8 files changed

+310
-180
lines changed

8 files changed

+310
-180
lines changed

package-lock.json

-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
},
3232
"homepage": "https://github.com/jenkinsci/pipeline-graph-view-plugin/#readme",
3333
"dependencies": {
34-
"@messageformat/core": "^3.4.0",
3534
"@tippyjs/react": "^4.2.6",
3635
"react": "^19.1.0",
3736
"react-dom": "^19.1.0",

src/main/frontend/common/i18n/choice-formatter.spec.ts

-28
This file was deleted.

src/main/frontend/common/i18n/choice-formatter.ts

-69
This file was deleted.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./i18n-provider.tsx";
2+
export type { MessageContext } from "./message-format.ts";
3+
export type { ResourceBundle } from "./messages.ts";
4+
export { Messages, ResourceBundleName } from "./messages.ts";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { MessageFormat } from "./message-format.ts";
2+
3+
describe("Message Format", () => {
4+
it("should render for no variable substitution", () => {
5+
const formatted = MessageFormat("Hello world!", "en").format();
6+
7+
expect(formatted).toEqual("Hello world!");
8+
});
9+
10+
describe("Variable chunk", () => {
11+
it("should render basic variable substitution", () => {
12+
const formatted = MessageFormat("Hello {somewhere}!", "en").format({
13+
somewhere: "world",
14+
});
15+
16+
expect(formatted).toEqual("Hello world!");
17+
});
18+
19+
it("should render multiple variable substitution", () => {
20+
const formatted = MessageFormat("{0} {1}{2}", "en").format({
21+
0: "Hello",
22+
1: "world",
23+
2: "!",
24+
});
25+
26+
expect(formatted).toEqual("Hello world!");
27+
});
28+
29+
it("should apply locale formatting to numbers", () => {
30+
const formatted = MessageFormat("{0}", "de-DE").format({
31+
0: 123123.123123,
32+
});
33+
34+
// java equivalent
35+
// new MessageFormat("{0}", Locale.GERMAN).format(new Object[]{123123.123123})
36+
expect(formatted).toEqual("123.123,123");
37+
});
38+
});
39+
40+
it("should render for a complex pattern", () => {
41+
const formatted = MessageFormat(
42+
"{0} {1,choice,0#world|1#team|1<moto}{2} {3}",
43+
"en",
44+
).format({ 0: "Hello", 1: 0, 2: "!", 3: "🚀" });
45+
46+
expect(formatted).toEqual("Hello world! 🚀");
47+
});
48+
49+
describe("Choice subformat", () => {
50+
const messageFormat = MessageFormat(
51+
"Hello {0,choice,0#world|1#team|1<moto}!",
52+
"en",
53+
);
54+
55+
it("should choose appropriate choice", () => {
56+
expect(messageFormat.format({ 0: 0 })).toEqual("Hello world!");
57+
expect(messageFormat.format({ 0: 1 })).toEqual("Hello team!");
58+
expect(messageFormat.format({ 0: 2 })).toEqual("Hello moto!");
59+
});
60+
61+
it("should use the first for no match found", () => {
62+
expect(messageFormat.format({ 0: -1 })).toEqual("Hello world!");
63+
});
64+
65+
it("should handle floating point numbers", () => {
66+
expect(messageFormat.format({ 0: 1.5 })).toEqual("Hello moto!");
67+
});
68+
69+
it("should handle invalid input", () => {
70+
expect(() => messageFormat.format({ 0: "ahhh" })).toThrow(
71+
"Argument 0 'ahhh' needs to be a number",
72+
);
73+
});
74+
75+
it("should handle empty arg", () => {
76+
expect(() => messageFormat.format({ 0: "" })).toThrow(
77+
"Argument 0 '' needs to be a number",
78+
);
79+
});
80+
});
81+
});

0 commit comments

Comments
 (0)