@tspro/ts-utils-lib 1.7.0 → 1.9.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.9.0] - 2025-10-12
4
+ ### Added
5
+ - Utils.Math.avg()
6
+ - Utils.Obj.deepEqual()
7
+
8
+ ## [1.8.0] - 2025-10-07
9
+ ### Added
10
+ - Utils.Math.cmp()
11
+
3
12
  ## [1.7.0] - 2025-10-03
4
13
  ### Added
5
14
  - Utils.Obj.hasProperties()
package/dist/index.d.mts CHANGED
@@ -217,9 +217,13 @@ declare function calcNormal(x1: number, y1: number, x2: number, y2: number): {
217
217
  ny: number;
218
218
  };
219
219
  declare function sum(arr: number[]): number;
220
+ declare function avg(...values: number[]): number;
221
+ declare function cmp(a: number, b: number): -1 | 0 | 1;
220
222
 
223
+ declare const index$3_avg: typeof avg;
221
224
  declare const index$3_calcNormal: typeof calcNormal;
222
225
  declare const index$3_clamp: typeof clamp;
226
+ declare const index$3_cmp: typeof cmp;
223
227
  declare const index$3_interpolateCoord: typeof interpolateCoord;
224
228
  declare const index$3_interpolateY: typeof interpolateY;
225
229
  declare const index$3_isInteger: typeof isInteger;
@@ -229,7 +233,7 @@ declare const index$3_romanize: typeof romanize;
229
233
  declare const index$3_sum: typeof sum;
230
234
  declare const index$3_toOrdinalNumber: typeof toOrdinalNumber;
