@yuneta/gobj-js 7.25.0 → 7.25.1

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.
@@ -3687,7 +3687,12 @@ function kw_get_real(gobj, kw, path, default_value, flag) {
3687
3687
  return Number(v);
3688
3688
  }
3689
3689
  /************************************************************
3690
- *
3690
+ * The default comes back AS GIVEN, as in the C kw_get_str()
3691
+ * (`const char *default_value`, where 0 is NULL). Turned into
3692
+ * a string, a default of 0 or null was "0" or "null", which is
3693
+ * TRUE: an `if(value)` on the answer took an absent key for a
3694
+ * present one. KW_CREATE stores a string default, and null for
3695
+ * any other, as C stores json_null() for a NULL default.
3691
3696
  ************************************************************/
3692
3697
  function kw_get_str(gobj, kw, path, default_value, flag) {
3693
3698
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
@@ -3697,14 +3702,13 @@ function kw_get_str(gobj, kw, path, default_value, flag) {
3697
3702
  const extract = flag && flag & kw_flag_t.KW_EXTRACT;
3698
3703
  if (v === void 0) {
3699
3704
  if (create) {
3700
- let v = String(default_value);
3701
- kw_set_dict_value(gobj, kw, path, v);
3702
- return v;
3705
+ kw_set_dict_value(gobj, kw, path, is_string(default_value) ? default_value : null);
3706
+ return default_value;
3703
3707
  } else if (required) {
3704
3708
  log_error(`path not found: '${path}'`);
3705
3709
  trace_json(kw);
3706
3710
  }
3707
- return String(default_value);
3711
+ return default_value;
3708
3712
  }
3709
3713
  if (extract) kw_delete(gobj, kw, path);
3710
3714
  if (!is_string(v)) {
@@ -3712,9 +3716,9 @@ function kw_get_str(gobj, kw, path, default_value, flag) {
3712
3716
  log_error(`${gobj_short_name(gobj)}: path value MUST BE a string: ${path}`);
3713
3717
  trace_msg(kw);
3714
3718
  }
3715
- return String(default_value);
3719
+ return default_value;
3716
3720
  }
3717
- return String(v);
3721
+ return v;
3718
3722
  }
3719
3723
  /************************************************************
3720
3724
  *