@ygracs/xobj-lib-js 0.0.13
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 +29 -0
- package/LICENSE +9 -0
- package/README.md +9 -0
- package/doc/xObj.md +339 -0
- package/index.js +14 -0
- package/lib/xObj-lib.js +548 -0
- package/package.json +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#### *v0.0.13*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.2.
|
|
6
|
+
|
|
7
|
+
#### *v0.0.12*
|
|
8
|
+
|
|
9
|
+
Pre-release version.
|
|
10
|
+
|
|
11
|
+
> - some fixes in 'xObj-lib.js' module;
|
|
12
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.1.
|
|
13
|
+
|
|
14
|
+
#### *v0.0.11*
|
|
15
|
+
|
|
16
|
+
Pre-release version.
|
|
17
|
+
|
|
18
|
+
> - remove dependency on `@ygracs/xml-js6` module;
|
|
19
|
+
> - fixed exports in `$module/index.js`.
|
|
20
|
+
|
|
21
|
+
#### *v0.0.10*
|
|
22
|
+
|
|
23
|
+
Pre-release version.
|
|
24
|
+
|
|
25
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.0.
|
|
26
|
+
|
|
27
|
+
#### *v0.0.1-v0.0.9*
|
|
28
|
+
|
|
29
|
+
Pre-release version.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2022 Yuri Grachev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
|***rev.*:**|0.1.0|
|
|
2
|
+
|:---|---:|
|
|
3
|
+
|***date***:|2022-05-18|
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This module provide a helper functions for object manipulation. It was primarily written to work with a XML-parse provided by a [`xml-js`](https://www.npmjs.com/package/xml-js) module for 'Node.js' running in "compact" mode.
|
|
8
|
+
|
|
9
|
+
> Note: for more see `xObj.md` in the project `doc` directory.
|
package/doc/xObj.md
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
>|***rev.*:**|0.1.10|
|
|
2
|
+
>|:---|---:|
|
|
3
|
+
>|date:|2022-05-23|
|
|
4
|
+
|
|
5
|
+
## Intoduction
|
|
6
|
+
|
|
7
|
+
This paper describes a functions provided by `xObj.js` module.
|
|
8
|
+
|
|
9
|
+
> Note: This module was primarily written to deal with a XML-parse provided by a [`xml-js`](https://www.npmjs.com/package/xml-js) module for 'Node.js' running in "compact" mode.
|
|
10
|
+
|
|
11
|
+
## Content
|
|
12
|
+
|
|
13
|
+
### Base constants
|
|
14
|
+
|
|
15
|
+
|name|type|value|
|
|
16
|
+
|:---|---|---:|
|
|
17
|
+
|XOBJ_DEF_PARAM_TNAME|`string`|`__text`|
|
|
18
|
+
|XOBJ_DEF_ATTR_TNAME|`string`|`__attr`|
|
|
19
|
+
|DEF_XML_PARSE_OPTIONS|`object`|---|
|
|
20
|
+
|
|
21
|
+
#### **DEF\_XML\_PARSE_OPTIONS**
|
|
22
|
+
|
|
23
|
+
This constant object provided by the module contains a default settings of options for XML-parser module used within.
|
|
24
|
+
|
|
25
|
+
The settings listed in the table below:
|
|
26
|
+
|
|
27
|
+
|name|type|value|
|
|
28
|
+
|:---|---|:---|
|
|
29
|
+
|compact|`boolean`|`true`|
|
|
30
|
+
|declarationKey|`string`|`__decl`|
|
|
31
|
+
|attributesKey|`string`|`__attr`|
|
|
32
|
+
|textKey|`string`|`__text`|
|
|
33
|
+
|commentKey|`string`|`__note`|
|
|
34
|
+
|cdataKey|`string`|`__cdata`|
|
|
35
|
+
|nameKey|`string`|`__name`|
|
|
36
|
+
|typeKey|`string`|`__type`|
|
|
37
|
+
|parentKey|`string`|`parent`|
|
|
38
|
+
|elementsKey|`string`|`items`|
|
|
39
|
+
|ignoreDeclaration|`boolean`|`false`|
|
|
40
|
+
|ignoreDocType|`boolean`|`false`|
|
|
41
|
+
|ignoreInstractions|`boolean`|`false`|
|
|
42
|
+
|ignoreText|`boolean`|`false`|
|
|
43
|
+
|ignoreComments|`boolean`|`false`|
|
|
44
|
+
|ignoreCData|`boolean`|`false`|
|
|
45
|
+
|fullTagEmptyElement|`boolean`|`true`|
|
|
46
|
+
|addParent|`boolean`|`false`|
|
|
47
|
+
|trim|`boolean`|`true`|
|
|
48
|
+
|spaces|`number`|`2`|
|
|
49
|
+
|
|
50
|
+
### Base functions for read and write an object parameter
|
|
51
|
+
|
|
52
|
+
> Note:
|
|
53
|
+
> If a `key` parameter given to the function is `undefined` or is not a type of `string`, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`
|
|
54
|
+
>
|
|
55
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
56
|
+
|
|
57
|
+
#### **readXObjParam(object\[, key])**
|
|
58
|
+
|
|
59
|
+
This function returns a value of an object parameter. The value is of a `string` type.
|
|
60
|
+
|
|
61
|
+
#### **readXObjParamAsBool(object\[, defValue \[, key]])**
|
|
62
|
+
|
|
63
|
+
This function reads a value of an object parameter and returns it as a `boolean`.
|
|
64
|
+
|
|
65
|
+
The `defValue` must be of a `boolean` type, if else the `false` is used.
|
|
66
|
+
|
|
67
|
+
#### **readXObjParamAsNum(object\[, defValue \[, key])**
|
|
68
|
+
|
|
69
|
+
This function reads a value of an object parameter and returns it as a `number`.
|
|
70
|
+
|
|
71
|
+
The `defValue` must be of a `number` type, if else the `0` is used.
|
|
72
|
+
|
|
73
|
+
#### **readXObjParamAsStr(object\[, defValue \[, key])**
|
|
74
|
+
|
|
75
|
+
This function reads a value of an object parameter and returns it as a `string`.
|
|
76
|
+
|
|
77
|
+
The `defValue` must be of a `string` type, if else the empty string is used.
|
|
78
|
+
|
|
79
|
+
#### **readXObjParamAsIndex(object\[, key])**
|
|
80
|
+
|
|
81
|
+
This function reads a value of an object parameter and try to convert it to a valid index value. If function failed, `-1` is returned.
|
|
82
|
+
|
|
83
|
+
> Note: *for use in this case, index is validated as a non-negative integer number.*
|
|
84
|
+
|
|
85
|
+
#### **writeXObjParam(object, value\[, key])**
|
|
86
|
+
|
|
87
|
+
This function sets object parameter to a given value and if succeed returns `true`.
|
|
88
|
+
|
|
89
|
+
#### **writeXObjParamAsBool(object, value\[, defValue\[, key]])**
|
|
90
|
+
|
|
91
|
+
This function writes a given `boolean` value of an object parameter.
|
|
92
|
+
|
|
93
|
+
The `defValue` must be of a `boolean` type, if else the `false` is used.
|
|
94
|
+
|
|
95
|
+
#### **writeXObjParamAsNum(object, value\[, defValue\[, key]])**
|
|
96
|
+
|
|
97
|
+
This function writes a given `number` value of an object parameter.
|
|
98
|
+
|
|
99
|
+
The `defValue` must be of a `number` type, if else the `0` is used.
|
|
100
|
+
|
|
101
|
+
#### **writeXObjParamAsIndex(object, value\[, key])**
|
|
102
|
+
|
|
103
|
+
This function try to interpret a given value as a valid index value and, if succeed, writes it into an object parameter.
|
|
104
|
+
|
|
105
|
+
#### **writeXObjParamEx(object, value\[, defValue\[, key]])**
|
|
106
|
+
|
|
107
|
+
This function sets object parameter to a given value and if succeed returns `true`.
|
|
108
|
+
|
|
109
|
+
### Base functions for read or write object attributes
|
|
110
|
+
|
|
111
|
+
> Note:
|
|
112
|
+
> If a `key` parameter given to the function is `undefined` or is not a type of `string`, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`
|
|
113
|
+
>
|
|
114
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
115
|
+
>
|
|
116
|
+
> If an `attr` parameter given to the function is not a 'string' type, the function will trow a `TypeError` exception.
|
|
117
|
+
|
|
118
|
+
#### **readXObjAttr(object, attr\[, key])**
|
|
119
|
+
|
|
120
|
+
This function returns a value of an object attribute. The value is of a `string` type.
|
|
121
|
+
|
|
122
|
+
#### **readXObjAttrAsBool(object, attr\[, defValue\[, key]])**
|
|
123
|
+
|
|
124
|
+
This function reads a value of an object attribute and returns it as a `boolean`.
|
|
125
|
+
|
|
126
|
+
The `defValue` must be of a `boolean` type, if else the `false` is used.
|
|
127
|
+
|
|
128
|
+
#### **readXObjAttrAsNum(object, attr\[, defValue\[, key]])**
|
|
129
|
+
|
|
130
|
+
This function reads a value of an object attribute and returns it as a `number`.
|
|
131
|
+
|
|
132
|
+
The `defValue` must be of a `number` type, if else the `0` is used.
|
|
133
|
+
|
|
134
|
+
#### **readXObjAttrAsStr(object, attr\[, defValue\[, key]])**
|
|
135
|
+
|
|
136
|
+
This function returns a value of an object attribute. The value is of a `string` type.
|
|
137
|
+
|
|
138
|
+
The `defValue` must be of a `string` type, if else the empty string is used.
|
|
139
|
+
|
|
140
|
+
#### **readXObjAttrAsIndex(object, attr\[, key])**
|
|
141
|
+
|
|
142
|
+
This function reads a value of an object attribute and try to convert it to a valid index value. If function failed, `-1` is returned.
|
|
143
|
+
|
|
144
|
+
> Note: *for use in this case, index is validated as a non-negative integer number.*
|
|
145
|
+
|
|
146
|
+
#### **writeXObjAttr(object, attr, value\[, key])**
|
|
147
|
+
|
|
148
|
+
This function sets object attribute to a given value and if succeed returns `true`.
|
|
149
|
+
|
|
150
|
+
>Note: a value must be of a `string` type or can be converted to a string
|
|
151
|
+
>
|
|
152
|
+
|
|
153
|
+
#### **writeXObjAttrAsBool(object, attr, value\[, defValue\[, key]])**
|
|
154
|
+
|
|
155
|
+
This function writes a given `boolean` value of an object attribute.
|
|
156
|
+
|
|
157
|
+
The `defValue` must be of a `boolean` type, if else the `false` is used.
|
|
158
|
+
|
|
159
|
+
#### **writeXObjAttrAsNum(object, attr, value\[, defValue\[, key]])**
|
|
160
|
+
|
|
161
|
+
This function writes a given `number` value of an object attribute.
|
|
162
|
+
|
|
163
|
+
The `defValue` must be of a `number` type, if else the `0` is used.
|
|
164
|
+
|
|
165
|
+
#### **writeXObjAttrAsIndex(object, attr, value\[, key])**
|
|
166
|
+
|
|
167
|
+
This function try to interpret a given value as a valid index value and, if succeed, writes it into an object attribute.
|
|
168
|
+
|
|
169
|
+
#### **writeXObjAttrEx(object, attr, value\[, defValue\[, key]])**
|
|
170
|
+
|
|
171
|
+
This function sets object attribute to a given value and if succeed returns `true`.
|
|
172
|
+
|
|
173
|
+
### Special functions for read and write an object parameter
|
|
174
|
+
|
|
175
|
+
> Note:
|
|
176
|
+
> If a `key` parameter given to the function is `undefined` or is not a type of `string`, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`
|
|
177
|
+
>
|
|
178
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
179
|
+
|
|
180
|
+
#### **readXObjParamRaw(object\[, key])**
|
|
181
|
+
|
|
182
|
+
This is a special function that returns a value of an object parameter as "IT IS".
|
|
183
|
+
|
|
184
|
+
#### **writeXObjParamRaw(object, value\[, key])**
|
|
185
|
+
|
|
186
|
+
This is a special function that writes a given value of an object parameter as "IT IS".
|
|
187
|
+
|
|
188
|
+
### Special functions for read or write object attributes
|
|
189
|
+
|
|
190
|
+
> Note:
|
|
191
|
+
> If a `key` parameter given to the function is `undefined` or is not a type of `string`, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`
|
|
192
|
+
>
|
|
193
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
194
|
+
|
|
195
|
+
#### **readXObjAttrRaw(object, attr\[, key])**
|
|
196
|
+
|
|
197
|
+
This is a special function that returns a value of an object attribute as "IT IS".
|
|
198
|
+
|
|
199
|
+
#### **writeXObjAttrRaw(object, attr, value\[, key])**
|
|
200
|
+
|
|
201
|
+
This is a special function that writes a given value of an object attribute as "IT IS".
|
|
202
|
+
|
|
203
|
+
#### **getXObjAttributes(object, name)**
|
|
204
|
+
|
|
205
|
+
This is a special function that returns an object which represents a set of the element attributes for a given object or `null` if failed.
|
|
206
|
+
|
|
207
|
+
### Other functions
|
|
208
|
+
|
|
209
|
+
#### **getXObjElement(object, name)**
|
|
210
|
+
|
|
211
|
+
This function returns an element from a given object by its name or `null` if that element not found.
|
|
212
|
+
|
|
213
|
+
> the function will trow a `TypeError` if:
|
|
214
|
+
> - `object` parameter is not a plain object;
|
|
215
|
+
> - `name` parameter is not a non-empty string.
|
|
216
|
+
|
|
217
|
+
#### **insertXObjElement(object, name\[, options])**
|
|
218
|
+
|
|
219
|
+
This function inserts an empty element named by a `name` parameter into a given object. If succeed the element will be returned or `null` in opposite.
|
|
220
|
+
|
|
221
|
+
> the function will trow a `TypeError` if:
|
|
222
|
+
> - `object` parameter is not a plain object;
|
|
223
|
+
> - `name` parameter is not a non-empty string.
|
|
224
|
+
|
|
225
|
+
An `options.force` parameter modifies the functions behavoir as follows:
|
|
226
|
+
- if not given it is set to `false`(default value);
|
|
227
|
+
- when set to `true`, the addressed element will be replaced with an empty element.
|
|
228
|
+
- when set to `false`, if the target element exists and is not a type of an `object`, the function will failed.
|
|
229
|
+
|
|
230
|
+
An `options.rip_oldies` parameter applied only if `options.force` is `true`. And if set to `false` (default value), it prevents a replacement of an element which exists and has a type of an `object`.
|
|
231
|
+
|
|
232
|
+
#### **addXObjElement(object, name)**
|
|
233
|
+
|
|
234
|
+
This function adds an element given by `name` parameter to a members of the given objectand and returns an `object` that represents a status of the operation.
|
|
235
|
+
|
|
236
|
+
> the function will trow a `TypeError` if:
|
|
237
|
+
> - `object` parameter is not a plain object;
|
|
238
|
+
> - `name` parameter is not a non-empty string.
|
|
239
|
+
|
|
240
|
+
The status of an operation contains 2 fields:
|
|
241
|
+
|
|
242
|
+
- `isSucceed` - `boolean` value;
|
|
243
|
+
- `item` - an item which was added or a `null`.
|
|
244
|
+
|
|
245
|
+
#### **deleteXObjElement(object, name)**
|
|
246
|
+
|
|
247
|
+
This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
|
|
248
|
+
|
|
249
|
+
> the function will trow a `TypeError` if:
|
|
250
|
+
> - `object` parameter is not a plain object;
|
|
251
|
+
> - `name` parameter is not a non-empty string.
|
|
252
|
+
|
|
253
|
+
#### **renameXObjElement(object, oldName, newName)**
|
|
254
|
+
|
|
255
|
+
This function renames an element with a name `oldName` to a name `newName` for the given object. If succeed `true` is returned.
|
|
256
|
+
|
|
257
|
+
> the function will trow a `TypeError` if:
|
|
258
|
+
> - `object` parameter is not a plain object;
|
|
259
|
+
> - `oldName` or `newName` parameter is not a non-empty string.
|
|
260
|
+
|
|
261
|
+
### Experimental functions
|
|
262
|
+
|
|
263
|
+
> Note: Purpose of those functions will be discussed and some may be deprecate and make obsolete or functionality may be altered. So use it with cautions in mind.
|
|
264
|
+
|
|
265
|
+
#### **insertXObjElements(object, names_list\[, options])**
|
|
266
|
+
|
|
267
|
+
This function inserts an elements given by the `names_list` and return quantity of the inserted elements.
|
|
268
|
+
|
|
269
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
270
|
+
>
|
|
271
|
+
> For use of `options` parameter see `insertXObjElement`.
|
|
272
|
+
|
|
273
|
+
#### **insertXObjEList(object, name\[, options])**
|
|
274
|
+
|
|
275
|
+
This function inserts an elements list named by a `name` parameter into a given object. If succeed the list will be returned or `null` in opposite.
|
|
276
|
+
|
|
277
|
+
> the function will trow a `TypeError` if:
|
|
278
|
+
> - `object` parameter is not a plain object;
|
|
279
|
+
> - `name` parameter is not a non-empty string.
|
|
280
|
+
|
|
281
|
+
An `options.force` parameter modifies the functions behavoir as follows:
|
|
282
|
+
- if not given it is set to `false`(default value);
|
|
283
|
+
- when set to `true`, the addresssed element will be replaced with an empty elements list.
|
|
284
|
+
- when set to `false`, if the target element type is an `object`, the function will wrapps it in the list.
|
|
285
|
+
- when set to `false`, if the target element exists and is not a type of an `array` or an `object`, the function will failed.
|
|
286
|
+
|
|
287
|
+
An `options.rip_oldies` parameter applied only if `options.force` is `true`. And if set to `false` (default value), it prevents a replacement of an element which exists and has a type of an `array`.
|
|
288
|
+
|
|
289
|
+
#### **insertXObjEChain(object, names_list\[, options])**
|
|
290
|
+
|
|
291
|
+
This function inserts a chain of the elements listed by `names_list`. If succeed the last inserted element will be returned or `null` if failed.
|
|
292
|
+
|
|
293
|
+
> If an `object` parameter given to the function is not a plain object, the function will trow a `TypeError` exception.
|
|
294
|
+
>
|
|
295
|
+
> For use of `options` parameter see `insertXObjElement`.
|
|
296
|
+
|
|
297
|
+
#### **deleteXObjElementEx(object, name)**
|
|
298
|
+
|
|
299
|
+
This function deletes an element adderssed by `name` parameter from a given object and returns an `object` that represents a status of the operation.
|
|
300
|
+
|
|
301
|
+
> the function will trow a `TypeError` if:
|
|
302
|
+
> - `object` parameter is not a plain object;
|
|
303
|
+
> - `name` parameter is not a non-empty string.
|
|
304
|
+
|
|
305
|
+
The status of an operation contains 2 fields:
|
|
306
|
+
|
|
307
|
+
- `isSucceed` - `boolean` value;
|
|
308
|
+
- `item` - an item which was deleted (only for objects) or a `null`.
|
|
309
|
+
|
|
310
|
+
### Base class
|
|
311
|
+
|
|
312
|
+
#### **TXmlContentParseOptions**
|
|
313
|
+
|
|
314
|
+
This class implements an interface for handling XML-parse options.
|
|
315
|
+
|
|
316
|
+
##### class constructor
|
|
317
|
+
|
|
318
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
319
|
+
|
|
320
|
+
|name|type|default value|description|
|
|
321
|
+
|:---|---|---:|:---|
|
|
322
|
+
|`object`|---|---|a host object.|
|
|
323
|
+
|`options`|`object`|---|an options settings.|
|
|
324
|
+
|
|
325
|
+
##### class properties
|
|
326
|
+
|
|
327
|
+
The table below describes a properties of a `TXmlContentParseOptions` class:
|
|
328
|
+
|
|
329
|
+
|name|read only|description|
|
|
330
|
+
|:---|---|:---|
|
|
331
|
+
|settings|yes|presents a current options|
|
|
332
|
+
|xml2js|yes|returns an options for an XML-to-JS converter|
|
|
333
|
+
|js2xml|yes|returns an options for an JS-to-XML converter|
|
|
334
|
+
|
|
335
|
+
##### class methods (*static*)
|
|
336
|
+
|
|
337
|
+
###### **createNewOptionsSet(obj)**
|
|
338
|
+
|
|
339
|
+
This method transforms a given object to a set of accepted parser options.
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// [v0.1.007-20220524]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
//const xObj = require('./lib/xObj-lib.js');
|
|
6
|
+
|
|
7
|
+
// === module extra block (helper functions) ===
|
|
8
|
+
|
|
9
|
+
// === module main block ===
|
|
10
|
+
|
|
11
|
+
// === module exports block ===
|
|
12
|
+
|
|
13
|
+
//module.exports.xObj = xObj;
|
|
14
|
+
module.exports = require('./lib/xObj-lib.js');
|
package/lib/xObj-lib.js
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
// [v0.1.022-20220822]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
valueToIndex, readAsBool, readAsString,
|
|
7
|
+
readAsBoolEx, readAsNumberEx, isNotEmptyString, isNullOrUndef,
|
|
8
|
+
isArray, isObject, isPlainObject, readAsListS,
|
|
9
|
+
} = require('@ygracs/bsfoc-lib-js');
|
|
10
|
+
|
|
11
|
+
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
12
|
+
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
13
|
+
|
|
14
|
+
const XOBJ_TE_INVARG_EMSG = 'invalid argument';
|
|
15
|
+
const XOBJ_TE_NOBJ_EMSG = XOBJ_TE_INVARG_EMSG + '(an object is expected)';
|
|
16
|
+
const XOBJ_TE_NARR_EMSG = XOBJ_TE_INVARG_EMSG + '(an array is expected)';
|
|
17
|
+
const XOBJ_TE_NSTR_EMSG = XOBJ_TE_INVARG_EMSG + '(a string is expected)';
|
|
18
|
+
const XOBJ_TE_NPOBJ_EMSG = XOBJ_TE_INVARG_EMSG + '(a plain object is expected)';
|
|
19
|
+
const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
|
|
20
|
+
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
21
|
+
|
|
22
|
+
const DEF_XML_PARSE_OPTIONS = {
|
|
23
|
+
compact: true,
|
|
24
|
+
declarationKey: '__decl',
|
|
25
|
+
attributesKey: XOBJ_DEF_ATTR_TNAME,
|
|
26
|
+
textKey: XOBJ_DEF_PARAM_TNAME,
|
|
27
|
+
commentKey: '__note',
|
|
28
|
+
cdataKey: '__cdata',
|
|
29
|
+
nameKey: '__name',
|
|
30
|
+
typeKey: '__type',
|
|
31
|
+
parentKey: 'parent',
|
|
32
|
+
elementsKey: 'items',
|
|
33
|
+
ignoreDeclaration: false,
|
|
34
|
+
ignoreDocType: false,
|
|
35
|
+
ignoreInstractions: false,
|
|
36
|
+
ignoreText: false,
|
|
37
|
+
ignoreComments: false,
|
|
38
|
+
ignoreCData: false,
|
|
39
|
+
fullTagEmptyElement: true,
|
|
40
|
+
addParent: false,
|
|
41
|
+
trim: true,
|
|
42
|
+
spaces: 2,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// === module extra block (helper functions) ===
|
|
46
|
+
|
|
47
|
+
// === module main block (function definitions) ===
|
|
48
|
+
|
|
49
|
+
function getXObjElement(obj, name){
|
|
50
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
51
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
52
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
53
|
+
// TODO: check type of obj[key_name]
|
|
54
|
+
return obj[key] !== undefined ? obj[key] : null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function getXObjAttributes(obj, key_name = XOBJ_DEF_ATTR_TNAME){
|
|
58
|
+
return getXObjElement(obj, readAsString(key_name, XOBJ_DEF_ATTR_TNAME, true));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function insertXObjElement(obj, name, opt){
|
|
62
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
63
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
64
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
65
|
+
let force_act = false;
|
|
66
|
+
let rip_oldies = false;
|
|
67
|
+
if (typeof opt === 'boolean') {
|
|
68
|
+
force_act = opt;
|
|
69
|
+
} else if (isPlainObject(opt)) {
|
|
70
|
+
force_act = readAsBool(opt.force, false);
|
|
71
|
+
if (force_act) rip_oldies = readAsBool(opt.rip_oldies, false);
|
|
72
|
+
};
|
|
73
|
+
let isACCEPTED = false;
|
|
74
|
+
if (isNullOrUndef(obj[key])) {
|
|
75
|
+
obj[key] = {};
|
|
76
|
+
isACCEPTED = true;
|
|
77
|
+
} else if (force_act) {
|
|
78
|
+
if (rip_oldies || !isPlainObject(obj[key])) obj[key] = {};
|
|
79
|
+
isACCEPTED = true;
|
|
80
|
+
} else {
|
|
81
|
+
isACCEPTED = isPlainObject(obj[key]);
|
|
82
|
+
};
|
|
83
|
+
return isACCEPTED ? obj[key] : null;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function addXObjElement(obj, name){
|
|
87
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
88
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
89
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
90
|
+
let prop = obj[key];
|
|
91
|
+
let item = {};
|
|
92
|
+
let result = false;
|
|
93
|
+
// // TODO: consider wheter or not do ops if new_key exists
|
|
94
|
+
if (isNullOrUndef(prop)) {
|
|
95
|
+
obj[key] = {};
|
|
96
|
+
prop = obj[key];
|
|
97
|
+
result = true;
|
|
98
|
+
} else if (isPlainObject(prop)) {
|
|
99
|
+
obj[key] = [ prop, item ];
|
|
100
|
+
prop = item;
|
|
101
|
+
result = true;
|
|
102
|
+
} else if (isArray(prop)) {
|
|
103
|
+
prop.push(item);
|
|
104
|
+
prop = item;
|
|
105
|
+
result = true;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
isSucceed: result,
|
|
109
|
+
item: result ? prop : null,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
function deleteXObjElement(obj, name){
|
|
114
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
115
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
116
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
117
|
+
let result = false;
|
|
118
|
+
// // TODO: catch errors in strict mode
|
|
119
|
+
result = delete obj[key];
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
function deleteXObjElementEx(obj, name){
|
|
124
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
125
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
126
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
127
|
+
let prop = obj[key];
|
|
128
|
+
let result = false;
|
|
129
|
+
// // TODO: catch errors in strict mode
|
|
130
|
+
result = delete obj[key];
|
|
131
|
+
return {
|
|
132
|
+
isSucceed: result,
|
|
133
|
+
item: result && isObject(prop) ? prop : null,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
function renameXObjElement(obj, name, newName){
|
|
138
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
139
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
140
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
141
|
+
const newKey = typeof newName === 'string' ? newName.trim() : '';
|
|
142
|
+
if (newKey === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
143
|
+
let prop = obj[key];
|
|
144
|
+
let result = false;
|
|
145
|
+
// // TODO: consider wheter or not do ops if new_key exists
|
|
146
|
+
if (prop !== undefined) {
|
|
147
|
+
if (key === newKey) return isObject(prop) ? true : false;
|
|
148
|
+
// // TODO: catch errors in strict mode
|
|
149
|
+
result = delete obj[key];
|
|
150
|
+
if (result) {
|
|
151
|
+
obj[newKey] = isObject(prop) ? prop : {};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
return result;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
function readXObjParamRaw(obj, key_name = XOBJ_DEF_PARAM_TNAME){
|
|
158
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
159
|
+
key_name = readAsString(key_name, XOBJ_DEF_PARAM_TNAME, true);
|
|
160
|
+
return isNotEmptyString(key_name) ? obj[key_name] : undefined;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function writeXObjParamRaw(obj, value, key_name = XOBJ_DEF_PARAM_TNAME){
|
|
164
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
165
|
+
key_name = readAsString(key_name, XOBJ_DEF_PARAM_TNAME, true);
|
|
166
|
+
let isACCEPTED = isNotEmptyString(key_name);
|
|
167
|
+
if (isACCEPTED) obj[key_name] = value;
|
|
168
|
+
return isACCEPTED;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function readXObjAttrRaw(obj, attr, key_name = XOBJ_DEF_ATTR_TNAME){
|
|
172
|
+
const attrName = typeof attr === 'string' ? attr.trim() : '';
|
|
173
|
+
if (attrName === '') throw new TypeError(XOBJ_TE_ANES_EMSG);
|
|
174
|
+
obj = getXObjElement(obj, readAsString(key_name, XOBJ_DEF_ATTR_TNAME, true));
|
|
175
|
+
return isPlainObject(obj) ? obj[attrName] : undefined ;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function writeXObjAttrRaw(obj, attr, value, key_name = XOBJ_DEF_ATTR_TNAME){
|
|
179
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
180
|
+
const attrName = typeof attr === 'string' ? attr.trim() : '';
|
|
181
|
+
if (attrName === '') throw new TypeError(XOBJ_TE_ANES_EMSG);
|
|
182
|
+
key_name = readAsString(key_name, XOBJ_DEF_ATTR_TNAME, true);
|
|
183
|
+
let isACCEPTED = isNotEmptyString(key_name);
|
|
184
|
+
if (isACCEPTED) {
|
|
185
|
+
if (!isPlainObject(obj[key_name])) obj[key_name] = {};
|
|
186
|
+
obj[key_name][attrName] = value;
|
|
187
|
+
};
|
|
188
|
+
return isACCEPTED;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
function readXObjParam(obj, defKey){
|
|
192
|
+
const param = readXObjParamRaw(obj, defKey);
|
|
193
|
+
return readAsString(param, {
|
|
194
|
+
useTrim: false,
|
|
195
|
+
numberToString: true,
|
|
196
|
+
boolToString: true,
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
function readXObjParamAsBool(obj, defValue = false, defKey){
|
|
201
|
+
const param = readXObjParamRaw(obj, defKey);
|
|
202
|
+
return readAsBoolEx(param, defValue);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
function readXObjParamAsNum(obj, defValue = 0, defKey){
|
|
206
|
+
const param = readXObjParamRaw(obj, defKey);
|
|
207
|
+
return readAsNumberEx(param, defValue);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
function readXObjParamAsStr(obj, defValue = '', defKey){
|
|
211
|
+
const param = readXObjParamRaw(obj, defKey);
|
|
212
|
+
return readAsString(param, defValue, {
|
|
213
|
+
useTrim: false,
|
|
214
|
+
numberToString: true,
|
|
215
|
+
boolToString: true,
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
function readXObjParamAsIndex(obj, defKey){
|
|
220
|
+
return valueToIndex(readXObjParamRaw(obj, defKey));
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
function writeXObjParam(obj, value, defKey){
|
|
224
|
+
const _value = readAsString(value, {
|
|
225
|
+
useTrim: false,
|
|
226
|
+
numberToString: true,
|
|
227
|
+
boolToString: true,
|
|
228
|
+
});
|
|
229
|
+
return writeXObjParamRaw(obj, _value, defKey);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
function writeXObjParamAsBool(obj, value, defValue = false, defKey){
|
|
233
|
+
const _value = readAsBoolEx(value, defValue).toString();
|
|
234
|
+
return writeXObjParamRaw(obj, _value, defKey);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
function writeXObjParamAsNum(obj, value, defValue = 0, defKey){
|
|
238
|
+
const _value = readAsNumberEx(value, defValue).toString();
|
|
239
|
+
return writeXObjParamRaw(obj, _value, defKey);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
function writeXObjParamAsIndex(obj, value, defKey){
|
|
243
|
+
const _value = valueToIndex(value).toString();
|
|
244
|
+
return writeXObjParamRaw(obj, _value, defKey);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
function writeXObjParamEx(obj, value, defValue, defKey){
|
|
248
|
+
const _defValue = readAsString(defValue, {
|
|
249
|
+
useTrim: false,
|
|
250
|
+
numberToString: true,
|
|
251
|
+
boolToString: true,
|
|
252
|
+
});
|
|
253
|
+
const _value = readAsString(value, _defValue, {
|
|
254
|
+
useTrim: false,
|
|
255
|
+
numberToString: true,
|
|
256
|
+
boolToString: true,
|
|
257
|
+
});
|
|
258
|
+
return writeXObjParamRaw(obj, _value, defKey);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
function readXObjAttr(obj, name, defKey){
|
|
262
|
+
const param = readXObjAttrRaw(obj, name, defKey);
|
|
263
|
+
return readAsString(param, {
|
|
264
|
+
useTrim: true,
|
|
265
|
+
numberToString: true,
|
|
266
|
+
boolToString: true,
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
function readXObjAttrAsBool(obj, name, defValue = false, defKey){
|
|
271
|
+
const param = readXObjAttrRaw(obj, name, defKey);
|
|
272
|
+
return readAsBoolEx(param, defValue);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
function readXObjAttrAsNum(obj, name, defValue = 0, defKey){
|
|
276
|
+
const param = readXObjAttrRaw(obj, name, defKey);
|
|
277
|
+
return readAsNumberEx(param, defValue);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function readXObjAttrAsStr(obj, name, defValue = '', defKey){
|
|
281
|
+
const param = readXObjAttrRaw(obj, name, defKey);
|
|
282
|
+
return readAsString(param, defValue, {
|
|
283
|
+
useTrim: true,
|
|
284
|
+
numberToString: true,
|
|
285
|
+
boolToString: true,
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
function readXObjAttrAsIndex(obj, name, defKey){
|
|
290
|
+
return valueToIndex(readXObjAttrRaw(obj, name, defKey));
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
function writeXObjAttr(obj, name, value, defKey){
|
|
294
|
+
const _value = readAsString(value, {
|
|
295
|
+
useTrim: true,
|
|
296
|
+
numberToString: true,
|
|
297
|
+
boolToString: true,
|
|
298
|
+
});
|
|
299
|
+
return writeXObjAttrRaw(obj, name, _value, defKey);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
function writeXObjAttrAsBool(obj, name, value, defValue = false, defKey){
|
|
303
|
+
const _value = readAsBoolEx(value, defValue).toString();
|
|
304
|
+
return writeXObjAttrRaw(obj, name, _value, defKey);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
function writeXObjAttrAsNum(obj, name, value, defValue = 0, defKey){
|
|
308
|
+
const _value = readAsNumberEx(value, defValue).toString();
|
|
309
|
+
return writeXObjAttrRaw(obj, name, _value, defKey);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
function writeXObjAttrAsIndex(obj, name, value, defKey){
|
|
313
|
+
const _value = valueToIndex(value).toString();
|
|
314
|
+
return writeXObjAttrRaw(obj, name, _value, defKey);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
function writeXObjAttrEx(obj, name, value, defValue, defKey){
|
|
318
|
+
const _defValue = readAsString(defValue, {
|
|
319
|
+
useTrim: true,
|
|
320
|
+
numberToString: true,
|
|
321
|
+
boolToString: true,
|
|
322
|
+
});
|
|
323
|
+
const _value = readAsString(value, _defValue, {
|
|
324
|
+
useTrim: true,
|
|
325
|
+
numberToString: true,
|
|
326
|
+
boolToString: true,
|
|
327
|
+
});
|
|
328
|
+
return writeXObjAttrRaw(obj, name, _value, defKey);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
function insertXObjElements(obj, ...args){
|
|
332
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
333
|
+
let opt = {};
|
|
334
|
+
let count = 0;
|
|
335
|
+
let args_len = args.length;
|
|
336
|
+
if (args_len > 0) {
|
|
337
|
+
let pos = args_len-1;
|
|
338
|
+
if (typeof args[pos] === 'boolean') {
|
|
339
|
+
opt.force = args.pop();
|
|
340
|
+
} else if (isPlainObject(args[pos])) {
|
|
341
|
+
opt = args.pop();
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
const key_names = readAsListS({
|
|
345
|
+
trim: true,
|
|
346
|
+
keep_empty: false,
|
|
347
|
+
}, ...args);
|
|
348
|
+
for (let key_name of key_names) {
|
|
349
|
+
if (insertXObjElement(obj, key_name, opt) !== null) count++;
|
|
350
|
+
};
|
|
351
|
+
return count;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
function insertXObjEList(obj, name, opt){
|
|
355
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
356
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
357
|
+
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
358
|
+
let force_act = false;
|
|
359
|
+
let rip_oldies = false;
|
|
360
|
+
if (typeof opt === 'boolean') {
|
|
361
|
+
force_act = opt;
|
|
362
|
+
} else if (isPlainObject(opt)) {
|
|
363
|
+
force_act = readAsBool(opt.force, false);
|
|
364
|
+
if (force_act) rip_oldies = readAsBool(opt.rip_oldies, false);
|
|
365
|
+
};
|
|
366
|
+
let isACCEPTED = false;
|
|
367
|
+
if (isNullOrUndef(obj[key])) {
|
|
368
|
+
obj[key] = [];
|
|
369
|
+
isACCEPTED = true;
|
|
370
|
+
} else if (force_act) {
|
|
371
|
+
if (rip_oldies || !isArray(obj[key])) obj[key] = [];
|
|
372
|
+
isACCEPTED = true;
|
|
373
|
+
} else {
|
|
374
|
+
isACCEPTED = isArray(obj[key]);
|
|
375
|
+
if (!isACCEPTED && isPlainObject(obj[key])) {
|
|
376
|
+
obj[key] = [ obj[key] ];
|
|
377
|
+
isACCEPTED = true;
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
return isACCEPTED ? obj[key] : null;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
function insertXObjEChain(obj, ...args){
|
|
384
|
+
if (!isPlainObject(obj)) throw new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
385
|
+
let opt = {};
|
|
386
|
+
let args_len = args.length;
|
|
387
|
+
if (args_len > 0) {
|
|
388
|
+
let pos = args_len-1;
|
|
389
|
+
if (typeof args[pos] === 'boolean') {
|
|
390
|
+
opt.force = args.pop();
|
|
391
|
+
} else if (isPlainObject(args[pos])) {
|
|
392
|
+
opt = args.pop();
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
let key_names = readAsListS({
|
|
396
|
+
trim: true,
|
|
397
|
+
keep_empty: false,
|
|
398
|
+
}, ...args);
|
|
399
|
+
let curObj = obj;
|
|
400
|
+
let isSUCCEED = false;
|
|
401
|
+
for (let key_name of key_names) {
|
|
402
|
+
obj = insertXObjElement(obj, key_name, opt);
|
|
403
|
+
isSUCCEED = isPlainObject(obj);
|
|
404
|
+
if (!isSUCCEED) break;
|
|
405
|
+
curObj = obj;
|
|
406
|
+
};
|
|
407
|
+
return isSUCCEED ? curObj : null;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// === module main block (class definitions) ===
|
|
411
|
+
|
|
412
|
+
class TXmlContentParseOptions {
|
|
413
|
+
#_options = null;
|
|
414
|
+
|
|
415
|
+
constructor(param){
|
|
416
|
+
this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
get settings(){ return this.#_options }
|
|
420
|
+
|
|
421
|
+
get xml2js(){
|
|
422
|
+
let _settings = this.#_options;
|
|
423
|
+
return {
|
|
424
|
+
compact: _settings.compact,
|
|
425
|
+
declarationKey: _settings.declarationKey,
|
|
426
|
+
attributesKey: _settings.attributesKey,
|
|
427
|
+
textKey: _settings.textKey,
|
|
428
|
+
commentKey: _settings.commentKey,
|
|
429
|
+
cdataKey: _settings.cdataKey,
|
|
430
|
+
nameKey: _settings.nameKey,
|
|
431
|
+
typeKey: _settings.typeKey,
|
|
432
|
+
parentKey: _settings.parentKey,
|
|
433
|
+
elementsKey: _settings.elementsKey,
|
|
434
|
+
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
435
|
+
ignoreDocType: _settings.ignoreDocType,
|
|
436
|
+
ignoreInstraction: _settings.ignoreInstractions,
|
|
437
|
+
ignoreText: _settings.ignoreText,
|
|
438
|
+
ignoreComment: _settings.ignoreComments,
|
|
439
|
+
ignoreCData: _settings.ignoreCData,
|
|
440
|
+
addParent: _settings.addParent,
|
|
441
|
+
trim: _settings.trim,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
get js2xml(){
|
|
446
|
+
let _settings = this.#_options;
|
|
447
|
+
return {
|
|
448
|
+
compact: _settings.compact,
|
|
449
|
+
declarationKey: _settings.declarationKey,
|
|
450
|
+
attributesKey: _settings.attributesKey,
|
|
451
|
+
textKey: _settings.textKey,
|
|
452
|
+
commentKey: _settings.commentKey,
|
|
453
|
+
cdataKey: _settings.cdataKey,
|
|
454
|
+
nameKey: _settings.nameKey,
|
|
455
|
+
typeKey: _settings.typeKey,
|
|
456
|
+
parentKey: _settings.parentKey,
|
|
457
|
+
elementsKey: _settings.elementsKey,
|
|
458
|
+
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
459
|
+
ignoreDocType: _settings.ignoreDocType,
|
|
460
|
+
ignoreInstraction: _settings.ignoreInstractions,
|
|
461
|
+
ignoreText: _settings.ignoreText,
|
|
462
|
+
ignoreComment: _settings.ignoreComments,
|
|
463
|
+
ignoreCData: _settings.ignoreCData,
|
|
464
|
+
fullTagEmptyElement: _settings.fullTagEmptyElement,
|
|
465
|
+
spaces: _settings.spaces,
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
static createNewOptionsSet(opt){
|
|
470
|
+
if (opt instanceof TXmlContentParseOptions) {
|
|
471
|
+
opt = opt.settings;
|
|
472
|
+
} else if (isPlainObject(opt)) {
|
|
473
|
+
opt = isPlainObject(opt.settings) ? opt.settings : opt;
|
|
474
|
+
} else {
|
|
475
|
+
opt = DEF_XML_PARSE_OPTIONS;
|
|
476
|
+
};
|
|
477
|
+
return {
|
|
478
|
+
compact: opt.compact,
|
|
479
|
+
declarationKey: opt.declarationKey,
|
|
480
|
+
attributesKey: opt.attributesKey,
|
|
481
|
+
textKey: opt.textKey,
|
|
482
|
+
commentKey: opt.commentKey,
|
|
483
|
+
cdataKey: opt.cdataKey,
|
|
484
|
+
nameKey: opt.nameKey,
|
|
485
|
+
typeKey: opt.typeKey,
|
|
486
|
+
parentKey: opt.parentKey,
|
|
487
|
+
elementsKey: opt.elementsKey,
|
|
488
|
+
ignoreDeclaration: opt.ignoreDeclaration,
|
|
489
|
+
ignoreDocType: opt.ignoreDocType,
|
|
490
|
+
ignoreInstractions: opt.ignoreInstractions,
|
|
491
|
+
ignoreText: opt.ignoreText,
|
|
492
|
+
ignoreComments: opt.ignoreComments,
|
|
493
|
+
ignoreCData: opt.ignoreCData,
|
|
494
|
+
fullTagEmptyElement: opt.fullTagEmptyElement,
|
|
495
|
+
addParent: opt.addParent,
|
|
496
|
+
trim: opt.trim,
|
|
497
|
+
spaces: opt.spaces,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// === module exports block ===
|
|
504
|
+
|
|
505
|
+
exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
506
|
+
exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
507
|
+
exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
508
|
+
|
|
509
|
+
exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
|
510
|
+
|
|
511
|
+
exports.readXObjParamRaw = readXObjParamRaw;
|
|
512
|
+
exports.readXObjParam = readXObjParam;
|
|
513
|
+
exports.readXObjParamAsBool = readXObjParamAsBool;
|
|
514
|
+
exports.readXObjParamAsNum = readXObjParamAsNum;
|
|
515
|
+
exports.readXObjParamAsStr = readXObjParamAsStr;
|
|
516
|
+
exports.readXObjParamAsIndex = readXObjParamAsIndex;
|
|
517
|
+
exports.writeXObjParamRaw = writeXObjParamRaw;
|
|
518
|
+
exports.writeXObjParam = writeXObjParam;
|
|
519
|
+
exports.writeXObjParamAsBool = writeXObjParamAsBool;
|
|
520
|
+
exports.writeXObjParamAsNum = writeXObjParamAsNum;
|
|
521
|
+
exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
|
|
522
|
+
exports.writeXObjParamEx = writeXObjParamEx;
|
|
523
|
+
|
|
524
|
+
exports.readXObjAttrRaw = readXObjAttrRaw;
|
|
525
|
+
exports.readXObjAttr = readXObjAttr;
|
|
526
|
+
exports.readXObjAttrAsBool = readXObjAttrAsBool;
|
|
527
|
+
exports.readXObjAttrAsNum = readXObjAttrAsNum;
|
|
528
|
+
exports.readXObjAttrAsStr = readXObjAttrAsStr;
|
|
529
|
+
exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
|
|
530
|
+
exports.writeXObjAttrRaw = writeXObjAttrRaw;
|
|
531
|
+
exports.writeXObjAttr = writeXObjAttr;
|
|
532
|
+
exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
|
|
533
|
+
exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
|
|
534
|
+
exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
|
|
535
|
+
exports.writeXObjAttrEx = writeXObjAttrEx;
|
|
536
|
+
|
|
537
|
+
exports.getXObjAttributes = getXObjAttributes;
|
|
538
|
+
|
|
539
|
+
exports.getXObjElement = getXObjElement;
|
|
540
|
+
exports.insertXObjElement = insertXObjElement;
|
|
541
|
+
exports.addXObjElement = addXObjElement;
|
|
542
|
+
exports.deleteXObjElement = deleteXObjElement;
|
|
543
|
+
exports.deleteXObjElementEx = deleteXObjElementEx;
|
|
544
|
+
exports.renameXObjElement = renameXObjElement;
|
|
545
|
+
|
|
546
|
+
exports.insertXObjElements = insertXObjElements;
|
|
547
|
+
exports.insertXObjEList = insertXObjEList;
|
|
548
|
+
exports.insertXObjEChain = insertXObjEChain;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ygracs/xobj-lib-js",
|
|
3
|
+
"version": "0.0.13",
|
|
4
|
+
"description": "A helper library to work with xml-js module",
|
|
5
|
+
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://gitlab.com/ygracs/xobj-lib-js.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"doc/xObj.md",
|
|
14
|
+
"lib/xObj-lib.js",
|
|
15
|
+
"index.js"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test-xobj": "jest xObj",
|
|
20
|
+
"test-xobj:c1": "jest xObj-lib.1",
|
|
21
|
+
"test-xobj:c2": "jest xObj-lib.2",
|
|
22
|
+
"test-xobj:c3": "jest xObj-lib.3",
|
|
23
|
+
"test-xobj:c4": "jest xObj-lib.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@ygracs/bsfoc-lib-js": "^0.1.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"jest": "^27.5.1"
|
|
30
|
+
}
|
|
31
|
+
}
|