231
235
  declare namespace index$3 {
232
- export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
236
+ export { index$3_avg as avg, index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_cmp as cmp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
233
237
  }
234
238
 
235
239
  declare function isObject(obj: unknown): obj is Record<string, unknown>;
@@ -241,11 +245,13 @@ declare function isObject(obj: unknown): obj is Record<string, unknown>;
241
245
  * </pre>
242
246
  */
243
247
  declare function hasProperties<T extends readonly string[]>(obj: unknown, props: T | string[]): obj is Record<T[number], unknown>;
248
+ declare function deepEqual<T>(a: T, b: T): boolean;
244
249
 
250
+ declare const index$2_deepEqual: typeof deepEqual;
245
251
  declare const index$2_hasProperties: typeof hasProperties;
246
252
  declare const index$2_isObject: typeof isObject;
247
253
  declare namespace index$2 {
248
- export { index$2_hasProperties as hasProperties, index$2_isObject as isObject };
254
+ export { index$2_deepEqual as deepEqual, index$2_hasProperties as hasProperties, index$2_isObject as isObject };
249
255
  }
250
256
 
251
257
  /**
package/dist/index.d.ts CHANGED
@@ -217,9 +217,13 @@ declare function calcNormal(x1: number, y1: number, x2: number, y2: number): {
217
217
  ny: number;
218
218
  };
219
219
  declare function sum(arr: number[]): number;
220
+ declare function avg(...values: number[]): number;
221
+ declare function cmp(a: number, b: number): -1 | 0 | 1;
220
222
 
223
+ declare const index$3_avg: typeof avg;
221
224
  declare const index$3_calcNormal: typeof calcNormal;
222
225
  declare const index$3_clamp: typeof clamp;
226
+ declare const index$3_cmp: typeof cmp;
223
227
  declare const index$3_interpolateCoord: typeof interpolateCoord;
224
228
  declare const index$3_interpolateY: typeof interpolateY;
225
229
  declare const index$3_isInteger: typeof isInteger;
@@ -229,7 +233,7 @@ declare const index$3_romanize: typeof romanize;
229
233
  declare const index$3_sum: typeof sum;
230
234
  declare const index$3_toOrdinalNumber: typeof toOrdinalNumber;
231
235
  declare namespace index$3 {
232
- export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
236
+ export { index$3_avg as avg, index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_cmp as cmp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
233
237
  }
234
238
 
235
239
  declare function isObject(obj: unknown): obj is Record<string, unknown>;
@@ -241,11 +245,13 @@ declare function isObject(obj: unknown): obj is Record<string, unknown>;
241
245
  * </pre>
242
246
  */
243
247
  declare function hasProperties<T extends readonly string[]>(obj: unknown, props: T | string[]): obj is Record<T[number], unknown>;
248
+ declare function deepEqual<T>(a: T, b: T): boolean;
244
249
 
250
+ declare const index$2_deepEqual: typeof deepEqual;
245
251
  declare const index$2_hasProperties: typeof hasProperties;
246
252
  declare const index$2_isObject: typeof isObject;
247
253
  declare namespace index$2 {
248
- export { index$2_hasProperties as hasProperties, index$2_isObject as isObject };
254
+ export { index$2_deepEqual as deepEqual, index$2_hasProperties as hasProperties, index$2_isObject as isObject };
249
255
  }
250
256
 
251
257
  /**
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.7.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.9.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -67,8 +67,10 @@ __export(arr_exports, {
67
67
  // src/utils/math/index.ts
68
68
  var math_exports = {};
69
69
  __export(math_exports, {
70
+ avg: () => avg,
70
71
  calcNormal: () => calcNormal,
71
72
  clamp: () => clamp,
73
+ cmp: () => cmp,
72
74
  interpolateCoord: () => interpolateCoord,
73
75
  interpolateY: () => interpolateY,
74
76
  isInteger: () => isInteger,
@@ -181,6 +183,12 @@ function calcNormal(x1, y1, x2, y2) {
181
183
  function sum(arr) {
182
184
  return arr.reduce((prev, cur) => cur + prev, 0);
183
185
  }
186
+ function avg(...values) {
187
+ return sum(values) / values.length;
188
+ }
189
+ function cmp(a, b) {
190
+ return a < b ? -1 : a > b ? 1 : 0;
191
+ }
184
192
 
185
193
  // src/utils/arr/index.ts
186
194
  function isArray(a) {
@@ -195,8 +203,8 @@ function duplicate(a) {
195
203
  function removeDuplicates(a) {
196
204
  return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
197
205
  }
198
- function removeDuplicatesCmp(arr, cmp) {
199
- return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp(t1, t2)));
206
+ function removeDuplicatesCmp(arr, cmp2) {
207
+ return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
200
208
  }
201
209
  function fillArray(fillValue, fillCount) {
202
210
  if (!isInteger(fillCount) || fillCount < 0) {
@@ -871,6 +879,7 @@ function getMapKeys(map) {
871
879
  // src/utils/obj/index.ts
872
880
  var obj_exports = {};
873
881
  __export(obj_exports, {
882
+ deepEqual: () => deepEqual,
874
883
  hasProperties: () => hasProperties,
875
884
  isObject: () => isObject2
876
885
  });
@@ -880,6 +889,24 @@ function isObject2(obj) {
880
889
  function hasProperties(obj, props) {
881
890
  return isObject2(obj) && props.every((p) => p in obj);
882
891
  }
892
+ function deepEqual(a, b) {
893
+ if (a === b) return true;
894
+ if (a === null || b === null) return false;
895
+ if (typeof a !== "object" || typeof b !== "object") return false;
896
+ if (Array.isArray(a) && Array.isArray(b)) {
897
+ if (a.length !== b.length) return false;
898
+ return a.every((val, i) => deepEqual(val, b[i]));
899
+ }
900
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
901
+ const keysA = Object.keys(a);
902
+ const keysB = Object.keys(b);
903
+ if (keysA.length !== keysB.length) return false;
904
+ for (const key of keysA) {
905
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
906
+ if (!deepEqual(a[key], b[key])) return false;
907
+ }
908
+ return true;
909
+ }
883
910
 
884
911
  // src/utils/str/index.ts
885
912
  var str_exports = {};
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.7.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.9.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __export = (target, all) => {
@@ -40,8 +40,10 @@ __export(arr_exports, {
40
40
  // src/utils/math/index.ts
41
41
  var math_exports = {};
42
42
  __export(math_exports, {
43
+ avg: () => avg,
43
44
  calcNormal: () => calcNormal,
44
45
  clamp: () => clamp,
46
+ cmp: () => cmp,
45
47
  interpolateCoord: () => interpolateCoord,
46
48
  interpolateY: () => interpolateY,
47
49
  isInteger: () => isInteger,
@@ -154,6 +156,12 @@ function calcNormal(x1, y1, x2, y2) {
154
156
  function sum(arr) {
155
157
  return arr.reduce((prev, cur) => cur + prev, 0);
156
158
  }
159
+ function avg(...values) {
160
+ return sum(values) / values.length;
161
+ }
162
+ function cmp(a, b) {
163
+ return a < b ? -1 : a > b ? 1 : 0;
164
+ }
157
165
 
158
166
  // src/utils/arr/index.ts
159
167
  function isArray(a) {
@@ -168,8 +176,8 @@ function duplicate(a) {
168
176
  function removeDuplicates(a) {
169
177
  return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
170
178
  }
171
- function removeDuplicatesCmp(arr, cmp) {
172
- return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp(t1, t2)));
179
+ function removeDuplicatesCmp(arr, cmp2) {
180
+ return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
173
181
  }
174
182
  function fillArray(fillValue, fillCount) {
175
183
  if (!isInteger(fillCount) || fillCount < 0) {
@@ -844,6 +852,7 @@ function getMapKeys(map) {
844
852
  // src/utils/obj/index.ts
845
853
  var obj_exports = {};
846
854
  __export(obj_exports, {
855
+ deepEqual: () => deepEqual,
847
856
  hasProperties: () => hasProperties,
848
857
  isObject: () => isObject2
849
858
  });
@@ -853,6 +862,24 @@ function isObject2(obj) {
853
862
  function hasProperties(obj, props) {
854
863
  return isObject2(obj) && props.every((p) => p in obj);
855
864
  }
865
+ function deepEqual(a, b) {
866
+ if (a === b) return true;
867
+ if (a === null || b === null) return false;
868
+ if (typeof a !== "object" || typeof b !== "object") return false;
869
+ if (Array.isArray(a) && Array.isArray(b)) {
870
+ if (a.length !== b.length) return false;
871
+ return a.every((val, i) => deepEqual(val, b[i]));
872
+ }
873
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
874
+ const keysA = Object.keys(a);
875
+ const keysB = Object.keys(b);
876
+ if (keysA.length !== keysB.length) return false;
877
+ for (const key of keysA) {
878
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
879
+ if (!deepEqual(a[key], b[key])) return false;
880
+ }
881
+ return true;
882
+ }
856
883
 
857
884
  // src/utils/str/index.ts
858
885
  var str_exports = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tspro/ts-utils-lib",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "author": "PahkaSoft",
5
5
  "license": "MIT",
6
6
  "private": false,