@ygracs/xobj-lib-js 0.1.0 → 0.1.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/CHANGELOG.md +14 -0
- package/LICENSE +1 -1
- package/index.js +9 -2
- package/lib/xObj-defs.js +166 -0
- package/lib/xObj-lib.js +386 -147
- package/package.json +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
#### *v0.1.2*
|
|
2
|
+
|
|
3
|
+
Release version.
|
|
4
|
+
|
|
5
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.1;
|
|
6
|
+
> - move some definitions from `xObj-lib.js` module into `xObj-defs.js`;
|
|
7
|
+
> - fix behavior for function: `evalXObjEName`.
|
|
8
|
+
|
|
9
|
+
#### *v0.1.1*
|
|
10
|
+
|
|
11
|
+
Release version.
|
|
12
|
+
|
|
13
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.0.
|
|
14
|
+
|
|
1
15
|
#### *v0.1.0*
|
|
2
16
|
|
|
3
17
|
Release version.
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2024 Yuri Grachev
|
|
4
4
|
|
|
5
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
6
|
|
package/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.012-20240624]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
|
+
const {
|
|
6
|
+
TXmlContentParseOptions,
|
|
7
|
+
DEF_XML_PARSE_OPTIONS,
|
|
8
|
+
} = require('./lib/xObj-defs');
|
|
9
|
+
|
|
5
10
|
// === module extra block (helper functions) ===
|
|
6
11
|
|
|
7
12
|
// === module main block ===
|
|
8
13
|
|
|
9
14
|
// === module exports block ===
|
|
10
15
|
|
|
11
|
-
module.exports = require('./lib/xObj-lib
|
|
16
|
+
module.exports = require('./lib/xObj-lib');
|
|
17
|
+
module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
|
18
|
+
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
package/lib/xObj-defs.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// [v0.1.060-20240623]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
//valueToIndex,
|
|
7
|
+
//readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
|
+
//isNullOrUndef,
|
|
9
|
+
//isArray, isObject,
|
|
10
|
+
isPlainObject, //readAsListS,
|
|
11
|
+
} = require('@ygracs/bsfoc-lib-js');
|
|
12
|
+
|
|
13
|
+
// === module extra block (helper functions) ===
|
|
14
|
+
|
|
15
|
+
// === module main block ===
|
|
16
|
+
|
|
17
|
+
/***
|
|
18
|
+
* (* constant definitions *)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
22
|
+
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
23
|
+
|
|
24
|
+
const XOBJ_TE_INVARG_EMSG = 'invalid argument';
|
|
25
|
+
const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
|
|
26
|
+
const XOBJ_TE_NOBJ_ECODE = 'ERR_XOBJ_NOBJ';
|
|
27
|
+
const XOBJ_TE_NARR_EMSG = `${XOBJ_TE_INVARG_EMSG} (an array expected)`;
|
|
28
|
+
const XOBJ_TE_NARR_ECODE = 'ERR_XOBJ_NARR';
|
|
29
|
+
const XOBJ_TE_NSTR_EMSG = `${XOBJ_TE_INVARG_EMSG} (a string expected)`;
|
|
30
|
+
const XOBJ_TE_NSTR_ECODE = 'ERR_XOBJ_NSTR';
|
|
31
|
+
const XOBJ_TE_NPOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (a plain object expected)`;
|
|
32
|
+
const XOBJ_TE_NPOBJ_ECODE = 'ERR_XOBJ_NPOBJ';
|
|
33
|
+
const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
|
|
34
|
+
const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
|
|
35
|
+
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
36
|
+
const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
|
|
37
|
+
|
|
38
|
+
const DEF_XML_PARSE_OPTIONS = {
|
|
39
|
+
compact: true,
|
|
40
|
+
declarationKey: '__decl',
|
|
41
|
+
attributesKey: XOBJ_DEF_ATTR_TNAME,
|
|
42
|
+
textKey: XOBJ_DEF_PARAM_TNAME,
|
|
43
|
+
commentKey: '__note',
|
|
44
|
+
cdataKey: '__cdata',
|
|
45
|
+
nameKey: '__name',
|
|
46
|
+
typeKey: '__type',
|
|
47
|
+
parentKey: 'parent',
|
|
48
|
+
elementsKey: 'items',
|
|
49
|
+
ignoreDeclaration: false,
|
|
50
|
+
ignoreDocType: false,
|
|
51
|
+
ignoreInstractions: false,
|
|
52
|
+
ignoreText: false,
|
|
53
|
+
ignoreComments: false,
|
|
54
|
+
ignoreCData: false,
|
|
55
|
+
fullTagEmptyElement: true,
|
|
56
|
+
addParent: false,
|
|
57
|
+
trim: true,
|
|
58
|
+
spaces: 2,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/***
|
|
62
|
+
* (* function definitions *)
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/***
|
|
66
|
+
* (* class definitions *)
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
class TXmlContentParseOptions {
|
|
70
|
+
#_options = null;
|
|
71
|
+
|
|
72
|
+
constructor(param){
|
|
73
|
+
this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get settings(){ return this.#_options }
|
|
77
|
+
|
|
78
|
+
get xml2js(){
|
|
79
|
+
let _settings = this.#_options;
|
|
80
|
+
return {
|
|
81
|
+
compact: _settings.compact,
|
|
82
|
+
declarationKey: _settings.declarationKey,
|
|
83
|
+
attributesKey: _settings.attributesKey,
|
|
84
|
+
textKey: _settings.textKey,
|
|
85
|
+
commentKey: _settings.commentKey,
|
|
86
|
+
cdataKey: _settings.cdataKey,
|
|
87
|
+
nameKey: _settings.nameKey,
|
|
88
|
+
typeKey: _settings.typeKey,
|
|
89
|
+
parentKey: _settings.parentKey,
|
|
90
|
+
elementsKey: _settings.elementsKey,
|
|
91
|
+
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
92
|
+
ignoreDocType: _settings.ignoreDocType,
|
|
93
|
+
ignoreInstraction: _settings.ignoreInstractions,
|
|
94
|
+
ignoreText: _settings.ignoreText,
|
|
95
|
+
ignoreComment: _settings.ignoreComments,
|
|
96
|
+
ignoreCData: _settings.ignoreCData,
|
|
97
|
+
addParent: _settings.addParent,
|
|
98
|
+
trim: _settings.trim,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get js2xml(){
|
|
103
|
+
let _settings = this.#_options;
|
|
104
|
+
return {
|
|
105
|
+
compact: _settings.compact,
|
|
106
|
+
declarationKey: _settings.declarationKey,
|
|
107
|
+
attributesKey: _settings.attributesKey,
|
|
108
|
+
textKey: _settings.textKey,
|
|
109
|
+
commentKey: _settings.commentKey,
|
|
110
|
+
cdataKey: _settings.cdataKey,
|
|
111
|
+
nameKey: _settings.nameKey,
|
|
112
|
+
typeKey: _settings.typeKey,
|
|
113
|
+
parentKey: _settings.parentKey,
|
|
114
|
+
elementsKey: _settings.elementsKey,
|
|
115
|
+
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
116
|
+
ignoreDocType: _settings.ignoreDocType,
|
|
117
|
+
ignoreInstraction: _settings.ignoreInstractions,
|
|
118
|
+
ignoreText: _settings.ignoreText,
|
|
119
|
+
ignoreComment: _settings.ignoreComments,
|
|
120
|
+
ignoreCData: _settings.ignoreCData,
|
|
121
|
+
fullTagEmptyElement: _settings.fullTagEmptyElement,
|
|
122
|
+
spaces: _settings.spaces,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static createNewOptionsSet(opt){
|
|
127
|
+
if (opt instanceof TXmlContentParseOptions) {
|
|
128
|
+
opt = opt.settings;
|
|
129
|
+
} else if (isPlainObject(opt)) {
|
|
130
|
+
opt = isPlainObject(opt.settings) ? opt.settings : opt;
|
|
131
|
+
} else {
|
|
132
|
+
opt = DEF_XML_PARSE_OPTIONS;
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
compact: opt.compact,
|
|
136
|
+
declarationKey: opt.declarationKey,
|
|
137
|
+
attributesKey: opt.attributesKey,
|
|
138
|
+
textKey: opt.textKey,
|
|
139
|
+
commentKey: opt.commentKey,
|
|
140
|
+
cdataKey: opt.cdataKey,
|
|
141
|
+
nameKey: opt.nameKey,
|
|
142
|
+
typeKey: opt.typeKey,
|
|
143
|
+
parentKey: opt.parentKey,
|
|
144
|
+
elementsKey: opt.elementsKey,
|
|
145
|
+
ignoreDeclaration: opt.ignoreDeclaration,
|
|
146
|
+
ignoreDocType: opt.ignoreDocType,
|
|
147
|
+
ignoreInstractions: opt.ignoreInstractions,
|
|
148
|
+
ignoreText: opt.ignoreText,
|
|
149
|
+
ignoreComments: opt.ignoreComments,
|
|
150
|
+
ignoreCData: opt.ignoreCData,
|
|
151
|
+
fullTagEmptyElement: opt.fullTagEmptyElement,
|
|
152
|
+
addParent: opt.addParent,
|
|
153
|
+
trim: opt.trim,
|
|
154
|
+
spaces: opt.spaces,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// === module exports block ===
|
|
161
|
+
|
|
162
|
+
module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
163
|
+
module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
164
|
+
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
165
|
+
|
|
166
|
+
module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.063-20240624]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
valueToIndex,
|
|
6
|
+
valueToIndex, valueToIDString,
|
|
7
7
|
readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
8
|
isNullOrUndef,
|
|
9
|
-
|
|
9
|
+
isInteger,
|
|
10
|
+
isArray, isObject, isPlainObject,
|
|
11
|
+
readAsListS,
|
|
10
12
|
} = require('@ygracs/bsfoc-lib-js');
|
|
11
13
|
|
|
14
|
+
// === module extra block (helper functions) ===
|
|
15
|
+
|
|
16
|
+
// === module main block ===
|
|
17
|
+
|
|
18
|
+
/***
|
|
19
|
+
* (* constant definitions *)
|
|
20
|
+
*/
|
|
21
|
+
|
|
12
22
|
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
13
23
|
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
14
24
|
|
|
@@ -26,56 +36,37 @@ const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
|
|
|
26
36
|
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
27
37
|
const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
attributesKey: XOBJ_DEF_ATTR_TNAME,
|
|
33
|
-
textKey: XOBJ_DEF_PARAM_TNAME,
|
|
34
|
-
commentKey: '__note',
|
|
35
|
-
cdataKey: '__cdata',
|
|
36
|
-
nameKey: '__name',
|
|
37
|
-
typeKey: '__type',
|
|
38
|
-
parentKey: 'parent',
|
|
39
|
-
elementsKey: 'items',
|
|
40
|
-
ignoreDeclaration: false,
|
|
41
|
-
ignoreDocType: false,
|
|
42
|
-
ignoreInstractions: false,
|
|
43
|
-
ignoreText: false,
|
|
44
|
-
ignoreComments: false,
|
|
45
|
-
ignoreCData: false,
|
|
46
|
-
fullTagEmptyElement: true,
|
|
47
|
-
addParent: false,
|
|
48
|
-
trim: true,
|
|
49
|
-
spaces: 2,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// === module extra block (helper functions) ===
|
|
53
|
-
|
|
54
|
-
// === module main block (function definitions) ===
|
|
39
|
+
/***
|
|
40
|
+
* (* function definitions *)
|
|
41
|
+
*/
|
|
55
42
|
|
|
56
43
|
function evalXObjEName(value){
|
|
44
|
+
//return valueToIDString(value); // // TODO: [?]
|
|
57
45
|
let name = value;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
switch (typeof name) {
|
|
47
|
+
case 'number' : {
|
|
48
|
+
if (valueToIndex(name) === -1) name = null;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'string' : {
|
|
52
|
+
name = name.trim();
|
|
53
|
+
if (name !== '') {
|
|
54
|
+
let value = Number(name);
|
|
55
|
+
if (!Number.isNaN(value)) {
|
|
56
|
+
name = (
|
|
57
|
+
value < 0 || !isInteger(value)
|
|
58
|
+
? null
|
|
59
|
+
: value
|
|
60
|
+
);
|
|
71
61
|
};
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
default: {
|
|
62
|
+
} else {
|
|
75
63
|
name = null;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
64
|
+
};
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
name = null;
|
|
69
|
+
}
|
|
79
70
|
};
|
|
80
71
|
return name;
|
|
81
72
|
};
|
|
@@ -131,6 +122,14 @@ function genXObjENameDescr(value){
|
|
|
131
122
|
return result;
|
|
132
123
|
};
|
|
133
124
|
|
|
125
|
+
/**
|
|
126
|
+
* @function getXObjElement
|
|
127
|
+
* @param {object}
|
|
128
|
+
* @param {ID_STRING}
|
|
129
|
+
* @returns {?object}
|
|
130
|
+
* @throws {TypeError}
|
|
131
|
+
* @description Extracts an element from a given object by its key.
|
|
132
|
+
*/
|
|
134
133
|
function getXObjElement(obj, name){
|
|
135
134
|
let err = null;
|
|
136
135
|
if (!isPlainObject(obj)) {
|
|
@@ -153,6 +152,14 @@ function getXObjElement(obj, name){
|
|
|
153
152
|
return obj[key] !== undefined ? obj[key] : null;
|
|
154
153
|
};
|
|
155
154
|
|
|
155
|
+
/**
|
|
156
|
+
* @function getXObjAttributes
|
|
157
|
+
* @param {object}
|
|
158
|
+
* @param {ID_STRING} [key]
|
|
159
|
+
* @returns {?object}
|
|
160
|
+
* @throws {TypeError}
|
|
161
|
+
* @description Extracts an attributes from a given object by its key.
|
|
162
|
+
*/
|
|
156
163
|
function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME){
|
|
157
164
|
let result = null;
|
|
158
165
|
try {
|
|
@@ -172,6 +179,14 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME){
|
|
|
172
179
|
return isPlainObject(result) ? result : null;
|
|
173
180
|
};
|
|
174
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @function addXObjElement
|
|
184
|
+
* @param {object}
|
|
185
|
+
* @param {ID_STRING}
|
|
186
|
+
* @returns {?object}
|
|
187
|
+
* @throws {TypeError}
|
|
188
|
+
* @description Adds an element addressed by its key to a given object.
|
|
189
|
+
*/
|
|
175
190
|
function addXObjElement(obj, name){
|
|
176
191
|
let err = null;
|
|
177
192
|
if (!isPlainObject(obj)) {
|
|
@@ -212,6 +227,17 @@ function addXObjElement(obj, name){
|
|
|
212
227
|
};
|
|
213
228
|
};
|
|
214
229
|
|
|
230
|
+
/**
|
|
231
|
+
* @function insertXObjElement
|
|
232
|
+
* @param {object}
|
|
233
|
+
* @param {ID_STRING}
|
|
234
|
+
* @param {object} [opt]
|
|
235
|
+
* @param {bool} [opt.force=false]
|
|
236
|
+
* @param {bool} [opt.ripOldies=false]
|
|
237
|
+
* @returns {?object}
|
|
238
|
+
* @throws {TypeError}
|
|
239
|
+
* @description Inserts an element addressed by its key into a given object.
|
|
240
|
+
*/
|
|
215
241
|
function insertXObjElement(obj, name, opt){
|
|
216
242
|
let err = null;
|
|
217
243
|
if (!isPlainObject(obj)) {
|
|
@@ -247,6 +273,14 @@ function insertXObjElement(obj, name, opt){
|
|
|
247
273
|
return isACCEPTED ? prop : null;
|
|
248
274
|
};
|
|
249
275
|
|
|
276
|
+
/**
|
|
277
|
+
* @function deleteXObjElement
|
|
278
|
+
* @param {object}
|
|
279
|
+
* @param {ID_STRING}
|
|
280
|
+
* @returns {bool}
|
|
281
|
+
* @throws {TypeError}
|
|
282
|
+
* @description Deletes an element addressed by its key from a given object.
|
|
283
|
+
*/
|
|
250
284
|
function deleteXObjElement(obj, name){
|
|
251
285
|
let err = null;
|
|
252
286
|
if (!isPlainObject(obj)) {
|
|
@@ -271,6 +305,14 @@ function deleteXObjElement(obj, name){
|
|
|
271
305
|
return result;
|
|
272
306
|
};
|
|
273
307
|
|
|
308
|
+
/**
|
|
309
|
+
* @function deleteXObjElementEx
|
|
310
|
+
* @param {object}
|
|
311
|
+
* @param {ID_STRING}
|
|
312
|
+
* @returns {object}
|
|
313
|
+
* @throws {TypeError}
|
|
314
|
+
* @description Deletes an element addressed by its key from a given object.
|
|
315
|
+
*/
|
|
274
316
|
function deleteXObjElementEx(obj, name){
|
|
275
317
|
let err = null;
|
|
276
318
|
if (!isPlainObject(obj)) {
|
|
@@ -299,6 +341,15 @@ function deleteXObjElementEx(obj, name){
|
|
|
299
341
|
};
|
|
300
342
|
};
|
|
301
343
|
|
|
344
|
+
/**
|
|
345
|
+
* @function renameXObjElement
|
|
346
|
+
* @param {object}
|
|
347
|
+
* @param {ID_STRING} - old key
|
|
348
|
+
* @param {ID_STRING} - new key
|
|
349
|
+
* @returns {bool}
|
|
350
|
+
* @throws {TypeError}
|
|
351
|
+
* @description Renames an element addressed by its key.
|
|
352
|
+
*/
|
|
302
353
|
function renameXObjElement(obj, name, newName){
|
|
303
354
|
let err = null;
|
|
304
355
|
if (!isPlainObject(obj)) {
|
|
@@ -332,6 +383,15 @@ function renameXObjElement(obj, name, newName){
|
|
|
332
383
|
return result;
|
|
333
384
|
};
|
|
334
385
|
|
|
386
|
+
/**
|
|
387
|
+
* @function checkXObjAttribute
|
|
388
|
+
* @param {object}
|
|
389
|
+
* @param {ID_STRING}
|
|
390
|
+
* @param {ID_STRING} [key]
|
|
391
|
+
* @returns {bool}
|
|
392
|
+
* @throws {TypeError}
|
|
393
|
+
* @description Checks wheter an attribute is exists.
|
|
394
|
+
*/
|
|
335
395
|
function checkXObjAttribute(obj, attr = '', key){
|
|
336
396
|
if (typeof attr !== 'string') {
|
|
337
397
|
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
@@ -356,6 +416,15 @@ function checkXObjAttribute(obj, attr = '', key){
|
|
|
356
416
|
return result;
|
|
357
417
|
};
|
|
358
418
|
|
|
419
|
+
/**
|
|
420
|
+
* @function deleteXObjAttribute
|
|
421
|
+
* @param {object}
|
|
422
|
+
* @param {ID_STRING}
|
|
423
|
+
* @param {ID_STRING} [key]
|
|
424
|
+
* @returns {bool}
|
|
425
|
+
* @throws {TypeError}
|
|
426
|
+
* @description Deletes an attribute addressed by a given key.
|
|
427
|
+
*/
|
|
359
428
|
function deleteXObjAttribute(obj, attr = '', key){
|
|
360
429
|
if (typeof attr !== 'string') {
|
|
361
430
|
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
@@ -377,6 +446,14 @@ function deleteXObjAttribute(obj, attr = '', key){
|
|
|
377
446
|
return result;
|
|
378
447
|
};
|
|
379
448
|
|
|
449
|
+
/**
|
|
450
|
+
* @function readXObjParamRaw
|
|
451
|
+
* @param {object}
|
|
452
|
+
* @param {ID_STRING} [key]
|
|
453
|
+
* @returns {any}
|
|
454
|
+
* @throws {TypeError}
|
|
455
|
+
* @description Extracts a parameter from a given object.
|
|
456
|
+
*/
|
|
380
457
|
function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME){
|
|
381
458
|
let err = null;
|
|
382
459
|
if (!isPlainObject(obj)) {
|
|
@@ -393,6 +470,15 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME){
|
|
|
393
470
|
return _key !== '' ? obj[_key] : undefined;
|
|
394
471
|
};
|
|
395
472
|
|
|
473
|
+
/**
|
|
474
|
+
* @function writeXObjParamRaw
|
|
475
|
+
* @param {object}
|
|
476
|
+
* @param {any}
|
|
477
|
+
* @param {ID_STRING} [key]
|
|
478
|
+
* @returns {bool}
|
|
479
|
+
* @throws {TypeError}
|
|
480
|
+
* @description Writes a parameter into a given object.
|
|
481
|
+
*/
|
|
396
482
|
function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME){
|
|
397
483
|
let err = null;
|
|
398
484
|
if (!isPlainObject(obj)) {
|
|
@@ -414,6 +500,15 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME){
|
|
|
414
500
|
return isSUCCEED;
|
|
415
501
|
};
|
|
416
502
|
|
|
503
|
+
/**
|
|
504
|
+
* @function readXObjAttrRaw
|
|
505
|
+
* @param {object}
|
|
506
|
+
* @param {ID_STRING}
|
|
507
|
+
* @param {ID_STRING} [key]
|
|
508
|
+
* @returns {any}
|
|
509
|
+
* @throws {TypeError}
|
|
510
|
+
* @description Extracts an attribute from a given object.
|
|
511
|
+
*/
|
|
417
512
|
function readXObjAttrRaw(obj, attr = '', key){
|
|
418
513
|
if (typeof attr !== 'string') {
|
|
419
514
|
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
@@ -430,6 +525,16 @@ function readXObjAttrRaw(obj, attr = '', key){
|
|
|
430
525
|
if (objAttr !== null && attrName !== '') return objAttr[attrName];
|
|
431
526
|
};
|
|
432
527
|
|
|
528
|
+
/**
|
|
529
|
+
* @function writeXObjAttrRaw
|
|
530
|
+
* @param {object}
|
|
531
|
+
* @param {ID_STRING}
|
|
532
|
+
* @param {any}
|
|
533
|
+
* @param {ID_STRING} [key]
|
|
534
|
+
* @returns {bool}
|
|
535
|
+
* @throws {TypeError}
|
|
536
|
+
* @description Writes a parameter into a given object.
|
|
537
|
+
*/
|
|
433
538
|
function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME){
|
|
434
539
|
if (typeof attr !== 'string') {
|
|
435
540
|
let err = new TypeError(XOBJ_TE_NSTR_EMSG);
|
|
@@ -462,6 +567,14 @@ function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME){
|
|
|
462
567
|
return isSUCCEED;
|
|
463
568
|
};
|
|
464
569
|
|
|
570
|
+
/**
|
|
571
|
+
* @function readXObjParam
|
|
572
|
+
* @param {object}
|
|
573
|
+
* @param {ID_STRING} [key]
|
|
574
|
+
* @returns {string}
|
|
575
|
+
* @throws {TypeError}
|
|
576
|
+
* @description Extracts a parameter from a given object.
|
|
577
|
+
*/
|
|
465
578
|
function readXObjParam(obj, key){
|
|
466
579
|
let result = undefined;
|
|
467
580
|
try {
|
|
@@ -484,6 +597,15 @@ function readXObjParam(obj, key){
|
|
|
484
597
|
});
|
|
485
598
|
};
|
|
486
599
|
|
|
600
|
+
/**
|
|
601
|
+
* @function readXObjParam
|
|
602
|
+
* @param {object}
|
|
603
|
+
* @param {bool}
|
|
604
|
+
* @param {ID_STRING} [key]
|
|
605
|
+
* @returns {bool}
|
|
606
|
+
* @throws {TypeError}
|
|
607
|
+
* @description Extracts a parameter from a given object.
|
|
608
|
+
*/
|
|
487
609
|
function readXObjParamAsBool(obj, defValue, key){
|
|
488
610
|
let result = undefined;
|
|
489
611
|
try {
|
|
@@ -502,6 +624,15 @@ function readXObjParamAsBool(obj, defValue, key){
|
|
|
502
624
|
return readAsBoolEx(result, defValue);
|
|
503
625
|
};
|
|
504
626
|
|
|
627
|
+
/**
|
|
628
|
+
* @function readXObjParam
|
|
629
|
+
* @param {object}
|
|
630
|
+
* @param {number}
|
|
631
|
+
* @param {ID_STRING} [key]
|
|
632
|
+
* @returns {number}
|
|
633
|
+
* @throws {TypeError}
|
|
634
|
+
* @description Extracts a parameter from a given object.
|
|
635
|
+
*/
|
|
505
636
|
function readXObjParamAsNum(obj, defValue, key){
|
|
506
637
|
let result = undefined;
|
|
507
638
|
try {
|
|
@@ -520,6 +651,15 @@ function readXObjParamAsNum(obj, defValue, key){
|
|
|
520
651
|
return readAsNumberEx(result, defValue);
|
|
521
652
|
};
|
|
522
653
|
|
|
654
|
+
/**
|
|
655
|
+
* @function readXObjParam
|
|
656
|
+
* @param {object}
|
|
657
|
+
* @param {string}
|
|
658
|
+
* @param {ID_STRING} [key]
|
|
659
|
+
* @returns {string}
|
|
660
|
+
* @throws {TypeError}
|
|
661
|
+
* @description Extracts a parameter from a given object.
|
|
662
|
+
*/
|
|
523
663
|
function readXObjParamAsStr(obj, defValue, key){
|
|
524
664
|
let result = undefined;
|
|
525
665
|
try {
|
|
@@ -535,13 +675,22 @@ function readXObjParamAsStr(obj, defValue, key){
|
|
|
535
675
|
}
|
|
536
676
|
};
|
|
537
677
|
};
|
|
538
|
-
return readAsString(result,
|
|
678
|
+
return readAsString(result, {
|
|
539
679
|
useTrim: false,
|
|
540
680
|
numberToString: true,
|
|
541
681
|
boolToString: true,
|
|
682
|
+
defValue,
|
|
542
683
|
});
|
|
543
684
|
};
|
|
544
685
|
|
|
686
|
+
/**
|
|
687
|
+
* @function readXObjParam
|
|
688
|
+
* @param {object}
|
|
689
|
+
* @param {ID_STRING} [key]
|
|
690
|
+
* @returns {index}
|
|
691
|
+
* @throws {TypeError}
|
|
692
|
+
* @description Extracts a parameter from a given object.
|
|
693
|
+
*/
|
|
545
694
|
function readXObjParamAsIndex(obj, key){
|
|
546
695
|
let result = undefined;
|
|
547
696
|
try {
|
|
@@ -560,6 +709,15 @@ function readXObjParamAsIndex(obj, key){
|
|
|
560
709
|
return valueToIndex(result);
|
|
561
710
|
};
|
|
562
711
|
|
|
712
|
+
/**
|
|
713
|
+
* @function writeXObjParam
|
|
714
|
+
* @param {object}
|
|
715
|
+
* @param {any}
|
|
716
|
+
* @param {ID_STRING} [key]
|
|
717
|
+
* @returns {bool}
|
|
718
|
+
* @throws {TypeError}
|
|
719
|
+
* @description Writes a parameter into a given object.
|
|
720
|
+
*/
|
|
563
721
|
function writeXObjParam(obj, value, key){
|
|
564
722
|
let isSUCCEED = false;
|
|
565
723
|
if (value !== undefined) {
|
|
@@ -585,6 +743,16 @@ function writeXObjParam(obj, value, key){
|
|
|
585
743
|
return isSUCCEED;
|
|
586
744
|
};
|
|
587
745
|
|
|
746
|
+
/**
|
|
747
|
+
* @function writeXObjParamAsBool
|
|
748
|
+
* @param {object}
|
|
749
|
+
* @param {any}
|
|
750
|
+
* @param {bool}
|
|
751
|
+
* @param {ID_STRING} [key]
|
|
752
|
+
* @returns {bool}
|
|
753
|
+
* @throws {TypeError}
|
|
754
|
+
* @description Writes a parameter into a given object.
|
|
755
|
+
*/
|
|
588
756
|
function writeXObjParamAsBool(obj, value, defValue, key){
|
|
589
757
|
let isSUCCEED = false;
|
|
590
758
|
if (value !== undefined) {
|
|
@@ -606,6 +774,16 @@ function writeXObjParamAsBool(obj, value, defValue, key){
|
|
|
606
774
|
return isSUCCEED;
|
|
607
775
|
};
|
|
608
776
|
|
|
777
|
+
/**
|
|
778
|
+
* @function writeXObjParamAsNum
|
|
779
|
+
* @param {object}
|
|
780
|
+
* @param {any}
|
|
781
|
+
* @param {number}
|
|
782
|
+
* @param {ID_STRING} [key]
|
|
783
|
+
* @returns {bool}
|
|
784
|
+
* @throws {TypeError}
|
|
785
|
+
* @description Writes a parameter into a given object.
|
|
786
|
+
*/
|
|
609
787
|
function writeXObjParamAsNum(obj, value, defValue, key){
|
|
610
788
|
let isSUCCEED = false;
|
|
611
789
|
if (value !== undefined) {
|
|
@@ -627,6 +805,15 @@ function writeXObjParamAsNum(obj, value, defValue, key){
|
|
|
627
805
|
return isSUCCEED;
|
|
628
806
|
};
|
|
629
807
|
|
|
808
|
+
/**
|
|
809
|
+
* @function writeXObjParamAsIndex
|
|
810
|
+
* @param {object}
|
|
811
|
+
* @param {any}
|
|
812
|
+
* @param {ID_STRING} [key]
|
|
813
|
+
* @returns {bool}
|
|
814
|
+
* @throws {TypeError}
|
|
815
|
+
* @description Writes a parameter into a given object.
|
|
816
|
+
*/
|
|
630
817
|
function writeXObjParamAsIndex(obj, value, key){
|
|
631
818
|
let isSUCCEED = false;
|
|
632
819
|
if (value !== undefined) {
|
|
@@ -648,6 +835,16 @@ function writeXObjParamAsIndex(obj, value, key){
|
|
|
648
835
|
return isSUCCEED;
|
|
649
836
|
};
|
|
650
837
|
|
|
838
|
+
/**
|
|
839
|
+
* @function writeXObjParamEx
|
|
840
|
+
* @param {object}
|
|
841
|
+
* @param {any}
|
|
842
|
+
* @param {any}
|
|
843
|
+
* @param {ID_STRING} [key]
|
|
844
|
+
* @returns {bool}
|
|
845
|
+
* @throws {TypeError}
|
|
846
|
+
* @description Writes a parameter into a given object.
|
|
847
|
+
*/
|
|
651
848
|
function writeXObjParamEx(obj, value, defValue, key){
|
|
652
849
|
let isSUCCEED = false;
|
|
653
850
|
if (value !== undefined) {
|
|
@@ -656,10 +853,11 @@ function writeXObjParamEx(obj, value, defValue, key){
|
|
|
656
853
|
numberToString: true,
|
|
657
854
|
boolToString: true,
|
|
658
855
|
});
|
|
659
|
-
const _value = readAsString(value,
|
|
856
|
+
const _value = readAsString(value, {
|
|
660
857
|
useTrim: false,
|
|
661
858
|
numberToString: true,
|
|
662
859
|
boolToString: true,
|
|
860
|
+
defValue: _defValue,
|
|
663
861
|
});
|
|
664
862
|
try {
|
|
665
863
|
isSUCCEED = writeXObjParamRaw(obj, _value, key);
|
|
@@ -678,6 +876,15 @@ function writeXObjParamEx(obj, value, defValue, key){
|
|
|
678
876
|
return isSUCCEED;
|
|
679
877
|
};
|
|
680
878
|
|
|
879
|
+
/**
|
|
880
|
+
* @function readXObjAttr
|
|
881
|
+
* @param {object}
|
|
882
|
+
* @param {ID_STRING}
|
|
883
|
+
* @param {ID_STRING} [key]
|
|
884
|
+
* @returns {string}
|
|
885
|
+
* @throws {TypeError}
|
|
886
|
+
* @description Extracts an attribute from a given object.
|
|
887
|
+
*/
|
|
681
888
|
function readXObjAttr(obj, attr, key){
|
|
682
889
|
let result = undefined;
|
|
683
890
|
try {
|
|
@@ -700,6 +907,16 @@ function readXObjAttr(obj, attr, key){
|
|
|
700
907
|
});
|
|
701
908
|
};
|
|
702
909
|
|
|
910
|
+
/**
|
|
911
|
+
* @function readXObjAttrAsBool
|
|
912
|
+
* @param {object}
|
|
913
|
+
* @param {ID_STRING}
|
|
914
|
+
* @param {bool}
|
|
915
|
+
* @param {ID_STRING} [key]
|
|
916
|
+
* @returns {bool}
|
|
917
|
+
* @throws {TypeError}
|
|
918
|
+
* @description Extracts an attribute from a given object.
|
|
919
|
+
*/
|
|
703
920
|
function readXObjAttrAsBool(obj, attr, defValue, key){
|
|
704
921
|
let result = undefined;
|
|
705
922
|
try {
|
|
@@ -718,6 +935,16 @@ function readXObjAttrAsBool(obj, attr, defValue, key){
|
|
|
718
935
|
return readAsBoolEx(result, defValue);
|
|
719
936
|
};
|
|
720
937
|
|
|
938
|
+
/**
|
|
939
|
+
* @function readXObjAttrAsNum
|
|
940
|
+
* @param {object}
|
|
941
|
+
* @param {ID_STRING}
|
|
942
|
+
* @param {number}
|
|
943
|
+
* @param {ID_STRING} [key]
|
|
944
|
+
* @returns {number}
|
|
945
|
+
* @throws {TypeError}
|
|
946
|
+
* @description Extracts an attribute from a given object.
|
|
947
|
+
*/
|
|
721
948
|
function readXObjAttrAsNum(obj, attr, defValue, key){
|
|
722
949
|
let result = undefined;
|
|
723
950
|
try {
|
|
@@ -736,6 +963,16 @@ function readXObjAttrAsNum(obj, attr, defValue, key){
|
|
|
736
963
|
return readAsNumberEx(result, defValue);
|
|
737
964
|
};
|
|
738
965
|
|
|
966
|
+
/**
|
|
967
|
+
* @function readXObjAttrAsStr
|
|
968
|
+
* @param {object}
|
|
969
|
+
* @param {ID_STRING}
|
|
970
|
+
* @param {string}
|
|
971
|
+
* @param {ID_STRING} [key]
|
|
972
|
+
* @returns {string}
|
|
973
|
+
* @throws {TypeError}
|
|
974
|
+
* @description Extracts an attribute from a given object.
|
|
975
|
+
*/
|
|
739
976
|
function readXObjAttrAsStr(obj, attr, defValue, key){
|
|
740
977
|
let result = undefined;
|
|
741
978
|
try {
|
|
@@ -751,13 +988,23 @@ function readXObjAttrAsStr(obj, attr, defValue, key){
|
|
|
751
988
|
}
|
|
752
989
|
};
|
|
753
990
|
};
|
|
754
|
-
return readAsString(result,
|
|
991
|
+
return readAsString(result, {
|
|
755
992
|
useTrim: true,
|
|
756
993
|
numberToString: true,
|
|
757
994
|
boolToString: true,
|
|
995
|
+
defValue,
|
|
758
996
|
});
|
|
759
997
|
};
|
|
760
998
|
|
|
999
|
+
/**
|
|
1000
|
+
* @function readXObjAttrAsIndex
|
|
1001
|
+
* @param {object}
|
|
1002
|
+
* @param {ID_STRING}
|
|
1003
|
+
* @param {ID_STRING} [key]
|
|
1004
|
+
* @returns {index}
|
|
1005
|
+
* @throws {TypeError}
|
|
1006
|
+
* @description Extracts an attribute from a given object.
|
|
1007
|
+
*/
|
|
761
1008
|
function readXObjAttrAsIndex(obj, attr, key){
|
|
762
1009
|
let result = undefined;
|
|
763
1010
|
try {
|
|
@@ -776,6 +1023,16 @@ function readXObjAttrAsIndex(obj, attr, key){
|
|
|
776
1023
|
return valueToIndex(result);
|
|
777
1024
|
};
|
|
778
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* @function writeXObjAttr
|
|
1028
|
+
* @param {object}
|
|
1029
|
+
* @param {ID_STRING}
|
|
1030
|
+
* @param {any}
|
|
1031
|
+
* @param {ID_STRING} [key]
|
|
1032
|
+
* @returns {bool}
|
|
1033
|
+
* @throws {TypeError}
|
|
1034
|
+
* @description Writes a parameter into a given object.
|
|
1035
|
+
*/
|
|
779
1036
|
function writeXObjAttr(obj, attr, value, key){
|
|
780
1037
|
let isSUCCEED = false;
|
|
781
1038
|
if (value !== undefined) {
|
|
@@ -801,6 +1058,17 @@ function writeXObjAttr(obj, attr, value, key){
|
|
|
801
1058
|
return isSUCCEED;
|
|
802
1059
|
};
|
|
803
1060
|
|
|
1061
|
+
/**
|
|
1062
|
+
* @function writeXObjAttrAsBool
|
|
1063
|
+
* @param {object}
|
|
1064
|
+
* @param {ID_STRING}
|
|
1065
|
+
* @param {any}
|
|
1066
|
+
* @param {bool}
|
|
1067
|
+
* @param {ID_STRING} [key]
|
|
1068
|
+
* @returns {bool}
|
|
1069
|
+
* @throws {TypeError}
|
|
1070
|
+
* @description Writes a parameter into a given object.
|
|
1071
|
+
*/
|
|
804
1072
|
function writeXObjAttrAsBool(obj, attr, value, defValue, key){
|
|
805
1073
|
let isSUCCEED = false;
|
|
806
1074
|
if (value !== undefined) {
|
|
@@ -822,6 +1090,17 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key){
|
|
|
822
1090
|
return isSUCCEED;
|
|
823
1091
|
};
|
|
824
1092
|
|
|
1093
|
+
/**
|
|
1094
|
+
* @function writeXObjAttrAsNum
|
|
1095
|
+
* @param {object}
|
|
1096
|
+
* @param {ID_STRING}
|
|
1097
|
+
* @param {any}
|
|
1098
|
+
* @param {number}
|
|
1099
|
+
* @param {ID_STRING} [key]
|
|
1100
|
+
* @returns {bool}
|
|
1101
|
+
* @throws {TypeError}
|
|
1102
|
+
* @description Writes a parameter into a given object.
|
|
1103
|
+
*/
|
|
825
1104
|
function writeXObjAttrAsNum(obj, attr, value, defValue, key){
|
|
826
1105
|
let isSUCCEED = false;
|
|
827
1106
|
if (value !== undefined) {
|
|
@@ -843,6 +1122,16 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key){
|
|
|
843
1122
|
return isSUCCEED;
|
|
844
1123
|
};
|
|
845
1124
|
|
|
1125
|
+
/**
|
|
1126
|
+
* @function writeXObjAttrAsIndex
|
|
1127
|
+
* @param {object}
|
|
1128
|
+
* @param {ID_STRING}
|
|
1129
|
+
* @param {any}
|
|
1130
|
+
* @param {ID_STRING} [key]
|
|
1131
|
+
* @returns {bool}
|
|
1132
|
+
* @throws {TypeError}
|
|
1133
|
+
* @description Writes a parameter into a given object.
|
|
1134
|
+
*/
|
|
846
1135
|
function writeXObjAttrAsIndex(obj, attr, value, key){
|
|
847
1136
|
let isSUCCEED = false;
|
|
848
1137
|
if (value !== undefined) {
|
|
@@ -864,6 +1153,17 @@ function writeXObjAttrAsIndex(obj, attr, value, key){
|
|
|
864
1153
|
return isSUCCEED;
|
|
865
1154
|
};
|
|
866
1155
|
|
|
1156
|
+
/**
|
|
1157
|
+
* @function writeXObjAttrEx
|
|
1158
|
+
* @param {object}
|
|
1159
|
+
* @param {ID_STRING}
|
|
1160
|
+
* @param {any}
|
|
1161
|
+
* @param {any}
|
|
1162
|
+
* @param {ID_STRING} [key]
|
|
1163
|
+
* @returns {bool}
|
|
1164
|
+
* @throws {TypeError}
|
|
1165
|
+
* @description Writes a parameter into a given object.
|
|
1166
|
+
*/
|
|
867
1167
|
function writeXObjAttrEx(obj, attr, value, defValue, key){
|
|
868
1168
|
let isSUCCEED = false;
|
|
869
1169
|
if (value !== undefined) {
|
|
@@ -872,10 +1172,11 @@ function writeXObjAttrEx(obj, attr, value, defValue, key){
|
|
|
872
1172
|
numberToString: true,
|
|
873
1173
|
boolToString: true,
|
|
874
1174
|
});
|
|
875
|
-
const _value = readAsString(value,
|
|
1175
|
+
const _value = readAsString(value, {
|
|
876
1176
|
useTrim: true,
|
|
877
1177
|
numberToString: true,
|
|
878
1178
|
boolToString: true,
|
|
1179
|
+
defValue: _defValue,
|
|
879
1180
|
});
|
|
880
1181
|
try {
|
|
881
1182
|
isSUCCEED = writeXObjAttrRaw(obj, attr, _value, key);
|
|
@@ -894,6 +1195,15 @@ function writeXObjAttrEx(obj, attr, value, defValue, key){
|
|
|
894
1195
|
return isSUCCEED;
|
|
895
1196
|
};
|
|
896
1197
|
|
|
1198
|
+
/**
|
|
1199
|
+
* @function insertXObjElements
|
|
1200
|
+
* @param {object}
|
|
1201
|
+
* @param {...ID_STRING} args - list of a keys
|
|
1202
|
+
* @param {object} [opt]
|
|
1203
|
+
* @returns {number}
|
|
1204
|
+
* @throws {TypeError}
|
|
1205
|
+
* @description Inserts an elements into a given object.
|
|
1206
|
+
*/
|
|
897
1207
|
function insertXObjElements(obj, ...args){
|
|
898
1208
|
if (!isPlainObject(obj)) {
|
|
899
1209
|
let err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
@@ -914,6 +1224,17 @@ function insertXObjElements(obj, ...args){
|
|
|
914
1224
|
return count;
|
|
915
1225
|
};
|
|
916
1226
|
|
|
1227
|
+
/**
|
|
1228
|
+
* @function insertXObjEList
|
|
1229
|
+
* @param {object}
|
|
1230
|
+
* @param {ID_STRING}
|
|
1231
|
+
* @param {object} [opt]
|
|
1232
|
+
* @param {bool} [opt.force=false]
|
|
1233
|
+
* @param {bool} [opt.ripOldies=false]
|
|
1234
|
+
* @returns {?any}
|
|
1235
|
+
* @throws {TypeError}
|
|
1236
|
+
* @description Inserts a list elements into a given object.
|
|
1237
|
+
*/
|
|
917
1238
|
function insertXObjEList(obj, name, opt){
|
|
918
1239
|
let err = null;
|
|
919
1240
|
if (!isPlainObject(obj)) {
|
|
@@ -953,6 +1274,16 @@ function insertXObjEList(obj, name, opt){
|
|
|
953
1274
|
return isACCEPTED ? item : null;
|
|
954
1275
|
};
|
|
955
1276
|
|
|
1277
|
+
/**
|
|
1278
|
+
* @function insertXObjEChain
|
|
1279
|
+
* @param {object}
|
|
1280
|
+
* @param {ID_STRING}
|
|
1281
|
+
* @param {...ID_STRING} args - a list of keys
|
|
1282
|
+
* @param {object} [opt]
|
|
1283
|
+
* @returns {?any}
|
|
1284
|
+
* @throws {TypeError}
|
|
1285
|
+
* @description Inserts a chain of an elements into a given object.
|
|
1286
|
+
*/
|
|
956
1287
|
function insertXObjEChain(obj, ...args){
|
|
957
1288
|
if (!isPlainObject(obj)) {
|
|
958
1289
|
let err = new TypeError(XOBJ_TE_NPOBJ_EMSG);
|
|
@@ -977,106 +1308,14 @@ function insertXObjEChain(obj, ...args){
|
|
|
977
1308
|
return isSUCCEED ? curObj : null;
|
|
978
1309
|
};
|
|
979
1310
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
#_options = null;
|
|
984
|
-
|
|
985
|
-
constructor(param){
|
|
986
|
-
this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
get settings(){ return this.#_options }
|
|
990
|
-
|
|
991
|
-
get xml2js(){
|
|
992
|
-
let _settings = this.#_options;
|
|
993
|
-
return {
|
|
994
|
-
compact: _settings.compact,
|
|
995
|
-
declarationKey: _settings.declarationKey,
|
|
996
|
-
attributesKey: _settings.attributesKey,
|
|
997
|
-
textKey: _settings.textKey,
|
|
998
|
-
commentKey: _settings.commentKey,
|
|
999
|
-
cdataKey: _settings.cdataKey,
|
|
1000
|
-
nameKey: _settings.nameKey,
|
|
1001
|
-
typeKey: _settings.typeKey,
|
|
1002
|
-
parentKey: _settings.parentKey,
|
|
1003
|
-
elementsKey: _settings.elementsKey,
|
|
1004
|
-
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
1005
|
-
ignoreDocType: _settings.ignoreDocType,
|
|
1006
|
-
ignoreInstraction: _settings.ignoreInstractions,
|
|
1007
|
-
ignoreText: _settings.ignoreText,
|
|
1008
|
-
ignoreComment: _settings.ignoreComments,
|
|
1009
|
-
ignoreCData: _settings.ignoreCData,
|
|
1010
|
-
addParent: _settings.addParent,
|
|
1011
|
-
trim: _settings.trim,
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
get js2xml(){
|
|
1016
|
-
let _settings = this.#_options;
|
|
1017
|
-
return {
|
|
1018
|
-
compact: _settings.compact,
|
|
1019
|
-
declarationKey: _settings.declarationKey,
|
|
1020
|
-
attributesKey: _settings.attributesKey,
|
|
1021
|
-
textKey: _settings.textKey,
|
|
1022
|
-
commentKey: _settings.commentKey,
|
|
1023
|
-
cdataKey: _settings.cdataKey,
|
|
1024
|
-
nameKey: _settings.nameKey,
|
|
1025
|
-
typeKey: _settings.typeKey,
|
|
1026
|
-
parentKey: _settings.parentKey,
|
|
1027
|
-
elementsKey: _settings.elementsKey,
|
|
1028
|
-
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
1029
|
-
ignoreDocType: _settings.ignoreDocType,
|
|
1030
|
-
ignoreInstraction: _settings.ignoreInstractions,
|
|
1031
|
-
ignoreText: _settings.ignoreText,
|
|
1032
|
-
ignoreComment: _settings.ignoreComments,
|
|
1033
|
-
ignoreCData: _settings.ignoreCData,
|
|
1034
|
-
fullTagEmptyElement: _settings.fullTagEmptyElement,
|
|
1035
|
-
spaces: _settings.spaces,
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
static createNewOptionsSet(opt){
|
|
1040
|
-
if (opt instanceof TXmlContentParseOptions) {
|
|
1041
|
-
opt = opt.settings;
|
|
1042
|
-
} else if (isPlainObject(opt)) {
|
|
1043
|
-
opt = isPlainObject(opt.settings) ? opt.settings : opt;
|
|
1044
|
-
} else {
|
|
1045
|
-
opt = DEF_XML_PARSE_OPTIONS;
|
|
1046
|
-
};
|
|
1047
|
-
return {
|
|
1048
|
-
compact: opt.compact,
|
|
1049
|
-
declarationKey: opt.declarationKey,
|
|
1050
|
-
attributesKey: opt.attributesKey,
|
|
1051
|
-
textKey: opt.textKey,
|
|
1052
|
-
commentKey: opt.commentKey,
|
|
1053
|
-
cdataKey: opt.cdataKey,
|
|
1054
|
-
nameKey: opt.nameKey,
|
|
1055
|
-
typeKey: opt.typeKey,
|
|
1056
|
-
parentKey: opt.parentKey,
|
|
1057
|
-
elementsKey: opt.elementsKey,
|
|
1058
|
-
ignoreDeclaration: opt.ignoreDeclaration,
|
|
1059
|
-
ignoreDocType: opt.ignoreDocType,
|
|
1060
|
-
ignoreInstractions: opt.ignoreInstractions,
|
|
1061
|
-
ignoreText: opt.ignoreText,
|
|
1062
|
-
ignoreComments: opt.ignoreComments,
|
|
1063
|
-
ignoreCData: opt.ignoreCData,
|
|
1064
|
-
fullTagEmptyElement: opt.fullTagEmptyElement,
|
|
1065
|
-
addParent: opt.addParent,
|
|
1066
|
-
trim: opt.trim,
|
|
1067
|
-
spaces: opt.spaces,
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1311
|
+
/***
|
|
1312
|
+
* (* class definitions *)
|
|
1313
|
+
*/
|
|
1072
1314
|
|
|
1073
1315
|
// === module exports block ===
|
|
1074
1316
|
|
|
1075
1317
|
exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
1076
1318
|
exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
1077
|
-
exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
1078
|
-
|
|
1079
|
-
exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
|
1080
1319
|
|
|
1081
1320
|
exports.evalXObjEName = evalXObjEName;
|
|
1082
1321
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ygracs/xobj-lib-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A helper library to work with xml-js module",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"doc/xObj.md",
|
|
14
14
|
"lib/xObj-lib.js",
|
|
15
|
+
"lib/xObj-defs.js",
|
|
15
16
|
"index.js",
|
|
16
17
|
"CHANGELOG.md"
|
|
17
18
|
],
|
|
@@ -21,16 +22,20 @@
|
|
|
21
22
|
"test-xobj:c1": "jest xObj-lib.1",
|
|
22
23
|
"test-xobj:c2": "jest xObj-lib.2",
|
|
23
24
|
"test-xobj:c3": "jest xObj-lib.3",
|
|
24
|
-
"test-xobj:c4": "jest xObj-lib.4"
|
|
25
|
+
"test-xobj:c4": "jest xObj-lib.4",
|
|
26
|
+
"build-doc-md": "jsdoc2md",
|
|
27
|
+
"build-doc-html": "jsdoc"
|
|
25
28
|
},
|
|
26
29
|
"imports": {
|
|
27
|
-
"#lib/*": "./lib/*"
|
|
30
|
+
"#lib/*": "./lib/*",
|
|
31
|
+
"#test-dir/*": "./__test__/*"
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@ygracs/bsfoc-lib-js": "^0.1
|
|
34
|
+
"@ygracs/bsfoc-lib-js": "^0.2.1"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
33
|
-
"jest": "^29.
|
|
37
|
+
"jest": "^29.7.0",
|
|
38
|
+
"jsdoc-to-markdown": "^8.0.1",
|
|
34
39
|
"minimist": "^1.2.8"
|
|
35
40
|
}
|
|
36
41
|
}
|