@ygracs/xobj-lib-js 0.1.1 → 0.2.0
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 +41 -81
- package/LICENSE +9 -9
- package/README.md +18 -15
- package/doc/xObj.md +790 -408
- package/index.js +18 -11
- package/lib/xObj-defs.js +166 -0
- package/lib/xObj-lib.js +1562 -1128
- package/package.json +41 -36
package/doc/xObj.md
CHANGED
|
@@ -1,408 +1,790 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
2
|
-
>|:---|---:|
|
|
3
|
-
>|date:|
|
|
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
|
|
51
|
-
|
|
52
|
-
> Note:
|
|
53
|
-
> If a `key` parameter
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#### **
|
|
80
|
-
|
|
81
|
-
This function reads a value of an object parameter and
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
#### **
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
>
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
>
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
#### **
|
|
359
|
-
|
|
360
|
-
This
|
|
361
|
-
|
|
362
|
-
>
|
|
363
|
-
>
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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.
|