@ygracs/xobj-lib-js 0.2.9-b → 0.2.9-b.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/doc/xObj.md +99 -6
- package/index.d.ts +1 -0
- package/lib/xObj-defs.d.ts +4 -0
- package/lib/xObj-defs.js +10 -19
- package/lib/xObj-errors.js +2 -1
- package/lib/xObj-lib.d.ts +24 -18
- package/lib/xObj-lib.js +133 -93
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,11 @@ Release version.
|
|
|
5
5
|
> - update `xObj.md`;
|
|
6
6
|
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
|
|
7
7
|
> - change behavior for function: `evalKeyName` on handling `opt` parameter;
|
|
8
|
+
> - change behavior for function: `writeXObjParamRaw`, `writeXObjAttrRaw`;
|
|
9
|
+
> - improve behavior for function: `writeXObjParam`, `writeXObjParamEx`, `writeXObjAttr`, `writeXObjAttrEx`;
|
|
10
|
+
> - add a new function: `clearXObjNode`;
|
|
8
11
|
> - add a new `EvalKeyNameError` class;
|
|
12
|
+
> - add new `compact`-property for `TXmlContentParseOptions`;
|
|
9
13
|
> - some fixes.
|
|
10
14
|
|
|
11
15
|
#### *v0.2.4*
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.48|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|
|
|
3
|
+
>|date:|2026-02-22|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -10,6 +10,20 @@ This paper describes a functions provided by `xObj.js` module.
|
|
|
10
10
|
|
|
11
11
|
## Content
|
|
12
12
|
|
|
13
|
+
- Base types
|
|
14
|
+
- <a href="#typedef+xml2jsParseOptions">xml2jsParseOptions</a>
|
|
15
|
+
- <a href="#typedef+js2xmlParseOptions">js2xmlParseOptions</a>
|
|
16
|
+
|
|
17
|
+
- Classes
|
|
18
|
+
- <a href="#TXmlContentParseOptions">TXmlContentParseOptions</a>
|
|
19
|
+
- <a href="#EvalKeyNameError">EvalKeyNameError</a>
|
|
20
|
+
|
|
21
|
+
- Functions
|
|
22
|
+
- <a href="#func+attribute+read">read element attributes</a>
|
|
23
|
+
- <a href="#func+attribute+write">write element attributes</a>
|
|
24
|
+
- <a href="#func+param+read">read element parameter</a>
|
|
25
|
+
- <a href="#func+param+write">write element parameter</a>
|
|
26
|
+
|
|
13
27
|
### Base type definitions
|
|
14
28
|
|
|
15
29
|
This section contains some definitions for a general types of the objects (e.g. options set) that frequently used in a function descriptions.
|
|
@@ -116,10 +130,8 @@ The settings listed in the table below:
|
|
|
116
130
|
| `elementsKey` | `string` | `items` ||
|
|
117
131
|
| `ignoreDeclaration` | `boolean` | `false` ||
|
|
118
132
|
| `ignoreDocType` | `boolean` | `false` ||
|
|
119
|
-
| `ignoreInstractions` | `boolean` | `false` | \<*deprecated*> (*use `ignoreInstraction` instead*) |
|
|
120
133
|
| `ignoreInstraction` | `boolean` | `false` ||
|
|
121
134
|
| `ignoreText` | `boolean` | `false` ||
|
|
122
|
-
| `ignoreComments` | `boolean` | `false` | \<*deprecated*> (*use `ignoreComment` instead*) |
|
|
123
135
|
| `ignoreComment` | `boolean` | `false` ||
|
|
124
136
|
| `ignoreCData` | `boolean` | `false` ||
|
|
125
137
|
| `fullTagEmptyElement` | `boolean` | `true` ||
|
|
@@ -127,6 +139,7 @@ The settings listed in the table below:
|
|
|
127
139
|
| `trim` | `boolean` | `true` ||
|
|
128
140
|
| `spaces` | `number` | `2` ||
|
|
129
141
|
|
|
142
|
+
<a name="func+param+read"></a>
|
|
130
143
|
### Base functions for read an object parameter value
|
|
131
144
|
|
|
132
145
|
> Note:
|
|
@@ -251,6 +264,7 @@ The function throws a `TypeError` exception in case:
|
|
|
251
264
|
- code: `ERR_XOBJ_NPOBJ`
|
|
252
265
|
+ if `object` parameter is not an `Object` instance.
|
|
253
266
|
|
|
267
|
+
<a name="func+param+write"></a>
|
|
254
268
|
### Base functions for write an object parameter value
|
|
255
269
|
|
|
256
270
|
> Note:
|
|
@@ -376,6 +390,7 @@ The function throws a `TypeError` exception in case:
|
|
|
376
390
|
- code: `ERR_XOBJ_NPOBJ`
|
|
377
391
|
+ if `object` parameter is not an `Object` instance.
|
|
378
392
|
|
|
393
|
+
<a name="func+attribute+read"></a>
|
|
379
394
|
### Base functions for read an object attributes value
|
|
380
395
|
|
|
381
396
|
> Note:
|
|
@@ -505,6 +520,7 @@ The function throws a `TypeError` exception in case:
|
|
|
505
520
|
- code: `ERR_XOBJ_NPOBJ`
|
|
506
521
|
+ if `object` parameter is not an `Object` instance.
|
|
507
522
|
|
|
523
|
+
<a name="func+attribute+write"></a>
|
|
508
524
|
### Base functions for write an object attributes value
|
|
509
525
|
|
|
510
526
|
> Note:
|
|
@@ -1040,6 +1056,26 @@ The function throws a `TypeError` exception in case:
|
|
|
1040
1056
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1041
1057
|
+ id `value` parameter given and is not a type of a `string`.
|
|
1042
1058
|
|
|
1059
|
+
<a name="clearXObjNode"></a>
|
|
1060
|
+
#### **clearXObjNode(node)** => `boolean`
|
|
1061
|
+
|
|
1062
|
+
> since: \[v0.2.x]
|
|
1063
|
+
|
|
1064
|
+
This function tries to clean a given node.
|
|
1065
|
+
|
|
1066
|
+
##### ***parameters***
|
|
1067
|
+
|
|
1068
|
+
| parameter name | value type | default value | description |
|
|
1069
|
+
|:---|---|---:|:---|
|
|
1070
|
+
| `node` | `object` or `object[]` | --- | some node |
|
|
1071
|
+
|
|
1072
|
+
##### ***exceptions***
|
|
1073
|
+
|
|
1074
|
+
The function throws a `TypeError` exception in case:
|
|
1075
|
+
|
|
1076
|
+
- code: `ERR_XOBJ_NPOBJ`
|
|
1077
|
+
+ if `node` parameter is not an `Object` or `Array` instance;
|
|
1078
|
+
|
|
1043
1079
|
### Other special functions
|
|
1044
1080
|
|
|
1045
1081
|
<a name="evalXObjEName"></a>
|
|
@@ -1214,7 +1250,7 @@ The class constructor receives an arguments listed below:
|
|
|
1214
1250
|
|
|
1215
1251
|
| parameter name | value type | default value | description |
|
|
1216
1252
|
|:---|---|---:|:---|
|
|
1217
|
-
| `options` | `object` | --- |
|
|
1253
|
+
| `options` | `object` | --- | some initial options settings |
|
|
1218
1254
|
|
|
1219
1255
|
##### class properties
|
|
1220
1256
|
|
|
@@ -1225,6 +1261,15 @@ The class constructor receives an arguments listed below:
|
|
|
1225
1261
|
|---|---|:---|
|
|
1226
1262
|
| `object` | yes | contains a current options |
|
|
1227
1263
|
|
|
1264
|
+
<a name="TXmlContentParseOptions+compact"></a>
|
|
1265
|
+
###### **compact**
|
|
1266
|
+
|
|
1267
|
+
> since: \[v0.2.x]
|
|
1268
|
+
|
|
1269
|
+
| property type | read only | description |
|
|
1270
|
+
|---|---|:---|
|
|
1271
|
+
| `boolean` | yes | returns a current value for a `compact`-options |
|
|
1272
|
+
|
|
1228
1273
|
<a name="TXmlContentParseOptions+xml2js"></a>
|
|
1229
1274
|
###### **xml2js**
|
|
1230
1275
|
|
|
@@ -1232,6 +1277,8 @@ The class constructor receives an arguments listed below:
|
|
|
1232
1277
|
|---|---|:---|
|
|
1233
1278
|
| `xml2jsParseOptions` | yes | returns an options for an XML-to-JS converter |
|
|
1234
1279
|
|
|
1280
|
+
for more details see [`xml2jsParseOptions`](#typedef+xml2jsParseOptions).
|
|
1281
|
+
|
|
1235
1282
|
<a name="TXmlContentParseOptions+js2xml"></a>
|
|
1236
1283
|
###### **js2xml**
|
|
1237
1284
|
|
|
@@ -1239,12 +1286,14 @@ The class constructor receives an arguments listed below:
|
|
|
1239
1286
|
|---|---|:---|
|
|
1240
1287
|
| `js2xmlParseOptions` | yes | returns an options for a JS-to-XML converter |
|
|
1241
1288
|
|
|
1289
|
+
for more details see [`js2xmlParseOptions`](#typedef+js2xmlParseOptions).
|
|
1290
|
+
|
|
1242
1291
|
<a name="TXmlContentParseOptions+reservedKeys"></a>
|
|
1243
1292
|
###### **reservedKeys**
|
|
1244
1293
|
|
|
1245
1294
|
| property type | read only | description |
|
|
1246
1295
|
|---|---|:---|
|
|
1247
|
-
| `Set<string>` | yes | returns a set of the reserved key words those must not be used as an element names
|
|
1296
|
+
| `Set<string>` | yes | returns a set of the reserved key words those must not be used as an element names |
|
|
1248
1297
|
|
|
1249
1298
|
##### class methods (*static*)
|
|
1250
1299
|
|
|
@@ -1252,3 +1301,47 @@ The class constructor receives an arguments listed below:
|
|
|
1252
1301
|
###### **createNewOptionsSet(obj)** => `object`
|
|
1253
1302
|
|
|
1254
1303
|
This method transforms a given object to a set of accepted parser options.
|
|
1304
|
+
|
|
1305
|
+
| parameter name | value type | default value | description |
|
|
1306
|
+
|:---|---|---:|:---|
|
|
1307
|
+
| `obj` | `object` | --- | some initial options settings |
|
|
1308
|
+
|
|
1309
|
+
### Special class
|
|
1310
|
+
|
|
1311
|
+
<a name="EvalKeyNameError"></a>
|
|
1312
|
+
#### **EvalKeyNameError**
|
|
1313
|
+
|
|
1314
|
+
> since: \[v0.2.x]
|
|
1315
|
+
|
|
1316
|
+
This class extends a functionality of a `TypeError`-object to provide more accurate information when an error happened through a key evaluation.
|
|
1317
|
+
|
|
1318
|
+
> NOTE: the class is in a `beta`-stage.
|
|
1319
|
+
|
|
1320
|
+
#### class constructor
|
|
1321
|
+
|
|
1322
|
+
The class constructor creates a new instance of the class.
|
|
1323
|
+
|
|
1324
|
+
##### constructor parameters
|
|
1325
|
+
|
|
1326
|
+
The class constructor receives an arguments listed below:
|
|
1327
|
+
|
|
1328
|
+
| parameter name | value type | default value | description |
|
|
1329
|
+
|:---|---|---:|:---|
|
|
1330
|
+
| `msg` | `string` | --- | some user error message |
|
|
1331
|
+
| `options` | `any` | --- | user options |
|
|
1332
|
+
|
|
1333
|
+
#### class properties
|
|
1334
|
+
|
|
1335
|
+
<a name="EvalKeyNameError+name"></a>
|
|
1336
|
+
##### **name**
|
|
1337
|
+
|
|
1338
|
+
| property type | read only | description |
|
|
1339
|
+
|---|---|:---|
|
|
1340
|
+
| `string` | yes | represents the name for the type of error |
|
|
1341
|
+
|
|
1342
|
+
<a name="EvalKeyNameError+code"></a>
|
|
1343
|
+
##### **code**
|
|
1344
|
+
|
|
1345
|
+
| property type | read only | description |
|
|
1346
|
+
|---|---|:---|
|
|
1347
|
+
| `string` | yes | represents an error code |
|
package/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare const _exports: {
|
|
|
41
41
|
genXObjENameDescr: typeof import("./lib/xObj-lib").genXObjENameDescr;
|
|
42
42
|
insertXObjElements: typeof import("./lib/xObj-lib").insertXObjElements;
|
|
43
43
|
insertXObjEChain: typeof import("./lib/xObj-lib").insertXObjEChain;
|
|
44
|
+
clearXObjNode: typeof import("./lib/xObj-lib").clearXObjNode;
|
|
44
45
|
|
|
45
46
|
TXmlContentParseOptions: typeof TXmlContentParseOptions; // [?] class declaration
|
|
46
47
|
DEF_XML_PARSE_OPTIONS: typeof DEF_XML_PARSE_OPTIONS;
|
package/lib/xObj-defs.d.ts
CHANGED
|
@@ -96,6 +96,10 @@ export class TXmlContentParseOptions {
|
|
|
96
96
|
* Contains a set of a current settings
|
|
97
97
|
*/
|
|
98
98
|
get settings(): OPT_parserOptions;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a value of `compact` option
|
|
101
|
+
*/
|
|
102
|
+
get compact(): boolean;
|
|
99
103
|
/**
|
|
100
104
|
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
101
105
|
*/
|
package/lib/xObj-defs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.070-20260221]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -10,10 +10,6 @@ const {
|
|
|
10
10
|
|
|
11
11
|
// === module main block ===
|
|
12
12
|
|
|
13
|
-
/***
|
|
14
|
-
* (* constant definitions *)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
13
|
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
18
14
|
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
19
15
|
const XOBJ_DEF_DECL_TNAME = '__decl';
|
|
@@ -25,8 +21,6 @@ const XOBJ_DEF_TNAMES = {
|
|
|
25
21
|
XOBJ_DEF_DECL_TNAME,
|
|
26
22
|
XOBJ_DEF_CDATA_TNAME,
|
|
27
23
|
};
|
|
28
|
-
//module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
29
|
-
//module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
30
24
|
module.exports.XOBJ_DEF_TNAMES = XOBJ_DEF_TNAMES;
|
|
31
25
|
|
|
32
26
|
/**
|
|
@@ -68,12 +62,8 @@ const DEF_XML_PARSE_OPTIONS = {
|
|
|
68
62
|
elementsKey: 'items',
|
|
69
63
|
ignoreDeclaration: false,
|
|
70
64
|
ignoreDocType: false,
|
|
71
|
-
/** @deprecated */
|
|
72
|
-
ignoreInstractions: false,
|
|
73
65
|
ignoreInstraction: false,
|
|
74
66
|
ignoreText: false,
|
|
75
|
-
/** @deprecated */
|
|
76
|
-
ignoreComments: false,
|
|
77
67
|
ignoreComment: false,
|
|
78
68
|
ignoreCData: false,
|
|
79
69
|
fullTagEmptyElement: true,
|
|
@@ -83,14 +73,6 @@ const DEF_XML_PARSE_OPTIONS = {
|
|
|
83
73
|
};
|
|
84
74
|
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
85
75
|
|
|
86
|
-
/***
|
|
87
|
-
* (* function definitions *)
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
/***
|
|
91
|
-
* (* class definitions *)
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
76
|
/**
|
|
95
77
|
* A parser options to convert an 'XML'-string into a 'JS'-object
|
|
96
78
|
* @typedef {Object} xml2jsParseOptions
|
|
@@ -161,6 +143,15 @@ class TXmlContentParseOptions {
|
|
|
161
143
|
return this.#_options;
|
|
162
144
|
}
|
|
163
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Returns a value of `compact` option
|
|
148
|
+
* @since 0.2.x
|
|
149
|
+
* @type {boolean}
|
|
150
|
+
*/
|
|
151
|
+
get compact() {
|
|
152
|
+
return this.#_options.compact ? true : false;
|
|
153
|
+
}
|
|
154
|
+
|
|
164
155
|
/**
|
|
165
156
|
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
166
157
|
* @type {xml2jsParseOptions}
|
package/lib/xObj-errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.004-20260221]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -41,6 +41,7 @@ const XOBJ_ECODE_TABLE = {
|
|
|
41
41
|
module.exports.XOBJ_ECODE_TABLE = XOBJ_ECODE_TABLE;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
+
* @since 0.2.x
|
|
44
45
|
* @augments TypeError
|
|
45
46
|
* @classdesc Extends a base `TypeError` object to provide some information
|
|
46
47
|
* on the errors thrown when a key name evaluation failed
|
package/lib/xObj-lib.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EvalKeyNameError } from "./xObj-errors";
|
|
1
2
|
/**
|
|
2
3
|
* A result of a value check ops.
|
|
3
4
|
*/
|
|
@@ -109,10 +110,15 @@ export type OPT_inselops_S = {
|
|
|
109
110
|
ripOldies?: boolean;
|
|
110
111
|
};
|
|
111
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Clears a given node
|
|
115
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
116
|
+
*/
|
|
117
|
+
export function clearXObjNode(node: object | object[]): boolean;
|
|
112
118
|
/**
|
|
113
119
|
* Extracts a parameter 'AS IS' from a given object.
|
|
114
120
|
* @throws {TypeError} if first param is not an object
|
|
115
|
-
* @throws {
|
|
121
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
116
122
|
*/
|
|
117
123
|
export function readXObjParamRaw(obj: object, key?: string): any;
|
|
118
124
|
/**
|
|
@@ -144,7 +150,7 @@ export function readXObjParamAsIndex(obj: object, key?: string): number;
|
|
|
144
150
|
/**
|
|
145
151
|
* Writes a parameter 'AS IS' into a given object.
|
|
146
152
|
* @throws {TypeError} if first param is not an object
|
|
147
|
-
* @throws {
|
|
153
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
148
154
|
*/
|
|
149
155
|
export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
|
|
150
156
|
/**
|
|
@@ -181,7 +187,7 @@ export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: st
|
|
|
181
187
|
/**
|
|
182
188
|
* Extracts an attribute 'AS IS' from a given object.
|
|
183
189
|
* @throws {TypeError} if first param is not an object
|
|
184
|
-
* @throws {
|
|
190
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
185
191
|
*/
|
|
186
192
|
export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
|
|
187
193
|
/**
|
|
@@ -214,7 +220,7 @@ export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): nu
|
|
|
214
220
|
/**
|
|
215
221
|
* Writes a parameter into a given object.
|
|
216
222
|
* @throws {TypeError} if first param is not an object
|
|
217
|
-
* @throws {
|
|
223
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
218
224
|
*/
|
|
219
225
|
export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
|
|
220
226
|
/**
|
|
@@ -256,67 +262,68 @@ export function getXObjAttributes(obj: object, key?: string): object | null;
|
|
|
256
262
|
/**
|
|
257
263
|
* Checks whether an attribute is exists.
|
|
258
264
|
* @throws {TypeError} if first param is not an object
|
|
265
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
259
266
|
*/
|
|
260
267
|
export function checkXObjAttribute(obj: object, attr?: string, key?: string): boolean;
|
|
261
268
|
/**
|
|
262
269
|
* Deletes an attribute addressed by a given name.
|
|
263
270
|
* @throws {TypeError} if first param is not an object
|
|
271
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
264
272
|
*/
|
|
265
273
|
export function deleteXObjAttribute(obj: object, attr?: string, key?: string): boolean;
|
|
266
274
|
/**
|
|
267
275
|
* Renames an attribute addressed by a given name.
|
|
268
276
|
* @since 0.2.0
|
|
269
277
|
* @throws {TypeError} if first param is not an object
|
|
270
|
-
* @throws {
|
|
271
|
-
* @throws {
|
|
278
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
279
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
280
|
+
* @throws {EvalKeyNameError} if forth param is not valid identifier
|
|
272
281
|
*/
|
|
273
282
|
export function renameXObjAttribute(obj: object, attr?: string, value?: string, key?: string): boolean;
|
|
274
283
|
/**
|
|
275
284
|
* Extracts an element from a given object by its key.
|
|
276
285
|
* @throws {TypeError} if first param is not an object
|
|
277
|
-
* @throws {
|
|
286
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
278
287
|
*/
|
|
279
288
|
export function getXObjElement(obj: object, name: string): any | null;
|
|
280
289
|
/**
|
|
281
290
|
* Adds an element addressed by its key to a given object.
|
|
282
291
|
* @throws {TypeError} if first param is not an object
|
|
283
|
-
* @throws {
|
|
292
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
284
293
|
*/
|
|
285
294
|
export function addXObjElement(obj: object, name: string): RVAL_emodif;
|
|
286
295
|
/**
|
|
287
296
|
* Inserts an element addressed by its key into a given object.
|
|
288
297
|
* @throws {TypeError} if first param is not an object
|
|
289
|
-
* @see insertXObjElementEx
|
|
298
|
+
* @see {@link insertXObjElementEx} for param details
|
|
290
299
|
*/
|
|
291
300
|
export function insertXObjElement(...args: insertXObjElementParams): object | null;
|
|
292
301
|
type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
|
|
293
|
-
//export function insertXObjElement(...args: [obj: object, name: string, opt?: OPT_inselops_L]): object | null;
|
|
294
302
|
/**
|
|
295
303
|
* Inserts an element addressed by its key into a given object.
|
|
296
304
|
* @since 0.2.0
|
|
297
305
|
* @throws {TypeError} if first param is not an object
|
|
298
|
-
* @throws {
|
|
306
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
299
307
|
*/
|
|
300
308
|
export function insertXObjElementEx(obj: object, name: string, opt?: OPT_inselops_L): RVAL_emodif;
|
|
301
309
|
/**
|
|
302
310
|
* Deletes an element addressed by its key from a given object.
|
|
303
311
|
* @throws {TypeError} if first param is not an object
|
|
304
|
-
* @see deleteXObjElementEx
|
|
312
|
+
* @see {@link deleteXObjElementEx} for param details
|
|
305
313
|
*/
|
|
306
314
|
export function deleteXObjElement(...args: deleteXObjElementParams): boolean;
|
|
307
315
|
type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
|
|
308
|
-
//export function deleteXObjElement(...args: [obj: object, name: string]): boolean;
|
|
309
316
|
/**
|
|
310
317
|
* Deletes an element addressed by its key from a given object.
|
|
311
318
|
* @throws {TypeError} if first param is not an object
|
|
312
|
-
* @throws {
|
|
319
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
313
320
|
*/
|
|
314
321
|
export function deleteXObjElementEx(obj: object, name: string): RVAL_emodif;
|
|
315
322
|
/**
|
|
316
323
|
* Renames an element addressed by its key.
|
|
317
324
|
* @throws {TypeError} if first param is not an object
|
|
318
|
-
* @throws {
|
|
319
|
-
* @throws {
|
|
325
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
326
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
320
327
|
*/
|
|
321
328
|
export function renameXObjElement(obj: object, name?: string, value?: string): boolean;
|
|
322
329
|
/**
|
|
@@ -330,12 +337,11 @@ export function evalXObjEName(value: any): null | number | string;
|
|
|
330
337
|
*/
|
|
331
338
|
export function insertXObjEList(...args: insertXObjEListParams): object | object[] | null;
|
|
332
339
|
type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
|
|
333
|
-
//export function insertXObjEList(...args: [obj: object, name: string, opt?: OPT_inselops_S]): object | object[] | null;
|
|
334
340
|
/**
|
|
335
341
|
* Inserts a list elements into a given object.
|
|
336
342
|
* @since 0.2.0
|
|
337
343
|
* @throws {TypeError} if first param is not an object
|
|
338
|
-
* @throws {
|
|
344
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
339
345
|
*/
|
|
340
346
|
export function insertXObjEListEx(obj: object, name: string, opt?: OPT_inselops_S): RVAL_emodif;
|
|
341
347
|
/**
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.127-20260222]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -8,6 +8,8 @@ const {
|
|
|
8
8
|
isNullOrUndef,
|
|
9
9
|
isInteger,
|
|
10
10
|
isArray, isObject, isPlainObject,
|
|
11
|
+
// * import types definitions *
|
|
12
|
+
OPT_valtostr,
|
|
11
13
|
} = require('@ygracs/bsfoc-lib-js');
|
|
12
14
|
|
|
13
15
|
const {
|
|
@@ -235,7 +237,7 @@ function genXObjENameDescr(value) {
|
|
|
235
237
|
* @param {string} name - some child element
|
|
236
238
|
* @returns {?any}
|
|
237
239
|
* @throws {TypeError} if first param is not an object
|
|
238
|
-
* @throws {
|
|
240
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
239
241
|
*/
|
|
240
242
|
function getXObjElement(obj, name) {
|
|
241
243
|
if (!isPlainObject(obj)) {
|
|
@@ -293,7 +295,7 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
|
|
|
293
295
|
* @param {string} name - some child element
|
|
294
296
|
* @returns {RVAL_emodif}
|
|
295
297
|
* @throws {TypeError} if first param is not an object
|
|
296
|
-
* @throws {
|
|
298
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
297
299
|
*/
|
|
298
300
|
function addXObjElement(obj, name) {
|
|
299
301
|
if (!isPlainObject(obj)) {
|
|
@@ -346,7 +348,7 @@ function addXObjElement(obj, name) {
|
|
|
346
348
|
* @param {OPT_inselops_L} [opt] - options
|
|
347
349
|
* @returns {?object}
|
|
348
350
|
* @throws {TypeError} if first param is not an object
|
|
349
|
-
* @see insertXObjElementEx
|
|
351
|
+
* @see {@link insertXObjElementEx} for param details
|
|
350
352
|
*/
|
|
351
353
|
function insertXObjElement(...args) {
|
|
352
354
|
let item = null;
|
|
@@ -375,7 +377,7 @@ function insertXObjElement(...args) {
|
|
|
375
377
|
* @param {OPT_inselops_L} [opt] - options
|
|
376
378
|
* @returns {RVAL_emodif}
|
|
377
379
|
* @throws {TypeError} if first param is not an object
|
|
378
|
-
* @throws {
|
|
380
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
379
381
|
*/
|
|
380
382
|
function insertXObjElementEx(obj, name, opt) {
|
|
381
383
|
if (!isPlainObject(obj)) {
|
|
@@ -426,7 +428,7 @@ function insertXObjElementEx(obj, name, opt) {
|
|
|
426
428
|
* @param {string} name - some child element
|
|
427
429
|
* @returns {boolean}
|
|
428
430
|
* @throws {TypeError} if first param is not an object
|
|
429
|
-
* @see deleteXObjElementEx
|
|
431
|
+
* @see {@link deleteXObjElementEx} for param details
|
|
430
432
|
*/
|
|
431
433
|
function deleteXObjElement(...args) {
|
|
432
434
|
let isSucceed = false;
|
|
@@ -453,7 +455,7 @@ function deleteXObjElement(...args) {
|
|
|
453
455
|
* @param {string} name - some child element
|
|
454
456
|
* @returns {RVAL_emodif}
|
|
455
457
|
* @throws {TypeError} if first param is not an object
|
|
456
|
-
* @throws {
|
|
458
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
457
459
|
*/
|
|
458
460
|
function deleteXObjElementEx(obj, name) {
|
|
459
461
|
if (!isPlainObject(obj)) {
|
|
@@ -486,8 +488,8 @@ function deleteXObjElementEx(obj, name) {
|
|
|
486
488
|
* @param {string} value - new element ID
|
|
487
489
|
* @returns {boolean}
|
|
488
490
|
* @throws {TypeError} if first param is not an object
|
|
489
|
-
* @throws {
|
|
490
|
-
* @throws {
|
|
491
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
492
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
491
493
|
*/
|
|
492
494
|
function renameXObjElement(obj, name = '', value = '') {
|
|
493
495
|
if (!isPlainObject(obj)) {
|
|
@@ -531,6 +533,7 @@ function renameXObjElement(obj, name = '', value = '') {
|
|
|
531
533
|
* @param {string} [key] - some key
|
|
532
534
|
* @returns {boolean}
|
|
533
535
|
* @throws {TypeError} if first param is not an object
|
|
536
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
534
537
|
*/
|
|
535
538
|
function checkXObjAttribute(obj, attr = '', key) {
|
|
536
539
|
let _obj = null;
|
|
@@ -558,6 +561,7 @@ function checkXObjAttribute(obj, attr = '', key) {
|
|
|
558
561
|
* @param {string} [key] - some key
|
|
559
562
|
* @returns {boolean}
|
|
560
563
|
* @throws {TypeError} if first param is not an object
|
|
564
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
561
565
|
*/
|
|
562
566
|
function deleteXObjAttribute(obj, attr = '', key) {
|
|
563
567
|
let _obj = null;
|
|
@@ -591,8 +595,9 @@ function deleteXObjAttribute(obj, attr = '', key) {
|
|
|
591
595
|
* @param {string} [key] - some key
|
|
592
596
|
* @returns {boolean}
|
|
593
597
|
* @throws {TypeError} if first param is not an object
|
|
594
|
-
* @throws {
|
|
595
|
-
* @throws {
|
|
598
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
599
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
600
|
+
* @throws {EvalKeyNameError} if forth param is not valid identifier
|
|
596
601
|
*/
|
|
597
602
|
function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNAME) {
|
|
598
603
|
if (!isPlainObject(obj)) {
|
|
@@ -602,37 +607,38 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
602
607
|
);
|
|
603
608
|
};
|
|
604
609
|
const opt = false;
|
|
605
|
-
|
|
606
|
-
if (
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
const {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
obj[_key] = Object.fromEntries(_obj);
|
|
610
|
+
const { isSucceed, value: _key } = evalKeyName(key, opt);
|
|
611
|
+
if (isSucceed) {
|
|
612
|
+
let isSucceed = false;
|
|
613
|
+
if (_key !== '') {
|
|
614
|
+
let _obj = obj[_key];
|
|
615
|
+
if (isPlainObject(_obj)) {
|
|
616
|
+
const { isSucceed: isAcceptON, value: oname } = evalKeyName(attr, opt);
|
|
617
|
+
if (!isAcceptON) {
|
|
618
|
+
const { code, msg } = oname;
|
|
619
|
+
throw new EvalKeyNameError(msg, { code });
|
|
620
|
+
};
|
|
621
|
+
const { isSucceed: isAcceptNN, value: nname } = evalKeyName(value, opt);
|
|
622
|
+
if (!isAcceptNN) {
|
|
623
|
+
const { code, msg } = nname;
|
|
624
|
+
throw new EvalKeyNameError(msg, { code });
|
|
625
|
+
};
|
|
626
|
+
if (oname !== '' && oname in _obj && nname !== '') {
|
|
627
|
+
if (oname !== nname) {
|
|
628
|
+
_obj = Object.entries(_obj);
|
|
629
|
+
const index = _obj.findIndex((item) => item[0] === oname);
|
|
630
|
+
_obj[index][0] = nname;
|
|
631
|
+
obj[_key] = Object.fromEntries(_obj);
|
|
632
|
+
};
|
|
633
|
+
isSucceed = true;
|
|
630
634
|
};
|
|
631
|
-
isSucceed = true;
|
|
632
635
|
};
|
|
633
636
|
};
|
|
637
|
+
return isSucceed;
|
|
638
|
+
} else {
|
|
639
|
+
const { code, msg } = _key;
|
|
640
|
+
throw new EvalKeyNameError(msg, { code });
|
|
634
641
|
};
|
|
635
|
-
return isSucceed;
|
|
636
642
|
};
|
|
637
643
|
|
|
638
644
|
/**
|
|
@@ -642,7 +648,7 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
642
648
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
643
649
|
* @returns {any}
|
|
644
650
|
* @throws {TypeError} if first param is not an object
|
|
645
|
-
* @throws {
|
|
651
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
646
652
|
*/
|
|
647
653
|
function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
648
654
|
if (!isPlainObject(obj)) {
|
|
@@ -667,7 +673,7 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
667
673
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
668
674
|
* @returns {boolean}
|
|
669
675
|
* @throws {TypeError} if first param is not an object
|
|
670
|
-
* @throws {
|
|
676
|
+
* @throws {EvalKeyNameError} if third param is not valid identifier
|
|
671
677
|
*/
|
|
672
678
|
function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
673
679
|
if (!isPlainObject(obj)) {
|
|
@@ -676,17 +682,22 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
676
682
|
{ code: XOBJ_TE_NPOBJ_ECODE },
|
|
677
683
|
);
|
|
678
684
|
};
|
|
679
|
-
|
|
680
|
-
if (
|
|
685
|
+
const { isSucceed, value: _key } = evalKeyName(key, false);
|
|
686
|
+
if (isSucceed) {
|
|
687
|
+
if (
|
|
688
|
+
_key === ''
|
|
689
|
+
|| value === undefined
|
|
690
|
+
|| isObject(value)
|
|
691
|
+
|| typeof value === 'function'
|
|
692
|
+
) {
|
|
693
|
+
return false;
|
|
694
|
+
};
|
|
695
|
+
obj[_key] = value;
|
|
696
|
+
return true;
|
|
697
|
+
} else {
|
|
681
698
|
const { code, msg } = _key;
|
|
682
699
|
throw new EvalKeyNameError(msg, { code });
|
|
683
700
|
};
|
|
684
|
-
if (_key === '' || value === undefined) {
|
|
685
|
-
isSucceed = false;
|
|
686
|
-
} else {
|
|
687
|
-
obj[_key] = value;
|
|
688
|
-
};
|
|
689
|
-
return isSucceed;
|
|
690
701
|
};
|
|
691
702
|
|
|
692
703
|
/**
|
|
@@ -697,7 +708,7 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
|
|
|
697
708
|
* @param {string} [key] - some key
|
|
698
709
|
* @returns {any}
|
|
699
710
|
* @throws {TypeError} if first param is not an object
|
|
700
|
-
* @throws {
|
|
711
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
701
712
|
*/
|
|
702
713
|
function readXObjAttrRaw(obj, attr = '', key) {
|
|
703
714
|
let _obj = null;
|
|
@@ -725,38 +736,44 @@ function readXObjAttrRaw(obj, attr = '', key) {
|
|
|
725
736
|
* @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
|
|
726
737
|
* @returns {boolean}
|
|
727
738
|
* @throws {TypeError} if first param is not an object
|
|
728
|
-
* @throws {
|
|
739
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
729
740
|
*/
|
|
730
741
|
function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
731
|
-
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
_obj = insertXObjElement(obj, key, opt);
|
|
742
|
-
} catch (err) {
|
|
743
|
-
throw err;
|
|
744
|
-
};
|
|
745
|
-
if (isArray(_obj)) {
|
|
746
|
-
// force a replacement of the old element if it's array
|
|
742
|
+
const { isSucceed, value: name } = evalKeyName(attr, false);
|
|
743
|
+
if (isSucceed) {
|
|
744
|
+
let isSucceed = false;
|
|
745
|
+
if (
|
|
746
|
+
name !== ''
|
|
747
|
+
&& value !== undefined
|
|
748
|
+
&& !isObject(value)
|
|
749
|
+
&& typeof value !== 'function'
|
|
750
|
+
) {
|
|
751
|
+
let _obj = null;
|
|
747
752
|
try {
|
|
748
|
-
const opt = { force: true,
|
|
753
|
+
const opt = { force: true, acceptIfList: true };
|
|
749
754
|
_obj = insertXObjElement(obj, key, opt);
|
|
750
755
|
} catch (err) {
|
|
751
756
|
throw err;
|
|
752
757
|
};
|
|
758
|
+
if (isArray(_obj)) {
|
|
759
|
+
// force a replacement of the old element if it's array
|
|
760
|
+
try {
|
|
761
|
+
const opt = { force: true, ripOldies: true };
|
|
762
|
+
_obj = insertXObjElement(obj, key, opt);
|
|
763
|
+
} catch (err) {
|
|
764
|
+
throw err;
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
if (_obj !== null) {
|
|
768
|
+
_obj[name] = value;
|
|
769
|
+
isSucceed = true;
|
|
770
|
+
};
|
|
753
771
|
};
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
};
|
|
772
|
+
return isSucceed;
|
|
773
|
+
} else {
|
|
774
|
+
const { code, msg } = name;
|
|
775
|
+
throw new EvalKeyNameError(msg, { code });
|
|
758
776
|
};
|
|
759
|
-
return isSucceed;
|
|
760
777
|
};
|
|
761
778
|
|
|
762
779
|
/**
|
|
@@ -791,6 +808,7 @@ function readXObjParam(obj, key) {
|
|
|
791
808
|
* @param {string} [key] - some key
|
|
792
809
|
* @returns {boolean}
|
|
793
810
|
* @throws {TypeError} if first param is not an object
|
|
811
|
+
* @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
794
812
|
*/
|
|
795
813
|
function readXObjParamAsBool(obj, defValue, key) {
|
|
796
814
|
let result = undefined;
|
|
@@ -817,6 +835,7 @@ function readXObjParamAsBool(obj, defValue, key) {
|
|
|
817
835
|
* @param {string} [key] - some key
|
|
818
836
|
* @returns {number}
|
|
819
837
|
* @throws {TypeError} if first param is not an object
|
|
838
|
+
* @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
820
839
|
*/
|
|
821
840
|
function readXObjParamAsNum(obj, defValue, key) {
|
|
822
841
|
let result = undefined;
|
|
@@ -859,14 +878,12 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
859
878
|
}
|
|
860
879
|
};
|
|
861
880
|
};
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
defValue: _opt,
|
|
869
|
-
};
|
|
881
|
+
/** @type {OPT_valtostr} */
|
|
882
|
+
const _opt = isPlainObject(opt) ? opt : {
|
|
883
|
+
useTrim: false,
|
|
884
|
+
numberToString: true,
|
|
885
|
+
boolToString: true,
|
|
886
|
+
defValue: opt,
|
|
870
887
|
};
|
|
871
888
|
return readAsString(result, _opt);
|
|
872
889
|
};
|
|
@@ -1028,7 +1045,7 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
1028
1045
|
*/
|
|
1029
1046
|
function writeXObjParamEx(obj, value, opt, key) {
|
|
1030
1047
|
let isSucceed = false;
|
|
1031
|
-
if (value !== undefined) {
|
|
1048
|
+
if (value !== undefined && typeof value !== 'function') {
|
|
1032
1049
|
let _opt = opt;
|
|
1033
1050
|
if (!isPlainObject(_opt)) {
|
|
1034
1051
|
const defValue = readAsString(_opt, {
|
|
@@ -1094,6 +1111,7 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1094
1111
|
* @param {string} [key] - some key
|
|
1095
1112
|
* @returns {boolean}
|
|
1096
1113
|
* @throws {TypeError} if first param is not an object
|
|
1114
|
+
* @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
1097
1115
|
*/
|
|
1098
1116
|
function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
1099
1117
|
let result = undefined;
|
|
@@ -1121,6 +1139,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1121
1139
|
* @param {string} [key] - some key
|
|
1122
1140
|
* @returns {number}
|
|
1123
1141
|
* @throws {TypeError} if first param is not an object
|
|
1142
|
+
* @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
1124
1143
|
*/
|
|
1125
1144
|
function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
1126
1145
|
let result = undefined;
|
|
@@ -1164,14 +1183,12 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
1164
1183
|
}
|
|
1165
1184
|
};
|
|
1166
1185
|
};
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
defValue: _opt,
|
|
1174
|
-
};
|
|
1186
|
+
/** @type {OPT_valtostr} */
|
|
1187
|
+
const _opt = isPlainObject(opt) ? opt : {
|
|
1188
|
+
useTrim: true,
|
|
1189
|
+
numberToString: true,
|
|
1190
|
+
boolToString: true,
|
|
1191
|
+
defValue: opt,
|
|
1175
1192
|
};
|
|
1176
1193
|
return readAsString(result, _opt);
|
|
1177
1194
|
};
|
|
@@ -1339,7 +1356,7 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1339
1356
|
*/
|
|
1340
1357
|
function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
1341
1358
|
let isSucceed = false;
|
|
1342
|
-
if (value !== undefined) {
|
|
1359
|
+
if (value !== undefined && typeof value !== 'function') {
|
|
1343
1360
|
let _opt = opt;
|
|
1344
1361
|
if (!isPlainObject(_opt)) {
|
|
1345
1362
|
const defValue = readAsString(_opt, {
|
|
@@ -1443,7 +1460,7 @@ function insertXObjEList(...args) {
|
|
|
1443
1460
|
* @param {OPT_inselops_S} [opt] - options
|
|
1444
1461
|
* @returns {RVAL_emodif}
|
|
1445
1462
|
* @throws {TypeError} if first param is not an object
|
|
1446
|
-
* @throws {
|
|
1463
|
+
* @throws {EvalKeyNameError} if second param is not valid identifier
|
|
1447
1464
|
*/
|
|
1448
1465
|
function insertXObjEListEx(obj, name, opt) {
|
|
1449
1466
|
if (!isPlainObject(obj)) {
|
|
@@ -1524,9 +1541,32 @@ function insertXObjEChain(obj, ...args) {
|
|
|
1524
1541
|
return result;
|
|
1525
1542
|
};
|
|
1526
1543
|
|
|
1527
|
-
|
|
1528
|
-
*
|
|
1544
|
+
/**
|
|
1545
|
+
* Clears a given node
|
|
1546
|
+
* @param {(object|object[])} node - some node
|
|
1547
|
+
* @returns {boolean}
|
|
1548
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
1529
1549
|
*/
|
|
1550
|
+
function clearXObjNode(node) {
|
|
1551
|
+
if (isObject(node)) {
|
|
1552
|
+
if (isArray(node)) {
|
|
1553
|
+
node.length = 0;
|
|
1554
|
+
return true;
|
|
1555
|
+
};
|
|
1556
|
+
let isSucceed = false;
|
|
1557
|
+
for (const key in node) {
|
|
1558
|
+
// // TODO: catch errors in strict mode
|
|
1559
|
+
isSucceed = delete node[key];
|
|
1560
|
+
};
|
|
1561
|
+
return isSucceed;
|
|
1562
|
+
} else {
|
|
1563
|
+
throw new EvalKeyNameError(
|
|
1564
|
+
XOBJ_TE_NPOBJ_EMSG,
|
|
1565
|
+
{ code: XOBJ_TE_NPOBJ_ECODE },
|
|
1566
|
+
);
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1569
|
+
module.exports.clearXObjNode = clearXObjNode;
|
|
1530
1570
|
|
|
1531
1571
|
// === module exports block ===
|
|
1532
1572
|
|