@nu-art/ts-common 0.204.129 → 0.204.130

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.204.129",
3
+ "version": "0.204.130",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -125,4 +125,6 @@ export declare function clearArrayInstance<T extends any[]>(arr: T): void;
125
125
  * @param arr2
126
126
  */
127
127
  export declare function arrayIncludesAll<T>(arr1: T[], arr2: T[]): boolean;
128
+ export declare function getMax<T>(arr: T[], mapper?: (item: T) => number): T | undefined;
129
+ export declare function getMin<T>(arr: T[], mapper?: (item: T) => number): T | undefined;
128
130
  export {};
@@ -48,6 +48,8 @@ exports.firstElement = firstElement;
48
48
  exports.arrayIncludesAny = arrayIncludesAny;
49
49
  exports.clearArrayInstance = clearArrayInstance;
50
50
  exports.arrayIncludesAll = arrayIncludesAll;
51
+ exports.getMax = getMax;
52
+ exports.getMin = getMin;
51
53
  const tools_1 = require("./tools");
52
54
  const object_tools_1 = require("./object-tools");
53
55
  const exceptions_1 = require("../core/exceptions/exceptions");
@@ -300,7 +302,7 @@ function lastElement(array) {
300
302
  return array === null || array === void 0 ? void 0 : array[(array === null || array === void 0 ? void 0 : array.length) - 1];
301
303
  }
302
304
  function firstElement(array) {
303
- return array === null || array === void 0 ? void 0 : array[1];
305
+ return array === null || array === void 0 ? void 0 : array[0];
304
306
  }
305
307
  function arrayIncludesAny(arr1, arr2) {
306
308
  return arr1.some(item => arr2.includes(item));
@@ -321,3 +323,11 @@ function clearArrayInstance(arr) {
321
323
  function arrayIncludesAll(arr1, arr2) {
322
324
  return arr2.every(item => arr1.includes(item));
323
325
  }
326
+ function getMax(arr, mapper = (item) => item) {
327
+ const sorted = sortArray(arr, mapper, true);
328
+ return sorted[0];
329
+ }
330
+ function getMin(arr, mapper = (item) => item) {
331
+ const sorted = sortArray(arr, mapper);
332
+ return sorted[0];
333
+ }
@@ -64,7 +64,7 @@ function merge(original, override) {
64
64
  if (!(0, tools_1.exists)(original))
65
65
  return typeof override === 'object' ? (0, object_tools_1.filterKeys)(override) : override;
66
66
  if (typeof original !== typeof override || (typeof original === 'object' && typeof override === 'object' && Array.isArray(original) !== Array.isArray(override)))
67
- throw new exceptions_1.BadImplementationException(`trying to merge object of different types!! \\n Original: ${JSON.stringify(original)}\\n Override: ${JSON.stringify(override)}`);
67
+ throw new exceptions_1.BadImplementationException(`trying to merge object of different types!! \n Original: ${JSON.stringify(original)}\n Override: ${JSON.stringify(override)}`);
68
68
  if (Array.isArray(original) && Array.isArray(override))
69
69
  return mergeArray(original, override);
70
70
  if (typeof original === 'object' && typeof override === 'object' && !Array.isArray(original) && !Array.isArray(override))