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