@tspro/ts-utils-lib 2.1.0 → 2.2.1

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * TsUtilsLib v2.1.0 (esm)
3
- * (c) 20232025 PahkaSoft
2
+ * TsUtilsLib v2.2.1 (esm)
3
+ * (c) 2023-2025 PahkaSoft
4
4
  * Licensed under the MIT License
5
5
  */
6
6
  var __defProp = Object.defineProperty;
@@ -68,6 +68,11 @@ __export(assert_exports, {
68
68
  isNumber: () => isNumber2,
69
69
  isNumberBetween: () => isNumberBetween2,
70
70
  isNumberBetweenExclusive: () => isNumberBetweenExclusive2,
71
+ isNumberEq: () => isNumberEq2,
72
+ isNumberGt: () => isNumberGt2,
73
+ isNumberGte: () => isNumberGte2,
74
+ isNumberLt: () => isNumberLt2,
75
+ isNumberLte: () => isNumberLte2,
71
76
  isNumberOrUndefined: () => isNumberOrUndefined2,
72
77
  isNumericString: () => isNumericString2,
73
78
  isObject: () => isObject2,
@@ -79,6 +84,7 @@ __export(assert_exports, {
79
84
  isPosZero: () => isPosZero2,
80
85
  isPowerOfTwo: () => isPowerOfTwo2,
81
86
  isSafeInteger: () => isSafeInteger2,
87
+ isSafeNumber: () => isSafeNumber2,
82
88
  isStrictEqual: () => isStrictEqual2,
83
89
  isString: () => isString2,
84
90
  isStringOrUndefined: () => isStringOrUndefined2,
@@ -104,6 +110,9 @@ __export(str_exports, {
104
110
  removeAt: () => removeAt,
105
111
  repeatString: () => repeatString,
106
112
  replaceAt: () => replaceAt,
113
+ splitByCaps: () => splitByCaps,
114
+ splitByChars: () => splitByChars,
115
+ splitByStrings: () => splitByStrings,
107
116
  stringify: () => stringify,
108
117
  toCharArray: () => toCharArray
109
118
  });
@@ -172,6 +181,11 @@ __export(guard_exports, {
172
181
  isNumber: () => isNumber,
173
182
  isNumberBetween: () => isNumberBetween,
174
183
  isNumberBetweenExclusive: () => isNumberBetweenExclusive,
184
+ isNumberEq: () => isNumberEq,
185
+ isNumberGt: () => isNumberGt,
186
+ isNumberGte: () => isNumberGte,
187
+ isNumberLt: () => isNumberLt,
188
+ isNumberLte: () => isNumberLte,
175
189
  isNumberOrUndefined: () => isNumberOrUndefined,
176
190
  isNumericString: () => isNumericString,
177
191
  isObject: () => isObject,
@@ -183,6 +197,7 @@ __export(guard_exports, {
183
197
  isPosZero: () => isPosZero,
184
198
  isPowerOfTwo: () => isPowerOfTwo,
185
199
  isSafeInteger: () => isSafeInteger,
200
+ isSafeNumber: () => isSafeNumber,
186
201
  isStrictEqual: () => isStrictEqual,
187
202
  isString: () => isString,
188
203
  isStringOrUndefined: () => isStringOrUndefined,
@@ -338,9 +353,33 @@ function isBigInt(val) {
338
353
  function isNumber(val) {
339
354
  return typeof val === "number";
340
355
  }
356
+ function isSafeNumber(val) {
357
+ return isNumber(val) && Number.isSafeInteger(val);
358
+ }
341
359
  function isNumberOrUndefined(val) {
342
360
  return typeof val === "number" || val === void 0;
343
361
  }
362
+ function isNumberEq(val, ref) {
363
+ return isNumber(val) && val === ref;
364
+ }
365
+ function isNumberGt(val, ref) {
366
+ return isNumber(val) && isNumber(ref) && val > ref;
367
+ }
368
+ function isNumberGte(val, ref) {
369
+ return isNumber(val) && isNumber(ref) && val >= ref;
370
+ }
371
+ function isNumberLt(val, ref) {
372
+ return isNumber(val) && isNumber(ref) && val < ref;
373
+ }
374
+ function isNumberLte(val, ref) {
375
+ return isNumber(val) && isNumber(ref) && val <= ref;
376
+ }
377
+ function isNumberBetween(val, min, max) {
378
+ return isNumber(val) && isNumber(min) && isNumber(max) && val >= min && val <= max;
379
+ }
380
+ function isNumberBetweenExclusive(val, min, max) {
381
+ return isNumber(val) && isNumber(min) && isNumber(max) && val > min && val < max;
382
+ }
344
383
  function isFinite2(val) {
345
384
  return typeof val === "number" && Number.isFinite(val);
346
385
  }
@@ -377,12 +416,6 @@ function isIntegerBetween(val, min, max) {
377
416
  function isIntegerBetweenExclusive(val, min, max) {
378
417
  return isInteger(val) && isNumber(min) && isNumber(max) && val > min && val < max;
379
418
  }
380
- function isNumberBetween(val, min, max) {
381
- return isNumber(val) && isNumber(min) && isNumber(max) && val >= min && val <= max;
382
- }
383
- function isNumberBetweenExclusive(val, min, max) {
384
- return isNumber(val) && isNumber(min) && isNumber(max) && val > min && val < max;
385
- }
386
419
  function isNaNValue(val) {
387
420
  return typeof val === "number" && Number.isNaN(val);
388
421
  }
@@ -652,6 +685,18 @@ function stringify(value, maxDepth = 5, seen = /* @__PURE__ */ new WeakSet()) {
652
685
  }
653
686
  return String(value);
654
687
  }
688
+ function splitByCaps(str2) {
689
+ return str2.split(/(?=[A-Z])/).filter((x) => !!x);
690
+ }
691
+ function splitByStrings(str2, ...splitters) {
692
+ if (splitters.length === 0) return [str2];
693
+ const escaped = splitters.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
694
+ const regex = new RegExp(escaped.join("|"), "g");
695
+ return str2.split(regex);
696
+ }
697
+ function splitByChars(str2, splitters) {
698
+ return splitByStrings(str2, ...splitters.split(""));
699
+ }
655
700
 
656
701
  // src/assert/index.ts
657
702
  var fmt = stringify;
@@ -871,11 +916,51 @@ function isNumber2(val, msg) {
871
916
  _fail(`Expected ${fmt(val)} to be number`, msg);
872
917
  return val;
873
918
  }
919
+ function isSafeNumber2(val, msg) {
920
+ if (!guard_exports.isSafeNumber(val))
921
+ _fail(`Expected ${fmt(val)} to be safe number`, msg);
922
+ return val;
923
+ }
874
924
  function isNumberOrUndefined2(val, msg) {
875
925
  if (!guard_exports.isNumberOrUndefined(val))
876
926
  _fail(`Expected ${fmt(val)} to be number or undefined`, msg);
877
927
  return val;
878
928
  }
929
+ function isNumberEq2(val, ref, msg) {
930
+ if (!guard_exports.isNumberEq(val, ref))
931
+ _fail(`Expected ${fmt(val)} to be number equal to ${fmt(ref)}`, msg);
932
+ return val;
933
+ }
934
+ function isNumberGt2(val, ref, msg) {
935
+ if (!guard_exports.isNumberGt(val, ref))
936
+ _fail(`Expected ${fmt(val)} to be number > ${fmt(ref)}`, msg);
937
+ return val;
938
+ }
939
+ function isNumberGte2(val, ref, msg) {
940
+ if (!guard_exports.isNumberGte(val, ref))
941
+ _fail(`Expected ${fmt(val)} to be number >= ${fmt(ref)}`, msg);
942
+ return val;
943
+ }
944
+ function isNumberLt2(val, ref, msg) {
945
+ if (!guard_exports.isNumberLt(val, ref))
946
+ _fail(`Expected ${fmt(val)} to be number < ${fmt(ref)}`, msg);
947
+ return val;
948
+ }
949
+ function isNumberLte2(val, ref, msg) {
950
+ if (!guard_exports.isNumberLte(val, ref))
951
+ _fail(`Expected ${fmt(val)} to be number <= ${fmt(ref)}`, msg);
952
+ return val;
953
+ }
954
+ function isNumberBetween2(val, min, max, msg) {
955
+ if (!guard_exports.isNumberBetween(val, min, max))
956
+ _fail(`Expected number ${fmt(min)} <= ${fmt(val)} <= ${fmt(max)}`, msg);
957
+ return val;
958
+ }
959
+ function isNumberBetweenExclusive2(val, min, max, msg) {
960
+ if (!guard_exports.isNumberBetweenExclusive(val, min, max))
961
+ _fail(`Expected number ${fmt(min)} < ${fmt(val)} < ${fmt(max)}`, msg);
962
+ return val;
963
+ }
879
964
  function isFinite3(val, msg) {
880
965
  if (!guard_exports.isFinite(val))
881
966
  _fail(`Expected ${fmt(val)} to be finite`, msg);
@@ -936,16 +1021,6 @@ function isIntegerBetweenExclusive2(val, min, max, msg) {
936
1021
  _fail(`Expected integer ${fmt(min)} < ${fmt(val)} < ${fmt(max)}`, msg);
937
1022
  return val;
938
1023
  }
939
- function isNumberBetween2(val, min, max, msg) {
940
- if (!guard_exports.isNumberBetween(val, min, max))
941
- _fail(`Expected number ${fmt(min)} <= ${fmt(val)} <= ${fmt(max)}`, msg);
942
- return val;
943
- }
944
- function isNumberBetweenExclusive2(val, min, max, msg) {
945
- if (!guard_exports.isNumberBetweenExclusive(val, min, max))
946
- _fail(`Expected number ${fmt(min)} < ${fmt(val)} < ${fmt(max)}`, msg);
947
- return val;
948
- }
949
1024
  function isNaNValue2(val, msg) {
950
1025
  if (!guard_exports.isNaNValue(val))
951
1026
  _fail(`Expected ${fmt(val)} to be NaN`, msg);
@@ -1068,7 +1143,9 @@ var _consent;
1068
1143
  var _expires;
1069
1144
  var str = _read(ConsentCookieName);
1070
1145
  _consent = str === "accept" /* Accept */ || str === "decline" /* Decline */ ? str : void 0;
1071
- function _getList() {
1146
+ function _getCookieList() {
1147
+ if (typeof document === "undefined")
1148
+ return [];
1072
1149
  let s = document.cookie;
1073
1150
  return s.split(";").map((c) => c.trim());
1074
1151
  }
@@ -1077,15 +1154,17 @@ function _save(name, value) {
1077
1154
  if (_expires) {
1078
1155
  cookie += "expires=" + _expires.toUTCString() + ";";
1079
1156
  }
1080
- document.cookie = cookie;
1157
+ if (typeof document !== "undefined")
1158
+ document.cookie = cookie;
1081
1159
  return value;
1082
1160
  }
1083
1161
  function _read(name, defaultValue) {
1084
- let str2 = _getList().find((c) => c.startsWith(name + "="));
1162
+ let str2 = _getCookieList().find((c) => c.startsWith(name + "="));
1085
1163
  return str2 === void 0 ? defaultValue : str2.substring(name.length + 1);
1086
1164
  }
1087
1165
  function _erase(name) {
1088
- document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
1166
+ if (typeof document !== "undefined")
1167
+ document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
1089
1168
  }
1090
1169
  function setExpireDays(days) {
1091
1170
  _expires = /* @__PURE__ */ new Date();
@@ -1134,7 +1213,8 @@ function erase(name) {
1134
1213
  _erase(name);
1135
1214
  }
1136
1215
  function eraseAll() {
1137
- document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
1216
+ if (typeof document !== "undefined")
1217
+ document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
1138
1218
  }
1139
1219
 
1140
1220
  // src/web/device.ts
@@ -1152,12 +1232,16 @@ __export(device_exports, {
1152
1232
  toPx: () => toPx
1153
1233
  });
1154
1234
  function getDPI() {
1155
- let el = document.createElement("div");
1156
- el.style.width = "1in";
1157
- document.body.appendChild(el);
1158
- let dpi = el.offsetWidth;
1159
- el.remove();
1160
- return dpi || 96;
1235
+ try {
1236
+ let el = document.createElement("div");
1237
+ el.style.width = "1in";
1238
+ document.body.appendChild(el);
1239
+ let dpi = el.offsetWidth;
1240
+ el.remove();
1241
+ return dpi || 96;
1242
+ } catch (e) {
1243
+ return 96;
1244
+ }
1161
1245
  }
1162
1246
  function getScrollBarWidth() {
1163
1247
  try {
@@ -1180,18 +1264,23 @@ function getScrollBarWidth() {
1180
1264
  }
1181
1265
  }
1182
1266
  function getSystemFontSize() {
1183
- let tmpDiv = document.createElement("div");
1184
- tmpDiv.style.cssText = "display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em";
1185
- tmpDiv.appendChild(document.createTextNode("M"));
1186
- document.body.appendChild(tmpDiv);
1187
- let fontsize = tmpDiv.offsetHeight;
1188
- document.body.removeChild(tmpDiv);
1189
- return fontsize;
1267
+ try {
1268
+ let tmpDiv = document.createElement("div");
1269
+ tmpDiv.style.cssText = "display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em";
1270
+ tmpDiv.appendChild(document.createTextNode("M"));
1271
+ document.body.appendChild(tmpDiv);
1272
+ let fontsize = tmpDiv.offsetHeight;
1273
+ document.body.removeChild(tmpDiv);
1274
+ return fontsize;
1275
+ } catch (e) {
1276
+ return 16;
1277
+ }
1190
1278
  }
1191
1279
  function getIsTouchDevice() {
1192
- if ("ontouchstart" in window || "DocumentTouch" in window || "createTouch" in document && "createTouchList" in document) {
1280
+ if (typeof window === "undefined")
1281
+ return false;
1282
+ if ("ontouchstart" in window || "DocumentTouch" in window || "createTouch" in document && "createTouchList" in document)
1193
1283
  return true;
1194
- }
1195
1284
  var prefixes = " -webkit- -moz- -o- -ms- ".split(" ");
1196
1285
  var mq = function(query2) {
1197
1286
  return window.matchMedia(query2).matches;
@@ -1204,7 +1293,10 @@ function getIsMobileDevice() {
1204
1293
  return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
1205
1294
  }
1206
1295
  function getHostAddress() {
1207
- return location.protocol + "//" + location.host;
1296
+ if (typeof location === "undefined" || !location.host) {
1297
+ return "localhost";
1298
+ }
1299
+ return `${location.protocol}//${location.host}`;
1208
1300
  }
1209
1301
  var UnitRegExp = /^(mm|cm|in|inch|px|em)$/;
1210
1302
  var ValueUnitRegExp = /^([0-9\\.]+)(.*)$/;
@@ -1364,6 +1456,9 @@ __export(dom_exports, {
1364
1456
  setWidth: () => setWidth,
1365
1457
  styleLayoutChanged: () => styleLayoutChanged
1366
1458
  });
1459
+ function _getElemById(id) {
1460
+ return typeof document === "undefined" ? void 0 : document.getElementById(id) ?? void 0;
1461
+ }
1367
1462
  function toPx2(value) {
1368
1463
  return value === void 0 ? void 0 : device_exports.toPx(value);
1369
1464
  }
@@ -1400,12 +1495,17 @@ function setOffset(el, left, top, unit = "px") {
1400
1495
  el.style.top = top + unit;
1401
1496
  }
1402
1497
  function getOffset(el) {
1403
- let box = el.getBoundingClientRect();
1404
- let docElem = document.documentElement;
1405
- return {
1406
- top: box.top + window.pageYOffset - docElem.clientTop,
1407
- left: box.left + window.pageXOffset - docElem.clientLeft
1408
- };
1498
+ let { left, top } = el.getBoundingClientRect();
1499
+ if (typeof window !== "undefined") {
1500
+ left += window.pageXOffset;
1501
+ top += window.pageYOffset;
1502
+ }
1503
+ if (typeof document !== "undefined") {
1504
+ let de = document.documentElement;
1505
+ left -= de.clientLeft;
1506
+ top -= de.clientTop;
1507
+ }
1508
+ return { left, top };
1409
1509
  }
1410
1510
  function getWidth(el) {
1411
1511
  if (el instanceof Window) {
@@ -1445,11 +1545,11 @@ function setRect(el, left, top, width, height, unit = "px") {
1445
1545
  el.style.height = height + unit;
1446
1546
  }
1447
1547
  function getButton(btn) {
1448
- let el = typeof btn === "string" ? document.getElementById(btn) : btn;
1548
+ let el = typeof btn === "string" ? _getElemById(btn) : btn;
1449
1549
  return el instanceof HTMLButtonElement ? el : void 0;
1450
1550
  }
1451
1551
  function getCanvas(canvas2) {
1452
- let el = typeof canvas2 === "string" ? document.getElementById(canvas2) : canvas2;
1552
+ let el = typeof canvas2 === "string" ? _getElemById(canvas2) : canvas2;
1453
1553
  return el instanceof HTMLCanvasElement ? el : void 0;
1454
1554
  }
1455
1555
  function getPadding(style) {
@@ -1522,11 +1622,11 @@ function styleLayoutChanged(style1, style2) {
1522
1622
  }
1523
1623
  var canvas;
1524
1624
  function getCanvasTextWidth(text, font) {
1525
- canvas ?? (canvas = document.createElement("canvas"));
1526
- let ctx = canvas.getContext("2d");
1527
- if (!ctx) {
1625
+ if (!canvas && typeof document !== "undefined")
1626
+ canvas = document.createElement("canvas");
1627
+ let ctx = canvas?.getContext("2d");
1628
+ if (!ctx)
1528
1629
  return 0;
1529
- }
1530
1630
  ctx.font = font;
1531
1631
  return ctx.measureText(text).width;
1532
1632
  }
@@ -4267,7 +4367,7 @@ var LinkedList = class _LinkedList extends BaseContainer {
4267
4367
 
4268
4368
  // src/index.ts
4269
4369
  function getLibInfo() {
4270
- return "TsUtilsLib v2.1.0 (esm)";
4370
+ return "TsUtilsLib v2.2.1 (esm)";
4271
4371
  }
4272
4372
 
4273
4373
  export { AnchoredRect, assert_exports as Assert, BaseContainer, BiMap, cookies_exports as Cookies, DefaultArray, DefaultEqualityFn, device_exports as Device, guard_exports as Guard, IndexArray, LRUCache, LinkedList, MultiContainer, Rect, SignedIndexArray, Stack, TriMap, UniMap, utils_exports as Utils, ValueSet, Vec, asMulti, getLibInfo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tspro/ts-utils-lib",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "author": "PahkaSoft",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -49,6 +49,7 @@
49
49
  "@swc/core": "^1.14.0",
50
50
  "@types/jasmine": "^5.1.8",
51
51
  "benchmark": "^2.1.4",
52
+ "core-js": "^3.46.0",
52
53
  "jasmine": "^5.8.0",
53
54
  "karma": "^6.4.4",
54
55
  "karma-chrome-launcher": "^3.2.0",
@@ -56,6 +57,7 @@
56
57
  "karma-jasmine": "^5.1.0",
57
58
  "karma-webpack": "^5.0.1",
58
59
  "npm-watch": "^0.13.0",
60
+ "regenerator-runtime": "^0.14.1",
59
61
  "ts-loader": "^9.5.2",
60
62
  "tsup": "^8.5.0",
61
63
  "typedoc": "^0.28.7",
@@ -67,9 +69,5 @@
67
69
  "watch": "tsup --watch",
68
70
  "test": "karma start",
69
71
  "docs": "typedoc"
70
- },
71
- "dependencies": {
72
- "core-js": "^3.46.0",
73
- "regenerator-runtime": "^0.14.1"
74
72
  }
75
- }
73
+ }