@ygracs/xobj-lib-js 0.2.9-b → 0.2.9-b.1

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 CHANGED
@@ -5,6 +5,7 @@ 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`;
8
9
  > - add a new `EvalKeyNameError` class;
9
10
  > - some fixes.
10
11
 
package/doc/xObj.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.46|
1
+ >|***rev.*:**|0.1.47|
2
2
  >|:---|---:|
3
- >|date:|2025-12-14|
3
+ >|date:|2026-02-14|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -10,6 +10,16 @@ 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
+
13
23
  ### Base type definitions
14
24
 
15
25
  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 +126,8 @@ The settings listed in the table below:
116
126
  | `elementsKey` | `string` | `items` ||
117
127
  | `ignoreDeclaration` | `boolean` | `false` ||
118
128
  | `ignoreDocType` | `boolean` | `false` ||
119
- | `ignoreInstractions` | `boolean` | `false` | \<*deprecated*> (*use `ignoreInstraction` instead*) |
120
129
  | `ignoreInstraction` | `boolean` | `false` ||
121
130
  | `ignoreText` | `boolean` | `false` ||
122
- | `ignoreComments` | `boolean` | `false` | \<*deprecated*> (*use `ignoreComment` instead*) |
123
131
  | `ignoreComment` | `boolean` | `false` ||
124
132
  | `ignoreCData` | `boolean` | `false` ||
125
133
  | `fullTagEmptyElement` | `boolean` | `true` ||
@@ -1214,7 +1222,7 @@ The class constructor receives an arguments listed below:
1214
1222
 
1215
1223
  | parameter name | value type | default value | description |
1216
1224
  |:---|---|---:|:---|
1217
- | `options` | `object` | --- | an options settings |
1225
+ | `options` | `object` | --- | some initial options settings |
1218
1226
 
1219
1227
  ##### class properties
1220
1228
 
@@ -1232,6 +1240,8 @@ The class constructor receives an arguments listed below:
1232
1240
  |---|---|:---|
1233
1241
  | `xml2jsParseOptions` | yes | returns an options for an XML-to-JS converter |
1234
1242
 
1243
+ for more details see [`xml2jsParseOptions`](#typedef+xml2jsParseOptions).
1244
+
1235
1245
  <a name="TXmlContentParseOptions+js2xml"></a>
1236
1246
  ###### **js2xml**
1237
1247
 
@@ -1239,12 +1249,14 @@ The class constructor receives an arguments listed below:
1239
1249
  |---|---|:---|
1240
1250
  | `js2xmlParseOptions` | yes | returns an options for a JS-to-XML converter |
1241
1251
 
1252
+ for more details see [`js2xmlParseOptions`](#typedef+js2xmlParseOptions).
1253
+
1242
1254
  <a name="TXmlContentParseOptions+reservedKeys"></a>
1243
1255
  ###### **reservedKeys**
1244
1256
 
1245
1257
  | property type | read only | description |
1246
1258
  |---|---|:---|
1247
- | `Set<string>` | yes | returns a set of the reserved key words those must not be used as an element names |
1259
+ | `Set<string>` | yes | returns a set of the reserved key words those must not be used as an element names |
1248
1260
 
1249
1261
  ##### class methods (*static*)
1250
1262
 
@@ -1252,3 +1264,47 @@ The class constructor receives an arguments listed below:
1252
1264
  ###### **createNewOptionsSet(obj)** => `object`
1253
1265
 
1254
1266
  This method transforms a given object to a set of accepted parser options.
1267
+
1268
+ | parameter name | value type | default value | description |
1269
+ |:---|---|---:|:---|
1270
+ | `obj` | `object` | --- | some initial options settings |
1271
+
1272
+ ### Special class
1273
+
1274
+ <a name="EvalKeyNameError"></a>
1275
+ #### **EvalKeyNameError**
1276
+
1277
+ > since: \[v0.2.x]
1278
+
1279
+ This class extends a functionality of a `TypeError`-object to provide more accurate information when an error happened through a key evaluation.
1280
+
1281
+ > NOTE: the class is in a `beta`-stage.
1282
+
1283
+ #### class constructor
1284
+
1285
+ The class constructor creates a new instance of the class.
1286
+
1287
+ ##### constructor parameters
1288
+
1289
+ The class constructor receives an arguments listed below:
1290
+
1291
+ | parameter name | value type | default value | description |
1292
+ |:---|---|---:|:---|
1293
+ | `msg` | `string` | --- | some user error message |
1294
+ | `options` | `any` | --- | user options |
1295
+
1296
+ #### class properties
1297
+
1298
+ <a name="EvalKeyNameError+name"></a>
1299
+ ##### **name**
1300
+
1301
+ | property type | read only | description |
1302
+ |---|---|:---|
1303
+ | `string` | yes | represents the name for the type of error |
1304
+
1305
+ <a name="EvalKeyNameError+code"></a>
1306
+ ##### **code**
1307
+
1308
+ | property type | read only | description |
1309
+ |---|---|:---|
1310
+ | `string` | yes | represents an error code |
package/lib/xObj-defs.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.067-20260101]
1
+ // [v0.1.068-20260203]
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
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
  */
@@ -112,7 +113,7 @@ export type OPT_inselops_S = {
112
113
  /**
113
114
  * Extracts a parameter 'AS IS' from a given object.
114
115
  * @throws {TypeError} if first param is not an object
115
- * @throws {TypeError} if third param is not a string
116
+ * @throws {EvalKeyNameError} if second param is not valid identifier
116
117
  */
117
118
  export function readXObjParamRaw(obj: object, key?: string): any;
118
119
  /**
@@ -144,7 +145,7 @@ export function readXObjParamAsIndex(obj: object, key?: string): number;
144
145
  /**
145
146
  * Writes a parameter 'AS IS' into a given object.
146
147
  * @throws {TypeError} if first param is not an object
147
- * @throws {TypeError} if third param is not a string
148
+ * @throws {EvalKeyNameError} if third param is not valid identifier
148
149
  */
149
150
  export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
150
151
  /**
@@ -181,7 +182,7 @@ export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: st
181
182
  /**
182
183
  * Extracts an attribute 'AS IS' from a given object.
183
184
  * @throws {TypeError} if first param is not an object
184
- * @throws {TypeError} if third param is not a string
185
+ * @throws {EvalKeyNameError} if second param is not valid identifier
185
186
  */
186
187
  export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
187
188
  /**
@@ -214,7 +215,7 @@ export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): nu
214
215
  /**
215
216
  * Writes a parameter into a given object.
216
217
  * @throws {TypeError} if first param is not an object
217
- * @throws {TypeError} if third param is not a string
218
+ * @throws {EvalKeyNameError} if second param is not valid identifier
218
219
  */
219
220
  export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
220
221
  /**
@@ -256,67 +257,68 @@ export function getXObjAttributes(obj: object, key?: string): object | null;
256
257
  /**
257
258
  * Checks whether an attribute is exists.
258
259
  * @throws {TypeError} if first param is not an object
260
+ * @throws {EvalKeyNameError} if second param is not valid identifier
259
261
  */
260
262
  export function checkXObjAttribute(obj: object, attr?: string, key?: string): boolean;
261
263
  /**
262
264
  * Deletes an attribute addressed by a given name.
263
265
  * @throws {TypeError} if first param is not an object
266
+ * @throws {EvalKeyNameError} if second param is not valid identifier
264
267
  */
265
268
  export function deleteXObjAttribute(obj: object, attr?: string, key?: string): boolean;
266
269
  /**
267
270
  * Renames an attribute addressed by a given name.
268
271
  * @since 0.2.0
269
272
  * @throws {TypeError} if first param is not an object
270
- * @throws {TypeError} if second param is not an object
271
- * @throws {TypeError} if third param is not an object
273
+ * @throws {EvalKeyNameError} if second param is not valid identifier
274
+ * @throws {EvalKeyNameError} if third param is not valid identifier
275
+ * @throws {EvalKeyNameError} if forth param is not valid identifier
272
276
  */
273
277
  export function renameXObjAttribute(obj: object, attr?: string, value?: string, key?: string): boolean;
274
278
  /**
275
279
  * Extracts an element from a given object by its key.
276
280
  * @throws {TypeError} if first param is not an object
277
- * @throws {TypeError} if second param is empty string or not a string at all
281
+ * @throws {EvalKeyNameError} if second param is not valid identifier
278
282
  */
279
283
  export function getXObjElement(obj: object, name: string): any | null;
280
284
  /**
281
285
  * Adds an element addressed by its key to a given object.
282
286
  * @throws {TypeError} if first param is not an object
283
- * @throws {TypeError} if second param is empty string or not a string at all
287
+ * @throws {EvalKeyNameError} if second param is not valid identifier
284
288
  */
285
289
  export function addXObjElement(obj: object, name: string): RVAL_emodif;
286
290
  /**
287
291
  * Inserts an element addressed by its key into a given object.
288
292
  * @throws {TypeError} if first param is not an object
289
- * @see insertXObjElementEx
293
+ * @see {@link insertXObjElementEx} for param details
290
294
  */
291
295
  export function insertXObjElement(...args: insertXObjElementParams): object | null;
292
296
  type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
293
- //export function insertXObjElement(...args: [obj: object, name: string, opt?: OPT_inselops_L]): object | null;
294
297
  /**
295
298
  * Inserts an element addressed by its key into a given object.
296
299
  * @since 0.2.0
297
300
  * @throws {TypeError} if first param is not an object
298
- * @throws {TypeError} if second param is empty string or not a string at all
301
+ * @throws {EvalKeyNameError} if second param is not valid identifier
299
302
  */
300
303
  export function insertXObjElementEx(obj: object, name: string, opt?: OPT_inselops_L): RVAL_emodif;
301
304
  /**
302
305
  * Deletes an element addressed by its key from a given object.
303
306
  * @throws {TypeError} if first param is not an object
304
- * @see deleteXObjElementEx
307
+ * @see {@link deleteXObjElementEx} for param details
305
308
  */
306
309
  export function deleteXObjElement(...args: deleteXObjElementParams): boolean;
307
310
  type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
308
- //export function deleteXObjElement(...args: [obj: object, name: string]): boolean;
309
311
  /**
310
312
  * Deletes an element addressed by its key from a given object.
311
313
  * @throws {TypeError} if first param is not an object
312
- * @throws {TypeError} if second param is empty string or not a string at all
314
+ * @throws {EvalKeyNameError} if second param is not valid identifier
313
315
  */
314
316
  export function deleteXObjElementEx(obj: object, name: string): RVAL_emodif;
315
317
  /**
316
318
  * Renames an element addressed by its key.
317
319
  * @throws {TypeError} if first param is not an object
318
- * @throws {TypeError} if second param is not a string
319
- * @throws {TypeError} if third param is not a string
320
+ * @throws {EvalKeyNameError} if second param is not valid identifier
321
+ * @throws {EvalKeyNameError} if third param is not valid identifier
320
322
  */
321
323
  export function renameXObjElement(obj: object, name?: string, value?: string): boolean;
322
324
  /**
@@ -330,12 +332,11 @@ export function evalXObjEName(value: any): null | number | string;
330
332
  */
331
333
  export function insertXObjEList(...args: insertXObjEListParams): object | object[] | null;
332
334
  type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
333
- //export function insertXObjEList(...args: [obj: object, name: string, opt?: OPT_inselops_S]): object | object[] | null;
334
335
  /**
335
336
  * Inserts a list elements into a given object.
336
337
  * @since 0.2.0
337
338
  * @throws {TypeError} if first param is not an object
338
- * @throws {TypeError} if second param is empty string or not a string at all
339
+ * @throws {EvalKeyNameError} if second param is not valid identifier
339
340
  */
340
341
  export function insertXObjEListEx(obj: object, name: string, opt?: OPT_inselops_S): RVAL_emodif;
341
342
  /**
package/lib/xObj-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.3.114-20260131]
1
+ // [v0.3.120-20260213]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -235,7 +235,7 @@ function genXObjENameDescr(value) {
235
235
  * @param {string} name - some child element
236
236
  * @returns {?any}
237
237
  * @throws {TypeError} if first param is not an object
238
- * @throws {TypeError} if second param is empty string or not a string at all
238
+ * @throws {EvalKeyNameError} if second param is not valid identifier
239
239
  */
240
240
  function getXObjElement(obj, name) {
241
241
  if (!isPlainObject(obj)) {
@@ -293,7 +293,7 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
293
293
  * @param {string} name - some child element
294
294
  * @returns {RVAL_emodif}
295
295
  * @throws {TypeError} if first param is not an object
296
- * @throws {TypeError} if second param is empty string or not a string at all
296
+ * @throws {EvalKeyNameError} if second param is not valid identifier
297
297
  */
298
298
  function addXObjElement(obj, name) {
299
299
  if (!isPlainObject(obj)) {
@@ -346,7 +346,7 @@ function addXObjElement(obj, name) {
346
346
  * @param {OPT_inselops_L} [opt] - options
347
347
  * @returns {?object}
348
348
  * @throws {TypeError} if first param is not an object
349
- * @see insertXObjElementEx
349
+ * @see {@link insertXObjElementEx} for param details
350
350
  */
351
351
  function insertXObjElement(...args) {
352
352
  let item = null;
@@ -375,7 +375,7 @@ function insertXObjElement(...args) {
375
375
  * @param {OPT_inselops_L} [opt] - options
376
376
  * @returns {RVAL_emodif}
377
377
  * @throws {TypeError} if first param is not an object
378
- * @throws {TypeError} if second param is empty string or not a string at all
378
+ * @throws {EvalKeyNameError} if second param is not valid identifier
379
379
  */
380
380
  function insertXObjElementEx(obj, name, opt) {
381
381
  if (!isPlainObject(obj)) {
@@ -426,7 +426,7 @@ function insertXObjElementEx(obj, name, opt) {
426
426
  * @param {string} name - some child element
427
427
  * @returns {boolean}
428
428
  * @throws {TypeError} if first param is not an object
429
- * @see deleteXObjElementEx
429
+ * @see {@link deleteXObjElementEx} for param details
430
430
  */
431
431
  function deleteXObjElement(...args) {
432
432
  let isSucceed = false;
@@ -453,7 +453,7 @@ function deleteXObjElement(...args) {
453
453
  * @param {string} name - some child element
454
454
  * @returns {RVAL_emodif}
455
455
  * @throws {TypeError} if first param is not an object
456
- * @throws {TypeError} if second param is empty string or not a string at all
456
+ * @throws {EvalKeyNameError} if second param is not valid identifier
457
457
  */
458
458
  function deleteXObjElementEx(obj, name) {
459
459
  if (!isPlainObject(obj)) {
@@ -486,8 +486,8 @@ function deleteXObjElementEx(obj, name) {
486
486
  * @param {string} value - new element ID
487
487
  * @returns {boolean}
488
488
  * @throws {TypeError} if first param is not an object
489
- * @throws {TypeError} if second param is not a string
490
- * @throws {TypeError} if third param is not a string
489
+ * @throws {EvalKeyNameError} if second param is not valid identifier
490
+ * @throws {EvalKeyNameError} if third param is not valid identifier
491
491
  */
492
492
  function renameXObjElement(obj, name = '', value = '') {
493
493
  if (!isPlainObject(obj)) {
@@ -531,6 +531,7 @@ function renameXObjElement(obj, name = '', value = '') {
531
531
  * @param {string} [key] - some key
532
532
  * @returns {boolean}
533
533
  * @throws {TypeError} if first param is not an object
534
+ * @throws {EvalKeyNameError} if second param is not valid identifier
534
535
  */
535
536
  function checkXObjAttribute(obj, attr = '', key) {
536
537
  let _obj = null;
@@ -558,6 +559,7 @@ function checkXObjAttribute(obj, attr = '', key) {
558
559
  * @param {string} [key] - some key
559
560
  * @returns {boolean}
560
561
  * @throws {TypeError} if first param is not an object
562
+ * @throws {EvalKeyNameError} if second param is not valid identifier
561
563
  */
562
564
  function deleteXObjAttribute(obj, attr = '', key) {
563
565
  let _obj = null;
@@ -591,8 +593,9 @@ function deleteXObjAttribute(obj, attr = '', key) {
591
593
  * @param {string} [key] - some key
592
594
  * @returns {boolean}
593
595
  * @throws {TypeError} if first param is not an object
594
- * @throws {TypeError} if second param is not an object
595
- * @throws {TypeError} if third param is not an object
596
+ * @throws {EvalKeyNameError} if second param is not valid identifier
597
+ * @throws {EvalKeyNameError} if third param is not valid identifier
598
+ * @throws {EvalKeyNameError} if forth param is not valid identifier
596
599
  */
597
600
  function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNAME) {
598
601
  if (!isPlainObject(obj)) {
@@ -602,37 +605,38 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
602
605
  );
603
606
  };
604
607
  const opt = false;
605
- let { isSucceed, value: _key } = evalKeyName(key, opt);
606
- if (!isSucceed) {
607
- const { code, msg } = _key;
608
- throw new EvalKeyNameError(msg, { code });
609
- };
610
- isSucceed = false;
611
- if (_key !== '') {
612
- let _obj = obj[_key];
613
- if (isPlainObject(_obj)) {
614
- const { isSucceed: isAcceptON, value: oname } = evalKeyName(attr, opt);
615
- if (!isAcceptON) {
616
- const { code, msg } = oname;
617
- throw new EvalKeyNameError(msg, { code });
618
- };
619
- const { isSucceed: isAcceptNN, value: nname } = evalKeyName(value, opt);
620
- if (!isAcceptNN) {
621
- const { code, msg } = nname;
622
- throw new EvalKeyNameError(msg, { code });
623
- };
624
- if (oname !== '' && oname in _obj && nname !== '') {
625
- if (oname !== nname) {
626
- _obj = Object.entries(_obj);
627
- const index = _obj.findIndex((item) => item[0] === oname);
628
- _obj[index][0] = nname;
629
- obj[_key] = Object.fromEntries(_obj);
608
+ const { isSucceed, value: _key } = evalKeyName(key, opt);
609
+ if (isSucceed) {
610
+ let isSucceed = false;
611
+ if (_key !== '') {
612
+ let _obj = obj[_key];
613
+ if (isPlainObject(_obj)) {
614
+ const { isSucceed: isAcceptON, value: oname } = evalKeyName(attr, opt);
615
+ if (!isAcceptON) {
616
+ const { code, msg } = oname;
617
+ throw new EvalKeyNameError(msg, { code });
618
+ };
619
+ const { isSucceed: isAcceptNN, value: nname } = evalKeyName(value, opt);
620
+ if (!isAcceptNN) {
621
+ const { code, msg } = nname;
622
+ throw new EvalKeyNameError(msg, { code });
623
+ };
624
+ if (oname !== '' && oname in _obj && nname !== '') {
625
+ if (oname !== nname) {
626
+ _obj = Object.entries(_obj);
627
+ const index = _obj.findIndex((item) => item[0] === oname);
628
+ _obj[index][0] = nname;
629
+ obj[_key] = Object.fromEntries(_obj);
630
+ };
631
+ isSucceed = true;
630
632
  };
631
- isSucceed = true;
632
633
  };
633
634
  };
635
+ return isSucceed;
636
+ } else {
637
+ const { code, msg } = _key;
638
+ throw new EvalKeyNameError(msg, { code });
634
639
  };
635
- return isSucceed;
636
640
  };
637
641
 
638
642
  /**
@@ -642,7 +646,7 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
642
646
  * @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
643
647
  * @returns {any}
644
648
  * @throws {TypeError} if first param is not an object
645
- * @throws {TypeError} if third param is not a string
649
+ * @throws {EvalKeyNameError} if second param is not valid identifier
646
650
  */
647
651
  function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
648
652
  if (!isPlainObject(obj)) {
@@ -667,7 +671,7 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
667
671
  * @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
668
672
  * @returns {boolean}
669
673
  * @throws {TypeError} if first param is not an object
670
- * @throws {TypeError} if third param is not a string
674
+ * @throws {EvalKeyNameError} if third param is not valid identifier
671
675
  */
672
676
  function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
673
677
  if (!isPlainObject(obj)) {
@@ -676,17 +680,22 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
676
680
  { code: XOBJ_TE_NPOBJ_ECODE },
677
681
  );
678
682
  };
679
- let { isSucceed, value: _key } = evalKeyName(key, false);
680
- if (!isSucceed) {
683
+ const { isSucceed, value: _key } = evalKeyName(key, false);
684
+ if (isSucceed) {
685
+ if (
686
+ _key === ''
687
+ || value === undefined
688
+ || isObject(value)
689
+ || typeof value === 'function'
690
+ ) {
691
+ return false;
692
+ };
693
+ obj[_key] = value;
694
+ return true;
695
+ } else {
681
696
  const { code, msg } = _key;
682
697
  throw new EvalKeyNameError(msg, { code });
683
698
  };
684
- if (_key === '' || value === undefined) {
685
- isSucceed = false;
686
- } else {
687
- obj[_key] = value;
688
- };
689
- return isSucceed;
690
699
  };
691
700
 
692
701
  /**
@@ -697,7 +706,7 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
697
706
  * @param {string} [key] - some key
698
707
  * @returns {any}
699
708
  * @throws {TypeError} if first param is not an object
700
- * @throws {TypeError} if third param is not a string
709
+ * @throws {EvalKeyNameError} if second param is not valid identifier
701
710
  */
702
711
  function readXObjAttrRaw(obj, attr = '', key) {
703
712
  let _obj = null;
@@ -725,38 +734,44 @@ function readXObjAttrRaw(obj, attr = '', key) {
725
734
  * @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
726
735
  * @returns {boolean}
727
736
  * @throws {TypeError} if first param is not an object
728
- * @throws {TypeError} if third param is not a string
737
+ * @throws {EvalKeyNameError} if second param is not valid identifier
729
738
  */
730
739
  function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
731
- let { isSucceed, value: name } = evalKeyName(attr, false);
732
- if (!isSucceed) {
733
- const { code, msg } = name;
734
- throw new EvalKeyNameError(msg, { code });
735
- };
736
- isSucceed = false;
737
- if (name !== '' && value !== undefined) {
738
- let _obj = null;
739
- try {
740
- const opt = { force: true, acceptIfList: true };
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
740
+ const { isSucceed, value: name } = evalKeyName(attr, false);
741
+ if (isSucceed) {
742
+ let isSucceed = false;
743
+ if (
744
+ name !== ''
745
+ && value !== undefined
746
+ && !isObject(value)
747
+ && typeof value !== 'function'
748
+ ) {
749
+ let _obj = null;
747
750
  try {
748
- const opt = { force: true, ripOldies: true };
751
+ const opt = { force: true, acceptIfList: true };
749
752
  _obj = insertXObjElement(obj, key, opt);
750
753
  } catch (err) {
751
754
  throw err;
752
755
  };
756
+ if (isArray(_obj)) {
757
+ // force a replacement of the old element if it's array
758
+ try {
759
+ const opt = { force: true, ripOldies: true };
760
+ _obj = insertXObjElement(obj, key, opt);
761
+ } catch (err) {
762
+ throw err;
763
+ };
764
+ };
765
+ if (_obj !== null) {
766
+ _obj[name] = value;
767
+ isSucceed = true;
768
+ };
753
769
  };
754
- if (_obj !== null) {
755
- _obj[name] = value;
756
- isSucceed = true;
757
- };
770
+ return isSucceed;
771
+ } else {
772
+ const { code, msg } = name;
773
+ throw new EvalKeyNameError(msg, { code });
758
774
  };
759
- return isSucceed;
760
775
  };
761
776
 
762
777
  /**
@@ -1443,7 +1458,7 @@ function insertXObjEList(...args) {
1443
1458
  * @param {OPT_inselops_S} [opt] - options
1444
1459
  * @returns {RVAL_emodif}
1445
1460
  * @throws {TypeError} if first param is not an object
1446
- * @throws {TypeError} if second param is empty string or not a string at all
1461
+ * @throws {EvalKeyNameError} if second param is not valid identifier
1447
1462
  */
1448
1463
  function insertXObjEListEx(obj, name, opt) {
1449
1464
  if (!isPlainObject(obj)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygracs/xobj-lib-js",
3
- "version": "0.2.9-b",
3
+ "version": "0.2.9-b.1",
4
4
  "description": "A helper library to work with xml-js module",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",