@movalib/movalib-commons 1.1.17 → 1.1.18

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.
@@ -32,14 +32,33 @@ var isEmpty = function (data) {
32
32
  exports.isEmpty = isEmpty;
33
33
  var formatFrenchVehiclePlate = function (input) {
34
34
  if (input) {
35
+ // On commence par détecter s'il s'agit d'un ancien ou nouveau format
36
+ var plateFormat = null;
37
+ if (/^[A-Za-z]/.test(input)) {
38
+ // Commence par une lettre => nouveau format
39
+ plateFormat = Enums_1.VehiclePlateFormat.FRENCH_NEW;
40
+ }
41
+ else if (/^\d/.test(input)) {
42
+ // Commence par un chiffre => ancien format
43
+ plateFormat = Enums_1.VehiclePlateFormat.FRENCH_OLD;
44
+ }
35
45
  // Supprimer tous les caractères non alphanumériques
36
46
  var cleanedInput = input.replace(/[^A-Z0-9]/gi, '').toUpperCase();
37
- // Ajouter des tirets aux positions appropriées
38
- if (cleanedInput.length >= 2) {
39
- cleanedInput = "".concat(cleanedInput.slice(0, 2), "-").concat(cleanedInput.slice(2));
40
- }
41
- if (cleanedInput.length >= 6) {
42
- cleanedInput = "".concat(cleanedInput.slice(0, 6), "-").concat(cleanedInput.slice(6, 8));
47
+ switch (plateFormat) {
48
+ case Enums_1.VehiclePlateFormat.FRENCH_NEW: {
49
+ // Ajouter des tirets aux positions appropriées
50
+ if (cleanedInput.length >= 2) {
51
+ cleanedInput = "".concat(cleanedInput.slice(0, 2), "-").concat(cleanedInput.slice(2));
52
+ }
53
+ if (cleanedInput.length >= 6) {
54
+ cleanedInput = "".concat(cleanedInput.slice(0, 6), "-").concat(cleanedInput.slice(6, 8));
55
+ }
56
+ break;
57
+ }
58
+ case Enums_1.VehiclePlateFormat.FRENCH_OLD: {
59
+ // Rien de particulier, pas de tiret sur les anciennes plaques
60
+ break;
61
+ }
43
62
  }
44
63
  return cleanedInput;
45
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -2,7 +2,7 @@ import Cookies from "js-cookie";
2
2
  import VehicleTire from "../models/VehicleTire";
3
3
  import { MovaFormField } from "./Types";
4
4
  import { CSSProperties } from "react";
5
- import { PartsApplicationType } from "./Enums";
5
+ import { PartsApplicationType, VehiclePlateFormat } from "./Enums";
6
6
 
7
7
  export const getApplicationShortLabel = (application:PartsApplicationType | undefined) => {
8
8
  if(application){
@@ -36,15 +36,37 @@ export const isEmpty = (data: Object): boolean => {
36
36
 
37
37
  export const formatFrenchVehiclePlate = (input: string | undefined): string => {
38
38
  if(input){
39
+
40
+ // On commence par détecter s'il s'agit d'un ancien ou nouveau format
41
+ let plateFormat: VehiclePlateFormat | null = null;
42
+
43
+ if (/^[A-Za-z]/.test(input)) {
44
+ // Commence par une lettre => nouveau format
45
+ plateFormat = VehiclePlateFormat.FRENCH_NEW;
46
+ } else if (/^\d/.test(input)) {
47
+ // Commence par un chiffre => ancien format
48
+ plateFormat = VehiclePlateFormat.FRENCH_OLD;
49
+ }
50
+
39
51
  // Supprimer tous les caractères non alphanumériques
40
52
  let cleanedInput = input.replace(/[^A-Z0-9]/gi, '').toUpperCase();
41
53
 
42
- // Ajouter des tirets aux positions appropriées
43
- if (cleanedInput.length >= 2) {
44
- cleanedInput = `${cleanedInput.slice(0, 2)}-${cleanedInput.slice(2)}`;
45
- }
46
- if (cleanedInput.length >= 6) {
47
- cleanedInput = `${cleanedInput.slice(0, 6)}-${cleanedInput.slice(6, 8)}`;
54
+ switch(plateFormat){
55
+ case VehiclePlateFormat.FRENCH_NEW : {
56
+ // Ajouter des tirets aux positions appropriées
57
+ if (cleanedInput.length >= 2) {
58
+ cleanedInput = `${cleanedInput.slice(0, 2)}-${cleanedInput.slice(2)}`;
59
+ }
60
+ if (cleanedInput.length >= 6) {
61
+ cleanedInput = `${cleanedInput.slice(0, 6)}-${cleanedInput.slice(6, 8)}`;
62
+ }
63
+ break;
64
+ }
65
+
66
+ case VehiclePlateFormat.FRENCH_OLD : {
67
+ // Rien de particulier, pas de tiret sur les anciennes plaques
68
+ break;
69
+ }
48
70
  }
49
71
 
50
72
  return cleanedInput;