tiny-essentials 1.21.6 → 1.21.7

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.
@@ -4053,6 +4053,87 @@ class TinyHtml {
4053
4053
  return TinyHtml.setNumber(this, value);
4054
4054
  }
4055
4055
 
4056
+ /**
4057
+ * Returns the boolean content of the element.
4058
+ * @param {TinyElement} el - Target element.
4059
+ * @returns {boolean|null} The boolean value or null if empty.
4060
+ */
4061
+ static toBoolean(el) {
4062
+ const elem = TinyHtml._preElem(el, 'toBoolean');
4063
+ const txt = elem.textContent?.trim();
4064
+ if (txt === undefined || txt === null || (txt !== 'true' && txt !== 'false')) return null;
4065
+ return /^true$/i.test(txt);
4066
+ }
4067
+
4068
+ /**
4069
+ * Returns the boolean content of the element.
4070
+ * @returns {boolean|null}
4071
+ */
4072
+ toBoolean() {
4073
+ return TinyHtml.toBoolean(this);
4074
+ }
4075
+
4076
+ /**
4077
+ * Set boolean content of elements.
4078
+ * @param {TinyElement|TinyElement[]} el
4079
+ * @param {boolean} value
4080
+ * @returns {TinyElement|TinyElement[]}
4081
+ */
4082
+ static setBoolean(el, value) {
4083
+ if (typeof value !== 'boolean') throw new Error('Value is not a valid boolean.');
4084
+ const data = value.toString();
4085
+ TinyHtml._preElems(el, 'setBoolean').forEach((el) => (el.textContent = data));
4086
+ return el;
4087
+ }
4088
+
4089
+ /**
4090
+ * Set boolean content of the element.
4091
+ * @param {boolean} value
4092
+ * @returns {TinyElement|TinyElement[]}
4093
+ */
4094
+ setBoolean(value) {
4095
+ return TinyHtml.setBoolean(this, value);
4096
+ }
4097
+
4098
+ /**
4099
+ * Returns the string content of the element.
4100
+ * @param {TinyElement} el - Target element.
4101
+ * @returns {string|null} The string content or null if none.
4102
+ */
4103
+ static toString(el) {
4104
+ const elem = TinyHtml._preElem(el, 'toString');
4105
+ return typeof elem.textContent === 'string' ? elem.textContent : null;
4106
+ }
4107
+
4108
+ /**
4109
+ * Returns the string content of the element.
4110
+ * @returns {string|null} The string content or null if none.
4111
+ */
4112
+ toString() {
4113
+ return TinyHtml.toString(this);
4114
+ }
4115
+
4116
+ /**
4117
+ * Set string content of elements.
4118
+ * @param {TinyElement|TinyElement[]} el
4119
+ * @param {string} value
4120
+ * @returns {TinyElement|TinyElement[]}
4121
+ */
4122
+ static setString(el, value) {
4123
+ if (typeof value !== 'string') throw new Error('Value is not a valid string.');
4124
+ TinyHtml._preElems(el, 'setString').forEach((el) => (el.textContent = value));
4125
+ return el;
4126
+ }
4127
+
4128
+ /**
4129
+ * Set string content of the element.
4130
+ * @param {string} value
4131
+ * @returns {TinyElement|TinyElement[]}
4132
+ */
4133
+ setString(value) {
4134
+ return TinyHtml.setString(this, value);
4135
+ }
4136
+
4056
4137
  /**
4057
4138
  * Returns the text content of the element.
4058
4139
  * @param {TinyElement} el - Target element.
@@ -4074,18 +4155,18 @@ class TinyHtml {
4074
4155
  /**
4075
4156
  * Set text content of elements.
4076
4157
  * @param {TinyElement|TinyElement[]} el
4077
- * @param {string} value
4158
+ * @param {*} value
4078
4159
  * @returns {TinyElement|TinyElement[]}
4079
4160
  */
4080
4161
  static setText(el, value) {
4081
- if (typeof value !== 'string') throw new Error('Value is not a valid string.');
4082
- TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
4162
+ const data = String(value);
4163
+ TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = data));
4083
4164
  return el;
4084
4165
  }
4085
4166
 
4086
4167
  /**
4087
4168
  * Set text content of the element.
4088
- * @param {string} value
4169
+ * @param {*} value
4089
4170
  * @returns {TinyElement|TinyElement[]}
4090
4171
  */
