@cntwg/xml-lib-js 0.0.24 → 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 +8 -0
- package/README.md +2 -4
- package/doc/xmldoc-lib.md +79 -49
- package/index.js +1 -6
- package/lib/xmldoc-lib.js +10 -14
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|***rev.*:**|0.1.
|
|
1
|
+
|***rev.*:**|0.1.4|
|
|
2
2
|
|:---|---:|
|
|
3
|
-
|***date***:|2023-
|
|
3
|
+
|***date***:|2023-09-19|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -26,8 +26,6 @@ xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` modu
|
|
|
26
26
|
|
|
27
27
|
+ `XML_DEF_ROOT_ETAG_NAME`;
|
|
28
28
|
+ `XML_DEF_PARSE_OPTIONS`;
|
|
29
|
-
+ `DEF_XML_ROOT_ETAG_NAME` (*will deprecate*);
|
|
30
|
-
+ `DEF_XML_PARSE_OPTIONS` (*will deprecate*).
|
|
31
29
|
|
|
32
30
|
- classes:
|
|
33
31
|
|
package/doc/xmldoc-lib.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.22|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2023-
|
|
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
|
-
### **
|
|
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,14 +37,10 @@ The settings listed in the table below:
|
|
|
37
37
|
|`trim`|`boolean`|`true`|
|
|
38
38
|
|`spaces`|`number`|`2`|
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### **DEF\_XML\_ROOT\_ETAG_NAME** or **XML\_DEF\_ROOT\_ETAG_NAME**
|
|
40
|
+
### **XML\_DEF\_ROOT\_ETAG_NAME**
|
|
43
41
|
|
|
44
42
|
This constant defines a default value for naming the root element for XML-document. Its value is `root`.
|
|
45
43
|
|
|
46
|
-
> WARNING: The constant `DEF\_XML\_ROOT\_ETAG_NAME` is deprecate. Use `XML\_DEF\_ROOT\_ETAG_NAME` instead.
|
|
47
|
-
|
|
48
44
|
## Module classes
|
|
49
45
|
|
|
50
46
|
### **TXmlContentParseOptions**
|
|
@@ -82,26 +78,32 @@ This class implements a proxy interface for handling attributes of an element.
|
|
|
82
78
|
|
|
83
79
|
#### class constructor
|
|
84
80
|
|
|
85
|
-
The class constructor creates a new instance of the class.
|
|
81
|
+
The class constructor creates a new instance of the class.
|
|
86
82
|
|
|
87
|
-
|
|
83
|
+
##### constructor parameters
|
|
84
|
+
|
|
85
|
+
The class constructor receives an arguments listed below:
|
|
86
|
+
|
|
87
|
+
|parameter name|value type|default value|description|
|
|
88
88
|
|:---|---|---:|:---|
|
|
89
89
|
|`object`|---|---|a host object that holds an attributes|
|
|
90
90
|
|`options`|`object`|---|an options settings|
|
|
91
91
|
|
|
92
|
+
> NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
|
|
93
|
+
|
|
94
|
+
##### `options` parameter
|
|
95
|
+
|
|
92
96
|
The `options` structure is listed below:
|
|
93
97
|
|
|
94
98
|
|option name|value type|default value|description|
|
|
95
99
|
|:---|---|---:|:---|
|
|
96
100
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
|
|
97
101
|
|
|
98
|
-
> NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
|
|
99
|
-
|
|
100
102
|
#### class properties
|
|
101
103
|
|
|
102
|
-
|name|read only|description|
|
|
103
|
-
|
|
104
|
-
|`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|
|
|
105
107
|
|
|
106
108
|
|
|
107
109
|
#### class methods
|
|
@@ -132,13 +134,19 @@ This class implements a proxy interface for an element.
|
|
|
132
134
|
|
|
133
135
|
#### class constructor
|
|
134
136
|
|
|
135
|
-
The class constructor creates a new instance of the class.
|
|
137
|
+
The class constructor creates a new instance of the class.
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
##### constructor parameters
|
|
140
|
+
|
|
141
|
+
The class constructor receives an arguments listed below:
|
|
142
|
+
|
|
143
|
+
|parameter name|value type|default value|description|
|
|
138
144
|
|:---|---|---:|:---|
|
|
139
145
|
|`object`|---|---|a host object|
|
|
140
146
|
|`options`|`object`|---|an options settings|
|
|
141
147
|
|
|
148
|
+
##### `options` parameter
|
|
149
|
+
|
|
142
150
|
The `options` structure is listed below:
|
|
143
151
|
|
|
144
152
|
|option name|value type|default value|description|
|
|
@@ -148,11 +156,11 @@ The `options` structure is listed below:
|
|
|
148
156
|
|
|
149
157
|
#### class properties
|
|
150
158
|
|
|
151
|
-
|property name|read only|description|
|
|
152
|
-
|
|
153
|
-
|`attributes`|yes|returns an attributes of the element|
|
|
154
|
-
|`name
|
|
155
|
-
|`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|
|
|
156
164
|
|
|
157
165
|
#### class methods
|
|
158
166
|
|
|
@@ -237,13 +245,19 @@ This class implements a proxy interface for a list of elements.
|
|
|
237
245
|
|
|
238
246
|
#### class constructor
|
|
239
247
|
|
|
240
|
-
The class constructor creates a new instance of the class.
|
|
248
|
+
The class constructor creates a new instance of the class.
|
|
241
249
|
|
|
242
|
-
|
|
250
|
+
##### constructor parameters
|
|
251
|
+
|
|
252
|
+
The class constructor receives an arguments listed below:
|
|
253
|
+
|
|
254
|
+
|parameter name|value type|default value|description|
|
|
243
255
|
|:---|---|---:|:---|
|
|
244
256
|
|`object`|---|---|a host object of an array type.|
|
|
245
257
|
|`options`|`object`|---|an options settings.|
|
|
246
258
|
|
|
259
|
+
##### `options` parameter
|
|
260
|
+
|
|
247
261
|
The `options` structure is listed below:
|
|
248
262
|
|
|
249
263
|
|option name|value type|default value|description|
|
|
@@ -255,7 +269,7 @@ The `options` structure is listed below:
|
|
|
255
269
|
#### class properties
|
|
256
270
|
|
|
257
271
|
|property name|property type|read only|description|
|
|
258
|
-
|
|
272
|
+
|:---|---|---|:---|
|
|
259
273
|
|`count`|`number`|yes|returns a quantity of the elements|
|
|
260
274
|
|`size`|`number`|yes|returns a quantity of the elements|
|
|
261
275
|
|`maxIndex`|`index`|yes|returns a last possible index of the elements|
|
|
@@ -337,13 +351,19 @@ This class implements a proxy interface for a document declaration element.
|
|
|
337
351
|
|
|
338
352
|
#### class constructor
|
|
339
353
|
|
|
340
|
-
The class constructor creates a new instance of the class.
|
|
354
|
+
The class constructor creates a new instance of the class.
|
|
341
355
|
|
|
342
|
-
|
|
356
|
+
##### constructor parameters
|
|
357
|
+
|
|
358
|
+
The class constructor receives an arguments listed below:
|
|
359
|
+
|
|
360
|
+
|parameter name|value type|default value|description|
|
|
343
361
|
|:---|---|---:|:---|
|
|
344
362
|
|`object`|`object`|---|a host object for the document content.|
|
|
345
363
|
|`options`|`object`|---|an options settings.|
|
|
346
364
|
|
|
365
|
+
##### `options` parameter
|
|
366
|
+
|
|
347
367
|
The `options` structure is listed below:
|
|
348
368
|
|
|
349
369
|
|option name|value type|default value|description|
|
|
@@ -353,7 +373,7 @@ The `options` structure is listed below:
|
|
|
353
373
|
#### class properties
|
|
354
374
|
|
|
355
375
|
|property name|property type|read only|description|
|
|
356
|
-
|
|
376
|
+
|:---|---|---|:---|
|
|
357
377
|
|`version`|`string`|no|returns a version of a XML|
|
|
358
378
|
|`encoding`|`string`|no|returns an encodings used by a document|
|
|
359
379
|
|
|
@@ -361,21 +381,27 @@ The `options` structure is listed below:
|
|
|
361
381
|
|
|
362
382
|
##### **init()**
|
|
363
383
|
|
|
364
|
-
This method initializes element with a default values.
|
|
384
|
+
This method initializes an element with a default values.
|
|
365
385
|
|
|
366
386
|
### **TXmlContentRootElement**
|
|
367
387
|
|
|
368
|
-
This class extends functionality of a `TXmlElementController` class.
|
|
388
|
+
This class extends a functionality of a `TXmlElementController` class.
|
|
369
389
|
|
|
370
390
|
#### class constructor
|
|
371
391
|
|
|
372
|
-
The class constructor creates a new instance of the class.
|
|
392
|
+
The class constructor creates a new instance of the class.
|
|
373
393
|
|
|
374
|
-
|
|
394
|
+
##### constructor parameters
|
|
395
|
+
|
|
396
|
+
The class constructor receives an arguments listed below:
|
|
397
|
+
|
|
398
|
+
|parameter name|value type|default value|description|
|
|
375
399
|
|:---|---|---:|:---|
|
|
376
400
|
|`object`|`object`|---|a host object for the document content|
|
|
377
401
|
|`options`|`object`|---|an options settings|
|
|
378
402
|
|
|
403
|
+
##### `options` parameter
|
|
404
|
+
|
|
379
405
|
The `options` structure is listed below:
|
|
380
406
|
|
|
381
407
|
|option name|value type|default value|description|
|
|
@@ -388,9 +414,9 @@ The `options` structure is listed below:
|
|
|
388
414
|
|
|
389
415
|
#### class properties
|
|
390
416
|
|
|
391
|
-
|name|read only|description|
|
|
392
|
-
|
|
393
|
-
|tagName
|
|
417
|
+
|property name|value type|read only|description|
|
|
418
|
+
|:---|---|---|:---|
|
|
419
|
+
|tagName|`string`|no||
|
|
394
420
|
|
|
395
421
|
#### class methods (*static*)
|
|
396
422
|
|
|
@@ -408,7 +434,13 @@ This class implements a proxy interface for manipulate a content of a document.
|
|
|
408
434
|
|
|
409
435
|
#### class constructor
|
|
410
436
|
|
|
411
|
-
The class constructor creates a new instance of the class.
|
|
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
|
|
412
444
|
|
|
413
445
|
The `options` structure is listed below:
|
|
414
446
|
|
|
@@ -422,9 +454,9 @@ The `options` structure is listed below:
|
|
|
422
454
|
|
|
423
455
|
#### class properties
|
|
424
456
|
|
|
425
|
-
|property name|read only|description|
|
|
426
|
-
|
|
427
|
-
|rootElement
|
|
457
|
+
|property name|value type|read only|description|
|
|
458
|
+
|:---|---|---|:---|
|
|
459
|
+
|rootElement||yes|returns a document root element|
|
|
428
460
|
|
|
429
461
|
#### class methods
|
|
430
462
|
|
|
@@ -436,12 +468,6 @@ This method clears a document content.
|
|
|
436
468
|
|
|
437
469
|
This method returns a document content as a string.
|
|
438
470
|
|
|
439
|
-
##### **saveToFile(src)**
|
|
440
|
-
|
|
441
|
-
This method saves a document content into a file addressed by `src`.
|
|
442
|
-
|
|
443
|
-
> This is `async` method.
|
|
444
|
-
|
|
445
471
|
##### **saveToFileSync(src)**
|
|
446
472
|
|
|
447
473
|
This method saves a document content into a file addressed by `src`.
|
|
@@ -450,13 +476,17 @@ This method saves a document content into a file addressed by `src`.
|
|
|
450
476
|
|
|
451
477
|
This method loads a document content from a string given by `str`.
|
|
452
478
|
|
|
453
|
-
##### **
|
|
479
|
+
##### **loadFromFileSync(src)**
|
|
454
480
|
|
|
455
481
|
This method loads a document content from a file addressed by `src`.
|
|
456
482
|
|
|
457
|
-
|
|
483
|
+
#### class methods (*async*)
|
|
458
484
|
|
|
459
|
-
##### **
|
|
485
|
+
##### **saveToFile(src)**
|
|
486
|
+
|
|
487
|
+
This method saves a document content into a file addressed by `src`.
|
|
488
|
+
|
|
489
|
+
##### **loadFromFile(src)**
|
|
460
490
|
|
|
461
491
|
This method loads a document content from a file addressed by `src`.
|
|
462
492
|
|
|
@@ -470,4 +500,4 @@ This method returns a document content as a string in the JSON-format.
|
|
|
470
500
|
|
|
471
501
|
This method binds a given object as a document content.
|
|
472
502
|
|
|
473
|
-
For `options` parameter details see the class
|
|
503
|
+
For `options` parameter details see the class constructor description.
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
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.
|
|
1
|
+
// [v0.1.069-20230926]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -587,9 +587,7 @@ class TXmlElementsListController {
|
|
|
587
587
|
const _options = isPlainObject(opt) ? opt : {};
|
|
588
588
|
let {
|
|
589
589
|
useClear,
|
|
590
|
-
load_as_new,
|
|
591
590
|
} = _options;
|
|
592
|
-
if (useClear === undefined) useClear = load_as_new;
|
|
593
591
|
if (typeof useClear !== 'boolean') useClear = true;
|
|
594
592
|
if (useClear) this.clear();
|
|
595
593
|
let count = this.count;
|
|
@@ -760,7 +758,7 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
760
758
|
}
|
|
761
759
|
|
|
762
760
|
set tagName(value){
|
|
763
|
-
value = readAsString(value,
|
|
761
|
+
value = readAsString(value, true);
|
|
764
762
|
this.#_options.rootETagName = isNotEmptyString(
|
|
765
763
|
value
|
|
766
764
|
) ? value : XML_DEF_ROOT_ETAG_NAME;
|
|
@@ -844,12 +842,10 @@ class TXmlContentContainer {
|
|
|
844
842
|
|
|
845
843
|
saveToXMLString(){
|
|
846
844
|
let result = '';
|
|
847
|
-
//let isERR = false;
|
|
848
845
|
try {
|
|
849
846
|
result = xmlParser.js2xml(this.#_content, this.#_parseOptions.js2xml);
|
|
850
847
|
} catch (err) {
|
|
851
848
|
//console.log('CHECK: TXmlContentContainer.saveToXMLString() => Error => '+err);
|
|
852
|
-
//isERR = true;
|
|
853
849
|
throw err;
|
|
854
850
|
};
|
|
855
851
|
return result;
|
|
@@ -887,8 +883,8 @@ class TXmlContentContainer {
|
|
|
887
883
|
break;
|
|
888
884
|
}
|
|
889
885
|
default: {
|
|
890
|
-
console.log('CHECK: TXmlContentContainer.saveToFile() => Error => '+err);
|
|
891
|
-
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);
|
|
892
888
|
reject(err);
|
|
893
889
|
break;
|
|
894
890
|
}
|
|
@@ -924,8 +920,8 @@ class TXmlContentContainer {
|
|
|
924
920
|
break;
|
|
925
921
|
}
|
|
926
922
|
default: {
|
|
927
|
-
console.log('CHECK: TXmlContentContainer.saveToFileSync() => Error => '+err);
|
|
928
|
-
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);
|
|
929
925
|
throw err;
|
|
930
926
|
break;
|
|
931
927
|
}
|
|
@@ -995,8 +991,8 @@ class TXmlContentContainer {
|
|
|
995
991
|
break;
|
|
996
992
|
}
|
|
997
993
|
default: {
|
|
998
|
-
console.log('CHECK: TXmlContentContainer.loadFromFile() => Error => '+err);
|
|
999
|
-
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);
|
|
1000
996
|
reject(err);
|
|
1001
997
|
break;
|
|
1002
998
|
}
|
|
@@ -1043,8 +1039,8 @@ class TXmlContentContainer {
|
|
|
1043
1039
|
break;
|
|
1044
1040
|
}
|
|
1045
1041
|
default: {
|
|
1046
|
-
console.log('CHECK: TXmlContentContainer.loadFromFileSync() => Error => '+err);
|
|
1047
|
-
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);
|
|
1048
1044
|
throw err;
|
|
1049
1045
|
break;
|
|
1050
1046
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntwg/xml-lib-js",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
35
|
+
"@ygracs/bsfoc-lib-js": "^0.2.0",
|
|
36
36
|
"@ygracs/xml-js6": "^0.0.3-b",
|
|
37
|
-
"@ygracs/xobj-lib-js": "^0.1.
|
|
37
|
+
"@ygracs/xobj-lib-js": "^0.1.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"jest": "^29.
|
|
40
|
+
"jest": "^29.7.0",
|
|
41
41
|
"minimist": "^1.2.8"
|
|
42
42
|
}
|
|
43
43
|
}
|