@yuneta/gobj-js 7.16.1 → 7.16.2

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.
@@ -3272,7 +3272,9 @@
3272
3272
  return 0;
3273
3273
  }
3274
3274
  /************************************************************
3275
- * String element = 1 if not empty string
3275
+ * How much content a json carries: elements of a container,
3276
+ * 1 for a non-empty string, 0 for everything else
3277
+ * (null/undefined, scalars). C twin: json_size() in helpers.h.
3276
3278
  ************************************************************/
3277
3279
  function json_size(a) {
3278
3280
  if (is_object(a)) return Object.keys(a).length;
@@ -3281,6 +3283,22 @@
3281
3283
  else return 0;
3282
3284
  }
3283
3285
  /************************************************************
3286
+ * "There is nothing usable here": null/undefined, {}, [],
3287
+ * "" and any scalar. C twin: empty_json() in helpers.h,
3288
+ * where it is the guard to write instead of `if(!jn)` --
3289
+ * there an absent DTP_JSON is json_null(), a valid pointer.
3290
+ * Here `if(!x)` happens to work, and that difference is what
3291
+ * a port across the two runtimes gets wrong: write the same
3292
+ * question in both.
3293
+ *
3294
+ * The other question -- "absent or explicitly null", C's
3295
+ * json_absent() -- is is_null() here, since javascript has
3296
+ * no second null to tell apart.
3297
+ ************************************************************/
3298
+ function empty_json(a) {
3299
+ return json_size(a) === 0;
3300
+ }
3301
+ /************************************************************
3284
3302
  * Return if a value is an object (excluding arrays & null)
3285
3303
  ************************************************************/
3286
3304
  function is_object(value) {
@@ -6916,6 +6934,7 @@
6916
6934
  exports.debounce = debounce;
6917
6935
  exports.delete_from_list = delete_from_list;
6918
6936
  exports.duplicate_objects = duplicate_objects;
6937
+ exports.empty_json = empty_json;
6919
6938
  exports.empty_string = empty_string;
6920
6939
  exports.escapeHtml = escapeHtml;
6921
6940
  exports.event_flag_t = event_flag_t;