mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-10-04 17:04:53 +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) {
|
if (mappingValueObject.convert_to_boolean_value) {
|
||||||
debugLog('convertProperty: is boolean_value_conversion')
|
debugLog('convertProperty: is boolean_value_conversion')
|
||||||
|
|
||||||
convertedValue = this.convertToYesOrNo(originalValue)
|
convertedValue = custom_utils.convertToYesOrNo(originalValue)
|
||||||
} else {
|
} else {
|
||||||
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
|
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ export default class MappingEngine {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (configObject.invert_boolean_value) {
|
if (configObject.invert_boolean_value) {
|
||||||
convertedValue = !this.convertToBoolean(originalValue) ? 'yes' : 'no'
|
convertedValue = !custom_utils.convertToBoolean(originalValue) ? 'yes' : 'no'
|
||||||
debugLog('invert boolean', convertedValue, originalValue)
|
debugLog('invert boolean', convertedValue, originalValue)
|
||||||
}
|
}
|
||||||
if (configObject.remove_stars) {
|
if (configObject.remove_stars) {
|
||||||
|
@ -409,10 +409,10 @@ export default class MappingEngine {
|
||||||
if (configObject.remove_original_key) {
|
if (configObject.remove_original_key) {
|
||||||
remove_original_key = true
|
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
|
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
|
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
|
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 {
|
export default {
|
||||||
// debug tools
|
// debug tools
|
||||||
debugLog,
|
debugLog,
|
||||||
|
@ -146,6 +187,9 @@ export default {
|
||||||
isTruthyValue,
|
isTruthyValue,
|
||||||
truthyValues,
|
truthyValues,
|
||||||
falsyValues,
|
falsyValues,
|
||||||
|
// booleans
|
||||||
|
convertToBoolean,
|
||||||
|
convertToYesOrNo,
|
||||||
// research
|
// research
|
||||||
find_max_in_string,
|
find_max_in_string,
|
||||||
// formatting
|
// formatting
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue