@open3cl/engine 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +20 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open3cl/engine",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Open Source 3CL-DPE engine",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utils.js CHANGED
@@ -7,6 +7,11 @@ export function set_bug_for_bug_compat() {
7
7
  bug_for_bug_compat = true;
8
8
  }
9
9
 
10
+ export let use_enum_as_string = false;
11
+ export function set_use_enum_as_string() {
12
+ use_enum_as_string = true;
13
+ }
14
+
10
15
  export let tv_match_new_version = false;
11
16
  export function set_tv_match_optimized_version() {
12
17
  tv_match_new_version = true;
@@ -279,6 +284,18 @@ export function removeKeyFromJSON(jsonObj, keyToRemove, skipKeys) {
279
284
  }
280
285
  }
281
286
 
287
+ export function useEnumAsString(jsonObj) {
288
+ for (const key in jsonObj) {
289
+ if (jsonObj.hasOwnProperty(key)) {
290
+ if (key.startsWith('enum_')) {
291
+ jsonObj[key] = jsonObj[key].toString();
292
+ } else if (typeof jsonObj[key] === 'object') {
293
+ useEnumAsString(jsonObj[key]);
294
+ }
295
+ }
296
+ }
297
+ }
298
+
282
299
  export function clean_dpe(dpe_in) {
283
300
  // skip generateur_[ecs|chauffage] because some input data is contained in donnee_intermediaire (e.g. pn, qp0, ...)
284
301
  removeKeyFromJSON(dpe_in, 'donnee_intermediaire', ['generateur_ecs', 'generateur_chauffage']);
@@ -300,6 +317,9 @@ export function sanitize_dpe(dpe_in) {
300
317
  _.set(dpe_in, path, []);
301
318
  }
302
319
  }
320
+ if (use_enum_as_string) {
321
+ useEnumAsString(dpe_in);
322
+ }
303
323
  }
304
324
 
305
325
  /**