@ygracs/xobj-lib-js 0.2.2 → 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 +10 -0
- package/doc/xObj.md +38 -29
- package/lib/xObj-defs.js +80 -11
- package/lib/xObj-lib.js +75 -92
- package/package.json +2 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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
|
+
|
|
1
11
|
#### *v0.2.2*
|
|
2
12
|
|
|
3
13
|
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,7 @@ function insertXObjElement(...args) {
|
|
|
320
316
|
};
|
|
321
317
|
|
|
322
318
|
/**
|
|
319
|
+
* Inserts an element addressed by its key into a given object.
|
|
323
320
|
* @since 0.2.0
|
|
324
321
|
* @function insertXObjElementEx
|
|
325
322
|
* @param {object} obj - some object
|
|
@@ -328,7 +325,6 @@ function insertXObjElement(...args) {
|
|
|
328
325
|
* @returns {RVAL_emodif}
|
|
329
326
|
* @throws {TypeError} if first param is not an object
|
|
330
327
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
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)) {
|
|
@@ -373,12 +369,13 @@ function insertXObjElementEx(obj, name, opt) {
|
|
|
373
369
|
};
|
|
374
370
|
|
|
375
371
|
/**
|
|
372
|
+
* Deletes an element addressed by its key from a given object.
|
|
376
373
|
* @function deleteXObjElement
|
|
377
374
|
* @param {object} obj - some object
|
|
378
375
|
* @param {string} name - some child element
|
|
379
376
|
* @returns {boolean}
|
|
380
377
|
* @throws {TypeError} if first param is not an object
|
|
381
|
-
* @
|
|
378
|
+
* @see deleteXObjElementEx
|
|
382
379
|
*/
|
|
383
380
|
function deleteXObjElement(...args) {
|
|
384
381
|
let isSucceed = false;
|
|
@@ -399,13 +396,13 @@ function deleteXObjElement(...args) {
|
|
|
399
396
|
};
|
|
400
397
|
|
|
401
398
|
/**
|
|
399
|
+
* Deletes an element addressed by its key from a given object.
|
|
402
400
|
* @function deleteXObjElementEx
|
|
403
401
|
* @param {object} obj - some object
|
|
404
402
|
* @param {string} name - some child element
|
|
405
403
|
* @returns {RVAL_emodif}
|
|
406
404
|
* @throws {TypeError} if first param is not an object
|
|
407
405
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
408
|
-
* @description Deletes an element addressed by its key from a given object.
|
|
409
406
|
*/
|
|
410
407
|
function deleteXObjElementEx(obj, name) {
|
|
411
408
|
if (!isPlainObject(obj)) {
|
|
@@ -431,6 +428,7 @@ function deleteXObjElementEx(obj, name) {
|
|
|
431
428
|
};
|
|
432
429
|
|
|
433
430
|
/**
|
|
431
|
+
* Renames an element addressed by its key.
|
|
434
432
|
* @function renameXObjElement
|
|
435
433
|
* @param {object} obj - some object
|
|
436
434
|
* @param {string} name - some child element
|
|
@@ -439,7 +437,6 @@ function deleteXObjElementEx(obj, name) {
|
|
|
439
437
|
* @throws {TypeError} if first param is not an object
|
|
440
438
|
* @throws {TypeError} if second param is not a string
|
|
441
439
|
* @throws {TypeError} if third param is not a string
|
|
442
|
-
* @description Renames an element addressed by its key.
|
|
443
440
|
*/
|
|
444
441
|
function renameXObjElement(obj, name = '', value = '') {
|
|
445
442
|
if (!isPlainObject(obj)) {
|
|
@@ -479,13 +476,13 @@ function renameXObjElement(obj, name = '', value = '') {
|
|
|
479
476
|
};
|
|
480
477
|
|
|
481
478
|
/**
|
|
479
|
+
* Checks whether an attribute is exists.
|
|
482
480
|
* @function checkXObjAttribute
|
|
483
481
|
* @param {object} obj - some object
|
|
484
482
|
* @param {string} attr - some attribute ID
|
|
485
483
|
* @param {string} [key] - some key
|
|
486
484
|
* @returns {boolean}
|
|
487
485
|
* @throws {TypeError} if first param is not an object
|
|
488
|
-
* @description Checks whether an attribute is exists.
|
|
489
486
|
*/
|
|
490
487
|
function checkXObjAttribute(obj, attr = '', key) {
|
|
491
488
|
let _obj = null;
|
|
@@ -508,13 +505,13 @@ function checkXObjAttribute(obj, attr = '', key) {
|
|
|
508
505
|
};
|
|
509
506
|
|
|
510
507
|
/**
|
|
508
|
+
* Deletes an attribute addressed by a given name.
|
|
511
509
|
* @function deleteXObjAttribute
|
|
512
510
|
* @param {object} obj - some object
|
|
513
511
|
* @param {string} attr - some attribute ID
|
|
514
512
|
* @param {string} [key] - some key
|
|
515
513
|
* @returns {boolean}
|
|
516
514
|
* @throws {TypeError} if first param is not an object
|
|
517
|
-
* @description Deletes an attribute addressed by a given name.
|
|
518
515
|
*/
|
|
519
516
|
function deleteXObjAttribute(obj, attr = '', key) {
|
|
520
517
|
let _obj = null;
|
|
@@ -540,6 +537,7 @@ function deleteXObjAttribute(obj, attr = '', key) {
|
|
|
540
537
|
};
|
|
541
538
|
|
|
542
539
|
/**
|
|
540
|
+
* Renames an attribute addressed by a given name.
|
|
543
541
|
* @since 0.2.0
|
|
544
542
|
* @function renameXObjAttribute
|
|
545
543
|
* @param {object} obj - some object
|
|
@@ -550,7 +548,6 @@ function deleteXObjAttribute(obj, attr = '', key) {
|
|
|
550
548
|
* @throws {TypeError} if first param is not an object
|
|
551
549
|
* @throws {TypeError} if second param is not an object
|
|
552
550
|
* @throws {TypeError} if third param is not an object
|
|
553
|
-
* @description Renames an attribute addressed by a given name.
|
|
554
551
|
*/
|
|
555
552
|
function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNAME) {
|
|
556
553
|
if (!isPlainObject(obj)) {
|
|
@@ -599,13 +596,13 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
599
596
|
};
|
|
600
597
|
|
|
601
598
|
/**
|
|
599
|
+
* Extracts a parameter 'AS IS' from a given object.
|
|
602
600
|
* @function readXObjParamRaw
|
|
603
601
|
* @param {object} obj - some object
|
|
604
602
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
605
603
|
* @returns {any}
|
|
606
604
|
* @throws {TypeError} if first param is not an object
|
|
607
605
|
* @throws {TypeError} if third param is not a string
|
|
608
|
-
* @description Extracts a parameter 'AS IS' from a given object.
|
|
609
606
|
*/
|
|
610
607
|
function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
611
608
|
if (!isPlainObject(obj)) {
|
|
@@ -624,6 +621,7 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
624
621
|
};
|
|
625
622
|
|
|
626
623
|
/**
|
|
624
|
+
* Writes a parameter 'AS IS' into a given object.
|
|
627
625
|
* @function writeXObjParamRaw
|
|
628
626
|
* @param {object} obj - some object
|
|
629
627
|
* @param {any} value - some value
|
|
@@ -631,7 +629,6 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
631
629
|
* @returns {boolean}
|
|
632
630
|
* @throws {TypeError} if first param is not an object
|
|
633
631
|
* @throws {TypeError} if third param is not a string
|
|
634
|
-
* @description Writes a parameter 'AS IS' into a given object.
|
|
635
632
|
*/
|
|
636
633
|
function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
637
634
|
if (!isPlainObject(obj)) {
|
|
@@ -655,6 +652,7 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
655
652
|
};
|
|
656
653
|
|
|
657
654
|
/**
|
|
655
|
+
* Extracts an attribute 'AS IS' from a given object.
|
|
658
656
|
* @function readXObjAttrRaw
|
|
659
657
|
* @param {object} obj - some object
|
|
660
658
|
* @param {string} attr - some attribute
|
|
@@ -662,7 +660,6 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
662
660
|
* @returns {any}
|
|
663
661
|
* @throws {TypeError} if first param is not an object
|
|
664
662
|
* @throws {TypeError} if third param is not a string
|
|
665
|
-
* @description Extracts an attribute 'AS IS' from a given object.
|
|
666
663
|
*/
|
|
667
664
|
function readXObjAttrRaw(obj, attr = '', key) {
|
|
668
665
|
let _obj = null;
|
|
@@ -684,6 +681,7 @@ function readXObjAttrRaw(obj, attr = '', key) {
|
|
|
684
681
|
};
|
|
685
682
|
|
|
686
683
|
/**
|
|
684
|
+
* Writes a parameter into a given object.
|
|
687
685
|
* @function writeXObjAttrRaw
|
|
688
686
|
* @param {object} obj - some object
|
|
689
687
|
* @param {string} attr - some attribute
|
|
@@ -692,7 +690,6 @@ function readXObjAttrRaw(obj, attr = '', key) {
|
|
|
692
690
|
* @returns {boolean}
|
|
693
691
|
* @throws {TypeError} if first param is not an object
|
|
694
692
|
* @throws {TypeError} if third param is not a string
|
|
695
|
-
* @description Writes a parameter into a given object.
|
|
696
693
|
*/
|
|
697
694
|
function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
698
695
|
let { isSucceed, value: name } = evalKeyName(attr, false);
|
|
@@ -729,13 +726,12 @@ function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
|
729
726
|
};
|
|
730
727
|
|
|
731
728
|
/**
|
|
729
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
732
730
|
* @function readXObjParam
|
|
733
731
|
* @param {object} obj - some object
|
|
734
732
|
* @param {string} [key] - some key
|
|
735
733
|
* @returns {string}
|
|
736
734
|
* @throws {TypeError} if first param is not an object
|
|
737
|
-
* @description Extracts a parameter from a given object
|
|
738
|
-
* and returns it as string.
|
|
739
735
|
*/
|
|
740
736
|
function readXObjParam(obj, key) {
|
|
741
737
|
const opt = {
|
|
@@ -754,14 +750,13 @@ function readXObjParam(obj, key) {
|
|
|
754
750
|
};
|
|
755
751
|
|
|
756
752
|
/**
|
|
753
|
+
* Extracts a parameter from a given object and returns it as a boolean.
|
|
757
754
|
* @function readXObjParamAsBool
|
|
758
755
|
* @param {object} obj - some object
|
|
759
756
|
* @param {boolean} [defValue] - default value
|
|
760
757
|
* @param {string} [key] - some key
|
|
761
758
|
* @returns {boolean}
|
|
762
759
|
* @throws {TypeError} if first param is not an object
|
|
763
|
-
* @description Extracts a parameter from a given object
|
|
764
|
-
* and returns it as boolean.
|
|
765
760
|
*/
|
|
766
761
|
function readXObjParamAsBool(obj, defValue, key) {
|
|
767
762
|
let result = undefined;
|
|
@@ -787,8 +782,7 @@ function readXObjParamAsBool(obj, defValue, key) {
|
|
|
787
782
|
* @param {string} [key] - some key
|
|
788
783
|
* @returns {number}
|
|
789
784
|
* @throws {TypeError} if first param is not an object
|
|
790
|
-
*
|
|
791
|
-
* and returns it as number.
|
|
785
|
+
* Extracts a parameter from a given object and returns it as a number.
|
|
792
786
|
*/
|
|
793
787
|
function readXObjParamAsNum(obj, defValue, key) {
|
|
794
788
|
let result = undefined;
|
|
@@ -808,14 +802,13 @@ function readXObjParamAsNum(obj, defValue, key) {
|
|
|
808
802
|
};
|
|
809
803
|
|
|
810
804
|
/**
|
|
805
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
811
806
|
* @function readXObjParamEx
|
|
812
807
|
* @param {object} obj - some object
|
|
813
808
|
* @param {object} [opt] - options
|
|
814
809
|
* @param {string} [key] - some key
|
|
815
810
|
* @returns {string}
|
|
816
811
|
* @throws {TypeError} if first param is not an object
|
|
817
|
-
* @description Extracts a parameter from a given object
|
|
818
|
-
* and returns it as string.
|
|
819
812
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
820
813
|
*/
|
|
821
814
|
function readXObjParamEx(obj, opt, key) {
|
|
@@ -845,13 +838,12 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
845
838
|
};
|
|
846
839
|
|
|
847
840
|
/**
|
|
841
|
+
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
848
842
|
* @function readXObjParamAsIndex
|
|
849
843
|
* @param {object} obj - some object
|
|
850
844
|
* @param {string} [key] - some key
|
|
851
845
|
* @returns {number}
|
|
852
846
|
* @throws {TypeError} if first param is not an object
|
|
853
|
-
* @description Extracts a parameter from a given object
|
|
854
|
-
* and returns it as 'index' value.
|
|
855
847
|
*/
|
|
856
848
|
function readXObjParamAsIndex(obj, key) {
|
|
857
849
|
let result = undefined;
|
|
@@ -871,14 +863,14 @@ function readXObjParamAsIndex(obj, key) {
|
|
|
871
863
|
};
|
|
872
864
|
|
|
873
865
|
/**
|
|
866
|
+
* Tries to convert a given value to a string and writes it as a parameter
|
|
867
|
+
* into a given object.
|
|
874
868
|
* @function writeXObjParam
|
|
875
869
|
* @param {object} obj - some object
|
|
876
870
|
* @param {any} value - some value
|
|
877
871
|
* @param {string} [key] - some key
|
|
878
872
|
* @returns {boolean}
|
|
879
873
|
* @throws {TypeError} if first param is not an object
|
|
880
|
-
* @description Tries to convert a given value to a string
|
|
881
|
-
* and writes it as a parameter into a given object.
|
|
882
874
|
*/
|
|
883
875
|
function writeXObjParam(obj, value, key) {
|
|
884
876
|
let isSucceed = false;
|
|
@@ -897,6 +889,8 @@ function writeXObjParam(obj, value, key) {
|
|
|
897
889
|
};
|
|
898
890
|
|
|
899
891
|
/**
|
|
892
|
+
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
893
|
+
* into a given object.
|
|
900
894
|
* @function writeXObjParamAsBool
|
|
901
895
|
* @param {object} obj - some object
|
|
902
896
|
* @param {any} value - some value
|
|
@@ -904,8 +898,6 @@ function writeXObjParam(obj, value, key) {
|
|
|
904
898
|
* @param {string} [key] - some key
|
|
905
899
|
* @returns {boolean}
|
|
906
900
|
* @throws {TypeError} if first param is not an object
|
|
907
|
-
* @description Tries to convert a given value to a boolean
|
|
908
|
-
* and writes it as a parameter into a given object.
|
|
909
901
|
*/
|
|
910
902
|
function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
911
903
|
let isSucceed = false;
|
|
@@ -928,6 +920,8 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
|
928
920
|
};
|
|
929
921
|
|
|
930
922
|
/**
|
|
923
|
+
* Tries to convert a given value to a number and writes it as a parameter
|
|
924
|
+
* into a given object.
|
|
931
925
|
* @function writeXObjParamAsNum
|
|
932
926
|
* @param {object} obj - some object
|
|
933
927
|
* @param {any} value - some value
|
|
@@ -935,8 +929,6 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
|
935
929
|
* @param {string} [key] - some key
|
|
936
930
|
* @returns {boolean}
|
|
937
931
|
* @throws {TypeError} if first param is not an object
|
|
938
|
-
* @description Tries to convert a given value to a number
|
|
939
|
-
* and writes it as a parameter into a given object.
|
|
940
932
|
*/
|
|
941
933
|
function writeXObjParamAsNum(obj, value, defValue, key) {
|
|
942
934
|
let isSucceed = false;
|
|
@@ -959,14 +951,14 @@ function writeXObjParamAsNum(obj, value, defValue, key) {
|
|
|
959
951
|
};
|
|
960
952
|
|
|
961
953
|
/**
|
|
954
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
955
|
+
* as a parameter into a given object.
|
|
962
956
|
* @function writeXObjParamAsIndex
|
|
963
957
|
* @param {object} obj - some object
|
|
964
958
|
* @param {any} value - some value
|
|
965
959
|
* @param {string} [key] - some key
|
|
966
960
|
* @returns {boolean}
|
|
967
961
|
* @throws {TypeError} if first param is not an object
|
|
968
|
-
* @description Tries to convert a given value into an 'index' value
|
|
969
|
-
* and writes it as a parameter into a given object.
|
|
970
962
|
*/
|
|
971
963
|
function writeXObjParamAsIndex(obj, value, key) {
|
|
972
964
|
let isSucceed = false;
|
|
@@ -989,6 +981,8 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
989
981
|
};
|
|
990
982
|
|
|
991
983
|
/**
|
|
984
|
+
* Tries to convert a given value to a string and writes it
|
|
985
|
+
* as a parameter into a given object.
|
|
992
986
|
* @function writeXObjParamEx
|
|
993
987
|
* @param {object} obj - some object
|
|
994
988
|
* @param {any} value - some value
|
|
@@ -996,8 +990,6 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
996
990
|
* @param {string} [key] - some key
|
|
997
991
|
* @returns {boolean}
|
|
998
992
|
* @throws {TypeError} if first param is not an object
|
|
999
|
-
* @description Tries to convert a given value to a string
|
|
1000
|
-
* and writes it as a parameter into a given object.
|
|
1001
993
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1002
994
|
*/
|
|
1003
995
|
function writeXObjParamEx(obj, value, opt, key) {
|
|
@@ -1035,14 +1027,13 @@ function writeXObjParamEx(obj, value, opt, key) {
|
|
|
1035
1027
|
};
|
|
1036
1028
|
|
|
1037
1029
|
/**
|
|
1030
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
1038
1031
|
* @function readXObjAttr
|
|
1039
1032
|
* @param {object} obj - some object
|
|
1040
1033
|
* @param {string} attr - some attribute
|
|
1041
1034
|
* @param {string} [key] - some key
|
|
1042
1035
|
* @returns {string}
|
|
1043
1036
|
* @throws {TypeError} if first param is not an object
|
|
1044
|
-
* @description Extracts an attribute from a given object
|
|
1045
|
-
* and returns it as string.
|
|
1046
1037
|
*/
|
|
1047
1038
|
function readXObjAttr(obj, attr, key) {
|
|
1048
1039
|
const opt = {
|
|
@@ -1061,6 +1052,7 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1061
1052
|
};
|
|
1062
1053
|
|
|
1063
1054
|
/**
|
|
1055
|
+
* Extracts an attribute from a given object and returns it as a boolean.
|
|
1064
1056
|
* @function readXObjAttrAsBool
|
|
1065
1057
|
* @param {object} obj - some object
|
|
1066
1058
|
* @param {string} attr - some attribute
|
|
@@ -1068,8 +1060,6 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1068
1060
|
* @param {string} [key] - some key
|
|
1069
1061
|
* @returns {boolean}
|
|
1070
1062
|
* @throws {TypeError} if first param is not an object
|
|
1071
|
-
* @description Extracts an attribute from a given object
|
|
1072
|
-
* and returns it as boolean.
|
|
1073
1063
|
*/
|
|
1074
1064
|
function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
1075
1065
|
let result = undefined;
|
|
@@ -1089,6 +1079,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1089
1079
|
};
|
|
1090
1080
|
|
|
1091
1081
|
/**
|
|
1082
|
+
* Extracts an attribute from a given object and returns it as a number.
|
|
1092
1083
|
* @function readXObjAttrAsNum
|
|
1093
1084
|
* @param {object} obj - some object
|
|
1094
1085
|
* @param {string} attr - some attribute
|
|
@@ -1096,8 +1087,6 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1096
1087
|
* @param {string} [key] - some key
|
|
1097
1088
|
* @returns {number}
|
|
1098
1089
|
* @throws {TypeError} if first param is not an object
|
|
1099
|
-
* @description Extracts an attribute from a given object
|
|
1100
|
-
* and returns it as number.
|
|
1101
1090
|
*/
|
|
1102
1091
|
function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
1103
1092
|
let result = undefined;
|
|
@@ -1117,6 +1106,7 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
|
1117
1106
|
};
|
|
1118
1107
|
|
|
1119
1108
|
/**
|
|
1109
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
1120
1110
|
* @function readXObjAttrEx
|
|
1121
1111
|
* @param {object} obj - some object
|
|
1122
1112
|
* @param {string} attr - some attribute
|
|
@@ -1124,8 +1114,6 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
|
1124
1114
|
* @param {string} [key] - some key
|
|
1125
1115
|
* @returns {string}
|
|
1126
1116
|
* @throws {TypeError} if first param is not an object
|
|
1127
|
-
* @description Extracts an attribute from a given object
|
|
1128
|
-
* and returns it as string.
|
|
1129
1117
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1130
1118
|
*/
|
|
1131
1119
|
function readXObjAttrEx(obj, attr, opt, key) {
|
|
@@ -1155,14 +1143,13 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
1155
1143
|
};
|
|
1156
1144
|
|
|
1157
1145
|
/**
|
|
1146
|
+
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
1158
1147
|
* @function readXObjAttrAsIndex
|
|
1159
1148
|
* @param {object} obj - some object
|
|
1160
1149
|
* @param {string} attr - some attribute
|
|
1161
1150
|
* @param {string} [key] - some key
|
|
1162
1151
|
* @returns {number}
|
|
1163
1152
|
* @throws {TypeError} if first param is not an object
|
|
1164
|
-
* @description Extracts an attribute from a given object
|
|
1165
|
-
* and returns it as 'index' value.
|
|
1166
1153
|
*/
|
|
1167
1154
|
function readXObjAttrAsIndex(obj, attr, key) {
|
|
1168
1155
|
let result = undefined;
|
|
@@ -1182,6 +1169,8 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
1182
1169
|
};
|
|
1183
1170
|
|
|
1184
1171
|
/**
|
|
1172
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
1173
|
+
* into a given object.
|
|
1185
1174
|
* @function writeXObjAttr
|
|
1186
1175
|
* @param {object} obj - some object
|
|
1187
1176
|
* @param {string} attr - some attribute
|
|
@@ -1189,8 +1178,6 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
1189
1178
|
* @param {string} [key] - some key
|
|
1190
1179
|
* @returns {boolean}
|
|
1191
1180
|
* @throws {TypeError} if first param is not an object
|
|
1192
|
-
* @description Tries to convert a given value to a string
|
|
1193
|
-
* and writes it as an attribute into a given object.
|
|
1194
1181
|
*/
|
|
1195
1182
|
function writeXObjAttr(obj, attr, value, key) {
|
|
1196
1183
|
let isSucceed = false;
|
|
@@ -1209,6 +1196,8 @@ function writeXObjAttr(obj, attr, value, key) {
|
|
|
1209
1196
|
};
|
|
1210
1197
|
|
|
1211
1198
|
/**
|
|
1199
|
+
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
1200
|
+
* into a given object.
|
|
1212
1201
|
* @function writeXObjAttrAsBool
|
|
1213
1202
|
* @param {object} obj - some object
|
|
1214
1203
|
* @param {string} attr - some attribute
|
|
@@ -1217,8 +1206,6 @@ function writeXObjAttr(obj, attr, value, key) {
|
|
|
1217
1206
|
* @param {string} [key] - some key
|
|
1218
1207
|
* @returns {boolean}
|
|
1219
1208
|
* @throws {TypeError} if first param is not an object
|
|
1220
|
-
* @description Tries to convert a given value to a boolean
|
|
1221
|
-
* and writes it as an attribute into a given object.
|
|
1222
1209
|
*/
|
|
1223
1210
|
function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
1224
1211
|
let isSucceed = false;
|
|
@@ -1241,6 +1228,8 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
|
1241
1228
|
};
|
|
1242
1229
|
|
|
1243
1230
|
/**
|
|
1231
|
+
* Tries to convert a given value to a number and writes it as an attribute
|
|
1232
|
+
* into a given object.
|
|
1244
1233
|
* @function writeXObjAttrAsNum
|
|
1245
1234
|
* @param {object} obj - some object
|
|
1246
1235
|
* @param {string} attr - some attribute
|
|
@@ -1249,8 +1238,6 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
|
1249
1238
|
* @param {string} [key] - some key
|
|
1250
1239
|
* @returns {boolean}
|
|
1251
1240
|
* @throws {TypeError} if first param is not an object
|
|
1252
|
-
* @description Tries to convert a given value to a number
|
|
1253
|
-
* and writes it as an attribute into a given object.
|
|
1254
1241
|
*/
|
|
1255
1242
|
function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
1256
1243
|
let isSucceed = false;
|
|
@@ -1273,6 +1260,8 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
|
1273
1260
|
};
|
|
1274
1261
|
|
|
1275
1262
|
/**
|
|
1263
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
1264
|
+
* as an attribute into a given object.
|
|
1276
1265
|
* @function writeXObjAttrAsIndex
|
|
1277
1266
|
* @param {object} obj - some object
|
|
1278
1267
|
* @param {string} attr - some attribute
|
|
@@ -1280,8 +1269,6 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
|
1280
1269
|
* @param {string} [key] - some key
|
|
1281
1270
|
* @returns {boolean}
|
|
1282
1271
|
* @throws {TypeError} if first param is not an object
|
|
1283
|
-
* @description Tries to convert a given value into an 'index' value
|
|
1284
|
-
* and writes it as an attribute into a given object.
|
|
1285
1272
|
*/
|
|
1286
1273
|
function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
1287
1274
|
let isSucceed = false;
|
|
@@ -1304,6 +1291,8 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1304
1291
|
};
|
|
1305
1292
|
|
|
1306
1293
|
/**
|
|
1294
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
1295
|
+
* into a given object.
|
|
1307
1296
|
* @function writeXObjAttrEx
|
|
1308
1297
|
* @param {object} obj - some object
|
|
1309
1298
|
* @param {string} attr - some attribute
|
|
@@ -1312,8 +1301,6 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1312
1301
|
* @param {string} [key] - some key
|
|
1313
1302
|
* @returns {boolean}
|
|
1314
1303
|
* @throws {TypeError} if first param is not an object
|
|
1315
|
-
* @description Tries to convert a given value to a string
|
|
1316
|
-
* and writes it as an attribute into a given object.
|
|
1317
1304
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1318
1305
|
*/
|
|
1319
1306
|
function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
@@ -1351,13 +1338,13 @@ function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
|
1351
1338
|
};
|
|
1352
1339
|
|
|
1353
1340
|
/**
|
|
1341
|
+
* Inserts an elements into a given object.
|
|
1354
1342
|
* @function insertXObjElements
|
|
1355
|
-
* @param {object} obj
|
|
1356
|
-
* @param {...string} name
|
|
1343
|
+
* @param {object} obj - some object
|
|
1344
|
+
* @param {...string} name - some child element name
|
|
1357
1345
|
* @param {OPT_inselops_L} [opt]
|
|
1358
1346
|
* @returns {number}
|
|
1359
1347
|
* @throws {TypeError} if first param is not an object
|
|
1360
|
-
* @description Inserts an elements into a given object.
|
|
1361
1348
|
*/
|
|
1362
1349
|
function insertXObjElements(obj, ...args) {
|
|
1363
1350
|
if (!isPlainObject(obj)) {
|
|
@@ -1379,19 +1366,20 @@ function insertXObjElements(obj, ...args) {
|
|
|
1379
1366
|
};
|
|
1380
1367
|
|
|
1381
1368
|
/**
|
|
1369
|
+
* An options for an element insertion ops
|
|
1382
1370
|
* @typedef {Object} OPT_inselops_S
|
|
1383
1371
|
* @property {boolean} [force=false]
|
|
1384
1372
|
* @property {boolean} [ripOldies=false]
|
|
1385
1373
|
*/
|
|
1386
1374
|
|
|
1387
1375
|
/**
|
|
1376
|
+
* Inserts a list elements into a given object.
|
|
1388
1377
|
* @function insertXObjEList
|
|
1389
1378
|
* @param {object} obj - some object
|
|
1390
|
-
* @param {string} name - some child element
|
|
1379
|
+
* @param {string} name - some child element name
|
|
1391
1380
|
* @param {OPT_inselops_S} [opt] - options
|
|
1392
1381
|
* @returns {?(object|object[])}
|
|
1393
1382
|
* @throws {TypeError} if first param is not an object
|
|
1394
|
-
* @description Inserts a list elements into a given object.
|
|
1395
1383
|
*/
|
|
1396
1384
|
function insertXObjEList(...args) {
|
|
1397
1385
|
let item = null;
|
|
@@ -1412,15 +1400,15 @@ function insertXObjEList(...args) {
|
|
|
1412
1400
|
};
|
|
1413
1401
|
|
|
1414
1402
|
/**
|
|
1403
|
+
* Inserts a list elements into a given object.
|
|
1415
1404
|
* @since 0.2.0
|
|
1416
1405
|
* @function insertXObjEListEx
|
|
1417
1406
|
* @param {object} obj - some object
|
|
1418
|
-
* @param {string} name - some child element
|
|
1407
|
+
* @param {string} name - some child element name
|
|
1419
1408
|
* @param {OPT_inselops_S} [opt] - options
|
|
1420
1409
|
* @returns {RVAL_emodif}
|
|
1421
1410
|
* @throws {TypeError} if first param is not an object
|
|
1422
1411
|
* @throws {TypeError} if second param is empty string or not a string at all
|
|
1423
|
-
* @description Inserts a list elements into a given object.
|
|
1424
1412
|
*/
|
|
1425
1413
|
function insertXObjEListEx(obj, name, opt) {
|
|
1426
1414
|
if (!isPlainObject(obj)) {
|
|
@@ -1464,13 +1452,13 @@ function insertXObjEListEx(obj, name, opt) {
|
|
|
1464
1452
|
};
|
|
1465
1453
|
|
|
1466
1454
|
/**
|
|
1455
|
+
* Inserts a chain of an elements into a given object.
|
|
1467
1456
|
* @function insertXObjEChain
|
|
1468
1457
|
* @param {object} obj - some object
|
|
1469
|
-
* @param {...string} name - some child element
|
|
1458
|
+
* @param {...string} name - some child element name
|
|
1470
1459
|
* @param {object} [opt] - options
|
|
1471
1460
|
* @returns {?any}
|
|
1472
1461
|
* @throws {TypeError} if first param is not an object
|
|
1473
|
-
* @description Inserts a chain of an elements into a given object.
|
|
1474
1462
|
*/
|
|
1475
1463
|
function insertXObjEChain(obj, ...args) {
|
|
1476
1464
|
if (!isPlainObject(obj)) {
|
|
@@ -1561,8 +1549,3 @@ module.exports.genXObjENameDescr = genXObjENameDescr;
|
|
|
1561
1549
|
module.exports.insertXObjElements = insertXObjElements;
|
|
1562
1550
|
/* experimental */
|
|
1563
1551
|
module.exports.insertXObjEChain = insertXObjEChain;
|
|
1564
|
-
|
|
1565
|
-
/** @deprecated */
|
|
1566
|
-
module.exports.readXObjParamAsStr = readXObjParamEx;
|
|
1567
|
-
/** @deprecated */
|
|
1568
|
-
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,10 +18,6 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "jest",
|
|
21
|
-
"test-xobj": "jest xObj",
|
|
22
|
-
"test-xobj:c1": "jest xobj-param",
|
|
23
|
-
"test-xobj:c2": "jest xobj-attr",
|
|
24
|
-
"test-xobj:c3": "jest xobj-elements",
|
|
25
21
|
"build-doc-md": "jsdoc2md",
|
|
26
22
|
"build-doc-html": "jsdoc"
|
|
27
23
|
},
|
|
@@ -33,7 +29,7 @@
|
|
|
33
29
|
"@ygracs/bsfoc-lib-js": "^0.2.3"
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
|
-
"jest": "^
|
|
32
|
+
"jest": "^30.0.4",
|
|
37
33
|
"jsdoc-to-markdown": "^9.1.1",
|
|
38
34
|
"minimist": "^1.2.8"
|
|
39
35
|
}
|