@ygracs/xobj-lib-js 0.2.9-b.1 → 0.2.9-b.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/doc/xObj.md +39 -2
- package/index.d.ts +1 -0
- package/lib/xObj-defs.d.ts +4 -0
- package/lib/xObj-defs.js +10 -1
- package/lib/xObj-errors.js +2 -1
- package/lib/xObj-lib.d.ts +5 -0
- package/lib/xObj-lib.js +46 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,10 @@ Release version.
|
|
|
6
6
|
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
|
|
7
7
|
> - change behavior for function: `evalKeyName` on handling `opt` parameter;
|
|
8
8
|
> - change behavior for function: `writeXObjParamRaw`, `writeXObjAttrRaw`;
|
|
9
|
+
> - improve behavior for function: `writeXObjParam`, `writeXObjParamEx`, `writeXObjAttr`, `writeXObjAttrEx`;
|
|
10
|
+
> - add a new function: `clearXObjNode`;
|
|
9
11
|
> - add a new `EvalKeyNameError` class;
|
|
12
|
+
> - add new `compact`-property for `TXmlContentParseOptions`;
|
|
10
13
|
> - some fixes.
|
|
11
14
|
|
|
12
15
|
#### *v0.2.4*
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.48|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2026-02-
|
|
3
|
+
>|date:|2026-02-22|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -19,6 +19,10 @@ This paper describes a functions provided by `xObj.js` module.
|
|
|
19
19
|
- <a href="#EvalKeyNameError">EvalKeyNameError</a>
|
|
20
20
|
|
|
21
21
|
- Functions
|
|
22
|
+
- <a href="#func+attribute+read">read element attributes</a>
|
|
23
|
+
- <a href="#func+attribute+write">write element attributes</a>
|
|
24
|
+
- <a href="#func+param+read">read element parameter</a>
|
|
25
|
+
- <a href="#func+param+write">write element parameter</a>
|
|
22
26
|
|
|
23
27
|
### Base type definitions
|
|
24
28
|
|
|
@@ -135,6 +139,7 @@ The settings listed in the table below:
|
|
|
135
139
|
| `trim` | `boolean` | `true` ||
|
|
136
140
|
| `spaces` | `number` | `2` ||
|
|
137
141
|
|
|
142
|
+
<a name="func+param+read"></a>
|
|
138
143
|
### Base functions for read an object parameter value
|
|
139
144
|
|
|
140
145
|
> Note:
|
|
@@ -259,6 +264,7 @@ The function throws a `TypeError` exception in case:
|
|
|
259
264
|
- code: `ERR_XOBJ_NPOBJ`
|
|
260
265
|
+ if `object` parameter is not an `Object` instance.
|
|
261
266
|
|
|
267
|
+
<a name="func+param+write"></a>
|
|
262
268
|
### Base functions for write an object parameter value
|
|
263
269
|
|
|
264
270
|
> Note:
|
|
@@ -384,6 +390,7 @@ The function throws a `TypeError` exception in case:
|
|
|
384
390
|
- code: `ERR_XOBJ_NPOBJ`
|
|
385
391
|
+ if `object` parameter is not an `Object` instance.
|
|
386
392
|
|
|
393
|
+
<a name="func+attribute+read"></a>
|
|
387
394
|
### Base functions for read an object attributes value
|
|
388
395
|
|
|
389
396
|
> Note:
|
|
@@ -513,6 +520,7 @@ The function throws a `TypeError` exception in case:
|
|
|
513
520
|
- code: `ERR_XOBJ_NPOBJ`
|
|
514
521
|
+ if `object` parameter is not an `Object` instance.
|
|
515
522
|
|
|
523
|
+
<a name="func+attribute+write"></a>
|
|
516
524
|
### Base functions for write an object attributes value
|
|
517
525
|
|
|
518
526
|
> Note:
|
|
@@ -1048,6 +1056,26 @@ The function throws a `TypeError` exception in case:
|
|
|
1048
1056
|
+ if `name` parameter given and is not a type of a `string`;
|
|
1049
1057
|
+ id `value` parameter given and is not a type of a `string`.
|
|
1050
1058
|
|
|
1059
|
+
<a name="clearXObjNode"></a>
|
|
1060
|
+
#### **clearXObjNode(node)** => `boolean`
|
|
1061
|
+
|
|
1062
|
+
> since: \[v0.2.x]
|
|
1063
|
+
|
|
1064
|
+
This function tries to clean a given node.
|
|
1065
|
+
|
|
1066
|
+
##### ***parameters***
|
|
1067
|
+
|
|
1068
|
+
| parameter name | value type | default value | description |
|
|
1069
|
+
|:---|---|---:|:---|
|
|
1070
|
+
| `node` | `object` or `object[]` | --- | some node |
|
|
1071
|
+
|
|
1072
|
+
##### ***exceptions***
|
|
1073
|
+
|
|
1074
|
+
The function throws a `TypeError` exception in case:
|
|
1075
|
+
|
|
1076
|
+
- code: `ERR_XOBJ_NPOBJ`
|
|
1077
|
+
+ if `node` parameter is not an `Object` or `Array` instance;
|
|
1078
|
+
|
|
1051
1079
|
### Other special functions
|
|
1052
1080
|
|
|
1053
1081
|
<a name="evalXObjEName"></a>
|
|
@@ -1233,6 +1261,15 @@ The class constructor receives an arguments listed below:
|
|
|
1233
1261
|
|---|---|:---|
|
|
1234
1262
|
| `object` | yes | contains a current options |
|
|
1235
1263
|
|
|
1264
|
+
<a name="TXmlContentParseOptions+compact"></a>
|
|
1265
|
+
###### **compact**
|
|
1266
|
+
|
|
1267
|
+
> since: \[v0.2.x]
|
|
1268
|
+
|
|
1269
|
+
| property type | read only | description |
|
|
1270
|
+
|---|---|:---|
|
|
1271
|
+
| `boolean` | yes | returns a current value for a `compact`-options |
|
|
1272
|
+
|
|
1236
1273
|
<a name="TXmlContentParseOptions+xml2js"></a>
|
|
1237
1274
|
###### **xml2js**
|
|
1238
1275
|
|
package/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare const _exports: {
|
|
|
41
41
|
genXObjENameDescr: typeof import("./lib/xObj-lib").genXObjENameDescr;
|
|
42
42
|
insertXObjElements: typeof import("./lib/xObj-lib").insertXObjElements;
|
|
43
43
|
insertXObjEChain: typeof import("./lib/xObj-lib").insertXObjEChain;
|
|
44
|
+
clearXObjNode: typeof import("./lib/xObj-lib").clearXObjNode;
|
|
44
45
|
|
|
45
46
|
TXmlContentParseOptions: typeof TXmlContentParseOptions; // [?] class declaration
|
|
46
47
|
DEF_XML_PARSE_OPTIONS: typeof DEF_XML_PARSE_OPTIONS;
|
package/lib/xObj-defs.d.ts
CHANGED
|
@@ -96,6 +96,10 @@ export class TXmlContentParseOptions {
|
|
|
96
96
|
* Contains a set of a current settings
|
|
97
97
|
*/
|
|
98
98
|
get settings(): OPT_parserOptions;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a value of `compact` option
|
|
101
|
+
*/
|
|
102
|
+
get compact(): boolean;
|
|
99
103
|
/**
|
|
100
104
|
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
101
105
|
*/
|
package/lib/xObj-defs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.070-20260221]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -143,6 +143,15 @@ class TXmlContentParseOptions {
|
|
|
143
143
|
return this.#_options;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Returns a value of `compact` option
|
|
148
|
+
* @since 0.2.x
|
|
149
|
+
* @type {boolean}
|
|
150
|
+
*/
|
|
151
|
+
get compact() {
|
|
152
|
+
return this.#_options.compact ? true : false;
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
/**
|
|
147
156
|
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
148
157
|
* @type {xml2jsParseOptions}
|
package/lib/xObj-errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.004-20260221]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -41,6 +41,7 @@ const XOBJ_ECODE_TABLE = {
|
|
|
41
41
|
module.exports.XOBJ_ECODE_TABLE = XOBJ_ECODE_TABLE;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
+
* @since 0.2.x
|
|
44
45
|
* @augments TypeError
|
|
45
46
|
* @classdesc Extends a base `TypeError` object to provide some information
|
|
46
47
|
* on the errors thrown when a key name evaluation failed
|
package/lib/xObj-lib.d.ts
CHANGED
|
@@ -110,6 +110,11 @@ export type OPT_inselops_S = {
|
|
|
110
110
|
ripOldies?: boolean;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Clears a given node
|
|
115
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
116
|
+
*/
|
|
117
|
+
export function clearXObjNode(node: object | object[]): boolean;
|
|
113
118
|
/**
|
|
114
119
|
* Extracts a parameter 'AS IS' from a given object.
|
|
115
120
|
* @throws {TypeError} if first param is not an object
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.127-20260222]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -8,6 +8,8 @@ const {
|
|
|
8
8
|
isNullOrUndef,
|
|
9
9
|
isInteger,
|
|
10
10
|
isArray, isObject, isPlainObject,
|
|
11
|
+
// * import types definitions *
|
|
12
|
+
OPT_valtostr,
|
|
11
13
|
} = require('@ygracs/bsfoc-lib-js');
|
|
12
14
|
|
|
13
15
|
const {
|
|
@@ -806,6 +808,7 @@ function readXObjParam(obj, key) {
|
|
|
806
808
|
* @param {string} [key] - some key
|
|
807
809
|
* @returns {boolean}
|
|
808
810
|
* @throws {TypeError} if first param is not an object
|
|
811
|
+
* @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
809
812
|
*/
|
|
810
813
|
function readXObjParamAsBool(obj, defValue, key) {
|
|
811
814
|
let result = undefined;
|
|
@@ -832,6 +835,7 @@ function readXObjParamAsBool(obj, defValue, key) {
|
|
|
832
835
|
* @param {string} [key] - some key
|
|
833
836
|
* @returns {number}
|
|
834
837
|
* @throws {TypeError} if first param is not an object
|
|
838
|
+
* @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
835
839
|
*/
|
|
836
840
|
function readXObjParamAsNum(obj, defValue, key) {
|
|
837
841
|
let result = undefined;
|
|
@@ -874,14 +878,12 @@ function readXObjParamEx(obj, opt, key) {
|
|
|
874
878
|
}
|
|
875
879
|
};
|
|
876
880
|
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
defValue: _opt,
|
|
884
|
-
};
|
|
881
|
+
/** @type {OPT_valtostr} */
|
|
882
|
+
const _opt = isPlainObject(opt) ? opt : {
|
|
883
|
+
useTrim: false,
|
|
884
|
+
numberToString: true,
|
|
885
|
+
boolToString: true,
|
|
886
|
+
defValue: opt,
|
|
885
887
|
};
|
|
886
888
|
return readAsString(result, _opt);
|
|
887
889
|
};
|
|
@@ -1043,7 +1045,7 @@ function writeXObjParamAsIndex(obj, value, key) {
|
|
|
1043
1045
|
*/
|
|
1044
1046
|
function writeXObjParamEx(obj, value, opt, key) {
|
|
1045
1047
|
let isSucceed = false;
|
|
1046
|
-
if (value !== undefined) {
|
|
1048
|
+
if (value !== undefined && typeof value !== 'function') {
|
|
1047
1049
|
let _opt = opt;
|
|
1048
1050
|
if (!isPlainObject(_opt)) {
|
|
1049
1051
|
const defValue = readAsString(_opt, {
|
|
@@ -1109,6 +1111,7 @@ function readXObjAttr(obj, attr, key) {
|
|
|
1109
1111
|
* @param {string} [key] - some key
|
|
1110
1112
|
* @returns {boolean}
|
|
1111
1113
|
* @throws {TypeError} if first param is not an object
|
|
1114
|
+
* @see readAsBoolEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
1112
1115
|
*/
|
|
1113
1116
|
function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
1114
1117
|
let result = undefined;
|
|
@@ -1136,6 +1139,7 @@ function readXObjAttrAsBool(obj, attr, defValue, key) {
|
|
|
1136
1139
|
* @param {string} [key] - some key
|
|
1137
1140
|
* @returns {number}
|
|
1138
1141
|
* @throws {TypeError} if first param is not an object
|
|
1142
|
+
* @see readAsNumberEx from `@ygracs/bsfoc-lib-js` on details for result
|
|
1139
1143
|
*/
|
|
1140
1144
|
function readXObjAttrAsNum(obj, attr, defValue, key) {
|
|
1141
1145
|
let result = undefined;
|
|
@@ -1179,14 +1183,12 @@ function readXObjAttrEx(obj, attr, opt, key) {
|
|
|
1179
1183
|
}
|
|
1180
1184
|
};
|
|
1181
1185
|
};
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
defValue: _opt,
|
|
1189
|
-
};
|
|
1186
|
+
/** @type {OPT_valtostr} */
|
|
1187
|
+
const _opt = isPlainObject(opt) ? opt : {
|
|
1188
|
+
useTrim: true,
|
|
1189
|
+
numberToString: true,
|
|
1190
|
+
boolToString: true,
|
|
1191
|
+
defValue: opt,
|
|
1190
1192
|
};
|
|
1191
1193
|
return readAsString(result, _opt);
|
|
1192
1194
|
};
|
|
@@ -1354,7 +1356,7 @@ function writeXObjAttrAsIndex(obj, attr, value, key) {
|
|
|
1354
1356
|
*/
|
|
1355
1357
|
function writeXObjAttrEx(obj, attr, value, opt, key) {
|
|
1356
1358
|
let isSucceed = false;
|
|
1357
|
-
if (value !== undefined) {
|
|
1359
|
+
if (value !== undefined && typeof value !== 'function') {
|
|
1358
1360
|
let _opt = opt;
|
|
1359
1361
|
if (!isPlainObject(_opt)) {
|
|
1360
1362
|
const defValue = readAsString(_opt, {
|
|
@@ -1539,9 +1541,32 @@ function insertXObjEChain(obj, ...args) {
|
|
|
1539
1541
|
return result;
|
|
1540
1542
|
};
|
|
1541
1543
|
|
|
1542
|
-
|
|
1543
|
-
*
|
|
1544
|
+
/**
|
|
1545
|
+
* Clears a given node
|
|
1546
|
+
* @param {(object|object[])} node - some node
|
|
1547
|
+
* @returns {boolean}
|
|
1548
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
1544
1549
|
*/
|
|
1550
|
+
function clearXObjNode(node) {
|
|
1551
|
+
if (isObject(node)) {
|
|
1552
|
+
if (isArray(node)) {
|
|
1553
|
+
node.length = 0;
|
|
1554
|
+
return true;
|
|
1555
|
+
};
|
|
1556
|
+
let isSucceed = false;
|
|
1557
|
+
for (const key in node) {
|
|
1558
|
+
// // TODO: catch errors in strict mode
|
|
1559
|
+
isSucceed = delete node[key];
|
|
1560
|
+
};
|
|
1561
|
+
return isSucceed;
|
|
1562
|
+
} else {
|
|
1563
|
+
throw new EvalKeyNameError(
|
|
1564
|
+
XOBJ_TE_NPOBJ_EMSG,
|
|
1565
|
+
{ code: XOBJ_TE_NPOBJ_ECODE },
|
|
1566
|
+
);
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1569
|
+
module.exports.clearXObjNode = clearXObjNode;
|
|
1545
1570
|
|
|
1546
1571
|
// === module exports block ===
|
|
1547
1572
|
|