@cntwg/xml-lib-js 0.0.30 → 0.0.31

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,14 @@
1
+ #### *v0.0.31*
2
+
3
+ Pre-release version.
4
+
5
+ > - `xmldoc-lib.md` updated;
6
+ > - (`TXmlElementController`) fix issue in method: `__setChildRaw`;
7
+ > - (`TXmlElementController`) add special static method: `__getChildRaw`;
8
+ > - (`TXmlElementController`) add special static method: `__addChildRaw`;
9
+ > - (`TXmlElementController`) deprecate methods: `_getChildRaw`, `_addChildRaw`< `_setChildRaw`;
10
+ > - some fixes in `xmldoc-lib.js` module.
11
+
1
12
  #### *v0.0.30*
2
13
 
3
14
  Pre-release version.
package/doc/xmldoc-lib.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.30|
1
+ >|***rev.*:**|0.1.31|
2
2
  >|:---|---:|
3
- >|date:|2024-09-23|
3
+ >|date:|2024-09-29|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -53,19 +53,19 @@ This constant defines a default value for naming the language attribute for XML-
53
53
 
54
54
  #### **readAsTagName(value)** => `string`
55
55
 
56
- > since: `v0.0.28`
56
+ > since: \[`v0.0.28`]
57
57
 
58
58
  This function tries to convert a given `value` to the value of type which is suitable for an XML-element's tag name. If failed an empty string is returned.
59
59
 
60
60
  #### **readAsAttrName(value)** => `string`
61
61
 
62
- > since: `v0.0.28`
62
+ > since: \[`v0.0.28`]
63
63
 
64
64
  This function tries to convert a given `value` to the value of type which is suitable for an XML-element's attribute name. If failed an empty string is returned.
65
65
 
66
66
  #### **valueToElementID(value)**
67
67
 
68
- > since: `v0.0.28`
68
+ > since: \[`v0.0.28`]
69
69
 
70
70
  This function tries to convert a given `value` to the value of a valid identifier which is suitable for an XML-element's ID-attribute. If failed an empty string is returned.
71
71
 
@@ -156,7 +156,7 @@ This method clears an attribute value addressed by a `name`.
156
156
 
157
157
  ##### **renameAttribute(name, value)** => `boolean`
158
158
 
159
- > since: `v0.0.30`
159
+ > since: \[`v0.0.30`]
160
160
 
161
161
  This method renames an attribute addressed by a `name` to its new name given by a `value` parameter.
162
162
 
@@ -222,7 +222,7 @@ This method clears an attribute value addressed by a `name` parameter.
222
222
 
223
223
  ##### **renameAttribute(name, value)** => `boolean`
224
224
 
225
- > since: `v0.0.30`
225
+ > since: \[`v0.0.30`]
226
226
 
227
227
  This method renames an attribute addressed by a `name` to its new name given by a `value` parameter.
228
228
 
@@ -276,27 +276,51 @@ This methods trows `Error` if something goes wrong through a parsing process of
276
276
 
277
277
  #### class methods (*special*)
278
278
 
279
- ##### **_getChildRaw(name)**
279
+ ##### **_getChildRaw(name)** => `?any`
280
280
 
281
- This method returns a child element addressed by `name` as object.
281
+ > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__getChildRaw` method of the class*).
282
282
 
283
- ##### **_addChildRaw(name)**
283
+ ##### **_addChildRaw(name)** => `?object`
284
284
 
285
- This method adds an element as a child element addressed by `name`.
285
+ > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__addChildRaw` method of the class*).
286
286
 
287
- ##### **_setChildRaw(name, obj)**
287
+ ##### **_setChildRaw(name, obj)** => `boolean`
288
288
 
289
- This method inserts a given object as a child element addressed by `name`.
289
+ > WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__setChildRaw` method of the class*).
290
290
 
291
291
  #### class methods (*static*)
292
292
 
293
- ##### **__unwrap(item)**
293
+ ##### **clear(item)** => `void`
294
+
295
+ This method clears an `item` content.
296
+
297
+ ##### **create(obj, opt)** => `?(TXmlElementController|TXmlElementsListController)`
298
+
299
+ > since: \[`v0.0.30`]
300
+
301
+ This method creates an instance from a given object.
302
+
303
+ #### class methods (*static, special*)
304
+
305
+ ##### **__unwrap(node)** => `?object`
294
306
 
295
307
  This method returns a host for an element as an object. If failed `null` is returned.
296
308
 
297
- ##### **clear(item)** => `void`
309
+ ##### **__getChildRaw(node, name)** => `?any`
298
310
 
299
- This method clears an `item` content.
311
+ > since: \[`v0.0.31`]
312
+
313
+ This method returns a child element addressed by `name` as object. If failed `null` is returned.
314
+
315
+ ##### **__addChildRaw(node, name)** => `?object`
316
+
317
+ > since: \[`v0.0.31`]
318
+
319
+ This method adds an element addressed by `name` as a child element.
320
+
321
+ ##### **__setChildRaw(node, name, obj)** => `boolean`
322
+
323
+ This method inserts a given object as a child element addressed by `name`.
300
324
 
301
325
  ### **TXmlElementsListController**
302
326
 
package/lib/xmldoc-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.092-20240922]
1
+ // [v0.2.096-20240929]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -554,20 +554,15 @@ class TXmlElementController {
554
554
 
555
555
  /**
556
556
  * @param {string} name
557
- * @returns {object}
557
+ * @returns {?any}
558
558
  * @protected
559
+ * @deprecated
559
560
  * @description Returns a child element.
561
+ * @see TXmlElementController.__getChildRaw
560
562
  */
561
563
  _getChildRaw(name) {
562
564
  //console.log('CHECK: TXmlElementController._getChildRaw() => was called...');
563
- //console.log('CHECK: TXmlElementController._getChildRaw() => _host => '+JSON.stringify(this.#_host, null, 2));
564
- let item = xObj.getXObjElement(this.#_host, name);
565
- //console.log('CHECK: TXmlElementController._getChildRaw() => item => '+item);
566
- //console.log('CHECK: TXmlElementController._getChildRaw() => item.name() => ['+name+']');
567
- //console.log('CHECK: TXmlElementController._getChildRaw() => item.typeof() => '+typeof item);
568
- //console.log('CHECK: TXmlElementController._getChildRaw() => item => '+JSON.stringify(item, null, 2));
569
- //console.log('CHECK: TXmlElementController._getChildRaw() => was left...');
570
- return item !== undefined ? item : null;
565
+ return TXmlElementController.__getChildRaw(this, name);
571
566
  }
572
567
 
573
568
  /**
@@ -575,6 +570,7 @@ class TXmlElementController {
575
570
  * @param {object} obj
576
571
  * @returns {boolean}
577
572
  * @protected
573
+ * @deprecated
578
574
  * @description Sets a child element.
579
575
  * @see TXmlElementController.__setChildRaw
580
576
  */
@@ -585,20 +581,15 @@ class TXmlElementController {
585
581
 
586
582
  /**
587
583
  * @param {string} name
588
- * @returns {?object}
584
+ * @returns {?Object}
589
585
  * @protected
586
+ * @deprecated
590
587
  * @description Adds a new child element.
588
+ * @see TXmlElementController.__addChildRaw
591
589
  */
592
590
  _addChildRaw(name) {
593
591
  //console.log('CHECK: TXmlElementController._addChild() => was called...');
594
- //console.log('CHECK: TXmlElementController._addChildRaw() => _host => '+JSON.stringify(this.#_host, null, 2));
595
- let result = xObj.addXObjElement(this.#_host, name);
596
- //console.log('CHECK: TXmlElementController._addChildRaw() => result => '+result);
597
- //console.log('CHECK: TXmlElementController._addChildRaw() => item.name() => ['+name+']');
598
- //console.log('CHECK: TXmlElementController._addChildRaw() => item.typeof() => '+typeof result.item);
599
- //console.log('CHECK: TXmlElementController._addChildRaw() => item => '+JSON.stringify(result.item, null, 2));
600
- //console.log('CHECK: TXmlElementController._addChildRaw() => was left...');
601
- return result.isSucceed ? result.item : null;
592
+ return TXmlElementController.__addChildRaw(this, name);
602
593
  }
603
594
 
604
595
  /**
@@ -667,6 +658,7 @@ class TXmlElementController {
667
658
  * @returns {boolean}
668
659
  * @throws {Error}
669
660
  * @experimental
661
+ * @since v0.0.30
670
662
  * @description Loads a element content from a string.
671
663
  */
672
664
  loadFromXMLString(xmlString) {
@@ -722,6 +714,57 @@ class TXmlElementController {
722
714
  return (item instanceof TXmlElementController) ? item.#_host : null;
723
715
  }
724
716
 
717
+ /**
718
+ * @param {TXmlElementController} node
719
+ * @param {string} name
720
+ * @returns {?any}
721
+ * @protected
722
+ * @static
723
+ * @since v0.0.31
724
+ * @description Returns a child element.
725
+ */
726
+ static __getChildRaw(node, name) {
727
+ let item = null;
728
+ if (node instanceof TXmlElementController) {
729
+ try {
730
+ const obj = node.#_host;
731
+ item = xObj.getXObjElement(obj, name);
732
+ if (item === undefined) item = null;
733
+ } catch (err) {
734
+ // // TODO: [?] check what kind of error thrown
735
+ item = null;
736
+ };
737
+ };
738
+ return item;
739
+ }
740
+
741
+ /**
742
+ * @param {TXmlElementController} node
743
+ * @param {string} name
744
+ * @returns {?Object}
745
+ * @protected
746
+ * @static
747
+ * @since v0.0.31
748
+ * @description Adds a new child element.
749
+ */
750
+ static __addChildRaw(node, name) {
751
+ const childName = readAsTagName(name);
752
+ let item = null;
753
+ if (
754
+ node instanceof TXmlElementController
755
+ && childName !== ''
756
+ ) {
757
+ try {
758
+ const obj = node.#_host;
759
+ ({ item } = xObj.addXObjElement(obj, childName));
760
+ } catch (err) {
761
+ // // TODO: [?] check what kind of error thrown
762
+ item = null;
763
+ };
764
+ };
765
+ return item;
766
+ }
767
+
725
768
  /**
726
769
  * @param {TXmlElementController} node
727
770
  * @param {string} name
@@ -732,25 +775,17 @@ class TXmlElementController {
732
775
  * @description Sets a child element.
733
776
  */
734
777
  static __setChildRaw(node, name, obj) {
735
- //console.log('CHECK: TXmlElementController.__setChildRaw() => was called...');
736
- let isSUCCEED = false;
737
- if (node instanceof TXmlElementController) {
738
- let item = null;
739
- if (isArray(obj)) {
740
- //console.log('CHECK: TXmlElementController.__setChildRaw() => <obj> is array...');
741
- item = xObj.insertXObjEList(node.#_host, name, { force: true });
742
- // load elements
743
- for (let element of obj) {
744
- if (isPlainObject(element)) item.push(element);
745
- };
746
- } else if (isObject(obj)) {
747
- //console.log('CHECK: TXmlElementController.__setChildRaw() => <obj> is object...');
748
- item = xObj.insertXObjElement(node.#_host, name, { force: true });
749
- // // TODO: set element
750
- };
751
- if (item) isSUCCEED = true;
778
+ const childName = readAsTagName(name);
779
+ let isSucceed = false;
780
+ if (
781
+ node instanceof TXmlElementController
782
+ && childName !== ''
783
+ && isObject(obj)
784
+ ) {
785
+ node.#_host[childName] = obj;
786
+ isSucceed = true;
752
787
  };
753
- return isSUCCEED;
788
+ return isSucceed;
754
789
  }
755
790
 
756
791
  /**
@@ -774,6 +809,7 @@ class TXmlElementController {
774
809
  * @param {object} [opt]
775
810
  * @returns {(null|TXmlElementController|TXmlElementsListController)}
776
811
  * @static
812
+ * @since v0.0.30
777
813
  * @description Creates new controller element.
778
814
  */
779
815
  static create(obj, opt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/xml-lib-js",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "A library for handling an XML-documents",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",