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