tiny-essentials 1.21.4 → 1.21.6

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.
@@ -3873,6 +3873,186 @@ class TinyHtml {
3873
3873
  return TinyHtml.id(this);
3874
3874
  }
3875
3875
 
3876
+ /**
3877
+ * Returns the BigInt content of the element.
3878
+ * @param {TinyElement} el - Target element.
3879
+ * @returns {bigint|null} The BigInt content or null if none.
3880
+ */
3881
+ static toBigInt(el) {
3882
+ const elem = TinyHtml._preElem(el, 'toBigInt');
3883
+ const txt = elem.textContent?.trim();
3884
+ let value = null;
3885
+ try {
3886
+ value = BigInt(txt ?? '');
3887
+ } catch {
3888
+ value = null;
3889
+ }
3890
+ return value;
3891
+ }
3892
+
3893
+ /**
3894
+ * Returns the BigInt content of the element.
3895
+ * @returns {bigint|null}
3896
+ */
3897
+ toBigInt() {
3898
+ return TinyHtml.toBigInt(this);
3899
+ }
3900
+
3901
+ /**
3902
+ * Set BigInt content of elements.
3903
+ * @param {TinyElement|TinyElement[]} el
3904
+ * @param {bigint} value
3905
+ * @returns {TinyElement|TinyElement[]}
3906
+ */
3907
+ static setBigInt(el, value) {
3908
+ if (typeof value !== 'bigint') throw new Error('Value is not a valid BigInt.');
3909
+ const data = value.toString();
3910
+ TinyHtml._preElems(el, 'setBigInt').forEach((el) => (el.textContent = data));
3911
+ return el;
3912
+ }
3913
+
3914
+ /**
3915
+ * Set BigInt content of the element.
3916
+ * @param {bigint} value
3917
+ * @returns {TinyElement|TinyElement[]}
3918
+ */
3919
+ setBigInt(value) {
3920
+ return TinyHtml.setBigInt(this, value);
3921
+ }
3922
+
3923
+ /**
3924
+ * Returns the Date content of the element.
3925
+ * @param {TinyElement} el - Target element.
3926
+ * @returns {Date|null} The Date content or null if invalid.
3927
+ */
3928
+ static toDate(el) {
3929
+ const elem = TinyHtml._preElem(el, 'toDate');
3930
+ const txt = elem.textContent?.trim();
3931
+ if (!txt) return null;
3932
+ const d = new Date(txt);
3933
+ return Number.isNaN(d.getTime()) ? null : d;
3934
+ }
3935
+
3936
+ /**
3937
+ * Returns the Date content of the element.
3938
+ * @returns {Date|null}
3939
+ */
3940
+ toDate() {
3941
+ return TinyHtml.toDate(this);
3942
+ }
3943
+
3944
+ /**
3945
+ * Set Date content of elements.
3946
+ * @param {TinyElement|TinyElement[]} el
3947
+ * @param {Date} value
3948
+ * @returns {TinyElement|TinyElement[]}
3949
+ */
3950
+ static setDate(el, value) {
3951
+ if (!(value instanceof Date) || Number.isNaN(value.getTime()))
3952
+ throw new Error('Value is not a valid Date.');
3953
+ const data = value.toISOString();
3954
+ TinyHtml._preElems(el, 'setDate').forEach((el) => (el.textContent = data));
3955
+ return el;
3956
+ }
3957
+
3958
+ /**
3959
+ * Set Date content of the element.
3960
+ * @param {Date} value
3961
+ * @returns {TinyElement|TinyElement[]}
3962
+ */
3963
+ setDate(value) {
3964
+ return TinyHtml.setDate(this, value);
3965
+ }
3966
+
3967
+ /**
3968
+ * Returns the JSON content of the element.
3969
+ * @param {TinyElement} el - Target element.
3970
+ * @returns {any|null} The parsed JSON content or null if invalid.
3971
+ */
3972
+ static toJson(el) {
3973
+ const elem = TinyHtml._preElem(el, 'toJson');
3974
+ const txt = elem.textContent?.trim();
3975
+ if (!txt) return null;
3976
+ try {
3977
+ return JSON.parse(txt);
3978
+ } catch {
3979
+ return null;
3980
+ }
3981
+ }
3982
+
3983
+ /**
3984
+ * Returns the JSON content of the element.
3985
+ * @returns {any|null}
3986
+ */
3987
+ toJson() {
3988
+ return TinyHtml.toJson(this);
3989
+ }
3990
+
3991
+ /**
3992
+ * Set JSON content of elements.
3993
+ * @param {TinyElement|TinyElement[]} el
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.
3996
+ * @param {number|string} [space] - Indentation level or string for formatting.
3997
+ * @returns {TinyElement|TinyElement[]}
3998
+ */
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));
4002
+ return el;
4003
+ }
4004
+
4005
+ /**
4006
+ * Set JSON content of the element.
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.
4009
+ * @param {number|string} [space] - Indentation level or string for formatting.
4010
+ * @returns {TinyElement|TinyElement[]}
4011
+ */
4012
+ setJson(value, replacer, space) {
4013
+ return TinyHtml.setJson(this, value, replacer, space);
4014
+ }
4015
+
4016
+ /**
4017
+ * Returns the number content of the element.
4018
+ * @param {TinyElement} el - Target element.
4019
+ * @returns {number|null} The text content or null if none.
4020
+ */
4021
+ static toNumber(el) {
4022
+ const elem = TinyHtml._preElem(el, 'toNumber');
4023
+ return typeof elem.textContent === 'string' ? parseFloat(elem.textContent.trim()) : null;
4024
+ }
4025
+
4026
+ /**
4027
+ * Returns the number content of the element.
4028
+ * @returns {number|null} The text content or null if none.
4029
+ */
4030
+ toNumber() {
4031
+ return TinyHtml.toNumber(this);
4032
+ }
4033
+
4034
+ /**
4035
+ * Set number content of elements.
4036
+ * @param {TinyElement|TinyElement[]} el
4037
+ * @param {number} value
4038
+ * @returns {TinyElement|TinyElement[]}
4039
+ */
4040
+ static setNumber(el, value) {
4041
+ if (typeof value !== 'number') throw new Error('Value is not a valid number.');
4042
+ const data = value.toString();
4043
+ TinyHtml._preElems(el, 'setNumber').forEach((el) => (el.textContent = data));
4044
+ return el;
4045
+ }
4046
+
4047
+ /**
4048
+ * Set number content of the element.
4049
+ * @param {number} value
4050
+ * @returns {TinyElement|TinyElement[]}
4051
+ */
4052
+ setNumber(value) {
4053
+ return TinyHtml.setNumber(this, value);
4054
+ }
4055
+
3876
4056
  /**
3877
4057
  * Returns the text content of the element.
3878
4058
  * @param {TinyElement} el - Target element.
@@ -1481,6 +1481,60 @@ declare class TinyHtml {
1481
1481
  * @returns {string} The element's ID.
1482
1482
  */
