@yuneta/gobj-js 7.26.15 → 7.26.16

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.
@@ -3296,6 +3296,20 @@ function log_stringify(v) {
3296
3296
  }
3297
3297
  }
3298
3298
  }
3299
+ function log_string(v) {
3300
+ try {
3301
+ return String(v);
3302
+ } catch (e) {
3303
+ return log_stringify(v);
3304
+ }
3305
+ }
3306
+ function log_number(parse, v) {
3307
+ try {
3308
+ return parse(v);
3309
+ } catch (e) {
3310
+ return log_string(v);
3311
+ }
3312
+ }
3299
3313
  function format_log(format) {
3300
3314
  const args = Array.prototype.slice.call(arguments);
3301
3315
  let output = "";
@@ -3305,18 +3319,18 @@ function format_log(format) {
3305
3319
  output = format.replace(/%[sdifoO]/g, (match) => {
3306
3320
  const val = args[i++];
3307
3321
  switch (match) {
3308
- case "%s": return String(val);
3322
+ case "%s": return log_string(val);
3309
3323
  case "%d":
3310
- case "%i": return parseInt(val);
3311
- case "%f": return parseFloat(val);
3324
+ case "%i": return log_number(parseInt, val);
3325
+ case "%f": return log_number(parseFloat, val);
3312
3326
  case "%o":
3313
- case "%O": return typeof val === "object" ? log_stringify(val) : String(val);
3327
+ case "%O": return typeof val === "object" ? log_stringify(val) : log_string(val);
3314
3328
  default: return match;
3315
3329
  }
3316
3330
  });
3317
- const rest = args.slice(i).map((arg) => typeof arg === "object" ? log_stringify(arg) : String(arg));
3331
+ const rest = args.slice(i).map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg));
3318
3332
  if (rest.length > 0) output += " " + rest.join(" ");
3319
- } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : String(arg)).join(" ");
3333
+ } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg)).join(" ");
3320
3334
  return output;
3321
3335
  }
3322
3336
  function log_error(format, ...args) {
@@ -4371,6 +4385,13 @@ function kw_get_dict(gobj, kw, path, default_value, flag) {
4371
4385
  kw_set_dict_value(gobj, kw, path, default_value);
4372
4386
  return default_value;
4373
4387
  }
4388
+ if (create && v === null) {
4389
+ if (required) {
4390
+ log_error(`path not found: '${path}'`);
4391
+ trace_json_masked(kw);
4392
+ }
4393
+ return default_value;
4394
+ }
4374
4395
  if (required || create) {
4375
4396
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'` + (create ? ", cannot create" : ""));
4376
4397
  trace_json_masked(kw);
@@ -4435,6 +4456,13 @@ function kw_get_list(gobj, kw, path, default_value, flag) {
4435
4456
  kw_set_dict_value(gobj, kw, path, default_value);
4436
4457
  return default_value;
4437
4458
  }
4459
+ if (create && v === null) {
4460
+ if (required) {
4461
+ log_error(`path not found: '${path}'`);
4462
+ trace_json_masked(kw);
4463
+ }
4464
+ return default_value;
4465
+ }
4438
4466
  if (required || create) {
4439
4467
  log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'` + (create ? ", cannot create" : ""));
4440
4468
  trace_json_masked(kw);
@@ -4648,8 +4676,8 @@ Keys:
4648
4676
  ["$key1", "$key2", ...]
4649
4677
  {"$key1":*, "$key2":*, ...}
4650
4678
 
4651
- It's not a deep copy, new keys are the paths.
4652
- If paths are empty return kw
4679
+ It's not a deep copy. A key is a KEY, not a path (as C, SDK 7.26.9).
4680
+ If keys are empty return kw
4653
4681
  *************************************************************/
4654
4682
  function kw_clone_by_keys(gobj, kw, keys, verbose) {
4655
4683
  if (gobj && !is_gobj(gobj)) log_error(`GObj bad instanceof`);
@@ -4676,8 +4704,8 @@ Keys:
4676
4704
  ["$key1", "$key2", ...]
4677
4705
  {"$key1":*, "$key2":*, ...}
4678
4706
 
4679
- It's not a deep copy, new keys are the paths.
4680
- If paths are empty return empty
4707
+ It's not a deep copy. A key is a KEY, not a path (as C, SDK 7.26.9).
4708
+ If keys are empty return empty
4681
4709
  ***************************************************************************/
4682
4710
  function kw_clone_by_not_keys(gobj, kw, keys, verbose) {
4683
4711
  let kw_clone = {};