@altinn/altinn-components 0.52.6 → 0.52.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,20 @@
1
- const l = ({ fullName: n, type: a, reverseNameOrder: i }) => {
2
- if (!n) return "";
3
- const p = ["enk", "as", "da", "sa", "asa", "ba", "ans", "sti", "nuf"], r = n.toLowerCase().split(" ");
4
- let t = r.map((s, e) => {
5
- const c = e === r.length - 1;
6
- return a === "company" && c && p.includes(s) ? s.toUpperCase() : s.split("-").map((o) => o.charAt(0).toUpperCase() + o.slice(1)).join("-");
7
- });
8
- if (a === "person" && i && t.length > 1) {
9
- const [s, ...e] = t;
10
- t = [...e, s];
1
+ const g = ({ fullName: a, type: r, reverseNameOrder: c }) => {
2
+ if (!a) return "";
3
+ const p = ["enk", "as", "da", "sa", "asa", "ba", "ans", "sti", "nuf"], i = a.split(" "), f = (t) => {
4
+ if (!t.includes(".")) return !1;
5
+ const s = t.split(".").filter((e) => e.length > 0);
6
+ return s.length > 0 && s.every((e) => e.length <= 3);
7
+ }, u = (t, s) => {
8
+ const e = s === i.length - 1, o = t.toLowerCase();
9
+ return r === "company" && e && p.includes(o) ? o.toUpperCase() : r === "company" && f(t) ? t : o.split("-").map((l) => l.charAt(0).toUpperCase() + l.slice(1)).join("-");
10
+ };
11
+ let n = i.map(u);
12
+ if (r === "person" && c && n.length > 1) {
13
+ const [t, ...s] = n;
14
+ n = [...s, t];
11
15
  }
12
- return t.join(" ");
16
+ return n.join(" ");
13
17
  };
14
18
  export {
15
- l as formatDisplayName
19
+ g as formatDisplayName
16
20
  };
@@ -17,5 +17,19 @@ s("formatDisplayName", () => {
17
17
  t(a({ fullName: "test testy-test da", type: "company" })).toBe("Test Testy-Test DA");
18
18
  }), e("returns empty string for empty input", () => {
19
19
  t(a({ fullName: "", type: "person" })).toBe("");
20
+ }), e("preserves abbreviations with periods in company names", () => {
21
+ t(a({ fullName: "A.B.C AS", type: "company" })).toBe("A.B.C AS");
22
+ }), e("preserves multiple abbreviations in company name", () => {
23
+ t(a({ fullName: "A.B.C X.Y.Z AS", type: "company" })).toBe("A.B.C X.Y.Z AS");
24
+ }), e("preserves abbreviation and formats regular words in company name", () => {
25
+ t(a({ fullName: "A.B.C consulting AS", type: "company" })).toBe("A.B.C Consulting AS");
26
+ }), e("formats regular company name without abbreviations", () => {
27
+ t(a({ fullName: "acme corporation AS", type: "company" })).toBe("Acme Corporation AS");
28
+ }), e("preserves two-letter abbreviation with period", () => {
29
+ t(a({ fullName: "A.B. services AS", type: "company" })).toBe("A.B. Services AS");
30
+ }), e("does not treat long segments as abbreviations", () => {
31
+ t(a({ fullName: "test.company AS", type: "company" })).toBe("Test.company AS");
32
+ }), e("does not affect person names with periods", () => {
33
+ t(a({ fullName: "TEST A.B.C", type: "person" })).toBe("Test A.b.c");
20
34
  });
21
35
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.52.6",
3
+ "version": "0.52.7",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",
@@ -75,6 +75,7 @@
75
75
  },
76
76
  "scripts": {
77
77
  "test": "vitest run",
78
+ "test:unit": "vitest run --project=unit",
78
79
  "storybook": "storybook dev -p 6006",
79
80
  "typecheck": "tsc --noEmit",
80
81
  "build": "tsc && vite build",