@cntwg/xml-lib-js 0.0.23 → 0.0.25

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.25*
2
+
3
+ Pre-release version.
4
+
5
+ > - `xmldoc-lib.md` updated;
6
+ > - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.0;
7
+ > - updated dependency on `@ygracs/xobj-lib-js` module to v0.1.1.
8
+
9
+ #### *v0.0.24*
10
+
11
+ Pre-release version.
12
+
13
+ > - `xmldoc-lib.md` updated;
14
+ > - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.4;
15
+ > - updated dependency on `@ygracs/xobj-lib-js` module to v0.1.0;
16
+ > - some fixes in `xmldoc-lib.js` module.
17
+
1
18
  #### *v0.0.23*
2
19
 
3
20
  Pre-release version.
package/README.md CHANGED
@@ -1,11 +1,21 @@
1
- |***rev.*:**|0.1.2|
1
+ |***rev.*:**|0.1.4|
2
2
  |:---|---:|
3
- |***date***:|2022-09-06|
3
+ |***date***:|2023-09-19|
4
4
 
5
5
  ## Introduction
6
6
 
7
7
  This module provide a base functionality for handling an XML-documents.
8
8
 
9
+ ## Use cases
10
+
11
+ ### Installation
12
+
13
+ `npm install @cntwg/xml-lib-js`
14
+
15
+ ## Description
16
+
17
+ This module contains the following components:
18
+
9
19
  ### 1. xObj-manipulator
10
20
 
11
21
  xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` module](https://gitlab.com/ygracs/xobj-lib-js)).
@@ -16,8 +26,6 @@ xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` modu
16
26
 
17
27
  + `XML_DEF_ROOT_ETAG_NAME`;
18
28
  + `XML_DEF_PARSE_OPTIONS`;
19
- + `DEF_XML_ROOT_ETAG_NAME` (*will deprecate*);
20
- + `DEF_XML_PARSE_OPTIONS` (*will deprecate*).
21
29
 
22
30
  - classes:
23
31
 
package/doc/xmldoc-lib.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.20|
1
+ >|***rev.*:**|0.1.22|
2
2
  >|:---|---:|
3
- >|date:|2023-03-01|
3
+ >|date:|2023-09-19|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -8,7 +8,7 @@ This paper describes a constants and an object classes provided by `xmldoc-lib.j
8
8
 
9
9
  ## Module constants
10
10
 
11
- ### **DEF\_XML\_PARSE_OPTIONS** or **XML\_DEF\_PARSE_OPTIONS**
11
+ ### **XML\_DEF\_PARSE_OPTIONS**
12
12
 
13
13
  This constant object provided by the module contains a default settings of options for XML-parser module used within.
14
14
 
@@ -37,12 +37,10 @@ The settings listed in the table below:
37
37
  |`trim`|`boolean`|`true`|
38
38
  |`spaces`|`number`|`2`|
39
39
 
40
- ### **DEF\_XML\_ROOT\_ETAG_NAME** or **XML\_DEF\_ROOT\_ETAG_NAME**
40
+ ### **XML\_DEF\_ROOT\_ETAG_NAME**
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
-
46
44
  ## Module classes
47
45
 
48
46
  ### **TXmlContentParseOptions**
@@ -80,26 +78,32 @@ This class implements a proxy interface for handling attributes of an element.
80
78
 
81
79
  #### class constructor
82
80
 
83
- The class constructor creates a new instance of the class. It receives arguments listed below:
81
+ The class constructor creates a new instance of the class.
84
82
 
85
- |name|type|default value|description|
83
+ ##### constructor parameters
84
+
85
+ The class constructor receives an arguments listed below:
86
+
87
+ |parameter name|value type|default value|description|
86
88
  |:---|---|---:|:---|
87
89
  |`object`|---|---|a host object that holds an attributes|
88
90
  |`options`|`object`|---|an options settings|
89
91
 
92
+ > NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
93
+
94
+ ##### `options` parameter
95
+
90
96
  The `options` structure is listed below:
91
97
 
92
98
  |option name|value type|default value|description|
93
99
  |:---|---|---:|:---|
94
100
  |`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
95
101
 
96
- > NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
97
-
98
102
  #### class properties
99
103
 
100
- |name|read only|description|
101
- |:---|---|:---|
102
- |`entries`|yes|returns array of entries for all existing attributes|
104
+ |property name|value type|read only|description|
105
+ |:---|---|---|:---|
106
+ |`entries`|`array`|yes|returns an array of entries for all existing attributes|
103
107
 
104
108
 
105
109
  #### class methods
@@ -130,13 +134,19 @@ This class implements a proxy interface for an element.
130
134
 
131
135
  #### class constructor
