@cntwg/xml-lib-js 0.0.33 → 0.0.34

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 CHANGED
@@ -1,3 +1,15 @@
1
+ #### *v0.0.34*
2
+
3
+ Pre-release version.
4
+
5
+ > - update `xmldoc-lib.md`;
6
+ > - update dependency on `@ygracs/xobj-lib-js` module to v0.2.3;
7
+ > - (`TXmlElementController`) remove methods: `_getChildRaw`, `_addChildRaw`< `_setChildRaw`;
8
+ > - (`TXmlElementsListController`) add special static method: `__getItemRaw`;
9
+ > - (`TXmlElementsListController`) add special static method: `__setItemRaw`;
10
+ > - (`TXmlElementsListController`) deprecate methods: `_getItemRaw`, `_setItemRaw`;
11
+ > - (`TXmlElementsListController`) add iterator method;
12
+
1
13
  #### *v0.0.33*
2
14
 
3
15
  Pre-release version.
package/doc/xmldoc-lib.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.37|
1
+ >|***rev.*:**|0.1.40|
2
2
  >|:---|---:|
3
- >|date:|2025-02-06|
3
+ >|date:|2025-07-19|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -409,20 +409,6 @@ This method loads an element content from a string given by a `str` parameter.
409
409
 
410
410
  This methods throws `Error` if something goes wrong through a parsing process of a string.
411
411
 
