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