1483
1483
  static id(el: TinyElement): string;
1484
+ /**
1485
+ * Returns the BigInt content of the element.
1486
+ * @param {TinyElement} el - Target element.
1487
+ * @returns {bigint|null} The BigInt content or null if none.
1488
+ */
1489
+ static toBigInt(el: TinyElement): bigint | null;
1490
+ /**
1491
+ * Set BigInt content of elements.
1492
+ * @param {TinyElement|TinyElement[]} el
1493
+ * @param {bigint} value
1494
+ * @returns {TinyElement|TinyElement[]}
1495
+ */
1496
+ static setBigInt(el: TinyElement | TinyElement[], value: bigint): TinyElement | TinyElement[];
1497
+ /**
1498
+ * Returns the Date content of the element.
1499
+ * @param {TinyElement} el - Target element.
1500
+ * @returns {Date|null} The Date content or null if invalid.
1501
+ */
1502
+ static toDate(el: TinyElement): Date | null;
1503
+ /**
1504
+ * Set Date content of elements.
1505
+ * @param {TinyElement|TinyElement[]} el
1506
+ * @param {Date} value
1507
+ * @returns {TinyElement|TinyElement[]}
1508
+ */
1509
+ static setDate(el: TinyElement | TinyElement[], value: Date): TinyElement | TinyElement[];
1510
+ /**
1511
+ * Returns the JSON content of the element.
1512
+ * @param {TinyElement} el - Target element.
1513
+ * @returns {any|null} The parsed JSON content or null if invalid.
1514
+ */
1515
+ static toJson(el: TinyElement): any | null;
1516
+ /**
1517
+ * Set JSON content of elements.
1518
+ * @param {TinyElement|TinyElement[]} el
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.
1521
+ * @param {number|string} [space] - Indentation level or string for formatting.
1522
+ * @returns {TinyElement|TinyElement[]}
1523
+ */
1524
+ static setJson(el: TinyElement | TinyElement[], value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): TinyElement | TinyElement[];
1525
+ /**
1526
+ * Returns the number content of the element.
1527
+ * @param {TinyElement} el - Target element.
1528
+ * @returns {number|null} The text content or null if none.
1529
+ */
1530
+ static toNumber(el: TinyElement): number | null;
1531
+ /**
1532
+ * Set number content of elements.
1533
+ * @param {TinyElement|TinyElement[]} el
1534
+ * @param {number} value
1535
+ * @returns {TinyElement|TinyElement[]}
1536
+ */
1537
+ static setNumber(el: TinyElement | TinyElement[], value: number): TinyElement | TinyElement[];
1484
1538
  /**
1485
1539
  * Returns the text content of the element.
1486
1540
  * @param {TinyElement} el - Target element.
@@ -2629,6 +2683,52 @@ declare class TinyHtml {
2629
2683
  * @returns {string} The element's ID.
2630
2684
  */
