@sumaris-net/ngx-components 1.23.25 → 1.23.27

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.
@@ -424,15 +424,18 @@
424
424
  return rv;
425
425
  }, {});
426
426
  }
427
- function arrayDistinct(obj, properties) {
428
- if (isEmptyArray(obj))
429
- return obj;
430
- properties = properties || Object.keys(obj[0]);
427
+ function arrayDistinct(values, keyOrProperty) {
428
+ if (isEmptyArray(values))
429
+ return values;
430
+ var properties = Array.isArray(keyOrProperty) ? keyOrProperty : (!keyOrProperty && Object.keys(values[0]));
431
+ var computeKeyFn = typeof keyOrProperty === 'function' ? keyOrProperty :
432
+ (typeof keyOrProperty === 'string' ? (function (obj) { return getPropertyByPathAsString(obj, keyOrProperty); })
433
+ : (function (obj) { return joinPropertiesPath(obj, properties, '|'); }));
431
434
  var existingIds = new Set();
432
- return obj.reduce(function (res, item) {
433
- var uniqueKey = joinPropertiesPath(item, properties, '|');
435
+ return values.reduce(function (res, item) {
436
+ var uniqueKey = computeKeyFn(item);
434
437
  if (existingIds.has(uniqueKey))
435
- return res; // Skip
438
+ return res; // Skip if duplicate
436
439
  existingIds.add(uniqueKey);
437
440
  return res.concat(item);
438
441
  }, []);
@@ -589,6 +592,10 @@
589
592
  return isNotNil(value) && NUMBER_RANGE_REGEXP.test(value);
590
593
  }
591
594
  function getPropertyByPath(obj, path, defaultValue) {
595
+ // Path is an array: convert path to string
596
+ if (Array.isArray(path)) {
597
+ return getPropertyByPath(obj, path.join('.'), defaultValue);
598
+ }
592
599
  if (isNil(obj))
593
600
  return defaultValue;
594
601
  if (isNilOrBlank(path))
@@ -603,7 +610,8 @@
603
610
  var key = path.substring(0, i);
604
611
  if (isNil(obj[key]))
605
612
  return defaultValue;
606
- if (obj[key] && typeof obj[key] === 'object') {
613
+ if (typeof obj[key] === 'object') { // Object or Array
614
+ // Recursive call
607
615
  return getPropertyByPath(obj[key], path.substring(i + 1));
608
616
  }
609
617
  throw new Error("Invalid property path: '" + key + "' is not an valid object.");
@@ -615,7 +623,7 @@
615
623
  }
616
624
  function getPropertyByPathAsString(obj, path) {
617
625
  var res = getPropertyByPath(obj, path);
618
- return res && (typeof res === 'string' ? res : ('' + res));
626
+ return (typeof res === 'string') ? res : ('' + res);
619
627
  }
620
628
  function sleep(ms) {
621
629
  if (ms <= 0)
@@ -3096,10 +3104,18 @@
3096
3104
  var ArrayPluckPipe = /** @class */ (function () {
3097
3105
  function ArrayPluckPipe() {
3098
3106
  }
3099
- ArrayPluckPipe.prototype.transform = function (val, opts) {
3100
- return (opts.omitNil !== true) ?
3101
- (val || []).map(function (value) { return value && value[opts.property]; }) :
3102
- (val || []).map(function (value) { return value && value[opts.property]; }).filter(isNotNil);
3107
+ /**
3108
+ *
3109
+ * @param values
3110
+ * @param opts property to get, or options
3111
+ */
3112
+ ArrayPluckPipe.prototype.transform = function (values, opts) {
3113
+ if (!opts || !values)
3114
+ return values;
3115
+ var property = (typeof opts === 'string') || Array.isArray(opts) ? opts : opts.property;
3116
+ return (opts['omitNil'] !== true) ?
3117
+ values.map(function (value) { return getPropertyByPath(value, property); }) :
3118
+ values.map(function (value) { return getPropertyByPath(value, property); }).filter(isNotNil);
3103
3119
  };
3104
3120
  return ArrayPluckPipe;
3105
3121
  }());
@@ -3134,6 +3150,19 @@
3134
3150
  name: 'arrayFilter'
3135
3151
  },] }
3136
3152
  ];
3153
+ var ArrayJoinPipe = /** @class */ (function () {
3154
+ function ArrayJoinPipe() {
3155
+ }
3156
+ ArrayJoinPipe.prototype.transform = function (val, separator) {
3157
+ return val && val.join(separator) || '';
3158
+ };
3159
+ return ArrayJoinPipe;
3160
+ }());
3161
+ ArrayJoinPipe.decorators = [
3162
+ { type: i0.Pipe, args: [{
3163
+ name: 'arrayJoin'
3164
+ },] }
3165
+ ];
3137
3166
 
3138
3167
  var MapGetPipe = /** @class */ (function () {
3139
3168
  function MapGetPipe() {
@@ -5043,6 +5072,7 @@
5043
5072
  ArrayPluckPipe,
5044
5073
  ArrayIncludesPipe,
5045
5074
  ArrayFilterPipe,
5075
+ ArrayJoinPipe,
5046
5076
  MapGetPipe,
5047
5077
  MapKeysPipe,
5048
5078
  MapValuesPipe,
@@ -5083,6 +5113,7 @@
5083
5113
  ArrayLengthPipe,
5084
5114
  ArrayFirstPipe,
5085
5115
  ArrayPluckPipe,
5116
+ ArrayJoinPipe,
5086
5117
  MapGetPipe,
5087
5118
  MapKeysPipe,
5088
5119
  MapValuesPipe,
@@ -35220,6 +35251,7 @@
35220
35251
  exports.ArrayFilterPipe = ArrayFilterPipe;
35221
35252
  exports.ArrayFirstPipe = ArrayFirstPipe;
35222
35253
  exports.ArrayIncludesPipe = ArrayIncludesPipe;
35254
+ exports.ArrayJoinPipe = ArrayJoinPipe;
35223
35255
  exports.ArrayLengthPipe = ArrayLengthPipe;
35224
35256
  exports.ArrayPluckPipe = ArrayPluckPipe;
35225
35257
  exports.AudioProvider = AudioProvider;