@ygracs/xobj-lib-js 0.0.14-rc1 → 0.0.14-rc3
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 +17 -0
- package/LICENSE +9 -9
- package/doc/xObj.md +71 -16
- package/index.js +11 -14
- package/lib/xObj-lib.js +468 -137
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
#### *v0.0.14rc3*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - `xObj-lib.md` updated;
|
|
6
|
+
> - some fixes in 'xObj-lib.js' module;
|
|
7
|
+
> - added `genXObjENameDescr` function.
|
|
8
|
+
|
|
9
|
+
#### *v0.0.14rc2*
|
|
10
|
+
|
|
11
|
+
Pre-release version.
|
|
12
|
+
|
|
13
|
+
> - some fixes in 'xObj-lib.js' module;
|
|
14
|
+
> - added some error codes (see details in docs);
|
|
15
|
+
> - added evalXObjEName function;
|
|
16
|
+
> - added deleteXObjAttribute function.
|
|
17
|
+
|
|
1
18
|
#### *v0.0.14rc1*
|
|
2
19
|
|
|
3
20
|
Pre-release version.
|
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019-2023 Yuri Grachev
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2023 Yuri Grachev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.22|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2023-
|
|
3
|
+
>|date:|2023-03-15|
|
|
4
4
|
|
|
5
5
|
## Intoduction
|
|
6
6
|
|
|
@@ -52,7 +52,7 @@ The settings listed in the table below:
|
|
|
52
52
|
> Note:
|
|
53
53
|
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
|
|
54
54
|
>
|
|
55
|
-
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
55
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
56
56
|
|
|
57
57
|
#### **readXObjParam(object\[, key])**
|
|
58
58
|
|
|
@@ -113,7 +113,7 @@ This function sets object parameter to a given value and if succeed returns `tru
|
|
|
113
113
|
>
|
|
114
114
|
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
115
115
|
>
|
|
116
|
-
> If an `attr` parameter given to the function is not a 'string' type, the function will throw a `TypeError` exception.
|
|
116
|
+
> If an `attr` parameter given to the function is not a 'string' type, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
117
117
|
|
|
118
118
|
#### **readXObjAttr(object, attr\[, key])**
|
|
119
119
|
|
|
@@ -175,7 +175,7 @@ This function sets object attribute to a given value and if succeed returns `tru
|
|
|
175
175
|
> Note:
|
|
176
176
|
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_PARAM_TNAME`.
|
|
177
177
|
>
|
|
178
|
-
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
178
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
179
179
|
|
|
180
180
|
#### **readXObjParamRaw(object\[, key])**
|
|
181
181
|
|
|
@@ -190,7 +190,7 @@ This is a special function that writes a given value of an object parameter as "
|
|
|
190
190
|
> Note:
|
|
191
191
|
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
192
192
|
>
|
|
193
|
-
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
193
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
194
194
|
|
|
195
195
|
#### **readXObjAttrRaw(object, attr\[, key])**
|
|
196
196
|
|
|
@@ -200,24 +200,49 @@ This is a special function that returns a value of an object attribute as "IT IS
|
|
|
200
200
|
|
|
201
201
|
This is a special function that writes a given value of an object attribute as "IT IS".
|
|
202
202
|
|
|
203
|
+
### Other functions for deal with an object attributes
|
|
204
|
+
|
|
205
|
+
> Note:
|
|
206
|
+
> If a `key` parameter given to the function is not a type of `string`, the `TypeError` will be thrown. If that parameter not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
207
|
+
>
|
|
208
|
+
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception (*error code: `ERR_XOBJ_NOBJ`*).
|
|
209
|
+
|
|
203
210
|
#### **getXObjAttributes(object\[, key])**
|
|
204
211
|
|
|
205
|
-
This
|
|
212
|
+
This function returns an object which represents a set of the element attributes for a given object or `null` if failed.
|
|
206
213
|
|
|
207
214
|
#### **checkXObjAttribute(object, attr\[, key])**
|
|
208
215
|
|
|
209
|
-
This
|
|
216
|
+
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.
|
|
217
|
+
|
|
218
|
+
> Note: If an `attr` parameter is not a type of `string`, the function will throw a `TypeError` exception.
|
|
219
|
+
|
|
220
|
+
#### **deleteXObjAttribute(object, attr\[, key])**
|
|
221
|
+
|
|
222
|
+
This function tries to delete an attribute with a name given by `attr` parameter. If succeed `true` is returned.
|
|
210
223
|
|
|
211
224
|
> Note: If an `attr` parameter is not a type of `string`, the function will throw a `TypeError` exception.
|
|
212
225
|
|
|
213
226
|
### Other functions
|
|
214
227
|
|
|
228
|
+
#### **evalXObjEName(name)**
|
|
229
|
+
|
|
230
|
+
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:
|
|
231
|
+
|
|
232
|
+
|given value|value of result|
|
|
233
|
+
|:---|---|
|
|
234
|
+
|value not given (*or `undefined`*)|value of `undefined`|
|
|
235
|
+
|any empty string|an empty string|
|
|
236
|
+
|value is a positive number or a string that can be converted to a such number|value of a `number`|
|
|
237
|
+
|any other string that can\'t be converted to a number|value of a string|
|
|
238
|
+
|any other cases|value of `null`|
|
|
239
|
+
|
|
215
240
|
#### **getXObjElement(object, name)**
|
|
216
241
|
|
|
217
242
|
This function returns an element from a given object by its name or `null` if that element not found.
|
|
218
243
|
|
|
219
244
|
> the function will throw a `TypeError` if:
|
|
220
|
-
> - `object` parameter is not a plain object;
|
|
245
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
221
246
|
> - `name` parameter is not a non-empty string.
|
|
222
247
|
|
|
223
248
|
#### **addXObjElement(object, name)**
|
|
@@ -225,7 +250,7 @@ This function returns an element from a given object by its name or `null` if th
|
|
|
225
250
|
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.
|
|
226
251
|
|
|
227
252
|
> the function will throw a `TypeError` if:
|
|
228
|
-
> - `object` parameter is not a plain object;
|
|
253
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
229
254
|
> - `name` parameter is not a non-empty string.
|
|
230
255
|
|
|
231
256
|
The status of an operation contains 2 fields:
|
|
@@ -238,7 +263,7 @@ The status of an operation contains 2 fields:
|
|
|
238
263
|
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.
|
|
239
264
|
|
|
240
265
|
> the function will throw a `TypeError` if:
|
|
241
|
-
> - `object` parameter is not a plain object;
|
|
266
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
242
267
|
> - `name` parameter is not a non-empty string.
|
|
243
268
|
|
|
244
269
|
An `options.force` parameter modifies the functions behavior as follows:
|
|
@@ -255,7 +280,7 @@ An `options.ripOldies` parameter applied only if `options.force` is `true`. And
|
|
|
255
280
|
This function deletes an element addressed by `name` parameter from a given object. If succeed `true` is returned.
|
|
256
281
|
|
|
257
282
|
> the function will throw a `TypeError` if:
|
|
258
|
-
> - `object` parameter is not a plain object;
|
|
283
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
259
284
|
> - `name` parameter is not a non-empty string.
|
|
260
285
|
|
|
261
286
|
#### **renameXObjElement(object, oldName, newName)**
|
|
@@ -263,20 +288,50 @@ This function deletes an element addressed by `name` parameter from a given obje
|
|
|
263
288
|
This function renames an element with a name `oldName` to a name `newName` for the given object. If succeed `true` is returned.
|
|
264
289
|
|
|
265
290
|
> the function will throw a `TypeError` if:
|
|
266
|
-
> - `object` parameter is not a plain object;
|
|
291
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
267
292
|
> - `oldName` or `newName` parameter is not a non-empty string.
|
|
268
293
|
|
|
269
294
|
### Experimental functions
|
|
270
295
|
|
|
271
296
|
> 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.
|
|
272
297
|
|
|
298
|
+
#### **genXObjENameDescr(name)**
|
|
299
|
+
|
|
300
|
+
This function creates a object that contains description of the value given by a `name` parameter.
|
|
301
|
+
|
|
302
|
+
A value of the `name` parameter must have some of the following formats:
|
|
303
|
+
|
|
304
|
+
1. `<name>`;
|
|
305
|
+
2. `<name>[<child>]`;
|
|
306
|
+
3. `<name>[<child>=<value>]`;
|
|
307
|
+
4. `<name>[@<attribute>]`;
|
|
308
|
+
5. `<name>[@<attribute>=<value>]`;
|
|
309
|
+
|
|
310
|
+
> Note: the `<value>` must be quotted if it contains characters like a spaces or square brackets.
|
|
311
|
+
|
|
312
|
+
The returned object has following attributes:
|
|
313
|
+
|
|
314
|
+
|attribute|value type|description|
|
|
315
|
+
|:---|---|---|
|
|
316
|
+
|`isERR`|`boolean`|set to `true` if error happend|
|
|
317
|
+
|`name`|`string`|contains a name of the element|
|
|
318
|
+
|`conditions`|`object`||
|
|
319
|
+
|
|
320
|
+
The object `conditions` property (*if present*) contains following attributes:
|
|
321
|
+
|
|
322
|
+
|attribute|value type|description|
|
|
323
|
+
|:---|---|---|
|
|
324
|
+
|`type`|`string`||
|
|
325
|
+
|`name`|||
|
|
326
|
+
|`value`|||
|
|
327
|
+
|
|
273
328
|
#### **insertXObjElements(object, names_list\[, options])**
|
|
274
329
|
|
|
275
330
|
This function inserts an elements given by the `names_list` and return quantity of the inserted elements.
|
|
276
331
|
|
|
277
332
|
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
278
333
|
>
|
|
279
|
-
>
|
|
334
|
+
> The `options` parameter if given must be an object. For details see `insertXObjElement`.
|
|
280
335
|
|
|
281
336
|
#### **insertXObjEList(object, name\[, options])**
|
|
282
337
|
|
|
@@ -302,14 +357,14 @@ This function inserts a chain of the elements listed by `names_list`. If succeed
|
|
|
302
357
|
|
|
303
358
|
> If an `object` parameter given to the function is not a plain object, the function will throw a `TypeError` exception.
|
|
304
359
|
>
|
|
305
|
-
>
|
|
360
|
+
> The `options` parameter if given must be an object. For details see `insertXObjElement`.
|
|
306
361
|
|
|
307
362
|
#### **deleteXObjElementEx(object, name)**
|
|
308
363
|
|
|
309
364
|
This function deletes an element addressed by `name` parameter from a given object and returns an `object` that represents a status of the operation.
|
|
310
365
|
|
|
311
366
|
> the function will throw a `TypeError` if:
|
|
312
|
-
> - `object` parameter is not a plain object;
|
|
367
|
+
> - `object` parameter is not a plain object (*error code: `ERR_XOBJ_NOBJ`*);
|
|
313
368
|
> - `name` parameter is not a non-empty string.
|
|
314
369
|
|
|
315
370
|
The status of an operation contains 2 fields:
|
package/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// [v0.1.
|
|
2
|
-
|
|
3
|
-
// === module init block ===
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
// === module
|
|
8
|
-
|
|
9
|
-
// === module
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//module.exports.xObj = xObj;
|
|
14
|
-
module.exports = require('./lib/xObj-lib.js');
|
|
1
|
+
// [v0.1.009-20230316]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
// === module extra block (helper functions) ===
|
|
6
|
+
|
|
7
|
+
// === module main block ===
|
|
8
|
+
|
|
9
|
+
// === module exports block ===
|
|
10
|
+
|
|
11
|
+
module.exports = require('./lib/xObj-lib.js');
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.056-20230316]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
valueToIndex,
|
|
7
|
-
readAsBoolEx, readAsNumberEx,
|
|
6
|
+
valueToIndex,
|
|
7
|
+
readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
|
+
isNullOrUndef,
|
|
8
9
|
isArray, isObject, isPlainObject, readAsListS,
|
|
9
10
|
} = require('@ygracs/bsfoc-lib-js');
|
|
10
11
|
|
|
@@ -12,12 +13,18 @@ const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
|
12
13
|
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
13
14
|
|
|
14
15
|
const XOBJ_TE_INVARG_EMSG = 'invalid argument';
|
|
15
|
-
const XOBJ_TE_NOBJ_EMSG = XOBJ_TE_INVARG_EMSG
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
|
|
17
|
+
const XOBJ_TE_NOBJ_ECODE = 'ERR_XOBJ_NOBJ';
|
|
18
|
+
const XOBJ_TE_NARR_EMSG = `${XOBJ_TE_INVARG_EMSG} (an array expected)`;
|
|
19
|
+
const XOBJ_TE_NARR_ECODE = 'ERR_XOBJ_NARR';
|
|
20
|
+
const XOBJ_TE_NSTR_EMSG = `${XOBJ_TE_INVARG_EMSG} (a string expected)`;
|
|
21
|
+
const XOBJ_TE_NSTR_ECODE = 'ERR_XOBJ_NSTR';
|
|
22
|
+
const XOBJ_TE_NPOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (a plain object expected)`;
|
|
23
|
+
const XOBJ_TE_NPOBJ_ECODE = 'ERR_XOBJ_NPOBJ';
|
|
19
24
|
const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
|
|
25
|
+
const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
|
|
20
26
|
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
27
|
+
const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
|
|
21
28
|
|
|
22
29
|
const DEF_XML_PARSE_OPTIONS = {
|
|
23
30
|
compact: true,
|
|
@@ -46,11 +53,102 @@ const DEF_XML_PARSE_OPTIONS = {
|
|
|
46
53
|
|
|
47
54
|
// === module main block (function definitions) ===
|
|
48
55
|
|
|
56
|
+
function evalXObjEName(value){
|
|
57
|
+
let name = value;
|
|
58
|
+
if (!isNullOrUndef(name)) {
|
|
59
|
+
switch (typeof name) {
|
|
60
|
+
case 'number' : {
|
|
61
|
+
if (Number.isNaN(name) || name < 0) name = null;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'string' : {
|
|
65
|
+
name = name.trim();
|
|
66
|
+
if (name !== '') {
|
|
67
|
+
let value = Number(name);
|
|
68
|
+
if (!Number.isNaN(value)) {
|
|
69
|
+
name = value < 0 ? null : value;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default: {
|
|
75
|
+
name = null;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
return name;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function genXObjENameDescr(value){
|
|
84
|
+
let result = null;
|
|
85
|
+
let name = null;
|
|
86
|
+
let conditions = null;
|
|
87
|
+
let isERR = false;
|
|
88
|
+
let tail = null;
|
|
89
|
+
if (typeof value === 'string') {
|
|
90
|
+
const re = /^\s*([^\[\]\s]+)?(\s*)(\[.*])?\s*$/;
|
|
91
|
+
tail = value.match(re);
|
|
92
|
+
//console.log('CHECK: '+JSON.stringify(tail, null, 2));
|
|
93
|
+
if (tail) {
|
|
94
|
+
if (tail[1]) {
|
|
95
|
+
name = tail[1];
|
|
96
|
+
if (name) {
|
|
97
|
+
if (tail[2] === '') {
|
|
98
|
+
if (tail[3]) {
|
|
99
|
+
const re = /\[(@{0,1})(?:([^\[=]*?)(?:(?=[=])(=)((?![\"\'])[^\]]*|(?=([\"\']))\5(.*)\5))?)](\s*.*)/;
|
|
100
|
+
tail = tail[3].match(re);
|
|
101
|
+
//console.log('CHECK: '+JSON.stringify(tail, null, 2));
|
|
102
|
+
if (tail) {
|
|
103
|
+
let name = evalXObjEName(tail[2]);
|
|
104
|
+
let type = tail[1] === '@' ? 'attribute' : 'child';
|
|
105
|
+
let value = undefined;
|
|
106
|
+
if (tail[3] === '=') value = tail[5] ? tail[6] : tail[4];
|
|
107
|
+
if (tail[7]) isERR = true;
|
|
108
|
+
conditions = {
|
|
109
|
+
name,
|
|
110
|
+
type,
|
|
111
|
+
value,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
} else if (tail[3]) {
|
|
116
|
+
name = null;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
} else {
|
|
122
|
+
name = value;
|
|
123
|
+
};
|
|
124
|
+
name = evalXObjEName(name);
|
|
125
|
+
if (name === null) isERR = true;
|
|
126
|
+
result = {
|
|
127
|
+
name,
|
|
128
|
+
conditions,
|
|
129
|
+
isERR,
|
|
130
|
+
};
|
|
131
|
+
return result;
|
|
132
|
+
};
|
|
133
|
+
|
|
49
134
|
function getXObjElement(obj, name){
|
|
50
|
-
|
|
51
|
-
if (
|
|
135
|
+
let err = null;
|
|
136
|
+
if (!isPlainObject(obj)) {
|
|
137
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
138
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
139
|
+
throw err;
|
|
140
|
+
};
|
|
141
|
+
if (typeof name !== 'string') {
|
|
142
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
143
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
144
|
+
throw err;
|
|
145
|
+
};
|
|
52
146
|
const key = name.trim();
|
|
53
|
-
if (key === '')
|
|
147
|
+
if (key === '') {
|
|
148
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
149
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
150
|
+
throw err;
|
|
151
|
+
};
|
|
54
152
|
// TODO: [?] check type of obj[key_name]
|
|
55
153
|
return obj[key] !== undefined ? obj[key] : null;
|
|
56
154
|
};
|
|
@@ -60,9 +158,9 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME){
|
|
|
60
158
|
try {
|
|
61
159
|
result = getXObjElement(obj, key);
|
|
62
160
|
} catch (err) {
|
|
63
|
-
switch (err.
|
|
64
|
-
case
|
|
65
|
-
case
|
|
161
|
+
switch (err.code) {
|
|
162
|
+
case XOBJ_TE_NSTR_ECODE :
|
|
163
|
+
case XOBJ_TE_KNES_ECODE : {
|
|
66
164
|
break;
|
|
67
165
|
}
|
|
68
166
|
default: {
|
|
@@ -75,10 +173,23 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME){
|
|
|
75
173
|
};
|
|
76
174
|
|
|
77
175
|
function addXObjElement(obj, name){
|
|
78
|
-
|
|
79
|
-
if (
|
|
176
|
+
let err = null;
|
|
177
|
+
if (!isPlainObject(obj)) {
|
|
178
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
179
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
180
|
+
throw err;
|
|
181
|
+
};
|
|
182
|
+
if (typeof name !== 'string') {
|
|
183
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
184
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
185
|
+
throw err;
|
|
186
|
+
};
|
|
80
187
|
const key = name.trim();
|
|
81
|
-
if (key === '')
|
|
188
|
+
if (key === '') {
|
|
189
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
190
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
191
|
+
throw err;
|
|
192
|
+
};
|
|
82
193
|
const item = {};
|
|
83
194
|
let prop = obj[key];
|
|
84
195
|
let isSUCCEED = false;
|
|
@@ -87,14 +198,13 @@ function addXObjElement(obj, name){
|
|
|
87
198
|
obj[key] = prop = item;
|
|
88
199
|
isSUCCEED = true;
|
|
89
200
|
} else if (isObject(prop)) {
|
|
90
|
-
isSUCCEED = true;
|
|
91
201
|
if (isArray(prop)) {
|
|
92
202
|
prop.push(item);
|
|
93
|
-
prop = item;
|
|
94
203
|
} else {
|
|
95
204
|
obj[key] = [ prop, item ];
|
|
96
|
-
prop = item;
|
|
97
205
|
};
|
|
206
|
+
prop = item;
|
|
207
|
+
isSUCCEED = true;
|
|
98
208
|
};
|
|
99
209
|
return {
|
|
100
210
|
isSucceed: isSUCCEED,
|
|
@@ -102,30 +212,36 @@ function addXObjElement(obj, name){
|
|
|
102
212
|
};
|
|
103
213
|
};
|
|
104
214
|
|
|
105
|
-
function insertXObjElement(obj, name, opt){
|
|
106
|
-
|
|
107
|
-
if (
|
|
215
|
+
function insertXObjElement(obj, name, opt = {}){
|
|
216
|
+
let err = null;
|
|
217
|
+
if (!isPlainObject(obj)) {
|
|
218
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
219
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
220
|
+
throw err;
|
|
221
|
+
};
|
|
222
|
+
if (typeof name !== 'string') {
|
|
223
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
224
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
225
|
+
throw err;
|
|
226
|
+
};
|
|
108
227
|
const key = name.trim();
|
|
109
|
-
if (key === '')
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} else if (!isPlainObject(_options)) {
|
|
114
|
-
_options = {};
|
|
228
|
+
if (key === '') {
|
|
229
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
230
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
231
|
+
throw err;
|
|
115
232
|
};
|
|
233
|
+
const _options = isPlainObject(opt) ? opt : {};
|
|
116
234
|
let { force, rip_oldies, ripOldies } = _options;
|
|
117
235
|
if (typeof force !== 'boolean') force = false;
|
|
118
236
|
if (ripOldies === undefined) ripOldies = rip_oldies;
|
|
119
237
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
120
|
-
const item = {};
|
|
121
238
|
let prop = obj[key];
|
|
122
|
-
let isACCEPTED =
|
|
123
|
-
|
|
239
|
+
let isACCEPTED = (
|
|
240
|
+
isNullOrUndef(prop)
|
|
241
|
+
|| (force && (ripOldies || !isPlainObject(prop)))
|
|
242
|
+
);
|
|
243
|
+
if (isACCEPTED) {
|
|
124
244
|
obj[key] = prop = {};
|
|
125
|
-
isACCEPTED = true;
|
|
126
|
-
} else if (force) {
|
|
127
|
-
if (ripOldies || !isPlainObject(prop)) obj[key] = prop = {};
|
|
128
|
-
isACCEPTED = true;
|
|
129
245
|
} else {
|
|
130
246
|
isACCEPTED = isPlainObject(prop);
|
|
131
247
|
};
|
|
@@ -133,10 +249,23 @@ function insertXObjElement(obj, name, opt){
|
|
|
133
249
|
};
|
|
134
250
|
|
|
135
251
|
function deleteXObjElement(obj, name){
|
|
136
|
-
|
|
137
|
-
if (
|
|
252
|
+
let err = null;
|
|
253
|
+
if (!isPlainObject(obj)) {
|
|
254
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
255
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
256
|
+
throw err;
|
|
257
|
+
};
|
|
258
|
+
if (typeof name !== 'string') {
|
|
259
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
260
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
261
|
+
throw err;
|
|
262
|
+
};
|
|
138
263
|
const key = name.trim();
|
|
139
|
-
if (key === '')
|
|
264
|
+
if (key === '') {
|
|
265
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
266
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
267
|
+
throw err;
|
|
268
|
+
};
|
|
140
269
|
let result = false;
|
|
141
270
|
// // TODO: catch errors in strict mode
|
|
142
271
|
result = delete obj[key];
|
|
@@ -144,10 +273,23 @@ function deleteXObjElement(obj, name){
|
|
|
144
273
|
};
|
|
145
274
|
|
|
146
275
|
function deleteXObjElementEx(obj, name){
|
|
147
|
-
|
|
148
|
-
if (
|
|
276
|
+
let err = null;
|
|
277
|
+
if (!isPlainObject(obj)) {
|
|
278
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
279
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
280
|
+
throw err;
|
|
281
|
+
};
|
|
282
|
+
if (typeof name !== 'string') {
|
|
283
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
284
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
285
|
+
throw err;
|
|
286
|
+
};
|
|
149
287
|
const key = name.trim();
|
|
150
|
-
if (key === '')
|
|
288
|
+
if (key === '') {
|
|
289
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
290
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
291
|
+
throw err;
|
|
292
|
+
};
|
|
151
293
|
let prop = obj[key];
|
|
152
294
|
let result = false;
|
|
153
295
|
// // TODO: catch errors in strict mode
|
|
@@ -159,13 +301,24 @@ function deleteXObjElementEx(obj, name){
|
|
|
159
301
|
};
|
|
160
302
|
|
|
161
303
|
function renameXObjElement(obj, name, newName){
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
304
|
+
let err = null;
|
|
305
|
+
if (!isPlainObject(obj)) {
|
|
306
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
307
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
308
|
+
throw err;
|
|
309
|
+
};
|
|
310
|
+
if (typeof name !== 'string' || typeof newName !== 'string') {
|
|
311
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
312
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
313
|
+
throw err;
|
|
314
|
+
};
|
|
165
315
|
const key = name.trim();
|
|
166
|
-
if (key === '') throw new TypeError(XOBJ_TE_KNES_EMSG);
|
|
167
316
|
const newKey = newName.trim();
|
|
168
|
-
if (
|
|
317
|
+
if (key === '' || newKey === '') {
|
|
318
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
319
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
320
|
+
throw err;
|
|
321
|
+
};
|
|
169
322
|
const prop = obj[key];
|
|
170
323
|
let result = false;
|
|
171
324
|
if (prop !== undefined) {
|
|
@@ -180,8 +333,12 @@ function renameXObjElement(obj, name, newName){
|
|
|
180
333
|
return result;
|
|
181
334
|
};
|
|
182
335
|
|
|
183
|
-
function checkXObjAttribute(obj, attr, key){
|
|
184
|
-
if (typeof attr !== 'string')
|
|
336
|
+
function checkXObjAttribute(obj, attr = '', key){
|
|
337
|
+
if (typeof attr !== 'string') {
|
|
338
|
+
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
339
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
340
|
+
throw err;
|
|
341
|
+
};
|
|
185
342
|
let objAttr = null;
|
|
186
343
|
try {
|
|
187
344
|
objAttr = getXObjAttributes(obj, key);
|
|
@@ -200,16 +357,55 @@ function checkXObjAttribute(obj, attr, key){
|
|
|
200
357
|
return result;
|
|
201
358
|
};
|
|
202
359
|
|
|
360
|
+
function deleteXObjAttribute(obj, attr = '', key){
|
|
361
|
+
if (typeof attr !== 'string') {
|
|
362
|
+
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
363
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
364
|
+
throw err;
|
|
365
|
+
};
|
|
366
|
+
let objAttr = null;
|
|
367
|
+
try {
|
|
368
|
+
objAttr = getXObjAttributes(obj, key);
|
|
369
|
+
} catch (err) {
|
|
370
|
+
throw err;
|
|
371
|
+
};
|
|
372
|
+
const attrName = attr.trim();
|
|
373
|
+
let result = false;
|
|
374
|
+
if (objAttr !== null && attrName !== '') {
|
|
375
|
+
// // TODO: catch errors in strict mode
|
|
376
|
+
result = delete objAttr[attrName];
|
|
377
|
+
};
|
|
378
|
+
return result;
|
|
379
|
+
};
|
|
380
|
+
|
|
203
381
|
function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME){
|
|
204
|
-
|
|
205
|
-
if (
|
|
382
|
+
let err = null;
|
|
383
|
+
if (!isPlainObject(obj)) {
|
|
384
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
385
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
386
|
+
throw err;
|
|
387
|
+
};
|
|
388
|
+
if (typeof key !== 'string') {
|
|
389
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
390
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
391
|
+
throw err;
|
|
392
|
+
};
|
|
206
393
|
const _key = key.trim();
|
|
207
394
|
return _key !== '' ? obj[_key] : undefined;
|
|
208
395
|
};
|
|
209
396
|
|
|
210
397
|
function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME){
|
|
211
|
-
|
|
212
|
-
if (
|
|
398
|
+
let err = null;
|
|
399
|
+
if (!isPlainObject(obj)) {
|
|
400
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
401
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
402
|
+
throw err;
|
|
403
|
+
};
|
|
404
|
+
if (typeof key !== 'string') {
|
|
405
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
406
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
407
|
+
throw err;
|
|
408
|
+
};
|
|
213
409
|
const _key = key.trim();
|
|
214
410
|
let isSUCCEED = false;
|
|
215
411
|
if (_key !== '' && value !== undefined){
|
|
@@ -219,8 +415,12 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME){
|
|
|
219
415
|
return isSUCCEED;
|
|
220
416
|
};
|
|
221
417
|
|
|
222
|
-
function readXObjAttrRaw(obj, attr, key){
|
|
223
|
-
if (typeof attr !== 'string')
|
|
418
|
+
function readXObjAttrRaw(obj, attr = '', key){
|
|
419
|
+
if (typeof attr !== 'string') {
|
|
420
|
+
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
421
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
422
|
+
throw err;
|
|
423
|
+
};
|
|
224
424
|
let objAttr = null;
|
|
225
425
|
try {
|
|
226
426
|
objAttr = getXObjAttributes(obj, key);
|
|
@@ -231,8 +431,12 @@ function readXObjAttrRaw(obj, attr, key){
|
|
|
231
431
|
if (objAttr !== null && attrName !== '') return objAttr[attrName];
|
|
232
432
|
};
|
|
233
433
|
|
|
234
|
-
function writeXObjAttrRaw(obj, attr, value, key = XOBJ_DEF_ATTR_TNAME){
|
|
235
|
-
if (typeof attr !== 'string')
|
|
434
|
+
function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME){
|
|
435
|
+
if (typeof attr !== 'string') {
|
|
436
|
+
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
437
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
438
|
+
throw err;
|
|
439
|
+
};
|
|
236
440
|
const attrName = attr.trim();
|
|
237
441
|
let objAttr = null;
|
|
238
442
|
let isSUCCEED = false;
|
|
@@ -240,9 +444,9 @@ function writeXObjAttrRaw(obj, attr, value, key = XOBJ_DEF_ATTR_TNAME){
|
|
|
240
444
|
try {
|
|
241
445
|
objAttr = insertXObjElement(obj, key, { force: true });
|
|
242
446
|
} catch (err) {
|
|
243
|
-
switch (err.
|
|
244
|
-
case
|
|
245
|
-
case
|
|
447
|
+
switch (err.code) {
|
|
448
|
+
case XOBJ_TE_NSTR_ECODE :
|
|
449
|
+
case XOBJ_TE_KNES_ECODE : {
|
|
246
450
|
break;
|
|
247
451
|
}
|
|
248
452
|
default: {
|
|
@@ -264,8 +468,8 @@ function readXObjParam(obj, key){
|
|
|
264
468
|
try {
|
|
265
469
|
result = readXObjParamRaw(obj, key);
|
|
266
470
|
} catch (err) {
|
|
267
|
-
switch (err.
|
|
268
|
-
case
|
|
471
|
+
switch (err.code) {
|
|
472
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
269
473
|
break;
|
|
270
474
|
}
|
|
271
475
|
default: {
|
|
@@ -286,8 +490,8 @@ function readXObjParamAsBool(obj, defValue, key){
|
|
|
286
490
|
try {
|
|
287
491
|
result = readXObjParamRaw(obj, key);
|
|
288
492
|
} catch (err) {
|
|
289
|
-
switch (err.
|
|
290
|
-
case
|
|
493
|
+
switch (err.code) {
|
|
494
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
291
495
|
break;
|
|
292
496
|
}
|
|
293
497
|
default: {
|
|
@@ -304,8 +508,8 @@ function readXObjParamAsNum(obj, defValue, key){
|
|
|
304
508
|
try {
|
|
305
509
|
result = readXObjParamRaw(obj, key);
|
|
306
510
|
} catch (err) {
|
|
307
|
-
switch (err.
|
|
308
|
-
case
|
|
511
|
+
switch (err.code) {
|
|
512
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
309
513
|
break;
|
|
310
514
|
}
|
|
311
515
|
default: {
|
|
@@ -322,8 +526,8 @@ function readXObjParamAsStr(obj, defValue, key){
|
|
|
322
526
|
try {
|
|
323
527
|
result = readXObjParamRaw(obj, key);
|
|
324
528
|
} catch (err) {
|
|
325
|
-
switch (err.
|
|
326
|
-
case
|
|
529
|
+
switch (err.code) {
|
|
530
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
327
531
|
break;
|
|
328
532
|
}
|
|
329
533
|
default: {
|
|
@@ -344,8 +548,8 @@ function readXObjParamAsIndex(obj, key){
|
|
|
344
548
|
try {
|
|
345
549
|
result = readXObjParamRaw(obj, key);
|
|
346
550
|
} catch (err) {
|
|
347
|
-
switch (err.
|
|
348
|
-
case
|
|
551
|
+
switch (err.code) {
|
|
552
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
349
553
|
break;
|
|
350
554
|
}
|
|
351
555
|
default: {
|
|
@@ -365,7 +569,19 @@ function writeXObjParam(obj, value, key){
|
|
|
365
569
|
numberToString: true,
|
|
366
570
|
boolToString: true,
|
|
367
571
|
});
|
|
368
|
-
|
|
572
|
+
try {
|
|
573
|
+
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
574
|
+
} catch (err) {
|
|
575
|
+
switch (err.code) {
|
|
576
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
default: {
|
|
580
|
+
throw err;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
};
|
|
369
585
|
};
|
|
370
586
|
return isSUCCEED;
|
|
371
587
|
};
|
|
@@ -374,7 +590,19 @@ function writeXObjParamAsBool(obj, value, defValue, key){
|
|
|
374
590
|
let isSUCCEED = false;
|
|
375
591
|
if (value !== undefined) {
|
|
376
592
|
const _value = readAsBoolEx(value, defValue).toString();
|
|
377
|
-
|
|
593
|
+
try {
|
|
594
|
+
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
595
|
+
} catch (err) {
|
|
596
|
+
switch (err.code) {
|
|
597
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
default: {
|
|
601
|
+
throw err;
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
};
|
|
378
606
|
};
|
|
379
607
|
return isSUCCEED;
|
|
380
608
|
};
|
|
@@ -383,7 +611,19 @@ function writeXObjParamAsNum(obj, value, defValue, key){
|
|
|
383
611
|
let isSUCCEED = false;
|
|
384
612
|
if (value !== undefined) {
|
|
385
613
|
const _value = readAsNumberEx(value, defValue).toString();
|
|
386
|
-
|
|
614
|
+
try {
|
|
615
|
+
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
616
|
+
} catch (err) {
|
|
617
|
+
switch (err.code) {
|
|
618
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
default: {
|
|
622
|
+
throw err;
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
};
|
|
387
627
|
};
|
|
388
628
|
return isSUCCEED;
|
|
389
629
|
};
|
|
@@ -392,7 +632,19 @@ function writeXObjParamAsIndex(obj, value, key){
|
|
|
392
632
|
let isSUCCEED = false;
|
|
393
633
|
if (value !== undefined) {
|
|
394
634
|
const _value = valueToIndex(value).toString();
|
|
395
|
-
|
|
635
|
+
try {
|
|
636
|
+
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
637
|
+
} catch (err) {
|
|
638
|
+
switch (err.code) {
|
|
639
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
default: {
|
|
643
|
+
throw err;
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
};
|
|
396
648
|
};
|
|
397
649
|
return isSUCCEED;
|
|
398
650
|
};
|
|
@@ -410,7 +662,19 @@ function writeXObjParamEx(obj, value, defValue, key){
|
|
|
410
662
|
numberToString: true,
|
|
411
663
|
boolToString: true,
|
|
412
664
|
});
|
|
413
|
-
|
|
665
|
+
try {
|
|
666
|
+
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
667
|
+
} catch (err) {
|
|
668
|
+
switch (err.code) {
|
|
669
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
default: {
|
|
673
|
+
throw err;
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
};
|
|
414
678
|
};
|
|
415
679
|
return isSUCCEED;
|
|
416
680
|
};
|
|
@@ -420,8 +684,8 @@ function readXObjAttr(obj, attr, key){
|
|
|
420
684
|
try {
|
|
421
685
|
result = readXObjAttrRaw(obj, attr, key);
|
|
422
686
|
} catch (err) {
|
|
423
|
-
switch (err.
|
|
424
|
-
case
|
|
687
|
+
switch (err.code) {
|
|
688
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
425
689
|
break;
|
|
426
690
|
}
|
|
427
691
|
default: {
|
|
@@ -442,8 +706,8 @@ function readXObjAttrAsBool(obj, attr, defValue, key){
|
|
|
442
706
|
try {
|
|
443
707
|
result = readXObjAttrRaw(obj, attr, key);
|
|
444
708
|
} catch (err) {
|
|
445
|
-
switch (err.
|
|
446
|
-
case
|
|
709
|
+
switch (err.code) {
|
|
710
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
447
711
|
break;
|
|
448
712
|
}
|
|
449
713
|
default: {
|
|
@@ -460,8 +724,8 @@ function readXObjAttrAsNum(obj, attr, defValue, key){
|
|
|
460
724
|
try {
|
|
461
725
|
result = readXObjAttrRaw(obj, attr, key);
|
|
462
726
|
} catch (err) {
|
|
463
|
-
switch (err.
|
|
464
|
-
case
|
|
727
|
+
switch (err.code) {
|
|
728
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
465
729
|
break;
|
|
466
730
|
}
|
|
467
731
|
default: {
|
|
@@ -478,8 +742,8 @@ function readXObjAttrAsStr(obj, attr, defValue, key){
|
|
|
478
742
|
try {
|
|
479
743
|
result = readXObjAttrRaw(obj, attr, key);
|
|
480
744
|
} catch (err) {
|
|
481
|
-
switch (err.
|
|
482
|
-
case
|
|
745
|
+
switch (err.code) {
|
|
746
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
483
747
|
break;
|
|
484
748
|
}
|
|
485
749
|
default: {
|
|
@@ -500,8 +764,8 @@ function readXObjAttrAsIndex(obj, attr, key){
|
|
|
500
764
|
try {
|
|
501
765
|
result = readXObjAttrRaw(obj, attr, key);
|
|
502
766
|
} catch (err) {
|
|
503
|
-
switch (err.
|
|
504
|
-
case
|
|
767
|
+
switch (err.code) {
|
|
768
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
505
769
|
break;
|
|
506
770
|
}
|
|
507
771
|
default: {
|
|
@@ -521,7 +785,19 @@ function writeXObjAttr(obj, attr, value, key){
|
|
|
521
785
|
numberToString: true,
|
|
522
786
|
boolToString: true,
|
|
523
787
|
});
|
|
524
|
-
|
|
788
|
+
try {
|
|
789
|
+
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
790
|
+
} catch (err) {
|
|
791
|
+
switch (err.code) {
|
|
792
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
default: {
|
|
796
|
+
throw err;
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
};
|
|
525
801
|
};
|
|
526
802
|
return isSUCCEED;
|
|
527
803
|
};
|
|
@@ -530,7 +806,19 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key){
|
|
|
530
806
|
let isSUCCEED = false;
|
|
531
807
|
if (value !== undefined) {
|
|
532
808
|
const _value = readAsBoolEx(value, defValue).toString();
|
|
533
|
-
|
|
809
|
+
try {
|
|
810
|
+
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
811
|
+
} catch (err) {
|
|
812
|
+
switch (err.code) {
|
|
813
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
default: {
|
|
817
|
+
throw err;
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
};
|
|
534
822
|
};
|
|
535
823
|
return isSUCCEED;
|
|
536
824
|
};
|
|
@@ -539,7 +827,19 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key){
|
|
|
539
827
|
let isSUCCEED = false;
|
|
540
828
|
if (value !== undefined) {
|
|
541
829
|
const _value = readAsNumberEx(value, defValue).toString();
|
|
542
|
-
|
|
830
|
+
try {
|
|
831
|
+
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
832
|
+
} catch (err) {
|
|
833
|
+
switch (err.code) {
|
|
834
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
default: {
|
|
838
|
+
throw err;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
};
|
|
543
843
|
};
|
|
544
844
|
return isSUCCEED;
|
|
545
845
|
};
|
|
@@ -548,7 +848,19 @@ function writeXObjAttrAsIndex(obj, attr, value, key){
|
|
|
548
848
|
let isSUCCEED = false;
|
|
549
849
|
if (value !== undefined) {
|
|
550
850
|
const _value = valueToIndex(value).toString();
|
|
551
|
-
|
|
851
|
+
try {
|
|
852
|
+
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
853
|
+
} catch (err) {
|
|
854
|
+
switch (err.code) {
|
|
855
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
default: {
|
|
859
|
+
throw err;
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
};
|
|
552
864
|
};
|
|
553
865
|
return isSUCCEED;
|
|
554
866
|
};
|
|
@@ -566,86 +878,100 @@ function writeXObjAttrEx(obj, attr, value, defValue, key){
|
|
|
566
878
|
numberToString: true,
|
|
567
879
|
boolToString: true,
|
|
568
880
|
});
|
|
569
|
-
|
|
881
|
+
try {
|
|
882
|
+
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
883
|
+
} catch (err) {
|
|
884
|
+
switch (err.code) {
|
|
885
|
+
case XOBJ_TE_NSTR_ECODE : {
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
default: {
|
|
889
|
+
throw err;
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
};
|
|
570
894
|
};
|
|
571
895
|
return isSUCCEED;
|
|
572
896
|
};
|
|
573
897
|
|
|
574
898
|
function insertXObjElements(obj, ...args){
|
|
575
|
-
if (!isPlainObject(obj))
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (args_len > 0) {
|
|
580
|
-
let pos = args_len-1;
|
|
581
|
-
if (typeof args[pos] === 'boolean') {
|
|
582
|
-
opt.force = args.pop();
|
|
583
|
-
} else if (isPlainObject(args[pos])) {
|
|
584
|
-
opt = args.pop();
|
|
585
|
-
};
|
|
899
|
+
if (!isPlainObject(obj)) {
|
|
900
|
+
let err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
901
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
902
|
+
throw err;
|
|
586
903
|
};
|
|
587
|
-
const
|
|
904
|
+
const len = args.length;
|
|
905
|
+
const hasOpt = len > 0 && isPlainObject(args[len - 1]);
|
|
906
|
+
const opt = hasOpt ? args.pop() : {};
|
|
907
|
+
const names = readAsListS({
|
|
588
908
|
trim: true,
|
|
589
909
|
keep_empty: false,
|
|
590
910
|
}, ...args);
|
|
591
|
-
|
|
592
|
-
|
|
911
|
+
let count = 0;
|
|
912
|
+
for (let key of names) {
|
|
913
|
+
if (insertXObjElement(obj, key, opt) !== null) count++;
|
|
593
914
|
};
|
|
594
915
|
return count;
|
|
595
916
|
};
|
|
596
917
|
|
|
597
|
-
function insertXObjEList(obj, name, opt){
|
|
598
|
-
|
|
599
|
-
if (
|
|
918
|
+
function insertXObjEList(obj, name, opt = {}){
|
|
919
|
+
let err = null;
|
|
920
|
+
if (!isPlainObject(obj)) {
|
|
921
|
+
err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
922
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
923
|
+
throw err;
|
|
924
|
+
};
|
|
925
|
+
if (typeof name !== 'string') {
|
|
926
|
+
err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
927
|
+
err.code = XOBJ_TE_NSTR_ECODE;
|
|
928
|
+
throw err;
|
|
929
|
+
};
|
|
600
930
|
const key = name.trim();
|
|
601
|
-
if (key === '')
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
} else if (!isPlainObject(_options)) {
|
|
606
|
-
_options = {};
|
|
931
|
+
if (key === '') {
|
|
932
|
+
err = new TypeError(XOBJ_TE_KNES_EMSG);
|
|
933
|
+
err.code = XOBJ_TE_KNES_ECODE;
|
|
934
|
+
throw err;
|
|
607
935
|
};
|
|
936
|
+
const _options = isPlainObject(opt) ? opt : {};
|
|
608
937
|
let { force, rip_oldies, ripOldies } = _options;
|
|
609
938
|
if (typeof force !== 'boolean') force = false;
|
|
610
939
|
if (ripOldies === undefined) ripOldies = rip_oldies;
|
|
611
940
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
612
|
-
let
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
941
|
+
let item = obj[key];
|
|
942
|
+
let isACCEPTED = (
|
|
943
|
+
isNullOrUndef(item)
|
|
944
|
+
|| (force && (ripOldies || !isArray(item)))
|
|
945
|
+
);
|
|
946
|
+
if (isACCEPTED) {
|
|
947
|
+
obj[key] = item = [];
|
|
619
948
|
} else {
|
|
620
|
-
isACCEPTED = isArray(
|
|
621
|
-
if (!isACCEPTED && isPlainObject(
|
|
622
|
-
obj[key] =
|
|
949
|
+
isACCEPTED = isArray(item);
|
|
950
|
+
if (!isACCEPTED && isPlainObject(item)) {
|
|
951
|
+
obj[key] = item = [ item ];
|
|
623
952
|
isACCEPTED = true;
|
|
624
953
|
};
|
|
625
954
|
};
|
|
626
|
-
return isACCEPTED ?
|
|
955
|
+
return isACCEPTED ? item : null;
|
|
627
956
|
};
|
|
628
957
|
|
|
629
958
|
function insertXObjEChain(obj, ...args){
|
|
630
|
-
if (!isPlainObject(obj))
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
};
|
|
640
|
-
};
|
|
641
|
-
let key_names = readAsListS({
|
|
959
|
+
if (!isPlainObject(obj)) {
|
|
960
|
+
let err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
961
|
+
err.code = XOBJ_TE_NPOBJ_ECODE;
|
|
962
|
+
throw err;
|
|
963
|
+
};
|
|
964
|
+
const len = args.length;
|
|
965
|
+
const hasOpt = len > 0 && isPlainObject(args[len - 1]);
|
|
966
|
+
const opt = hasOpt ? args.pop() : {};
|
|
967
|
+
const names = readAsListS({
|
|
642
968
|
trim: true,
|
|
643
969
|
keep_empty: false,
|
|
644
970
|
}, ...args);
|
|
645
971
|
let curObj = obj;
|
|
646
972
|
let isSUCCEED = false;
|
|
647
|
-
for (let
|
|
648
|
-
obj = insertXObjElement(obj,
|
|
973
|
+
for (let key of names) {
|
|
974
|
+
obj = insertXObjElement(obj, key, opt);
|
|
649
975
|
isSUCCEED = isPlainObject(obj);
|
|
650
976
|
if (!isSUCCEED) break;
|
|
651
977
|
curObj = obj;
|
|
@@ -754,6 +1080,8 @@ exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
|
754
1080
|
|
|
755
1081
|
exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
|
756
1082
|
|
|
1083
|
+
exports.evalXObjEName = evalXObjEName;
|
|
1084
|
+
|
|
757
1085
|
exports.readXObjParamRaw = readXObjParamRaw;
|
|
758
1086
|
exports.readXObjParam = readXObjParam;
|
|
759
1087
|
exports.readXObjParamAsBool = readXObjParamAsBool;
|
|
@@ -782,6 +1110,7 @@ exports.writeXObjAttrEx = writeXObjAttrEx;
|
|
|
782
1110
|
|
|
783
1111
|
exports.getXObjAttributes = getXObjAttributes;
|
|
784
1112
|
exports.checkXObjAttribute = checkXObjAttribute;
|
|
1113
|
+
exports.deleteXObjAttribute = deleteXObjAttribute;
|
|
785
1114
|
|
|
786
1115
|
exports.getXObjElement = getXObjElement;
|
|
787
1116
|
exports.insertXObjElement = insertXObjElement;
|
|
@@ -793,3 +1122,5 @@ exports.renameXObjElement = renameXObjElement;
|
|
|
793
1122
|
exports.insertXObjElements = insertXObjElements;
|
|
794
1123
|
exports.insertXObjEList = insertXObjEList;
|
|
795
1124
|
exports.insertXObjEChain = insertXObjEChain;
|
|
1125
|
+
|
|
1126
|
+
exports.genXObjENameDescr = genXObjENameDescr;
|