132
136
 
133
- The class constructor creates a new instance of the class. It receives an arguments listed below:
137
+ The class constructor creates a new instance of the class.
134
138
 
135
- |name|type|default value|description|
139
+ ##### constructor parameters
140
+
141
+ The class constructor receives an arguments listed below:
142
+
143
+ |parameter name|value type|default value|description|
136
144
  |:---|---|---:|:---|
137
145
  |`object`|---|---|a host object|
138
146
  |`options`|`object`|---|an options settings|
139
147
 
148
+ ##### `options` parameter
149
+
140
150
  The `options` structure is listed below:
141
151
 
142
152
  |option name|value type|default value|description|
@@ -146,11 +156,11 @@ The `options` structure is listed below:
146
156
 
147
157
  #### class properties
148
158
 
149
- |property name|read only|description|
150
- |:---|---|:---|
151
- |`attributes`|yes|returns an attributes of the element|
152
- |`name`|yes|returns a tag name of the element|
153
- |`textValue`|no|represents a value of the element|
159
+ |property name|value type|read only|description|
160
+ |:---|---|---|:---|
161
+ |`attributes`|`TXmlAttributesMapper`|yes|returns an attributes of the element|
162
+ |`name`||yes|\<*reserved*>|
163
+ |`textValue`|`string`|no|represents a value of the element|
154
164
 
155
165
  #### class methods
156
166
 
@@ -235,13 +245,19 @@ This class implements a proxy interface for a list of elements.
235
245
 
236
246
  #### class constructor
237
247
 
238
- The class constructor creates a new instance of the class. It receives arguments listed below:
248
+ The class constructor creates a new instance of the class.
239
249
 
240
- |name|type|default value|description|
250
+ ##### constructor parameters
251
+
252
+ The class constructor receives an arguments listed below:
253
+
254
+ |parameter name|value type|default value|description|
241
255
  |:---|---|---:|:---|
242
256
  |`object`|---|---|a host object of an array type.|
243
257
  |`options`|`object`|---|an options settings.|
244
258
 
259
+ ##### `options` parameter
260
+
245
261
  The `options` structure is listed below:
246
262
 
247
263
  |option name|value type|default value|description|
@@ -253,7 +269,7 @@ The `options` structure is listed below:
253
269
  #### class properties
254
270
 
255
271
  |property name|property type|read only|description|
256
- |:---|---|:---|
272
+ |:---|---|---|:---|
257
273
  |`count`|`number`|yes|returns a quantity of the elements|
258
274
  |`size`|`number`|yes|returns a quantity of the elements|
259
275
  |`maxIndex`|`index`|yes|returns a last possible index of the elements|
@@ -305,6 +321,12 @@ This method deletes an element addressed by `index`. If succeed `true` is return
305
321
 
306
322
  This method loaded a list of elements listed by `items` and returns a quantity of a successfully added elements.
307
323
 
324
+ The `options` structure is listed below:
325
+
326
+ |option name|value type|default value|description|
327
+ |:---|---|---:|:---|
328
+ |`useClear`|`boolean`|`true`|if `true` the method deletes all the previous content before load the list|
329
+
308
330
  #### class methods (*special*)
309
331
 
310
332
  ##### **_getItemRaw(name)**
@@ -329,13 +351,19 @@ This class implements a proxy interface for a document declaration element.
329
351
 
330
352
  #### class constructor
331
353
 
332
- The class constructor creates a new instance of the class. It receives arguments listed below:
354
+ The class constructor creates a new instance of the class.
333
355
 
334
- |name|type|default value|description|
356
+ ##### constructor parameters
357
+
358
+ The class constructor receives an arguments listed below:
359
+
360
+ |parameter name|value type|default value|description|
335
361
  |:---|---|---:|:---|
336
362
  |`object`|`object`|---|a host object for the document content.|
337
363
  |`options`|`object`|---|an options settings.|
338
364
 
365
+ ##### `options` parameter
366
+
339
367
  The `options` structure is listed below:
340
368
 
341
369
  |option name|value type|default value|description|
@@ -345,7 +373,7 @@ The `options` structure is listed below:
345
373
  #### class properties
346
374
 
347
375
  |property name|property type|read only|description|
348
- |:---|---|:---|
376
+ |:---|---|---|:---|
349
377
  |`version`|`string`|no|returns a version of a XML|
350
378
  |`encoding`|`string`|no|returns an encodings used by a document|
351
379
 
@@ -353,21 +381,27 @@ The `options` structure is listed below:
353
381
 
354
382
  ##### **init()**
355
383
 
356
- This method initializes element with a default values.
384
+ This method initializes an element with a default values.
357
385
 
