@ygracs/xobj-lib-js 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/doc/xObj.md +34 -2
- package/index.d.ts +13 -15
- package/index.js +13 -3
- package/lib/xObj-attr.js +36 -31
- package/lib/xObj-lib.d.ts +75 -165
- package/lib/xObj-lib.js +143 -275
- package/lib/xObj-names.d.ts +102 -0
- package/lib/xObj-names.js +219 -0
- package/lib/xObj-param.js +4 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
#### *v0.4.1*
|
|
2
|
+
|
|
3
|
+
Release version.
|
|
4
|
+
|
|
5
|
+
> - update `xObj.md`;
|
|
6
|
+
> - add a new function: `insertXObjNode`;
|
|
7
|
+
> - some fixes.
|
|
8
|
+
|
|
9
|
+
#### *v0.4.0*
|
|
10
|
+
|
|
11
|
+
Release version.
|
|
12
|
+
|
|
13
|
+
> - update dependency on `@ygracs/bsfoc-lib-js` module to v0.4.0;
|
|
14
|
+
> - some fixes.
|
|
15
|
+
|
|
1
16
|
#### *v0.3.3*
|
|
2
17
|
|
|
3
18
|
Release version.
|
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.54|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2026-
|
|
3
|
+
>|date:|2026-07-12|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -24,6 +24,8 @@ This paper describes a functions provided by `xObj.js` module.
|
|
|
24
24
|
- <a href="#func+attribute+write">write element attributes</a>
|
|
25
25
|
- <a href="#func+param+read">read element parameter</a>
|
|
26
26
|
- <a href="#func+param+write">write element parameter</a>
|
|
27
|
+
- <a href="#func+other">other</a>
|
|
28
|
+
- <a href="#func+experimental">experimental</a>
|
|
27
29
|
|
|
28
30
|
### Base type definitions
|
|
29
31
|
|
|
@@ -885,6 +887,7 @@ The function throws a `EvalKeyNameError` exception in case:
|
|
|
885
887
|
+ if `value` parameter given and is not a type of a `string`;
|
|
886
888
|
+ if `key` parameter given and is not a type of a `string`.
|
|
887
889
|
|
|
890
|
+
<a name="func+other"></a>
|
|
888
891
|
### Other functions
|
|
889
892
|
|
|
890
893
|
<a name="getXObjElement"></a>
|
|
@@ -1234,6 +1237,7 @@ The function throws a `EvalKeyNameError` exception in case:
|
|
|
1234
1237
|
- code: `ERR_XOBJ_INVARG_KEY`
|
|
1235
1238
|
+ if `name` parameter given and is an empty string.
|
|
1236
1239
|
|
|
1240
|
+
<a name="func+experimental"></a>
|
|
1237
1241
|
### Experimental functions
|
|
1238
1242
|
|
|
1239
1243
|
> Note: Purpose of those functions will be discussed and some may be deprecate and make obsolete or functionality may be altered. So use it with cautions in mind.
|
|
@@ -1269,6 +1273,34 @@ The object `conditions` property (*if present*) contains following attributes:
|
|
|
1269
1273
|
|`name`|`string`||
|
|
1270
1274
|
|`value`|`any`||
|
|
1271
1275
|
|
|
1276
|
+
<a name="insertXObjNode"></a>
|
|
1277
|
+
#### **insertXObjNode(object, name)** => `null`\|`object`
|
|
1278
|
+
|
|
1279
|
+
> since: \[v0.4.1]
|
|
1280
|
+
|
|
1281
|
+
This function inserts an empty element named by a `name` parameter into a given object. When element exists but it is not an `object`, such element will be replaced. If succeed the element will be returned or `null` in opposite.
|
|
1282
|
+
|
|
1283
|
+
##### ***parameters***
|
|
1284
|
+
|
|
1285
|
+
| parameter name | value type | default value | description |
|
|
1286
|
+
|:---|---|---:|:---|
|
|
1287
|
+
| `object` | `INode` | --- | some object |
|
|
1288
|
+
| `name` | `string` | --- | some child element ID |
|
|
1289
|
+
|
|
1290
|
+
##### ***exceptions***
|
|
1291
|
+
|
|
1292
|
+
The function throws a `TypeError` exception in case:
|
|
1293
|
+
|
|
1294
|
+
- code: `ERR_XOBJ_NPOBJ`
|
|
1295
|
+
+ if `object` parameter is not an `Object` instance;
|
|
1296
|
+
|
|
1297
|
+
The function throws a `EvalKeyNameError` exception in case:
|
|
1298
|
+
|
|
1299
|
+
- code: `ERR_XOBJ_NSTR`
|
|
1300
|
+
+ if `name` parameter given and is not a type of a `string`;
|
|
1301
|
+
- code: `ERR_XOBJ_INVARG_KEY`
|
|
1302
|
+
+ if `name` parameter given and is an empty string.
|
|
1303
|
+
|
|
1272
1304
|
<a name="insertXObjElements"></a>
|
|
1273
1305
|
#### **insertXObjElements(object, name\[...name_N\[, options]])** => `number`
|
|
1274
1306
|
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { TXmlContentParseOptions } from "./lib/xObj-defs";
|
|
2
2
|
import { DEF_XML_PARSE_OPTIONS } from "./lib/xObj-defs";
|
|
3
3
|
import { XOBJ_DEF_TNAMES } from "./lib/xObj-defs";
|
|
4
|
+
import { EvalKeyNameError } from "./lib/xObj-errors";
|
|
5
|
+
import { evalXObjEName } from "./lib/xObj-names";
|
|
6
|
+
import { genXObjENameDescr } from "./lib/xObj-names";
|
|
4
7
|
|
|
5
8
|
export {
|
|
6
9
|
TXmlContentParseOptions,
|
|
@@ -8,6 +11,8 @@ export {
|
|
|
8
11
|
XOBJ_DEF_TNAMES,
|
|
9
12
|
};
|
|
10
13
|
|
|
14
|
+
export { EvalKeyNameError };
|
|
15
|
+
|
|
11
16
|
import type {
|
|
12
17
|
xml2jsParseOptions, js2xmlParseOptions,
|
|
13
18
|
OPT_parserOptions,
|
|
@@ -18,10 +23,6 @@ export type {
|
|
|
18
23
|
OPT_parserOptions,
|
|
19
24
|
};
|
|
20
25
|
|
|
21
|
-
import { EvalKeyNameError } from "./lib/xObj-errors";
|
|
22
|
-
|
|
23
|
-
export { EvalKeyNameError };
|
|
24
|
-
|
|
25
26
|
import {
|
|
26
27
|
readXObjAttrRaw,
|
|
27
28
|
readXObjAttr,
|
|
@@ -55,12 +56,10 @@ import {
|
|
|
55
56
|
deleteXObjElement, deleteXObjElementEx,
|
|
56
57
|
renameXObjElement,
|
|
57
58
|
insertXObjEList, insertXObjEListEx,
|
|
58
|
-
evalXObjEName,
|
|
59
|
-
evalKeyName,
|
|
60
|
-
genXObjENameDescr,
|
|
61
59
|
insertXObjElements,
|
|
62
60
|
insertXObjEChain,
|
|
63
61
|
clearXObjNode,
|
|
62
|
+
insertXObjNode,
|
|
64
63
|
} from "./lib/xObj-lib";
|
|
65
64
|
|
|
66
65
|
export {
|
|
@@ -91,27 +90,26 @@ export {
|
|
|
91
90
|
renameXObjElement,
|
|
92
91
|
insertXObjEList, insertXObjEListEx,
|
|
93
92
|
evalXObjEName,
|
|
94
|
-
evalKeyName,
|
|
95
93
|
genXObjENameDescr,
|
|
96
94
|
insertXObjElements,
|
|
97
95
|
insertXObjEChain,
|
|
98
96
|
clearXObjNode,
|
|
97
|
+
insertXObjNode,
|
|
99
98
|
};
|
|
100
99
|
|
|
101
100
|
import type {
|
|
102
|
-
|
|
103
|
-
OPT_inselops_L, OPT_inselops_S,
|
|
104
|
-
RVAL_emodif,
|
|
105
|
-
VCOR_evalkname, RVAL_reason,
|
|
101
|
+
IXObjENameDescr, IXObjENameDescrConditions,
|
|
106
102
|
IEvalKeyNameResult,
|
|
103
|
+
} from "./lib/xObj-names";
|
|
104
|
+
|
|
105
|
+
import type {
|
|
106
|
+
OPT_inselops_L, OPT_inselops_S,
|
|
107
107
|
INode,
|
|
108
108
|
} from "./lib/xObj-lib";
|
|
109
109
|
|
|
110
110
|
export type {
|
|
111
|
-
|
|
111
|
+
IXObjENameDescr, IXObjENameDescrConditions,
|
|
112
112
|
OPT_inselops_L, OPT_inselops_S,
|
|
113
|
-
RVAL_emodif,
|
|
114
|
-
VCOR_evalkname, RVAL_reason,
|
|
115
113
|
IEvalKeyNameResult,
|
|
116
114
|
INode,
|
|
117
115
|
};
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.020-20260712]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -12,6 +12,11 @@ const {
|
|
|
12
12
|
EvalKeyNameError,
|
|
13
13
|
} = require('./lib/xObj-errors');
|
|
14
14
|
|
|
15
|
+
const {
|
|
16
|
+
evalXObjEName,
|
|
17
|
+
genXObjENameDescr,
|
|
18
|
+
} = require('./lib/xObj-names');
|
|
19
|
+
|
|
15
20
|
const xObjAttr = require('./lib/xObj-attr');
|
|
16
21
|
|
|
17
22
|
const xObjParam = require('./lib/xObj-param');
|
|
@@ -30,6 +35,9 @@ module.exports.XOBJ_DEF_TNAMES = XOBJ_DEF_TNAMES;
|
|
|
30
35
|
|
|
31
36
|
module.exports.EvalKeyNameError = EvalKeyNameError;
|
|
32
37
|
|
|
38
|
+
module.exports.evalXObjEName = evalXObjEName;
|
|
39
|
+
module.exports.genXObjENameDescr = genXObjENameDescr;
|
|
40
|
+
|
|
33
41
|
module.exports.readXObjParamRaw = xObjParam.readXObjParamRaw;
|
|
34
42
|
module.exports.readXObjParam = xObjParam.readXObjParam;
|
|
35
43
|
module.exports.readXObjParamAsBool = xObjParam.readXObjParamAsBool;
|
|
@@ -70,12 +78,14 @@ module.exports.deleteXObjElement = xObj.deleteXObjElement;
|
|
|
70
78
|
module.exports.deleteXObjElementEx = xObj.deleteXObjElementEx;
|
|
71
79
|
module.exports.renameXObjElement = xObj.renameXObjElement;
|
|
72
80
|
|
|
73
|
-
module.exports.evalXObjEName = xObj.evalXObjEName;
|
|
74
81
|
module.exports.insertXObjEList = xObj.insertXObjEList;
|
|
75
82
|
module.exports.insertXObjEListEx = xObj.insertXObjEListEx;
|
|
76
83
|
|
|
77
|
-
module.exports.genXObjENameDescr = xObj.genXObjENameDescr;
|
|
78
84
|
module.exports.insertXObjElements = xObj.insertXObjElements;
|
|
79
85
|
module.exports.insertXObjEChain = xObj.insertXObjEChain;
|
|
80
86
|
|
|
87
|
+
module.exports.clearXObjNode = xObj.clearXObjNode;
|
|
88
|
+
module.exports.insertXObjNode = xObj.insertXObjNode;
|
|
89
|
+
|
|
90
|
+
|
|
81
91
|
module.exports.INode = xObj.INode;
|
package/lib/xObj-attr.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.3.
|
|
1
|
+
// [v0.3.144-20260712]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -21,7 +21,10 @@ const {
|
|
|
21
21
|
|
|
22
22
|
const {
|
|
23
23
|
evalKeyName,
|
|
24
|
-
|
|
24
|
+
} = require('./xObj-names');
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
getXObjElement, insertXObjNode,
|
|
25
28
|
// * import types definitions *
|
|
26
29
|
INode,
|
|
27
30
|
} = require('./xObj-lib');
|
|
@@ -154,28 +157,32 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
154
157
|
);
|
|
155
158
|
};
|
|
156
159
|
const opt = false;
|
|
157
|
-
const { isSucceed, value:
|
|
160
|
+
const { isSucceed, value: aKey } = evalKeyName(key, opt);
|
|
158
161
|
if (isSucceed) {
|
|
159
162
|
let isSucceed = false;
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
if (isPlainObject(
|
|
163
|
-
const { isSucceed: isAcceptON, value:
|
|
163
|
+
if (aKey !== '') {
|
|
164
|
+
const aNode = obj[aKey];
|
|
165
|
+
if (isPlainObject(aNode)) {
|
|
166
|
+
const { isSucceed: isAcceptON, value: aname } = evalKeyName(attr, opt);
|
|
164
167
|
if (!isAcceptON) {
|
|
165
|
-
const { code, msg } =
|
|
168
|
+
const { code, msg } = aname;
|
|
166
169
|
throw new EvalKeyNameError(msg, { code });
|
|
167
170
|
};
|
|
168
|
-
const { isSucceed: isAcceptNN, value:
|
|
171
|
+
const { isSucceed: isAcceptNN, value: vname } = evalKeyName(value, opt);
|
|
169
172
|
if (!isAcceptNN) {
|
|
170
|
-
const { code, msg } =
|
|
173
|
+
const { code, msg } = vname;
|
|
171
174
|
throw new EvalKeyNameError(msg, { code });
|
|
172
175
|
};
|
|
173
|
-
if (
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
if (aname !== '' && aname in aNode && vname !== '') {
|
|
177
|
+
if (aname !== vname) {
|
|
178
|
+
const entries = Object.entries(aNode);
|
|
179
|
+
const ai = entries.findIndex((item) => item[0] === aname);
|
|
180
|
+
if (vname in aNode) {
|
|
181
|
+
const vi = entries.findIndex((item) => item[0] === vname);
|
|
182
|
+
if (ai < vi) entries[vi][1] = entries[ai][1];
|
|
183
|
+
};
|
|
184
|
+
entries[ai][0] = vname;
|
|
185
|
+
obj[aKey] = Object.fromEntries(entries);
|
|
179
186
|
};
|
|
180
187
|
isSucceed = true;
|
|
181
188
|
};
|
|
@@ -183,7 +190,7 @@ function renameXObjAttribute(obj, attr = '', value = '', key = XOBJ_DEF_ATTR_TNA
|
|
|
183
190
|
};
|
|
184
191
|
return isSucceed;
|
|
185
192
|
} else {
|
|
186
|
-
const { code, msg } =
|
|
193
|
+
const { code, msg } = aKey;
|
|
187
194
|
throw new EvalKeyNameError(msg, { code });
|
|
188
195
|
};
|
|
189
196
|
};
|
|
@@ -240,24 +247,22 @@ function writeXObjAttrRaw(obj, attr = '', value, key = XOBJ_DEF_ATTR_TNAME) {
|
|
|
240
247
|
&& !isObject(value)
|
|
241
248
|
&& typeof value !== 'function'
|
|
242
249
|
) {
|
|
243
|
-
let
|
|
250
|
+
let node = null;
|
|
244
251
|
try {
|
|
245
|
-
|
|
246
|
-
_obj = insertXObjElement(obj, key, opt);
|
|
252
|
+
node = insertXObjNode(obj, key);
|
|
247
253
|
} catch (err) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
throw err;
|
|
254
|
+
switch (err.code) {
|
|
255
|
+
case XOBJ_TE_NSTR_ECODE :
|
|
256
|
+
case XOBJ_TE_KNES_ECODE : {
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
default: {
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
257
262
|
};
|
|
258
263
|
};
|
|
259
|
-
if (
|
|
260
|
-
|
|
264
|
+
if (node !== null) {
|
|
265
|
+
node[name] = value;
|
|
261
266
|
isSucceed = true;
|
|
262
267
|
};
|
|
263
268
|
};
|
package/lib/xObj-lib.d.ts
CHANGED
|
@@ -1,196 +1,102 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A
|
|
2
|
+
* A `Node`-element
|
|
3
|
+
* @since 0.3.2
|
|
3
4
|
*/
|
|
4
|
-
export type IEvalKeyNameResult = IEvalKeyNameResultOnSuccess | IEvalKeyNameResultOnFail;
|
|
5
|
-
export const IEvalKeyNameResult: IEvalKeyNameResult;
|
|
6
5
|
export type INode = {
|
|
7
6
|
[x: string]: any;
|
|
8
7
|
};
|
|
9
8
|
export const INode: INode;
|
|
10
9
|
/**
|
|
11
|
-
* A result of an xObj modification ops
|
|
12
|
-
*/
|
|
13
|
-
export type INodeModifResult = INodeModifResultOnFail | INodeModifResultOnSuccess;
|
|
14
|
-
export const INodeModifResult: INodeModifResult;
|
|
15
|
-
/**
|
|
16
|
-
* Some conditions applied to an element as a result of an element name pattern
|
|
17
|
-
* evaluation ops.
|
|
18
|
-
*/
|
|
19
|
-
export type XObjENameDescrConditions = {
|
|
20
|
-
/**
|
|
21
|
-
* - element name
|
|
22
|
-
*/
|
|
23
|
-
name: any;
|
|
24
|
-
/**
|
|
25
|
-
* - element type
|
|
26
|
-
*/
|
|
27
|
-
type: any;
|
|
28
|
-
/**
|
|
29
|
-
* - some value
|
|
30
|
-
*/
|
|
31
|
-
value?: any;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* A result of an element name pattern evaluation ops.
|
|
10
|
+
* A result of an xObj modification ops if failed
|
|
35
11
|
*/
|
|
36
|
-
export type
|
|
37
|
-
/**
|
|
38
|
-
* - ops flag
|
|
39
|
-
*/
|
|
40
|
-
isERR: boolean;
|
|
12
|
+
export type INodeModifResultOnFail = {
|
|
41
13
|
/**
|
|
42
|
-
* -
|
|
14
|
+
* - flag that indicates whether an ops is succeed or not
|
|
43
15
|
*/
|
|
44
|
-
|
|
16
|
+
isSucceed: false;
|
|
45
17
|
/**
|
|
46
|
-
* - some
|
|
18
|
+
* - some element as a result
|
|
47
19
|
*/
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* A list of a `INode`-elements
|
|
52
|
-
*/
|
|
53
|
-
export type INodeList = INode[];
|
|
54
|
-
/**
|
|
55
|
-
* An options for an element insertion ops
|
|
56
|
-
*/
|
|
57
|
-
export type OPT_inselops_L = {
|
|
58
|
-
force?: boolean;
|
|
59
|
-
ripOldies?: boolean;
|
|
60
|
-
acceptIfList?: boolean;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* An options for an element insertion ops
|
|
64
|
-
*/
|
|
65
|
-
export type OPT_inselops_S = {
|
|
66
|
-
force?: boolean;
|
|
67
|
-
ripOldies?: boolean;
|
|
20
|
+
item: null;
|
|
68
21
|
};
|
|
22
|
+
export const INodeModifResultOnFail: INodeModifResultOnFail;
|
|
69
23
|
/**
|
|
70
|
-
* A result of
|
|
71
|
-
* @deprecated
|
|
72
|
-
* @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameReasonOnFail` instead.
|
|
24
|
+
* A result of an xObj modification ops if succeed (when child element returned)
|
|
73
25
|
*/
|
|
74
|
-
export type
|
|
26
|
+
export type INodeModifResultOnSuccess_S1 = {
|
|
75
27
|
/**
|
|
76
|
-
* -
|
|
28
|
+
* - flag that indicates whether an ops is succeed or not
|
|
77
29
|
*/
|
|
78
|
-
|
|
30
|
+
isSucceed: true;
|
|
79
31
|
/**
|
|
80
|
-
* -
|
|
32
|
+
* - some element as a result
|
|
81
33
|
*/
|
|
82
|
-
|
|
34
|
+
item: INode;
|
|
83
35
|
};
|
|
36
|
+
export const INodeModifResultOnSuccess_S1: INodeModifResultOnSuccess_S1;
|
|
84
37
|
/**
|
|
85
|
-
*
|
|
38
|
+
* A result of an xObj modification ops if succeed (when child element returned)
|
|
86
39
|
*/
|
|
87
|
-
export type
|
|
40
|
+
export type INodeModifResultOnSuccess_S2 = {
|
|
88
41
|
/**
|
|
89
|
-
* -
|
|
42
|
+
* - flag that indicates whether an ops is succeed or not
|
|
90
43
|
*/
|
|
91
|
-
|
|
44
|
+
isSucceed: true;
|
|
92
45
|
/**
|
|
93
|
-
* -
|
|
46
|
+
* - some element as a result
|
|
94
47
|
*/
|
|
95
|
-
|
|
48
|
+
item: INode[];
|
|
96
49
|
};
|
|
50
|
+
export const INodeModifResultOnSuccess_S2: INodeModifResultOnSuccess_S2;
|
|
97
51
|
/**
|
|
98
|
-
* A result of
|
|
99
|
-
* @deprecated
|
|
100
|
-
* @todo \[from v0.3.0] make obsolete. Use `IEvalKeyNameResult` instead.
|
|
52
|
+
* A result of an xObj modification ops if succeed (when child element not returned)
|
|
101
53
|
*/
|
|
102
|
-
export type
|
|
54
|
+
export type INodeModifResultOnSuccess_S0 = {
|
|
103
55
|
/**
|
|
104
|
-
* - ops
|
|
56
|
+
* - flag that indicates whether an ops is succeed or not
|
|
105
57
|
*/
|
|
106
|
-
isSucceed:
|
|
58
|
+
isSucceed: true;
|
|
107
59
|
/**
|
|
108
|
-
* -
|
|
60
|
+
* - some element as a result
|
|
109
61
|
*/
|
|
110
|
-
|
|
62
|
+
item: null;
|
|
111
63
|
};
|
|
64
|
+
export const INodeModifResultOnSuccess_S0: INodeModifResultOnSuccess_S0;
|
|
112
65
|
/**
|
|
113
|
-
*
|
|
66
|
+
* A list of a `Node`-elements
|
|
114
67
|
*/
|
|
115
|
-
export type
|
|
116
|
-
/**
|
|
117
|
-
* - a flag to accept only a non-empty string values
|
|
118
|
-
*/
|
|
119
|
-
onlyNES?: boolean;
|
|
120
|
-
};
|
|
68
|
+
export type INodeList = INode[];
|
|
121
69
|
/**
|
|
122
|
-
* A result of
|
|
70
|
+
* A result of an xObj modification ops
|
|
71
|
+
* @since 0.4.0
|
|
123
72
|
*/
|
|
124
|
-
export type
|
|
125
|
-
/**
|
|
126
|
-
* - ops flag
|
|
127
|
-
*/
|
|
128
|
-
isSucceed: true;
|
|
129
|
-
/**
|
|
130
|
-
* - result value
|
|
131
|
-
*/
|
|
132
|
-
value: string;
|
|
133
|
-
};
|
|
73
|
+
export type IAddNodeResult = INodeModifResultOnFail | INodeModifResultOnSuccess_S1;
|
|
134
74
|
/**
|
|
135
|
-
*
|
|
75
|
+
* An options for an element insertion ops
|
|
136
76
|
*/
|
|
137
|
-
export type
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
isSucceed: false;
|
|
142
|
-
/**
|
|
143
|
-
* - reason of fail
|
|
144
|
-
*/
|
|
145
|
-
value: IEvalKeyNameReasonOnFail;
|
|
77
|
+
export type OPT_inselops_L = {
|
|
78
|
+
force?: boolean;
|
|
79
|
+
ripOldies?: boolean;
|
|
80
|
+
acceptIfList?: boolean;
|
|
146
81
|
};
|
|
147
82
|
/**
|
|
148
83
|
* A result of an xObj modification ops
|
|
149
|
-
* @
|
|
150
|
-
* @todo \[from v0.3.2] make obsolete. Use `INodeModifResult` instead.
|
|
84
|
+
* @since 0.4.0
|
|
151
85
|
*/
|
|
152
|
-
export type
|
|
153
|
-
/**
|
|
154
|
-
* - flag that indicates whether an ops is succeed or not
|
|
155
|
-
*/
|
|
156
|
-
isSucceed: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* - some element as a result
|
|
159
|
-
*/
|
|
160
|
-
item: object | object[] | null;
|
|
161
|
-
};
|
|
86
|
+
export type IInsertNodeResult = INodeModifResultOnFail | INodeModifResultOnSuccess_S1 | INodeModifResultOnSuccess_S2;
|
|
162
87
|
/**
|
|
163
|
-
* A result of an xObj modification ops
|
|
88
|
+
* A result of an xObj modification ops
|
|
89
|
+
* @since 0.4.0
|
|
164
90
|
*/
|
|
165
|
-
export type
|
|
166
|
-
/**
|
|
167
|
-
* - flag that indicates whether an ops is succeed or not
|
|
168
|
-
*/
|
|
169
|
-
isSucceed: false;
|
|
170
|
-
/**
|
|
171
|
-
* - some element as a result
|
|
172
|
-
*/
|
|
173
|
-
item: null;
|
|
174
|
-
};
|
|
91
|
+
export type IDeleteNodeResult = INodeModifResultOnFail | INodeModifResultOnSuccess_S0 | INodeModifResultOnSuccess_S1 | INodeModifResultOnSuccess_S2;
|
|
175
92
|
/**
|
|
176
|
-
*
|
|
93
|
+
* An options for an element insertion ops
|
|
177
94
|
*/
|
|
178
|
-
export type
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*/
|
|
182
|
-
isSucceed: true;
|
|
183
|
-
/**
|
|
184
|
-
* - some element as a result
|
|
185
|
-
*/
|
|
186
|
-
item: object | object[];
|
|
95
|
+
export type OPT_inselops_S = {
|
|
96
|
+
force?: boolean;
|
|
97
|
+
ripOldies?: boolean;
|
|
187
98
|
};
|
|
188
99
|
|
|
189
|
-
/**
|
|
190
|
-
* Tries to convert a value into an ID.
|
|
191
|
-
* @inner
|
|
192
|
-
*/
|
|
193
|
-
export function evalKeyName(value: any, opt?: boolean | IEvalKeyNameOptions): IEvalKeyNameResult;
|
|
194
100
|
/**
|
|
195
101
|
* Extracts an element from a given object by its key.
|
|
196
102
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -202,7 +108,7 @@ export function getXObjElement(obj: INode, name: string): any | null;
|
|
|
202
108
|
* @throws {TypeError} if `obj` param is not an object
|
|
203
109
|
* @see {@link addXObjElementEx} for param details
|
|
204
110
|
*/
|
|
205
|
-
export function addXObjElement(...args: addXObjElementParams):
|
|
111
|
+
export function addXObjElement(...args: addXObjElementParams): INode | null;
|
|
206
112
|
type addXObjElementParams = Parameters<typeof addXObjElementEx>;
|
|
207
113
|
/**
|
|
208
114
|
* Adds an element addressed by its key to a given object.
|
|
@@ -210,13 +116,13 @@ type addXObjElementParams = Parameters<typeof addXObjElementEx>;
|
|
|
210
116
|
* @throws {TypeError} if `obj` param is not an object
|
|
211
117
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
212
118
|
*/
|
|
213
|
-
export function addXObjElementEx(obj: INode, name: string):
|
|
119
|
+
export function addXObjElementEx(obj: INode, name: string): IAddNodeResult;
|
|
214
120
|
/**
|
|
215
121
|
* Inserts an element addressed by its key into a given object.
|
|
216
122
|
* @throws {TypeError} if `obj` param is not an object
|
|
217
123
|
* @see {@link insertXObjElementEx} for param details
|
|
218
124
|
*/
|
|
219
|
-
export function insertXObjElement(...args: insertXObjElementParams):
|
|
125
|
+
export function insertXObjElement(...args: insertXObjElementParams): INode | INode[] | null;
|
|
220
126
|
type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
|
|
221
127
|
/**
|
|
222
128
|
* Inserts an element addressed by its key into a given object.
|
|
@@ -224,7 +130,7 @@ type insertXObjElementParams = Parameters<typeof insertXObjElementEx>;
|
|
|
224
130
|
* @throws {TypeError} if `obj` param is not an object
|
|
225
131
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
226
132
|
*/
|
|
227
|
-
export function insertXObjElementEx(obj: INode, name: string, opt?: OPT_inselops_L):
|
|
133
|
+
export function insertXObjElementEx(obj: INode, name: string, opt?: OPT_inselops_L): IInsertNodeResult;
|
|
228
134
|
/**
|
|
229
135
|
* Deletes an element addressed by its key from a given object.
|
|
230
136
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -237,7 +143,7 @@ type deleteXObjElementParams = Parameters<typeof deleteXObjElementEx>;
|
|
|
237
143
|
* @throws {TypeError} if `obj` param is not an object
|
|
238
144
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
239
145
|
*/
|
|
240
|
-
export function deleteXObjElementEx(obj: INode, name: string):
|
|
146
|
+
export function deleteXObjElementEx(obj: INode, name: string): IDeleteNodeResult;
|
|
241
147
|
/**
|
|
242
148
|
* Renames an element addressed by its key.
|
|
243
149
|
* @throws {TypeError} if `obj` param is not an object
|
|
@@ -245,21 +151,12 @@ export function deleteXObjElementEx(obj: INode, name: string): INodeModifResult;
|
|
|
245
151
|
* @throws {EvalKeyNameError} if `value` param is not valid identifier
|
|
246
152
|
*/
|
|
247
153
|
export function renameXObjElement(obj: INode, name?: string, value?: string): boolean;
|
|
248
|
-
/**
|
|
249
|
-
* Clears a given node
|
|
250
|
-
* @throws {TypeError} if `node`-param is not an object or array
|
|
251
|
-
*/
|
|
252
|
-
export function clearXObjNode(node: INode | INode[]): boolean;
|
|
253
|
-
/**
|
|
254
|
-
* Tries to convert a value into an ID.
|
|
255
|
-
*/
|
|
256
|
-
export function evalXObjEName(value: any): null | number | string;
|
|
257
154
|
/**
|
|
258
155
|
* Inserts a list elements into a given object.
|
|
259
156
|
* @throws {TypeError} if `obj` param is not an object
|
|
260
157
|
* @see insertXObjEListEx
|
|
261
158
|
*/
|
|
262
|
-
export function insertXObjEList(...args: insertXObjEListParams):
|
|
159
|
+
export function insertXObjEList(...args: insertXObjEListParams): INode[] | null;
|
|
263
160
|
type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
|
|
264
161
|
/**
|
|
265
162
|
* Inserts a list elements into a given object.
|
|
@@ -267,18 +164,31 @@ type insertXObjEListParams = Parameters<typeof insertXObjEListEx>;
|
|
|
267
164
|
* @throws {TypeError} if `obj` param is not an object
|
|
268
165
|
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
269
166
|
*/
|
|
270
|
-
export function insertXObjEListEx(obj: INode, name: string, opt?: OPT_inselops_S):
|
|
167
|
+
export function insertXObjEListEx(obj: INode, name: string, opt?: OPT_inselops_S): INodeModifResultOnFail | INodeModifResultOnSuccess_S2;
|
|
271
168
|
/**
|
|
272
|
-
*
|
|
169
|
+
* Inserts a chain of an elements into a given object.
|
|
170
|
+
* @throws {TypeError} if `obj` param is not an object
|
|
171
|
+
* @experimental
|
|
273
172
|
*/
|
|
274
|
-
export function
|
|
173
|
+
export function insertXObjEChain(obj: INode, ...args: insertListOfElementsParams): any | null;
|
|
275
174
|
/**
|
|
276
|
-
*
|
|
175
|
+
* Clears a given node
|
|
176
|
+
* @throws {TypeError} if `node`-param is not an object or array
|
|
177
|
+
*/
|
|
178
|
+
export function clearXObjNode(node: INode | INode[]): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Inserts an element addressed by its key into a given object. If it exists
|
|
181
|
+
* and it is not an `object` a function forces an element replacement.
|
|
182
|
+
* @since 0.4.1
|
|
183
|
+
* @experimental
|
|
277
184
|
* @throws {TypeError} if `obj` param is not an object
|
|
185
|
+
* @throws {EvalKeyNameError} if `name` param is not valid identifier
|
|
278
186
|
*/
|
|
279
|
-
export function
|
|
187
|
+
export function insertXObjNode(obj: INode, name: string): INode | null;
|
|
280
188
|
/**
|
|
281
|
-
* Inserts
|
|
189
|
+
* Inserts an elements into a given object.
|
|
282
190
|
* @throws {TypeError} if `obj` param is not an object
|
|
191
|
+
* @experimental
|
|
283
192
|
*/
|
|
284
|
-
export function
|
|
193
|
+
export function insertXObjElements(obj: INode, ...args: insertListOfElementsParams): number;
|
|
194
|
+
type insertListOfElementsParams = [ ...names: string[], options: OPT_inselops_L];
|