add tests and utils : limit values, get max in enums

This commit is contained in:
Tykayn 2025-04-10 12:53:03 +02:00 committed by tykayn
parent aa35803a0b
commit b4c28335b2
10 changed files with 153 additions and 43 deletions

View file

@ -1,26 +1,26 @@
import custom_utils from "./utils";
const {debugLog,prefix_phone_fr_only} = custom_utils
const { debugLog, prefix_phone_fr_only } = custom_utils
/**
* Class that helps to convert values into predefined formats
*/
export default class Formatters {
static convertToPhone(originalValue: string) :string{
static convertToPhone(originalValue: string): string {
/**
* nettoyer les numéros de téléphone en ne gardant que les nombres et le préfixe de pays
*/
debugLog("convertToPhone:" , originalValue);
debugLog("convertToPhone:", originalValue);
// debugLog('originalValue', originalValue.substring(1))
if (!originalValue) {
originalValue = ''
}
let original_without_spaces = originalValue.replace(' ', '')
let original_without_spaces = originalValue.replaceAll(' ', '')
let cleaned_value = `${original_without_spaces}`
cleaned_value = cleaned_value
.trim()
.replace('Stations-e', '')
.replaceAll('Stations-e', '')
.replace(/[a-zA-Zéèà]/ig, '')
.replace(/[\(\)\.\- ]/g, '')
let add_prefix = false;
@ -30,9 +30,9 @@ export default class Formatters {
) {
add_prefix = true
}
cleaned_value = cleaned_value.replace('+33', '')
cleaned_value = cleaned_value.replaceAll('+33', '')
debugLog("convertToPhone: cleaned_value" , cleaned_value);
debugLog("convertToPhone: cleaned_value", cleaned_value);
if (/^0/.test(cleaned_value)) {
cleaned_value = cleaned_value.substring(1)
@ -55,7 +55,7 @@ export default class Formatters {
})
convertedValue = convertedValue.replace(' ', ' ').trim();
convertedValue = convertedValue.replaceAll(' ', ' ').trim();
debugLog('convertedValue', convertedValue)
if (
/^\d/.test(convertedValue) &&
@ -70,7 +70,7 @@ export default class Formatters {
debugLog('phone: ', originalValue, '=>', convertedValue)
return ""+convertedValue;
return "" + convertedValue;
}
static convertToName(originalValue: string) {