@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.
- package/dist/src/helpers/Tools.js +25 -6
- package/package.json +1 -1
- package/src/helpers/Tools.ts +29 -7
|
@@ -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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
package/src/helpers/Tools.ts
CHANGED
|
@@ -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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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;
|