@ygracs/xobj-lib-js 0.3.0-beta.0 → 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/CHANGELOG.md +1 -1
- package/README.md +4 -2
- package/doc/xObj.md +44 -5
- package/index.d.ts +11 -9
- package/lib/xObj-lib.d.ts +97 -66
- package/lib/xObj-lib.js +72 -53
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|***rev.*:**|0.1.
|
|
1
|
+
|***rev.*:**|0.1.4|
|
|
2
2
|
|:---|---:|
|
|
3
|
-
|***date***:|2026-
|
|
3
|
+
|***date***:|2026-03-03|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -16,3 +16,5 @@ This module provide a helper functions for object manipulation. It was primarily
|
|
|
16
16
|
### Installation
|
|
17
17
|
|
|
18
18
|
`npm install @ygracs/xobj-lib-js`
|
|
19
|
+
|
|
20
|
+
> Note: It's recommended to "pin" a package versions range to its minor releases after installation. To do so use `~` range specifier (*e.g. `~0.3.0`*) in `package.json`.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.52|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2026-
|
|
3
|
+
>|date:|2026-03-03|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -676,6 +676,9 @@ The function throws a `TypeError` exception in case:
|
|
|
676
676
|
|
|
677
677
|
- code: `ERR_XOBJ_NPOBJ`
|
|
678
678
|
+ if `object` parameter is not an `Object` instance;
|
|
679
|
+
|
|
680
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
681
|
+
|
|
679
682
|
- code: `ERR_XOBJ_NSTR`
|
|
680
683
|
+ if `key` parameter given and is not a type of a `string`.
|
|
681
684
|
|
|
@@ -702,6 +705,9 @@ The function throws a `TypeError` exception in case:
|
|
|
702
705
|
|
|
703
706
|
- code: `ERR_XOBJ_NPOBJ`
|
|
704
707
|
+ if `object` parameter is not an `Object` instance;
|
|
708
|
+
|
|
709
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
710
|
+
|
|
705
711
|
- code: `ERR_XOBJ_NSTR`
|
|
706
712
|
+ if `key` parameter given and is not a type of a `string`.
|
|
707
713
|
|
|
@@ -729,6 +735,9 @@ The function throws a `TypeError` exception in case:
|
|
|
729
735
|
|
|
730
736
|
- code: `ERR_XOBJ_NPOBJ`
|
|
731
737
|
+ if `object` parameter is not an `Object` instance;
|
|
738
|
+
|
|
739
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
740
|
+
|
|
732
741
|
- code: `ERR_XOBJ_NSTR`
|
|
733
742
|
+ if `attr` parameter given and is not a type of a `string`;
|
|
734
743
|
+ if `key` parameter given and is not a type of a `string`.
|
|
@@ -757,6 +766,9 @@ The function throws a `TypeError` exception in case:
|
|
|
757
766
|
|
|
758
767
|
- code: `ERR_XOBJ_NPOBJ`
|
|
759
768
|
+ if `object` parameter is not an `Object` instance;
|
|
769
|
+
|
|
770
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
771
|
+
|
|
760
772
|
- code: `ERR_XOBJ_NSTR`
|
|
761
773
|
+ if `attr` parameter given and is not a type of a `string`;
|
|
762
774
|
+ if `key` parameter given and is not a type of a `string`.
|
|
@@ -804,6 +816,9 @@ The function throws a `TypeError` exception in case:
|
|
|
804
816
|
|
|
805
817
|
- code: `ERR_XOBJ_NPOBJ`
|
|
806
818
|
+ if `object` parameter is not an `Object` instance;
|
|
819
|
+
|
|
820
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
821
|
+
|
|
807
822
|
- code: `ERR_XOBJ_NSTR`
|
|
808
823
|
+ if `attr` parameter given and is not a type of a `string`;
|
|
809
824
|
+ if `key` parameter given and is not a type of a `string`.
|
|
@@ -827,6 +842,9 @@ The function throws a `TypeError` exception in case:
|
|
|
827
842
|
|
|
828
843
|
- code: `ERR_XOBJ_NPOBJ`
|
|
829
844
|
+ if `object` parameter is not an `Object` instance;
|
|
845
|
+
|
|
846
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
847
|
+
|
|
830
848
|
- code: `ERR_XOBJ_NSTR`
|
|
831
849
|
+ if `attr` parameter given and is not a type of a `string`;
|
|
832
850
|
+ if `key` parameter given and is not a type of a `string`.
|
|
@@ -853,6 +871,9 @@ The function throws a `TypeError` exception in case:
|
|
|
853
871
|
|
|
854
872
|
- code: `ERR_XOBJ_NPOBJ`
|
|
855
873
|
+ if `object` parameter is not an `Object` instance;
|
|
874
|
+
|
|
875
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
876
|
+
|
|
856
877
|
- code: `ERR_XOBJ_NSTR`
|
|
857
878
|
+ if `attr` parameter given and is not a type of a `string`;
|
|
858
879
|
+ if `value` parameter given and is not a type of a `string`;
|
|
@@ -878,6 +899,9 @@ The function throws a `TypeError` exception in case:
|
|
|
878
899
|
|
|
879
900
|
- code: `ERR_XOBJ_NPOBJ`
|
|
880
901
|
+ if `object` parameter is not an `Object` instance;
|
|
902
|
+
|
|
903
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
904
|
+
|
|
881
905
|
- code: `ERR_XOBJ_NSTR`
|
|
882
906
|
+ if `name` parameter given and is not a type of a `string`;
|
|
883
907
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
@@ -931,6 +955,9 @@ The function throws a `TypeError` exception in case:
|
|
|
931
955
|
|
|
932
956
|
- code: `ERR_XOBJ_NPOBJ`
|
|
933
957
|
+ if `object` parameter is not an `Object` instance;
|
|
958
|
+
|
|
959
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
960
|
+
|
|
934
961
|
- code: `ERR_XOBJ_NSTR`
|
|
935
962
|
+ if `name` parameter given and is not a type of a `string`;
|
|
936
963
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
@@ -1000,6 +1027,9 @@ The function throws a `TypeError` exception in case:
|
|
|
1000
1027
|
|
|
1001
1028
|
- code: `ERR_XOBJ_NPOBJ`
|
|
1002
1029
|
+ if `object` parameter is not an `Object` instance;
|
|
1030
|
+
|
|
1031
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
1032
|
+
|
|
1003
1033
|
- code: `ERR_XOBJ_NSTR`
|
|
1004
1034
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1005
1035
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
@@ -1049,6 +1079,9 @@ The function throws a `TypeError` exception in case:
|
|
|
1049
1079
|
|
|
1050
1080
|
- code: `ERR_XOBJ_NPOBJ`
|
|
1051
1081
|
+ if `object` parameter is not an `Object` instance;
|
|
1082
|
+
|
|
1083
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
1084
|
+
|
|
1052
1085
|
- code: `ERR_XOBJ_NSTR`
|
|
1053
1086
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1054
1087
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
@@ -1073,6 +1106,9 @@ The function throws a `TypeError` exception in case:
|
|
|
1073
1106
|
|
|
1074
1107
|
- code: `ERR_XOBJ_NPOBJ`
|
|
1075
1108
|
+ if `object` parameter is not an `Object` instance;
|
|
1109
|
+
|
|
1110
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
1111
|
+
|
|
1076
1112
|
- code: `ERR_XOBJ_NSTR`
|
|
1077
1113
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1078
1114
|
+ id `value` parameter given and is not a type of a `string`.
|
|
@@ -1080,7 +1116,7 @@ The function throws a `TypeError` exception in case:
|
|
|
1080
1116
|
<a name="clearXObjNode"></a>
|
|
1081
1117
|
#### **clearXObjNode(node)** => `boolean`
|
|
1082
1118
|
|
|
1083
|
-
> since: \[v0.
|
|
1119
|
+
> since: \[v0.3.0]
|
|
1084
1120
|
|
|
1085
1121
|
This function tries to clean a given node.
|
|
1086
1122
|
|
|
@@ -1184,6 +1220,9 @@ The function throws a `TypeError` exception in case:
|
|
|
1184
1220
|
|
|
1185
1221
|
- code: `ERR_XOBJ_NPOBJ`
|
|
1186
1222
|
+ if `object` parameter is not an `Object` instance;
|
|
1223
|
+
|
|
1224
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
1225
|
+
|
|
1187
1226
|
- code: `ERR_XOBJ_NSTR`
|
|
1188
1227
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1189
1228
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
@@ -1285,7 +1324,7 @@ The class constructor receives an arguments listed below:
|
|
|
1285
1324
|
<a name="TXmlContentParseOptions+compact"></a>
|
|
1286
1325
|
###### **compact**
|
|
1287
1326
|
|
|
1288
|
-
> since: \[v0.
|
|
1327
|
+
> since: \[v0.3.0]
|
|
1289
1328
|
|
|
1290
1329
|
| property type | read only | description |
|
|
1291
1330
|
|---|---|:---|
|
|
@@ -1332,7 +1371,7 @@ This method transforms a given object to a set of accepted parser options.
|
|
|
1332
1371
|
<a name="EvalKeyNameError"></a>
|
|
1333
1372
|
#### **EvalKeyNameError**
|
|
1334
1373
|
|
|
1335
|
-
> since: \[v0.
|
|
1374
|
+
> since: \[v0.3.0]
|
|
1336
1375
|
|
|
1337
1376
|
This class extends a functionality of a `TypeError`-object to provide more accurate information when an error happened through a key evaluation.
|
|
1338
1377
|
|
package/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
import type {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
xml2jsParseOptions, js2xmlParseOptions,
|
|
13
|
+
OPT_parserOptions,
|
|
14
14
|
} from "./lib/xObj-defs";
|
|
15
15
|
|
|
16
16
|
export type {
|
|
@@ -93,15 +93,17 @@ export {
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
import type {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
XObjENameDescr, XObjENameDescrConditions,
|
|
97
|
+
OPT_inselops_L, OPT_inselops_S,
|
|
98
|
+
RVAL_emodif,
|
|
99
|
+
VCOR_evalkname, RVAL_reason,
|
|
100
|
+
IEvalKeyNameResult,
|
|
100
101
|
} from "./lib/xObj-lib";
|
|
101
102
|
|
|
102
103
|
export type {
|
|
103
|
-
XObjENameDescr,
|
|
104
|
+
XObjENameDescr, XObjENameDescrConditions,
|
|
104
105
|
OPT_inselops_L, OPT_inselops_S,
|
|
105
|
-
|
|
106
|
-
VCOR_evalkname,
|
|
106
|
+
RVAL_emodif,
|
|
107
|
+
VCOR_evalkname, RVAL_reason,
|
|
108
|
+
IEvalKeyNameResult,
|
|
107
109
|
};
|
package/lib/xObj-lib.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { EvalKeyNameError } from "./xObj-errors";
|
|
2
|
+
/**
|
|
3
|
+
* An error description of a value check ops on fail.
|
|
4
|
+
*/
|
|
5
|
+
export type IEvalKeyNameReasonOnFail = {
|
|
6
|
+
/**
|
|
7
|
+
* - message ID
|
|
8
|
+
*/
|
|
9
|
+
code: string;
|
|
10
|
+
/**
|
|
11
|
+
* - message text
|
|
12
|
+
*/
|
|
13
|
+
msg: string;
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* A result of a value check ops.
|
|
4
17
|
*/
|
|
@@ -19,7 +32,7 @@ export type IEvalKeyNameOptions = {
|
|
|
19
32
|
/**
|
|
20
33
|
* - a flag to accept only a non-empty string values
|
|
21
34
|
*/
|
|
22
|
-
onlyNES?: boolean
|
|
35
|
+
onlyNES?: boolean;
|
|
23
36
|
};
|
|
24
37
|
/**
|
|
25
38
|
* A result of `evalKeyName` function if succeed
|
|
@@ -45,7 +58,7 @@ export type IEvalKeyNameResultOnFail = {
|
|
|
45
58
|
/**
|
|
46
59
|
* - reason of fail
|
|
47
60
|
*/
|
|
48
|
-
value:
|
|
61
|
+
value: IEvalKeyNameReasonOnFail;
|
|
49
62
|
};
|
|
50
63
|
/**
|
|
51
64
|
* A result of `evalKeyName` function
|
|
@@ -64,6 +77,24 @@ export type VCOR_evalkname = {
|
|
|
64
77
|
*/
|
|
65
78
|
value: string | RVAL_reason;
|
|
66
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Some conditions applied to an element as a result of an element name pattern
|
|
82
|
+
* evaluation ops.
|
|
83
|
+
*/
|
|
84
|
+
export type XObjENameDescrConditions = {
|
|
85
|
+
/**
|
|
86
|
+
* - element name
|
|
87
|
+
*/
|
|
88
|
+
name: any;
|
|
89
|
+
/**
|
|
90
|
+
* - element type
|
|
91
|
+
*/
|
|
92
|
+
type: any;
|
|
93
|
+
/**
|
|
94
|
+
* - some value
|
|
95
|
+
*/
|
|
96
|
+
value?: any;
|
|
97
|
+
};
|
|
67
98
|
/**
|
|
68
99
|
* A result of an element name pattern evaluation ops.
|
|
69
100
|
*/
|
|
@@ -79,7 +110,7 @@ export type XObjENameDescr = {
|
|
|
79
110
|
/**
|
|
80
111
|
* - some conditions applied to an element
|
|
81
112
|
*/
|
|
82
|
-
conditions:
|
|
113
|
+
conditions: XObjENameDescrConditions | null;
|
|
83
114
|
};
|
|
84
115
|
/**
|
|
85
116
|
* A result of an xObj modification ops
|
|
@@ -118,142 +149,142 @@ export type OPT_inselops_S = {
|
|
|
118
149
|
*/
|
|
119
150
|
export function addXObjElementEx(obj: object, name: string): RVAL_emodif;
|
|
120
151
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @throws {TypeError} if `
|
|
152
|
+
* Extracts a parameter from a given object and returns it as a boolean.
|
|
153
|
+
* @throws {TypeError} if `obj` param is not an object
|
|
123
154
|
*/
|
|
124
|
-
export function
|
|
155
|
+
export function readXObjParamAsBool(obj: object, defValue?: boolean, key?: string): boolean;
|
|
125
156
|
/**
|
|
126
|
-
* Extracts a parameter
|
|
157
|
+
* Extracts a parameter from a given object and returns it as a number.
|
|
127
158
|
* @throws {TypeError} if `obj` param is not an object
|
|
128
|
-
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
129
159
|
*/
|
|
130
|
-
export function
|
|
160
|
+
export function readXObjParamAsNum(obj: object, defValue?: number, key?: string): number;
|
|
131
161
|
/**
|
|
132
|
-
* Extracts a parameter from a given object and returns it as
|
|
162
|
+
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
133
163
|
* @throws {TypeError} if `obj` param is not an object
|
|
134
164
|
*/
|
|
135
|
-
export function
|
|
165
|
+
export function readXObjParamAsIndex(obj: object, key?: string): number;
|
|
136
166
|
/**
|
|
137
|
-
*
|
|
167
|
+
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
168
|
+
* into a given object.
|
|
138
169
|
* @throws {TypeError} if `obj` param is not an object
|
|
139
170
|
*/
|
|
140
|
-
export function
|
|
171
|
+
export function writeXObjParamAsBool(obj: object, value: any, defValue?: boolean, key?: string): boolean;
|
|
141
172
|
/**
|
|
142
|
-
*
|
|
173
|
+
* Tries to convert a given value to a number and writes it as a parameter
|
|
174
|
+
* into a given object.
|
|
143
175
|
* @throws {TypeError} if `obj` param is not an object
|
|
144
176
|
*/
|
|
145
|
-
export function
|
|
177
|
+
export function writeXObjParamAsNum(obj: object, value: any, defValue?: number, key?: string): boolean;
|
|
146
178
|
/**
|
|
147
|
-
*
|
|
179
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
180
|
+
* as a parameter into a given object.
|
|
148
181
|
* @throws {TypeError} if `obj` param is not an object
|
|
149
|
-
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
150
182
|
*/
|
|
151
|
-
export function
|
|
183
|
+
export function writeXObjParamAsIndex(obj: object, value: any, key?: string): boolean;
|
|
152
184
|
/**
|
|
153
|
-
* Extracts
|
|
185
|
+
* Extracts an attribute from a given object and returns it as a boolean.
|
|
154
186
|
* @throws {TypeError} if `obj` param is not an object
|
|
155
187
|
*/
|
|
156
|
-
export function
|
|
188
|
+
export function readXObjAttrAsBool(obj: object, attr: string, defValue?: boolean, key?: string): boolean;
|
|
157
189
|
/**
|
|
158
|
-
*
|
|
190
|
+
* Extracts an attribute from a given object and returns it as a number.
|
|
191
|
+
* @returns {number}
|
|
159
192
|
* @throws {TypeError} if `obj` param is not an object
|
|
160
|
-
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
161
193
|
*/
|
|
162
|
-
export function
|
|
194
|
+
export function readXObjAttrAsNum(obj: object, attr: string, defValue?: number, key?: string): number;
|
|
163
195
|
/**
|
|
164
|
-
*
|
|
165
|
-
* into a given object.
|
|
196
|
+
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
166
197
|
* @throws {TypeError} if `obj` param is not an object
|
|
167
198
|
*/
|
|
168
|
-
export function
|
|
199
|
+
export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): number;
|
|
169
200
|
/**
|
|
170
|
-
* Tries to convert a given value to a boolean and writes it as
|
|
201
|
+
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
171
202
|
* into a given object.
|
|
172
203
|
* @throws {TypeError} if `obj` param is not an object
|
|
173
204
|
*/
|
|
174
|
-
export function
|
|
205
|
+
export function writeXObjAttrAsBool(obj: object, attr: string, value: any, defValue?: boolean, key?: string): boolean;
|
|
175
206
|
/**
|
|
176
|
-
* Tries to convert a given value to a number and writes it as
|
|
207
|
+
* Tries to convert a given value to a number and writes it as an attribute
|
|
177
208
|
* into a given object.
|
|
178
209
|
* @throws {TypeError} if `obj` param is not an object
|
|
179
210
|
*/
|
|
180
|
-
export function
|
|
211
|
+
export function writeXObjAttrAsNum(obj: object, attr: string, value: any, defValue?: number, key?: string): boolean;
|
|
181
212
|
/**
|
|
182
213
|
* Tries to convert a given value into an 'index' value and writes it
|
|
183
|
-
* as
|
|
214
|
+
* as an attribute into a given object.
|
|
184
215
|
* @throws {TypeError} if `obj` param is not an object
|
|
185
216
|
*/
|
|
186
|
-
export function
|
|
217
|
+
export function writeXObjAttrAsIndex(obj: object, attr: string, value: any, key?: string): boolean;
|
|
187
218
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @throws {TypeError} if `obj` param is not an object
|
|
191
|
-
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
219
|
+
* Clears a given node
|
|
220
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
192
221
|
*/
|
|
193
|
-
export function
|
|
222
|
+
export function clearXObjNode(node: object | object[]): boolean;
|
|
194
223
|
/**
|
|
195
|
-
* Extracts
|
|
224
|
+
* Extracts a parameter 'AS IS' from a given object.
|
|
196
225
|
* @throws {TypeError} if `obj` param is not an object
|
|
197
|
-
* @throws {EvalKeyNameError} if `
|
|
226
|
+
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
198
227
|
*/
|
|
199
|
-
export function
|
|
228
|
+
export function readXObjParamRaw(obj: object, key?: string): any;
|
|
200
229
|
/**
|
|
201
|
-
* Extracts
|
|
230
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
202
231
|
* @throws {TypeError} if `obj` param is not an object
|
|
203
232
|
*/
|
|
204
|
-
export function
|
|
233
|
+
export function readXObjParam(obj: object, key?: string): string;
|
|
205
234
|
/**
|
|
206
|
-
* Extracts
|
|
235
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
207
236
|
* @throws {TypeError} if `obj` param is not an object
|
|
237
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
208
238
|
*/
|
|
209
|
-
export function
|
|
239
|
+
export function readXObjParamEx(obj: object, opt?: object, key?: string): string;
|
|
210
240
|
/**
|
|
211
|
-
*
|
|
212
|
-
* @returns {number}
|
|
241
|
+
* Writes a parameter 'AS IS' into a given object.
|
|
213
242
|
* @throws {TypeError} if `obj` param is not an object
|
|
243
|
+
* @throws {EvalKeyNameError} if `key` param is not valid identifier
|
|
214
244
|
*/
|
|
215
|
-
export function
|
|
245
|
+
export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
|
|
216
246
|
/**
|
|
217
|
-
*
|
|
247
|
+
* Tries to convert a given value to a string and writes it as a parameter
|
|
248
|
+
* into a given object.
|
|
218
249
|
* @throws {TypeError} if `obj` param is not an object
|
|
219
|
-
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
220
250
|
*/
|
|
221
|
-
export function
|
|
251
|
+
export function writeXObjParam(obj: object, value: any, key?: string): boolean;
|
|
222
252
|
/**
|
|
223
|
-
*
|
|
253
|
+
* Tries to convert a given value to a string and writes it
|
|
254
|
+
* as a parameter into a given object.
|
|
224
255
|
* @throws {TypeError} if `obj` param is not an object
|
|
256
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
225
257
|
*/
|
|
226
|
-
export function
|
|
258
|
+
export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: string): boolean;
|
|
227
259
|
/**
|
|
228
|
-
*
|
|
260
|
+
* Extracts an attribute 'AS IS' from a given object.
|
|
229
261
|
* @throws {TypeError} if `obj` param is not an object
|
|
230
262
|
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
231
263
|
*/
|
|
232
|
-
export function
|
|
264
|
+
export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
|
|
233
265
|
/**
|
|
234
|
-
*
|
|
235
|
-
* into a given object.
|
|
266
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
236
267
|
* @throws {TypeError} if `obj` param is not an object
|
|
237
268
|
*/
|
|
238
|
-
export function
|
|
269
|
+
export function readXObjAttr(obj: object, attr: string, key?: string): string;
|
|
239
270
|
/**
|
|
240
|
-
*
|
|
241
|
-
* into a given object.
|
|
271
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
242
272
|
* @throws {TypeError} if `obj` param is not an object
|
|
273
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
243
274
|
*/
|
|
244
|
-
export function
|
|
275
|
+
export function readXObjAttrEx(obj: object, attr: string, opt?: object, key?: string): string;
|
|
245
276
|
/**
|
|
246
|
-
*
|
|
247
|
-
* into a given object.
|
|
277
|
+
* Writes a parameter into a given object.
|
|
248
278
|
* @throws {TypeError} if `obj` param is not an object
|
|
279
|
+
* @throws {EvalKeyNameError} if `attr` param is not valid identifier
|
|
249
280
|
*/
|
|
250
|
-
export function
|
|
281
|
+
export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
|
|
251
282
|
/**
|
|
252
|
-
* Tries to convert a given value
|
|
253
|
-
*
|
|
283
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
284
|
+
* into a given object.
|
|
254
285
|
* @throws {TypeError} if `obj` param is not an object
|
|
255
286
|
*/
|
|
256
|
-
export function
|
|
287
|
+
export function writeXObjAttr(obj: object, attr: string, value: any, key?: string): boolean;
|
|
257
288
|
/**
|
|
258
289
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
259
290
|
* into a given object.
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.134-20260303]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -37,11 +37,20 @@ 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
|
/**
|
|
@@ -64,7 +73,7 @@ const {
|
|
|
64
73
|
* @since 0.3.0
|
|
65
74
|
* @typedef {Object} IEvalKeyNameResultOnFail
|
|
66
75
|
* @property {false} isSucceed - ops flag
|
|
67
|
-
* @property {
|
|
76
|
+
* @property {IEvalKeyNameReasonOnFail} value - reason of fail
|
|
68
77
|
*/
|
|
69
78
|
|
|
70
79
|
/**
|
|
@@ -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 {?
|
|
192
|
+
* @property {?XObjENameDescrConditions} conditions - some conditions applied to an element
|
|
174
193
|
*/
|
|
175
194
|
|
|
176
195
|
/**
|
|
@@ -856,6 +875,7 @@ function readXObjParamAsBool(obj, defValue, key) {
|
|
|
856
875
|
};
|
|
857
876
|
return readAsBoolEx(result, defValue);
|
|
858
877
|
};
|
|
878
|
+
module.exports.readXObjParamAsBool = readXObjParamAsBool;
|
|
859
879
|
|
|
860
880
|
/**
|
|
861
881
|
* Extracts a parameter from a given object and returns it as a number.
|
|
@@ -883,18 +903,17 @@ function readXObjParamAsNum(obj, defValue, key) {
|
|
|
883
903
|
};
|
|
884
904
|
return readAsNumberEx(result, defValue);
|
|
885
905
|
};
|
|
906
|
+
module.exports.readXObjParamAsNum = readXObjParamAsNum;
|
|
886
907
|
|
|
887
908
|
/**
|
|
888
|
-
* Extracts a parameter from a given object and returns it as
|
|
889
|
-
* @function
|
|
909
|
+
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
910
|
+
* @function readXObjParamAsIndex
|
|
890
911
|
* @param {object} obj - some object
|
|
891
|
-
* @param {object} [opt] - options
|
|
892
912
|
* @param {string} [key] - some key
|
|
893
|
-
* @returns {
|
|
913
|
+
* @returns {number}
|
|
894
914
|
* @throws {TypeError} if `obj` param is not an object
|
|
895
|
-
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
896
915
|
*/
|
|
897
|
-
function
|
|
916
|
+
function readXObjParamAsIndex(obj, key) {
|
|
898
917
|
let result = undefined;
|
|
899
918
|
try {
|
|
900
919
|
result = readXObjParamRaw(obj, key);
|
|
@@ -908,25 +927,21 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
908
927
|
}
|
|
909
928
|
};
|
|
910
929
|
};
|
|
911
|
-
|
|
912
|
-
const _opt = isPlainObject(opt) ? opt : {
|
|
913
|
-
useTrim: false,
|
|
914
|
-
numberToString: true,
|
|
915
|
-
boolToString: true,
|
|
916
|
-
defValue: opt,
|
|
917
|
-
};
|
|
918
|
-
return readAsString(result, _opt);
|
|
930
|
+
return valueToIndex(result);
|
|
919
931
|
};
|
|
932
|
+
module.exports.readXObjParamAsIndex = readXObjParamAsIndex;
|
|
920
933
|
|
|
921
934
|
/**
|
|
922
|
-
* Extracts a parameter from a given object and returns it as
|
|
923
|
-
* @function
|
|
935
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
936
|
+
* @function readXObjParamEx
|
|
924
937
|
* @param {object} obj - some object
|
|
938
|
+
* @param {object} [opt] - options
|
|
925
939
|
* @param {string} [key] - some key
|
|
926
|
-
* @returns {
|
|
940
|
+
* @returns {string}
|
|
927
941
|
* @throws {TypeError} if `obj` param is not an object
|
|
942
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
928
943
|
*/
|
|
929
|
-
function
|
|
944
|
+
function readXObjParamEx(obj, opt, key) {
|
|
930
945
|
let result = undefined;
|
|
931
946
|
try {
|
|
932
947
|
result = readXObjParamRaw(obj, key);
|
|
@@ -940,7 +955,14 @@ function readXObjParamAsIndex(obj, key) {
|
|
|
940
955
|
}
|
|
941
956
|
};
|
|
942
957
|
};
|
|
943
|
-
|
|
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);
|
|
944
966
|
};
|
|
945
967
|
|
|
946
968
|
/**
|
|
@@ -999,6 +1021,7 @@ function writeXObjParamAsBool(obj, value, defValue, key) {
|
|
|
999
1021
|
};
|
|
1000
1022
|
return isSucceed;
|
|
1001
1023
|
};
|
|
1024
|
+
module.exports.writeXObjParamAsBool = writeXObjParamAsBool;
|
|
1002
1025
|
|
|
1003
1026
|
/**
|
|
1004
1027
|
* Tries to convert a given value to a number and writes it as a parameter
|
|
@@ -1030,6 +1053,7 @@ function writeXObjParamAsNum(obj, value, defValue, key) {
|
|
|
1030
1053
|
};
|
|
1031
1054
|
return isSucceed;
|
|
1032
1055
|
};
|
|
1056
|
+
module.exports.writeXObjParamAsNum = writeXObjParamAsNum;
|
|
1033
1057
|
|
|
1034
1058
|
/**
|
|
1035
1059
|
* Tries to convert a given value into an 'index' value and writes it
|
|
@@ -1060,6 +1084,7 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
1060
1084
|
};
|
|
1061
1085
|
return isSucceed;
|
|
1062
1086
|
};
|
|
1087
|
+
module.exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
|
|
1063
1088
|
|
|
1064
1089
|
/**
|
|
1065
1090
|
* Tries to convert a given value to a string and writes it
|
|
@@ -1159,6 +1184,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1159
1184
|
};
|
|
1160
1185
|
return readAsBoolEx(result, defValue);
|
|
1161
1186
|
};
|
|
1187
|
+
module.exports.readXObjAttrAsBool = readXObjAttrAsBool;
|
|
1162
1188
|
|
|
1163
1189
|
/**
|
|
1164
1190
|
* Extracts an attribute from a given object and returns it as a number.
|
|
@@ -1187,19 +1213,18 @@ function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
|
1187
1213
|
};
|
|
1188
1214
|
return readAsNumberEx(result, defValue);
|
|
1189
1215
|
};
|
|
1216
|
+
module.exports.readXObjAttrAsNum = readXObjAttrAsNum;
|
|
1190
1217
|
|
|
1191
1218
|
/**
|
|
1192
|
-
* Extracts an attribute from a given object and returns it as
|
|
1193
|
-
* @function
|
|
1219
|
+
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
1220
|
+
* @function readXObjAttrAsIndex
|
|
1194
1221
|
* @param {object} obj - some object
|
|
1195
1222
|
* @param {string} attr - some attribute
|
|
1196
|
-
* @param {object} [opt] - options
|
|
1197
1223
|
* @param {string} [key] - some key
|
|
1198
|
-
* @returns {
|
|
1224
|
+
* @returns {number}
|
|
1199
1225
|
* @throws {TypeError} if `obj` param is not an object
|
|
1200
|
-
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1201
1226
|
*/
|
|
1202
|
-
function
|
|
1227
|
+
function readXObjAttrAsIndex(obj, attr, key) {
|
|
1203
1228
|
let result = undefined;
|
|
1204
1229
|
try {
|
|
1205
1230
|
result = readXObjAttrRaw(obj, attr, key);
|
|
@@ -1213,26 +1238,22 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
1213
1238
|
}
|
|
1214
1239
|
};
|
|
1215
1240
|
};
|
|
1216
|
-
|
|
1217
|
-
const _opt = isPlainObject(opt) ? opt : {
|
|
1218
|
-
useTrim: true,
|
|
1219
|
-
numberToString: true,
|
|
1220
|
-
boolToString: true,
|
|
1221
|
-
defValue: opt,
|
|
1222
|
-
};
|
|
1223
|
-
return readAsString(result, _opt);
|
|
1241
|
+
return valueToIndex(result);
|
|
1224
1242
|
};
|
|
1243
|
+
module.exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
|
|
1225
1244
|
|
|
1226
1245
|
/**
|
|
1227
|
-
* Extracts an attribute from a given object and returns it as
|
|
1228
|
-
* @function
|
|
1246
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
1247
|
+
* @function readXObjAttrEx
|
|
1229
1248
|
* @param {object} obj - some object
|
|
1230
1249
|
* @param {string} attr - some attribute
|
|
1250
|
+
* @param {object} [opt] - options
|
|
1231
1251
|
* @param {string} [key] - some key
|
|
1232
|
-
* @returns {
|
|
1252
|
+
* @returns {string}
|
|
1233
1253
|
* @throws {TypeError} if `obj` param is not an object
|
|
1254
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
1234
1255
|
*/
|
|
1235
|
-
function
|
|
1256
|
+
function readXObjAttrEx(obj, attr, opt, key) {
|
|
1236
1257
|
let result = undefined;
|
|
1237
1258
|
try {
|
|
1238
1259
|
result = readXObjAttrRaw(obj, attr, key);
|
|
@@ -1246,7 +1267,14 @@ function readXObjAttrAsIndex(obj, attr, key) {
|
|
|
1246
1267
|
}
|
|
1247
1268
|
};
|
|
1248
1269
|
};
|
|
1249
|
-
|
|
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);
|
|
1250
1278
|
};
|
|
1251
1279
|
|
|
1252
1280
|
/**
|
|
@@ -1307,6 +1335,7 @@ function writeXObjAttrAsBool(obj, attr, value, defValue, key) {
|
|
|
1307
1335
|
};
|
|
1308
1336
|
return isSucceed;
|
|
1309
1337
|
};
|
|
1338
|
+
module.exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
|
|
1310
1339
|
|
|
1311
1340
|
/**
|
|
1312
1341
|
* Tries to convert a given value to a number and writes it as an attribute
|
|
@@ -1339,6 +1368,7 @@ function writeXObjAttrAsNum(obj, attr, value, defValue, key) {
|
|
|
1339
1368
|
};
|
|
1340
1369
|
return isSucceed;
|
|
1341
1370
|
};
|
|
1371
|
+
module.exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
|
|
1342
1372
|
|
|
1343
1373
|
/**
|
|
1344
1374
|
* Tries to convert a given value into an 'index' value and writes it
|
|
@@ -1370,6 +1400,7 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1370
1400
|
};
|
|
1371
1401
|
return isSucceed;
|
|
1372
1402
|
};
|
|
1403
|
+
module.exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
|
|
1373
1404
|
|
|
1374
1405
|
/**
|
|
1375
1406
|
* Tries to convert a given value to a string and writes it as an attribute
|
|
@@ -1604,28 +1635,16 @@ module.exports.clearXObjNode = clearXObjNode;
|
|
|
1604
1635
|
|
|
1605
1636
|
module.exports.readXObjParamRaw = readXObjParamRaw;
|
|
1606
1637
|
module.exports.readXObjParam = readXObjParam;
|
|
1607
|
-
module.exports.readXObjParamAsBool = readXObjParamAsBool;
|
|
1608
|
-
module.exports.readXObjParamAsNum = readXObjParamAsNum;
|
|
1609
1638
|
module.exports.readXObjParamEx = readXObjParamEx;
|
|
1610
|
-
module.exports.readXObjParamAsIndex = readXObjParamAsIndex;
|
|
1611
1639
|
module.exports.writeXObjParamRaw = writeXObjParamRaw;
|
|
1612
1640
|
module.exports.writeXObjParam = writeXObjParam;
|
|
1613
|
-
module.exports.writeXObjParamAsBool = writeXObjParamAsBool;
|
|
1614
|
-
module.exports.writeXObjParamAsNum = writeXObjParamAsNum;
|
|
1615
|
-
module.exports.writeXObjParamAsIndex = writeXObjParamAsIndex;
|
|
1616
1641
|
module.exports.writeXObjParamEx = writeXObjParamEx;
|
|
1617
1642
|
|
|
1618
1643
|
module.exports.readXObjAttrRaw = readXObjAttrRaw;
|
|
1619
1644
|
module.exports.readXObjAttr = readXObjAttr;
|
|
1620
|
-
module.exports.readXObjAttrAsBool = readXObjAttrAsBool;
|
|
1621
|
-
module.exports.readXObjAttrAsNum = readXObjAttrAsNum;
|
|
1622
1645
|
module.exports.readXObjAttrEx = readXObjAttrEx;
|
|
1623
|
-
module.exports.readXObjAttrAsIndex = readXObjAttrAsIndex;
|
|
1624
1646
|
module.exports.writeXObjAttrRaw = writeXObjAttrRaw;
|
|
1625
1647
|
module.exports.writeXObjAttr = writeXObjAttr;
|
|
1626
|
-
module.exports.writeXObjAttrAsBool = writeXObjAttrAsBool;
|
|
1627
|
-
module.exports.writeXObjAttrAsNum = writeXObjAttrAsNum;
|
|
1628
|
-
module.exports.writeXObjAttrAsIndex = writeXObjAttrAsIndex;
|
|
1629
1648
|
module.exports.writeXObjAttrEx = writeXObjAttrEx;
|
|
1630
1649
|
|
|
1631
1650
|
module.exports.getXObjAttributes = getXObjAttributes;
|