358
386
  ### **TXmlContentRootElement**
359
387
 
360
- This class extends functionality of a `TXmlElementController` class.
388
+ This class extends a functionality of a `TXmlElementController` class.
361
389
 
362
390
  #### class constructor
363
391
 
364
- The class constructor creates a new instance of the class. It receives arguments listed below:
392
+ The class constructor creates a new instance of the class.
365
393
 
366
- |name|type|default value|description|
394
+ ##### constructor parameters
395
+
396
+ The class constructor receives an arguments listed below:
397
+
398
+ |parameter name|value type|default value|description|
367
399
  |:---|---|---:|:---|
368
400
  |`object`|`object`|---|a host object for the document content|
369
401
  |`options`|`object`|---|an options settings|
370
402
 
403
+ ##### `options` parameter
404
+
371
405
  The `options` structure is listed below:
372
406
 
373
407
  |option name|value type|default value|description|
@@ -380,9 +414,9 @@ The `options` structure is listed below:
380
414
 
381
415
  #### class properties
382
416
 
383
- |name|read only|description|
384
- |:---|---|:---|
385
- |tagName|no||
417
+ |property name|value type|read only|description|
418
+ |:---|---|---|:---|
419
+ |tagName|`string`|no||
386
420
 
387
421
  #### class methods (*static*)
388
422
 
@@ -400,7 +434,13 @@ This class implements a proxy interface for manipulate a content of a document.
400
434
 
401
435
  #### class constructor
402
436
 
403
- The class constructor creates a new instance of the class. It receives an `options` parameter as its argument.
437
+ The class constructor creates a new instance of the class.
438
+
439
+ ##### constructor parameters
440
+
441
+ The class constructor receives an `options` parameter as its argument.
442
+
443
+ ##### `options` parameter
404
444
 
405
445
  The `options` structure is listed below:
406
446
 
@@ -414,9 +454,9 @@ The `options` structure is listed below:
414
454
 
415
455
  #### class properties
416
456
 
417
- |property name|read only|description|
418
- |:---|---|:---|
419
- |rootElement|yes|returns a document root element|
457
+ |property name|value type|read only|description|
458
+ |:---|---|---|:---|
459
+ |rootElement||yes|returns a document root element|
420
460
 
421
461
  #### class methods
422
462
 
@@ -428,12 +468,6 @@ This method clears a document content.
428
468
 
429
469
  This method returns a document content as a string.
430
470
 
431
- ##### **saveToFile(src)**
432
-
433
- This method saves a document content into a file addressed by `src`.
434
-
435
- > This is `async` method.
436
-
437
471
  ##### **saveToFileSync(src)**
438
472
 
439
473
  This method saves a document content into a file addressed by `src`.
@@ -442,13 +476,17 @@ This method saves a document content into a file addressed by `src`.
442
476
 
443
477
  This method loads a document content from a string given by `str`.
444
478
 
445
- ##### **loadFromFile(src)**
479
+ ##### **loadFromFileSync(src)**
446
480
 
447
481
  This method loads a document content from a file addressed by `src`.
448
482
 
449
- > This is `async` method.
483
+ #### class methods (*async*)
450
484
 
451
- ##### **loadFromFileSync(src)**
485
+ ##### **saveToFile(src)**
486
+
487
+ This method saves a document content into a file addressed by `src`.
488
+
489
+ ##### **loadFromFile(src)**
452
490
 
453
491
  This method loads a document content from a file addressed by `src`.
454
492
 
@@ -461,3 +499,5 @@ This method returns a document content as a string in the JSON-format.
461
499
  ##### **_bindContent(obj\[, options])**
462
500
 
463
501
  This method binds a given object as a document content.
502
+
503
+ For `options` parameter details see the class constructor description.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.009-20230316]
1
+ // [v0.1.011-20230919]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -13,11 +13,6 @@ const xmldoc = require('./lib/xmldoc-lib.js');
13
13
 
14
14
  exports.xObj = xObj;
15
15
 
16
- // will deprecate
17
- exports.DEF_XML_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
18
- // will deprecate
19
- exports.DEF_XML_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
20
-
21
16
  exports.XML_DEF_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
22
17
  exports.XML_DEF_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
23
18
 
package/lib/xmldoc-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.066-20230317]
1
+ // [v0.1.069-20230926]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -584,11 +584,12 @@ class TXmlElementsListController {
584
584
  }
585
585
 
