@tspro/ts-utils-lib 3.1.1 → 3.3.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 +11 -0
- package/README.md +6 -26
- package/dist/index.d.ts +16 -11
- package/dist/index.es5.iife.js +1 -1
- package/dist/index.es5.polyfilled.iife.js +1 -1
- package/dist/index.js +64 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/*!
|
|
4
|
-
* TsUtilsLib v3.
|
|
4
|
+
* TsUtilsLib v3.3.0 (cjs)
|
|
5
5
|
* (c) 2023-2025 PahkaSoft
|
|
6
6
|
* Licensed under the MIT License
|
|
7
7
|
*/
|
|
@@ -116,7 +116,10 @@ __export(str_exports, {
|
|
|
116
116
|
splitByChars: () => splitByChars,
|
|
117
117
|
splitByStrings: () => splitByStrings,
|
|
118
118
|
stringify: () => stringify,
|
|
119
|
-
toCharArray: () => toCharArray
|
|
119
|
+
toCharArray: () => toCharArray,
|
|
120
|
+
trim: () => trim,
|
|
121
|
+
trimEnd: () => trimEnd,
|
|
122
|
+
trimStart: () => trimStart
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
// src/utils/obj/index.ts
|
|
@@ -699,6 +702,42 @@ function splitByStrings(str2, ...splitters) {
|
|
|
699
702
|
function splitByChars(str2, splitters) {
|
|
700
703
|
return splitByStrings(str2, ...splitters.split(""));
|
|
701
704
|
}
|
|
705
|
+
function trimStart(str2, ...chars) {
|
|
706
|
+
if (chars.length === 0) return str2.trimStart();
|
|
707
|
+
const sorted = [...chars].sort((a, b) => b.length - a.length);
|
|
708
|
+
let changed = true;
|
|
709
|
+
while (changed) {
|
|
710
|
+
changed = false;
|
|
711
|
+
for (const c of sorted) {
|
|
712
|
+
if (str2.startsWith(c)) {
|
|
713
|
+
str2 = str2.slice(c.length);
|
|
714
|
+
changed = true;
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return str2;
|
|
720
|
+
}
|
|
721
|
+
function trimEnd(str2, ...chars) {
|
|
722
|
+
if (chars.length === 0) return str2.trimEnd();
|
|
723
|
+
const sorted = [...chars].sort((a, b) => b.length - a.length);
|
|
724
|
+
let changed = true;
|
|
725
|
+
while (changed) {
|
|
726
|
+
changed = false;
|
|
727
|
+
for (const c of sorted) {
|
|
728
|
+
if (str2.endsWith(c)) {
|
|
729
|
+
str2 = str2.slice(0, -c.length);
|
|
730
|
+
changed = true;
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return str2;
|
|
736
|
+
}
|
|
737
|
+
function trim(str2, ...chars) {
|
|
738
|
+
if (chars.length === 0) return str2.trim();
|
|
739
|
+
return trimEnd(trimStart(str2, ...chars), ...chars);
|
|
740
|
+
}
|
|
702
741
|
|
|
703
742
|
// src/assert/index.ts
|
|
704
743
|
var fmt = stringify;
|
|
@@ -1483,32 +1522,32 @@ function toPx(value) {
|
|
|
1483
1522
|
return value === void 0 ? void 0 : device_exports.unitToPx(value);
|
|
1484
1523
|
}
|
|
1485
1524
|
function hasClass(el, className) {
|
|
1486
|
-
if (className.length === 0)
|
|
1525
|
+
if (className.length === 0)
|
|
1487
1526
|
return false;
|
|
1488
|
-
|
|
1527
|
+
else if (el.classList)
|
|
1489
1528
|
return el.classList.contains(className);
|
|
1490
|
-
|
|
1529
|
+
else
|
|
1491
1530
|
return !!el.className.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
function addClass(el, className) {
|
|
1495
|
-
if (className.length === 0) {
|
|
1496
|
-
return;
|
|
1497
|
-
} else if (el.classList) {
|
|
1498
|
-
el.classList.add(className);
|
|
1499
|
-
} else if (!hasClass(el, className)) {
|
|
1500
|
-
el.className += " " + className;
|
|
1501
|
-
}
|
|
1502
1531
|
}
|
|
1503
|
-
function
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
el.classList
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}
|
|
1532
|
+
function addClass(el, ...className) {
|
|
1533
|
+
className.forEach((cls) => {
|
|
1534
|
+
if (cls.length === 0)
|
|
1535
|
+
return;
|
|
1536
|
+
else if (el.classList)
|
|
1537
|
+
el.classList.add(cls);
|
|
1538
|
+
else if (!hasClass(el, cls))
|
|
1539
|
+
el.className += " " + cls;
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
function removeClass(el, ...className) {
|
|
1543
|
+
className.forEach((cls) => {
|
|
1544
|
+
if (cls.length === 0)
|
|
1545
|
+
return;
|
|
1546
|
+
else if (el.classList)
|
|
1547
|
+
el.classList.remove(cls);
|
|
1548
|
+
else if (hasClass(el, cls))
|
|
1549
|
+
el.className = el.className.replace(new RegExp("(\\s|^)" + cls + "(\\s|$)"), " ");
|
|
1550
|
+
});
|
|
1512
1551
|
}
|
|
1513
1552
|
function setOffset(el, left, top, unit = "px") {
|
|
1514
1553
|
el.style.left = left + unit;
|
|
@@ -4427,7 +4466,7 @@ var CallTracker = _CallTracker;
|
|
|
4427
4466
|
|
|
4428
4467
|
// src/index.ts
|
|
4429
4468
|
function getLibInfo() {
|
|
4430
|
-
return "TsUtilsLib v3.
|
|
4469
|
+
return "TsUtilsLib v3.3.0 (cjs)";
|
|
4431
4470
|
}
|
|
4432
4471
|
|
|
4433
4472
|
exports.AnchoredRect = AnchoredRect;
|