@ygracs/xobj-lib-js 0.2.1 → 0.2.3
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/doc/xObj.md +38 -29
- package/lib/xObj-defs.js +80 -11
- package/lib/xObj-lib.js +89 -99
- package/package.json +3 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
#### *v0.2.3*
|
|
2
|
+
|
|
3
|
+
Release version.
|
|
4
|
+
|
|
5
|
+
> - update `xObj.md`;
|
|
6
|
+
> - add a new `reservedKeys` property to a `TXmlContentParseOptions` class;
|
|
7
|
+
> - remove `readXObjParamAsStr` function;
|
|
8
|
+
> - remove `readXObjAttrAsStr` function;
|
|
9
|
+
> - other fixes.
|
|
10
|
+
|
|
11
|
+
#### *v0.2.2*
|
|
12
|
+
|
|
13
|
+
Release version.
|
|
14
|
+
|
|
15
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.3;
|
|
16
|
+
> - other fixes.
|
|
17
|
+
|
|
1
18
|
#### *v0.2.1*
|
|
2
19
|
|
|
3
20
|
Release version.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.45|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2025-
|
|
3
|
+
>|date:|2025-07-19|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -158,14 +158,6 @@ The function throws a `TypeError` exception in case:
|
|
|
158
158
|
- code: `ERR_XOBJ_NPOBJ`
|
|
159
159
|
+ if `object` parameter is not an `Object` instance.
|
|
160
160
|
|
|
161
|
-
#### **readXObjParamAsStr(object\[, defValue \[, key])** => `string`
|
|
162
|
-
|
|
163
|
-
> WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjParam`](#readxobjparamobject-key--string) or [`readXObjParamEx`](#readxobjparamexobject-opt-key--string) instead.*
|
|
164
|
-
|
|
165
|
-
This function reads a value of an object parameter and returns it as a `string`.
|
|
166
|
-
|
|
167
|
-
The `defValue` must be of a `string` type, if else the empty string is used.
|
|
168
|
-
|
|
169
161
|
<a name="readXObjParamEx"></a>
|
|
170
162
|
#### **readXObjParamEx(object\[, options \[, key])** => `string`
|
|
171
163
|
|
|
@@ -419,14 +411,6 @@ The function throws a `TypeError` exception in case:
|
|
|
419
411
|
- code: `ERR_XOBJ_NPOBJ`
|
|
420
412
|
+ if `object` parameter is not an `Object` instance.
|
|
421
413
|
|
|
422
|
-
#### **readXObjAttrAsStr(object, attr\[, defValue\[, key]])** => `string`
|
|
423
|
-
|
|
424
|
-
> WARNING: `[since: v0.2.0]` ***this function deprecated.** Use [`readXObjAttr`](#readxobjattrobject-attr-key--string) or [`readXObjAttrEx`](#readxobjattrexobject-attr-opt-key--string) instead.*
|
|
425
|
-
|
|
426
|
-
This function returns a value of an object attribute. The value is of a `string` type.
|
|
427
|
-
|
|
428
|
-
The `defValue` must be of a `string` type, if else the empty string is used.
|
|
429
|
-
|
|
430
414
|
<a name="readXObjAttrEx"></a>
|
|
431
415
|
#### **readXObjAttrEx(object, attr\[, options\[, key]])** => `string`
|
|
432
416
|
|
|
@@ -1161,31 +1145,56 @@ The function throws a `TypeError` exception in case:
|
|
|
1161
1145
|
|
|
1162
1146
|
### Base class
|
|
1163
1147
|
|
|
1148
|
+
<a name="TXmlContentParseOptions"></a>
|
|
1164
1149
|
#### **TXmlContentParseOptions**
|
|
1165
1150
|
|
|
1166
1151
|
This class implements an interface for handling XML-parse options.
|
|
1167
1152
|
|
|
1168
1153
|
##### class constructor
|
|
1169
1154
|
|
|
1170
|
-
The class constructor creates a new instance of the class.
|
|
1155
|
+
The class constructor creates a new instance of the class.
|
|
1171
1156
|
|
|
1172
|
-
|
|
1157
|
+
###### constructor parameters
|
|
1158
|
+
|
|
1159
|
+
The class constructor receives an arguments listed below:
|
|
1160
|
+
|
|
1161
|
+
| parameter name | value type | default value | description |
|
|
1173
1162
|
|:---|---|---:|:---|
|
|
1174
|
-
|
|
1175
|
-
|`options`|`object`|---|an options settings.|
|
|
1163
|
+
| `options` | `object` | --- | an options settings |
|
|
1176
1164
|
|
|
1177
1165
|
##### class properties
|
|
1178
1166
|
|
|
1179
|
-
|
|
1167
|
+
<a name="TXmlContentParseOptions+settings"></a>
|
|
1168
|
+
###### **settings**
|
|
1180
1169
|
|
|
1181
|
-
|
|
|
1182
|
-
|
|
1183
|
-
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1170
|
+
| property type | read only | description |
|
|
1171
|
+
|---|---|:---|
|
|
1172
|
+
| `object` | yes | contains a current options |
|
|
1173
|
+
|
|
1174
|
+
<a name="TXmlContentParseOptions+xml2js"></a>
|
|
1175
|
+
###### **xml2js**
|
|
1176
|
+
|
|
1177
|
+
| property type | read only | description |
|
|
1178
|
+
|---|---|:---|
|
|
1179
|
+
| `object` | yes | returns an options for an XML-to-JS converter |
|
|
1180
|
+
|
|
1181
|
+
<a name="TXmlContentParseOptions+js2xml"></a>
|
|
1182
|
+
###### **js2xml**
|
|
1183
|
+
|
|
1184
|
+
| property type | read only | description |
|
|
1185
|
+
|---|---|:---|
|
|
1186
|
+
| `object` | yes | returns an options for a JS-to-XML converter |
|
|
1187
|
+
|
|
1188
|
+
<a name="TXmlContentParseOptions+reservedKeys"></a>
|
|
1189
|
+
###### **reservedKeys**
|
|
1190
|
+
|
|
1191
|
+
| property type | read only | description |
|
|
1192
|
+
|---|---|:---|
|
|
1193
|
+
| `Set<string>` | yes | returns a set of the reserved key words those must not be used as an element names |
|
|
1186
1194
|
|
|
1187
1195
|
##### class methods (*static*)
|
|
1188
1196
|
|
|
1189
|
-
|
|
1197
|
+
<a name="TXmlContentParseOptions.createNewOptionsSet"></a>
|
|
1198
|
+
###### **createNewOptionsSet(obj)** => `object`
|
|
1190
1199
|
|
|
1191
1200
|
This method transforms a given object to a set of accepted parser options.
|
package/lib/xObj-defs.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.064-20250718]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
|
|
7
|
-
//readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
|
-
//isNullOrUndef,
|
|
9
|
-
//isArray, isObject,
|
|
10
|
-
isPlainObject, //readAsListS,
|
|
6
|
+
isPlainObject,
|
|
11
7
|
} = require('@ygracs/bsfoc-lib-js');
|
|
12
8
|
|
|
13
9
|
// === module extra block (helper functions) ===
|
|
@@ -35,6 +31,21 @@ const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
|
|
|
35
31
|
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
36
32
|
const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
|
|
37
33
|
|
|
34
|
+
const XOBJ_ECODE_TABLE = {
|
|
35
|
+
XOBJ_TE_NOBJ_EMSG,
|
|
36
|
+
XOBJ_TE_NOBJ_ECODE,
|
|
37
|
+
XOBJ_TE_NARR_EMSG,
|
|
38
|
+
XOBJ_TE_NARR_ECODE,
|
|
39
|
+
XOBJ_TE_NSTR_EMSG,
|
|
40
|
+
XOBJ_TE_NSTR_ECODE,
|
|
41
|
+
XOBJ_TE_NPOBJ_EMSG,
|
|
42
|
+
XOBJ_TE_NPOBJ_ECODE,
|
|
43
|
+
XOBJ_TE_ANES_EMSG,
|
|
44
|
+
XOBJ_TE_ANES_ECODE,
|
|
45
|
+
XOBJ_TE_KNES_EMSG,
|
|
46
|
+
XOBJ_TE_KNES_ECODE,
|
|
47
|
+
};
|
|
48
|
+
|
|
38
49
|
const DEF_XML_PARSE_OPTIONS = {
|
|
39
50
|
compact: true,
|
|
40
51
|
declarationKey: '__decl',
|
|
@@ -66,16 +77,35 @@ const DEF_XML_PARSE_OPTIONS = {
|
|
|
66
77
|
* (* class definitions *)
|
|
67
78
|
*/
|
|
68
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @classdesc Implements a container that provide a functionality to work
|
|
82
|
+
* with options for an XML-parser
|
|
83
|
+
*/
|
|
69
84
|
class TXmlContentParseOptions {
|
|
85
|
+
/** @type {object} */
|
|
70
86
|
#_options = null;
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Creates a container instance
|
|
90
|
+
* @param {any} [param] - some initial options set
|
|
91
|
+
*/
|
|
92
|
+
constructor(param) {
|
|
73
93
|
this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
|
|
74
94
|
}
|
|
75
95
|
|
|
76
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Contains a set of a current settings
|
|
98
|
+
* @type {object}
|
|
99
|
+
*/
|
|
100
|
+
get settings() {
|
|
101
|
+
return this.#_options;
|
|
102
|
+
}
|
|
77
103
|
|
|
78
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
106
|
+
* @type {object}
|
|
107
|
+
*/
|
|
108
|
+
get xml2js() {
|
|
79
109
|
let _settings = this.#_options;
|
|
80
110
|
return {
|
|
81
111
|
compact: _settings.compact,
|
|
@@ -99,7 +129,11 @@ class TXmlContentParseOptions {
|
|
|
99
129
|
};
|
|
100
130
|
}
|
|
101
131
|
|
|
102
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Contains a set of a settings for converting an 'JS'-object to 'XML'
|
|
134
|
+
* @type {object}
|
|
135
|
+
*/
|
|
136
|
+
get js2xml() {
|
|
103
137
|
let _settings = this.#_options;
|
|
104
138
|
return {
|
|
105
139
|
compact: _settings.compact,
|
|
@@ -123,7 +157,41 @@ class TXmlContentParseOptions {
|
|
|
123
157
|
};
|
|
124
158
|
}
|
|
125
159
|
|
|
126
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Contains a set of a reserved key words
|
|
162
|
+
* @type {Set<string>}
|
|
163
|
+
*/
|
|
164
|
+
get reservedKeys() {
|
|
165
|
+
const {
|
|
166
|
+
declarationKey,
|
|
167
|
+
attributesKey,
|
|
168
|
+
textKey,
|
|
169
|
+
commentKey,
|
|
170
|
+
cdataKey,
|
|
171
|
+
nameKey,
|
|
172
|
+
typeKey,
|
|
173
|
+
parentKey,
|
|
174
|
+
elementsKey,
|
|
175
|
+
} = this.#_options;
|
|
176
|
+
return new Set([
|
|
177
|
+
declarationKey,
|
|
178
|
+
attributesKey,
|
|
179
|
+
textKey,
|
|
180
|
+
commentKey,
|
|
181
|
+
cdataKey,
|
|
182
|
+
nameKey,
|
|
183
|
+
typeKey,
|
|
184
|
+
parentKey,
|
|
185
|
+
elementsKey,
|
|
186
|
+
].filter((key) => typeof key === 'string'));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Creates a container instance
|
|
191
|
+
* @param {any} [opt] - some initial options set
|
|
192
|
+
* @static
|
|
193
|
+
*/
|
|
194
|
+
static createNewOptionsSet(opt) {
|
|
127
195
|
if (opt instanceof TXmlContentParseOptions) {
|
|
128
196
|
opt = opt.settings;
|
|
129
197
|
} else if (isPlainObject(opt)) {
|
|
@@ -161,6 +229,7 @@ class TXmlContentParseOptions {
|
|
|
161
229
|
|
|
162
230
|
module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
163
231
|
module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
232
|
+
module.exports.XOBJ_ECODE_TABLE = XOBJ_ECODE_TABLE;
|
|
164
233
|
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
165
234
|
|
|
166
235
|
module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,39 +1,47 @@
|
|
|
1
|
-
// [v0.2.
|
|
1
|
+
// [v0.2.105-20250719]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
|
-
valueToIndex, valueToIDString,
|
|
6
|
+
valueToIndex, //valueToIDString,
|
|
7
7
|
readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
8
|
isNullOrUndef,
|
|
9
9
|
isInteger,
|
|
10
10
|
isArray, isObject, isPlainObject,
|
|
11
|
-
readAsListS,
|
|
12
11
|
} = require('@ygracs/bsfoc-lib-js');
|
|
13
12
|
|
|
13
|
+
const {
|
|
14
|
+
XOBJ_TE_NSTR_EMSG,
|
|
15
|
+
XOBJ_TE_NSTR_ECODE,
|
|
16
|
+
XOBJ_TE_NPOBJ_EMSG,
|
|
17
|
+
XOBJ_TE_NPOBJ_ECODE,
|
|
18
|
+
XOBJ_TE_KNES_EMSG,
|
|
19
|
+
XOBJ_TE_KNES_ECODE,
|
|
20
|
+
} = require('#lib/xObj-defs.js').XOBJ_ECODE_TABLE;
|
|
21
|
+
|
|
14
22
|
// === module extra block (helper functions) ===
|
|
15
23
|
|
|
16
24
|
/**
|
|
25
|
+
* A result of a value check ops.
|
|
17
26
|
* @typedef {Object} RVAL_reason
|
|
18
27
|
* @property {string} code - message ID
|
|
19
28
|
* @property {string} msg - message text
|
|
20
|
-
* @description A result of a value check ops.
|
|
21
29
|
*/
|
|
22
30
|
|
|
23
31
|
/**
|
|
32
|
+
* A result of a value check ops.
|
|
24
33
|
* @typedef {Object} VCOR_evalkname
|
|
25
34
|
* @property {boolean} isSucceed - ops flag
|
|
26
35
|
* @property {(string|RVAL_reason)} value - result value or reson if failed
|
|
27
|
-
* @description A result of a value check ops.
|
|
28
36
|
*/
|
|
29
37
|
|
|
30
38
|
/**
|
|
39
|
+
* Tries to convert a value into an ID.
|
|
31
40
|
* @function evalKeyName
|
|
32
41
|
* @param {any} value - key to validate
|
|
33
42
|
* @param {boolean} [opt=true]
|
|
34
43
|
* @returns {VCOR_evalkname}
|
|
35
44
|
* @inner
|
|
36
|
-
* @description Tries to convert a value into an ID.
|
|
37
45
|
*/
|
|
38
46
|
function evalKeyName(value, opt = true) {
|
|
39
47
|
if (typeof value !== 'string') {
|
|
@@ -70,29 +78,15 @@ function evalKeyName(value, opt = true) {
|
|
|
70
78
|
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
71
79
|
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
72
80
|
|
|
73
|
-
const XOBJ_TE_INVARG_EMSG = 'invalid argument';
|
|
74
|
-
const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
|
|
75
|
-
const XOBJ_TE_NOBJ_ECODE = 'ERR_XOBJ_NOBJ';
|
|
76
|
-
const XOBJ_TE_NARR_EMSG = `${XOBJ_TE_INVARG_EMSG} (an array expected)`;
|
|
77
|
-
const XOBJ_TE_NARR_ECODE = 'ERR_XOBJ_NARR';
|
|
78
|
-
const XOBJ_TE_NSTR_EMSG = `${XOBJ_TE_INVARG_EMSG} (a string expected)`;
|
|
79
|
-
const XOBJ_TE_NSTR_ECODE = 'ERR_XOBJ_NSTR';
|
|
80
|
-
const XOBJ_TE_NPOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (a plain object expected)`;
|
|
81
|
-
const XOBJ_TE_NPOBJ_ECODE = 'ERR_XOBJ_NPOBJ';
|
|
82
|
-
const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
|
|
83
|
-
const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
|
|
84
|
-
const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
|
|
85
|
-
const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
|
|
86
|
-
|
|
87
81
|
/***
|
|
88
82
|
* (* function definitions *)
|
|
89
83
|
*/
|
|
90
84
|
|
|
91
85
|
/**
|
|
86
|
+
* Tries to convert a value into an ID.
|
|
92
87
|
* @function evalXObjEName
|
|
93
88
|
* @param {any} value - some value to evaluate
|
|
94
89
|
* @returns {(null|number|string)}
|
|
95
|
-
* @description Tries to convert a value into an ID.
|
|
96
90
|
*/
|
|
97
91
|
function evalXObjEName(value) {
|
|
98
92
|
//return valueToIDString(value); // // TODO: [?]
|
|
@@ -126,10 +120,10 @@ function evalXObjEName(value) {
|
|
|
126
120
|
};
|
|
127
121
|
|
|
128
122
|
/**
|
|
123
|
+
* Tries to convert a value into an element name description.
|
|
129
124
|
* @function genXObjENameDescr
|
|
130
125
|
* @param {any} value
|
|
131
126
|
* @returns {object}
|
|
132
|
-
* @description Tries to convert a value into an element name description.
|
|
133
127
|
*/
|
|
134
128
|
function genXObjENameDescr(value) {
|
|
135
129
|
let result = null;
|
|
@@ -183,13 +177,13 @@ function genXObjENameDescr(value) {
|
|
|
183
177
|
};
|
|
184
178
|
|
|
185
179
|
/**
|
|
180
|
+
* Extracts an element from a given object by its key.
|
|
186
181
|
* @function getXObjElement
|
|
187
182
|
* @param {object} obj - some object
|
|
188
183
|
* @param {string} name - some child element
|
|
189
184
|
* @returns {?any}
|
|
190
185
|
* @throws {TypeError} if first param is not an object
|
|
191
186
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
192
|
-
* @description Extracts an element from a given object by its key.
|
|
193
187
|
*/
|
|
194
188
|
function getXObjElement(obj, name) {
|
|
195
189
|
if (!isPlainObject(obj)) {
|
|
@@ -209,12 +203,12 @@ function getXObjElement(obj, name) {
|
|
|
209
203
|
};
|
|
210
204
|
|
|
211
205
|
/**
|
|
206
|
+
* Extracts an attributes from a given object by its key.
|
|
212
207
|
* @function getXObjAttributes
|
|
213
208
|
* @param {object} obj - some object
|
|
214
209
|
* @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
|
|
215
210
|
* @returns {?object}
|
|
216
211
|
* @throws {TypeError} if first param is not an object
|
|
217
|
-
* @description Extracts an attributes from a given object by its key.
|
|
218
212
|
*/
|
|
219
213
|
function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
|
|
220
214
|
let result = null;
|
|
@@ -235,20 +229,20 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
|
|
|
235
229
|
};
|
|
236
230
|
|
|
237
231
|
/**
|
|
232
|
+
* A result of an xObj modification ops
|
|
238
233
|
* @typedef {Object} RVAL_emodif
|
|
239
234
|
* @property {boolean} isSucceed - flag that indicates whether an ops is succeed or not
|
|
240
235
|
* @property {?(object|object[])} item - some element as a result
|
|
241
|
-
* @description A result of an xObj modification ops
|
|
242
236
|
*/
|
|
243
237
|
|
|
244
238
|
/**
|
|
239
|
+
* Adds an element addressed by its key to a given object.
|
|
245
240
|
* @function addXObjElement
|
|
246
241
|
* @param {object} obj - some object
|
|
247
242
|
* @param {string} name - some child element
|
|
248
243
|
* @returns {RVAL_emodif}
|
|
249
244
|
* @throws {TypeError} if first param is not an object
|
|
250
245
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
251
|
-
* @description Adds an element addressed by its key to a given object.
|
|
252
246
|
*/
|
|
253
247
|
function addXObjElement(obj, name) {
|
|
254
248
|
if (!isPlainObject(obj)) {
|
|
@@ -286,6 +280,7 @@ function addXObjElement(obj, name) {
|
|
|
286
280
|
};
|
|
287
281
|
|
|
288
282
|
/**
|
|
283
|
+
* An options for an element insertion ops
|
|
289
284
|
* @typedef {Object} OPT_inselops_L
|
|
290
285
|
* @property {boolean} [force=false]
|
|
291
286
|
* @property {boolean} [ripOldies=false]
|
|
@@ -293,13 +288,14 @@ function addXObjElement(obj, name) {
|
|
|
293
288
|
*/
|
|
294
289
|
|
|
295
290
|
/**
|
|
291
|
+
* Inserts an element addressed by its key into a given object.
|
|
296
292
|
* @function insertXObjElement
|
|
297
293
|
* @param {object} obj - some object
|
|
298
294
|
* @param {string} name - some child element
|
|
299
295
|
* @param {OPT_inselops_L} [opt] - options
|
|
300
296
|
* @returns {?object}
|
|
301
297
|
* @throws {TypeError} if first param is not an object
|
|
302
|
-
* @
|
|
298
|
+
* @see insertXObjElementEx
|
|
303
299
|
*/
|
|
304
300
|
function insertXObjElement(...args) {
|
|
305
301
|
let item = null;
|
|
@@ -320,6 +316,8 @@ function insertXObjElement(...args) {
|
|
|
320
316
|
};
|
|
321
317
|
|
|
322
318
|
/**
|
|
319
|
+
* Inserts an element addressed by its key into a given object.
|
|
320
|
+
* @since 0.2.0
|
|
323
321
|
* @function insertXObjElementEx
|
|
324
322
|
* @param {object} obj - some object
|
|
325
323
|
* @param {string} name - some child element
|
|
@@ -327,8 +325,6 @@ function insertXObjElement(...args) {
|
|
|
327
325
|
* @returns {RVAL_emodif}
|
|
328
326
|
* @throws {TypeError} if first param is not an object
|
|
329
327
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
330
|
-
* @since 0.2.0
|
|
331
|
-
* @description Inserts an element addressed by its key into a given object.
|
|
332
328
|
*/
|
|
333
329
|
function insertXObjElementEx(obj, name, opt) {
|
|
334
330
|
if (!isPlainObject(obj)) {
|
|
@@ -350,8 +346,12 @@ function insertXObjElementEx(obj, name, opt) {
|
|
|
350
346
|
obj[key] = prop = item;
|
|
351
347
|
isSucceed = true;
|
|
352
348
|
} else {
|
|
353
|
-
|
|
354
|
-
let {
|
|
349
|
+
/** @type {OPT_inselops_L} */
|
|
350
|
+
let {
|
|
351
|
+
force,
|
|
352
|
+
ripOldies,
|
|
353
|
+
acceptIfList,
|
|
354
|
+
} = isPlainObject(opt) ? opt : {};
|
|
355
355
|
if (typeof force !== 'boolean') force = false;
|
|
356
356
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
357
357
|
if (typeof acceptIfList !== 'boolean') acceptIfList = false;
|
|
@@ -369,12 +369,13 @@ function insertXObjElementEx(obj, name, opt) {
|
|
|
369
369
|
};
|
|
370
370
|
|
|
371
371
|
/**
|
|
372
|
+
* Deletes an element addressed by its key from a given object.
|
|
372
373
|
* @function deleteXObjElement
|
|
373
374
|
* @param {object} obj - some object
|
|
374
375
|
* @param {string} name - some child element
|
|
375
376
|
* @returns {boolean}
|
|
376
377
|
* @throws {TypeError} if first param is not an object
|
|
377
|
-
* @
|
|
378
|
+
* @see deleteXObjElementEx
|
|
378
379
|
*/
|
|
379
380
|
function deleteXObjElement(...args) {
|
|
380
381
|
let isSucceed = false;
|
|
@@ -395,13 +396,13 @@ function deleteXObjElement(...args) {
|
|
|
395
396
|
};
|
|
396
397
|
|
|
397
398
|
/**
|
|
399
|
+
* Deletes an element addressed by its key from a given object.
|
|
398
400
|
* @function deleteXObjElementEx
|
|
399
401
|
* @param {object} obj - some object
|
|
400
402
|
* @param {string} name - some child element
|
|
401
403
|
* @returns {RVAL_emodif}
|
|
402
404
|
* @throws {TypeError} if first param is not an object
|
|
403
405
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
404
|
-
* @description Deletes an element addressed by its key from a given object.
|
|
405
406
|
*/
|
|
406
407
|
function deleteXObjElementEx(obj, name) {
|
|
407
408
|
if (!isPlainObject(obj)) {
|
|
@@ -427,6 +428,7 @@ function deleteXObjElementEx(obj, name) {
|
|
|
427
428
|
};
|
|
428
429
|
|
|
429
430
|
/**
|
|
431
|
+
* Renames an element addressed by its key.
|
|
430
432
|
* @function renameXObjElement
|
|
431
433
|
* @param {object} obj - some object
|
|
432
434
|
* @param {string} name - some child element
|
|
@@ -435,7 +437,6 @@ function deleteXObjElementEx(obj, name) {
|
|
|
435
437
|
* @throws {TypeError} if first param is not an object
|
|
436
438
|
* @throws {TypeError} if second param is not a string
|
|
437
439
|
* @throws {TypeError} if third param is not a string
|
|
438
|
-
* @description Renames an element addressed by its key.
|
|
439
440
|
*/
|
|
440
441
|
function renameXObjElement(obj, name = '', value = '') {
|
|
441
442
|
if (!isPlainObject(obj)) {
|
|
@@ -475,13 +476,13 @@ function renameXObjElement(obj, name = '', value = '') {
|
|
|
475
476
|
};
|
|
476
477
|
|
|
477
478
|
/**
|
|
479
|
+
* Checks whether an attribute is exists.
|
|
478
480
|
* @function checkXObjAttribute
|
|
479
481
|
* @param {object} obj - some object
|
|
480
482
|
* @param {string} attr - some attribute ID
|
|
481
483
|
* @param {string} [key] - some key
|
|
482
484
|
* @returns {boolean}
|
|
483
485
|
* @throws {TypeError} if first param is not an object
|
|
484
|
-
* @description Checks whether an attribute is exists.
|
|
485
486
|
*/
|
|
486
487
|
function checkXObjAttribute(obj, attr = '', key) {
|
|
487
488
|
let _obj = null;
|
|
@@ -504,13 +505,13 @@ function checkXObjAttribute(obj, attr = '', key) {
|
|
|
504
505
|
};
|
|
505
506
|
|
|
506
507
|
/**
|
|
508
|
+
* Deletes an attribute addressed by a given name.
|
|
507
509
|
* @function deleteXObjAttribute
|
|
508
510
|
* @param {object} obj - some object
|
|
509
511
|
* @param {string} attr - some attribute ID
|
|
510
512
|
* @param {string} [key] - some key
|
|
511
513
|
* @returns {boolean}
|
|
512
514
|
* @throws {TypeError} if first param is not an object
|
|
513
|
-
* @description Deletes an attribute addressed by a given name.
|
|
514
515
|
*/
|
|
515
516
|
function deleteXObjAttribute(obj, attr = '', key) {
|
|
516
517
|
let _obj = null;
|
|
@@ -536,6 +537,8 @@ function deleteXObjAttribute(obj, attr = '', key) {
|
|
|
536
537
|
};
|
|
537
538
|
|
|
538
539
|
/**
|
|
540
|
+
* Renames an attribute addressed by a given name.
|
|
541
|
+
* @since 0.2.0
|
|
539
542
|
* @function renameXObjAttribute
|
|
540
543
|
* @param {object} obj - some object
|
|
541
544
|
* @param {string} attr - some attribute ID
|
|
@@ -545,8 +548,6 @@ function deleteXObjAttribute(obj, attr = '', key) {
|
|
|
545
548
|
* @throws {TypeError} if first param is not an object
|
|
546
549
|
* @throws {TypeError} if second param is not an object
|
|
547
550
|
* @throws {TypeError} if third param is not an object
|
|
548
|
-
* @since 0.2.0
|
|
549
|
-
* @description Renames an attribute addressed by a given name.
|
|
550
551
|
*/
|
|
551
552
|
function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNAME) {
|
|
552
553
|
if (!isPlainObject(obj)) {
|
|
@@ -595,13 +596,13 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
595
596
|
};
|
|
596
597
|
|
|
597
598
|
/**
|
|
599
|
+
* Extracts a parameter 'AS IS' from a given object.
|
|
598
600
|
* @function readXObjParamRaw
|
|
599
601
|
* @param {object} obj - some object
|
|
600
602
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
601
603
|
* @returns {any}
|
|
602
604
|
* @throws {TypeError} if first param is not an object
|
|
603
605
|
* @throws {TypeError} if third param is not a string
|
|
604
|
-
* @description Extracts a parameter 'AS IS' from a given object.
|
|
605
606
|
*/
|
|
606
607
|
function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
607
608
|
if (!isPlainObject(obj)) {
|
|
@@ -620,6 +621,7 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
620
621
|
};
|
|
621
622
|
|
|
622
623
|
/**
|
|
624
|
+
* Writes a parameter 'AS IS' into a given object.
|
|
623
625
|
* @function writeXObjParamRaw
|
|
624
626
|
* @param {object} obj - some object
|
|
625
627
|
* @param {any} value - some value
|
|
@@ -627,7 +629,6 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
627
629
|
* @returns {boolean}
|
|
628
630
|
* @throws {TypeError} if first param is not an object
|
|
629
631
|
* @throws {TypeError} if third param is not a string
|
|
630
|
-
* @description Writes a parameter 'AS IS' into a given object.
|
|
631
632
|
*/
|
|
632
633
|
function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
633
634
|
if (!isPlainObject(obj)) {
|
|
@@ -651,6 +652,7 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
651
652
|
};
|
|
652
653
|
|
|
653
654
|
/**
|
|
655
|
+
* Extracts an attribute 'AS IS' from a given object.
|
|
654
656
|
* @function readXObjAttrRaw
|
|
655
657
|
* @param {object} obj - some object
|
|
656
658
|
* @param {string} attr - some attribute
|
|
@@ -658,7 +660,6 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
658
660
|
* @returns {any}
|
|
659
661
|
* @throws {TypeError} if first param is not an object
|
|
660
662
|
* @throws {TypeError} if third param is not a string
|
|
661
|
-
* @description Extracts an attribute 'AS IS' from a given object.
|
|
662
663
|
*/
|
|
663
664
|
function readXObjAttrRaw(obj, attr = '', key) {
|
|
664
665
|
let _obj = null;
|
|
@@ -680,6 +681,7 @@ function readXObjAttrRaw(obj, attr = '', key) {
|
|
|
680
681
|
};
|
|
681
682
|
|
|
682
683
|
/**
|
|
684
|
+
* Writes a parameter into a given object.
|
|
683
685
|
* @function writeXObjAttrRaw
|
|
684
686
|
* @param {object} obj - some object
|
|
685
687
|
* @param {string} attr - some attribute
|
|
@@ -688,7 +690,6 @@ function readXObjAttrRaw(obj, attr = '', key) {
|
|
|
688
690
|
* @returns {boolean}
|
|
689
691
|
* @throws {TypeError} if first param is not an object
|
|
690
692
|
* @throws {TypeError} if third param is not a string
|
|
691
|
-
* @description Writes a parameter into a given object.
|
|
692
693
|
*/
|
|
693
694
|
function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
694
695
|
let { isSucceed, value: name } = evalKeyName(attr, false);
|
|
@@ -725,13 +726,12 @@ function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
|
725
726
|
};
|
|
726
727
|
|
|
727
728
|
/**
|
|
729
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
728
730
|
* @function readXObjParam
|
|
729
731
|
* @param {object} obj - some object
|
|
730
732
|
* @param {string} [key] - some key
|
|
731
733
|
* @returns {string}
|
|
732
734
|
* @throws {TypeError} if first param is not an object
|
|
733
|
-
* @description Extracts a parameter from a given object
|
|
734
|
-
* and returns it as string.
|
|
735
735
|
*/
|
|
736
736
|
function readXObjParam(obj, key) {
|
|
737
737
|
const opt = {
|
|
@@ -750,14 +750,13 @@ function readXObjParam(obj, key) {
|
|
|
750
750
|
};
|
|
751
751
|
|
|
752
752
|
/**
|
|
753
|
+
* Extracts a parameter from a given object and returns it as a boolean.
|
|
753
754
|
* @function readXObjParamAsBool
|
|
754
755
|
* @param {object} obj - some object
|
|
755
756
|
* @param {boolean} [defValue] - default value
|
|
756
757
|
* @param {string} [key] - some key
|
|
757
758
|
* @returns {boolean}
|
|
758
759
|
* @throws {TypeError} if first param is not an object
|
|
759
|
-
* @description Extracts a parameter from a given object
|
|
760
|
-
* and returns it as boolean.
|
|
761
760
|
*/
|
|
762
761
|
function readXObjParamAsBool(obj, defValue, key) {
|
|
763
762
|
let result = undefined;
|
|
@@ -783,8 +782,7 @@ function readXObjParamAsBool(obj, defValue, key) {
|
|
|
783
782
|
* @param {string} [key] - some key
|
|
784
783
|
* @returns {number}
|
|
785
784
|
* @throws {TypeError} if first param is not an object
|
|
786
|
-
*
|
|
787
|
-
* and returns it as number.
|
|
785
|
+
* Extracts a parameter from a given object and returns it as a number.
|
|
788
786
|
*/
|
|
789
787
|
function readXObjParamAsNum(obj, defValue, key) {
|
|
790
788
|
let result = undefined;
|
|
@@ -804,14 +802,13 @@ function readXObjParamAsNum(obj, defValue, key) {
|
|
|
804
802
|
};
|
|
805
803
|
|
|
806
804
|
/**
|
|
805
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
807
806
|
* @function readXObjParamEx
|
|
808
807
|
* @param {object} obj - some object
|
|
809
808
|
* @param {object} [opt] - options
|
|
810
809
|
* @param {string} [key] - some key
|
|
811
810
|
* @returns {string}
|
|
812
811
|
* @throws {TypeError} if first param is not an object
|
|
813
|
-
* @description Extracts a parameter from a given object
|
|
814
|
-
* and returns it as string.
|
|
815
812
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
816
813
|
*/
|
|
817
814
|
function readXObjParamEx(obj, opt, key) {
|
|
@@ -841,13 +838,12 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
841
838
|
};
|
|
842
839
|
|
|
843
840
|
/**
|
|
841
|
+
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
844
842
|
* @function readXObjParamAsIndex
|
|
845
843
|
* @param {object} obj - some object
|
|
846
844
|
* @param {string} [key] - some key
|
|
847
845
|
* @returns {number}
|
|
848
846
|
* @throws {TypeError} if first param is not an object
|
|
849
|
-
* @description Extracts a parameter from a given object
|
|
850
|
-
* and returns it as 'index' value.
|
|
851
847
|
*/
|
|
852
848
|
function readXObjParamAsIndex(obj, key) {
|
|
853
849
|
let result = undefined;
|
|
@@ -867,14 +863,14 @@ function readXObjParamAsIndex(obj, key) {
|
|
|
867
863
|
};
|
|
868
864
|
|
|
869
865
|
/**
|
|
866
|
+
* Tries to convert a given value to a string and writes it as a parameter
|
|
867
|
+
* into a given object.
|
|
870
868
|
* @function writeXObjParam
|
|
871
869
|
* @param {object} obj - some object
|
|
872
870
|
* @param {any} value - some value
|
|
873
871
|
* @param {string} [key] - some key
|
|
874
872
|
* @returns {boolean}
|
|
875
873
|
* @throws {TypeError} if first param is not an object
|
|
876
|
-
* @description Tries to convert a given value to a string
|
|
877
|
-
* and writes it as a parameter into a given object.
|
|
878
874
|
*/
|
|
879
875
|
function writeXObjParam(obj, value, key) {
|
|
880
876
|
let isSucceed = false;
|
|
@@ -893,6 +889,8 @@ function writeXObjParam(obj, value, key) {
|
|
|
893
889
|
};
|
|
894
890
|
|
|
895
891
|
/**
|
|
892
|
+
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
893
|
+
* into a given object.
|
|
896
894
|
* @function writeXObjParamAsBool
|
|
897
895
|
* @param {object} obj - some object
|
|
898
896
|
* @param {any} value - some value
|
|
@@ -900,8 +898,6 @@ function writeXObjParam(obj, value, key) {
|
|
|
900
898
|
* @param {string} [key] - some key
|
|
901
899
|
* @returns {boolean}
|
|
902
900
|
* @throws {TypeError} if first param is not an object
|
|
903
|
-
* @description Tries to convert a given value to a boolean
|
|
904
|
-
* and writes it as a parameter into a given object.
|
|
905
901
|
*/
|
|
906
902
|
function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
907
903
|
let isSucceed = false;
|
|
@@ -924,6 +920,8 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
|
924
920
|
};
|
|
925
921
|
|
|
926
922
|
/**
|
|
923
|
+
* Tries to convert a given value to a number and writes it as a parameter
|
|
924
|
+
* into a given object.
|
|
927
925
|
* @function writeXObjParamAsNum
|
|
928
926
|
* @param {object} obj - some object
|
|
929
927
|
* @param {any} value - some value
|
|
@@ -931,8 +929,6 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
|
931
929
|
* @param {string} [key] - some key
|
|
932
930
|
* @returns {boolean}
|
|
933
931
|
* @throws {TypeError} if first param is not an object
|
|
934
|
-
* @description Tries to convert a given value to a number
|
|
935
|
-
* and writes it as a parameter into a given object.
|
|
936
932
|
*/
|
|
937
933
|
function writeXObjParamAsNum(obj, value, defValue, key) {
|
|
938
934
|
let isSucceed = false;
|
|
@@ -955,14 +951,14 @@ function writeXObjParamAsNum(obj, value, defValue, key) {
|
|
|
955
951
|
};
|
|
956
952
|
|
|
957
953
|
/**
|
|
954
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
955
|
+
* as a parameter into a given object.
|
|
958
956
|
* @function writeXObjParamAsIndex
|
|
959
957
|
* @param {object} obj - some object
|
|
960
958
|
* @param {any} value - some value
|
|
961
959
|
* @param {string} [key] - some key
|
|
962
960
|
* @returns {boolean}
|
|
963
961
|
* @throws {TypeError} if first param is not an object
|
|
964
|
-
* @description Tries to convert a given value into an 'index' value
|
|
965
|
-
* and writes it as a parameter into a given object.
|
|
966
962
|
*/
|
|
967
963
|
function writeXObjParamAsIndex(obj, value, key) {
|
|
968
964
|
let isSucceed = false;
|
|
@@ -985,6 +981,8 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
985
981
|
};
|
|
986
982
|
|
|
987
983
|
/**
|
|
984
|
+
* Tries to convert a given value to a string and writes it
|
|
985
|
+
* as a parameter into a given object.
|
|
988
986
|
* @function writeXObjParamEx
|
|
989
987
|
* @param {object} obj - some object
|
|
990
988
|
* @param {any} value - some value
|
|
@@ -992,8 +990,6 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
992
990
|
* @param {string} [key] - some key
|
|
993
991
|
* @returns {boolean}
|
|
994
992
|
* @throws {TypeError} if first param is not an object
|
|
995
|
-
* @description Tries to convert a given value to a string
|
|
996
|
-
* and writes it as a parameter into a given object.
|
|
997
993
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
998
994
|
*/
|
|
999
995
|
function writeXObjParamEx(obj, value, opt, key) {
|
|
@@ -1031,14 +1027,13 @@ function writeXObjParamEx(obj, value, opt, key) {
|
|
|
1031
1027
|
};
|
|
1032
1028
|
|
|
1033
1029
|
/**
|
|
1030
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
1034
1031
|
* @function readXObjAttr
|
|
1035
1032
|
* @param {object} obj - some object
|
|
1036
1033
|
* @param {string} attr - some attribute
|
|
1037
1034
|
* @param {string} [key] - some key
|
|
1038
1035
|
* @returns {string}
|
|
1039
1036
|
* @throws {TypeError} if first param is not an object
|
|
1040
|
-
* @description Extracts an attribute from a given object
|
|
1041
|
-
* and returns it as string.
|
|
1042
1037
|
*/
|
|
1043
1038
|
function readXObjAttr(obj, attr, key) {
|
|
1044
1039
|
const opt = {
|
|
@@ -1057,6 +1052,7 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1057
1052
|
};
|
|
1058
1053
|
|
|
1059
1054
|
/**
|
|
1055
|
+
* Extracts an attribute from a given object and returns it as a boolean.
|
|
1060
1056
|
* @function readXObjAttrAsBool
|
|
1061
1057
|
* @param {object} obj - some object
|
|
1062
1058
|
* @param {string} attr - some attribute
|
|
@@ -1064,8 +1060,6 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1064
1060
|
* @param {string} [key] - some key
|
|
1065
1061
|
* @returns {boolean}
|
|
1066
1062
|
* @throws {TypeError} if first param is not an object
|
|
1067
|
-
* @description Extracts an attribute from a given object
|
|
1068
|
-
* and returns it as boolean.
|
|
1069
1063
|
*/
|
|
1070
1064
|
function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
1071
1065
|
let result = undefined;
|
|
@@ -1085,6 +1079,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1085
1079
|
};
|
|
1086
1080
|
|
|
1087
1081
|
/**
|
|
1082
|
+
* Extracts an attribute from a given object and returns it as a number.
|
|
1088
1083
|
* @function readXObjAttrAsNum
|
|
1089
1084
|
* @param {object} obj - some object
|
|
1090
1085
|
* @param {string} attr - some attribute
|
|
@@ -1092,8 +1087,6 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1092
1087
|
* @param {string} [key] - some key
|
|
1093
1088
|
* @returns {number}
|
|
1094
1089
|
* @throws {TypeError} if first param is not an object
|
|
1095
|
-
* @description Extracts an attribute from a given object
|
|
1096
|
-
* and returns it as number.
|
|
1097
1090
|
*/
|
|
1098
1091
|
function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
1099
1092
|
let result = undefined;
|
|
@@ -1113,6 +1106,7 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
|
1113
1106
|
};
|
|
1114
1107
|
|
|
1115
1108
|
/**
|
|
1109
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
1116
1110
|
* @function readXObjAttrEx
|
|
1117
1111
|
* @param {object} obj - some object
|
|
1118
1112
|
* @param {string} attr - some attribute
|
|
@@ -1120,8 +1114,6 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
|
1120
1114
|
* @param {string} [key] - some key
|
|
1121
1115
|
* @returns {string}
|
|
1122
1116
|
* @throws {TypeError} if first param is not an object
|
|
1123
|
-
* @description Extracts an attribute from a given object
|
|
1124
|
-
* and returns it as string.
|
|
1125
1117
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1126
1118
|
*/
|
|
1127
1119
|
function readXObjAttrEx(obj, attr, opt, key) {
|
|
@@ -1151,14 +1143,13 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
1151
1143
|
};
|
|
1152
1144
|
|
|
1153
1145
|
/**
|
|
1146
|
+
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
1154
1147
|
* @function readXObjAttrAsIndex
|
|
1155
1148
|
* @param {object} obj - some object
|
|
1156
1149
|
* @param {string} attr - some attribute
|
|
1157
1150
|
* @param {string} [key] - some key
|
|
1158
1151
|
* @returns {number}
|
|
1159
1152
|
* @throws {TypeError} if first param is not an object
|
|
1160
|
-
* @description Extracts an attribute from a given object
|
|
1161
|
-
* and returns it as 'index' value.
|
|
1162
1153
|
*/
|
|
1163
1154
|
function readXObjAttrAsIndex(obj, attr, key) {
|
|
1164
1155
|
let result = undefined;
|
|
@@ -1178,6 +1169,8 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
1178
1169
|
};
|
|
1179
1170
|
|
|
1180
1171
|
/**
|
|
1172
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
1173
|
+
* into a given object.
|
|
1181
1174
|
* @function writeXObjAttr
|
|
1182
1175
|
* @param {object} obj - some object
|
|
1183
1176
|
* @param {string} attr - some attribute
|
|
@@ -1185,8 +1178,6 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
1185
1178
|
* @param {string} [key] - some key
|
|
1186
1179
|
* @returns {boolean}
|
|
1187
1180
|
* @throws {TypeError} if first param is not an object
|
|
1188
|
-
* @description Tries to convert a given value to a string
|
|
1189
|
-
* and writes it as an attribute into a given object.
|
|
1190
1181
|
*/
|
|
1191
1182
|
function writeXObjAttr(obj, attr, value, key) {
|
|
1192
1183
|
let isSucceed = false;
|
|
@@ -1205,6 +1196,8 @@ function writeXObjAttr(obj, attr, value, key) {
|
|
|
1205
1196
|
};
|
|
1206
1197
|
|
|
1207
1198
|
/**
|
|
1199
|
+
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
1200
|
+
* into a given object.
|
|
1208
1201
|
* @function writeXObjAttrAsBool
|
|
1209
1202
|
* @param {object} obj - some object
|
|
1210
1203
|
* @param {string} attr - some attribute
|
|
@@ -1213,8 +1206,6 @@ function writeXObjAttr(obj, attr, value, key) {
|
|
|
1213
1206
|
* @param {string} [key] - some key
|
|
1214
1207
|
* @returns {boolean}
|
|
1215
1208
|
* @throws {TypeError} if first param is not an object
|
|
1216
|
-
* @description Tries to convert a given value to a boolean
|
|
1217
|
-
* and writes it as an attribute into a given object.
|
|
1218
1209
|
*/
|
|
1219
1210
|
function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
1220
1211
|
let isSucceed = false;
|
|
@@ -1237,6 +1228,8 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
|
1237
1228
|
};
|
|
1238
1229
|
|
|
1239
1230
|
/**
|
|
1231
|
+
* Tries to convert a given value to a number and writes it as an attribute
|
|
1232
|
+
* into a given object.
|
|
1240
1233
|
* @function writeXObjAttrAsNum
|
|
1241
1234
|
* @param {object} obj - some object
|
|
1242
1235
|
* @param {string} attr - some attribute
|
|
@@ -1245,8 +1238,6 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
|
1245
1238
|
* @param {string} [key] - some key
|
|
1246
1239
|
* @returns {boolean}
|
|
1247
1240
|
* @throws {TypeError} if first param is not an object
|
|
1248
|
-
* @description Tries to convert a given value to a number
|
|
1249
|
-
* and writes it as an attribute into a given object.
|
|
1250
1241
|
*/
|
|
1251
1242
|
function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
1252
1243
|
let isSucceed = false;
|
|
@@ -1269,6 +1260,8 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
|
1269
1260
|
};
|
|
1270
1261
|
|
|
1271
1262
|
/**
|
|
1263
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
1264
|
+
* as an attribute into a given object.
|
|
1272
1265
|
* @function writeXObjAttrAsIndex
|
|
1273
1266
|
* @param {object} obj - some object
|
|
1274
1267
|
* @param {string} attr - some attribute
|
|
@@ -1276,8 +1269,6 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
|
1276
1269
|
* @param {string} [key] - some key
|
|
1277
1270
|
* @returns {boolean}
|
|
1278
1271
|
* @throws {TypeError} if first param is not an object
|
|
1279
|
-
* @description Tries to convert a given value into an 'index' value
|
|
1280
|
-
* and writes it as an attribute into a given object.
|
|
1281
1272
|
*/
|
|
1282
1273
|
function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
1283
1274
|
let isSucceed = false;
|
|
@@ -1300,6 +1291,8 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1300
1291
|
};
|
|
1301
1292
|
|
|
1302
1293
|
/**
|
|
1294
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
1295
|
+
* into a given object.
|
|
1303
1296
|
* @function writeXObjAttrEx
|
|
1304
1297
|
* @param {object} obj - some object
|
|
1305
1298
|
* @param {string} attr - some attribute
|
|
@@ -1308,8 +1301,6 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1308
1301
|
* @param {string} [key] - some key
|
|
1309
1302
|
* @returns {boolean}
|
|
1310
1303
|
* @throws {TypeError} if first param is not an object
|
|
1311
|
-
* @description Tries to convert a given value to a string
|
|
1312
|
-
* and writes it as an attribute into a given object.
|
|
1313
1304
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1314
1305
|
*/
|
|
1315
1306
|
function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
@@ -1347,13 +1338,13 @@ function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
|
1347
1338
|
};
|
|
1348
1339
|
|
|
1349
1340
|
/**
|
|
1341
|
+
* Inserts an elements into a given object.
|
|
1350
1342
|
* @function insertXObjElements
|
|
1351
|
-
* @param {object} obj
|
|
1352
|
-
* @param {...string} name
|
|
1343
|
+
* @param {object} obj - some object
|
|
1344
|
+
* @param {...string} name - some child element name
|
|
1353
1345
|
* @param {OPT_inselops_L} [opt]
|
|
1354
1346
|
* @returns {number}
|
|
1355
1347
|
* @throws {TypeError} if first param is not an object
|
|
1356
|
-
* @description Inserts an elements into a given object.
|
|
1357
1348
|
*/
|
|
1358
1349
|
function insertXObjElements(obj, ...args) {
|
|
1359
1350
|
if (!isPlainObject(obj)) {
|
|
@@ -1375,19 +1366,20 @@ function insertXObjElements(obj, ...args) {
|
|
|
1375
1366
|
};
|
|
1376
1367
|
|
|
1377
1368
|
/**
|
|
1369
|
+
* An options for an element insertion ops
|
|
1378
1370
|
* @typedef {Object} OPT_inselops_S
|
|
1379
1371
|
* @property {boolean} [force=false]
|
|
1380
1372
|
* @property {boolean} [ripOldies=false]
|
|
1381
1373
|
*/
|
|
1382
1374
|
|
|
1383
1375
|
/**
|
|
1376
|
+
* Inserts a list elements into a given object.
|
|
1384
1377
|
* @function insertXObjEList
|
|
1385
1378
|
* @param {object} obj - some object
|
|
1386
|
-
* @param {string} name - some child element
|
|
1379
|
+
* @param {string} name - some child element name
|
|
1387
1380
|
* @param {OPT_inselops_S} [opt] - options
|
|
1388
1381
|
* @returns {?(object|object[])}
|
|
1389
1382
|
* @throws {TypeError} if first param is not an object
|
|
1390
|
-
* @description Inserts a list elements into a given object.
|
|
1391
1383
|
*/
|
|
1392
1384
|
function insertXObjEList(...args) {
|
|
1393
1385
|
let item = null;
|
|
@@ -1408,15 +1400,15 @@ function insertXObjEList(...args) {
|
|
|
1408
1400
|
};
|
|
1409
1401
|
|
|
1410
1402
|
/**
|
|
1403
|
+
* Inserts a list elements into a given object.
|
|
1404
|
+
* @since 0.2.0
|
|
1411
1405
|
* @function insertXObjEListEx
|
|
1412
1406
|
* @param {object} obj - some object
|
|
1413
|
-
* @param {string} name - some child element
|
|
1407
|
+
* @param {string} name - some child element name
|
|
1414
1408
|
* @param {OPT_inselops_S} [opt] - options
|
|
1415
1409
|
* @returns {RVAL_emodif}
|
|
1416
1410
|
* @throws {TypeError} if first param is not an object
|
|
1417
1411
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
1418
|
-
* @since 0.2.0
|
|
1419
|
-
* @description Inserts a list elements into a given object.
|
|
1420
1412
|
*/
|
|
1421
1413
|
function insertXObjEListEx(obj, name, opt) {
|
|
1422
1414
|
if (!isPlainObject(obj)) {
|
|
@@ -1431,8 +1423,11 @@ function insertXObjEListEx(obj, name, opt) {
|
|
|
1431
1423
|
err.code = code;
|
|
1432
1424
|
throw err;
|
|
1433
1425
|
};
|
|
1434
|
-
|
|
1435
|
-
let {
|
|
1426
|
+
/** @type {OPT_inselops_S} */
|
|
1427
|
+
let {
|
|
1428
|
+
force,
|
|
1429
|
+
ripOldies,
|
|
1430
|
+
} = isPlainObject(opt) ? opt : {};
|
|
1436
1431
|
if (typeof force !== 'boolean') force = false;
|
|
1437
1432
|
if (typeof ripOldies !== 'boolean') ripOldies = false;
|
|
1438
1433
|
let prop = obj[key];
|
|
@@ -1457,13 +1452,13 @@ function insertXObjEListEx(obj, name, opt) {
|
|
|
1457
1452
|
};
|
|
1458
1453
|
|
|
1459
1454
|
/**
|
|
1455
|
+
* Inserts a chain of an elements into a given object.
|
|
1460
1456
|
* @function insertXObjEChain
|
|
1461
1457
|
* @param {object} obj - some object
|
|
1462
|
-
* @param {...string} name - some child element
|
|
1458
|
+
* @param {...string} name - some child element name
|
|
1463
1459
|
* @param {object} [opt] - options
|
|
1464
1460
|
* @returns {?any}
|
|
1465
1461
|
* @throws {TypeError} if first param is not an object
|
|
1466
|
-
* @description Inserts a chain of an elements into a given object.
|
|
1467
1462
|
*/
|
|
1468
1463
|
function insertXObjEChain(obj, ...args) {
|
|
1469
1464
|
if (!isPlainObject(obj)) {
|
|
@@ -1554,8 +1549,3 @@ module.exports.genXObjENameDescr = genXObjENameDescr;
|
|
|
1554
1549
|
module.exports.insertXObjElements = insertXObjElements;
|
|
1555
1550
|
/* experimental */
|
|
1556
1551
|
module.exports.insertXObjEChain = insertXObjEChain;
|
|
1557
|
-
|
|
1558
|
-
/** @deprecated */
|
|
1559
|
-
module.exports.readXObjParamAsStr = readXObjParamEx;
|
|
1560
|
-
/** @deprecated */
|
|
1561
|
-
module.exports.readXObjAttrAsStr = readXObjAttrEx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ygracs/xobj-lib-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A helper library to work with xml-js module",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,11 +18,6 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "jest",
|
|
21
|
-
"test-xobj": "jest xObj",
|
|
22
|
-
"test-xobj:c1": "jest xObj-lib.1",
|
|
23
|
-
"test-xobj:c2": "jest xObj-lib.2",
|
|
24
|
-
"test-xobj:c3": "jest xObj-lib.3",
|
|
25
|
-
"test-xobj:c4": "jest xObj-lib.4",
|
|
26
21
|
"build-doc-md": "jsdoc2md",
|
|
27
22
|
"build-doc-html": "jsdoc"
|
|
28
23
|
},
|
|
@@ -31,10 +26,10 @@
|
|
|
31
26
|
"#test-dir/*": "./__test__/*"
|
|
32
27
|
},
|
|
33
28
|
"dependencies": {
|
|
34
|
-
"@ygracs/bsfoc-lib-js": "^0.2.
|
|
29
|
+
"@ygracs/bsfoc-lib-js": "^0.2.3"
|
|
35
30
|
},
|
|
36
31
|
"devDependencies": {
|
|
37
|
-
"jest": "^
|
|
32
|
+
"jest": "^30.0.4",
|
|
38
33
|
"jsdoc-to-markdown": "^9.1.1",
|
|
39
34
|
"minimist": "^1.2.8"
|
|
40
35
|
}
|