@yuneta/gobj-js 7.25.2 → 7.25.3

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.
package/README.md CHANGED
@@ -531,8 +531,10 @@ kw_get_dict_value(gobj, kw, path, default_value, flag)
531
531
  // the default AS GIVEN otherwise (absent key or other type), as in C:
532
532
  // kw_get_list(gobj, {x: [1, 2]}, "x", [], 0) → [1, 2] (the same array)
533
533
  // kw_get_dict(gobj, {}, "x", null, 0) → null
534
- // kw_get_bool(gobj, {x: "false"}, "x", true, 0) → true (not a boolean)
534
+ // kw_get_bool(gobj, {x: "false"}, "x", true, 0) → true (not a boolean: logged)
535
535
  // kw_get_bool(gobj, {x: "false"}, "x", true, KW_WILD_NUMBER) → false
536
+ // kw_get_bool() logs a value that is not a boolean even without
537
+ // KW_REQUIRED ("path MUST BE a json boolean"), as the C reader does.
536
538
 
537
539
  kw_set_dict_value(gobj, kw, path, value)
538
540
  kw_set_subdict_value(gobj, kw, path, key, value)
@@ -3605,10 +3605,13 @@ function kw_delete(gobj, kw, path) {
3605
3605
  }
3606
3606
  /************************************************************
3607
3607
  * As the C kw_get_bool(): a boolean found is the answer, and
3608
- * anything else gives the default back -- unless KW_WILD_NUMBER
3609
- * asks to read a number (0 is false), a string ("true"/"false"
3610
- * in any case, else its integer) or null (false). Before gobj-js
3611
- * 7.25.2 the value went through Boolean(), so "false" was TRUE.
3608
+ * anything else gives the default back, LOGGED ("path MUST BE a
3609
+ * json boolean", required or not) -- unless KW_WILD_NUMBER asks
3610
+ * to read a number (0 is false), a string ("true"/"false" in any
3611
+ * case, else its integer) or null (false); a list or a dict is
3612
+ * then false, logged too. Before gobj-js 7.25.2 the value went
3613
+ * through Boolean(), so "false" was TRUE; before 7.25.3 a value
3614
+ * of the wrong type gave the default back in silence.
3612
3615
  ************************************************************/
3613
3616
  function kw_get_bool(gobj, kw, path, default_value, flag) {
3614
3617
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
@@ -3636,11 +3639,13 @@ function kw_get_bool(gobj, kw, path, default_value, flag) {
3636
3639
  else if (b.toLowerCase() === "false") value = false;
3637
3640
  else value = (parseInt(b) || 0) !== 0;
3638
3641
  } else if (wild && b === null) value = false;
3639
- else {
3640
- if (required) {
3641
- log_error(`${gobj_short_name(gobj)}: path value MUST BE a boolean: ${path}`);
3642
- trace_msg(kw);
3643
- }
3642
+ else if (wild) {
3643
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a simple json element: '${path}'`);
3644
+ trace_json(kw);
3645
+ return false;
3646
+ } else {
3647
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json boolean: '${path}'`);
3648
+ trace_json(kw);
3644
3649
  return Boolean(default_value);
3645
3650
  }
3646
3651
  if (extract) kw_delete(gobj, kw, path);