2631
2685
  id(): string;
2686
+ /**
2687
+ * Returns the BigInt content of the element.
2688
+ * @returns {bigint|null}
2689
+ */
2690
+ toBigInt(): bigint | null;
2691
+ /**
2692
+ * Set BigInt content of the element.
2693
+ * @param {bigint} value
2694
+ * @returns {TinyElement|TinyElement[]}
2695
+ */
2696
+ setBigInt(value: bigint): TinyElement | TinyElement[];
2697
+ /**
2698
+ * Returns the Date content of the element.
2699
+ * @returns {Date|null}
2700
+ */
2701
+ toDate(): Date | null;
2702
+ /**
2703
+ * Set Date content of the element.
2704
+ * @param {Date} value
2705
+ * @returns {TinyElement|TinyElement[]}
2706
+ */
2707
+ setDate(value: Date): TinyElement | TinyElement[];
2708
+ /**
2709
+ * Returns the JSON content of the element.
2710
+ * @returns {any|null}
2711
+ */
2712
+ toJson(): any | null;
2713
+ /**
2714
+ * Set JSON content of the element.
2715
+ * @param {any} value - A JavaScript value, usually an object or array, to be converted.
2716
+ * @param {(this: any, key: string, value: any) => any} [replacer] - A function that transforms the results.
2717
+ * @param {number|string} [space] - Indentation level or string for formatting.
2718
+ * @returns {TinyElement|TinyElement[]}
2719
+ */
2720
+ setJson(value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): TinyElement | TinyElement[];
2721
+ /**
2722
+ * Returns the number content of the element.
2723
+ * @returns {number|null} The text content or null if none.
2724
+ */
2725
+ toNumber(): number | null;
2726
+ /**
2727
+ * Set number content of the element.
2728
+ * @param {number} value
2729
+ * @returns {TinyElement|TinyElement[]}
2730
+ */
2731
+ setNumber(value: number): TinyElement | TinyElement[];
2632
2732
  /**
2633
2733
  * Returns the text content of the element.
2634
2734
  * @returns {string|null} The text content or null if none.
@@ -3466,6 +3466,176 @@ class TinyHtml {
3466
3466
  id() {
3467
3467
  return TinyHtml.id(this);
3468
3468
  }
3469
+ /**
3470
+ * Returns the BigInt content of the element.
3471
+ * @param {TinyElement} el - Target element.
3472
+ * @returns {bigint|null} The BigInt content or null if none.
3473
+ */
3474
+ static toBigInt(el) {
3475
+ const elem = TinyHtml._preElem(el, 'toBigInt');
3476
+ const txt = elem.textContent?.trim();
3477
+ let value = null;
3478
+ try {
3479
+ value = BigInt(txt ?? '');
3480
+ }
3481
+ catch {
3482
+ value = null;
3483
+ }
3484
+ return value;
3485
+ }
3486
+ /**
3487
+ * Returns the BigInt content of the element.
3488
+ * @returns {bigint|null}
3489
+ */
3490
+ toBigInt() {
3491
+ return TinyHtml.toBigInt(this);
3492
+ }
3493
+ /**
3494
+ * Set BigInt content of elements.
3495
+ * @param {TinyElement|TinyElement[]} el
3496
+ * @param {bigint} value
3497
+ * @returns {TinyElement|TinyElement[]}
3498
+ */
3499
+ static setBigInt(el, value) {
3500
+ if (typeof value !== 'bigint')
3501
+ throw new Error('Value is not a valid BigInt.');
3502
+ const data = value.toString();
3503
+ TinyHtml._preElems(el, 'setBigInt').forEach((el) => (el.textContent = data));
3504
+ return el;
3505
+ }
3506
+ /**
3507
+ * Set BigInt content of the element.
3508
+ * @param {bigint} value
3509
+ * @returns {TinyElement|TinyElement[]}
3510
+ */
3511
+ setBigInt(value) {
3512
+ return TinyHtml.setBigInt(this, value);
3513
+ }
3514
+ /**
3515
+ * Returns the Date content of the element.
3516
+ * @param {TinyElement} el - Target element.
3517
+ * @returns {Date|null} The Date content or null if invalid.
3518
+ */
3519
+ static toDate(el) {
3520
+ const elem = TinyHtml._preElem(el, 'toDate');
3521
+ const txt = elem.textContent?.trim();
3522
+ if (!txt)
3523
+ return null;
3524
+ const d = new Date(txt);
3525
+ return Number.isNaN(d.getTime()) ? null : d;
3526
+ }
3527
+ /**
3528
+ * Returns the Date content of the element.
3529
+ * @returns {Date|null}
3530
+ */
3531
+ toDate() {
3532
+ return TinyHtml.toDate(this);
3533
+ }
3534
+ /**
3535
+ * Set Date content of elements.
3536
+ * @param {TinyElement|TinyElement[]} el
3537
+ * @param {Date} value
3538
+ * @returns {TinyElement|TinyElement[]}
3539
+ */
3540
+ static setDate(el, value) {
3541
+ if (!(value instanceof Date) || Number.isNaN(value.getTime()))
3542
+ throw new Error('Value is not a valid Date.');
3543
+ const data = value.toISOString();
3544
+ TinyHtml._preElems(el, 'setDate').forEach((el) => (el.textContent = data));
3545
+ return el;
3546
+ }
3547
+ /**
3548
+ * Set Date content of the element.
3549
+ * @param {Date} value
3550
+ * @returns {TinyElement|TinyElement[]}
3551
+ */
3552
+ setDate(value) {
3553
+ return TinyHtml.setDate(this, value);
3554
+ }
3555
+ /**
3556
+ * Returns the JSON content of the element.
3557
+ * @param {TinyElement} el - Target element.
3558
+ * @returns {any|null} The parsed JSON content or null if invalid.
3559
+ */
3560
+ static toJson(el) {
3561
+ const elem = TinyHtml._preElem(el, 'toJson');
3562
+ const txt = elem.textContent?.trim();
3563
+ if (!txt)
3564
+ return null;
3565
+ try {
3566
+ return JSON.parse(txt);
3567
+ }
3568
+ catch {
3569
+ return null;
3570
+ }
3571
+ }
3572
+ /**
3573
+ * Returns the JSON content of the element.
3574
+ * @returns {any|null}
3575
+ */
3576
+ toJson() {
3577
+ return TinyHtml.toJson(this);
3578
+ }
3579
+ /**
3580
+ * Set JSON content of elements.
3581
+ * @param {TinyElement|TinyElement[]} el
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.
3584
+ * @param {number|string} [space] - Indentation level or string for formatting.
3585
+ * @returns {TinyElement|TinyElement[]}
3586
+ */
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));
3590
+ return el;
3591
+ }
3592
+ /**
3593
+ * Set JSON content of the element.
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.
3596
+ * @param {number|string} [space] - Indentation level or string for formatting.
3597
+ * @returns {TinyElement|TinyElement[]}
3598
+ */
3599
+ setJson(value, replacer, space) {
3600
+ return TinyHtml.setJson(this, value, replacer, space);
3601
+ }
3602
+ /**
3603
+ * Returns the number content of the element.
3604
+ * @param {TinyElement} el - Target element.
3605
+ * @returns {number|null} The text content or null if none.
3606
+ */
3607
+ static toNumber(el) {
3608
+ const elem = TinyHtml._preElem(el, 'toNumber');
3609
+ return typeof elem.textContent === 'string' ? parseFloat(elem.textContent.trim()) : null;
3610
+ }
3611
+ /**
3612
+ * Returns the number content of the element.
3613
+ * @returns {number|null} The text content or null if none.
3614
+ */
3615
+ toNumber() {
3616
+ return TinyHtml.toNumber(this);
3617
+ }
3618
+ /**
3619
+ * Set number content of elements.
3620
+ * @param {TinyElement|TinyElement[]} el
3621
+ * @param {number} value
3622
+ * @returns {TinyElement|TinyElement[]}
3623
+ */
3624
+ static setNumber(el, value) {
3625
+ if (typeof value !== 'number')
3626
+ throw new Error('Value is not a valid number.');
3627
+ const data = value.toString();
3628
+ TinyHtml._preElems(el, 'setNumber').forEach((el) => (el.textContent = data));
3629
+ return el;
3630
+ }
3631
+ /**
3632
+ * Set number content of the element.
3633
+ * @param {number} value
3634
+ * @returns {TinyElement|TinyElement[]}
3635
+ */
3636
+ setNumber(value) {
3637
+ return TinyHtml.setNumber(this, value);
3638
+ }
3469
3639
  /**
3470
3640
  * Returns the text content of the element.
3471
3641
  * @param {TinyElement} el - Target element.
@@ -1328,6 +1328,87 @@ element.id(); // → "my-element-id"
1328
1328
 
1329
1329
  ---
1330
1330
 
1331
+ ### 📝 `.toBigInt()` / `TinyHtml.toBigInt(el)`
1332
+
1333
+ Gets the **BigInt** content of the element (returns `null` if invalid or empty).
1334
+
1335
+ ```js
1336
+ element.toBigInt(); // → 123n
1337
+ ```
1338
+
1339
+ ---
1340
+
1341
+ ### ✍️ `.setBigInt(value)` / `TinyHtml.setBigInt(el, value)`
1342
+
1343
+ Sets the **BigInt** content of one or more elements. Throws if `value` is not a BigInt.
1344
+
1345
+ ```js
1346
+ element.setBigInt(456n);
1347
+ ```
1348
+
1349
+ ---
1350
+
1351
+ ### 📝 `.toDate()` / `TinyHtml.toDate(el)`
1352
+
1353
+ Gets the **Date** content of the element (returns `null` if invalid).
1354
+
1355
+ ```js
1356
+ element.toDate(); // → 2025-08-31T00:00:00.000Z
1357
+ ```
1358
+
1359
+ ---
1360
+
1361
+ ### ✍️ `.setDate(value)` / `TinyHtml.setDate(el, value)`
1362
+
1363
+ Sets the **Date** content of one or more elements. Throws if `value` is not a valid `Date`.
1364
+
1365
+ ```js
1366
+ element.setDate(new Date("2025-08-31T00:00:00Z"));
1367
+ ```
1368
+
1369
+ ---
1370
+
1371
+ ### 📝 `.toJson()` / `TinyHtml.toJson(el)`
1372
+
1373
+ Gets the **JSON** content of the element (returns `null` if invalid or empty).
1374
+
1375
+ ```js
1376
+ element.toJson(); // → { a: 1, b: 2 }
1377
+ ```
1378
+
1379
+ ---
1380
+
1381
+ ### ✍️ `.setJson(value, replacer, space)` / `TinyHtml.setJson(el, value, replacer, space)`
1382
+
1383
+ Sets the **JSON** content of one or more elements.
1384
+
1385
+ ```js
1386
+ element.setJson({ a: 1, b: 2 }); // minified
1387
+ element.setJson({ a: 1, b: 2 }, null, 2); // 2-space indentation
1388
+ ```
1389
+
1390
+ ---
1391
+
1392
+ ### 📝 `.toNumber()` / `TinyHtml.toNumber(el)`
1393
+
1394
+ Gets the **number** content of the element (returns `null` if invalid or empty).
1395
+
1396
+ ```js
1397
+ element.toNumber(); // → 42
1398
+ ```
1399
+
1400
+ ---
1401
+
1402
+ ### ✍️ `.setNumber(value)` / `TinyHtml.setNumber(el, value)`
1403
+
1404
+ Sets the **number** content of one or more elements. Throws if `value` is not a number.
1405
+
1406
+ ```js
1407
+ element.setNumber(99);
1408
+ ```
1409
+
1410
+ ---
1411
+
1331
1412
  ### 📝 `.text()` / `TinyHtml.text(el)`
1332
1413
 
1333
1414
  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.4",
3
+ "version": "1.21.6",
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",