@rkmodules/rules 0.0.129 → 0.0.131

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.
package/dist/index.cjs.js CHANGED
@@ -373,10 +373,13 @@ function forEachItem(tree, fn) {
373
373
  });
374
374
  });
375
375
  }
376
- function pushItem(tree, path, item) {
376
+ function ensureBranch(tree, path) {
377
377
  if (!tree[path]) {
378
378
  tree[path] = [];
379
379
  }
380
+ }
381
+ function pushItem(tree, path, item) {
382
+ ensureBranch(tree, path);
380
383
  tree[path].push(item);
381
384
  }
382
385
  /**
@@ -2459,6 +2462,7 @@ var explodeObject = {
2459
2462
  },
2460
2463
  params: {
2461
2464
  split: { type: "boolean", default: false, label: "split groups" },
2465
+ removeEmpty: { type: "boolean", default: false, label: "remove empty" },
2462
2466
  },
2463
2467
  outputs: {
2464
2468
  // values: "any",
@@ -2475,6 +2479,10 @@ var explodeObject = {
2475
2479
  branch.forEach(function (obj, index) {
2476
2480
  if (!obj)
2477
2481
  return;
2482
+ if (typeof obj !== "object")
2483
+ obj = null;
2484
+ if (obj === null && params.removeEmpty)
2485
+ ;
2478
2486
  var props = obj || {};
2479
2487
  Object.entries(props).forEach(function (_a) {
2480
2488
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
@@ -2489,6 +2497,15 @@ var explodeObject = {
2489
2497
  });
2490
2498
  });
2491
2499
  });
2500
+ if (!params.removeEmpty) {
2501
+ // ensure the same branches exist in the output even if they are empty, so that the outputs don't change shape when empty branches are added or removed from the input
2502
+ Object.entries(outputs).forEach(function (_a) {
2503
+ var _b = __read(_a, 2); _b[0]; var tree = _b[1];
2504
+ forEachBranch(object, function (branch, path) {
2505
+ ensureBranch(tree, path);
2506
+ });
2507
+ });
2508
+ }
2492
2509
  return [2 /*return*/, outputs];
2493
2510
  });
2494
2511
  }); },
@@ -8167,6 +8184,7 @@ exports.Lib = Lib;
8167
8184
  exports.binaryOnTree = binaryOnTree;
8168
8185
  exports.binaryOnTreeBranch = binaryOnTreeBranch;
8169
8186
  exports.broadCast = broadCast;
8187
+ exports.ensureBranch = ensureBranch;
8170
8188
  exports.expandTree = expandTree;
8171
8189
  exports.forEachBranch = forEachBranch;
8172
8190
  exports.forEachItem = forEachItem;