412
- #### class methods (*special*)
413
-
414
- ##### **_getChildRaw(name)** => `?any`
415
-
416
- > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__getChildRaw` method of the class*).
417
-
418
- ##### **_addChildRaw(name)** => `?object`
419
-
420
- > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__addChildRaw` method of the class*).
421
-
422
- ##### **_setChildRaw(name, obj)** => `boolean`
423
-
424
- > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__setChildRaw` method of the class*).
425
-
426
412
  #### class methods (*static*)
427
413
 
428
414
  ##### **clear(item)** => `void`
@@ -455,6 +441,8 @@ This method adds an element addressed by `name` as a child element.
455
441
 
456
442
  ##### **__setChildRaw(node, name, obj)** => `boolean`
457
443
 
444
+ > since: \[`v0.0.31`]
445
+
458
446
  This method inserts a given object as a child element addressed by `name`.
459
447
 
460
448
  <a name="TXmlElementsListController"></a>
@@ -619,7 +607,9 @@ The `options` structure is listed below:
619
607
 
620
608
  #### class methods (*special*)
621
609
 
622
- ##### **_getItemRaw(name)**
610
+ ##### **_getItemRaw(index)**
611
+
612
+ > WARNING: \[since `v0.0.34`] this method deprecated (*use `__getItemRaw`, a static method of the class, instead*).
623
613
 
624
614
  This method returns an element addressed by `index` as object. If failed `null` is returned.
625
615
 
@@ -629,12 +619,30 @@ This method adds an element to a list members as object. If succeed an index of
629
619
 
630
620
  ##### **_setItemRaw(index, obj)**
631
621
 
622
+ > WARNING: \[since `v0.0.34`] this method deprecated (*use `__setItemRaw`, a static method of the class, instead*).
623
+
632
624
  This method replaces an element addressed by `index` with a new element which is saved as raw object. If succeed `true` is returned.
633
625
 
634
626
  ##### **_insItemRaw(index, obj)**
635
627
 
636
628
  This method inserts an element as a raw object in the position addressed by `index`. If succeed `true` is returned.
637
629
 
630
+ #### class methods (*static, special*)
631
+
632
+ <a name="TXmlElementsListController.__getItemRaw"></a>
633
+ ##### **__getItemRaw(node, index)** => `?any`
634
+
635
+ > since: \[`v0.0.34`]
636
+
637
+ This method returns an element addressed by `index` as object. If failed `null` is returned.
638
+
639
+ <a name="TXmlElementsListController.__setItemRaw"></a>
640
+ ##### **__setItemRaw(node, index, item)** => `?any`
641
+
642
+ > since: \[`v0.0.34`]
643
+
644
+ This method replaces an element addressed by `index` with a new element which is saved as raw object. If succeed `true` is returned.
645
+
638
646
  <a name="TXmlContentDeclaration"></a>
639
647
  ### **TXmlContentDeclaration**
640
648
 
package/lib/xmldoc-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.2.111-20250415]
1
+ // [v0.2.117-20250719]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -28,19 +28,19 @@ const {
28
28
  // === module extra block (helper functions) ===
29
29
 
30
30
  /**
31
+ * An XML-element controller settings.
31
32
  * @typedef {Object} OPT_xmlelemsett
32
33
  * @property {TXmlContentParseOptions} [parseOptions] - parser options
33
34
  * @property {boolean} [proxyModeEnable=false] - mode flag
34
35
  * @property {boolean} [isNullItemsAllowed=false] - <reserved>
35
- * @description An XML-element controller settings.
36
36
  */
37
37
 
38
38
  /**
39
+ * Evaluates an XML-element settings
39
40
  * @function __evalXMLElementSettings
40
41
  * @param {any} value - element settings to evaluate
41
42
  * @returns {OPT_xmlelemsett}
42
43
  * @inner
43
- * @description Evaluates an XML-element settings
44
44
  */
45
45
  function __evalXMLElementSettings(value) {
46
46
  /** @type {OPT_xmlelemsett} */
@@ -59,22 +59,22 @@ function __evalXMLElementSettings(value) {
59
59
  };
60
60
 
61
61
  /**
62
+ * An XML-content container settings.
62
63
  * @typedef {Object} OPT_xmlcontsett
63
64
  * @property {TXmlContentParseOptions} [parseOptions] - parser options
64
65
  * @property {boolean} [proxyModeEnable=false] - mode flag
65
66
  * @property {boolean} [isNullItemsAllowed=false] - <reserved>
66
67
  * @property {string} [rootETagName] - tag name of the root element
67
68
  * @property {boolean} [autoBindRoot=true] - mode flag
68
- * @description An XML-content container settings.
69
69
  * @see OPT_xmlelemsett
70
70
  */
71
71
 
72
72
  /**
73
+ * Evaluates an XML-container settings
73
74
  * @function __evalXMLContainerSettings
74
75
  * @param {any} value - container settings to evaluate
75
76
  * @returns {OPT_xmlcontsett}
76
77
  * @inner
77
- * @description Evaluates an XML-container settings
78
78
  */
79
79
  function __evalXMLContainerSettings(value) {
80
80
  /** @type {OPT_xmlcontsett} */
@@ -110,12 +110,11 @@ const XML_TE_NROOT_EMSG = 'root element not found';
110
110
  */
111
111
 
112
112
  /**
113
+ * Tries to convert a given value to a valid tag name of an XML-element.
113
114
  * @since v0.0.28
114
115
  * @function readAsTagName
115
116
  * @param {any} value - some value
116
117
  * @returns {string}
117
- * @description Tries to convert a given value to a valid tag name
118
- * of an XML-element.
119
118
  */
120
119
  function readAsTagName(value) {
121
120
  let tagName = valueToIDString(value, { ignoreNumbers: true });
@@ -133,12 +132,11 @@ function readAsTagName(value) {
133
132
  };
134
133
 
135
134
  /**
135
+ * Tries to convert a given value to a valid name of an XML-attribute.
136
136
  * @since v0.0.28
137
137
  * @function readAsAttrName
138
138
  * @param {any} value - some value
139
139
  * @returns {string}
140
- * @description Tries to convert a given value to a valid name
141
- * of an XML-attribute.
142
140
  */
143
141
  function readAsAttrName(value) {
144
142
  let attrName = valueToIDString(value, { ignoreNumbers: true });
@@ -156,12 +154,12 @@ function readAsAttrName(value) {
156
154
  };
157
155
 
158
156
  /**
157
+ * Tries to convert a given value to a valid identifier
158
+ * suitable as a value for an "ID-attribute" of an XML-element.
159
159
  * @since v0.0.28
160
160
  * @function valueToElementID
161
161
  * @param {any} value - some value
162
162
  * @returns {string}
163
- * @description Tries to convert a given value to a valid identifier
164
- * suitable as a value for an "ID-attribute" of an XML-element.
165
163
  */
166
164
  function valueToElementID(value) {
167
165
  let id = valueToIDString(value);
@@ -192,13 +190,12 @@ class TXmlAttributesMapper {
192
190
  #_options;
193
191
 
194
192
  /**
193
+ * Creates an attributes mapper instance
195
194
  * @param {object} obj - some object
196
195
  * @param {OPT_xmlelemsett} [opt] - options
197
196
  * @throws {TypeError}
198
- * @description Creates an attributes mapper instance
199
197
  */
200
198
  constructor(obj, opt) {
201
- // init an elements content
202
199
  if (!isPlainObject(obj)) throw new TypeError(XML_TE_NOBJ_EMSG);
203
200
  this.#_host = obj;
204
201
  // load options
@@ -231,9 +228,9 @@ class TXmlAttributesMapper {
231
228
  }
232
229
 
233
230
  /**
231
+ * Checks whether an attribute exists.
234
232
  * @param {string} name - attribute name
235
233
  * @returns {boolean}
236
- * @description Checks whether an attribute exists.
237
234
  */
238
235
  hasAttribute(name) {
239
236
  let result = false;
@@ -251,9 +248,9 @@ class TXmlAttributesMapper {
251
248
  }
252
249
 
253
250
  /**
251
+ * Returns an attribute value.
254
252
  * @param {string} name - attribute name
255
253
  * @returns {string}
256
- * @description Returns an attribute value.
257
254
  */
258
255
  getAttribute(name) {
259
256
  let result = '';
@@ -271,10 +268,10 @@ class TXmlAttributesMapper {
271
268
  }
272
269
 
273
270
  /**
271
+ * Sets an attribute value.
274
272
  * @param {string} name - attribute name
275
273
  * @param {any} value - some value
276
274
  * @returns {boolean}
277
- * @description Sets an attribute value.
278
275
  */
279
276
  setAttribute(name, value) {
280
277
  const attrName = readAsAttrName(name);
@@ -296,9 +293,9 @@ class TXmlAttributesMapper {
296
293
  }
297
294
 
298
295
  /**
296
+ * Deletes an attribute.
299
297
  * @param {string} name - attribute name
300
298
  * @returns {boolean}
301
- * @description Deletes an attribute.
302
299
  */
303
300
  delAttribute(name) {
304
301
  let result = false;
@@ -316,11 +313,11 @@ class TXmlAttributesMapper {
316
313
  }
317
314
 
318
315
  /**
316
+ * Renames an attribute.
319
317
  * @since v0.0.30
320
318
  * @param {string} name - attribute name
321
319
  * @param {string} value - new name
322
320
  * @returns {boolean}
323
- * @description Renames an attribute.
324
321
  */
325
322
  renameAttribute(name, value) {
326
323
  const newName = readAsAttrName(value);
@@ -342,8 +339,8 @@ class TXmlAttributesMapper {
342
339
  }
343
340
 
344
341
  /**
342
+ * Deletes all attributes.
345
343
  * @returns {void}
346
- * @description Deletes all attributes.
347
344
  */
348
345
  clear() {
349
346
  insertXObjElement(
@@ -373,10 +370,10 @@ class TXmlElementController {
373
370
  #_name = null;
374
371
 
375
372
  /**
373
+ * Creates an instance of an element controller
376
374
  * @param {object} obj - some element
377
375
  * @param {OPT_xmlelemsett} [opt] - options
378
376
  * @throws {TypeError}
379
- * @description Creates an instance of an element controller
380
377
  */
381
378
  constructor(obj, opt) {
382
379
  // load options
@@ -445,9 +442,9 @@ class TXmlElementController {
445
442
  }
446
443
 
447
444
  /**
445
+ * Checks whether an attribute exists.
448
446
  * @param {string} name - attribute name
449
447
  * @returns {boolean}
450
- * @description Checks whether an attribute exists.
451
448
  * @see TXmlAttributesMapper.hasAttribute
452
449
  */
453
450
  hasAttribute(name) {
@@ -455,9 +452,9 @@ class TXmlElementController {
455
452
  }
456
453
 
457
454
  /**
455
+ * Returns an attribute value.
458
456
  * @param {string} name - attribute name
459
457
  * @returns {string}
460
- * @description Returns an attribute value.
461
458
  * @see TXmlAttributesMapper.getAttribute
462
459
  */
463
460
  getAttribute(name) {
@@ -465,10 +462,10 @@ class TXmlElementController {
465
462
  }
466
463
 
467
464
  /**
465
+ * Sets an attribute value.
468
466
  * @param {string} name - attribute name
469
467
  * @param {any} value - some value
470
468
  * @returns {boolean}
471
- * @description Sets an attribute value.
472
469
  * @see TXmlAttributesMapper.setAttribute
473
470
  */
474
471
  setAttribute(...args) {
@@ -476,9 +473,9 @@ class TXmlElementController {
476
473
  }
477
474
 
478
475
  /**
476
+ * Deletes an attribute.
479
477
  * @param {string} name - attribute name
480
478
  * @returns {boolean}
481
- * @description Deletes an attribute.
482
479
  * @see TXmlAttributesMapper.delAttribute
483
480
  */
484
481
  delAttribute(name) {
@@ -486,11 +483,11 @@ class TXmlElementController {
486
483
  }
487
484
 
488
485
  /**
486
+ * Renames an attribute.
489
487
  * @since v0.0.30
490
488
  * @param {string} name - attribute name
491
489
  * @param {string} value - new attribute name
492
490
  * @returns {boolean}
493
- * @description Renames an attribute.
494
491
  * @see TXmlAttributesMapper.renameAttribute
495
492
  */
496
493
  renameAttribute(...args) {
@@ -498,8 +495,8 @@ class TXmlElementController {
498
495
  }
499
496
 
500
497
  /**
498
+ * Returns a text value in format of a `[ <lang>, <text> ]` pair.
501
499
  * @returns {string[]}
502
- * @description Returns a text value in format of a `[ <lang>, <text> ]` pair.
503
500
  */
504
501
  getTextValue() {
505
502
  return [
@@ -509,9 +506,9 @@ class TXmlElementController {
509
506
  }
510
507
 
511
508
  /**
509
+ * Sets a text value.
512
510
  * @param {(string|string[])} value - some text
513
511
  * @returns {boolean}
514
- * @description Sets a text value.
515
512
  */
516
513
  setTextValue(value) {
517
514
  const _value = valueToEntry(value);
@@ -538,9 +535,9 @@ class TXmlElementController {
538
535
  }
539
536
 
540
537
  /**
538
+ * Checks whether an element has a child element.
541
539
  * @param {string} name - some child element name
542
540
  * @returns {boolean}
543
- * @description Checks whether an element has a child element.
544
541
  */
545
542
  hasChild(name) {
546
543
  const _name = evalXObjEName(name);
@@ -557,9 +554,9 @@ class TXmlElementController {
557
554
  }
558
555
 
559
556
  /**
557
+ * Returns a child element.
560
558
  * @param {string} name - some child element name
561
559
  * @returns {?(TXmlElementController|TXmlElementsListController)}
562
- * @description Returns a child element.
563
560
  */
564
561
  getChild(name) {
565
562
  const _name = evalXObjEName(name);
@@ -577,49 +574,9 @@ class TXmlElementController {
577
574
  }
578
575
 
579
576
  /**
580
- * @param {string} name
581
- * @returns {?any}
582
- * @protected
583
- * @deprecated
584
- * @description Returns a child element.
585
- * @see TXmlElementController.__getChildRaw
586
- */
587
- _getChildRaw(name) {
588
- //console.log('CHECK: TXmlElementController._getChildRaw() => was called...');
589
- return TXmlElementController.__getChildRaw(this, name);
590
- }
591
-
592
- /**
593
- * @param {string} name
594
- * @param {object} obj
595
- * @returns {boolean}
596
- * @protected
597
- * @deprecated
598
- * @description Sets a child element.
599
- * @see TXmlElementController.__setChildRaw
600
- */
601
- _setChildRaw(...args) {
602
- //console.log('CHECK: TXmlElementController._setChildRaw() => was called...');
603
- return TXmlElementController.__setChildRaw(this, ...args);
604
- }
605
-
606
- /**
607
- * @param {string} name
608
- * @returns {?Object}
609
- * @protected
610
- * @deprecated
611
- * @description Adds a new child element.
612
- * @see TXmlElementController.__addChildRaw
613
- */
614
- _addChildRaw(name) {
615
- //console.log('CHECK: TXmlElementController._addChild() => was called...');
616
- return TXmlElementController.__addChildRaw(this, name);
617
- }
618
-
619
- /**
577
+ * Adds a new child element.
620
578
  * @param {string} name - some child element name
621
579
  * @returns {?TXmlElementController}
622
- * @description Adds a new child element.
623
580
  */
624
581
  addChild(name) {
625
582
  const _name = evalXObjEName(name);
@@ -637,9 +594,9 @@ class TXmlElementController {
637
594
  }
638
595
 
639
596
  /**
597
+ * Deletes a child element.
640
598
  * @param {string} name - some child element name
641
599
  * @returns {boolean}
642
- * @description Deletes a child element.
643
600
  */
644
601
  delChild(name) {
645
602
  const _name = evalXObjEName(name);
@@ -670,20 +627,20 @@ class TXmlElementController {
670
627
  }
671
628
 
672
629
  /**
630
+ * Deletes all child elements and attributes.
673
631
  * @returns {void}
674
- * @description Deletes all child elements and attributes.
675
632
  */
676
633
  clear() {
677
634
  TXmlElementController.clear(this);
678
635
  }
679
636
 
680
637
  /**
638
+ * Loads a element content from a string.
681
639
  * @since v0.0.30
682
640
  * @param {string} xmlString - some content
683
641
  * @returns {boolean}
684
642
  * @throws {Error}
685
643
  * @experimental
686
- * @description Loads a element content from a string.
687
644
  */
688
645
  loadFromXMLString(xmlString) {
689
646
  let result = false;
@@ -728,24 +685,24 @@ class TXmlElementController {
728
685
  }
729
686
 
730
687
  /**
688
+ * Tries to unwraps a given object.
731
689
  * @param {object} item
732
690
  * @returns {?object}
733
691
  * @protected
734
692
  * @static
735
- * @description Tries to unwraps a given object.
736
693
  */
737
694
  static __unwrap(item) {
738
695
  return (item instanceof TXmlElementController) ? item.#_host : null;
739
696
  }
740
697
 
741
698
  /**
699
+ * Returns a child element.
742
700
  * @since v0.0.31
743
- * @param {TXmlElementController} node
744
- * @param {string} name
701
+ * @param {TXmlElementController} node - some element
702
+ * @param {string} name - child element name
745
703
  * @returns {?any}
746
704
  * @protected
747
705
  * @static
748
- * @description Returns a child element.
749
706
  */
750
707
  static __getChildRaw(node, name) {
751
708
  let item = null;
@@ -763,13 +720,13 @@ class TXmlElementController {
763
720
  }
764
721
 
765
722
  /**
723
+ * Adds a new child element.
766
724
  * @since v0.0.31
767
- * @param {TXmlElementController} node
768
- * @param {string} name
725
+ * @param {TXmlElementController} node - some element
726
+ * @param {string} name - child element name
769
727
  * @returns {?Object}
770
728
  * @protected
771
729
  * @static
772
- * @description Adds a new child element.
773
730
  */
774
731
  static __addChildRaw(node, name) {
775
732
  const childName = readAsTagName(name);
@@ -790,13 +747,13 @@ class TXmlElementController {
790
747
  }
791
748
 
792
749
  /**
793
- * @param {TXmlElementController} node
794
- * @param {string} name
795
- * @param {object} obj
750
+ * Sets a child element.
751
+ * @param {TXmlElementController} node - some element
752
+ * @param {string} name - child element name
753
+ * @param {object} obj - raw child element
796
754
  * @returns {boolean}
797
755
  * @protected
798
756
  * @static
799
- * @description Sets a child element.
800
757
  */
801
758
  static __setChildRaw(node, name, obj) {
802
759
  const childName = readAsTagName(name);
@@ -813,10 +770,10 @@ class TXmlElementController {
813
770
  }
814
771
 
815
772
  /**
773
+ * Tries to clean a given object.
816
774
  * @param {object} obj
817
775
  * @returns {void}
818
776
  * @static
819
- * @description Tries to clean a given object.
820
777
  */
821
778
  static clear(obj) {
822
779
  let item = TXmlElementController.__unwrap(obj);
@@ -829,12 +786,12 @@ class TXmlElementController {
829
786
  }
830
787
 
831
788
  /**
789
+ * Creates new controller element.
832
790
  * @since v0.0.30
833
791
  * @param {object} obj - some object
834
792
  * @param {object} [opt] - options
835
793
  * @returns {?(TXmlElementController|TXmlElementsListController)}
836
794
  * @static
837
- * @description Creates new controller element.
838
795
  */
839
796
  static create(obj, opt) {
840
797
  let result = null;
@@ -866,10 +823,10 @@ class TXmlElementsListController {
866
823
  #_count = null;
867
824
 
868
825
  /**
826
+ * Creates an instance of a list controller
869
827
  * @param {object[]} obj - elements list
870
828
  * @param {OPT_xmlelemsett} [opt] - options
871
829
  * @throws {TypeError}
872
- * @description Creates an instance of a list controller
873
830
  */
874
831
  constructor(obj, opt) {
875
832
  // load options
@@ -894,6 +851,22 @@ class TXmlElementsListController {
894
851
  this.#_options = _options;
895
852
  }
896
853
 
854
+ [Symbol.iterator]() {
855
+ let index = 0;
856
+ return {
857
+ next: () => {
858
+ if (index < this.count) {
859
+ return { done: false, value: this.getItem(index++) };
860
+ } else {
861
+ return { done: true, value: undefined };
862
+ };
863
+ },
864
+ return() {
865
+ return { done: true, value: undefined };
866
+ },
867
+ };
868
+ }
869
+
897
870
  /**
898
871
  * Contains a quantity of an elements
899
872
  * @type {number}
@@ -931,34 +904,34 @@ class TXmlElementsListController {
931
904
  }
932
905
 
933
906
  /**
907
+ * Deletes all child elements and attributes.
934
908
  * @returns {void}
935
- * @description Deletes all child elements and attributes.
936
909
  */
937
910
  clear() {
938
911
  this.#_host.length = 0;
939
912
  }
940
913
 
941
914
  /**
915
+ * Checks whether an instance holds none element.
942
916
  * @returns {boolean}
943
- * @description Checks whether an instance holds none element.
944
917
  */
945
918
  isEmpty() {
946
919
  return this.count === 0;
947
920
  }
948
921
 
949
922
  /**
923
+ * Checks whether an instance holds at least one element.
950
924
  * @returns {boolean}
951
- * @description Checks whether an instance holds at least one element.
952
925
  */
953
926
  isNotEmpty() {
954
927
  return this.count > 0;
955
928
  }
956
929
 
957
930
  /**
931
+ * Checks whether a given value is a valid index value
932
+ * and it is not exceeds an index range within the instance.
958
933
  * @param {(number|string)} value - some index
959
934
  * @returns {boolean}
960
- * @description Checks whether a given value is a valid index value
961
- * and it is not exceeds an index range within the instance.
962
935
  */
963
936
  chkIndex(value) {
964
937
  const index = valueToIndex(value);
@@ -966,9 +939,9 @@ class TXmlElementsListController {
966
939
  }
967
940
 
968
941
  /**
942
+ * Checks whether or not a given element is valid.
969
943
  * @param {any} obj - some element
970
944
  * @returns {boolean}
971
- * @description Checks whether or not a given element is valid.
972
945
  */
973
946
  isValidItem(obj) {
974
947
  return (
@@ -978,20 +951,22 @@ class TXmlElementsListController {
978
951
  }
979
952
 
980
953
  /**
981
- * @param {number} index
954
+ * Returns an element.
955
+ * @param {(number|string)} index - element index
982
956
  * @returns {?object}
983
957
  * @protected
984
- * @description Returns an element.
958
+ * @deprecated
959
+ * @todo \[since `v0.0.34`] deprecated and will be removed later, consider
960
+ * to use `TXmlElementsListController.__getItemRaw` instead.
985
961
  */
986
962
  _getItemRaw(index) {
987
- let item = this.#_host[valueToIndex(index)];
988
- return item !== undefined ? item : null;
963
+ return TXmlElementsListController.__getItemRaw(this, index);
989
964
  }
990
965
 
991
966
  /**
992
- * @param {number} index - element index
967
+ * Returns an element.
968
+ * @param {(number|string)} index - element index
993
969
  * @returns {?TXmlElementController}
994
- * @description Returns an element.
995
970
  */
996
971
  getItem(index) {
997
972
  let item = this.#_host[valueToIndex(index)];
@@ -1004,10 +979,10 @@ class TXmlElementsListController {
1004
979
  }
1005
980
 
1006
981
  /**
982
+ * Adds a new element.
1007
983
  * @param {any} item
1008
984
  * @returns {number}
1009
985
  * @protected
1010
- * @description Adds a new element.
1011
986
  */
1012
987
  _addItemRaw(item) {
1013
988
  let index = -1;
@@ -1019,9 +994,9 @@ class TXmlElementsListController {
1019
994
  }
1020
995
 
1021
996
  /**
997
+ * Adds a new element.
1022
998
  * @param {any} item - some element
1023
999
  * @returns {number}
1024
- * @description Adds a new element.
1025
1000
  */
1026
1001
  addItem(item) {
1027
1002
  // unwrap item from container
@@ -1032,38 +1007,39 @@ class TXmlElementsListController {
1032
1007
  }
1033
1008
 
1034
1009
  /**
1035
- * @param {number} index
1010
+ * Sets a new element.
1011
+ * @param {(number|string)} index - element index
1036
1012
  * @param {any} item
1037
1013
  * @returns {boolean}
1038
1014
  * @protected
1039
- * @description Sets a new element.
1015
+ * @deprecated
1016
+ * @todo \[since `v0.0.34`] deprecated and will be removed later, consider
1017
+ * to use `TXmlElementsListController.__setItemRaw` instead.
1040
1018
  */
1041
1019
  _setItemRaw(index, item) {
1042
- let isSUCCEED = this.chkIndex(index) && this.isValidItem(item);
1043
- if (isSUCCEED) this.#_host[Number(index)] = item; // // TODO: correct count
1044
- return isSUCCEED;
1020
+ return TXmlElementsListController.__setItemRaw(this, index, item);
1045
1021
  }
1046
1022
 
1047
1023
  /**
1048
- * @param {string} index - element index
1024
+ * Sets a new element.
1025
+ * @param {(number|string)} index - element index
1049
1026
  * @param {any} item - some element
1050
1027
  * @returns {boolean}
1051
- * @description Sets a new element.
1052
1028
  */
1053
1029
  setItem(index, item) {
1054
1030
  // unwrap item from container
1055
1031
  if (item instanceof TXmlElementController) {
1056
1032
  item = TXmlElementController.__unwrap(item);
1057
1033
  };
1058
- return this._setItemRaw(index, item);
1034
+ return TXmlElementsListController.__setItemRaw(this, index, item);
1059
1035
  }
1060
1036
 
1061
1037
  /**
1062
- * @param {number} index
1038
+ * Insertes a new element.
1039
+ * @param {(number|string)} index - element index
1063
1040
  * @param {any} item
1064
1041
  * @returns {boolean}
1065
1042
  * @protected
1066
- * @description Insertes a new element.
1067
1043
  */
1068
1044
  _insItemRaw(index, item) {
1069
1045
  index = valueToIndex(index);
@@ -1086,10 +1062,10 @@ class TXmlElementsListController {
1086
1062
  }
1087
1063
 
1088
1064
  /**
1089
- * @param {number} index - element index
1065
+ * Insertes a new element.
1066
+ * @param {(number|string)} index - element index
1090
1067
  * @param {any} item - some element
1091
1068
  * @returns {boolean}
1092
- * @description Insertes a new element.
1093
1069
  */
1094
1070
  insItem(index, item) {
1095
1071
  // unwrap item from container
@@ -1100,9 +1076,9 @@ class TXmlElementsListController {
1100
1076
  }
1101
1077
 
1102
1078
  /**
1103
- * @param {number} index - element index
1079
+ * Deletes an element.
1080
+ * @param {(number|string)} value - element index
1104
1081
  * @returns {boolean}
1105
- * @description Deletes an element.
1106
1082
  */
1107
1083
  delItem(value) {
1108
1084
  let isSUCCEED = this.chkIndex(value);
@@ -1124,16 +1100,16 @@ class TXmlElementsListController {
1124
1100
  }
1125
1101
 
1126
1102
  /**
1103
+ * Settings for the list load ops
1127
1104
  * @typedef {Object} OPT_ELC_loaditems
1128
1105
  * @property {boolean} [useClear=true] - indicates whether to clear the list before load
1129
- * @description A settings for the list load ops
1130
1106
  */
1131
1107
 
1132
1108
  /**
1109
+ * Loads a list of an elements.
1133
1110
  * @param {any} items - element or a list of an elements
1134
1111
  * @param {OPT_ELC_loaditems} [opt]
1135
1112
  * @returns {number}
1136
- * @description Loads a list of an elements.
1137
1113
  */
1138
1114
  loadItems(items, opt) {
1139
1115
  const _options = isPlainObject(opt) ? opt : {};
@@ -1147,6 +1123,47 @@ class TXmlElementsListController {
1147
1123
  return this.count - count;
1148
1124
  }
1149
1125
 
1126
+ /**
1127
+ * Returns an element.
1128
+ * @since v0.0.34
1129
+ * @param {TXmlElementsListController} node - some element
1130
+ * @param {(number|string)} index - element index
1131
+ * @returns {?object}
1132
+ * @protected
1133
+ * @static
1134
+ */
1135
+ static __getItemRaw(node, index) {
1136
+ let item = null;
1137
+ if (node instanceof TXmlElementsListController) {
1138
+ item = node.#_host[valueToIndex(index)];
1139
+ if (item === undefined) item = null;
1140
+ };
1141
+ return item;
1142
+ }
1143
+
1144
+ /**
1145
+ * Sets a new element.
1146
+ * @since v0.0.34
1147
+ * @param {TXmlElementsListController} node - some element
1148
+ * @param {(number|string)} index - element index
1149
+ * @param {any} item - new element
1150
+ * @returns {boolean}
1151
+ * @protected
1152
+ * @static
1153
+ */
1154
+ static __setItemRaw(node, index, item) {
1155
+ let isSucceed = false;
1156
+ if (
1157
+ node instanceof TXmlElementsListController
1158
+ && node.chkIndex(index)
1159
+ && node.isValidItem(item)
1160
+ ) {
1161
+ node.#_host[Number(index)] = item; // // TODO: correct count
1162
+ isSucceed = true;
1163
+ };
1164
+ return isSucceed;
1165
+ }
1166
+
1150
1167
  };
1151
1168
 
1152
1169
  /**
@@ -1162,13 +1179,12 @@ class TXmlContentDeclaration {
1162
1179
  #_ctrls;
1163
1180
 
1164
1181
  /**
1182
+ * Creates an instance of the element
1165
1183
  * @param {object} obj - some object
1166
1184
  * @param {OPT_xmlcontsett} [opt] - options
1167
1185
  * @throws {TypeError}
1168
- * @description Creates an instance of the element
1169
1186
  */
1170
1187
  constructor(obj, opt) {
1171
- // check <obj>-param
1172
1188
  if (!isPlainObject(obj)) {
1173
1189
  throw new TypeError(`TXmlContentDeclaration : ${XML_TE_NOBJ_EMSG}`);
1174
1190
  };
@@ -1219,8 +1235,8 @@ class TXmlContentDeclaration {
1219
1235
  }
1220
1236
 
1221
1237
  /**
1238
+ * Initializes an instance content.
1222
1239
  * @returns {boolean}
1223
- * @description Initializes an instance content.
1224
1240
  */
1225
1241
  init() {
1226
1242
  const _options = this.#_options;
@@ -1240,7 +1256,7 @@ class TXmlContentDeclaration {
1240
1256
 
1241
1257
  /**
1242
1258
  * @augments TXmlElementController
1243
- * @description This class implements an instance of a root element
1259
+ * @classdesc This class implements an instance of a root element
1244
1260
  */
1245
1261
  class TXmlContentRootElement extends TXmlElementController {
1246
1262
  /** @type {?object} */
@@ -1249,12 +1265,12 @@ class TXmlContentRootElement extends TXmlElementController {
1249
1265
  #_options;
1250
1266
 
1251
1267
  /**
1268
+ * Creates an instance of a root element.
1252
1269
  * @param {object} obj - some object
1253
1270
  * @param {OPT_xmlcontsett} [opt] - options
1254
1271
  * @throws {TypeError}
1255
1272
  */
1256
1273
  constructor(obj, opt) {
1257
- // check <obj>-param
1258
1274
  if (!isPlainObject(obj)) {
1259
1275
  throw new TypeError(`TXmlContentRootElement : ${XML_TE_NOBJ_EMSG}`);
1260
1276
  };
@@ -1269,28 +1285,7 @@ class TXmlContentRootElement extends TXmlElementController {
1269
1285
  if (len === 0) {
1270
1286
  rootItem = insertXObjElement(obj, rootETagName);
1271
1287
  } else {
1272
- const {
1273
- declarationKey,
1274
- attributesKey,
1275
- textKey,
1276
- commentKey,
1277
- cdataKey,
1278
- nameKey,
1279
- typeKey,
1280
- parentKey,
1281
- elementsKey,
1282
- } = parseOptions.settings;
1283
- const reservedKeys = new Set([
1284
- declarationKey,
1285
- attributesKey,
1286
- textKey,
1287
- commentKey,
1288
- cdataKey,
1289
- nameKey,
1290
- typeKey,
1291
- parentKey,
1292
- elementsKey,
1293
- ]);
1288
+ const reservedKeys = parseOptions.reservedKeys;
1294
1289
  let targetKey = '';
1295
1290
  for (let name of entries) {
1296
1291
  if (!reservedKeys.has(name)) {
@@ -1339,12 +1334,12 @@ class TXmlContentRootElement extends TXmlElementController {
1339
1334
  }
1340
1335
 
1341
1336
  /**
1337
+ * Tries to unwraps a given object.
1342
1338
  * @param {object} item
1343
1339
  * @param {boolean} [opt=false]
1344
1340
  * @returns {?object}
1345
1341
  * @protected
1346
1342
  * @static
1347
- * @description Tries to unwraps a given object.
1348
1343
  */
1349
1344
  static __unwrap(item, opt) {
1350
1345
  return (
@@ -1358,6 +1353,7 @@ class TXmlContentRootElement extends TXmlElementController {
1358
1353
  }
1359
1354
 
1360
1355
  /**
1356
+ * A fs ops description.
1361
1357
  * @typedef {Object} fsoDescr
1362
1358
  * @property {boolean} isERR - flag
1363
1359
  * @property {number} [errCode] - error code
@@ -1365,7 +1361,6 @@ class TXmlContentRootElement extends TXmlElementController {
1365
1361
  * @property {string} [errMsg] - event message
1366
1362
  * @property {string} [source] - path to file
1367
1363
  * @property {any} [content] - file content
1368
- * @description A fs ops description.
1369
1364
  */
1370
1365
 
1371
1366
  /**
@@ -1385,8 +1380,8 @@ class TXmlContentContainer {
1385
1380
  #_docRoot;
1386
1381
 
1387
1382
  /**
1383
+ * Creates an instance of the container
1388
1384
  * @param {OPT_xmlcontsett} [opt] - options
1389
- * @description Creates an instance of the container
1390
1385
  */
1391
1386
  constructor(opt) {
1392
1387
  // load options
@@ -1414,8 +1409,8 @@ class TXmlContentContainer {
1414
1409
  }
1415
1410
 
1416
1411
  /**
1412
+ * Cleans a document content.
1417
1413
  * @returns {void}
1418
- * @description Cleans a document content.
1419
1414
  */
1420
1415
  clear() {
1421
1416
  this.#_docDecl.init();
@@ -1423,11 +1418,11 @@ class TXmlContentContainer {
1423
1418
  }
1424
1419
 
1425
1420
  /**
1421
+ * Initializes an instance with a given content.
1426
1422
  * @param {object} obj
1427
1423
  * @param {object} [opt]
1428
1424
  * @returns {boolean}
1429
1425
  * @protected
1430
- * @description Initializes an instance with a given content.
1431
1426
  */
1432
1427
  _bindContent(obj, opt) {
1433
1428
  let isSUCCEED = false;
@@ -1458,9 +1453,9 @@ class TXmlContentContainer {
1458
1453
  }
1459
1454
 
1460
1455
  /**
1456
+ * Returns a document content as a string in an XML-format.
1461
1457
  * @returns {string}
1462
1458
  * @throws {Error}
1463
- * @description Returns a document content as a string in an XML-format.
1464
1459
  */
1465
1460
  saveToXMLString() {
1466
1461
  let result = '';
@@ -1474,11 +1469,11 @@ class TXmlContentContainer {
1474
1469
  }
1475
1470
 
1476
1471
  /**
1472
+ * Saves a document content to a file.
1477
1473
  * @param {string} source - a path to a file
1478
1474
  * @returns {Promise<fsoDescr, Error>}
1479
1475
  * @throws {Error}
1480
1476
  * @async
1481
- * @description Saves a document content to a file.
1482
1477
  */
1483
1478
  saveToFile(source) {
1484
1479
  /**/// main part that return promise as a result
@@ -1515,9 +1510,9 @@ class TXmlContentContainer {
1515
1510
  }
1516
1511
 
1517
1512
  /**
1513
+ * Saves a document content to a file.
1518
1514
  * @param {string} source - path to a file
1519
1515
  * @returns {fsoDescr}
1520
- * @description Saves a document content to a file.
1521
1516
  */
1522
1517
  saveToFileSync(source) {
1523
1518
  /** @type {fsoDescr} */
@@ -1544,10 +1539,10 @@ class TXmlContentContainer {
1544
1539
  }
1545
1540
 
1546
1541
  /**
1542
+ * Loads a document content from a string.
1547
1543
  * @param {string} xmlString - some content
1548
1544
  * @returns {boolean}
1549
1545
  * @throws {Error}
1550
- * @description Loads a document content from a string.
1551
1546
  */
1552
1547
  loadFromXMLString(xmlString) {
1553
1548
  let isSUCCEED = false;
@@ -1568,11 +1563,11 @@ class TXmlContentContainer {
1568
1563
  }
1569
1564
 
1570
1565
  /**
1566
+ * Loads a document content from a file.
1571
1567
  * @param {string} source - path to a file
1572
1568
  * @returns {Promise<fsoDescr, Error>}
1573
1569
  * @throws {Error}
1574
1570
  * @async
1575
- * @description Loads a document content from a file.
1576
1571
  */
1577
1572
  loadFromFile(source) {
1578
1573
  /**/// main part that return promise as a result
@@ -1603,10 +1598,10 @@ class TXmlContentContainer {
1603
1598
  }
1604
1599
 
1605
1600
  /**
1601
+ * Loads a document content from a file.
1606
1602
  * @param {string} source source - path to a file
1607
1603
  * @returns {fsoDescr}
1608
1604
  * @throws {Error}
1609
- * @description Loads a document content from a file.
1610
1605
  */
1611
1606
  loadFromFileSync(source) {
1612
1607
  const data = loadFromFileSync(source);
@@ -1629,9 +1624,9 @@ class TXmlContentContainer {
1629
1624
  }
1630
1625
 
1631
1626
  /**
1627
+ * Returns a document content a string in a JSON-format.
1632
1628
  * @returns {string}
1633
1629
  * @protected
1634
- * @description Returns a document content a string in a JSON-format.
1635
1630
  */
1636
1631
  asJSON() {
1637
1632
  return JSON.stringify(this.#_content, null, 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/xml-lib-js",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "A library for handling an XML-documents",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -39,10 +39,10 @@
39
39
  "@cntwg/file-helper": "^0.0.1",
40
40
  "@ygracs/bsfoc-lib-js": "^0.2.3",
41
41
  "@ygracs/xml-js6": "^0.0.5-b",
42
- "@ygracs/xobj-lib-js": "^0.2.2"
42
+ "@ygracs/xobj-lib-js": "^0.2.3"
43
43
  },
44
44
  "devDependencies": {
45
- "jest": "^29.7.0",
45
+ "jest": "^30.0.4",
46
46
  "jsdoc-to-markdown": "^9.1.1",
47
47
  "minimist": "^1.2.8"
48
48
  }