@ygracs/xobj-lib-js 0.2.9-b.2 → 0.3.0

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/lib/xObj-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.3.127-20260222]
1
+ // [v0.3.134-20260303]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -37,23 +37,32 @@ const {
37
37
 
38
38
  // === module inner block ===
39
39
 
40
+ /**
41
+ * An error description of a value check ops on fail.
42
+ * @since 0.3.0
43
+ * @typedef {Object} IEvalKeyNameReasonOnFail
44
+ * @property {string} code - message ID
45
+ * @property {string} msg - message text
46
+ */
47
+
40
48
  /**
41
49
  * A result of a value check ops.
42
50
  * @typedef {Object} RVAL_reason
43
51
  * @property {string} code - message ID
44
52
  * @property {string} msg - message text
53
+ * @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameReasonOnFail` instead.
45
54
  */
46
55
 
47
56
  /**
48
57
  * An options setting for `evalKeyName` function
49
- * @since 0.2.x
58
+ * @since 0.3.0
50
59
  * @typedef {Object} IEvalKeyNameOptions
51
60
  * @property {boolean} [onlyNES] - a flag to accept only a non-empty string values
52
61
  */
53
62
 
54
63
  /**
55
64
  * A result of `evalKeyName` function if succeed
56
- * @since 0.2.x
65
+ * @since 0.3.0
57
66
  * @typedef {Object} IEvalKeyNameResultOnSuccess
58
67
  * @property {true} isSucceed - ops flag
59
68
  * @property {string} value - result value
@@ -61,15 +70,15 @@ const {
61
70
 
62
71
  /**
63
72
  * A result of `evalKeyName` function if failed
64
- * @since 0.2.x
73
+ * @since 0.3.0
65
74
  * @typedef {Object} IEvalKeyNameResultOnFail
66
75
  * @property {false} isSucceed - ops flag
67
- * @property {RVAL_reason} value - reason of fail
76
+ * @property {IEvalKeyNameReasonOnFail} value - reason of fail
68
77
  */
69
78
 
70
79
  /**
71
80
  * A result of `evalKeyName` function
72
- * @since 0.2.x
81
+ * @since 0.3.0
73
82
  * @typedef {(IEvalKeyNameResultOnSuccess|IEvalKeyNameResultOnFail)} IEvalKeyNameResult
74
83
  */
75
84
 
