@ygracs/xobj-lib-js 0.2.0 → 0.2.2

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/doc/xObj.md CHANGED
@@ -1,790 +1,1191 @@
1
- >|***rev.*:**|0.1.36|
2
- >|:---|---:|
3
- >|date:|2024-09-15|
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 an object parameter value
51
-
52
- > Note:
53
- > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
54
-
55
- #### **readXObjParam(object\[, key])** => `string`
56
-
57
- This function returns a value of an object parameter. The value is of a `string` type.
58
-
59
- ##### ***exceptions***
60
-
61
- The function throws a `TypeError` exception in case:
62
-
63
- - code: `ERR_XOBJ_NPOBJ`
64
- + if `object` parameter is not an `Object` instance.
65
-
66
- #### **readXObjParamAsBool(object\[, defValue \[, key]])** => `boolean`
67
-
68
- This function reads a value of an object parameter and returns it as a `boolean`.
69
-
70
- The `defValue` must be of a `boolean` type, if else the `false` is used.
71
-
72
- ##### ***exceptions***
73
-
74
- The function throws a `TypeError` exception in case:
75
-
76
- - code: `ERR_XOBJ_NPOBJ`
77
- + if `object` parameter is not an `Object` instance.
78
-
79
- #### **readXObjParamAsNum(object\[, defValue \[, key])** => `number`
80
-
81
- This function reads a value of an object parameter and returns it as a `number`.
82
-
83
- The `defValue` must be of a `number` type, if else the `0` is used.
84
-
85
- ##### ***exceptions***
86
-
87
- The function throws a `TypeError` exception in case:
88
-
89
- - code: `ERR_XOBJ_NPOBJ`
90
- + if `object` parameter is not an `Object` instance.
91
-
92
- #### **readXObjParamAsIndex(object\[, key])** => `index`
93
-
94
- 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.
95
-
96
- > Note: *for use in this case, index is validated as a non-negative integer number.*
97
-
98
- ##### ***exceptions***
99
-
100
- The function throws a `TypeError` exception in case:
101
-
102
- - code: `ERR_XOBJ_NPOBJ`
103
- + if `object` parameter is not an `Object` instance.
104
-
105
- #### **readXObjParamAsStr(object\[, defValue \[, key])** => `string`
106
-
107
- > WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjParam`](#readxobjparamobject-key--string) or [`readXObjParamEx`](#readxobjparamexobject-opt-key--string) instead.*
108
-
109
- This function reads a value of an object parameter and returns it as a `string`.
110
-
111
- The `defValue` must be of a `string` type, if else the empty string is used.
112
-
113
- #### **readXObjParamEx(object\[, opt \[, key])** => `string`
114
-
115
- > since: \[v0.2.0]
116
-
117
- This function reads a value of an object parameter and returns it as a `string`.
118
-
119
- ##### ***parameters***
120
-
121
- The `opt` parameter must be:
122
- - a `string` - defines a default value;
123
- - an `object` - defines a set of options to transform a value.
124
-
125
- ##### ***exceptions***
126
-
127
- The function throws a `TypeError` exception in case:
128
-
129
- - code: `ERR_XOBJ_NPOBJ`
130
- + if `object` parameter is not an `Object` instance.
131
-
132
- ### Base functions for write an object parameter value
133
-
134
- > Note:
135
- > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
136
-
137
- #### **writeXObjParam(object, value\[, key])** => `boolean`
138
-
139
- This function sets object parameter to a given value and if succeed returns `true`.
140
-
141
- ##### ***exceptions***
142
-
143
- The function throws a `TypeError` exception in case:
144
-
145
- - code: `ERR_XOBJ_NPOBJ`
146
- + if `object` parameter is not an `Object` instance.
147
-
148
- #### **writeXObjParamAsBool(object, value\[, defValue\[, key]])** => `boolean`
149
-
150
- This function writes a given `boolean` value of an object parameter.
151
-
152
- The `defValue` must be of a `boolean` type, if else the `false` is used.
153
-
154
- ##### ***exceptions***
155
-
156
- The function throws a `TypeError` exception in case:
157
-
158
- - code: `ERR_XOBJ_NPOBJ`
159
- + if `object` parameter is not an `Object` instance.
160
-
161
- #### **writeXObjParamAsNum(object, value\[, defValue\[, key]])** => `boolean`
162
-
163
- This function writes a given `number` value of an object parameter.
164
-
165
- The `defValue` must be of a `number` type, if else the `0` is used.
166
-
167
- ##### ***exceptions***
168
-
169
- The function throws a `TypeError` exception in case:
170
-
171
- - code: `ERR_XOBJ_NPOBJ`
172
- + if `object` parameter is not an `Object` instance.
173
-
174
- #### **writeXObjParamAsIndex(object, value\[, key])** => `boolean`
175
-
176
- This function try to interpret a given value as a valid index value and, if succeed, writes it into an object parameter.
177
-
178
- ##### ***exceptions***
179
-
180
- The function throws a `TypeError` exception in case:
181
-
182
- - code: `ERR_XOBJ_NPOBJ`
183
- + if `object` parameter is not an `Object` instance.
184
-
185
- #### **writeXObjParamEx(object, value\[, opt\[, key]])** => `boolean`
186
-
187
- This function sets object parameter to a given value and if succeed returns `true`.
188
-
189
- ##### ***parameters***
190
-
191
- The `opt` parameter must be:
192
- - a `string` - defines a default value;
193
- - an `object` - defines a set of options to transform a value.
194
-
195
- ##### ***exceptions***
196
-
197
- The function throws a `TypeError` exception in case:
198
-
199
- - code: `ERR_XOBJ_NPOBJ`
200
- + if `object` parameter is not an `Object` instance.
201
-
202
- ### Base functions for read an object attributes value
203
-
204
- > Note:
205
- > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
206
-
207
- #### **readXObjAttr(object, attr\[, key])** => `string`
208
-
209
- This function returns a value of an object attribute. The value is of a `string` type.
210
-
211
- ##### ***exceptions***
212
-
213
- The function throws a `TypeError` exception in case:
214
-
215
- - code: `ERR_XOBJ_NPOBJ`
216
- + if `object` parameter is not an `Object` instance.
217
-
218
- #### **readXObjAttrAsBool(object, attr\[, defValue\[, key]])** => `boolean`
219
-
220
- This function reads a value of an object attribute and returns it as a `boolean`.
221
-
222
- The `defValue` must be of a `boolean` type, if else the `false` is used.
223
-
224
- ##### ***exceptions***
225
-
226
- The function throws a `TypeError` exception in case:
227
-
228
- - code: `ERR_XOBJ_NPOBJ`
229
- + if `object` parameter is not an `Object` instance.
230
-
231
- #### **readXObjAttrAsNum(object, attr\[, defValue\[, key]])** => `number`
232
-
233
- This function reads a value of an object attribute and returns it as a `number`.
234
-
235
- The `defValue` must be of a `number` type, if else the `0` is used.
236
-
237
- ##### ***exceptions***
238
-
239
- The function throws a `TypeError` exception in case:
240
-
241
- - code: `ERR_XOBJ_NPOBJ`
242
- + if `object` parameter is not an `Object` instance.
243
-
244
- #### **readXObjAttrAsIndex(object, attr\[, key])** => `index`
245
-
246
- 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.
247
-
248
- > Note: *for use in this case, index is validated as a non-negative integer number.*
249
-
250
- ##### ***exceptions***
251
-
252
- The function throws a `TypeError` exception in case:
253
-
254
- - code: `ERR_XOBJ_NPOBJ`
255
- + if `object` parameter is not an `Object` instance.
256
-
257
- #### **readXObjAttrAsStr(object, attr\[, defValue\[, key]])** => `string`
258
-
259
- > WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjAttr`](#readxobjattrobject-attr-key--string) or [`readXObjAttrEx`](#readxobjattrexobject-attr-opt-key--string) instead.*
260
-
261
- This function returns a value of an object attribute. The value is of a `string` type.
262
-
263
- The `defValue` must be of a `string` type, if else the empty string is used.
264
-
265
- #### **readXObjAttrEx(object, attr\[, opt\[, key]])** => `string`
266
-
267
- > since: \[v0.2.0]
268
-
269
- This function returns a value of an object attribute. The value is of a `string` type.
270
-
271
- ##### ***parameters***
272
-
273
- The `opt` parameter must be:
274
- - a `string` - defines a default value;
275
- - an `object` - defines a set of options to transform a value.
276
-
277
- ##### ***exceptions***
278
-
279
- The function throws a `TypeError` exception in case:
280
-
281
- - code: `ERR_XOBJ_NPOBJ`
282
- + if `object` parameter is not an `Object` instance.
283
-
284
- ### Base functions for write an object attributes value
285
-
286
- > Note:
287
- > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
288
-
289
- #### **writeXObjAttr(object, attr, value\[, key])** => `boolean`
290
-
291
- This function sets object attribute to a given value and if succeed returns `true`.
292
-
293
- >Note: a value must be of a `string` type or can be converted to a string
294
-
295
- ##### ***exceptions***
296
-
297
- The function throws a `TypeError` exception in case:
298
-
299
- - code: `ERR_XOBJ_NPOBJ`
300
- + if `object` parameter is not an `Object` instance.
301
-
302
- #### **writeXObjAttrAsBool(object, attr, value\[, defValue\[, key]])** => `boolean`
303
-
304
- This function writes a given `boolean` value of an object attribute.
305
-
306
- The `defValue` must be of a `boolean` type, if else the `false` is used.
307
-
308
- ##### ***exceptions***
309
-
310
- The function throws a `TypeError` exception in case:
311
-
312
- - code: `ERR_XOBJ_NPOBJ`
313
- + if `object` parameter is not an `Object` instance.
314
-
315
- #### **writeXObjAttrAsNum(object, attr, value\[, defValue\[, key]])** => `boolean`
316
-
317
- This function writes a given `number` value of an object attribute.
318
-
319
- The `defValue` must be of a `number` type, if else the `0` is used.
320
-
321
- ##### ***exceptions***
322
-
323
- The function throws a `TypeError` exception in case:
324
-
325
- - code: `ERR_XOBJ_NPOBJ`
326
- + if `object` parameter is not an `Object` instance.
327
-
328
- #### **writeXObjAttrAsIndex(object, attr, value\[, key])** => `boolean`
329
-
330
- This function try to interpret a given value as a valid index value and, if succeed, writes it into an object attribute.
331
-
332
- ##### ***exceptions***
333
-
334
- The function throws a `TypeError` exception in case:
335
-
336
- - code: `ERR_XOBJ_NPOBJ`
337
- + if `object` parameter is not an `Object` instance.
338
-
339
- #### **writeXObjAttrEx(object, attr, value\[, opt\[, key]])** => `boolean`
340
-
341
- This function sets object attribute to a given value and if succeed returns `true`.
342
-
343
- ##### ***parameters***
344
-
345
- The `opt` parameter must be:
346
- - a `string` - defines a default value;
347
- - an `object` - defines a set of options to transform a value.
348
-
349
- ##### ***exceptions***
350
-
351
- The function throws a `TypeError` exception in case:
352
-
353
- - code: `ERR_XOBJ_NPOBJ`
354
- + if `object` parameter is not an `Object` instance.
355
-
356
- ### Special functions for read and write an object parameter value
357
-
358
- #### **readXObjParamRaw(object\[, key])** => `any`
359
-
360
- This is a special function that returns a value of an object parameter as "IT IS".
361
-
362
- > NOTE:
363
- > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
364
-
365
- ##### ***exceptions***
366
-
367
- The function throws a `TypeError` exception in case:
368
-
369
- - code: `ERR_XOBJ_NPOBJ`
370
- + if `object` parameter is not an `Object` instance;
371
- - code: `ERR_XOBJ_NSTR`
372
- + if `key` parameter given and is not a type of a `string`.
373
-
374
- #### **writeXObjParamRaw(object, value\[, key])** => `boolean`
375
-
376
- This is a special function that writes a given value of an object parameter as "IT IS".
377
-
378
- > NOTE:
379
- > - If `value` parameter not given, the function failed.
380
- > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
381
-
382
- ##### ***exceptions***
383
-
384
- The function throws a `TypeError` exception in case:
385
-
386
- - code: `ERR_XOBJ_NPOBJ`
387
- + if `object` parameter is not an `Object` instance;
388
- - code: `ERR_XOBJ_NSTR`
389
- + if `key` parameter given and is not a type of a `string`.
390
-
391
- ### Special functions for read or write object attributes value
392
-
393
- #### **readXObjAttrRaw(object, attr\[, key])** => `any`
394
-
395
- This is a special function that returns a value of an object attribute as "IT IS".
396
-
397
- > NOTE:
398
- > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
399
-
400
- ##### ***exceptions***
401
-
402
- The function throws a `TypeError` exception in case:
403
-
404
- - code: `ERR_XOBJ_NPOBJ`
405
- + if `object` parameter is not an `Object` instance;
406
- - code: `ERR_XOBJ_NSTR`
407
- + if `attr` parameter given and is not a type of a `string`;
408
- + if `key` parameter given and is not a type of a `string`.
409
-
410
- #### **writeXObjAttrRaw(object, attr, value\[, key])** => `boolean`
411
-
412
- This is a special function that writes a given value of an object attribute as "IT IS".
413
-
414
- > NOTE:
415
- > - If `value` parameter not given, the function failed.
416
- > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
417
-
418
- ##### ***exceptions***
419
-
420
- The function throws a `TypeError` exception in case:
421
-
422
- - code: `ERR_XOBJ_NPOBJ`
423
- + if `object` parameter is not an `Object` instance;
424
- - code: `ERR_XOBJ_NSTR`
425
- + if `attr` parameter given and is not a type of a `string`;
426
- + if `key` parameter given and is not a type of a `string`.
427
-
428
- ### Other functions for deal with an object attributes
429
-
430
- > Note:
431
- > If a `key` parameter given not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
432
-
433
- #### **getXObjAttributes(object\[, key])** => `?object`
434
-
435
- This function returns an object which represents a set of the element attributes for a given object or `null` if failed.
436
-
437
- ##### ***exceptions***
438
-
439
- The function throws a `TypeError` exception in case:
440
-
441
- - code: `ERR_XOBJ_NPOBJ`
442
- + if `object` parameter is not an `Object` instance.
443
-
444
- #### **checkXObjAttribute(object, attr\[, key])** => `boolean`
445
-
446
- This function tries to check whether or not an attribute with a name given by `attr` parameter exists for the element given by `object` parameter. If attribute exists `true` is returned.
447
-
448
- ##### ***exceptions***
449
-
450
- The function throws a `TypeError` exception in case:
451
-
452
- - code: `ERR_XOBJ_NPOBJ`
453
- + if `object` parameter is not an `Object` instance;
454
- - code: `ERR_XOBJ_NSTR`
455
- + if `attr` parameter given and is not a type of a `string`;
456
- + if `key` parameter given and is not a type of a `string`.
457
-
458
- #### **deleteXObjAttribute(object, attr\[, key])** => `boolean`
459
-
460
- This function tries to delete an attribute with a name given by `attr` parameter. If succeed `true` is returned.
461
-
462
- ##### ***exceptions***
463
-
464
- The function throws a `TypeError` exception in case:
465
-
466
- - code: `ERR_XOBJ_NPOBJ`
467
- + if `object` parameter is not an `Object` instance;
468
- - code: `ERR_XOBJ_NSTR`
469
- + if `attr` parameter given and is not a type of a `string`;
470
- + if `key` parameter given and is not a type of a `string`.
471
-
472
- #### **renameXObjAttribute(object, attr, newName\[, key])** => `boolean`
473
-
474
- > since: \[v0.2.0]
475
-
476
- This function tries to rename an attribute with a name given by `attr` parameter to its new name. If succeed `true` is returned.
477
-
478
- ##### ***exceptions***
479
-
480
- The function throws a `TypeError` exception in case:
481
-
482
- - code: `ERR_XOBJ_NPOBJ`
483
- + if `object` parameter is not an `Object` instance;
484
- - code: `ERR_XOBJ_NSTR`
485
- + if `attr` parameter given and is not a type of a `string`;
486
- + if `newName` parameter given and is not a type of a `string`;
487
- + if `key` parameter given and is not a type of a `string`.
488
-
489
- ### Other functions
490
-
491
- #### **getXObjElement(object, name)** => `?any`
492
-
493
- This function returns an element from a given object by its name or `null` if that element not found.
494
-
495
- ##### ***exceptions***
496
-
497
- The function throws a `TypeError` exception in case:
498
-
499
- - code: `ERR_XOBJ_NPOBJ`
500
- + if `object` parameter is not an `Object` instance;
501
- - code: `ERR_XOBJ_NSTR`
502
- + if `name` parameter given and is not a type of a `string`;
503
- - code: `ERR_XOBJ_INVARG_KEY`
504
- + if `name` parameter given and is an empty string.
505
-
506
- #### **addXObjElement(object, name)** => `object`
507
-
508
- This function adds an element given by `name` parameter to a members of the given object and returns an `object` that represents a status of the operation.
509
-
510
- ##### ***result***
511
-
512
- The status of an operation contains 2 fields:
513
-
514
- - `isSucceed` - `boolean` value;
515
- - `item` - an item which was added or a `null`.
516
-
517
- > <!> The function will fail if a target element exists and it is not an object or an array or not a `null`.
518
-
519
- ##### ***exceptions***
520
-
521
- The function throws a `TypeError` exception in case:
522
-
523
- - code: `ERR_XOBJ_NPOBJ`
524
- + if `object` parameter is not an `Object` instance;
525
- - code: `ERR_XOBJ_NSTR`
526
- + if `name` parameter given and is not a type of a `string`;
527
- - code: `ERR_XOBJ_INVARG_KEY`
528
- + if `name` parameter given and is an empty string.
529
-
530
- #### **insertXObjElement(object, name\[, options])** => `?(object|Array)`
531
-
532
- 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.
533
-
534
- ##### ***parameters***
535
-
536
- For details of an `options` parameter read the appropriate section in the description of the [`insertXObjElementEx`](#insertxobjelementexobject-name-options--object) function.
537
-
538
- ##### ***exceptions***
539
-
540
- The function throws a `TypeError` exception in case:
541
-
542
- - code: `ERR_XOBJ_NPOBJ`
543
- + if `object` parameter is not an `Object` instance.
544
-
545
- #### **insertXObjElementEx(object, name\[, options])** => `object`
546
-
547
- > since: \[v0.2.0]
548
-
549
- This function inserts an empty element named by a `name` parameter into a given object and returns an `object` that represents a status of the operation.
550
-
551
- ##### ***parameters***
552
-
553
- An `options` parameter contains the following parameters:
554
-
555
- |option name|value type|default value|description|
556
- |:---|---|---:|:---|
557
- |`force`|`boolean`|`false`|modifies the functions behavior|
558
- |`ripOldies`|`boolean`|`false`|it prevents a replacement of an element which exists and is an object or an array. Applied only if `force` option is set to `true`|
559
- |`acceptIfList`|`boolean`|`false`|it defines whether a list elements is treated as a type of an `object`|
560
-
561
- An `options.force` parameter modifies the functions behavior as follows:
562
- - when set to `true`, the addressed element will be replaced with an empty element.
563
- - when set to `false`, if the target element exists and is not an object or an array, the function will failed.
564
-
565
- ##### ***result***
566
-
567
- The status of an operation contains 2 fields:
568
-
569
- - `isSucceed` - `boolean` value;
570
- - `item` - an item which was inserted or a `null`.
571
-
572
- > <!> If a target element exists and it is not a `null`, the function behavior defined by the given options. When a required conditions not met, the function failed.
573
-
574
- ##### ***exceptions***
575
-
576
- The function throws a `TypeError` exception in case:
577
-
578
- - code: `ERR_XOBJ_NPOBJ`
579
- + if `object` parameter is not an `Object` instance;
580
- - code: `ERR_XOBJ_NSTR`
581
- + if `name` parameter given and is not a type of a `string`;
582
- - code: `ERR_XOBJ_INVARG_KEY`
583
- + if `name` parameter given and is an empty string.
584
-
585
- #### **deleteXObjElement(object, name)** => `boolean`
586
-
587
- This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
588
-
589
- ##### ***exceptions***
590
-
591
- The function throws a `TypeError` exception in case:
592
-
593
- - code: `ERR_XOBJ_NPOBJ`
594
- + if `object` parameter is not an `Object` instance.
595
-
596
- #### **deleteXObjElementEx(object, name)** => `object`
597
-
598
- This function deletes an element addressed by `name` parameter from a given object and returns an `object` that represents a status of the operation.
599
-
600
- ##### ***result***
601
-
602
- The status of an operation contains 2 fields:
603
-
604
- - `isSucceed` - `boolean` value;
605
- - `item` - an item which was deleted or a `null`.
606
-
607
- ##### ***exceptions***
608
-
609
- The function throws a `TypeError` exception in case:
610
-
611
- - code: `ERR_XOBJ_NPOBJ`
612
- + if `object` parameter is not an `Object` instance;
613
- - code: `ERR_XOBJ_NSTR`
614
- + if `name` parameter given and is not a type of a `string`;
615
- - code: `ERR_XOBJ_INVARG_KEY`
616
- + if `name` parameter given and is an empty string.
617
-
618
- #### **renameXObjElement(object, oldName, newName)** => `boolean`
619
-
620
- This function renames an element with a name `oldName` to a name `newName` for the given object. If succeed `true` is returned.
621
-
622
- ##### ***exceptions***
623
-
624
- The function throws a `TypeError` exception in case:
625
-
626
- - code: `ERR_XOBJ_NPOBJ`
627
- + if `object` parameter is not an `Object` instance;
628
- - code: `ERR_XOBJ_NSTR`
629
- + if `oldName` parameter given and is not a type of a `string`;
630
- + id `newName` parameter given and is not a type of a `string`.
631
-
632
- ### Other special functions
633
-
634
- #### **evalXObjEName(name)**
635
-
636
- This function evaluated a value given by a `name` parameter and return a result. The dependencies of a resulted value returned by the function given in the following table:
637
-
638
- |given value|value of result|
639
- |:---|---|
640
- |value is an integer positive number or a string that can be converted to a such number|value of a `number`|
641
- |any other string that can\'t be converted to a number|value of a string|
642
- |any other cases|value of `null`|
643
-
644
- #### **insertXObjEList(object, name\[, options])** => `?Array`
645
-
646
- 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.
647
-
648
- ##### ***parameters***
649
-
650
- For details of an `options` parameter read the appropriate section in the description of the [`insertXObjEListEx`](#insertxobjelistexobject-name-options--object) function.
651
-
652
- ##### ***exceptions***
653
-
654
- The function throws a `TypeError` exception in case:
655
-
656
- - code: `ERR_XOBJ_NPOBJ`
657
- + if `object` parameter is not an `Object` instance.
658
-
659
- #### **insertXObjEListEx(object, name\[, options])** => `object`
660
-
661
- > since: \[v0.2.0]
662
-
663
- This function inserts an elements list named by a `name` parameter into a given object and returns an `object` that represents a status of the operation.
664
-
665
- ##### ***parameters***
666
-
667
- An `options` parameter contains the following parameters:
668
-
669
- |option name|value type|default value|description|
670
- |:---|---|---:|:---|
671
- |`force`|`boolean`|`false`|modifies the functions behavior|
672
- |`ripOldies`|`boolean`|`false`|it prevents a replacement of an element which exists and has a type of an `array`. Applied only if `force` option is set to `true`|
673
-
674
- An `options.force` parameter modifies the functions behavior as follows:
675
- - when set to `true`, the addressed element will be replaced with an empty elements list.
676
- - when set to `false`, if the target element type is an `object`, the function will wraps it in the list.
677
- - when set to `false`, if the target element exists and is not an object or an array, the function will failed.
678
-
679
- ##### ***result***
680
-
681
- The status of an operation contains 2 fields:
682
-
683
- - `isSucceed` - `boolean` value;
684
- - `item` - an item which was inserted or a `null`.
685
-
686
- > <!> If a target element exists and it is not a `null`, the function behavior defined by the given options. When a required conditions not met, the function failed.
687
-
688
- ##### ***exceptions***
689
-
690
- The function throws a `TypeError` exception in case:
691
-
692
- - code: `ERR_XOBJ_NPOBJ`
693
- + if `object` parameter is not an `Object` instance;
694
- - code: `ERR_XOBJ_NSTR`
695
- + if `name` parameter given and is not a type of a `string`;
696
- - code: `ERR_XOBJ_INVARG_KEY`
697
- + if `name` parameter given and is an empty string.
698
-
699
- ### Experimental functions
700
-
701
- > 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.
702
-
703
- #### **genXObjENameDescr(name)**
704
-
705
- This function creates a object that contains description of the value given by a `name` parameter.
706
-
707
- A value of the `name` parameter must have some of the following formats:
708
-
709
- 1. `<name>`;
710
- 2. `<name>[<child>]`;
711
- 3. `<name>[<child>=<value>]`;
712
- 4. `<name>[@<attribute>]`;
713
- 5. `<name>[@<attribute>=<value>]`;
714
-
715
- > Note: the `<value>` must be quoted if it contains characters like a spaces or square brackets.
716
-
717
- The returned object has following attributes:
718
-
719
- |attribute|value type|description|
720
- |:---|---|---|
721
- |`isERR`|`boolean`|set to `true` if error happend|
722
- |`name`|`string`|contains a name of the element|
723
- |`conditions`|`object`|contains conditions applied to that element|
724
-
725
- The object `conditions` property (*if present*) contains following attributes:
726
-
727
- |attribute|value type|description|
728
- |:---|---|---|
729
- |`type`|`string`||
730
- |`name`|`string`||
731
- |`value`|`any`||
732
-
733
- #### **insertXObjElements(object, name\[...name_N\[, options]])** => `number`
734
-
735
- This function inserts an elements given by the list of names and returns a quantity of the inserted elements.
736
-
737
- ##### ***parameters***
738
-
739
- The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertxobjelementobject-name-options--objectarray).
740
-
741
- ##### ***exceptions***
742
-
743
- The function throws a `TypeError` exception in case:
744
-
745
- - code: `ERR_XOBJ_NPOBJ`
746
- + if `object` parameter is not an `Object` instance.
747
-
748
- #### **insertXObjEChain(object, name\[, ...name_N\[, options])**
749
-
750
- This function inserts a chain of the elements listed as a function arguments. If succeed the last inserted element will be returned or `null` if failed.
751
-
752
- > The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertxobjelementobject-name-options--objectarray).
753
-
754
- ##### ***exceptions***
755
-
756
- The function throws a `TypeError` exception in case:
757
-
758
- - code: `ERR_XOBJ_NPOBJ`
759
- + if `object` parameter is not an `Object` instance.
760
-
761
- ### Base class
762
-
763
- #### **TXmlContentParseOptions**
764
-
765
- This class implements an interface for handling XML-parse options.
766
-
767
- ##### class constructor
768
-
769
- The class constructor creates a new instance of the class. It receives arguments listed below:
770
-
771
- |name|type|default value|description|
772
- |:---|---|---:|:---|
773
- |`object`|---|---|a host object.|
774
- |`options`|`object`|---|an options settings.|
775
-
776
- ##### class properties
777
-
778
- The table below describes a properties of a `TXmlContentParseOptions` class:
779
-
780
- |name|read only|description|
781
- |:---|---|:---|
782
- |settings|yes|presents a current options|
783
- |xml2js|yes|returns an options for an XML-to-JS converter|
784
- |js2xml|yes|returns an options for an JS-to-XML converter|
785
-
786
- ##### class methods (*static*)
787
-
788
- ###### **createNewOptionsSet(obj)**
789
-
790
- This method transforms a given object to a set of accepted parser options.
1
+ >|***rev.*:**|0.1.43|
2
+ >|:---|---:|
3
+ >|date:|2025-01-28|
4
+
5
+ ## Introduction
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 type definitions
14
+
15
+ This section contains some definitions for a general types of the objects (e.g. options set) that frequently used in a function descriptions.
16
+
17
+ <a name="typedef+OPT_valtostr"></a>
18
+ #### `OPT_valtostr` - options set
19
+
20
+ This options set is an `object` which defines how a value transforms to a 'string' type.
21
+
22
+ | option name | option type | default value | description |
23
+ |:---|---|---:|:---|
24
+ | `useTrim` | `boolean` | `false` | defines whether or not the resulting string must to be trimmed |
25
+ | `letterCase` | `string` | --- | if given defines a function behavior on the resulting string |
26
+ | `numberToString` | `boolean` | `false` | if set a values of `number` types will be converted to a string |
27
+ | `boolToString` | `boolean` | `false` | if set a values of `boolean` types will be converted to a string |
28
+ | `boolToUpperCase` | `boolean` | `false` | if set a values of `boolean` types when converted to a string will be present in upper case |
29
+ | `defValue` | `string` | `EMPTY_STRING` | if given represents a value which will be returned in case the function failed |
30
+
31
+ The behavior for `letterCase` settings defined in the table below:
32
+
33
+ | option value | description |
34
+ |:---|:---|
35
+ | `upper` | the resulting string must to be present in upper case |
36
+ | `lower` | the resulting string must to be present in lower case |
37
+ | any other values | the resulting string will be not transformed |
38
+
39
+ ### Base constants
40
+
41
+ |name|type|value|
42
+ |:---|---|---:|
43
+ |XOBJ_DEF_PARAM_TNAME|`string`|`__text`|
44
+ |XOBJ_DEF_ATTR_TNAME|`string`|`__attr`|
45
+ |DEF_XML_PARSE_OPTIONS|`object`|---|
46
+
47
+ #### **DEF\_XML\_PARSE_OPTIONS**
48
+
49
+ This constant object provided by the module contains a default settings of options for XML-parser module used within.
50
+
51
+ The settings listed in the table below:
52
+
53
+ |name|type|value|
54
+ |:---|---|:---|
55
+ |compact|`boolean`|`true`|
56
+ |declarationKey|`string`|`__decl`|
57
+ |attributesKey|`string`|`__attr`|
58
+ |textKey|`string`|`__text`|
59
+ |commentKey|`string`|`__note`|
60
+ |cdataKey|`string`|`__cdata`|
61
+ |nameKey|`string`|`__name`|
62
+ |typeKey|`string`|`__type`|
63
+ |parentKey|`string`|`parent`|
64
+ |elementsKey|`string`|`items`|
65
+ |ignoreDeclaration|`boolean`|`false`|
66
+ |ignoreDocType|`boolean`|`false`|
67
+ |ignoreInstractions|`boolean`|`false`|
68
+ |ignoreText|`boolean`|`false`|
69
+ |ignoreComments|`boolean`|`false`|
70
+ |ignoreCData|`boolean`|`false`|
71
+ |fullTagEmptyElement|`boolean`|`true`|
72
+ |addParent|`boolean`|`false`|
73
+ |trim|`boolean`|`true`|
74
+ |spaces|`number`|`2`|
75
+
76
+ ### Base functions for read an object parameter value
77
+
78
+ > Note:
79
+ > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
80
+
81
+ <a name="readXObjParam"></a>
82
+ #### **readXObjParam(object\[, key])** => `string`
83
+
84
+ This function returns a value of an object parameter as a string.
85
+
86
+ ##### ***parameters***
87
+
88
+ | parameter name | value type | default value | description |
89
+ |:---|---|---:|:---|
90
+ | `object` | `object` | --- | some object |
91
+ | `key` | `string` | --- | some key |
92
+
93
+ ##### ***exceptions***
94
+
95
+ The function throws a `TypeError` exception in case:
96
+
97
+ - code: `ERR_XOBJ_NPOBJ`
98
+ + if `object` parameter is not an `Object` instance.
99
+
100
+ <a name="readXObjParamAsBool"></a>
101
+ #### **readXObjParamAsBool(object\[, defValue \[, key]])** => `boolean`
102
+
103
+ This function reads a value of an object parameter and returns it as a `boolean`.
104
+
105
+ ##### ***parameters***
106
+
107
+ | parameter name | value type | default value | description |
108
+ |:---|---|---:|:---|
109
+ | `object` | `object` | --- | some object |
110
+ | `defValue` | `boolean` | `false` | default value |
111
+ | `key` | `string` | --- | some key |
112
+
113
+ ##### ***exceptions***
114
+
115
+ The function throws a `TypeError` exception in case:
116
+
117
+ - code: `ERR_XOBJ_NPOBJ`
118
+ + if `object` parameter is not an `Object` instance.
119
+
120
+ <a name="readXObjParamAsNum"></a>
121
+ #### **readXObjParamAsNum(object\[, defValue \[, key])** => `number`
122
+
123
+ This function reads a value of an object parameter and returns it as a `number`.
124
+
125
+ ##### ***parameters***
126
+
127
+ | parameter name | value type | default value | description |
128
+ |:---|---|---:|:---|
129
+ | `object` | `object` | --- | some object |
130
+ | `defValue` | `number` | `0` | default value |
131
+ | `key` | `string` | --- | some key |
132
+
133
+ ##### ***exceptions***
134
+
135
+ The function throws a `TypeError` exception in case:
136
+
137
+ - code: `ERR_XOBJ_NPOBJ`
138
+ + if `object` parameter is not an `Object` instance.
139
+
140
+ <a name="readXObjParamAsIndex"></a>
141
+ #### **readXObjParamAsIndex(object\[, key])** => `number`
142
+
143
+ 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.
144
+
145
+ > Note: *for use in this case, index is validated as a non-negative integer number.*
146
+
147
+ ##### ***parameters***
148
+
149
+ | parameter name | value type | default value | description |
150
+ |:---|---|---:|:---|
151
+ | `object` | `object` | --- | some object |
152
+ | `key` | `string` | --- | some key |
153
+
154
+ ##### ***exceptions***
155
+
156
+ The function throws a `TypeError` exception in case:
157
+
158
+ - code: `ERR_XOBJ_NPOBJ`
159
+ + if `object` parameter is not an `Object` instance.
160
+
161
+ #### **readXObjParamAsStr(object\[, defValue \[, key])** => `string`
162
+
163
+ > WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjParam`](#readxobjparamobject-key--string) or [`readXObjParamEx`](#readxobjparamexobject-opt-key--string) instead.*
164
+
165
+ This function reads a value of an object parameter and returns it as a `string`.
166
+
167
+ The `defValue` must be of a `string` type, if else the empty string is used.
168
+
169
+ <a name="readXObjParamEx"></a>
170
+ #### **readXObjParamEx(object\[, options \[, key])** => `string`
171
+
172
+ > since: \[v0.2.0]
173
+
174
+ This function reads a value of an object parameter and returns it as a `string`.
175
+
176
+ ##### ***parameters***
177
+
178
+ | parameter name | value type | default value | description |
179
+ |:---|---|---:|:---|
180
+ | `object` | `object` | --- | some object |
181
+ | `options` | `string`, `object` | --- | options that defines how a value must be transformed |
182
+ | `key` | `string` | --- | some key |
183
+
184
+ An `options` parameter must be a `string` or an `object`.
185
+
186
+ > \[!] NOTE: `[since v0.2.1]` a use of a `string` type a as values of an `options` are deprecated and will be dropped soon.
187
+
188
+ If `options` is an `object` it contains the settings (see [OPT_valtostr](#typedef+OPT_valtostr)).
189
+
190
+ If `options` is of a `string` type the function treats it as a value of `options.defValue`.
191
+
192
+ If `options` is not given the settings listed in table below are used by default:
193
+
194
+ | option name | option type | value |
195
+ |:---|---|---:|
196
+ | `useTrim` | `boolean` | `false` |
197
+ | `numberToString` | `boolean` | `true` |
198
+ | `boolToString` | `boolean` | `true` |
199
+ | `defValue` | `string` | `EMPTY_STRING` |
200
+
201
+ ##### ***exceptions***
202
+
203
+ The function throws a `TypeError` exception in case:
204
+
205
+ - code: `ERR_XOBJ_NPOBJ`
206
+ + if `object` parameter is not an `Object` instance.
207
+
208
+ ### Base functions for write an object parameter value
209
+
210
+ > Note:
211
+ > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
212
+
213
+ <a name="writeXObjParam"></a>
214
+ #### **writeXObjParam(object, value\[, key])** => `boolean`
215
+
216
+ This function sets object parameter to a given value and if succeed returns `true`.
217
+
218
+ ##### ***parameters***
219
+
220
+ | parameter name | value type | default value | description |
221
+ |:---|---|---:|:---|
222
+ | `object` | `object` | --- | some object |
223
+ | `value` | `any` | --- | some value to write |
224
+ | `key` | `string` | --- | some key |
225
+
226
+ ##### ***exceptions***
227
+
228
+ The function throws a `TypeError` exception in case:
229
+
230
+ - code: `ERR_XOBJ_NPOBJ`
231
+ + if `object` parameter is not an `Object` instance.
232
+
233
+ <a name="writeXObjParamAsBool"></a>
234
+ #### **writeXObjParamAsBool(object, value\[, defValue\[, key]])** => `boolean`
235
+
236
+ This function writes a given `boolean` value of an object parameter.
237
+
238
+ ##### ***parameters***
239
+
240
+ | parameter name | value type | default value | description |
241
+ |:---|---|---:|:---|
242
+ | `object` | `object` | --- | some object |
243
+ | `value` | `any` | --- | some value to write |
244
+ | `defValue` | `boolean` | `false` | default value |
245
+ | `key` | `string` | --- | some key |
246
+
247
+ ##### ***exceptions***
248
+
249
+ The function throws a `TypeError` exception in case:
250
+
251
+ - code: `ERR_XOBJ_NPOBJ`
252
+ + if `object` parameter is not an `Object` instance.
253
+
254
+ <a name="writeXObjParamAsNum"></a>
255
+ #### **writeXObjParamAsNum(object, value\[, defValue\[, key]])** => `boolean`
256
+
257
+ This function writes a given `number` value of an object parameter.
258
+
259
+ ##### ***parameters***
260
+
261
+ | parameter name | value type | default value | description |
262
+ |:---|---|---:|:---|
263
+ | `object` | `object` | --- | some object |
264
+ | `value` | `any` | --- | some value to write |
265
+ | `defValue` | `number` | `0` | default value |
266
+ | `key` | `string` | --- | some key |
267
+
268
+ ##### ***exceptions***
269
+
270
+ The function throws a `TypeError` exception in case:
271
+
272
+ - code: `ERR_XOBJ_NPOBJ`
273
+ + if `object` parameter is not an `Object` instance.
274
+
275
+ <a name="writeXObjParamAsIndex"></a>
276
+ #### **writeXObjParamAsIndex(object, value\[, key])** => `boolean`
277
+
278
+ This function try to interpret a given value as a valid index value and, if succeed, writes it into an object parameter.
279
+
280
+ ##### ***parameters***
281
+
282
+ | parameter name | value type | default value | description |
283
+ |:---|---|---:|:---|
284
+ | `object` | `object` | --- | some object |
285
+ | `value` | `any` | --- | some value to write |
286
+ | `key` | `string` | --- | some key |
287
+
288
+ ##### ***exceptions***
289
+
290
+ The function throws a `TypeError` exception in case:
291
+
292
+ - code: `ERR_XOBJ_NPOBJ`
293
+ + if `object` parameter is not an `Object` instance.
294
+
295
+ <a name="writeXObjParamEx"></a>
296
+ #### **writeXObjParamEx(object, value\[, options\[, key]])** => `boolean`
297
+
298
+ This function sets object parameter to a given value and if succeed returns `true`.
299
+
300
+ ##### ***parameters***
301
+
302
+ | parameter name | value type | default value | description |
303
+ |:---|---|---:|:---|
304
+ | `object` | `object` | --- | some object |
305
+ | `value` | `any` | --- | some value to write |
306
+ | `options` | `string`, `object` | --- | options that defines how a value must be transformed |
307
+ | `key` | `string` | --- | some key |
308
+
309
+ An `options` parameter must be a `string` or an `object`.
310
+
311
+ > \[!] NOTE: `[since v0.2.1]` a use of a `string` type a as values of an `options` are deprecated and will be dropped soon.
312
+
313
+ If `options` is an `object` it contains the settings (see [OPT_valtostr](#typedef+OPT_valtostr)).
314
+
315
+ If `options` is of a `string` type the function treats it as a value of `options.defValue`.
316
+
317
+ If `options` is not given the settings listed in table below are used by default:
318
+
319
+ | option name | option type | value |
320
+ |:---|---|---:|
321
+ | `useTrim` | `boolean` | `false` |
322
+ | `numberToString` | `boolean` | `true` |
323
+ | `boolToString` | `boolean` | `true` |
324
+ | `defValue` | `string` | `EMPTY_STRING` |
325
+
326
+ ##### ***exceptions***
327
+
328
+ The function throws a `TypeError` exception in case:
329
+
330
+ - code: `ERR_XOBJ_NPOBJ`
331
+ + if `object` parameter is not an `Object` instance.
332
+
333
+ ### Base functions for read an object attributes value
334
+
335
+ > Note:
336
+ > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
337
+
338
+ <a name="readXObjAttr"></a>
339
+ #### **readXObjAttr(object, attr\[, key])** => `string`
340
+
341
+ This function returns a value of an object attribute. The value is of a `string` type.
342
+
343
+ ##### ***parameters***
344
+
345
+ | parameter name | value type | default value | description |
346
+ |:---|---|---:|:---|
347
+ | `object` | `object` | --- | some object |
348
+ | `attr` | `string` | --- | some attribute |
349
+ | `key` | `string` | --- | some key |
350
+
351
+ ##### ***exceptions***
352
+
353
+ The function throws a `TypeError` exception in case:
354
+
355
+ - code: `ERR_XOBJ_NPOBJ`
356
+ + if `object` parameter is not an `Object` instance.
357
+
358
+ <a name="readXObjAttrAsBool"></a>
359
+ #### **readXObjAttrAsBool(object, attr\[, defValue\[, key]])** => `boolean`
360
+
361
+ This function reads a value of an object attribute and returns it as a `boolean`.
362
+
363
+ ##### ***parameters***
364
+
365
+ | parameter name | value type | default value | description |
366
+ |:---|---|---:|:---|
367
+ | `object` | `object` | --- | some object |
368
+ | `attr` | `string` | --- | some attribute |
369
+ | `defValue` | `boolean` | `false` | default value |
370
+ | `key` | `string` | --- | some key |
371
+
372
+ ##### ***exceptions***
373
+
374
+ The function throws a `TypeError` exception in case:
375
+
376
+ - code: `ERR_XOBJ_NPOBJ`
377
+ + if `object` parameter is not an `Object` instance.
378
+
379
+ <a name="readXObjAttrAsNum"></a>
380
+ #### **readXObjAttrAsNum(object, attr\[, defValue\[, key]])** => `number`
381
+
382
+ This function reads a value of an object attribute and returns it as a `number`.
383
+
384
+ ##### ***parameters***
385
+
386
+ | parameter name | value type | default value | description |
387
+ |:---|---|---:|:---|
388
+ | `object` | `object` | --- | some object |
389
+ | `attr` | `string` | --- | some attribute |
390
+ | `defValue` | `number` | `0` | default value |
391
+ | `key` | `string` | --- | some key |
392
+
393
+ ##### ***exceptions***
394
+
395
+ The function throws a `TypeError` exception in case:
396
+
397
+ - code: `ERR_XOBJ_NPOBJ`
398
+ + if `object` parameter is not an `Object` instance.
399
+
400
+ <a name="readXObjAttrAsIndex"></a>
401
+ #### **readXObjAttrAsIndex(object, attr\[, key])** => `number`
402
+
403
+ 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.
404
+
405
+ > Note: *for use in this case, index is validated as a non-negative integer number.*
406
+
407
+ ##### ***parameters***
408
+
409
+ | parameter name | value type | default value | description |
410
+ |:---|---|---:|:---|
411
+ | `object` | `object` | --- | some object |
412
+ | `attr` | `string` | --- | some attribute |
413
+ | `key` | `string` | --- | some key |
414
+
415
+ ##### ***exceptions***
416
+
417
+ The function throws a `TypeError` exception in case:
418
+
419
+ - code: `ERR_XOBJ_NPOBJ`
420
+ + if `object` parameter is not an `Object` instance.
421
+
422
+ #### **readXObjAttrAsStr(object, attr\[, defValue\[, key]])** => `string`
423
+
424
+ > WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjAttr`](#readxobjattrobject-attr-key--string) or [`readXObjAttrEx`](#readxobjattrexobject-attr-opt-key--string) instead.*
425
+
426
+ This function returns a value of an object attribute. The value is of a `string` type.
427
+
428
+ The `defValue` must be of a `string` type, if else the empty string is used.
429
+
430
+ <a name="readXObjAttrEx"></a>
431
+ #### **readXObjAttrEx(object, attr\[, options\[, key]])** => `string`
432
+
433
+ > since: \[v0.2.0]
434
+
435
+ This function returns a value of an object attribute. The value is of a `string` type.
436
+
437
+ ##### ***parameters***
438
+
439
+ | parameter name | value type | default value | description |
440
+ |:---|---|---:|:---|
441
+ | `object` | `object` | --- | some object |
442
+ | `attr` | `string` | --- | some attribute |
443
+ | `options` | `string`, `object` | --- | options that defines how a value must be transformed |
444
+ | `key` | `string` | --- | some key |
445
+
446
+ An `options` parameter must be a `string` or an `object`.
447
+
448
+ > \[!] NOTE: `[since v0.2.1]` a use of a `string` type a as values of an `options` are deprecated and will be dropped soon.
449
+
450
+ If `options` is an `object` it contains the settings (see [OPT_valtostr](#typedef+OPT_valtostr)).
451
+
452
+ If `options` is of a `string` type the function treats it as a value of `options.defValue`.
453
+
454
+ If `options` is not given the settings listed in table below are used by default:
455
+
456
+ | option name | option type | value |
457
+ |:---|---|---:|
458
+ | `useTrim` | `boolean` | `true` |
459
+ | `numberToString` | `boolean` | `true` |
460
+ | `boolToString` | `boolean` | `true` |
461
+ | `defValue` | `string` | `EMPTY_STRING` |
462
+
463
+ ##### ***exceptions***
464
+
465
+ The function throws a `TypeError` exception in case:
466
+
467
+ - code: `ERR_XOBJ_NPOBJ`
468
+ + if `object` parameter is not an `Object` instance.
469
+
470
+ ### Base functions for write an object attributes value
471
+
472
+ > Note:
473
+ > If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
474
+
475
+ <a name="writeXObjAttr"></a>
476
+ #### **writeXObjAttr(object, attr, value\[, key])** => `boolean`
477
+
478
+ This function sets object attribute to a given value and if succeed returns `true`.
479
+
480
+ ##### ***parameters***
481
+
482
+ | parameter name | value type | default value | description |
483
+ |:---|---|---:|:---|
484
+ | `object` | `object` | --- | some object |
485
+ | `attr` | `string` | --- | some attribute |
486
+ | `value` | `any` | --- | some value |
487
+ | `key` | `string` | --- | some key |
488
+
489
+ > Note: a value must be of a `string` type or can be converted to a string
490
+
491
+ ##### ***exceptions***
492
+
493
+ The function throws a `TypeError` exception in case:
494
+
495
+ - code: `ERR_XOBJ_NPOBJ`
496
+ + if `object` parameter is not an `Object` instance.
497
+
498
+ <a name="writeXObjAttrAsBool"></a>
499
+ #### **writeXObjAttrAsBool(object, attr, value\[, defValue\[, key]])** => `boolean`
500
+
501
+ This function writes a given `boolean` value of an object attribute.
502
+
503
+ ##### ***parameters***
504
+
505
+ | parameter name | value type | default value | description |
506
+ |:---|---|---:|:---|
507
+ | `object` | `object` | --- | some object |
508
+ | `attr` | `string` | --- | some attribute |
509
+ | `value` | `any` | --- | some value |
510
+ | `defValue` | `boolean` | `false` | default value |
511
+ | `key` | `string` | --- | some key |
512
+
513
+ ##### ***exceptions***
514
+
515
+ The function throws a `TypeError` exception in case:
516
+
517
+ - code: `ERR_XOBJ_NPOBJ`
518
+ + if `object` parameter is not an `Object` instance.
519
+
520
+ <a name="writeXObjAttrAsNum"></a>
521
+ #### **writeXObjAttrAsNum(object, attr, value\[, defValue\[, key]])** => `boolean`
522
+
523
+ This function writes a given `number` value of an object attribute.
524
+
525
+ ##### ***parameters***
526
+
527
+ | parameter name | value type | default value | description |
528
+ |:---|---|---:|:---|
529
+ | `object` | `object` | --- | some object |
530
+ | `attr` | `string` | --- | some attribute |
531
+ | `value` | `any` | --- | some value |
532
+ | `defValue` | `number` | `0` | default value |
533
+ | `key` | `string` | --- | some key |
534
+
535
+ ##### ***exceptions***
536
+
537
+ The function throws a `TypeError` exception in case:
538
+
539
+ - code: `ERR_XOBJ_NPOBJ`
540
+ + if `object` parameter is not an `Object` instance.
541
+
542
+ <a name="writeXObjAttrAsIndex"></a>
543
+ #### **writeXObjAttrAsIndex(object, attr, value\[, key])** => `boolean`
544
+
545
+ This function try to interpret a given value as a valid index value and, if succeed, writes it into an object attribute.
546
+
547
+ ##### ***parameters***
548
+
549
+ | parameter name | value type | default value | description |
550
+ |:---|---|---:|:---|
551
+ | `object` | `object` | --- | some object |
552
+ | `attr` | `string` | --- | some attribute |
553
+ | `value` | `any` | --- | some value |
554
+ | `key` | `string` | --- | some key |
555
+
556
+ ##### ***exceptions***
557
+
558
+ The function throws a `TypeError` exception in case:
559
+
560
+ - code: `ERR_XOBJ_NPOBJ`
561
+ + if `object` parameter is not an `Object` instance.
562
+
563
+ <a name="writeXObjAttrEx"></a>
564
+ #### **writeXObjAttrEx(object, attr, value\[, options\[, key]])** => `boolean`
565
+
566
+ This function sets object attribute to a given value and if succeed returns `true`.
567
+
568
+ ##### ***parameters***
569
+
570
+ | parameter name | value type | default value | description |
571
+ |:---|---|---:|:---|
572
+ | `object` | `object` | --- | some object |
573
+ | `attr` | `string` | --- | some attribute |
574
+ | `value` | `any` | --- | some value |
575
+ | `options` | `string`, `object` | --- | options that defines how a value must be transformed |
576
+ | `key` | `string` | --- | some key |
577
+
578
+ An `options` parameter must be a `string` or an `object`.
579
+
580
+ > \[!] NOTE: `[since v0.2.1]` a use of a `string` type a as values of an `options` are deprecated and will be dropped soon.
581
+
582
+ If `options` is an `object` it contains the settings (see [OPT_valtostr](#typedef+OPT_valtostr)).
583
+
584
+ If `options` is of a `string` type the function treats it as a value of `options.defValue`.
585
+
586
+ If `options` is not given the settings listed in table below are used by default:
587
+
588
+ | option name | option type | value |
589
+ |:---|---|---:|
590
+ | `useTrim` | `boolean` | `true` |
591
+ | `numberToString` | `boolean` | `true` |
592
+ | `boolToString` | `boolean` | `true` |
593
+ | `defValue` | `string` | `EMPTY_STRING` |
594
+
595
+ ##### ***exceptions***
596
+
597
+ The function throws a `TypeError` exception in case:
598
+
599
+ - code: `ERR_XOBJ_NPOBJ`
600
+ + if `object` parameter is not an `Object` instance.
601
+
602
+ ### Special functions for read and write an object parameter value
603
+
604
+ <a name="readXObjParamRaw"></a>
605
+ #### **readXObjParamRaw(object\[, key])** => `any`
606
+
607
+ This is a special function that returns a value of an object parameter as "IT IS".
608
+
609
+ ##### ***parameters***
610
+
611
+ | parameter name | value type | default value | description |
612
+ |:---|---|---:|:---|
613
+ | `object` | `object` | --- | some object |
614
+ | `key` | `string` | --- | some key |
615
+
616
+ > NOTE:
617
+ > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
618
+
619
+ ##### ***exceptions***
620
+
621
+ The function throws a `TypeError` exception in case:
622
+
623
+ - code: `ERR_XOBJ_NPOBJ`
624
+ + if `object` parameter is not an `Object` instance;
625
+ - code: `ERR_XOBJ_NSTR`
626
+ + if `key` parameter given and is not a type of a `string`.
627
+
628
+ <a name="writeXObjParamRaw"></a>
629
+ #### **writeXObjParamRaw(object, value\[, key])** => `boolean`
630
+
631
+ This is a special function that writes a given value of an object parameter as "IT IS".
632
+
633
+ ##### ***parameters***
634
+
635
+ | parameter name | value type | default value | description |
636
+ |:---|---|---:|:---|
637
+ | `object` | `object` | --- | some object |
638
+ | `value` | `any` | --- | some value |
639
+ | `key` | `string` | --- | some key |
640
+
641
+ > NOTE:
642
+ > - If `value` parameter not given, the function failed.
643
+ > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
644
+
645
+ ##### ***exceptions***
646
+
647
+ The function throws a `TypeError` exception in case:
648
+
649
+ - code: `ERR_XOBJ_NPOBJ`
650
+ + if `object` parameter is not an `Object` instance;
651
+ - code: `ERR_XOBJ_NSTR`
652
+ + if `key` parameter given and is not a type of a `string`.
653
+
654
+ ### Special functions for read or write object attributes value
655
+
656
+ <a name="readXObjAttrRaw"></a>
657
+ #### **readXObjAttrRaw(object, attr\[, key])** => `any`
658
+
659
+ This is a special function that returns a value of an object attribute as "IT IS".
660
+
661
+ ##### ***parameters***
662
+
663
+ | parameter name | value type | default value | description |
664
+ |:---|---|---:|:---|
665
+ | `object` | `object` | --- | some object |
666
+ | `attr` | `string` | --- | some attribute |
667
+ | `key` | `string` | --- | some key |
668
+
669
+ > NOTE:
670
+ > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
671
+
672
+ ##### ***exceptions***
673
+
674
+ The function throws a `TypeError` exception in case:
675
+
676
+ - code: `ERR_XOBJ_NPOBJ`
677
+ + if `object` parameter is not an `Object` instance;
678
+ - code: `ERR_XOBJ_NSTR`
679
+ + if `attr` parameter given and is not a type of a `string`;
680
+ + if `key` parameter given and is not a type of a `string`.
681
+
682
+ <a name="writeXObjAttrRaw"></a>
683
+ #### **writeXObjAttrRaw(object, attr, value\[, key])** => `boolean`
684
+
685
+ This is a special function that writes a given value of an object attribute as "IT IS".
686
+
687
+ ##### ***parameters***
688
+
689
+ | parameter name | value type | default value | description |
690
+ |:---|---|---:|:---|
691
+ | `object` | `object` | --- | some object |
692
+ | `attr` | `string` | --- | some attribute |
693
+ | `value` | `any` | --- | some value |
694
+ | `key` | `string` | --- | some key |
695
+
696
+ > NOTE:
697
+ > - If `value` parameter not given, the function failed.
698
+ > - If a `key` parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
699
+
700
+ ##### ***exceptions***
701
+
702
+ The function throws a `TypeError` exception in case:
703
+
704
+ - code: `ERR_XOBJ_NPOBJ`
705
+ + if `object` parameter is not an `Object` instance;
706
+ - code: `ERR_XOBJ_NSTR`
707
+ + if `attr` parameter given and is not a type of a `string`;
708
+ + if `key` parameter given and is not a type of a `string`.
709
+
710
+ ### Other functions for deal with an object attributes
711
+
712
+ > Note:
713
+ > If a `key` parameter given not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
714
+
715
+ <a name="getXObjAttributes"></a>
716
+ #### **getXObjAttributes(object\[, key])** => `?object`
717
+
718
+ This function returns an object which represents a set of the element attributes for a given object or `null` if failed.
719
+
720
+ ##### ***parameters***
721
+
722
+ | parameter name | value type | default value | description |
723
+ |:---|---|---:|:---|
724
+ | `object` | `object` | --- | some object |
725
+ | `key` | `string` | --- | some key |
726
+
727
+ ##### ***exceptions***
728
+
729
+ The function throws a `TypeError` exception in case:
730
+
731
+ - code: `ERR_XOBJ_NPOBJ`
732
+ + if `object` parameter is not an `Object` instance.
733
+
734
+ <a name="checkXObjAttribute"></a>
735
+ #### **checkXObjAttribute(object, attr\[, key])** => `boolean`
736
+
737
+ This function tries to check whether or not an attribute with a name given by `attr` parameter exists for the element given by `object` parameter. If attribute exists `true` is returned.
738
+
739
+ ##### ***parameters***
740
+
741
+ | parameter name | value type | default value | description |
742
+ |:---|---|---:|:---|
743
+ | `object` | `object` | --- | some object |
744
+ | `attr` | `string` | --- | some attribute |
745
+ | `key` | `string` | --- | some key |
746
+
747
+ ##### ***exceptions***
748
+
749
+ The function throws a `TypeError` exception in case:
750
+
751
+ - code: `ERR_XOBJ_NPOBJ`
752
+ + if `object` parameter is not an `Object` instance;
753
+ - code: `ERR_XOBJ_NSTR`
754
+ + if `attr` parameter given and is not a type of a `string`;
755
+ + if `key` parameter given and is not a type of a `string`.
756
+
757
+ <a name="deleteXObjAttribute"></a>
758
+ #### **deleteXObjAttribute(object, attr\[, key])** => `boolean`
759
+
760
+ This function tries to delete an attribute with a name given by `attr` parameter. If succeed `true` is returned.
761
+
762
+ ##### ***parameters***
763
+
764
+ | parameter name | value type | default value | description |
765
+ |:---|---|---:|:---|
766
+ | `object` | `object` | --- | some object |
767
+ | `attr` | `string` | --- | some attribute |
768
+ | `key` | `string` | --- | some key |
769
+
770
+ ##### ***exceptions***
771
+
772
+ The function throws a `TypeError` exception in case:
773
+
774
+ - code: `ERR_XOBJ_NPOBJ`
775
+ + if `object` parameter is not an `Object` instance;
776
+ - code: `ERR_XOBJ_NSTR`
777
+ + if `attr` parameter given and is not a type of a `string`;
778
+ + if `key` parameter given and is not a type of a `string`.
779
+
780
+ <a name="renameXObjElement"></a>
781
+ #### **renameXObjAttribute(object, attr, value\[, key])** => `boolean`
782
+
783
+ > since: \[v0.2.0]
784
+
785
+ This function tries to rename an attribute with a name given by `attr` parameter to its new name. If succeed `true` is returned.
786
+
787
+ ##### ***parameters***
788
+
789
+ | parameter name | value type | default value | description |
790
+ |:---|---|---:|:---|
791
+ | `object` | `object` | --- | some object |
792
+ | `attr` | `string` | --- | some attribute |
793
+ | `value` | `string` | --- | new attribute ID |
794
+ | `key` | `string` | --- | some key |
795
+
796
+ ##### ***exceptions***
797
+
798
+ The function throws a `TypeError` exception in case:
799
+
800
+ - code: `ERR_XOBJ_NPOBJ`
801
+ + if `object` parameter is not an `Object` instance;
802
+ - code: `ERR_XOBJ_NSTR`
803
+ + if `attr` parameter given and is not a type of a `string`;
804
+ + if `value` parameter given and is not a type of a `string`;
805
+ + if `key` parameter given and is not a type of a `string`.
806
+
807
+ ### Other functions
808
+
809
+ <a name="getXObjElement"></a>
810
+ #### **getXObjElement(object, name)** => `?any`
811
+
812
+ This function returns an element from a given object by its name or `null` if that element not found.
813
+
814
+ ##### ***parameters***
815
+
816
+ | parameter name | value type | default value | description |
817
+ |:---|---|---:|:---|
818
+ | `object` | `object` | --- | some object |
819
+ | `name` | `string` | --- | some child element ID |
820
+
821
+ ##### ***exceptions***
822
+
823
+ The function throws a `TypeError` exception in case:
824
+
825
+ - code: `ERR_XOBJ_NPOBJ`
826
+ + if `object` parameter is not an `Object` instance;
827
+ - code: `ERR_XOBJ_NSTR`
828
+ + if `name` parameter given and is not a type of a `string`;
829
+ - code: `ERR_XOBJ_INVARG_KEY`
830
+ + if `name` parameter given and is an empty string.
831
+
832
+ <a name="addXObjElement"></a>
833
+ #### **addXObjElement(object, name)** => `object`
834
+
835
+ This function adds an element given by `name` parameter to a members of the given object and returns an `object` that represents a status of the operation.
836
+
837
+ ##### ***parameters***
838
+
839
+ | parameter name | value type | default value | description |
840
+ |:---|---|---:|:---|
841
+ | `object` | `object` | --- | some object |
842
+ | `name` | `string` | --- | some child element ID |
843
+
844
+ ##### ***result***
845
+
846
+ The status of an operation contains 2 fields:
847
+
848
+ - `isSucceed` - `boolean` value;
849
+ - `item` - an item which was added or a `null`.
850
+
851
+ > <!> The function will fail if a target element exists and it is not an object or an array or not a `null`.
852
+
853
+ ##### ***exceptions***
854
+
855
+ The function throws a `TypeError` exception in case:
856
+
857
+ - code: `ERR_XOBJ_NPOBJ`
858
+ + if `object` parameter is not an `Object` instance;
859
+ - code: `ERR_XOBJ_NSTR`
860
+ + if `name` parameter given and is not a type of a `string`;
861
+ - code: `ERR_XOBJ_INVARG_KEY`
862
+ + if `name` parameter given and is an empty string.
863
+
864
+ <a name="insertXObjElement"></a>
865
+ #### **insertXObjElement(object, name\[, options])** => `null`\|`object`\|`object[]`
866
+
867
+ 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.
868
+
869
+ ##### ***parameters***
870
+
871
+ | parameter name | value type | default value | description |
872
+ |:---|---|---:|:---|
873
+ | `object` | `object` | --- | some object |
874
+ | `name` | `string` | --- | some child element ID |
875
+ | `options` | `object` | --- | options |
876
+
877
+ For details of an `options` parameter read the appropriate section in the description of the [`insertXObjElementEx`](#insertXObjElementEx) function.
878
+
879
+ ##### ***exceptions***
880
+
881
+ The function throws a `TypeError` exception in case:
882
+
883
+ - code: `ERR_XOBJ_NPOBJ`
884
+ + if `object` parameter is not an `Object` instance.
885
+
886
+ <a name="insertXObjElementEx"></a>
887
+ #### **insertXObjElementEx(object, name\[, options])** => `object`
888
+
889
+ > since: \[v0.2.0]
890
+
891
+ This function inserts an empty element named by a `name` parameter into a given object and returns an `object` that represents a status of the operation.
892
+
893
+ ##### ***parameters***
894
+
895
+ | parameter name | value type | default value | description |
896
+ |:---|---|---:|:---|
897
+ | `object` | `object` | --- | some object |
898
+ | `name` | `string` | --- | some child element ID |
899
+ | `options` | `object` | --- | options |
900
+
901
+ An `options` parameter contains the following parameters:
902
+
903
+ | option name | value type | default value | description |
904
+ |:---|---|---:|:---|
905
+ | `force` | `boolean` | `false` | modifies the functions behavior |
906
+ | `ripOldies` | `boolean` | `false` | it prevents a replacement of an element which exists and is an object or an array. Applied only if `force` option is set to `true` |
907
+ | `acceptIfList` | `boolean` | `false` | it defines whether a list elements is treated as a type of an `object` |
908
+
909
+ An `options.force` parameter modifies the functions behavior as follows:
910
+ - when set to `true`, the addressed element will be replaced with an empty element.
911
+ - when set to `false`, if the target element exists and is not an object or an array, the function will failed.
912
+
913
+ ##### ***result***
914
+
915
+ The status of an operation contains 2 fields:
916
+
917
+ - `isSucceed` - `boolean` value;
918
+ - `item` - an item which was inserted or a `null`.
919
+
920
+ > <!> If a target element exists and it is not a `null`, the function behavior defined by the given options. When a required conditions not met, the function failed.
921
+
922
+ ##### ***exceptions***
923
+
924
+ The function throws a `TypeError` exception in case:
925
+
926
+ - code: `ERR_XOBJ_NPOBJ`
927
+ + if `object` parameter is not an `Object` instance;
928
+ - code: `ERR_XOBJ_NSTR`
929
+ + if `name` parameter given and is not a type of a `string`;
930
+ - code: `ERR_XOBJ_INVARG_KEY`
931
+ + if `name` parameter given and is an empty string.
932
+
933
+ <a name="deleteXObjElement"></a>
934
+ #### **deleteXObjElement(object, name)** => `boolean`
935
+
936
+ This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
937
+
938
+ ##### ***parameters***
939
+
940
+ | parameter name | value type | default value | description |
941
+ |:---|---|---:|:---|
942
+ | `object` | `object` | --- | some object |
943
+ | `name` | `string` | --- | some child element ID |
944
+
945
+ ##### ***exceptions***
946
+
947
+ The function throws a `TypeError` exception in case:
948
+
949
+ - code: `ERR_XOBJ_NPOBJ`
950
+ + if `object` parameter is not an `Object` instance.
951
+
952
+ <a name="deleteXObjElementEx"></a>
953
+ #### **deleteXObjElementEx(object, name)** => `object`
954
+
955
+ This function deletes an element addressed by `name` parameter from a given object and returns an `object` that represents a status of the operation.
956
+
957
+ ##### ***parameters***
958
+
959
+ | parameter name | value type | default value | description |
960
+ |:---|---|---:|:---|
961
+ | `object` | `object` | --- | some object |
962
+ | `name` | `string` | --- | some child element ID |
963
+
964
+ ##### ***result***
965
+
966
+ The status of an operation contains 2 fields:
967
+
968
+ - `isSucceed` - `boolean` value;
969
+ - `item` - an item which was deleted or a `null`.
970
+
971
+ ##### ***exceptions***
972
+
973
+ The function throws a `TypeError` exception in case:
974
+
975
+ - code: `ERR_XOBJ_NPOBJ`
976
+ + if `object` parameter is not an `Object` instance;
977
+ - code: `ERR_XOBJ_NSTR`
978
+ + if `name` parameter given and is not a type of a `string`;
979
+ - code: `ERR_XOBJ_INVARG_KEY`
980
+ + if `name` parameter given and is an empty string.
981
+
982
+ <a name="renameXObjElement"></a>
983
+ #### **renameXObjElement(object, name, value)** => `boolean`
984
+
985
+ This function renames an element addressed by `name` for the given object. If succeed `true` is returned.
986
+
987
+ ##### ***parameters***
988
+
989
+ | parameter name | value type | default value | description |
990
+ |:---|---|---:|:---|
991
+ | `object` | `object` | --- | some object |
992
+ | `name` | `string` | --- | some child element ID |
993
+ | `value` | `string` | --- | new element ID |
994
+
995
+ ##### ***exceptions***
996
+
997
+ The function throws a `TypeError` exception in case:
998
+
999
+ - code: `ERR_XOBJ_NPOBJ`
1000
+ + if `object` parameter is not an `Object` instance;
1001
+ - code: `ERR_XOBJ_NSTR`
1002
+ + if `name` parameter given and is not a type of a `string`;
1003
+ + id `value` parameter given and is not a type of a `string`.
1004
+
1005
+ ### Other special functions
1006
+
1007
+ <a name="evalXObjEName"></a>
1008
+ #### **evalXObjEName(value)** => `null`\|`number`\|`string`
1009
+
1010
+ This function evaluates a given value whether it can be accepted as a valid element ID and returns a result.
1011
+
1012
+ ##### ***parameters***
1013
+
1014
+ | parameter name | value type | default value | description |
1015
+ |:---|---|---:|:---|
1016
+ | `value` | `any` | --- | some value to evaluate |
1017
+
1018
+ ##### ***result***
1019
+
1020
+ The dependencies of a resulted value returned by the function given in the following table:
1021
+
1022
+ | given value | value type of the result |
1023
+ |:---|---|
1024
+ | value is an integer positive number or a string that can be converted to a such number | `number` |
1025
+ | any other string that can\'t be converted to a number | `string` |
1026
+ | any other cases | `null` |
1027
+
1028
+ <a name="insertXObjEList"></a>
1029
+ #### **insertXObjEList(object, name\[, options])** => `null`\|`object[]`
1030
+
1031
+ 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.
1032
+
1033
+ ##### ***parameters***
1034
+
1035
+ | parameter name | value type | default value | description |
1036
+ |:---|---|---:|:---|
1037
+ | `object` | `object` | --- | some object |
1038
+ | `name` | `string` | --- | some child element ID |
1039
+ | `options` | `object` | --- | options |
1040
+
1041
+ For details of an `options` parameter read the appropriate section in the description of the [`insertXObjEListEx`](#insertXObjEListEx) function.
1042
+
1043
+ ##### ***exceptions***
1044
+
1045
+ The function throws a `TypeError` exception in case:
1046
+
1047
+ - code: `ERR_XOBJ_NPOBJ`
1048
+ + if `object` parameter is not an `Object` instance.
1049
+
1050
+ <a name="insertXObjEListEx"></a>
1051
+ #### **insertXObjEListEx(object, name\[, options])** => `object`
1052
+
1053
+ > since: \[v0.2.0]
1054
+
1055
+ This function inserts an elements list named by a `name` parameter into a given object and returns an `object` that represents a status of the operation.
1056
+
1057
+ ##### ***parameters***
1058
+
1059
+ | parameter name | value type | default value | description |
1060
+ |:---|---|---:|:---|
1061
+ | `object` | `object` | --- | some object |
1062
+ | `name` | `string` | --- | some child element ID |
1063
+ | `options` | `object` | --- | options |
1064
+
1065
+ An `options` parameter contains the following parameters:
1066
+
1067
+ | option name|value type|default value|description|
1068
+ |:---|---|---:|:---|
1069
+ | `force` | `boolean` | `false` | modifies the functions behavior |
1070
+ | `ripOldies` | `boolean` | `false` | it prevents a replacement of an element which exists and has a type of an `array`. Applied only if `force` option is set to `true` |
1071
+
1072
+ An `options.force` parameter modifies the functions behavior as follows:
1073
+ - when set to `true`, the addressed element will be replaced with an empty elements list.
1074
+ - when set to `false`, if the target element type is an `object`, the function will wraps it in the list.
1075
+ - when set to `false`, if the target element exists and is not an object or an array, the function will failed.
1076
+
1077
+ ##### ***result***
1078
+
1079
+ The status of an operation contains 2 fields:
1080
+
1081
+ - `isSucceed` - `boolean` value;
1082
+ - `item` - an item which was inserted or a `null`.
1083
+
1084
+ > <!> If a target element exists and it is not a `null`, the function behavior defined by the given options. When a required conditions not met, the function failed.
1085
+
1086
+ ##### ***exceptions***
1087
+
1088
+ The function throws a `TypeError` exception in case:
1089
+
1090
+ - code: `ERR_XOBJ_NPOBJ`
1091
+ + if `object` parameter is not an `Object` instance;
1092
+ - code: `ERR_XOBJ_NSTR`
1093
+ + if `name` parameter given and is not a type of a `string`;
1094
+ - code: `ERR_XOBJ_INVARG_KEY`
1095
+ + if `name` parameter given and is an empty string.
1096
+
1097
+ ### Experimental functions
1098
+
1099
+ > 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.
1100
+
1101
+ <a name="genXObjENameDescr"></a>
1102
+ #### **genXObjENameDescr(name)**
1103
+
1104
+ This function creates a object that contains description of the value given by a `name` parameter.
1105
+
1106
+ A value of the `name` parameter must have some of the following formats:
1107
+
1108
+ 1. `<name>`;
1109
+ 2. `<name>[<child>]`;
1110
+ 3. `<name>[<child>=<value>]`;
1111
+ 4. `<name>[@<attribute>]`;
1112
+ 5. `<name>[@<attribute>=<value>]`;
1113
+
1114
+ > Note: the `<value>` must be quoted if it contains characters like a spaces or square brackets.
1115
+
1116
+ The returned object has following attributes:
1117
+
1118
+ |attribute|value type|description|
1119
+ |:---|---|---|
1120
+ |`isERR`|`boolean`|set to `true` if error happend|
1121
+ |`name`|`string`|contains a name of the element|
1122
+ |`conditions`|`object`|contains conditions applied to that element|
1123
+
1124
+ The object `conditions` property (*if present*) contains following attributes:
1125
+
1126
+ |attribute|value type|description|
1127
+ |:---|---|---|
1128
+ |`type`|`string`||
1129
+ |`name`|`string`||
1130
+ |`value`|`any`||
1131
+
1132
+ <a name="insertXObjElements"></a>
1133
+ #### **insertXObjElements(object, name\[...name_N\[, options]])** => `number`
1134
+
1135
+ This function inserts an elements given by the list of names and returns a quantity of the inserted elements.
1136
+
1137
+ ##### ***parameters***
1138
+
1139
+ The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertXObjElement).
1140
+
1141
+ ##### ***exceptions***
1142
+
1143
+ The function throws a `TypeError` exception in case:
1144
+
1145
+ - code: `ERR_XOBJ_NPOBJ`
1146
+ + if `object` parameter is not an `Object` instance.
1147
+
1148
+ <a name="insertXObjEChain"></a>
1149
+ #### **insertXObjEChain(object, name\[, ...name_N\[, options])**
1150
+
1151
+ This function inserts a chain of the elements listed as a function arguments. If succeed the last inserted element will be returned or `null` if failed.
1152
+
1153
+ > The `options` parameter if given must be an object. For details see [`insertXObjElement`](#insertxobjelementobject-name-options--objectarray).
1154
+
1155
+ ##### ***exceptions***
1156
+
1157
+ The function throws a `TypeError` exception in case:
1158
+
1159
+ - code: `ERR_XOBJ_NPOBJ`
1160
+ + if `object` parameter is not an `Object` instance.
1161
+
1162
+ ### Base class
1163
+
1164
+ #### **TXmlContentParseOptions**
1165
+
1166
+ This class implements an interface for handling XML-parse options.
1167
+
1168
+ ##### class constructor
1169
+
1170
+ The class constructor creates a new instance of the class. It receives arguments listed below:
1171
+
1172
+ |name|type|default value|description|
1173
+ |:---|---|---:|:---|
1174
+ |`object`|---|---|a host object.|
1175
+ |`options`|`object`|---|an options settings.|
1176
+
1177
+ ##### class properties
1178
+
1179
+ The table below describes a properties of a `TXmlContentParseOptions` class:
1180
+
1181
+ |name|read only|description|
1182
+ |:---|---|:---|
1183
+ |settings|yes|presents a current options|
1184
+ |xml2js|yes|returns an options for an XML-to-JS converter|
1185
+ |js2xml|yes|returns an options for an JS-to-XML converter|
1186
+
1187
+ ##### class methods (*static*)
1188
+
1189
+ ###### **createNewOptionsSet(obj)**
1190
+
1191
+ This method transforms a given object to a set of accepted parser options.