@ygracs/xobj-lib-js 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/doc/xObj.md +44 -38
- package/index.d.ts +2 -0
- package/index.js +3 -1
- package/lib/xObj-attr.d.ts +29 -17
- package/lib/xObj-attr.js +43 -20
- package/lib/xObj-lib.d.ts +7 -7
- package/lib/xObj-lib.js +8 -19
- package/lib/xObj-param.d.ts +35 -21
- package/lib/xObj-param.js +41 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.53|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2026-
|
|
3
|
+
>|date:|2026-06-08|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -13,6 +13,7 @@ This paper describes a functions provided by `xObj.js` module.
|
|
|
13
13
|
- Base types
|
|
14
14
|
- <a href="#typedef+xml2jsParseOptions">xml2jsParseOptions</a>
|
|
15
15
|
- <a href="#typedef+js2xmlParseOptions">js2xmlParseOptions</a>
|
|
16
|
+
- <a href="#typedef+INode">INode</a>
|
|
16
17
|
|
|
17
18
|
- Classes
|
|
18
19
|
- <a href="#TXmlContentParseOptions">TXmlContentParseOptions</a>
|
|
@@ -28,6 +29,11 @@ This paper describes a functions provided by `xObj.js` module.
|
|
|
28
29
|
|
|
29
30
|
This section contains some definitions for a general types of the objects (e.g. options set) that frequently used in a function descriptions.
|
|
30
31
|
|
|
32
|
+
<a name="typedef+INode"></a>
|
|
33
|
+
#### `INode` - object type
|
|
34
|
+
|
|
35
|
+
This type is an `object` which represents a base element (so called an `XObj-node`). Its child elements addressed by a `key`. Each `key` is defined by a used parser options and must be a `string`.
|
|
36
|
+
|
|
31
37
|
<a name="typedef+OPT_valtostr"></a>
|
|
32
38
|
#### `OPT_valtostr` - options set
|
|
33
39
|
|
|
@@ -154,7 +160,7 @@ This function returns a value of an object parameter as a string.
|
|
|
154
160
|
|
|
155
161
|
| parameter name | value type | default value | description |
|
|
156
162
|
|:---|---|---:|:---|
|
|
157
|
-
| `object` | `
|
|
163
|
+
| `object` | `INode` | --- | some object |
|
|
158
164
|
| `key` | `string` | --- | some key |
|
|
159
165
|
|
|
160
166
|
##### ***exceptions***
|
|
@@ -173,7 +179,7 @@ This function reads a value of an object parameter and returns it as a `boolean`
|
|
|
173
179
|
|
|
174
180
|
| parameter name | value type | default value | description |
|
|
175
181
|
|:---|---|---:|:---|
|
|
176
|
-
| `object` | `
|
|
182
|
+
| `object` | `INode` | --- | some object |
|
|
177
183
|
| `defValue` | `boolean` | `false` | default value |
|
|
178
184
|
| `key` | `string` | --- | some key |
|
|
179
185
|
|
|
@@ -193,7 +199,7 @@ This function reads a value of an object parameter and returns it as a `number`.
|
|
|
193
199
|
|
|
194
200
|
| parameter name | value type | default value | description |
|
|
195
201
|
|:---|---|---:|:---|
|
|
196
|
-
| `object` | `
|
|
202
|
+
| `object` | `INode` | --- | some object |
|
|
197
203
|
| `defValue` | `number` | `0` | default value |
|
|
198
204
|
| `key` | `string` | --- | some key |
|
|
199
205
|
|
|
@@ -215,7 +221,7 @@ This function reads a value of an object parameter and try to convert it to a va
|
|
|
215
221
|
|
|
216
222
|
| parameter name | value type | default value | description |
|
|
217
223
|
|:---|---|---:|:---|
|
|
218
|
-
| `object` | `
|
|
224
|
+
| `object` | `INode` | --- | some object |
|
|
219
225
|
| `key` | `string` | --- | some key |
|
|
220
226
|
|
|
221
227
|
##### ***exceptions***
|
|
@@ -236,7 +242,7 @@ This function reads a value of an object parameter and returns it as a `string`.
|
|
|
236
242
|
|
|
237
243
|
| parameter name | value type | default value | description |
|
|
238
244
|
|:---|---|---:|:---|
|
|
239
|
-
| `object` | `
|
|
245
|
+
| `object` | `INode` | --- | some object |
|
|
240
246
|
| `options` | `string`, `object` | --- | options that defines how a value must be transformed |
|
|
241
247
|
| `key` | `string` | --- | some key |
|
|
242
248
|
|
|
@@ -279,7 +285,7 @@ This function sets object parameter to a given value and if succeed returns `tru
|
|
|
279
285
|
|
|
280
286
|
| parameter name | value type | default value | description |
|
|
281
287
|
|:---|---|---:|:---|
|
|
282
|
-
| `object` | `
|
|
288
|
+
| `object` | `INode` | --- | some object |
|
|
283
289
|
| `value` | `any` | --- | some value to write |
|
|
284
290
|
| `key` | `string` | --- | some key |
|
|
285
291
|
|
|
@@ -299,7 +305,7 @@ This function writes a given `boolean` value of an object parameter.
|
|
|
299
305
|
|
|
300
306
|
| parameter name | value type | default value | description |
|
|
301
307
|
|:---|---|---:|:---|
|
|
302
|
-
| `object` | `
|
|
308
|
+
| `object` | `INode` | --- | some object |
|
|
303
309
|
| `value` | `any` | --- | some value to write |
|
|
304
310
|
| `defValue` | `boolean` | `false` | default value |
|
|
305
311
|
| `key` | `string` | --- | some key |
|
|
@@ -320,7 +326,7 @@ This function writes a given `number` value of an object parameter.
|
|
|
320
326
|
|
|
321
327
|
| parameter name | value type | default value | description |
|
|
322
328
|
|:---|---|---:|:---|
|
|
323
|
-
| `object` | `
|
|
329
|
+
| `object` | `INode` | --- | some object |
|
|
324
330
|
| `value` | `any` | --- | some value to write |
|
|
325
331
|
| `defValue` | `number` | `0` | default value |
|
|
326
332
|
| `key` | `string` | --- | some key |
|
|
@@ -341,7 +347,7 @@ This function try to interpret a given value as a valid index value and, if succ
|
|
|
341
347
|
|
|
342
348
|
| parameter name | value type | default value | description |
|
|
343
349
|
|:---|---|---:|:---|
|
|
344
|
-
| `object` | `
|
|
350
|
+
| `object` | `INode` | --- | some object |
|
|
345
351
|
| `value` | `any` | --- | some value to write |
|
|
346
352
|
| `key` | `string` | --- | some key |
|
|
347
353
|
|
|
@@ -361,7 +367,7 @@ This function sets object parameter to a given value and if succeed returns `tru
|
|
|
361
367
|
|
|
362
368
|
| parameter name | value type | default value | description |
|
|
363
369
|
|:---|---|---:|:---|
|
|
364
|
-
| `object` | `
|
|
370
|
+
| `object` | `INode` | --- | some object |
|
|
365
371
|
| `value` | `any` | --- | some value to write |
|
|
366
372
|
| `options` | `string`, `object` | --- | options that defines how a value must be transformed |
|
|
367
373
|
| `key` | `string` | --- | some key |
|
|
@@ -405,7 +411,7 @@ This function returns a value of an object attribute. The value is of a `string`
|
|
|
405
411
|
|
|
406
412
|
| parameter name | value type | default value | description |
|
|
407
413
|
|:---|---|---:|:---|
|
|
408
|
-
| `object` | `
|
|
414
|
+
| `object` | `INode` | --- | some object |
|
|
409
415
|
| `attr` | `string` | --- | some attribute |
|
|
410
416
|
| `key` | `string` | --- | some key |
|
|
411
417
|
|
|
@@ -425,7 +431,7 @@ This function reads a value of an object attribute and returns it as a `boolean`
|
|
|
425
431
|
|
|
426
432
|
| parameter name | value type | default value | description |
|
|
427
433
|
|:---|---|---:|:---|
|
|
428
|
-
| `object` | `
|
|
434
|
+
| `object` | `INode` | --- | some object |
|
|
429
435
|
| `attr` | `string` | --- | some attribute |
|
|
430
436
|
| `defValue` | `boolean` | `false` | default value |
|
|
431
437
|
| `key` | `string` | --- | some key |
|
|
@@ -446,7 +452,7 @@ This function reads a value of an object attribute and returns it as a `number`.
|
|
|
446
452
|
|
|
447
453
|
| parameter name | value type | default value | description |
|
|
448
454
|
|:---|---|---:|:---|
|
|
449
|
-
| `object` | `
|
|
455
|
+
| `object` | `INode` | --- | some object |
|
|
450
456
|
| `attr` | `string` | --- | some attribute |
|
|
451
457
|
| `defValue` | `number` | `0` | default value |
|
|
452
458
|
| `key` | `string` | --- | some key |
|
|
@@ -469,7 +475,7 @@ This function reads a value of an object attribute and try to convert it to a va
|
|
|
469
475
|
|
|
470
476
|
| parameter name | value type | default value | description |
|
|
471
477
|
|:---|---|---:|:---|
|
|
472
|
-
| `object` | `
|
|
478
|
+
| `object` | `INode` | --- | some object |
|
|
473
479
|
| `attr` | `string` | --- | some attribute |
|
|
474
480
|
| `key` | `string` | --- | some key |
|
|
475
481
|
|
|
@@ -491,7 +497,7 @@ This function returns a value of an object attribute. The value is of a `string`
|
|
|
491
497
|
|
|
492
498
|
| parameter name | value type | default value | description |
|
|
493
499
|
|:---|---|---:|:---|
|
|
494
|
-
| `object` | `
|
|
500
|
+
| `object` | `INode` | --- | some object |
|
|
495
501
|
| `attr` | `string` | --- | some attribute |
|
|
496
502
|
| `options` | `string`, `object` | --- | options that defines how a value must be transformed |
|
|
497
503
|
| `key` | `string` | --- | some key |
|
|
@@ -535,7 +541,7 @@ This function sets object attribute to a given value and if succeed returns `tru
|
|
|
535
541
|
|
|
536
542
|
| parameter name | value type | default value | description |
|
|
537
543
|
|:---|---|---:|:---|
|
|
538
|
-
| `object` | `
|
|
544
|
+
| `object` | `INode` | --- | some object |
|
|
539
545
|
| `attr` | `string` | --- | some attribute |
|
|
540
546
|
| `value` | `any` | --- | some value |
|
|
541
547
|
| `key` | `string` | --- | some key |
|
|
@@ -558,7 +564,7 @@ This function writes a given `boolean` value of an object attribute.
|
|
|
558
564
|
|
|
559
565
|
| parameter name | value type | default value | description |
|
|
560
566
|
|:---|---|---:|:---|
|
|
561
|
-
| `object` | `
|
|
567
|
+
| `object` | `INode` | --- | some object |
|
|
562
568
|
| `attr` | `string` | --- | some attribute |
|
|
563
569
|
| `value` | `any` | --- | some value |
|
|
564
570
|
| `defValue` | `boolean` | `false` | default value |
|
|
@@ -580,7 +586,7 @@ This function writes a given `number` value of an object attribute.
|
|
|
580
586
|
|
|
581
587
|
| parameter name | value type | default value | description |
|
|
582
588
|
|:---|---|---:|:---|
|
|
583
|
-
| `object` | `
|
|
589
|
+
| `object` | `INode` | --- | some object |
|
|
584
590
|
| `attr` | `string` | --- | some attribute |
|
|
585
591
|
| `value` | `any` | --- | some value |
|
|
586
592
|
| `defValue` | `number` | `0` | default value |
|
|
@@ -602,7 +608,7 @@ This function try to interpret a given value as a valid index value and, if succ
|
|
|
602
608
|
|
|
603
609
|
| parameter name | value type | default value | description |
|
|
604
610
|
|:---|---|---:|:---|
|
|
605
|
-
| `object` | `
|
|
611
|
+
| `object` | `INode` | --- | some object |
|
|
606
612
|
| `attr` | `string` | --- | some attribute |
|
|
607
613
|
| `value` | `any` | --- | some value |
|
|
608
614
|
| `key` | `string` | --- | some key |
|
|
@@ -623,7 +629,7 @@ This function sets object attribute to a given value and if succeed returns `tru
|
|
|
623
629
|
|
|
624
630
|
| parameter name | value type | default value | description |
|
|
625
631
|
|:---|---|---:|:---|
|
|
626
|
-
| `object` | `
|
|
632
|
+
| `object` | `INode` | --- | some object |
|
|
627
633
|
| `attr` | `string` | --- | some attribute |
|
|
628
634
|
| `value` | `any` | --- | some value |
|
|
629
635
|
| `options` | `string`, `object` | --- | options that defines how a value must be transformed |
|
|
@@ -664,7 +670,7 @@ This is a special function that returns a value of an object parameter as "IT IS
|
|
|
664
670
|
|
|
665
671
|
| parameter name | value type | default value | description |
|
|
666
672
|
|:---|---|---:|:---|
|
|
667
|
-
| `object` | `
|
|
673
|
+
| `object` | `INode` | --- | some object |
|
|
668
674
|
| `key` | `string` | --- | some key |
|
|
669
675
|
|
|
670
676
|
> NOTE:
|
|
@@ -691,7 +697,7 @@ This is a special function that writes a given value of an object parameter as "
|
|
|
691
697
|
|
|
692
698
|
| parameter name | value type | default value | description |
|
|
693
699
|
|:---|---|---:|:---|
|
|
694
|
-
| `object` | `
|
|
700
|
+
| `object` | `INode` | --- | some object |
|
|
695
701
|
| `value` | `any` | --- | some value |
|
|
696
702
|
| `key` | `string` | --- | some key |
|
|
697
703
|
|
|
@@ -722,7 +728,7 @@ This is a special function that returns a value of an object attribute as "IT IS
|
|
|
722
728
|
|
|
723
729
|
| parameter name | value type | default value | description |
|
|
724
730
|
|:---|---|---:|:---|
|
|
725
|
-
| `object` | `
|
|
731
|
+
| `object` | `INode` | --- | some object |
|
|
726
732
|
| `attr` | `string` | --- | some attribute |
|
|
727
733
|
| `key` | `string` | --- | some key |
|
|
728
734
|
|
|
@@ -751,7 +757,7 @@ This is a special function that writes a given value of an object attribute as "
|
|
|
751
757
|
|
|
752
758
|
| parameter name | value type | default value | description |
|
|
753
759
|
|:---|---|---:|:---|
|
|
754
|
-
| `object` | `
|
|
760
|
+
| `object` | `INode` | --- | some object |
|
|
755
761
|
| `attr` | `string` | --- | some attribute |
|
|
756
762
|
| `value` | `any` | --- | some value |
|
|
757
763
|
| `key` | `string` | --- | some key |
|
|
@@ -779,7 +785,7 @@ The function throws a `EvalKeyNameError` exception in case:
|
|
|
779
785
|
> If a `key` parameter given not given, the function will use a default value defined by `XOBJ_DEF_ATTR_TNAME`.
|
|
780
786
|
|
|
781
787
|
<a name="getXObjAttributes"></a>
|
|
782
|
-
#### **getXObjAttributes(object\[, key])** => `?
|
|
788
|
+
#### **getXObjAttributes(object\[, key])** => `?INode`
|
|
783
789
|
|
|
784
790
|
This function returns an object which represents a set of the element attributes for a given object or `null` if failed.
|
|
785
791
|
|
|
@@ -787,7 +793,7 @@ This function returns an object which represents a set of the element attributes
|
|
|
787
793
|
|
|
788
794
|
| parameter name | value type | default value | description |
|
|
789
795
|
|:---|---|---:|:---|
|
|
790
|
-
| `object` | `
|
|
796
|
+
| `object` | `INode` | --- | some object |
|
|
791
797
|
| `key` | `string` | --- | some key |
|
|
792
798
|
|
|
793
799
|
##### ***exceptions***
|
|
@@ -806,7 +812,7 @@ This function tries to check whether or not an attribute with a name given by `a
|
|
|
806
812
|
|
|
807
813
|
| parameter name | value type | default value | description |
|
|
808
814
|
|:---|---|---:|:---|
|
|
809
|
-
| `object` | `
|
|
815
|
+
| `object` | `INode` | --- | some object |
|
|
810
816
|
| `attr` | `string` | --- | some attribute |
|
|
811
817
|
| `key` | `string` | --- | some key |
|
|
812
818
|
|
|
@@ -832,7 +838,7 @@ This function tries to delete an attribute with a name given by `attr` paramete
|
|
|
832
838
|
|
|
833
839
|
| parameter name | value type | default value | description |
|
|
834
840
|
|:---|---|---:|:---|
|
|
835
|
-
| `object` | `
|
|
841
|
+
| `object` | `INode` | --- | some object |
|
|
836
842
|
| `attr` | `string` | --- | some attribute |
|
|
837
843
|
| `key` | `string` | --- | some key |
|
|
838
844
|
|
|
@@ -860,7 +866,7 @@ This function tries to rename an attribute with a name given by `attr` parameter
|
|
|
860
866
|
|
|
861
867
|
| parameter name | value type | default value | description |
|
|
862
868
|
|:---|---|---:|:---|
|
|
863
|
-
| `object` | `
|
|
869
|
+
| `object` | `INode` | --- | some object |
|
|
864
870
|
| `attr` | `string` | --- | some attribute |
|
|
865
871
|
| `value` | `string` | --- | new attribute ID |
|
|
866
872
|
| `key` | `string` | --- | some key |
|
|
@@ -890,7 +896,7 @@ This function returns an element from a given object by its name or `null` if th
|
|
|
890
896
|
|
|
891
897
|
| parameter name | value type | default value | description |
|
|
892
898
|
|:---|---|---:|:---|
|
|
893
|
-
| `object` | `
|
|
899
|
+
| `object` | `INode` | --- | some object |
|
|
894
900
|
| `name` | `string` | --- | some child element ID |
|
|
895
901
|
|
|
896
902
|
##### ***exceptions***
|
|
@@ -937,7 +943,7 @@ This function adds an element given by `name` parameter to a members of the give
|
|
|
937
943
|
|
|
938
944
|
| parameter name | value type | default value | description |
|
|
939
945
|
|:---|---|---:|:---|
|
|
940
|
-
| `object` | `
|
|
946
|
+
| `object` | `INode` | --- | some object |
|
|
941
947
|
| `name` | `string` | --- | some child element ID |
|
|
942
948
|
|
|
943
949
|
##### ***result***
|
|
@@ -996,7 +1002,7 @@ This function inserts an empty element named by a `name` parameter into a given
|
|
|
996
1002
|
|
|
997
1003
|
| parameter name | value type | default value | description |
|
|
998
1004
|
|:---|---|---:|:---|
|
|
999
|
-
| `object` | `
|
|
1005
|
+
| `object` | `INode` | --- | some object |
|
|
1000
1006
|
| `name` | `string` | --- | some child element ID |
|
|
1001
1007
|
| `options` | `object` | --- | options |
|
|
1002
1008
|
|
|
@@ -1063,7 +1069,7 @@ This function deletes an element addressed by `name` parameter from a given obje
|
|
|
1063
1069
|
|
|
1064
1070
|
| parameter name | value type | default value | description |
|
|
1065
1071
|
|:---|---|---:|:---|
|
|
1066
|
-
| `object` | `
|
|
1072
|
+
| `object` | `INode` | --- | some object |
|
|
1067
1073
|
| `name` | `string` | --- | some child element ID |
|
|
1068
1074
|
|
|
1069
1075
|
##### ***result***
|
|
@@ -1096,7 +1102,7 @@ This function renames an element addressed by `name` for the given object. If su
|
|
|
1096
1102
|
|
|
1097
1103
|
| parameter name | value type | default value | description |
|
|
1098
1104
|
|:---|---|---:|:---|
|
|
1099
|
-
| `object` | `
|
|
1105
|
+
| `object` | `INode` | --- | some object |
|
|
1100
1106
|
| `name` | `string` | --- | some child element ID |
|
|
1101
1107
|
| `value` | `string` | --- | new element ID |
|
|
1102
1108
|
|
|
@@ -1124,7 +1130,7 @@ This function tries to clean a given node.
|
|
|
1124
1130
|
|
|
1125
1131
|
| parameter name | value type | default value | description |
|
|
1126
1132
|
|:---|---|---:|:---|
|
|
1127
|
-
| `node` | `
|
|
1133
|
+
| `node` | `INode` or `INode[]` | --- | some node or nodes list |
|
|
1128
1134
|
|
|
1129
1135
|
##### ***exceptions***
|
|
1130
1136
|
|
|
@@ -1189,7 +1195,7 @@ This function inserts an elements list named by a `name` parameter into a given
|
|
|
1189
1195
|
|
|
1190
1196
|
| parameter name | value type | default value | description |
|
|
1191
1197
|
|:---|---|---:|:---|
|
|
1192
|
-
| `object` | `
|
|
1198
|
+
| `object` | `INode` | --- | some object |
|
|
1193
1199
|
| `name` | `string` | --- | some child element ID |
|
|
1194
1200
|
| `options` | `object` | --- | options |
|
|
1195
1201
|
|
package/index.d.ts
CHANGED
|
@@ -104,6 +104,7 @@ import type {
|
|
|
104
104
|
RVAL_emodif,
|
|
105
105
|
VCOR_evalkname, RVAL_reason,
|
|
106
106
|
IEvalKeyNameResult,
|
|
107
|
+
INode,
|
|
107
108
|
} from "./lib/xObj-lib";
|
|
108
109
|
|
|
109
110
|
export type {
|
|
@@ -112,4 +113,5 @@ export type {
|
|
|
112
113
|
RVAL_emodif,
|
|
113
114
|
VCOR_evalkname, RVAL_reason,
|
|
114
115
|
IEvalKeyNameResult,
|
|
116
|
+
INode,
|
|
115
117
|
};
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.017-20260606]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -77,3 +77,5 @@ module.exports.insertXObjEListEx = xObj.insertXObjEListEx;
|
|
|
77
77
|
module.exports.genXObjENameDescr = xObj.genXObjENameDescr;
|
|
78
78
|
module.exports.insertXObjElements = xObj.insertXObjElements;
|
|
79
79
|
module.exports.insertXObjEChain = xObj.insertXObjEChain;
|
|
80
|
+
|
|
81
|
+
module.exports.INode = xObj.INode;
|
package/lib/xObj-attr.d.ts
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated
|
|
3
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
4
|
+
*/
|
|
5
|
+
export type readXObjAttrOptionAsStr = string;
|
|
6
|
+
export const readXObjAttrOptionAsStr: readXObjAttrOptionAsStr;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
10
|
+
*/
|
|
11
|
+
export type writeXObjAttrOptionAsStr = string;
|
|
12
|
+
export const writeXObjAttrOptionAsStr: writeXObjAttrOptionAsStr;
|
|
1
13
|
/**
|
|
2
14
|
* Extracts an attributes from a given object by its key.
|
|
3
15
|
* @throws {TypeError} if `obj` param is not an object
|
|
4
16
|
*/
|
|
5
|
-
export function getXObjAttributes(obj:
|
|
17
|
+
export function getXObjAttributes(obj: INode, key?: string): INode | null;
|
|
6
18
|
/**
|
|
7
19
|
* Checks whether an attribute is exists.
|
|
8
20
|
* @throws {TypeError} if `obj` param is not an object
|
|
9
21
|
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
10
22
|
*/
|
|
11
|
-
export function checkXObjAttribute(obj:
|
|
23
|
+
export function checkXObjAttribute(obj: INode, attr?: string, key?: string): boolean;
|
|
12
24
|
/**
|
|
13
25
|
* Deletes an attribute addressed by a given name.
|
|
14
26
|
* @throws {TypeError} if `obj` param is not an object
|
|
15
27
|
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
16
28
|
*/
|
|
17
|
-
export function deleteXObjAttribute(obj:
|
|
29
|
+
export function deleteXObjAttribute(obj: INode, attr?: string, key?: string): boolean;
|
|
18
30
|
/**
|
|
19
31
|
* Renames an attribute addressed by a given name.
|
|
20
32
|
* @since 0.2.0
|
|
@@ -23,75 +35,75 @@ export function deleteXObjAttribute(obj: object, attr?: string, key?: string): b
|
|
|
23
35
|
* @throws {EvalKeyNameError} if `value` param is not valid identifier
|
|
24
36
|
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
25
37
|
*/
|
|
26
|
-
export function renameXObjAttribute(obj:
|
|
38
|
+
export function renameXObjAttribute(obj: INode, attr?: string, value?: string, key?: string): boolean;
|
|
27
39
|
/**
|
|
28
40
|
* Extracts an attribute 'AS IS' from a given object.
|
|
29
41
|
* @throws {TypeError} if `obj` param is not an object
|
|
30
42
|
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
31
43
|
*/
|
|
32
|
-
export function readXObjAttrRaw(obj:
|
|
44
|
+
export function readXObjAttrRaw(obj: INode, attr?: string, key?: string): any;
|
|
33
45
|
/**
|
|
34
46
|
* Writes a parameter into a given object.
|
|
35
47
|
* @throws {TypeError} if `obj` param is not an object
|
|
36
48
|
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
37
49
|
*/
|
|
38
|
-
export function writeXObjAttrRaw(obj:
|
|
50
|
+
export function writeXObjAttrRaw(obj: INode, attr: string, value: any, key?: string): boolean;
|
|
39
51
|
/**
|
|
40
52
|
* Extracts an attribute from a given object and returns it as a string.
|
|
41
53
|
* @throws {TypeError} if `obj` param is not an object
|
|
42
54
|
*/
|
|
43
|
-
export function readXObjAttr(obj:
|
|
55
|
+
export function readXObjAttr(obj: INode, attr: string, key?: string): string;
|
|
44
56
|
/**
|
|
45
57
|
* Extracts an attribute from a given object and returns it as a boolean.
|
|
46
58
|
* @throws {TypeError} if `obj` param is not an object
|
|
47
59
|
*/
|
|
48
|
-
export function readXObjAttrAsBool(obj:
|
|
60
|
+
export function readXObjAttrAsBool(obj: INode, attr: string, defValue?: boolean, key?: string): boolean;
|
|
49
61
|
/**
|
|
50
62
|
* Extracts an attribute from a given object and returns it as a number.
|
|
51
|
-
* @returns {number}
|
|
52
63
|
* @throws {TypeError} if `obj` param is not an object
|
|
53
64
|
*/
|
|
54
|
-
export function readXObjAttrAsNum(obj:
|
|
65
|
+
export function readXObjAttrAsNum(obj: INode, attr: string, defValue?: number, key?: string): number;
|
|
55
66
|
/**
|
|
56
67
|
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
57
68
|
* @throws {TypeError} if `obj` param is not an object
|
|
58
69
|
*/
|
|
59
|
-
export function readXObjAttrAsIndex(obj:
|
|
70
|
+
export function readXObjAttrAsIndex(obj: INode, attr: string, key?: string): number;
|
|
60
71
|
/**
|
|
61
72
|
* Extracts an attribute from a given object and returns it as a string.
|
|
62
73
|
* @throws {TypeError} if `obj` param is not an object
|
|
63
74
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
64
75
|
*/
|
|
65
|
-
export function readXObjAttrEx(obj:
|
|
76
|
+
export function readXObjAttrEx(obj: INode, attr: string, opt?: readXObjAttrOptionAsStr | IValueToStringTransformOptions, key?: string): string;
|
|
66
77
|
/**
|
|
67
78
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
68
79
|
* into a given object.
|
|
69
80
|
* @throws {TypeError} if `obj` param is not an object
|
|
70
81
|
*/
|
|
71
|
-
export function writeXObjAttr(obj:
|
|
82
|
+
export function writeXObjAttr(obj: INode, attr: string, value: any, key?: string): boolean;
|
|
72
83
|
/**
|
|
73
84
|
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
74
85
|
* into a given object.
|
|
75
86
|
* @throws {TypeError} if `obj` param is not an object
|
|
76
87
|
*/
|
|
77
|
-
export function writeXObjAttrAsBool(obj:
|
|
88
|
+
export function writeXObjAttrAsBool(obj: INode, attr: string, value: any, defValue?: boolean, key?: string): boolean;
|
|
78
89
|
/**
|
|
79
90
|
* Tries to convert a given value to a number and writes it as an attribute
|
|
80
91
|
* into a given object.
|
|
81
92
|
* @throws {TypeError} if `obj` param is not an object
|
|
82
93
|
*/
|
|
83
|
-
export function writeXObjAttrAsNum(obj:
|
|
94
|
+
export function writeXObjAttrAsNum(obj: INode, attr: string, value: any, defValue?: number, key?: string): boolean;
|
|
84
95
|
/**
|
|
85
96
|
* Tries to convert a given value into an 'index' value and writes it
|
|
86
97
|
* as an attribute into a given object.
|
|
87
98
|
* @throws {TypeError} if `obj` param is not an object
|
|
88
99
|
*/
|
|
89
|
-
export function writeXObjAttrAsIndex(obj:
|
|
100
|
+
export function writeXObjAttrAsIndex(obj: INode, attr: string, value: any, key?: string): boolean;
|
|
90
101
|
/**
|
|
91
102
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
92
103
|
* into a given object.
|
|
93
104
|
* @throws {TypeError} if `obj` param is not an object
|
|
94
105
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
95
106
|
*/
|
|
96
|
-
export function writeXObjAttrEx(obj:
|
|
107
|
+
export function writeXObjAttrEx(obj: INode, attr: string, value: any, opt?: writeXObjAttrOptionAsStr | IValueToStringTransformOptions, key?: string): boolean;
|
|
97
108
|
import type { INode } from "./xObj-lib";
|
|
109
|
+
import type { IValueToStringTransformOptions } from "@ygracs/bsfoc-lib-js";
|
package/lib/xObj-attr.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.140-20260607]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -44,7 +44,7 @@ const {
|
|
|
44
44
|
/**
|
|
45
45
|
* Extracts an attributes from a given object by its key.
|
|
46
46
|
* @function getXObjAttributes
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {INode} obj - some object
|
|
48
48
|
* @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
|
|
49
49
|
* @returns {?INode}
|
|
50
50
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -71,7 +71,7 @@ module.exports.getXObjAttributes = getXObjAttributes;
|
|
|
71
71
|
/**
|
|
72
72
|
* Checks whether an attribute is exists.
|
|
73
73
|
* @function checkXObjAttribute
|
|
74
|
-
* @param {
|
|
74
|
+
* @param {INode} obj - some object
|
|
75
75
|
* @param {string} attr - some attribute ID
|
|
76
76
|
* @param {string} [key] - some key
|
|
77
77
|
* @returns {boolean}
|
|
@@ -101,7 +101,7 @@ module.exports.checkXObjAttribute = checkXObjAttribute;
|
|
|
101
101
|
/**
|
|
102
102
|
* Deletes an attribute addressed by a given name.
|
|
103
103
|
* @function deleteXObjAttribute
|
|
104
|
-
* @param {
|
|
104
|
+
* @param {INode} obj - some object
|
|
105
105
|
* @param {string} attr - some attribute ID
|
|
106
106
|
* @param {string} [key] - some key
|
|
107
107
|
* @returns {boolean}
|
|
@@ -136,7 +136,7 @@ module.exports.deleteXObjAttribute = deleteXObjAttribute;
|
|
|
136
136
|
* Renames an attribute addressed by a given name.
|
|
137
137
|
* @since 0.2.0
|
|
138
138
|
* @function renameXObjAttribute
|
|
139
|
-
* @param {
|
|
139
|
+
* @param {INode} obj - some object
|
|
140
140
|
* @param {string} attr - some attribute ID
|
|
141
141
|
* @param {string} value - new attribute ID
|
|
142
142
|
* @param {string} [key] - some key
|
|
@@ -192,7 +192,7 @@ module.exports.renameXObjAttribute = renameXObjAttribute;
|
|
|
192
192
|
/**
|
|
193
193
|
* Extracts an attribute 'AS IS' from a given object.
|
|
194
194
|
* @function readXObjAttrRaw
|
|
195
|
-
* @param {
|
|
195
|
+
* @param {INode} obj - some object
|
|
196
196
|
* @param {string} attr - some attribute
|
|
197
197
|
* @param {string} [key] - some key
|
|
198
198
|
* @returns {any}
|
|
@@ -222,7 +222,7 @@ module.exports.readXObjAttrRaw = readXObjAttrRaw;
|
|
|
222
222
|
/**
|
|
223
223
|
* Writes a parameter into a given object.
|
|
224
224
|
* @function writeXObjAttrRaw
|
|
225
|
-
* @param {
|
|
225
|
+
* @param {INode} obj - some object
|
|
226
226
|
* @param {string} attr - some attribute
|
|
227
227
|
* @param {any} value - some value
|
|
228
228
|
* @param {string} [key=XOBJ_DEF_ATTR_TNAME] - some key
|
|
@@ -272,7 +272,7 @@ module.exports.writeXObjAttrRaw = writeXObjAttrRaw;
|
|
|
272
272
|
/**
|
|
273
273
|
* Extracts an attribute from a given object and returns it as a string.
|
|
274
274
|
* @function readXObjAttr
|
|
275
|
-
* @param {
|
|
275
|
+
* @param {INode} obj - some object
|
|
276
276
|
* @param {string} attr - some attribute
|
|
277
277
|
* @param {string} [key] - some key
|
|
278
278
|
* @returns {string}
|
|
@@ -298,7 +298,7 @@ module.exports.readXObjAttr = readXObjAttr;
|
|
|
298
298
|
/**
|
|
299
299
|
* Extracts an attribute from a given object and returns it as a boolean.
|
|
300
300
|
* @function readXObjAttrAsBool
|
|
301
|
-
* @param {
|
|
301
|
+
* @param {INode} obj - some object
|
|
302
302
|
* @param {string} attr - some attribute
|
|
303
303
|
* @param {boolean} [defValue] - default value
|
|
304
304
|
* @param {string} [key] - some key
|
|
@@ -327,7 +327,7 @@ module.exports.readXObjAttrAsBool = readXObjAttrAsBool;
|
|
|
327
327
|
/**
|
|
328
328
|
* Extracts an attribute from a given object and returns it as a number.
|
|
329
329
|
* @function readXObjAttrAsNum
|
|
330
|
-
* @param {
|
|
330
|
+
* @param {INode} obj - some object
|
|
331
331
|
* @param {string} attr - some attribute
|
|
332
332
|
* @param {number} [defValue] - default value
|
|
333
333
|
* @param {string} [key] - some key
|
|
@@ -356,7 +356,7 @@ module.exports.readXObjAttrAsNum = readXObjAttrAsNum;
|
|
|
356
356
|
/**
|
|
357
357
|
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
358
358
|
* @function readXObjAttrAsIndex
|
|
359
|
-
* @param {
|
|
359
|
+
* @param {INode} obj - some object
|
|
360
360
|
* @param {string} attr - some attribute
|
|
361
361
|
* @param {string} [key] - some key
|
|
362
362
|
* @returns {number}
|
|
@@ -380,12 +380,24 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
380
380
|
};
|
|
381
381
|
module.exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
|
|
382
382
|
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
* @typedef {string} readXObjAttrOptionAsStr
|
|
386
|
+
* @deprecated
|
|
387
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
388
|
+
*/
|
|
389
|
+
/**
|
|
390
|
+
* A virtual constant meant for support jsdoc notation:
|
|
391
|
+
* @type {readXObjAttrOptionAsStr}
|
|
392
|
+
*/
|
|
393
|
+
module.exports.readXObjAttrOptionAsStr = '';
|
|
394
|
+
|
|
383
395
|
/**
|
|
384
396
|
* Extracts an attribute from a given object and returns it as a string.
|
|
385
397
|
* @function readXObjAttrEx
|
|
386
|
-
* @param {
|
|
398
|
+
* @param {INode} obj - some object
|
|
387
399
|
* @param {string} attr - some attribute
|
|
388
|
-
* @param {
|
|
400
|
+
* @param {readXObjAttrOptionAsStr|IValueToStringTransformOptions} [opt] - options
|
|
389
401
|
* @param {string} [key] - some key
|
|
390
402
|
* @returns {string}
|
|
391
403
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -405,7 +417,6 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
405
417
|
}
|
|
406
418
|
};
|
|
407
419
|
};
|
|
408
|
-
/** @type {IValueToStringTransformOptions} */
|
|
409
420
|
const _opt = isPlainObject(opt) ? opt : {
|
|
410
421
|
useTrim: true,
|
|
411
422
|
numberToString: true,
|
|
@@ -420,7 +431,7 @@ module.exports.readXObjAttrEx = readXObjAttrEx;
|
|
|
420
431
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
421
432
|
* into a given object.
|
|
422
433
|
* @function writeXObjAttr
|
|
423
|
-
* @param {
|
|
434
|
+
* @param {INode} obj - some object
|
|
424
435
|
* @param {string} attr - some attribute
|
|
425
436
|
* @param {any} value - some value
|
|
426
437
|
* @param {string} [key] - some key
|
|
@@ -448,7 +459,7 @@ module.exports.writeXObjAttr = writeXObjAttr;
|
|
|
448
459
|
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
449
460
|
* into a given object.
|
|
450
461
|
* @function writeXObjAttrAsBool
|
|
451
|
-
* @param {
|
|
462
|
+
* @param {INode} obj - some object
|
|
452
463
|
* @param {string} attr - some attribute
|
|
453
464
|
* @param {any} value - some value
|
|
454
465
|
* @param {boolean} [defValue] - default value
|
|
@@ -481,7 +492,7 @@ module.exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
|
|
|
481
492
|
* Tries to convert a given value to a number and writes it as an attribute
|
|
482
493
|
* into a given object.
|
|
483
494
|
* @function writeXObjAttrAsNum
|
|
484
|
-
* @param {
|
|
495
|
+
* @param {INode} obj - some object
|
|
485
496
|
* @param {string} attr - some attribute
|
|
486
497
|
* @param {any} value - some value
|
|
487
498
|
* @param {number} [defValue] - default value
|
|
@@ -514,7 +525,7 @@ module.exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
|
|
|
514
525
|
* Tries to convert a given value into an 'index' value and writes it
|
|
515
526
|
* as an attribute into a given object.
|
|
516
527
|
* @function writeXObjAttrAsIndex
|
|
517
|
-
* @param {
|
|
528
|
+
* @param {INode} obj - some object
|
|
518
529
|
* @param {string} attr - some attribute
|
|
519
530
|
* @param {any} value - some value
|
|
520
531
|
* @param {string} [key] - some key
|
|
@@ -542,14 +553,26 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
542
553
|
};
|
|
543
554
|
module.exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
|
|
544
555
|
|
|
556
|
+
/**
|
|
557
|
+
*
|
|
558
|
+
* @typedef {string} writeXObjAttrOptionAsStr
|
|
559
|
+
* @deprecated
|
|
560
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
561
|
+
*/
|
|
562
|
+
/**
|
|
563
|
+
* A virtual constant meant for support jsdoc notation:
|
|
564
|
+
* @type {writeXObjAttrOptionAsStr}
|
|
565
|
+
*/
|
|
566
|
+
module.exports.writeXObjAttrOptionAsStr = '';
|
|
567
|
+
|
|
545
568
|
/**
|
|
546
569
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
547
570
|
* into a given object.
|
|
548
571
|
* @function writeXObjAttrEx
|
|
549
|
-
* @param {
|
|
572
|
+
* @param {INode} obj - some object
|
|
550
573
|
* @param {string} attr - some attribute
|
|
551
574
|
* @param {any} value - some value
|
|
552
|
-
* @param {
|
|
575
|
+
* @param {writeXObjAttrOptionAsStr|IValueToStringTransformOptions} [opt] - options
|
|
553
576
|
* @param {string} [key] - some key
|
|
554
577
|
* @returns {boolean}
|
|
555
578
|
* @throws {TypeError} if `obj` param is not an object
|
package/lib/xObj-lib.d.ts
CHANGED
|
@@ -196,7 +196,7 @@ export function evalKeyName(value: any, opt?: boolean | IEvalKeyNameOptions): IE
|
|
|
196
196
|
* @throws {TypeError} if `obj` param is not an object
|
|
197
197
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
198
198
|
*/
|
|
199
|
-
export function getXObjElement(obj:
|
|
199
|
+
export function getXObjElement(obj: INode, name: string): any | null;
|
|
200
200
|
/**
|
|
201
201
|
* Adds an element addressed by its key to a given object.
|
|
202
202
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -210,7 +210,7 @@ type addXObjElementParams = Parameters<typeof addXObjElementEx>;
|
|
|
210
210
|
* @throws {TypeError} if `obj` param is not an object
|
|
211
211
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
212
212
|
*/
|
|
213
|
-
export function addXObjElementEx(obj:
|
|
213
|
+
export function addXObjElementEx(obj: INode, name: string): INodeModifResult;
|
|
214
214
|
/**
|
|
215
215
|
* Inserts an element addressed by its key into a given object.
|
|
216
216
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -224,7 +224,7 @@ type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
|
|
|
224
224
|
* @throws {TypeError} if `obj` param is not an object
|
|
225
225
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
226
226
|
*/
|
|
227
|
-
export function insertXObjElementEx(obj:
|
|
227
|
+
export function insertXObjElementEx(obj: INode, name: string, opt?: OPT_inselops_L): INodeModifResult;
|
|
228
228
|
/**
|
|
229
229
|
* Deletes an element addressed by its key from a given object.
|
|
230
230
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -237,19 +237,19 @@ type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
|
|
|
237
237
|
* @throws {TypeError} if `obj` param is not an object
|
|
238
238
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
239
239
|
*/
|
|
240
|
-
export function deleteXObjElementEx(obj:
|
|
240
|
+
export function deleteXObjElementEx(obj: INode, name: string): INodeModifResult;
|
|
241
241
|
/**
|
|
242
242
|
* Renames an element addressed by its key.
|
|
243
243
|
* @throws {TypeError} if `obj` param is not an object
|
|
244
244
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
245
245
|
* @throws {EvalKeyNameError} if `value` param is not valid identifier
|
|
246
246
|
*/
|
|
247
|
-
export function renameXObjElement(obj:
|
|
247
|
+
export function renameXObjElement(obj: INode, name?: string, value?: string): boolean;
|
|
248
248
|
/**
|
|
249
249
|
* Clears a given node
|
|
250
250
|
* @throws {TypeError} if `node`-param is not an object or array
|
|
251
251
|
*/
|
|
252
|
-
export function clearXObjNode(node:
|
|
252
|
+
export function clearXObjNode(node: INode | INode[]): boolean;
|
|
253
253
|
/**
|
|
254
254
|
* Tries to convert a value into an ID.
|
|
255
255
|
*/
|
|
@@ -267,7 +267,7 @@ type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
|
|
|
267
267
|
* @throws {TypeError} if `obj` param is not an object
|
|
268
268
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
269
269
|
*/
|
|
270
|
-
export function insertXObjEListEx(obj:
|
|
270
|
+
export function insertXObjEListEx(obj: INode, name: string, opt?: OPT_inselops_S): INodeModifResult;
|
|
271
271
|
/**
|
|
272
272
|
* Tries to convert a value into an element name description.
|
|
273
273
|
*/
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.140-20260606]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
valueToIndex,
|
|
7
|
-
readAsString, readAsBoolEx, readAsNumberEx,
|
|
8
7
|
isNullOrUndef,
|
|
9
8
|
isInteger,
|
|
10
9
|
isArray, isObject, isPlainObject,
|
|
11
|
-
// * import types definitions *
|
|
12
|
-
IValueToStringTransformOptions,
|
|
13
10
|
} = require('@ygracs/bsfoc-lib-js');
|
|
14
11
|
|
|
15
12
|
const {
|
|
@@ -17,10 +14,6 @@ const {
|
|
|
17
14
|
XOBJ_ECODE_TABLE,
|
|
18
15
|
} = require('./xObj-errors');
|
|
19
16
|
|
|
20
|
-
const {
|
|
21
|
-
XOBJ_DEF_TNAMES,
|
|
22
|
-
} = require('./xObj-defs');
|
|
23
|
-
|
|
24
17
|
// === module inner block ===
|
|
25
18
|
|
|
26
19
|
const {
|
|
@@ -32,10 +25,6 @@ const {
|
|
|
32
25
|
XOBJ_TE_KNES_ECODE,
|
|
33
26
|
} = XOBJ_ECODE_TABLE;
|
|
34
27
|
|
|
35
|
-
const {
|
|
36
|
-
XOBJ_DEF_PARAM_TNAME,
|
|
37
|
-
} = XOBJ_DEF_TNAMES;
|
|
38
|
-
|
|
39
28
|
/**
|
|
40
29
|
* A result of a value check ops.
|
|
41
30
|
* @typedef {Object} RVAL_reason
|
|
@@ -268,7 +257,7 @@ module.exports.INode = {};
|
|
|
268
257
|
/**
|
|
269
258
|
* Extracts an element from a given object by its key.
|
|
270
259
|
* @function getXObjElement
|
|
271
|
-
* @param {
|
|
260
|
+
* @param {INode} obj - some object
|
|
272
261
|
* @param {string} name - some child element
|
|
273
262
|
* @returns {?any}
|
|
274
263
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -364,7 +353,7 @@ module.exports.addXObjElement = addXObjElement;
|
|
|
364
353
|
* Adds an element addressed by its key to a given object.
|
|
365
354
|
* @since 0.3.0
|
|
366
355
|
* @function addXObjElementEx
|
|
367
|
-
* @param {
|
|
356
|
+
* @param {INode} obj - some object
|
|
368
357
|
* @param {string} name - some child element
|
|
369
358
|
* @returns {INodeModifResult}
|
|
370
359
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -452,7 +441,7 @@ module.exports.insertXObjElement = insertXObjElement;
|
|
|
452
441
|
* Inserts an element addressed by its key into a given object.
|
|
453
442
|
* @since 0.2.0
|
|
454
443
|
* @function insertXObjElementEx
|
|
455
|
-
* @param {
|
|
444
|
+
* @param {INode} obj - some object
|
|
456
445
|
* @param {string} name - some child element
|
|
457
446
|
* @param {OPT_inselops_L} [opt] - options
|
|
458
447
|
* @returns {INodeModifResult}
|
|
@@ -538,7 +527,7 @@ module.exports.deleteXObjElement = deleteXObjElement;
|
|
|
538
527
|
/**
|
|
539
528
|
* Deletes an element addressed by its key from a given object.
|
|
540
529
|
* @function deleteXObjElementEx
|
|
541
|
-
* @param {
|
|
530
|
+
* @param {INode} obj - some object
|
|
542
531
|
* @param {string} name - some child element
|
|
543
532
|
* @returns {INodeModifResult}
|
|
544
533
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -571,7 +560,7 @@ module.exports.deleteXObjElementEx = deleteXObjElementEx;
|
|
|
571
560
|
/**
|
|
572
561
|
* Renames an element addressed by its key.
|
|
573
562
|
* @function renameXObjElement
|
|
574
|
-
* @param {
|
|
563
|
+
* @param {INode} obj - some object
|
|
575
564
|
* @param {string} name - some child element
|
|
576
565
|
* @param {string} value - new element ID
|
|
577
566
|
* @returns {boolean}
|
|
@@ -682,7 +671,7 @@ function insertXObjEList(...args) {
|
|
|
682
671
|
* Inserts a list elements into a given object.
|
|
683
672
|
* @since 0.2.0
|
|
684
673
|
* @function insertXObjEListEx
|
|
685
|
-
* @param {
|
|
674
|
+
* @param {INode} obj - some object
|
|
686
675
|
* @param {string} name - some child element name
|
|
687
676
|
* @param {OPT_inselops_S} [opt] - options
|
|
688
677
|
* @returns {INodeModifResult}
|
|
@@ -771,7 +760,7 @@ function insertXObjEChain(obj, ...args) {
|
|
|
771
760
|
|
|
772
761
|
/**
|
|
773
762
|
* Clears a given node
|
|
774
|
-
* @param {
|
|
763
|
+
* @param {INode|INode[]} node - some node
|
|
775
764
|
* @returns {boolean}
|
|
776
765
|
* @throws {TypeError} if `node`-param is not an object or array
|
|
777
766
|
*/
|
package/lib/xObj-param.d.ts
CHANGED
|
@@ -1,69 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated
|
|
3
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
4
|
+
*/
|
|
5
|
+
export type readXObjParamOptionAsStr = string;
|
|
6
|
+
export const readXObjParamOptionAsStr: readXObjParamOptionAsStr;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
10
|
+
*/
|
|
11
|
+
export type writeXObjParamOptionAsStr = string;
|
|
12
|
+
export const writeXObjParamOptionAsStr: writeXObjParamOptionAsStr;
|
|
1
13
|
/**
|
|
2
14
|
* Extracts a parameter 'AS IS' from a given object.
|
|
3
15
|
* @throws {TypeError} if `obj` param is not an object
|
|
4
16
|
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
5
17
|
*/
|
|
6
|
-
export function readXObjParamRaw(obj:
|
|
18
|
+
export function readXObjParamRaw(obj: INode, key?: string): any;
|
|
7
19
|
/**
|
|
8
20
|
* Writes a parameter 'AS IS' into a given object.
|
|
9
21
|
* @throws {TypeError} if `obj` param is not an object
|
|
10
22
|
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
11
23
|
*/
|
|
12
|
-
export function writeXObjParamRaw(obj:
|
|
24
|
+
export function writeXObjParamRaw(obj: INode, value: any, key?: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
27
|
+
* @throws {TypeError} if `obj` param is not an object
|
|
28
|
+
*/
|
|
29
|
+
export function readXObjParam(obj: INode, key?: string): string;
|
|
13
30
|
/**
|
|
14
31
|
* Extracts a parameter from a given object and returns it as a boolean.
|
|
15
32
|
* @throws {TypeError} if `obj` param is not an object
|
|
16
33
|
*/
|
|
17
|
-
export function readXObjParamAsBool(obj:
|
|
34
|
+
export function readXObjParamAsBool(obj: INode, defValue?: boolean, key?: string): boolean;
|
|
18
35
|
/**
|
|
19
36
|
* Extracts a parameter from a given object and returns it as a number.
|
|
20
37
|
* @throws {TypeError} if `obj` param is not an object
|
|
21
38
|
*/
|
|
22
|
-
export function readXObjParamAsNum(obj:
|
|
39
|
+
export function readXObjParamAsNum(obj: INode, defValue?: number, key?: string): number;
|
|
23
40
|
/**
|
|
24
41
|
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
25
42
|
* @throws {TypeError} if `obj` param is not an object
|
|
26
43
|
*/
|
|
27
|
-
export function readXObjParamAsIndex(obj:
|
|
44
|
+
export function readXObjParamAsIndex(obj: INode, key?: string): number;
|
|
28
45
|
/**
|
|
29
46
|
* Extracts a parameter from a given object and returns it as a string.
|
|
30
47
|
* @throws {TypeError} if `obj` param is not an object
|
|
31
48
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
32
49
|
*/
|
|
33
|
-
export function readXObjParamEx(obj:
|
|
50
|
+
export function readXObjParamEx(obj: INode, opt?: readXObjParamOptionAsStr | IValueToStringTransformOptions, key?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Tries to convert a given value to a string and writes it as a parameter
|
|
53
|
+
* into a given object.
|
|
54
|
+
* @throws {TypeError} if `obj` param is not an object
|
|
55
|
+
*/
|
|
56
|
+
export function writeXObjParam(obj: INode, value: any, key?: string): boolean;
|
|
34
57
|
/**
|
|
35
58
|
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
36
59
|
* into a given object.
|
|
37
60
|
* @throws {TypeError} if `obj` param is not an object
|
|
38
61
|
*/
|
|
39
|
-
export function writeXObjParamAsBool(obj:
|
|
62
|
+
export function writeXObjParamAsBool(obj: INode, value: any, defValue?: boolean, key?: string): boolean;
|
|
40
63
|
/**
|
|
41
64
|
* Tries to convert a given value to a number and writes it as a parameter
|
|
42
65
|
* into a given object.
|
|
43
66
|
* @throws {TypeError} if `obj` param is not an object
|
|
44
67
|
*/
|
|
45
|
-
export function writeXObjParamAsNum(obj:
|
|
68
|
+
export function writeXObjParamAsNum(obj: INode, value: any, defValue?: number, key?: string): boolean;
|
|
46
69
|
/**
|
|
47
70
|
* Tries to convert a given value into an 'index' value and writes it
|
|
48
71
|
* as a parameter into a given object.
|
|
49
72
|
* @throws {TypeError} if `obj` param is not an object
|
|
50
73
|
*/
|
|
51
|
-
export function writeXObjParamAsIndex(obj:
|
|
74
|
+
export function writeXObjParamAsIndex(obj: INode, value: any, key?: string): boolean;
|
|
52
75
|
/**
|
|
53
76
|
* Tries to convert a given value to a string and writes it
|
|
54
77
|
* as a parameter into a given object.
|
|
55
78
|
* @throws {TypeError} if `obj` param is not an object
|
|
56
79
|
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
57
80
|
*/
|
|
58
|
-
export function writeXObjParamEx(obj:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @throws {TypeError} if `obj` param is not an object
|
|
62
|
-
*/
|
|
63
|
-
export function readXObjParam(obj: object, key?: string): string;
|
|
64
|
-
/**
|
|
65
|
-
* Tries to convert a given value to a string and writes it as a parameter
|
|
66
|
-
* into a given object.
|
|
67
|
-
* @throws {TypeError} if `obj` param is not an object
|
|
68
|
-
*/
|
|
69
|
-
export function writeXObjParam(obj: object, value: any, key?: string): boolean;
|
|
81
|
+
export function writeXObjParamEx(obj: INode, value: any, opt?: writeXObjParamOptionAsStr | IValueToStringTransformOptions, key?: string): boolean;
|
|
82
|
+
import type { INode } from "./xObj-lib";
|
|
83
|
+
import type { IValueToStringTransformOptions } from "@ygracs/bsfoc-lib-js";
|
package/lib/xObj-param.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.140-20260607]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -21,6 +21,8 @@ const {
|
|
|
21
21
|
|
|
22
22
|
const {
|
|
23
23
|
evalKeyName,
|
|
24
|
+
// * import types definitions *
|
|
25
|
+
INode,
|
|
24
26
|
} = require('./xObj-lib');
|
|
25
27
|
|
|
26
28
|
// === module inner block ===
|
|
@@ -40,7 +42,7 @@ const {
|
|
|
40
42
|
/**
|
|
41
43
|
* Extracts a parameter 'AS IS' from a given object.
|
|
42
44
|
* @function readXObjParamRaw
|
|
43
|
-
* @param {
|
|
45
|
+
* @param {INode} obj - some object
|
|
44
46
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
45
47
|
* @returns {any}
|
|
46
48
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -65,7 +67,7 @@ module.exports.readXObjParamRaw = readXObjParamRaw;
|
|
|
65
67
|
/**
|
|
66
68
|
* Writes a parameter 'AS IS' into a given object.
|
|
67
69
|
* @function writeXObjParamRaw
|
|
68
|
-
* @param {
|
|
70
|
+
* @param {INode} obj - some object
|
|
69
71
|
* @param {any} value - some value
|
|
70
72
|
* @param {string} [key=XOBJ_DEF_PARAM_TNAME] - some key
|
|
71
73
|
* @returns {boolean}
|
|
@@ -101,7 +103,7 @@ module.exports.writeXObjParamRaw = writeXObjParamRaw;
|
|
|
101
103
|
/**
|
|
102
104
|
* Extracts a parameter from a given object and returns it as a string.
|
|
103
105
|
* @function readXObjParam
|
|
104
|
-
* @param {
|
|
106
|
+
* @param {INode} obj - some object
|
|
105
107
|
* @param {string} [key] - some key
|
|
106
108
|
* @returns {string}
|
|
107
109
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -126,7 +128,7 @@ module.exports.readXObjParam = readXObjParam;
|
|
|
126
128
|
/**
|
|
127
129
|
* Extracts a parameter from a given object and returns it as a boolean.
|
|
128
130
|
* @function readXObjParamAsBool
|
|
129
|
-
* @param {
|
|
131
|
+
* @param {INode} obj - some object
|
|
130
132
|
* @param {boolean} [defValue] - default value
|
|
131
133
|
* @param {string} [key] - some key
|
|
132
134
|
* @returns {boolean}
|
|
@@ -154,7 +156,7 @@ module.exports.readXObjParamAsBool = readXObjParamAsBool;
|
|
|
154
156
|
/**
|
|
155
157
|
* Extracts a parameter from a given object and returns it as a number.
|
|
156
158
|
* @function readXObjParamAsNum
|
|
157
|
-
* @param {
|
|
159
|
+
* @param {INode} obj - some object
|
|
158
160
|
* @param {number} [defValue] - default value
|
|
159
161
|
* @param {string} [key] - some key
|
|
160
162
|
* @returns {number}
|
|
@@ -182,7 +184,7 @@ module.exports.readXObjParamAsNum = readXObjParamAsNum;
|
|
|
182
184
|
/**
|
|
183
185
|
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
184
186
|
* @function readXObjParamAsIndex
|
|
185
|
-
* @param {
|
|
187
|
+
* @param {INode} obj - some object
|
|
186
188
|
* @param {string} [key] - some key
|
|
187
189
|
* @returns {number}
|
|
188
190
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -205,11 +207,23 @@ function readXObjParamAsIndex(obj, key) {
|
|
|
205
207
|
};
|
|
206
208
|
module.exports.readXObjParamAsIndex = readXObjParamAsIndex;
|
|
207
209
|
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @typedef {string} readXObjParamOptionAsStr
|
|
213
|
+
* @deprecated
|
|
214
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* A virtual constant meant for support jsdoc notation:
|
|
218
|
+
* @type {readXObjParamOptionAsStr}
|
|
219
|
+
*/
|
|
220
|
+
module.exports.readXObjParamOptionAsStr = '';
|
|
221
|
+
|
|
208
222
|
/**
|
|
209
223
|
* Extracts a parameter from a given object and returns it as a string.
|
|
210
224
|
* @function readXObjParamEx
|
|
211
|
-
* @param {
|
|
212
|
-
* @param {
|
|
225
|
+
* @param {INode} obj - some object
|
|
226
|
+
* @param {readXObjParamOptionAsStr|IValueToStringTransformOptions} [opt] - options
|
|
213
227
|
* @param {string} [key] - some key
|
|
214
228
|
* @returns {string}
|
|
215
229
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -229,7 +243,6 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
229
243
|
}
|
|
230
244
|
};
|
|
231
245
|
};
|
|
232
|
-
/** @type {IValueToStringTransformOptions} */
|
|
233
246
|
const _opt = isPlainObject(opt) ? opt : {
|
|
234
247
|
useTrim: false,
|
|
235
248
|
numberToString: true,
|
|
@@ -244,7 +257,7 @@ module.exports.readXObjParamEx = readXObjParamEx;
|
|
|
244
257
|
* Tries to convert a given value to a string and writes it as a parameter
|
|
245
258
|
* into a given object.
|
|
246
259
|
* @function writeXObjParam
|
|
247
|
-
* @param {
|
|
260
|
+
* @param {INode} obj - some object
|
|
248
261
|
* @param {any} value - some value
|
|
249
262
|
* @param {string} [key] - some key
|
|
250
263
|
* @returns {boolean}
|
|
@@ -271,7 +284,7 @@ module.exports.writeXObjParam = writeXObjParam;
|
|
|
271
284
|
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
272
285
|
* into a given object.
|
|
273
286
|
* @function writeXObjParamAsBool
|
|
274
|
-
* @param {
|
|
287
|
+
* @param {INode} obj - some object
|
|
275
288
|
* @param {any} value - some value
|
|
276
289
|
* @param {boolean} [defValue] - default value
|
|
277
290
|
* @param {string} [key] - some key
|
|
@@ -303,7 +316,7 @@ module.exports.writeXObjParamAsBool = writeXObjParamAsBool;
|
|
|
303
316
|
* Tries to convert a given value to a number and writes it as a parameter
|
|
304
317
|
* into a given object.
|
|
305
318
|
* @function writeXObjParamAsNum
|
|
306
|
-
* @param {
|
|
319
|
+
* @param {INode} obj - some object
|
|
307
320
|
* @param {any} value - some value
|
|
308
321
|
* @param {number} [defValue] - default value
|
|
309
322
|
* @param {string} [key] - some key
|
|
@@ -335,7 +348,7 @@ module.exports.writeXObjParamAsNum = writeXObjParamAsNum;
|
|
|
335
348
|
* Tries to convert a given value into an 'index' value and writes it
|
|
336
349
|
* as a parameter into a given object.
|
|
337
350
|
* @function writeXObjParamAsIndex
|
|
338
|
-
* @param {
|
|
351
|
+
* @param {INode} obj - some object
|
|
339
352
|
* @param {any} value - some value
|
|
340
353
|
* @param {string} [key] - some key
|
|
341
354
|
* @returns {boolean}
|
|
@@ -362,13 +375,25 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
362
375
|
};
|
|
363
376
|
module.exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
|
|
364
377
|
|
|
378
|
+
/**
|
|
379
|
+
*
|
|
380
|
+
* @typedef {string} writeXObjParamOptionAsStr
|
|
381
|
+
* @deprecated
|
|
382
|
+
* @todo \[since `v0.2.1`] deprecated and will be removed
|
|
383
|
+
*/
|
|
384
|
+
/**
|
|
385
|
+
* A virtual constant meant for support jsdoc notation:
|
|
386
|
+
* @type {writeXObjParamOptionAsStr}
|
|
387
|
+
*/
|
|
388
|
+
module.exports.writeXObjParamOptionAsStr = '';
|
|
389
|
+
|
|
365
390
|
/**
|
|
366
391
|
* Tries to convert a given value to a string and writes it
|
|
367
392
|
* as a parameter into a given object.
|
|
368
393
|
* @function writeXObjParamEx
|
|
369
|
-
* @param {
|
|
394
|
+
* @param {INode} obj - some object
|
|
370
395
|
* @param {any} value - some value
|
|
371
|
-
* @param {
|
|
396
|
+
* @param {writeXObjParamOptionAsStr|IValueToStringTransformOptions} [opt] - options
|
|
372
397
|
* @param {string} [key] - some key
|
|
373
398
|
* @returns {boolean}
|
|
374
399
|
* @throws {TypeError} if `obj` param is not an object
|