@@ -78,7 +87,7 @@ const {
78
87
  * @typedef {Object} VCOR_evalkname
79
88
  * @property {boolean} isSucceed - ops flag
80
89
  * @property {(string|RVAL_reason)} value - result value or reson if failed
81
- * @todo \[from v0.2.x] make obsolete. Use `IEvalKeyNameResult` instead.
90
+ * @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameResult` instead.
82
91
  */
83
92
 
84
93
  /**
@@ -165,12 +174,22 @@ function evalXObjEName(value) {
165
174
  return name;
166
175
  };
167
176
 
177
+ /**
178
+ * Some conditions applied to an element as a result of an element name pattern
179
+ * evaluation ops.
180
+ * @since 0.3.0
181
+ * @typedef {Object} XObjENameDescrConditions
182
+ * @property {any} name - element name
183
+ * @property {any} type - element type
184
+ * @property {any} [value] - some value
185
+ */
186
+
168
187
  /**
169
188
  * A result of an element name pattern evaluation ops.
170
189
  * @typedef {Object} XObjENameDescr
171
190
  * @property {boolean} isERR - ops flag
172
191
  * @property {(null|number|string)} name - element name
173
- * @property {?object} conditions - some conditions applied to an element
192
+ * @property {?XObjENameDescrConditions} conditions - some conditions applied to an element
174
193
  */
175
194
 
176
195
  /**
@@ -178,6 +197,7 @@ function evalXObjEName(value) {
178
197
  * @function genXObjENameDescr
179
198
  * @param {any} value - element name pattern
180
199
  * @returns {XObjENameDescr}
200
+ * @experimental
181
201
  */
182
202
  function genXObjENameDescr(value) {
183
203
  let result = null;
@@ -236,8 +256,8 @@ function genXObjENameDescr(value) {
236
256
  * @param {object} obj - some object
237
257
  * @param {string} name - some child element
238
258
  * @returns {?any}
239
- * @throws {TypeError} if first param is not an object
240
- * @throws {EvalKeyNameError} if second param is not valid identifier
259
+ * @throws {TypeError} if `obj` param is not an object
260
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
241
261
  */
242
262
  function getXObjElement(obj, name) {
243
263
  if (!isPlainObject(obj)) {
@@ -261,7 +281,7 @@ function getXObjElement(obj, name) {
261
281
  * @param {object} obj - some object
262
282
  * @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
263
283
  * @returns {?object}
264
- * @throws {TypeError} if first param is not an object
284
+ * @throws {TypeError} if `obj` param is not an object
265
285
  */
266
286
  function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
267
287
  let result = null;
@@ -293,11 +313,39 @@ function getXObjAttributes(obj, key = XOBJ_DEF_ATTR_TNAME) {
293
313
  * @function addXObjElement
294
314
  * @param {object} obj - some object
295
315
  * @param {string} name - some child element
316
+ * @returns {?object}
317
+ * @throws {TypeError} if `obj` param is not an object
318
+ * @see {@link addXObjElementEx} for param details
319
+ */
320
+ function addXObjElement(...args) {
321
+ let item = null;
322
+ try {
323
+ ({ item } = addXObjElementEx(...args));
324
+ } catch (err) {
325
+ switch (err.code) {
326
+ case XOBJ_TE_NSTR_ECODE :
327
+ case XOBJ_TE_KNES_ECODE : {
328
+ break;
329
+ }
330
+ default: {
331
+ throw err;
332
+ }
333
+ };
334
+ };
335
+ return item;
336
+ };
337
+
338
+ /**
339
+ * Adds an element addressed by its key to a given object.
340
+ * @since 0.3.0
341
+ * @function addXObjElementEx
342
+ * @param {object} obj - some object
343
+ * @param {string} name - some child element
296
344
  * @returns {RVAL_emodif}
297
- * @throws {TypeError} if first param is not an object
298
- * @throws {EvalKeyNameError} if second param is not valid identifier
345
+ * @throws {TypeError} if `obj` param is not an object
346
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
299
347
  */
300
- function addXObjElement(obj, name) {
348
+ function addXObjElementEx(obj, name) {
301
349
  if (!isPlainObject(obj)) {
302
350
  throw new EvalKeyNameError(
303
351
  XOBJ_TE_NPOBJ_EMSG,
@@ -331,6 +379,7 @@ function addXObjElement(obj, name) {
331
379
  throw new EvalKeyNameError(msg, { code });
332
380
  };
333
381
  };
382
+ module.exports.addXObjElementEx = addXObjElementEx;
334
383
 
335
384
  /**
336
385
  * An options for an element insertion ops
@@ -347,7 +396,7 @@ function addXObjElement(obj, name) {
347
396
  * @param {string} name - some child element
348
397
  * @param {OPT_inselops_L} [opt] - options
349
398
  * @returns {?object}
350
- * @throws {TypeError} if first param is not an object
399
+ * @throws {TypeError} if `obj` param is not an object
351
400
  * @see {@link insertXObjElementEx} for param details
352
401
  */
353
402
  function insertXObjElement(...args) {
@@ -376,8 +425,8 @@ function insertXObjElement(...args) {
376
425
  * @param {string} name - some child element
377
426
  * @param {OPT_inselops_L} [opt] - options
378
427
  * @returns {RVAL_emodif}
379
- * @throws {TypeError} if first param is not an object
380
- * @throws {EvalKeyNameError} if second param is not valid identifier
428
+ * @throws {TypeError} if `obj` param is not an object
429
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
381
430
  */
382
431
  function insertXObjElementEx(obj, name, opt) {
383
432
  if (!isPlainObject(obj)) {
@@ -427,7 +476,7 @@ function insertXObjElementEx(obj, name, opt) {
427
476
  * @param {object} obj - some object
428
477
  * @param {string} name - some child element
429
478
  * @returns {boolean}
430
- * @throws {TypeError} if first param is not an object
479
+ * @throws {TypeError} if `obj` param is not an object
431
480
  * @see {@link deleteXObjElementEx} for param details
432
481
  */
433
482
  function deleteXObjElement(...args) {
@@ -454,8 +503,8 @@ function deleteXObjElement(...args) {
454
503
  * @param {object} obj - some object
455
504
  * @param {string} name - some child element
456
505
  * @returns {RVAL_emodif}
457
- * @throws {TypeError} if first param is not an object
458
- * @throws {EvalKeyNameError} if second param is not valid identifier
506
+ * @throws {TypeError} if `obj` param is not an object
507
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
459
508
  */
460
509
  function deleteXObjElementEx(obj, name) {
461
510
  if (!isPlainObject(obj)) {
@@ -487,9 +536,9 @@ function deleteXObjElementEx(obj, name) {
487
536
  * @param {string} name - some child element
488
537
  * @param {string} value - new element ID
489
538
  * @returns {boolean}
490
- * @throws {TypeError} if first param is not an object
491
- * @throws {EvalKeyNameError} if second param is not valid identifier
492
- * @throws {EvalKeyNameError} if third param is not valid identifier
539
+ * @throws {TypeError} if `obj` param is not an object
540
+ * @throws {EvalKeyNameError} if `name` param is not valid identifier
541
+ * @throws {EvalKeyNameError} if `value` param is not valid identifier
493
542
  */
494
543
  function renameXObjElement(obj, name = '', value = '') {
495
544
  if (!isPlainObject(obj)) {
@@ -532,8 +581,8 @@ function renameXObjElement(obj, name = '', value = '') {
532
581
  * @param {string} attr - some attribute ID
533
582
  * @param {string} [key] - some key
534
583
  * @returns {boolean}
535
- * @throws {TypeError} if first param is not an object
536
- * @throws {EvalKeyNameError} if second param is not valid identifier
584
+ * @throws {TypeError} if `obj` param is not an object
585
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
537
586
  */
538
587
  function checkXObjAttribute(obj, attr = '', key) {
539
588
  let _obj = null;
@@ -560,8 +609,8 @@ function checkXObjAttribute(obj, attr = '', key) {
560
609
  * @param {string} attr - some attribute ID
561
610
  * @param {string} [key] - some key
562
611
  * @returns {boolean}
563
- * @throws {TypeError} if first param is not an object
564
- * @throws {EvalKeyNameError} if second param is not valid identifier
612
+ * @throws {TypeError} if `obj` param is not an object
613
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
565
614
  */
566
615
  function deleteXObjAttribute(obj, attr = '', key) {
567
616
  let _obj = null;
@@ -594,10 +643,10 @@ function deleteXObjAttribute(obj, attr = '', key) {
594
643
  * @param {string} value - new attribute ID
595
644
  * @param {string} [key] - some key
596
645
  * @returns {boolean}
597
- * @throws {TypeError} if first param is not an object
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
646
+ * @throws {TypeError} if `obj` param is not an object
647
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
648
+ * @throws {EvalKeyNameError} if `value` param is not valid identifier
649
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
601
650
  */
602
651
  function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNAME) {
603
652
  if (!isPlainObject(obj)) {
@@ -647,8 +696,8 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
647
696
  * @param {object} obj - some object
648
697
  * @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
649
698
  * @returns {any}
650
- * @throws {TypeError} if first param is not an object
651
- * @throws {EvalKeyNameError} if second param is not valid identifier
699
+ * @throws {TypeError} if `obj` param is not an object
700
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
652
701
  */
653
702
  function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
654
703
  if (!isPlainObject(obj)) {
@@ -672,8 +721,8 @@ function readXObjParamRaw(obj, key = XOBJ_DEF_PARAM_TNAME) {
672
721
  * @param {any} value - some value
673
722
  * @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
674
723
  * @returns {boolean}
675
- * @throws {TypeError} if first param is not an object
676
- * @throws {EvalKeyNameError} if third param is not valid identifier
724
+ * @throws {TypeError} if `obj` param is not an object
725
+ * @throws {EvalKeyNameError} if `key` param is not valid identifier
677
726
  */
678
727
  function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
679
728
  if (!isPlainObject(obj)) {
@@ -707,8 +756,8 @@ function writeXObjParamRaw(obj, value, key = XOBJ_DEF_PARAM_TNAME) {
707
756
  * @param {string} attr - some attribute
708
757
  * @param {string} [key] - some key
709
758
  * @returns {any}
710
- * @throws {TypeError} if first param is not an object
711
- * @throws {EvalKeyNameError} if second param is not valid identifier
759
+ * @throws {TypeError} if `obj` param is not an object
760
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
712
761
  */
713
762
  function readXObjAttrRaw(obj, attr = '', key) {
714
763
  let _obj = null;
@@ -735,8 +784,8 @@ function readXObjAttrRaw(obj, attr = '', key) {
735
784
  * @param {any} value - some value
736
785
  * @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
737
786
  * @returns {boolean}
738
- * @throws {TypeError} if first param is not an object
739
- * @throws {EvalKeyNameError} if second param is not valid identifier
787
+ * @throws {TypeError} if `obj` param is not an object
788
+ * @throws {EvalKeyNameError} if `attr` param is not valid identifier
740
789
  */
741
790
  function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
742
791
  const { isSucceed, value: name } = evalKeyName(attr, false);
@@ -782,7 +831,7 @@ function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
782
831
  * @param {object} obj - some object
783
832
  * @param {string} [key] - some key
784
833
  * @returns {string}
785
- * @throws {TypeError} if first param is not an object
834
+ * @throws {TypeError} if `obj` param is not an object
786
835
  */
787
836
  function readXObjParam(obj, key) {
788
837
  const opt = {
@@ -807,7 +856,7 @@ function readXObjParam(obj, key) {
807
856
  * @param {boolean} [defValue] - default value
808
857
  * @param {string} [key] - some key
809
858
  * @returns {boolean}
810
- * @throws {TypeError} if first param is not an object
859
+ * @throws {TypeError} if `obj` param is not an object
811
860
  * @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
812
861
  */
813
862
  function readXObjParamAsBool(obj, defValue, key) {
@@ -826,6 +875,7 @@ function readXObjParamAsBool(obj, defValue, key) {
826
875
  };
827
876
  return readAsBoolEx(result, defValue);
828
877
  };
878
+ module.exports.readXObjParamAsBool = readXObjParamAsBool;
829
879
 
830
880
  /**
831
881
  * Extracts a parameter from a given object and returns it as a number.
@@ -834,7 +884,7 @@ function readXObjParamAsBool(obj, defValue, key) {
834
884
  * @param {number} [defValue] - default value
835
885
  * @param {string} [key] - some key
836
886
  * @returns {number}
837
- * @throws {TypeError} if first param is not an object
887
+ * @throws {TypeError} if `obj` param is not an object
838
888
  * @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
839
889
  */
840
890
  function readXObjParamAsNum(obj, defValue, key) {
@@ -853,18 +903,17 @@ function readXObjParamAsNum(obj, defValue, key) {
853
903
  };
854
904
  return readAsNumberEx(result, defValue);
855
905
  };
906
+ module.exports.readXObjParamAsNum = readXObjParamAsNum;
856
907
 
857
908
  /**
858
- * Extracts a parameter from a given object and returns it as a string.
859
- * @function readXObjParamEx
909
+ * Extracts a parameter from a given object and returns it as 'index' value.
910
+ * @function readXObjParamAsIndex
860
911
  * @param {object} obj - some object
861
- * @param {object} [opt] - options
862
912
  * @param {string} [key] - some key
863
- * @returns {string}
864
- * @throws {TypeError} if first param is not an object
865
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
913
+ * @returns {number}
914
+ * @throws {TypeError} if `obj` param is not an object
866
915
  */
867
- function readXObjParamEx(obj, opt, key) {
916
+ function readXObjParamAsIndex(obj, key) {
868
917
  let result = undefined;
869
918
  try {
870
919
  result = readXObjParamRaw(obj, key);
@@ -878,25 +927,21 @@ function readXObjParamEx(obj, opt, key) {
878
927
  }
879
928
  };
880
929
  };
881
- /** @type {OPT_valtostr} */
882
- const _opt = isPlainObject(opt) ? opt : {
883
- useTrim: false,
884
- numberToString: true,
885
- boolToString: true,
886
- defValue: opt,
887
- };
888
- return readAsString(result, _opt);
930
+ return valueToIndex(result);
889
931
  };
932
+ module.exports.readXObjParamAsIndex = readXObjParamAsIndex;
890
933
 
891
934
  /**
892
- * Extracts a parameter from a given object and returns it as 'index' value.
893
- * @function readXObjParamAsIndex
935
+ * Extracts a parameter from a given object and returns it as a string.
936
+ * @function readXObjParamEx
894
937
  * @param {object} obj - some object
938
+ * @param {object} [opt] - options
895
939
  * @param {string} [key] - some key
896
- * @returns {number}
897
- * @throws {TypeError} if first param is not an object
940
+ * @returns {string}
941
+ * @throws {TypeError} if `obj` param is not an object
942
+ * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
898
943
  */
899
- function readXObjParamAsIndex(obj, key) {
944
+ function readXObjParamEx(obj, opt, key) {
900
945
  let result = undefined;
901
946
  try {
902
947
  result = readXObjParamRaw(obj, key);
@@ -910,7 +955,14 @@ function readXObjParamAsIndex(obj, key) {
910
955
  }
911
956
  };
912
957
  };
913
- return valueToIndex(result);
958
+ /** @type {OPT_valtostr} */
959
+ const _opt = isPlainObject(opt) ? opt : {
960
+ useTrim: false,
961
+ numberToString: true,
962
+ boolToString: true,
963
+ defValue: opt,
964
+ };
965
+ return readAsString(result, _opt);
914
966
  };
915
967
 
916
968
  /**
@@ -921,7 +973,7 @@ function readXObjParamAsIndex(obj, key) {
921
973
  * @param {any} value - some value
922
974
  * @param {string} [key] - some key
923
975
  * @returns {boolean}
924
- * @throws {TypeError} if first param is not an object
976
+ * @throws {TypeError} if `obj` param is not an object
925
977
  */
926
978
  function writeXObjParam(obj, value, key) {
927
979
  let isSucceed = false;
@@ -948,7 +1000,7 @@ function writeXObjParam(obj, value, key) {
948
1000
  * @param {boolean} [defValue] - default value
949
1001
  * @param {string} [key] - some key
950
1002
  * @returns {boolean}
951
- * @throws {TypeError} if first param is not an object
1003
+ * @throws {TypeError} if `obj` param is not an object
952
1004
  */
953
1005
  function writeXObjParamAsBool(obj, value, defValue, key) {
954
1006
  let isSucceed = false;
@@ -969,6 +1021,7 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
969
1021
  };
970
1022
  return isSucceed;
971
1023
  };
1024
+ module.exports.writeXObjParamAsBool = writeXObjParamAsBool;
972
1025
 
973
1026
  /**
974
1027
  * Tries to convert a given value to a number and writes it as a parameter
@@ -979,7 +1032,7 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
979
1032
  * @param {number} [defValue] - default value
980
1033
  * @param {string} [key] - some key
981
1034
  * @returns {boolean}
982
- * @throws {TypeError} if first param is not an object
1035
+ * @throws {TypeError} if `obj` param is not an object
983
1036
  */
984
1037
  function writeXObjParamAsNum(obj, value, defValue, key) {
985
1038
  let isSucceed = false;
@@ -1000,6 +1053,7 @@ function writeXObjParamAsNum(obj, value, defValue, key) {
1000
1053
  };
1001
1054
  return isSucceed;
1002
1055
  };
1056
+ module.exports.writeXObjParamAsNum = writeXObjParamAsNum;
1003
1057
 
1004
1058
  /**
1005
1059
  * Tries to convert a given value into an 'index' value and writes it
@@ -1009,7 +1063,7 @@ function writeXObjParamAsNum(obj, value, defValue, key) {
1009
1063
  * @param {any} value - some value
1010
1064
  * @param {string} [key] - some key
1011
1065
  * @returns {boolean}
1012
- * @throws {TypeError} if first param is not an object
1066
+ * @throws {TypeError} if `obj` param is not an object
1013
1067
  */
1014
1068
  function writeXObjParamAsIndex(obj, value, key) {
1015
1069
  let isSucceed = false;
@@ -1030,6 +1084,7 @@ function writeXObjParamAsIndex(obj, value, key) {
1030
1084
  };
1031
1085
  return isSucceed;
1032
1086
  };
1087
+ module.exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
1033
1088
 
1034
1089
  /**
1035
1090
  * Tries to convert a given value to a string and writes it
@@ -1040,7 +1095,7 @@ function writeXObjParamAsIndex(obj, value, key) {
1040
1095
  * @param {object} [opt] - options
1041
1096
  * @param {string} [key] - some key
1042
1097
  * @returns {boolean}
1043
- * @throws {TypeError} if first param is not an object
1098
+ * @throws {TypeError} if `obj` param is not an object
1044
1099
  * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
1045
1100
  */
1046
1101
  function writeXObjParamEx(obj, value, opt, key) {
@@ -1084,7 +1139,7 @@ function writeXObjParamEx(obj, value, opt, key) {
1084
1139
  * @param {string} attr - some attribute
1085
1140
  * @param {string} [key] - some key
1086
1141
  * @returns {string}
1087
- * @throws {TypeError} if first param is not an object
1142
+ * @throws {TypeError} if `obj` param is not an object
1088
1143
  */
1089
1144
  function readXObjAttr(obj, attr, key) {
1090
1145
  const opt = {
@@ -1110,7 +1165,7 @@ function readXObjAttr(obj, attr, key) {
1110
1165
  * @param {boolean} [defValue] - default value
1111
1166
  * @param {string} [key] - some key
1112
1167
  * @returns {boolean}
1113
- * @throws {TypeError} if first param is not an object
1168
+ * @throws {TypeError} if `obj` param is not an object
1114
1169
  * @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
1115
1170
  */
1116
1171
  function readXObjAttrAsBool(obj, attr, defValue, key) {
@@ -1129,6 +1184,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
1129
1184
  };
1130
1185
  return readAsBoolEx(result, defValue);
1131
1186
  };
1187
+ module.exports.readXObjAttrAsBool = readXObjAttrAsBool;
1132
1188
 
1133
1189
  /**
1134
1190
  * Extracts an attribute from a given object and returns it as a number.
@@ -1138,7 +1194,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
1138
1194
  * @param {number} [defValue] - default value
1139
1195
  * @param {string} [key] - some key
1140
1196
  * @returns {number}
1141
- * @throws {TypeError} if first param is not an object
1197
+ * @throws {TypeError} if `obj` param is not an object
1142
1198
  * @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
1143
1199
  */
1144
1200
  function readXObjAttrAsNum(obj, attr, defValue, key) {
@@ -1157,19 +1213,18 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
1157
1213
  };
1158
1214
  return readAsNumberEx(result, defValue);
1159
1215
  };
1216
+ module.exports.readXObjAttrAsNum = readXObjAttrAsNum;
1160
1217
 
1161
1218
  /**
1162
- * Extracts an attribute from a given object and returns it as a string.
1163
- * @function readXObjAttrEx
1219
+ * Extracts an attribute from a given object and returns it as 'index' value.
1220
+ * @function readXObjAttrAsIndex
1164
1221
  * @param {object} obj - some object
1165
1222
  * @param {string} attr - some attribute
1166
- * @param {object} [opt] - options
1167
1223
  * @param {string} [key] - some key
1168
- * @returns {string}
1169
- * @throws {TypeError} if first param is not an object
1170
- * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
1224
+ * @returns {number}
1225
+ * @throws {TypeError} if `obj` param is not an object
1171
1226
  */
1172
- function readXObjAttrEx(obj, attr, opt, key) {
1227
+ function readXObjAttrAsIndex(obj, attr, key) {
1173
1228
  let result = undefined;
1174
1229
  try {
1175
1230
  result = readXObjAttrRaw(obj, attr, key);
@@ -1183,26 +1238,22 @@ function readXObjAttrEx(obj, attr, opt, key) {
1183
1238
  }
1184
1239
  };
1185
1240
  };
1186
- /** @type {OPT_valtostr} */
1187
- const _opt = isPlainObject(opt) ? opt : {
1188
- useTrim: true,
1189
- numberToString: true,
1190
- boolToString: true,
1191
- defValue: opt,
1192
- };
1193
- return readAsString(result, _opt);
1241
+ return valueToIndex(result);
1194
1242
  };
1243
+ module.exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
1195
1244
 
1196
1245
  /**
1197
- * Extracts an attribute from a given object and returns it as 'index' value.
1198
- * @function readXObjAttrAsIndex
1246
+ * Extracts an attribute from a given object and returns it as a string.
1247
+ * @function readXObjAttrEx
1199
1248
  * @param {object} obj - some object
1200
1249
  * @param {string} attr - some attribute
1250
+ * @param {object} [opt] - options
1201
1251
  * @param {string} [key] - some key
1202
- * @returns {number}
1203
- * @throws {TypeError} if first param is not an object
1252
+ * @returns {string}
1253
+ * @throws {TypeError} if `obj` param is not an object
1254
+ * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
1204
1255
  */
1205
- function readXObjAttrAsIndex(obj, attr, key) {
1256
+ function readXObjAttrEx(obj, attr, opt, key) {
1206
1257
  let result = undefined;
1207
1258
  try {
1208
1259
  result = readXObjAttrRaw(obj, attr, key);
@@ -1216,7 +1267,14 @@ function readXObjAttrAsIndex(obj, attr, key) {
1216
1267
  }
1217
1268
  };
1218
1269
  };
1219
- return valueToIndex(result);
1270
+ /** @type {OPT_valtostr} */
1271
+ const _opt = isPlainObject(opt) ? opt : {
1272
+ useTrim: true,
1273
+ numberToString: true,
1274
+ boolToString: true,
1275
+ defValue: opt,
1276
+ };
1277
+ return readAsString(result, _opt);
1220
1278
  };
1221
1279
 
1222
1280
  /**
@@ -1228,7 +1286,7 @@ function readXObjAttrAsIndex(obj, attr, key) {
1228
1286
  * @param {any} value - some value
1229
1287
  * @param {string} [key] - some key
1230
1288
  * @returns {boolean}
1231
- * @throws {TypeError} if first param is not an object
1289
+ * @throws {TypeError} if `obj` param is not an object
1232
1290
  */
1233
1291
  function writeXObjAttr(obj, attr, value, key) {
1234
1292
  let isSucceed = false;
@@ -1256,7 +1314,7 @@ function writeXObjAttr(obj, attr, value, key) {
1256
1314
  * @param {boolean} [defValue] - default value
1257
1315
  * @param {string} [key] - some key
1258
1316
  * @returns {boolean}
1259
- * @throws {TypeError} if first param is not an object
1317
+ * @throws {TypeError} if `obj` param is not an object
1260
1318
  */
1261
1319
  function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
1262
1320
  let isSucceed = false;
@@ -1277,6 +1335,7 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
1277
1335
  };
1278
1336
  return isSucceed;
1279
1337
  };
1338
+ module.exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
1280
1339
 
1281
1340
  /**
1282
1341
  * Tries to convert a given value to a number and writes it as an attribute
@@ -1288,7 +1347,7 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
1288
1347
  * @param {number} [defValue] - default value
1289
1348
  * @param {string} [key] - some key
1290
1349
  * @returns {boolean}
1291
- * @throws {TypeError} if first param is not an object
1350
+ * @throws {TypeError} if `obj` param is not an object
1292
1351
  */
1293
1352
  function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
1294
1353
  let isSucceed = false;
@@ -1309,6 +1368,7 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
1309
1368
  };
1310
1369
  return isSucceed;
1311
1370
  };
1371
+ module.exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
1312
1372
 
1313
1373
  /**
1314
1374
  * Tries to convert a given value into an 'index' value and writes it
@@ -1319,7 +1379,7 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
1319
1379
  * @param {any} value - some value
1320
1380
  * @param {string} [key] - some key
1321
1381
  * @returns {boolean}
1322
- * @throws {TypeError} if first param is not an object
1382
+ * @throws {TypeError} if `obj` param is not an object
1323
1383
  */
1324
1384
  function writeXObjAttrAsIndex(obj, attr, value, key) {
1325
1385
  let isSucceed = false;
@@ -1340,6 +1400,7 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
1340
1400
  };
1341
1401
  return isSucceed;
1342
1402
  };
1403
+ module.exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
1343
1404
 
1344
1405
  /**
1345
1406
  * Tries to convert a given value to a string and writes it as an attribute
@@ -1351,7 +1412,7 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
1351
1412
  * @param {object} [opt] - options
1352
1413
  * @param {string} [key] - some key
1353
1414
  * @returns {boolean}
1354
- * @throws {TypeError} if first param is not an object
1415
+ * @throws {TypeError} if `obj` param is not an object
1355
1416
  * @todo [since `v0.2.1`] deprecate use of `opt` as `string`
1356
1417
  */
1357
1418
  function writeXObjAttrEx(obj, attr, value, opt, key) {
@@ -1395,7 +1456,8 @@ function writeXObjAttrEx(obj, attr, value, opt, key) {
1395
1456
  * @param {...string} name - some child element name
1396
1457
  * @param {OPT_inselops_L} [opt]
1397
1458
  * @returns {number}
1398
- * @throws {TypeError} if first param is not an object
1459
+ * @throws {TypeError} if `obj` param is not an object
1460
+ * @experimental
1399
1461
  */
1400
1462
  function insertXObjElements(obj, ...args) {
1401
1463
  if (!isPlainObject(obj)) {
@@ -1431,7 +1493,7 @@ function insertXObjElements(obj, ...args) {
1431
1493
  * @param {string} name - some child element name
1432
1494
  * @param {OPT_inselops_S} [opt] - options
1433
1495
  * @returns {?(object|object[])}
1434
- * @throws {TypeError} if first param is not an object
1496
+ * @throws {TypeError} if `obj` param is not an object
1435
1497
  */
1436
1498
  function insertXObjEList(...args) {
1437
1499
  let item = null;
@@ -1459,8 +1521,8 @@ function insertXObjEList(...args) {
1459
1521
  * @param {string} name - some child element name
1460
1522
  * @param {OPT_inselops_S} [opt] - options
1461
1523
  * @returns {RVAL_emodif}
1462
- * @throws {TypeError} if first param is not an object
1463
- * @throws {EvalKeyNameError} if second param is not valid identifier
1524
+ * @throws {TypeError} if `obj` param is not an object
1525
+ * @throws {EvalKeyNameError} if `nmae` param is not valid identifier
1464
1526
  */
1465
1527
  function insertXObjEListEx(obj, name, opt) {
1466
1528
  if (!isPlainObject(obj)) {
@@ -1510,7 +1572,8 @@ function insertXObjEListEx(obj, name, opt) {
1510
1572
  * @param {...string} name - some child element name
1511
1573
  * @param {object} [opt] - options
1512
1574
  * @returns {?any}
1513
- * @throws {TypeError} if first param is not an object
1575
+ * @throws {TypeError} if `obj` param is not an object
1576
+ * @experimental
1514
1577
  */
1515
1578
  function insertXObjEChain(obj, ...args) {
1516
1579
  if (!isPlainObject(obj)) {
@@ -1572,28 +1635,16 @@ module.exports.clearXObjNode = clearXObjNode;
1572
1635
 
1573
1636
  module.exports.readXObjParamRaw = readXObjParamRaw;
1574
1637
  module.exports.readXObjParam = readXObjParam;
1575
- module.exports.readXObjParamAsBool = readXObjParamAsBool;
1576
- module.exports.readXObjParamAsNum = readXObjParamAsNum;
1577
1638
  module.exports.readXObjParamEx = readXObjParamEx;
1578
- module.exports.readXObjParamAsIndex = readXObjParamAsIndex;
1579
1639
  module.exports.writeXObjParamRaw = writeXObjParamRaw;
1580
1640
  module.exports.writeXObjParam = writeXObjParam;
1581
- module.exports.writeXObjParamAsBool = writeXObjParamAsBool;
1582
- module.exports.writeXObjParamAsNum = writeXObjParamAsNum;
1583
- module.exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
1584
1641
  module.exports.writeXObjParamEx = writeXObjParamEx;
1585
1642
 
1586
1643
  module.exports.readXObjAttrRaw = readXObjAttrRaw;
1587
1644
  module.exports.readXObjAttr = readXObjAttr;
1588
- module.exports.readXObjAttrAsBool = readXObjAttrAsBool;
1589
- module.exports.readXObjAttrAsNum = readXObjAttrAsNum;
1590
1645
  module.exports.readXObjAttrEx = readXObjAttrEx;
1591
- module.exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
1592
1646
  module.exports.writeXObjAttrRaw = writeXObjAttrRaw;
1593
1647
  module.exports.writeXObjAttr = writeXObjAttr;
1594
- module.exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
1595
- module.exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
1596
- module.exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
1597
1648
  module.exports.writeXObjAttrEx = writeXObjAttrEx;
1598
1649
 
1599
1650
  module.exports.getXObjAttributes = getXObjAttributes;