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