tiny-essentials 1.21.5 → 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.
- package/README.md +4 -6
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/libs/TinyHtml.cjs +100 -15
- package/dist/v1/libs/TinyHtml.d.mts +58 -8
- package/dist/v1/libs/TinyHtml.mjs +95 -14
- package/docs/v1/libs/TinyHtml.md +46 -4
- package/package.json +1 -1
|
@@ -3906,7 +3906,8 @@ class TinyHtml {
|
|
|
3906
3906
|
*/
|
|
3907
3907
|
static setBigInt(el, value) {
|
|
3908
3908
|
if (typeof value !== 'bigint') throw new Error('Value is not a valid BigInt.');
|
|
3909
|
-
|
|
3909
|
+
const data = value.toString();
|
|
3910
|
+
TinyHtml._preElems(el, 'setBigInt').forEach((el) => (el.textContent = data));
|
|
3910
3911
|
return el;
|
|
3911
3912
|
}
|
|
3912
3913
|
|
|
@@ -3949,7 +3950,8 @@ class TinyHtml {
|
|
|
3949
3950
|
static setDate(el, value) {
|
|
3950
3951
|
if (!(value instanceof Date) || Number.isNaN(value.getTime()))
|
|
3951
3952
|
throw new Error('Value is not a valid Date.');
|
|
3952
|
-
|
|
3953
|
+
const data = value.toISOString();
|
|
3954
|
+
TinyHtml._preElems(el, 'setDate').forEach((el) => (el.textContent = data));
|
|
3953
3955
|
return el;
|
|
3954
3956
|
}
|
|
3955
3957
|
|
|
@@ -3989,25 +3991,26 @@ class TinyHtml {
|
|
|
3989
3991
|
/**
|
|
3990
3992
|
* Set JSON content of elements.
|
|
3991
3993
|
* @param {TinyElement|TinyElement[]} el
|
|
3992
|
-
* @param {any} value
|
|
3994
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
3995
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
3993
3996
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
3994
3997
|
* @returns {TinyElement|TinyElement[]}
|
|
3995
3998
|
*/
|
|
3996
|
-
static setJson(el, value, space) {
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
);
|
|
3999
|
+
static setJson(el, value, replacer, space) {
|
|
4000
|
+
const data = JSON.stringify(value, replacer, space);
|
|
4001
|
+
TinyHtml._preElems(el, 'setJson').forEach((el) => (el.textContent = data));
|
|
4000
4002
|
return el;
|
|
4001
4003
|
}
|
|
4002
4004
|
|
|
4003
4005
|
/**
|
|
4004
4006
|
* Set JSON content of the element.
|
|
4005
|
-
* @param {any} value
|
|
4007
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
4008
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
4006
4009
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
4007
4010
|
* @returns {TinyElement|TinyElement[]}
|
|
4008
4011
|
*/
|
|
4009
|
-
setJson(value, space) {
|
|
4010
|
-
return TinyHtml.setJson(this, value, space);
|
|
4012
|
+
setJson(value, replacer, space) {
|
|
4013
|
+
return TinyHtml.setJson(this, value, replacer, space);
|
|
4011
4014
|
}
|
|
4012
4015
|
|
|
4013
4016
|
/**
|
|
@@ -4036,7 +4039,8 @@ class TinyHtml {
|
|
|
4036
4039
|
*/
|
|
4037
4040
|
static setNumber(el, value) {
|
|
4038
4041
|
if (typeof value !== 'number') throw new Error('Value is not a valid number.');
|
|
4039
|
-
|
|
4042
|
+
const data = value.toString();
|
|
4043
|
+
TinyHtml._preElems(el, 'setNumber').forEach((el) => (el.textContent = data));
|
|
4040
4044
|
return el;
|
|
4041
4045
|
}
|
|
4042
4046
|
|
|
@@ -4049,6 +4053,87 @@ class TinyHtml {
|
|
|
4049
4053
|
return TinyHtml.setNumber(this, value);
|
|
4050
4054
|
}
|
|
4051
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
|
+
|
|
4052
4137
|
/**
|
|
4053
4138
|
* Returns the text content of the element.
|
|
4054
4139
|
* @param {TinyElement} el - Target element.
|
|
@@ -4070,18 +4155,18 @@ class TinyHtml {
|
|
|
4070
4155
|
/**
|
|
4071
4156
|
* Set text content of elements.
|
|
4072
4157
|
* @param {TinyElement|TinyElement[]} el
|
|
4073
|
-
* @param {
|
|
4158
|
+
* @param {*} value
|
|
4074
4159
|
* @returns {TinyElement|TinyElement[]}
|
|
4075
4160
|
*/
|
|
4076
4161
|
static setText(el, value) {
|
|
4077
|
-
|
|
4078
|
-
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent =
|
|
4162
|
+
const data = String(value);
|
|
4163
|
+
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = data));
|
|
4079
4164
|
return el;
|
|
4080
4165
|
}
|
|
4081
4166
|
|
|
4082
4167
|
/**
|
|
4083
4168
|
* Set text content of the element.
|
|
4084
|
-
* @param {
|
|
4169
|
+
* @param {*} value
|
|
4085
4170
|
* @returns {TinyElement|TinyElement[]}
|
|
4086
4171
|
*/
|
|
4087
4172
|
setText(value) {
|
|
@@ -1516,11 +1516,12 @@ declare class TinyHtml {
|
|
|
1516
1516
|
/**
|
|
1517
1517
|
* Set JSON content of elements.
|
|
1518
1518
|
* @param {TinyElement|TinyElement[]} el
|
|
1519
|
-
* @param {any} value
|
|
1519
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
1520
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
1520
1521
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
1521
1522
|
* @returns {TinyElement|TinyElement[]}
|
|
1522
1523
|
*/
|
|
1523
|
-
static setJson(el: TinyElement | TinyElement[], value: any, space?: number | string): TinyElement | TinyElement[];
|
|
1524
|
+
static setJson(el: TinyElement | TinyElement[], value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): TinyElement | TinyElement[];
|
|
1524
1525
|
/**
|
|
1525
1526
|
* Returns the number content of the element.
|
|
1526
1527
|
* @param {TinyElement} el - Target element.
|
|
@@ -1534,6 +1535,32 @@ declare class TinyHtml {
|
|
|
1534
1535
|
* @returns {TinyElement|TinyElement[]}
|
|
1535
1536
|
*/
|
|
1536
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[];
|
|
1537
1564
|
/**
|
|
1538
1565
|
* Returns the text content of the element.
|
|
1539
1566
|
* @param {TinyElement} el - Target element.
|
|
@@ -1543,10 +1570,10 @@ declare class TinyHtml {
|
|
|
1543
1570
|
/**
|
|
1544
1571
|
* Set text content of elements.
|
|
1545
1572
|
* @param {TinyElement|TinyElement[]} el
|
|
1546
|
-
* @param {
|
|
1573
|
+
* @param {*} value
|
|
1547
1574
|
* @returns {TinyElement|TinyElement[]}
|
|
1548
1575
|
*/
|
|
1549
|
-
static setText(el: TinyElement | TinyElement[], value:
|
|
1576
|
+
static setText(el: TinyElement | TinyElement[], value: any): TinyElement | TinyElement[];
|
|
1550
1577
|
/**
|
|
1551
1578
|
* Remove all child nodes from each element.
|
|
1552
1579
|
* @param {TinyElement|TinyElement[]} el
|
|
@@ -2711,11 +2738,12 @@ declare class TinyHtml {
|
|
|
2711
2738
|
toJson(): any | null;
|
|
2712
2739
|
/**
|
|
2713
2740
|
* Set JSON content of the element.
|
|
2714
|
-
* @param {any} value
|
|
2741
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
2742
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
2715
2743
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
2716
2744
|
* @returns {TinyElement|TinyElement[]}
|
|
2717
2745
|
*/
|
|
2718
|
-
setJson(value: any, space?: number | string): TinyElement | TinyElement[];
|
|
2746
|
+
setJson(value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): TinyElement | TinyElement[];
|
|
2719
2747
|
/**
|
|
2720
2748
|
* Returns the number content of the element.
|
|
2721
2749
|
* @returns {number|null} The text content or null if none.
|
|
@@ -2727,6 +2755,28 @@ declare class TinyHtml {
|
|
|
2727
2755
|
* @returns {TinyElement|TinyElement[]}
|
|
2728
2756
|
*/
|
|
2729
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[];
|
|
2730
2780
|
/**
|
|
2731
2781
|
* Returns the text content of the element.
|
|
2732
2782
|
* @returns {string|null} The text content or null if none.
|
|
@@ -2734,10 +2784,10 @@ declare class TinyHtml {
|
|
|
2734
2784
|
text(): string | null;
|
|
2735
2785
|
/**
|
|
2736
2786
|
* Set text content of the element.
|
|
2737
|
-
* @param {
|
|
2787
|
+
* @param {*} value
|
|
2738
2788
|
* @returns {TinyElement|TinyElement[]}
|
|
2739
2789
|
*/
|
|
2740
|
-
setText(value:
|
|
2790
|
+
setText(value: any): TinyElement | TinyElement[];
|
|
2741
2791
|
/**
|
|
2742
2792
|
* Remove all child nodes of the element.
|
|
2743
2793
|
* @returns {TinyElement|TinyElement[]}
|
|
@@ -3499,7 +3499,8 @@ class TinyHtml {
|
|
|
3499
3499
|
static setBigInt(el, value) {
|
|
3500
3500
|
if (typeof value !== 'bigint')
|
|
3501
3501
|
throw new Error('Value is not a valid BigInt.');
|
|
3502
|
-
|
|
3502
|
+
const data = value.toString();
|
|
3503
|
+
TinyHtml._preElems(el, 'setBigInt').forEach((el) => (el.textContent = data));
|
|
3503
3504
|
return el;
|
|
3504
3505
|
}
|
|
3505
3506
|
/**
|
|
@@ -3539,7 +3540,8 @@ class TinyHtml {
|
|
|
3539
3540
|
static setDate(el, value) {
|
|
3540
3541
|
if (!(value instanceof Date) || Number.isNaN(value.getTime()))
|
|
3541
3542
|
throw new Error('Value is not a valid Date.');
|
|
3542
|
-
|
|
3543
|
+
const data = value.toISOString();
|
|
3544
|
+
TinyHtml._preElems(el, 'setDate').forEach((el) => (el.textContent = data));
|
|
3543
3545
|
return el;
|
|
3544
3546
|
}
|
|
3545
3547
|
/**
|
|
@@ -3577,22 +3579,25 @@ class TinyHtml {
|
|
|
3577
3579
|
/**
|
|
3578
3580
|
* Set JSON content of elements.
|
|
3579
3581
|
* @param {TinyElement|TinyElement[]} el
|
|
3580
|
-
* @param {any} value
|
|
3582
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
3583
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
3581
3584
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
3582
3585
|
* @returns {TinyElement|TinyElement[]}
|
|
3583
3586
|
*/
|
|
3584
|
-
static setJson(el, value, space) {
|
|
3585
|
-
|
|
3587
|
+
static setJson(el, value, replacer, space) {
|
|
3588
|
+
const data = JSON.stringify(value, replacer, space);
|
|
3589
|
+
TinyHtml._preElems(el, 'setJson').forEach((el) => (el.textContent = data));
|
|
3586
3590
|
return el;
|
|
3587
3591
|
}
|
|
3588
3592
|
/**
|
|
3589
3593
|
* Set JSON content of the element.
|
|
3590
|
-
* @param {any} value
|
|
3594
|
+
* @param {any} value - A JavaScript value, usually an object or array, to be converted.
|
|
3595
|
+
* @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
|
|
3591
3596
|
* @param {number|string} [space] - Indentation level or string for formatting.
|
|
3592
3597
|
* @returns {TinyElement|TinyElement[]}
|
|
3593
3598
|
*/
|
|
3594
|
-
setJson(value, space) {
|
|
3595
|
-
return TinyHtml.setJson(this, value, space);
|
|
3599
|
+
setJson(value, replacer, space) {
|
|
3600
|
+
return TinyHtml.setJson(this, value, replacer, space);
|
|
3596
3601
|
}
|
|
3597
3602
|
/**
|
|
3598
3603
|
* Returns the number content of the element.
|
|
@@ -3619,7 +3624,8 @@ class TinyHtml {
|
|
|
3619
3624
|
static setNumber(el, value) {
|
|
3620
3625
|
if (typeof value !== 'number')
|
|
3621
3626
|
throw new Error('Value is not a valid number.');
|
|
3622
|
-
|
|
3627
|
+
const data = value.toString();
|
|
3628
|
+
TinyHtml._preElems(el, 'setNumber').forEach((el) => (el.textContent = data));
|
|
3623
3629
|
return el;
|
|
3624
3630
|
}
|
|
3625
3631
|
/**
|
|
@@ -3630,6 +3636,82 @@ class TinyHtml {
|
|
|
3630
3636
|
setNumber(value) {
|
|
3631
3637
|
return TinyHtml.setNumber(this, value);
|
|
3632
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
|
+
}
|
|
3633
3715
|
/**
|
|
3634
3716
|
* Returns the text content of the element.
|
|
3635
3717
|
* @param {TinyElement} el - Target element.
|
|
@@ -3649,18 +3731,17 @@ class TinyHtml {
|
|
|
3649
3731
|
/**
|
|
3650
3732
|
* Set text content of elements.
|
|
3651
3733
|
* @param {TinyElement|TinyElement[]} el
|
|
3652
|
-
* @param {
|
|
3734
|
+
* @param {*} value
|
|
3653
3735
|
* @returns {TinyElement|TinyElement[]}
|
|
3654
3736
|
*/
|
|
3655
3737
|
static setText(el, value) {
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
3738
|
+
const data = String(value);
|
|
3739
|
+
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = data));
|
|
3659
3740
|
return el;
|
|
3660
3741
|
}
|
|
3661
3742
|
/**
|
|
3662
3743
|
* Set text content of the element.
|
|
3663
|
-
* @param {
|
|
3744
|
+
* @param {*} value
|
|
3664
3745
|
* @returns {TinyElement|TinyElement[]}
|
|
3665
3746
|
*/
|
|
3666
3747
|
setText(value) {
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -1378,15 +1378,13 @@ element.toJson(); // → { a: 1, b: 2 }
|
|
|
1378
1378
|
|
|
1379
1379
|
---
|
|
1380
1380
|
|
|
1381
|
-
### ✍️ `.setJson(value, space)` / `TinyHtml.setJson(el, value, space)`
|
|
1381
|
+
### ✍️ `.setJson(value, replacer, space)` / `TinyHtml.setJson(el, value, replacer, space)`
|
|
1382
1382
|
|
|
1383
1383
|
Sets the **JSON** content of one or more elements.
|
|
1384
|
-
`space` is optional and can be a number or string for indentation.
|
|
1385
1384
|
|
|
1386
1385
|
```js
|
|
1387
1386
|
element.setJson({ a: 1, b: 2 }); // minified
|
|
1388
|
-
element.setJson({ a: 1, b: 2 }, 2); // 2-space indentation
|
|
1389
|
-
element.setJson({ a: 1, b: 2 }, "\t"); // tab indentation
|
|
1387
|
+
element.setJson({ a: 1, b: 2 }, null, 2); // 2-space indentation
|
|
1390
1388
|
```
|
|
1391
1389
|
|
|
1392
1390
|
---
|
|
@@ -1411,6 +1409,50 @@ element.setNumber(99);
|
|
|
1411
1409
|
|
|
1412
1410
|
---
|
|
1413
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
|
+
|
|
1414
1456
|
### 📝 `.text()` / `TinyHtml.text(el)`
|
|
1415
1457
|
|
|
1416
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.
|
|
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",
|