4091
4172
  setText(value) {
@@ -1535,6 +1535,32 @@ declare class TinyHtml {
1535
1535
  * @returns {TinyElement|TinyElement[]}
1536
1536
  */
1537
1537
  static setNumber(el: TinyElement | TinyElement[], value: number): TinyElement | TinyElement[];
1538
+ /**
1539
+ * Returns the boolean content of the element.
1540
+ * @param {TinyElement} el - Target element.
1541
+ * @returns {boolean|null} The boolean value or null if empty.
1542
+ */
1543
+ static toBoolean(el: TinyElement): boolean | null;
1544
+ /**
1545
+ * Set boolean content of elements.
1546
+ * @param {TinyElement|TinyElement[]} el
1547
+ * @param {boolean} value
1548
+ * @returns {TinyElement|TinyElement[]}
1549
+ */
1550
+ static setBoolean(el: TinyElement | TinyElement[], value: boolean): TinyElement | TinyElement[];
1551
+ /**
1552
+ * Returns the string content of the element.
1553
+ * @param {TinyElement} el - Target element.
1554
+ * @returns {string|null} The string content or null if none.
1555
+ */
1556
+ static toString(el: TinyElement): string | null;
1557
+ /**
1558
+ * Set string content of elements.
1559
+ * @param {TinyElement|TinyElement[]} el
1560
+ * @param {string} value
1561
+ * @returns {TinyElement|TinyElement[]}
1562
+ */
1563
+ static setString(el: TinyElement | TinyElement[], value: string): TinyElement | TinyElement[];
1538
1564
  /**
1539
1565
  * Returns the text content of the element.
1540
1566
  * @param {TinyElement} el - Target element.
@@ -1544,10 +1570,10 @@ declare class TinyHtml {
1544
1570
  /**
1545
1571
  * Set text content of elements.
1546
1572
  * @param {TinyElement|TinyElement[]} el
1547
- * @param {string} value
1573
+ * @param {*} value
1548
1574
  * @returns {TinyElement|TinyElement[]}
1549
1575
  */
1550
- static setText(el: TinyElement | TinyElement[], value: string): TinyElement | TinyElement[];
1576
+ static setText(el: TinyElement | TinyElement[], value: any): TinyElement | TinyElement[];
1551
1577
  /**
1552
1578
  * Remove all child nodes from each element.
1553
1579
  * @param {TinyElement|TinyElement[]} el
@@ -2729,6 +2755,28 @@ declare class TinyHtml {
2729
2755
  * @returns {TinyElement|TinyElement[]}
2730
2756
  */
2731
2757
  setNumber(value: number): TinyElement | TinyElement[];
2758
+ /**
2759
+ * Returns the boolean content of the element.
2760
+ * @returns {boolean|null}
2761
+ */
2762
+ toBoolean(): boolean | null;
2763
+ /**
2764
+ * Set boolean content of the element.
2765
+ * @param {boolean} value
2766
+ * @returns {TinyElement|TinyElement[]}
2767
+ */
2768
+ setBoolean(value: boolean): TinyElement | TinyElement[];
2769
+ /**
2770
+ * Returns the string content of the element.
2771
+ * @returns {string|null} The string content or null if none.
2772
+ */
2773
+ toString(): string | null;
2774
+ /**
2775
+ * Set string content of the element.
2776
+ * @param {string} value
2777
+ * @returns {TinyElement|TinyElement[]}
2778
+ */
2779
+ setString(value: string): TinyElement | TinyElement[];
2732
2780
  /**
2733
2781
  * Returns the text content of the element.
2734
2782
  * @returns {string|null} The text content or null if none.
@@ -2736,10 +2784,10 @@ declare class TinyHtml {
2736
2784
  text(): string | null;
2737
2785
  /**
2738
2786
  * Set text content of the element.
2739
- * @param {string} value
2787
+ * @param {*} value
2740
2788
  * @returns {TinyElement|TinyElement[]}
2741
2789
  */
2742
- setText(value: string): TinyElement | TinyElement[];
2790
+ setText(value: any): TinyElement | TinyElement[];
2743
2791
  /**
2744
2792
  * Remove all child nodes of the element.
2745
2793
  * @returns {TinyElement|TinyElement[]}
@@ -3636,6 +3636,82 @@ class TinyHtml {
3636
3636
  setNumber(value) {
3637
3637
  return TinyHtml.setNumber(this, value);
3638
3638
  }
3639
+ /**
3640
+ * Returns the boolean content of the element.
3641
+ * @param {TinyElement} el - Target element.
3642
+ * @returns {boolean|null} The boolean value or null if empty.
3643
+ */
3644
+ static toBoolean(el) {
3645
+ const elem = TinyHtml._preElem(el, 'toBoolean');
3646
+ const txt = elem.textContent?.trim();
3647
+ if (txt === undefined || txt === null || (txt !== 'true' && txt !== 'false'))
3648
+ return null;
3649
+ return /^true$/i.test(txt);
3650
+ }
3651
+ /**
3652
+ * Returns the boolean content of the element.
3653
+ * @returns {boolean|null}
3654
+ */
3655
+ toBoolean() {
3656
+ return TinyHtml.toBoolean(this);
3657
+ }
3658
+ /**
3659
+ * Set boolean content of elements.
3660
+ * @param {TinyElement|TinyElement[]} el
3661
+ * @param {boolean} value
3662
+ * @returns {TinyElement|TinyElement[]}
3663
+ */
3664
+ static setBoolean(el, value) {
3665
+ if (typeof value !== 'boolean')
3666
+ throw new Error('Value is not a valid boolean.');
3667
+ const data = value.toString();
3668
+ TinyHtml._preElems(el, 'setBoolean').forEach((el) => (el.textContent = data));
3669
+ return el;
3670
+ }
3671
+ /**
3672
+ * Set boolean content of the element.
3673
+ * @param {boolean} value
3674
+ * @returns {TinyElement|TinyElement[]}
3675
+ */
3676
+ setBoolean(value) {
3677
+ return TinyHtml.setBoolean(this, value);
3678
+ }
3679
+ /**
3680
+ * Returns the string content of the element.
3681
+ * @param {TinyElement} el - Target element.
3682
+ * @returns {string|null} The string content or null if none.
3683
+ */
3684
+ static toString(el) {
3685
+ const elem = TinyHtml._preElem(el, 'toString');
3686
+ return typeof elem.textContent === 'string' ? elem.textContent : null;
3687
+ }
3688
+ /**
3689
+ * Returns the string content of the element.
3690
+ * @returns {string|null} The string content or null if none.
3691
+ */
3692
+ toString() {
3693
+ return TinyHtml.toString(this);
3694
+ }
3695
+ /**
3696
+ * Set string content of elements.
3697
+ * @param {TinyElement|TinyElement[]} el
3698
+ * @param {string} value
3699
+ * @returns {TinyElement|TinyElement[]}
3700
+ */
3701
+ static setString(el, value) {
3702
+ if (typeof value !== 'string')
3703
+ throw new Error('Value is not a valid string.');
3704
+ TinyHtml._preElems(el, 'setString').forEach((el) => (el.textContent = value));
3705
+ return el;
3706
+ }
3707
+ /**
3708
+ * Set string content of the element.
3709
+ * @param {string} value
3710
+ * @returns {TinyElement|TinyElement[]}
3711
+ */
3712
+ setString(value) {
3713
+ return TinyHtml.setString(this, value);
3714
+ }
3639
3715
  /**
3640
3716
  * Returns the text content of the element.
3641
3717
  * @param {TinyElement} el - Target element.
@@ -3655,18 +3731,17 @@ class TinyHtml {
3655
3731
  /**
3656
3732
  * Set text content of elements.
3657
3733
  * @param {TinyElement|TinyElement[]} el
3658
- * @param {string} value
3734
+ * @param {*} value
3659
3735
  * @returns {TinyElement|TinyElement[]}
3660
3736
  */
3661
3737
  static setText(el, value) {
3662
- if (typeof value !== 'string')
3663
- throw new Error('Value is not a valid string.');
3664
- TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
3738
+ const data = String(value);
3739
+ TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = data));
3665
3740
  return el;
3666
3741
  }
3667
3742
  /**
3668
3743
  * Set text content of the element.
3669
- * @param {string} value
3744
+ * @param {*} value
3670
3745
  * @returns {TinyElement|TinyElement[]}
3671
3746
  */
3672
3747
  setText(value) {
@@ -1409,6 +1409,50 @@ element.setNumber(99);
1409
1409
 
1410
1410
  ---
1411
1411
 
1412
+ ### 📝 `.toBoolean()` / `TinyHtml.toBoolean(el)`
1413
+
1414
+ Gets the **boolean** content of the element.
1415
+ Returns `true` if the text is `"true"`, `false` if `"false"`, and `null` if empty or invalid.
1416
+
1417
+ ```js
1418
+ element.toBoolean(); // → true | false | null
1419
+ ```
1420
+
1421
+ ---
1422
+
1423
+ ### ✍️ `.setBoolean(value)` / `TinyHtml.setBoolean(el, value)`
1424
+
1425
+ Sets the **boolean** content of one or more elements.
1426
+ Throws if `value` is not a boolean.
1427
+
1428
+ ```js
1429
+ element.setBoolean(true); // sets content to "true"
1430
+ element.setBoolean(false); // sets content to "false"
1431
+ ```
1432
+
1433
+ ---
1434
+
1435
+ ### 📝 `.toString()` / `TinyHtml.toString(el)`
1436
+
1437
+ Gets the **string** content of the element (returns `null` if none).
1438
+
1439
+ ```js
1440
+ element.toString(); // → "Hello world"
1441
+ ```
1442
+
1443
+ ---
1444
+
1445
+ ### ✍️ `.setString(value)` / `TinyHtml.setString(el, value)`
1446
+
1447
+ Sets the **string** content of one or more elements.
1448
+ Throws if `value` is not a string.
1449
+
1450
+ ```js
1451
+ element.setString("New text content");
1452
+ ```
1453
+
1454
+ ---
1455
+
1412
1456
  ### 📝 `.text()` / `TinyHtml.text(el)`
1413
1457
 
1414
1458
  Gets the text content of the element (returns `null` if none).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.21.6",
3
+ "version": "1.21.7",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",