mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
refacto boolean util
This commit is contained in:
parent
44a6d309a9
commit
20b9e24eea
2 changed files with 48 additions and 43 deletions
|
@ -356,7 +356,7 @@ export default class MappingEngine {
|
|||
if (mappingValueObject.convert_to_boolean_value) {
|
||||
debugLog('convertProperty: is boolean_value_conversion')
|
||||
|
||||
convertedValue = this.convertToYesOrNo(originalValue)
|
||||
convertedValue = custom_utils.convertToYesOrNo(originalValue)
|
||||
} else {
|
||||
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ export default class MappingEngine {
|
|||
|
||||
}
|
||||
if (configObject.invert_boolean_value) {
|
||||
convertedValue = !this.convertToBoolean(originalValue) ? 'yes' : 'no'
|
||||
convertedValue = !custom_utils.convertToBoolean(originalValue) ? 'yes' : 'no'
|
||||
debugLog('invert boolean', convertedValue, originalValue)
|
||||
}
|
||||
if (configObject.remove_stars) {
|
||||
|
@ -409,10 +409,10 @@ export default class MappingEngine {
|
|||
if (configObject.remove_original_key) {
|
||||
remove_original_key = true
|
||||
}
|
||||
if (configObject.ignore_if_falsy && !this.convertToBoolean(originalValue)) {
|
||||
if (configObject.ignore_if_falsy && !custom_utils.convertToBoolean(originalValue)) {
|
||||
remove_original_key = true
|
||||
}
|
||||
if (configObject.ignore_if_truthy && this.convertToBoolean(originalValue)) {
|
||||
if (configObject.ignore_if_truthy && custom_utils.convertToBoolean(originalValue)) {
|
||||
remove_original_key = true
|
||||
}
|
||||
|
||||
|
@ -545,45 +545,6 @@ export default class MappingEngine {
|
|||
}
|
||||
|
||||
|
||||
private convertToYesOrNo(originalValue: any) {
|
||||
let intermediateValue = '' + originalValue
|
||||
let isEnumeration = false;
|
||||
let convertedValue = '';
|
||||
|
||||
// handle lists with ; as separator
|
||||
if (intermediateValue.includes(';')) {
|
||||
isEnumeration = true;
|
||||
intermediateValue = intermediateValue.split(';')[0]
|
||||
}
|
||||
// on ne peut pas conclure ce que l'on doit garder avec une liste
|
||||
if (isEnumeration) {
|
||||
this.stats.enumeration_detected++
|
||||
return ''
|
||||
}
|
||||
|
||||
debugLog('convertProperty: ==========> original value', originalValue, intermediateValue)
|
||||
if (custom_utils.truthyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'yes'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
|
||||
}
|
||||
if (custom_utils.falsyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'no'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
|
||||
}
|
||||
|
||||
return convertedValue;
|
||||
}
|
||||
|
||||
private convertToBoolean(originalValue: any): boolean {
|
||||
if (custom_utils.truthyValues.indexOf(originalValue) !== -1) {
|
||||
return true;
|
||||
}
|
||||
if (custom_utils.falsyValues.indexOf(originalValue) !== -1) {
|
||||
return false;
|
||||
}
|
||||
return false; // valeur par défaut
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,6 +137,47 @@ function truncate_enums_to_limit(str: string, limit: number = 255) {
|
|||
return str
|
||||
}
|
||||
|
||||
function convertToBoolean(originalValue: any): boolean {
|
||||
if (truthyValues.indexOf(originalValue) !== -1) {
|
||||
return true;
|
||||
}
|
||||
if (falsyValues.indexOf(originalValue) !== -1) {
|
||||
return false;
|
||||
}
|
||||
return false; // valeur par défaut
|
||||
}
|
||||
|
||||
function convertToYesOrNo(originalValue: any) {
|
||||
let intermediateValue = '' + originalValue
|
||||
let isEnumeration = false;
|
||||
let convertedValue = '';
|
||||
|
||||
// handle lists with ; as separator
|
||||
if (intermediateValue.includes(';')) {
|
||||
isEnumeration = true;
|
||||
intermediateValue = intermediateValue.split(';')[0]
|
||||
}
|
||||
// on ne peut pas conclure ce que l'on doit garder avec une liste
|
||||
if (isEnumeration) {
|
||||
this.stats.enumeration_detected++
|
||||
return ''
|
||||
}
|
||||
|
||||
debugLog('convertProperty: ==========> original value', originalValue, intermediateValue)
|
||||
if (truthyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'yes'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
|
||||
}
|
||||
if (falsyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'no'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
|
||||
}
|
||||
|
||||
return convertedValue;
|
||||
}
|
||||
|
||||
export default {
|
||||
// debug tools
|
||||
debugLog,
|
||||
|
@ -146,6 +187,9 @@ export default {
|
|||
isTruthyValue,
|
||||
truthyValues,
|
||||
falsyValues,
|
||||
// booleans
|
||||
convertToBoolean,
|
||||
convertToYesOrNo,
|
||||
// research
|
||||
find_max_in_string,
|
||||
// formatting
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue