@cntwg/xml-lib-js 0.0.19 → 0.0.21

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,20 @@
1
+ #### *v0.0.21*
2
+
3
+ Pre-release version.
4
+
5
+ > - some fixes in `xmldoc-lib.js` module;
6
+ > - added method `hasChild()` from `TXmlElementController` class;
7
+ > - removed constants `DEF_XML_PARSE_OPTIONS` and `DEF_XML_ROOT_ETAG_NAME` from `xmldoc-lib.js` module exports;
8
+ > - updated dependency on `@ygracs/xobj-lib-js` module to v0.0.14rc3.
9
+
10
+ #### *v0.0.20*
11
+
12
+ Pre-release version.
13
+
14
+ > - `xmldoc-lib.md` updated;
15
+ > - changed behavior of `TXmlAttributesMapper` class constructor: if `obj` parameter is not an object, the `TypeError` will be thrown;
16
+ > - some fixes in `xmldoc-lib.js` module.
17
+
1
18
  #### *v0.0.19*
2
19
 
3
20
  Pre-release version.
package/doc/xmldoc-lib.md CHANGED
@@ -1,8 +1,8 @@
1
- >|***rev.*:**|0.1.18|
1
+ >|***rev.*:**|0.1.20|
2
2
  >|:---|---:|
3
- >|date:|2022-09-06|
3
+ >|date:|2023-03-01|
4
4
 
5
- ## Intoduction
5
+ ## Introduction
6
6
 
7
7
  This paper describes a constants and an object classes provided by `xmldoc-lib.js` module.
8
8
 
@@ -41,6 +41,8 @@ The settings listed in the table below:
41
41
 
42
42
  This constant defines a default value for naming the root element for XML-document. Its value is `root`.
43
43
 
44
+ > WARNING: The constant `DEF\_XML\_ROOT\_ETAG_NAME` will be deprecated. Use `XML\_DEF\_ROOT\_ETAG_NAME` instead.
45
+
44
46
  ## Module classes
45
47
 
46
48
  ### **TXmlContentParseOptions**
@@ -91,6 +93,8 @@ The `options` structure is listed below:
91
93
  |:---|---|---:|:---|
92
94
  |`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
93
95
 
96
+ > NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
97
+
94
98
  #### class properties
95
99
 
96
100
  |name|read only|description|
@@ -179,6 +183,10 @@ The method received value that can be a string or an array. If value is an array
179
183
  or
180
184
  `[ <lang>, <textValue> ]`.
181
185
 
186
+ ##### **hasChild(name)**
187
+
188
+ This method checks whether or not a child element addressed by `name` is exists.
189
+
182
190
  ##### **getChild(name)**
183
191
 
184
192
  This method returns a child element addressed by `name`.
@@ -295,7 +303,7 @@ This method deletes an element addressed by `index`. If succeed `true` is return
295
303
 
296
304
  ##### **loadItems(items, options)**
297
305
 
298
- This method loaded a list of elements listed by `items` and returns a quantity of a successfuly added elements.
306
+ This method loaded a list of elements listed by `items` and returns a quantity of a successfully added elements.
299
307
 
300
308
  #### class methods (*special*)
301
309
 
@@ -382,7 +390,7 @@ The `options` structure is listed below:
382
390
 
383
391
  This method returns a host for an element as an object. If failed `null` is returned.
384
392
 
385
- The `options` parameter, if given, change a behavoir for the method. If set to 'true' the given instance checks aganst inheritance from a `TXmlContentRootElement`, if else, from a `TXmlElementController` class.
393
+ The `options` parameter, if given, change a behavior for the method. If set to 'true' the given instance checks against inheritance from a `TXmlContentRootElement`, if else, from a `TXmlElementController` class.
386
394
 
387
395
  #### class methods (*special*)
388
396
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.007-20220722]
1
+ // [v0.1.009-20230316]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -14,9 +14,9 @@ const xmldoc = require('./lib/xmldoc-lib.js');
14
14
  exports.xObj = xObj;
15
15
 
16
16
  // will deprecate
17
- exports.DEF_XML_PARSE_OPTIONS = xmldoc.DEF_XML_PARSE_OPTIONS;
17
+ exports.DEF_XML_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
18
18
  // will deprecate
19
- exports.DEF_XML_ROOT_ETAG_NAME = xmldoc.DEF_XML_ROOT_ETAG_NAME;
19
+ exports.DEF_XML_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
20
20
 
21
21
  exports.XML_DEF_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
22
22
  exports.XML_DEF_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
package/lib/xmldoc-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.048-20220908]
1
+ // [v0.1.065-20230316]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -36,16 +36,17 @@ class TXmlAttributesMapper {
36
36
 
37
37
  constructor(obj, opt){
38
38
  // init an elements content
39
- this.#_host = isPlainObject(obj) ? obj : {};
39
+ if (!isPlainObject(obj)) throw new TypeError(XML_TE_NOBJ_EMSG);
40
+ this.#_host = obj;
40
41
  // load options
41
- let _options = (
42
- isPlainObject(opt) && isPlainObject(opt.parseOptions)
43
- ? opt.parseOptions
44
- : {}
45
- );
46
- let { settings: _settings } = _options;
47
- if (!isPlainObject(_settings)) _options.settings = _settings = {};
48
- let { attributesKey } = _settings;
42
+ const _options = isPlainObject(opt) ? opt : {};
43
+ let { parseOptions } = _options;
44
+ if (!isPlainObject(parseOptions)) {
45
+ _options.parseOptions = parseOptions = {};
46
+ };
47
+ let { settings } = parseOptions;
48
+ if (!isPlainObject(settings)) parseOptions.settings = settings = {};
49
+ let { attributesKey } = settings;
49
50
  if (
50
51
  typeof attributesKey !== 'string'
51
52
  || ((attributesKey = attributesKey.trim()) === '')
@@ -53,8 +54,8 @@ class TXmlAttributesMapper {
53
54
  attributesKey = XML_DEF_PARSE_OPTIONS.attributesKey;
54
55
  };
55
56
  // save options
56
- _settings.attributesKey = attributesKey;
57
- this.#_options = _options;
57
+ settings.attributesKey = attributesKey;
58
+ this.#_options = parseOptions;
58
59
  }
59
60
 
60
61
  get entries(){
@@ -65,69 +66,65 @@ class TXmlAttributesMapper {
65
66
  return isPlainObject(items) ? Object.entries(items) : [];
66
67
  }
67
68
 
68
- hasAttribute(value){
69
- let name = '';
70
- if (
71
- typeof value !== 'string' || ((name = value.trim()) === '')
72
- ) {
73
- return false;
69
+ hasAttribute(name){
70
+ let result = false;
71
+ try {
72
+ result = xObj.checkXObjAttribute(
73
+ this.#_host,
74
+ name,
75
+ this.#_options.settings.attributesKey,
76
+ );
77
+ } catch (err) {
78
+ // // TODO: verify what error is thrown
79
+ result = false;
74
80
  };
75
- // // TODO: await implementation for class method provided by xObj
76
- let item = xObj.getXObjAttributes(
77
- this.#_host,
78
- this.#_options.settings.attributesKey,
79
- );
80
- return isPlainObject(item) && item[name] !== undefined;
81
+ return result;
81
82
  }
82
83
 
83
- getAttribute(value){
84
- let name = '';
85
- if (
86
- typeof value !== 'string' || ((name = value.trim()) === '')
87
- ) {
88
- return '';
84
+ getAttribute(name){
85
+ let result = '';
86
+ try {
87
+ result = xObj.readXObjAttr(
88
+ this.#_host,
89
+ name,
90
+ this.#_options.settings.attributesKey,
91
+ );
92
+ } catch (err) {
93
+ // // TODO: verify what error is thrown
94
+ result = '';
89
95
  };
90
- return xObj.readXObjAttr(
91
- this.#_host,
92
- name,
93
- this.#_options.settings.attributesKey,
94
- );
96
+ return result;
95
97
  }
96
98
 
97
- setAttribute(attr, value){
98
- let name = '';
99
- if (
100
- typeof attr !== 'string' || ((name = attr.trim()) === '')
101
- || value === undefined
102
- ) {
103
- return false;
99
+ setAttribute(name, value){
100
+ let result = false;
101
+ try {
102
+ result = xObj.writeXObjAttr(
103
+ this.#_host,
104
+ name,
105
+ value,
106
+ this.#_options.settings.attributesKey,
107
+ );
108
+ } catch (err) {
109
+ // // TODO: verify what error is thrown
110
+ result = false;
104
111
  };
105
- return xObj.writeXObjAttr(
106
- this.#_host,
107
- name,
108
- value,
109
- this.#_options.settings.attributesKey,
110
- );
112
+ return result;
111
113
  }
112
114
 
113
- delAttribute(value){
114
- let name = '';
115
- if (
116
- typeof value !== 'string' || ((name = value.trim()) === '')
117
- ) {
118
- return false;
119
- };
120
- // // TODO: await implementation for class method provided by xObj
121
- let items = xObj.getXObjAttributes(
122
- this.#_host,
123
- this.#_options.settings.attributesKey,
124
- );
125
- let isSUCCEED = isPlainObject(items);
126
- if (isSUCCEED) {
127
- // // TODO: catch errors in strict mode
128
- isSUCCEED = delete items[name];
115
+ delAttribute(name){
116
+ let result = false;
117
+ try {
118
+ result = xObj.deleteXObjAttribute(
119
+ this.#_host,
120
+ name,
121
+ this.#_options.settings.attributesKey,
122
+ );
123
+ } catch (err) {
124
+ // // TODO: verify what error is thrown
125
+ result = false;
129
126
  };
130
- return isSUCCEED;
127
+ return result;
131
128
  }
132
129
 
133
130
  clear(){
@@ -136,7 +133,7 @@ class TXmlAttributesMapper {
136
133
  this.#_options.settings.attributesKey,
137
134
  {
138
135
  force: true,
139
- rip_oldies: true,
136
+ ripOldies: true,
140
137
  },
141
138
  );
142
139
  }
@@ -153,9 +150,12 @@ class TXmlElementController {
153
150
  constructor(obj, opt){
154
151
  // load options
155
152
  let _options = isPlainObject(opt) ? opt : {};
156
- let { proxyModeEnable } = _options;
153
+ let {
154
+ proxyModeEnable,
155
+ parseOptions,
156
+ } = _options;
157
157
  if (typeof proxyModeEnable !== 'boolean') proxyModeEnable = false;
158
- // init an elements content
158
+ // init an element content
159
159
  if (isObject(obj)) {
160
160
  if (isArray(obj)) return new TXmlElementsListController(obj, opt);
161
161
  // // TODO: split a plain object and class instances
@@ -169,18 +169,21 @@ class TXmlElementController {
169
169
  this.#_host = {};
170
170
  };
171
171
  // set parser options
172
- let { parseOptions: _parseOptions } = _options;
173
- if (!isPlainObject(_parseOptions)) {
174
- _options.parseOptions = _parseOptions = {};
172
+ if (!isPlainObject(parseOptions)) {
173
+ _options.parseOptions = parseOptions = {};
175
174
  };
176
- let { settings: _settings } = _parseOptions;
177
- if (!isPlainObject(_settings)) {
178
- _parseOptions.settings = _settings = {};
179
- // // TODO: set defaults
175
+ let { settings } = parseOptions;
176
+ if (!isPlainObject(settings)) parseOptions.settings = settings = {};
177
+ let { textKey } = settings;
178
+ if (
179
+ typeof textKey !== 'string'
180
+ || ((textKey = textKey.trim()) === '')
181
+ ) {
182
+ textKey = XML_DEF_PARSE_OPTIONS.textKey;
180
183
  };
181
- // save parser options
182
- this.#_parseOptions = _parseOptions;
183
184
  // save options
185
+ settings.textKey = textKey;
186
+ this.#_parseOptions = parseOptions;
184
187
  _options.proxyModeEnable = proxyModeEnable;
185
188
  this.#_options = _options;
186
189
  // bind atributes mapper
@@ -236,42 +239,60 @@ class TXmlElementController {
236
239
  }
237
240
 
238
241
  setTextValue(value){
239
- value = valueToArray(value);
240
- let val_size = value.length;
241
- if (val_size === 1) {
242
- return xObj.writeXObjParam(
243
- this.#_host,
244
- value[0],
245
- this.#_parseOptions.settings.textKey,
246
- );
247
- } else if (val_size > 1) {
248
- if (xObj.writeXObjParam(
249
- this.#_host,
250
- value[1],
251
- this.#_parseOptions.settings.textKey,
252
- )) {
253
- return this.#_attributes.setAttribute(XML_LANG_ATTR_TNAME, value[0]);
242
+ const _value = valueToArray(value);
243
+ const len = _value.length;
244
+ if (len > 0) {
245
+ if (len === 1) {
246
+ return xObj.writeXObjParam(
247
+ this.#_host,
248
+ _value[0],
249
+ this.#_parseOptions.settings.textKey,
250
+ );
251
+ } else {
252
+ const [ lang, param ] = _value;
253
+ if (xObj.writeXObjParam(
254
+ this.#_host,
255
+ param,
256
+ this.#_parseOptions.settings.textKey,
257
+ )) {
258
+ return this.#_attributes.setAttribute(XML_LANG_ATTR_TNAME, lang);
259
+ };
254
260
  };
255
261
  };
256
262
  return false;
257
263
  }
258
264
 
259
- getChild(value){
260
- let name = '';
261
- if (
262
- typeof value !== 'string' || ((name = value.trim()) === '')
263
- ) {
264
- return null;
265
+ hasChild(name){
266
+ const _name = xObj.evalXObjEName(name);
267
+ let result = false;
268
+ if (typeof _name === 'string' && _name !== '') {
269
+ try {
270
+ result = isObject(xObj.getXObjElement(this.#_host, name));
271
+ } catch (err) {
272
+ // // TODO: [?] verify what error is thrown
273
+ throw err;
274
+ };
265
275
  };
266
- let item = xObj.getXObjElement(this.#_host, name);
267
- if (isArray(item)) {
268
- item = new TXmlElementsListController(item, this.#_options);
269
- } else if (isObject(item)) {
270
- item = new TXmlElementController(item, this.#_options);
271
- } else {
272
- item = null;
276
+ return result;
277
+ }
278
+
279
+ getChild(name){
280
+ const _name = xObj.evalXObjEName(name);
281
+ let result = null;
282
+ if (typeof _name === 'string' && _name !== '') {
283
+ try {
284
+ const item = xObj.getXObjElement(this.#_host, name);
285
+ if (isArray(item)) {
286
+ result = new TXmlElementsListController(item, this.#_options);
287
+ } else if (isObject(item)) {
288
+ result = new TXmlElementController(item, this.#_options);
289
+ };
290
+ } catch (err) {
291
+ // // TODO: [?] verify what error is thrown
292
+ throw err;
293
+ };
273
294
  };
274
- return item;
295
+ return result;
275
296
  }
276
297
 
277
298
  _getChildRaw(name){
@@ -298,7 +319,7 @@ class TXmlElementController {
298
319
  };
299
320
  } else if (isObject(obj)) {
300
321
  //console.log('CHECK: TXmlElementController._setChildRaw() => <obj> is object...');
301
- item = xObj.insertXObjElement(this.#_host, name, true);
322
+ item = xObj.insertXObjElement(this.#_host, name, { force: true });
302
323
  // // TODO: set element
303
324
  };
304
325
  if (item) isSUCCEED = true;
@@ -317,38 +338,48 @@ class TXmlElementController {
317
338
  return result.isSucceed ? result.item : null;
318
339
  }
319
340
 
320
- addChild(value){
321
- let name = '';
322
- if (
323
- typeof value !== 'string' || ((name = value.trim()) === '')
324
- ) {
325
- return null;
341
+ addChild(name){
342
+ const _name = xObj.evalXObjEName(name);
343
+ let result = null;
344
+ if (typeof _name === 'string' && _name !== '') {
345
+ try {
346
+ let { item } = xObj.addXObjElement(this.#_host, name);
347
+ if (item) result = new TXmlElementController(item, this.#_options)
348
+ } catch (err) {
349
+ // // TODO: [?] verify what error is thrown
350
+ throw err;
351
+ };
326
352
  };
327
- const result = xObj.addXObjElement(this.#_host, name);
328
- return (
329
- result.isSucceed
330
- ? new TXmlElementController(result.item, this.#_options)
331
- : null
332
- );
353
+ return result;
333
354
  }
334
355
 
335
- delChild(value){
336
- let name = '';
337
- if (
338
- typeof value !== 'string' || ((name = value.trim()) === '')
339
- ) {
340
- return false;
341
- };
342
- let item = xObj.getXObjElement(this.#_host, name);
343
- if (isArray(item)) {
344
- //console.log('CHECK: TXmlElementController.delChild() => item.typeof() => [object Array]');
345
- } else if (isObject(item)) {
346
- return xObj.deleteXObjElement(this.#_host, name);
347
- } else {
348
- //console.log('CHECK: TXmlElementController.delChild() => item.typeof() => ['+typeof item+']');
349
- //console.log('CHECK: TXmlElementController.delChild() => item.value() => ['+item+']');
356
+ delChild(name){
357
+ const _name = xObj.evalXObjEName(name);
358
+ let isSUCCEED = false;
359
+ if (typeof _name === 'string' && _name !== '') {
360
+ try {
361
+ const item = xObj.getXObjElement(this.#_host, name);
362
+ let isACCEPTED = false;
363
+ if (isArray(item)) {
364
+ //console.log('CHECK: TXmlElementController.delChild() => item.typeof() => [object Array]');
365
+ if (item.length < 2) {
366
+ isACCEPTED = true;
367
+ } else {
368
+ //console.log('CHECK: TXmlElementController.delChild() => item.length() => ['+item.length+']');
369
+ };
370
+ } else if (isObject(item)) {
371
+ isACCEPTED = true;
372
+ } else {
373
+ //console.log('CHECK: TXmlElementController.delChild() => item.typeof() => ['+typeof item+']');
374
+ //console.log('CHECK: TXmlElementController.delChild() => item.value() => ['+item+']');
375
+ };
376
+ if (isACCEPTED) isSUCCEED = xObj.deleteXObjElement(this.#_host, name);
377
+ } catch (err) {
378
+ // // TODO: [?] verify what error is thrown
379
+ throw err;
380
+ };
350
381
  };
351
- return false;
382
+ return isSUCCEED;
352
383
  }
353
384
 
354
385
  clear(){
@@ -379,17 +410,19 @@ class TXmlElementsListController {
379
410
  constructor(obj, opt){
380
411
  // load options
381
412
  let _options = isPlainObject(opt) ? opt : {};
382
- let { proxyModeEnable, isNullItemsAllowed } = _options;
413
+ let {
414
+ proxyModeEnable,
415
+ isNullItemsAllowed,
416
+ parseOptions,
417
+ } = _options;
383
418
  if (typeof proxyModeEnable !== 'boolean') proxyModeEnable = false;
384
419
  if (typeof isNullItemsAllowed !== 'boolean') isNullItemsAllowed = false;
385
420
  // set parser options
386
- let { parseOptions: _parseOptions } = _options;
387
- if (!isPlainObject(_parseOptions)) _parseOptions = {};
388
- let { settings: _settings } = _parseOptions;
389
- if (!isPlainObject(_settings)) {
390
- _parseOptions.settings = _settings = {};
391
- // // TODO: set defaults
421
+ if (!isPlainObject(parseOptions)) {
422
+ _options.parseOptions = parseOptions = {};
392
423
  };
424
+ let { settings } = parseOptions;
425
+ if (!isPlainObject(settings)) parseOptions.settings = settings = {};
393
426
  // init an elements list content
394
427
  if (isArray(obj)) {
395
428
  this.#_host = obj;
@@ -403,8 +436,6 @@ class TXmlElementsListController {
403
436
  this.#_host = [];
404
437
  };
405
438
  };
406
- // save parser options
407
- _options.parseOptions = _parseOptions;
408
439
  // save options
409
440
  _options.proxyModeEnable = proxyModeEnable;
410
441
  _options.isNullItemsAllowed = isNullItemsAllowed;
@@ -570,21 +601,20 @@ class TXmlContentDeclaration {
570
601
  // load options
571
602
  let _options = isPlainObject(opt) ? opt : {};
572
603
  // set parser options
573
- let { parseOptions: _parseOptions } = _options;
574
- if (!isPlainObject(_parseOptions)) _parseOptions = {};
575
- let { settings: _settings } = _parseOptions;
576
- if (!isPlainObject(_settings)) _parseOptions.settings = _settings = {};
577
- let { declarationKey } = _settings;
604
+ let { parseOptions: parseOptions } = _options;
605
+ if (!isPlainObject(parseOptions)) {
606
+ _options.parseOptions = parseOptions = {};
607
+ };
608
+ let { settings: settings } = parseOptions;
609
+ if (!isPlainObject(settings)) parseOptions.settings = settings = {};
610
+ let { declarationKey } = settings;
578
611
  if (
579
612
  typeof declarationKey !== 'string'
580
613
  || ((declarationKey = declarationKey.trim()) === '')
581
614
  ) {
582
615
  declarationKey = XML_DEF_PARSE_OPTIONS.declarationKey;
616
+ settings.declarationKey = declarationKey;
583
617
  };
584
- // // TODO: set defaults
585
- // save parser options
586
- _options.parseOptions = _parseOptions;
587
- _settings.declarationKey = declarationKey;
588
618
  // save options
589
619
  this.#_options = _options;
590
620
  // bind a documents content
@@ -610,13 +640,13 @@ class TXmlContentDeclaration {
610
640
  }
611
641
 
612
642
  init(){
613
- let _options = this.#_options;
643
+ const _options = this.#_options;
614
644
  this.#_ctrls = new TXmlElementController(
615
645
  xObj.insertXObjElement(
616
646
  this.#_host,
617
647
  _options.parseOptions.settings.declarationKey,
618
648
  ),
619
- this._options,
649
+ _options,
620
650
  );
621
651
  // // TODO: set version & encoding
622
652
  if (!isNotEmptyString(this.version)) this.version = '1.0';
@@ -653,7 +683,7 @@ class TXmlContentRootElement extends TXmlElementController {
653
683
  const entries = Object.keys(obj);
654
684
  const len = entries.length;
655
685
  if (len === 0) {
656
- rootItem = xObj.insertXObjElement(obj, rootETagName, false);
686
+ rootItem = xObj.insertXObjElement(obj, rootETagName);
657
687
  } else {
658
688
  const {
659
689
  declarationKey,
@@ -685,13 +715,13 @@ class TXmlContentRootElement extends TXmlElementController {
685
715
  };
686
716
  };
687
717
  if (targetKey === '') {
688
- rootItem = xObj.insertXObjElement(obj, rootETagName, false);
718
+ rootItem = xObj.insertXObjElement(obj, rootETagName);
689
719
  } else {
690
720
  if (autoBindRoot) {
691
721
  rootItem = obj[targetKey];
692
722
  rootETagName = targetKey;
693
723
  if (!isPlainObject(rootItem)) {
694
- rootItem = xObj.insertXObjElement(obj, rootETagName, false);
724
+ rootItem = xObj.insertXObjElement(obj, rootETagName);
695
725
  };
696
726
  } else {
697
727
  throw new TypeError(`TXmlContentRootElement : ${XML_TE_NROOT_EMSG}`);
@@ -699,7 +729,7 @@ class TXmlContentRootElement extends TXmlElementController {
699
729
  };
700
730
  };
701
731
  } else if (!isPlainObject(rootItem)) {
702
- rootItem = xObj.insertXObjElement(obj, rootETagName, false);
732
+ rootItem = xObj.insertXObjElement(obj, rootETagName);
703
733
  };
704
734
  // init parent class instance
705
735
  super(rootItem, _options);
@@ -725,19 +755,6 @@ class TXmlContentRootElement extends TXmlElementController {
725
755
  ) ? value : XML_DEF_ROOT_ETAG_NAME;
726
756
  }
727
757
 
728
- //* will deprecate */
729
- /*init(name){
730
- //console.log('CHECK: TXmlContentRootElement.init() => was called...');
731
- //console.log('CHECK: TXmlContentRootElement.init() => (*1) name:['+name+']');
732
- let _options = this.#_options;
733
- name = readAsString(name, _options.rootETagName, true);
734
- // // TODO: check if name is valid
735
- //console.log('CHECK: TXmlContentRootElement.init() => (*2) name:['+name+']');
736
- if (!isPlainObject(this.#_content[name])) this.#_content[name] = {};
737
- this.#_ctrls = new TXmlElementController(this.#_content[name], _options);
738
- //console.log('CHECK: TXmlContentRootElement.init() => was left...');
739
- }*/
740
-
741
758
  static __unwrap(item, opt){
742
759
  return (
743
760
  item instanceof TXmlContentRootElement
@@ -820,7 +837,7 @@ class TXmlContentContainer {
820
837
  try {
821
838
  result = xmlParser.js2xml(this.#_content, this.#_parseOptions.js2xml);
822
839
  } catch (err) {
823
- console.log('CHECK: TXmlContentContainer.saveToXMLString() => Error => '+err);
840
+ //console.log('CHECK: TXmlContentContainer.saveToXMLString() => Error => '+err);
824
841
  //isERR = true;
825
842
  throw err;
826
843
  };
@@ -850,9 +867,21 @@ class TXmlContentContainer {
850
867
  data.errEvent = 'OPS_IS_SUCCEED';
851
868
  resolve(data);
852
869
  }).catch(err => {
853
- console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err);
854
- console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err.code);
855
- reject(err);
870
+ switch (err.code) {
871
+ case 'ENOENT': {
872
+ data.isERR = true;
873
+ data.errEvent = err.code;
874
+ data.content = '';
875
+ resolve(data);
876
+ break;
877
+ }
878
+ default: {
879
+ console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err);
880
+ console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err.code);
881
+ reject(err);
882
+ break;
883
+ }
884
+ };
856
885
  });
857
886
  };
858
887
  });
@@ -876,9 +905,20 @@ class TXmlContentContainer {
876
905
  data.content = this.saveToXMLString();
877
906
  fs.writeFileSync(data.source, data.content, 'utf8');
878
907
  } catch (err) {
879
- console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err);
880
- console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err.code);
881
- throw err;
908
+ switch (err.code) {
909
+ case 'ENOENT': {
910
+ data.isERR = true;
911
+ data.errEvent = err.code;
912
+ data.content = '';
913
+ break;
914
+ }
915
+ default: {
916
+ console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err);
917
+ console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err.code);
918
+ throw err;
919
+ break;
920
+ }
921
+ };
882
922
  };
883
923
  };
884
924
  return data;
@@ -894,8 +934,8 @@ class TXmlContentContainer {
894
934
  isSUCCEED = this._bindContent(obj, this.#_options);
895
935
  };
896
936
  } catch (err) {
897
- console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err);
898
- console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err.code);
937
+ //console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err);
938
+ //console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err.code);
899
939
  throw err;
900
940
  };
901
941
  };
@@ -937,16 +977,18 @@ class TXmlContentContainer {
937
977
  }).catch(err => {
938
978
  switch (err.code) {
939
979
  case 'ENOENT':
940
- case 'EISDIR':
980
+ case 'EISDIR': {
941
981
  data.isERR = true;
942
982
  data.errEvent = err.code;
943
983
  resolve(data);
944
984
  break;
945
- default:
985
+ }
986
+ default: {
946
987
  console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err);
947
988
  console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err.code);
948
989
  reject(err);
949
990
  break;
991
+ }
950
992
  };
951
993
  });
952
994
  };
@@ -984,15 +1026,17 @@ class TXmlContentContainer {
984
1026
  } catch (err) {
985
1027
  switch (err.code) {
986
1028
  case 'ENOENT':
987
- case 'EISDIR':
988
- data.isERR = true;
989
- data.errEvent = err.code;
990
- break;
991
- default:
992
- console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err);
993
- console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err.code);
994
- throw err;
995
- break;
1029
+ case 'EISDIR': {
1030
+ data.isERR = true;
1031
+ data.errEvent = err.code;
1032
+ break;
1033
+ }
1034
+ default: {
1035
+ console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err);
1036
+ console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err.code);
1037
+ throw err;
1038
+ break;
1039
+ }
996
1040
  };
997
1041
  };
998
1042
  };
@@ -1007,8 +1051,8 @@ class TXmlContentContainer {
1007
1051
 
1008
1052
  // === module exports block ===
1009
1053
 
1010
- exports.DEF_XML_PARSE_OPTIONS = XML_DEF_PARSE_OPTIONS; // will deprecate
1011
- exports.DEF_XML_ROOT_ETAG_NAME = XML_DEF_ROOT_ETAG_NAME; // will deprecate
1054
+ //exports.DEF_XML_PARSE_OPTIONS = XML_DEF_PARSE_OPTIONS; // will deprecate
1055
+ //exports.DEF_XML_ROOT_ETAG_NAME = XML_DEF_ROOT_ETAG_NAME; // will deprecate
1012
1056
 
1013
1057
  exports.XML_DEF_PARSE_OPTIONS = XML_DEF_PARSE_OPTIONS;
1014
1058
  exports.XML_DEF_ROOT_ETAG_NAME = XML_DEF_ROOT_ETAG_NAME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/xml-lib-js",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "A library for handling an XML-documents",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@ygracs/bsfoc-lib-js": "^0.1.2",
33
33
  "@ygracs/xml-js6": "^0.0.3-b",
34
- "@ygracs/xobj-lib-js": "^0.0.14-rc1"
34
+ "@ygracs/xobj-lib-js": "^0.0.14-rc3"
35
35
  },
36
36
  "devDependencies": {
37
- "jest": "^27.5.1"
37
+ "jest": "^29.4.2"
38
38
  }
39
39
  }