586
586
  loadItems(items, opt){
587
- let act_as_new = true;
588
- if (isPlainObject(opt)) {
589
- act_as_new = readAsBool(opt.load_as_new, act_as_new);
590
- };
591
- if (act_as_new) this.clear();
587
+ const _options = isPlainObject(opt) ? opt : {};
588
+ let {
589
+ useClear,
590
+ } = _options;
591
+ if (typeof useClear !== 'boolean') useClear = true;
592
+ if (useClear) this.clear();
592
593
  let count = this.count;
593
594
  valueToArray(items).forEach((item) => { this.addItem(item); });
594
595
  return this.count - count;
@@ -609,11 +610,11 @@ class TXmlContentDeclaration {
609
610
  // load options
610
611
  let _options = isPlainObject(opt) ? opt : {};
611
612
  // set parser options
612
- let { parseOptions: parseOptions } = _options;
613
+ let { parseOptions } = _options;
613
614
  if (!isPlainObject(parseOptions)) {
614
615
  _options.parseOptions = parseOptions = {};
615
616
  };
616
- let { settings: settings } = parseOptions;
617
+ let { settings } = parseOptions;
617
618
  if (!isPlainObject(settings)) parseOptions.settings = settings = {};
618
619
  let { declarationKey } = settings;
619
620
  if (
@@ -757,7 +758,7 @@ class TXmlContentRootElement extends TXmlElementController {
757
758
  }
758
759
 
759
760
  set tagName(value){
760
- value = readAsString(value, '', true);
761
+ value = readAsString(value, true);
761
762
  this.#_options.rootETagName = isNotEmptyString(
762
763
  value
763
764
  ) ? value : XML_DEF_ROOT_ETAG_NAME;
@@ -841,12 +842,10 @@ class TXmlContentContainer {
841
842
 
842
843
  saveToXMLString(){
843
844
  let result = '';
844
- //let isERR = false;
845
845
  try {
846
846
  result = xmlParser.js2xml(this.#_content, this.#_parseOptions.js2xml);
847
847
  } catch (err) {
848
848
  //console.log('CHECK: TXmlContentContainer.saveToXMLString() => Error => '+err);
849
- //isERR = true;
850
849
  throw err;
851
850
  };
852
851
  return result;
@@ -884,8 +883,8 @@ class TXmlContentContainer {
884
883
  break;
885
884
  }
886
885
  default: {
887
- console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err);
888
- console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err.code);
886
+ //console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err);
887
+ //console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err.code);
889
888
  reject(err);
890
889
  break;
891
890
  }
@@ -921,8 +920,8 @@ class TXmlContentContainer {
921
920
  break;
922
921
  }
923
922
  default: {
924
- console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err);
925
- console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err.code);
923
+ //console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err);
924
+ //console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err.code);
926
925
  throw err;
927
926
  break;
928
927
  }
@@ -992,8 +991,8 @@ class TXmlContentContainer {
992
991
  break;
993
992
  }
994
993
  default: {
995
- console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err);
996
- console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err.code);
994
+ //console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err);
995
+ //console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err.code);
997
996
  reject(err);
998
997
  break;
999
998
  }
@@ -1040,8 +1039,8 @@ class TXmlContentContainer {
1040
1039
  break;
1041
1040
  }
1042
1041
  default: {
1043
- console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err);
1044
- console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err.code);
1042
+ //console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err);
1043
+ //console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err.code);
1045
1044
  throw err;
1046
1045
  break;
1047
1046
  }
@@ -1059,9 +1058,6 @@ class TXmlContentContainer {
1059
1058
 
1060
1059
  // === module exports block ===
1061
1060
 
1062
- //exports.DEF_XML_PARSE_OPTIONS = XML_DEF_PARSE_OPTIONS; // will deprecate
1063
- //exports.DEF_XML_ROOT_ETAG_NAME = XML_DEF_ROOT_ETAG_NAME; // will deprecate
1064
-
1065
1061
  exports.XML_DEF_PARSE_OPTIONS = XML_DEF_PARSE_OPTIONS;
1066
1062
  exports.XML_DEF_ROOT_ETAG_NAME = XML_DEF_ROOT_ETAG_NAME;
1067
1063
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/xml-lib-js",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "A library for handling an XML-documents",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -32,12 +32,12 @@
32
32
  "#lib/*": "./lib/*"
33
33
  },
34
34
  "dependencies": {
35
- "@ygracs/bsfoc-lib-js": "^0.1.3",
35
+ "@ygracs/bsfoc-lib-js": "^0.2.0",
36
36
  "@ygracs/xml-js6": "^0.0.3-b",
37
- "@ygracs/xobj-lib-js": "^0.0.14-rc4"
37
+ "@ygracs/xobj-lib-js": "^0.1.1"
38
38
  },
39
39
  "devDependencies": {
40
- "jest": "^29.6.1",
40
+ "jest": "^29.7.0",
41
41
  "minimist": "^1.2.8"
42
42
  }
43
43
  }