@proconnect-gouv/proconnect.identite 10.2.0 → 10.2.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @proconnect-gouv/proconnect.identite
2
2
 
3
+ ## 10.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2174](https://github.com/proconnect-gouv/proconnect-identite/pull/2174) [`bdc9f6d`](https://github.com/proconnect-gouv/proconnect-identite/commit/bdc9f6d34c80b3a5fe1bb3ad9f97212a8e913932) Thanks [@Dev-next-gen](https://github.com/Dev-next-gen)! - normalizeText retire tous les diacritiques (ñ, ã, á, ř…) et traite pareil les accents composés et décomposés
8
+ - Updated dependencies [[`4c83789`](https://github.com/proconnect-gouv/proconnect-identite/commit/4c837898d9c1e2781525aed02d7b53cc4f755f11)]:
9
+ - @proconnect-gouv/proconnect.annuaire_entreprises@3.0.4
10
+
3
11
  ## 10.2.0
4
12
 
5
13
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CA2CrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAM7E"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/managers/certification/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAgCrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAM7E"}
@@ -15,29 +15,17 @@ export function normalizeText(text) {
15
15
  return "";
16
16
  // Convert to uppercase
17
17
  let normalized = text.toUpperCase();
18
- // Replace accented characters with their simple versions
19
- const accentMap = {
20
- À: "A",
21
- Â: "A",
22
- Ä: "A",
23
- Ç: "C",
24
- É: "E",
25
- È: "E",
26
- Ê: "E",
27
- Ë: "E",
28
- Î: "I",
29
- Ï: "I",
30
- Ô: "O",
31
- Ö: "O",
32
- Ù: "U",
33
- Û: "U",
34
- Ü: "U",
35
- Ÿ: "Y",
18
+ // Replace accented characters with their simple versions: decompose them
19
+ // (NFD) and drop the combining marks, so that every Latin diacritic is
20
+ // covered and precomposed and decomposed inputs normalize the same way
21
+ normalized = normalized.normalize("NFD").replace(/\p{M}/gu, "");
22
+ // Ligatures do not decompose
23
+ const ligatureMap = {
36
24
  Æ: "AE",
37
25
  Œ: "OE",
38
26
  };
39
- for (const [accented, simple] of Object.entries(accentMap)) {
40
- normalized = normalized.replaceAll(accented, simple);
27
+ for (const [ligature, simple] of Object.entries(ligatureMap)) {
28
+ normalized = normalized.replaceAll(ligature, simple);
41
29
  }
42
30
  // Replace special characters (including ' and -) with spaces
43
31
  // Keep only letters, digits, and spaces
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proconnect-gouv/proconnect.identite",
3
- "version": "10.2.0",
3
+ "version": "10.2.1",
4
4
  "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/identite#readme",
5
5
  "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@electric-sql/pglite": "^0.3.12",
54
- "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.2",
54
+ "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.4",
55
55
  "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
56
56
  "@proconnect-gouv/proconnect.core": "^1.0.0",
57
57
  "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
@@ -65,7 +65,7 @@
65
65
  "tsx": "^4.20.3"
66
66
  },
67
67
  "peerDependencies": {
68
- "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.2",
68
+ "@proconnect-gouv/proconnect.annuaire_entreprises": "^3.0.4",
69
69
  "@proconnect-gouv/proconnect.api_entreprise": "^2.3.0",
70
70
  "@proconnect-gouv/proconnect.core": "^1.0.0",
71
71
  "@proconnect-gouv/proconnect.insee": "^2.0.0",
@@ -17,6 +17,17 @@ describe("normalizeText", () => {
17
17
  assert.equal(normalizeText("Hélène"), "HELENE");
18
18
  });
19
19
 
20
+ it("removes diacritics outside the French alphabet", () => {
21
+ assert.equal(normalizeText("Muñoz"), "MUNOZ");
22
+ assert.equal(normalizeText("João"), "JOAO");
23
+ assert.equal(normalizeText("Ángel Íñigo"), "ANGEL INIGO");
24
+ assert.equal(normalizeText("Dvořák"), "DVORAK");
25
+ });
26
+
27
+ it("normalizes decomposed and precomposed accents the same way", () => {
28
+ assert.equal(normalizeText("He\u0301le\u0300ne"), "HELENE");
29
+ });
30
+
20
31
  it("replaces special characters with spaces", () => {
21
32
  assert.equal(normalizeText("Jean-Pierre"), "JEAN PIERRE");
22
33
  assert.equal(normalizeText("O'Connor"), "O CONNOR");
@@ -60,6 +71,10 @@ describe("extractFirstName", () => {
60
71
  assert.equal(extractFirstName("Marie-Thérèse"), "MARIE");
61
72
  });
62
73
 
74
+ it("keeps the whole first name when it has a non-French diacritic", () => {
75
+ assert.equal(extractFirstName("João Pedro"), "JOAO");
76
+ });
77
+
63
78
  it("handles single name", () => {
64
79
  assert.equal(extractFirstName("Jean"), "JEAN");
65
80
  });
@@ -17,30 +17,19 @@ export function normalizeText(text: string | null | undefined): string {
17
17
  // Convert to uppercase
18
18
  let normalized = text.toUpperCase();
19
19
 
20
- // Replace accented characters with their simple versions
21
- const accentMap: Record<string, string> = {
22
- À: "A",
23
- Â: "A",
24
- Ä: "A",
25
- Ç: "C",
26
- É: "E",
27
- È: "E",
28
- Ê: "E",
29
- Ë: "E",
30
- Î: "I",
31
- Ï: "I",
32
- Ô: "O",
33
- Ö: "O",
34
- Ù: "U",
35
- Û: "U",
36
- Ü: "U",
37
- Ÿ: "Y",
20
+ // Replace accented characters with their simple versions: decompose them
21
+ // (NFD) and drop the combining marks, so that every Latin diacritic is
22
+ // covered and precomposed and decomposed inputs normalize the same way
23
+ normalized = normalized.normalize("NFD").replace(/\p{M}/gu, "");
24
+
25
+ // Ligatures do not decompose
26
+ const ligatureMap: Record<string, string> = {
38
27
  Æ: "AE",
39
28
  Œ: "OE",
40
29
  };
41
30
 
42
- for (const [accented, simple] of Object.entries(accentMap)) {
43
- normalized = normalized.replaceAll(accented, simple);
31
+ for (const [ligature, simple] of Object.entries(ligatureMap)) {
32
+ normalized = normalized.replaceAll(ligature, simple);
44
33
  }
45
34
 
46
35
  // Replace special characters (including ' and -) with spaces