|
1 | 1 | import enums from './enums.js'; |
2 | 2 | import tvs from './tv.js'; |
3 | | -import { set, has } from 'lodash-es'; |
| 3 | +import { set } from 'lodash-es'; |
| 4 | +import { XMLParser } from 'fast-xml-parser'; |
| 5 | + |
| 6 | +export const xmlParser = new XMLParser({ |
| 7 | + // We want to make sure collections of length 1 are still parsed as arrays |
| 8 | + isArray: (name) => { |
| 9 | + const collectionNames = [ |
| 10 | + 'mur', |
| 11 | + 'plancher_bas', |
| 12 | + 'plancher_haut', |
| 13 | + 'baie_vitree', |
| 14 | + 'porte', |
| 15 | + 'pont_thermique', |
| 16 | + 'ventilation', |
| 17 | + 'installation_ecs', |
| 18 | + 'generateur_ecs', |
| 19 | + 'climatisation', |
| 20 | + 'installation_chauffage', |
| 21 | + 'generateur_chauffage', |
| 22 | + 'emetteur_chauffage', |
| 23 | + 'sortie_par_energie' |
| 24 | + ]; |
| 25 | + if (collectionNames.includes(name)) return true; |
| 26 | + }, |
| 27 | + tagValueProcessor: (tagName, val) => { |
| 28 | + if (tagName.startsWith('enum_')) { |
| 29 | + // Preserve value as string for tags starting with "enum_" |
| 30 | + return null; |
| 31 | + } |
| 32 | + if (Number.isNaN(Number(val))) return val; |
| 33 | + return Number(val); |
| 34 | + } |
| 35 | +}); |
4 | 36 |
|
5 | 37 | export let bug_for_bug_compat = false; |
6 | 38 | export function set_bug_for_bug_compat() { |
@@ -285,44 +317,12 @@ export function removeKeyFromJSON(jsonObj, keyToRemove, skipKeys) { |
285 | 317 | } |
286 | 318 | } |
287 | 319 |
|
288 | | -export function useEnumAsString(jsonObj) { |
289 | | - for (const key in jsonObj) { |
290 | | - if (jsonObj.hasOwnProperty(key)) { |
291 | | - if (key.startsWith('enum_')) { |
292 | | - if (jsonObj[key] !== null) jsonObj[key] = jsonObj[key].toString(); |
293 | | - } else if (typeof jsonObj[key] === 'object') { |
294 | | - useEnumAsString(jsonObj[key]); |
295 | | - } |
296 | | - } |
297 | | - } |
298 | | -} |
299 | | - |
300 | 320 | export function clean_dpe(dpe_in) { |
301 | 321 | // skip generateur_[ecs|chauffage] because some input data is contained in donnee_intermediaire (e.g. pn, qp0, ...) |
302 | 322 | removeKeyFromJSON(dpe_in, 'donnee_intermediaire', ['generateur_ecs', 'generateur_chauffage']); |
303 | 323 | set(dpe_in, 'logement.sortie', null); |
304 | 324 | } |
305 | 325 |
|
306 | | -export function sanitize_dpe(dpe_in) { |
307 | | - const collection_paths = [ |
308 | | - 'logement.enveloppe.plancher_bas_collection.plancher_bas', |
309 | | - 'logement.enveloppe.plancher_haut_collection.plancher_haut', |
310 | | - 'logement.ventilation_collection.ventilation', |
311 | | - 'logement.climatisation_collection.climatisation', |
312 | | - 'logement.enveloppe.baie_vitree_collection.baie_vitree', |
313 | | - 'logement.enveloppe.porte_collection.porte', |
314 | | - 'logement.enveloppe.pont_thermique_collection.pont_thermique' |
315 | | - ]; |
316 | | - for (const path of collection_paths) { |
317 | | - if (!has(dpe_in, path)) { |
318 | | - set(dpe_in, path, []); |
319 | | - } |
320 | | - } |
321 | | - if (use_enum_as_string) { |
322 | | - useEnumAsString(dpe_in); |
323 | | - } |
324 | | -} |
325 | | - |
326 | 326 | /** |
327 | 327 | * Retrieve a number describing a thickness from the description |
328 | 328 | * @param description string in which to get the number |
|
0 commit comments