@ygracs/xobj-lib-js 0.2.3 → 0.2.5-b
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 +13 -0
- package/doc/xObj.md +80 -26
- package/index.d.ts +53 -0
- package/index.js +4 -2
- package/lib/xObj-defs.d.ts +166 -0
- package/lib/xObj-defs.js +102 -15
- package/lib/xObj-lib.d.ts +301 -0
- package/lib/xObj-lib.js +13 -6
- package/package.json +12 -6
package/CHANGELOG.md
CHANGED
package/doc/xObj.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.46|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2025-
|
|
3
|
+
>|date:|2025-12-14|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -36,6 +36,58 @@ The behavior for `letterCase` settings defined in the table below:
|
|
|
36
36
|
| `lower` | the resulting string must to be present in lower case |
|
|
37
37
|
| any other values | the resulting string will be not transformed |
|
|
38
38
|
|
|
39
|
+
<a name="typedef+xml2jsParseOptions"></a>
|
|
40
|
+
#### `xml2jsParseOptions` - parser options set
|
|
41
|
+
|
|
42
|
+
This options set is an `object` which defines how an 'XML'-string transforms into a 'JS'-object.
|
|
43
|
+
|
|
44
|
+
| option name | value type | optional | description |
|
|
45
|
+
|:---|---|---:|:---|
|
|
46
|
+
| `compact` | `boolean` | `yes` ||
|
|
47
|
+
| `declarationKey` | `string` | `yes` ||
|
|
48
|
+
| `attributesKey` | `string` | `yes` ||
|
|
49
|
+
| `textKey` | `string` | `yes` ||
|
|
50
|
+
| `commentKey` | `string` | `yes` ||
|
|
51
|
+
| `cdataKey` | `string` | `yes` ||
|
|
52
|
+
| `nameKey` | `string` | `yes` ||
|
|
53
|
+
| `typeKey` | `string` | `yes` ||
|
|
54
|
+
| `parentKey` | `string` | `yes` ||
|
|
55
|
+
| `elementsKey` | `string` | `yes` ||
|
|
56
|
+
| `ignoreDeclaration` | `boolean` | `yes` ||
|
|
57
|
+
| `ignoreDocType` | `boolean` | `yes` ||
|
|
58
|
+
| `ignoreInstraction` | `boolean` | `yes` ||
|
|
59
|
+
| `ignoreText` | `boolean` | `yes` ||
|
|
60
|
+
| `ignoreComment` | `boolean` | `yes` ||
|
|
61
|
+
| `ignoreCData` | `boolean` | `yes` ||
|
|
62
|
+
| `addParent` | `boolean` | `yes` ||
|
|
63
|
+
| `trim` | `boolean` | `yes` ||
|
|
64
|
+
|
|
65
|
+
<a name="typedef+js2xmlParseOptions"></a>
|
|
66
|
+
#### `js2xmlParseOptions` - parser options set
|
|
67
|
+
|
|
68
|
+
This options set is an `object` which defines how a 'JS'-object transforms into an 'XML'-string.
|
|
69
|
+
|
|
70
|
+
| option name | value type | optional | description |
|
|
71
|
+
|:---|---|---:|:---|
|
|
72
|
+
| `compact` | `boolean` | `yes` ||
|
|
73
|
+
| `declarationKey` | `string` | `yes` ||
|
|
74
|
+
| `attributesKey` | `string` | `yes` ||
|
|
75
|
+
| `textKey` | `string` | `yes` ||
|
|
76
|
+
| `commentKey` | `string` | `yes` ||
|
|
77
|
+
| `cdataKey` | `string` | `yes` ||
|
|
78
|
+
| `nameKey` | `string` | `yes` ||
|
|
79
|
+
| `typeKey` | `string` | `yes` ||
|
|
80
|
+
| `parentKey` | `string` | `yes` ||
|
|
81
|
+
| `elementsKey` | `string` | `yes` ||
|
|
82
|
+
| `ignoreDeclaration` | `boolean` | `yes` ||
|
|
83
|
+
| `ignoreDocType` | `boolean` | `yes` ||
|
|
84
|
+
| `ignoreInstraction` | `boolean` | `yes` ||
|
|
85
|
+
| `ignoreText` | `boolean` | `yes` ||
|
|
86
|
+
| `ignoreComment` | `boolean` | `yes` ||
|
|
87
|
+
| `ignoreCData` | `boolean` | `yes` ||
|
|
88
|
+
| `fullTagEmptyElement` | `boolean` | `yes` ||
|
|
89
|
+
| `spaces` | `number` | `yes` ||
|
|
90
|
+
|
|
39
91
|
### Base constants
|
|
40
92
|
|
|
41
93
|
|name|type|value|
|
|
@@ -50,28 +102,30 @@ This constant object provided by the module contains a default settings of optio
|
|
|
50
102
|
|
|
51
103
|
The settings listed in the table below:
|
|
52
104
|
|
|
53
|
-
|name|type|value|
|
|
54
|
-
|
|
55
|
-
|compact
|
|
56
|
-
|declarationKey
|
|
57
|
-
|attributesKey
|
|
58
|
-
|textKey
|
|
59
|
-
|commentKey
|
|
60
|
-
|cdataKey
|
|
61
|
-
|nameKey
|
|
62
|
-
|typeKey
|
|
63
|
-
|parentKey
|
|
64
|
-
|elementsKey
|
|
65
|
-
|ignoreDeclaration
|
|
66
|
-
|ignoreDocType
|
|
67
|
-
|ignoreInstractions
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
105
|
+
| name | value type | value | description |
|
|
106
|
+
|:---|---|---:|:---|
|
|
107
|
+
| `compact` | `boolean` | `true` ||
|
|
108
|
+
| `declarationKey` | `string` | `__decl` ||
|
|
109
|
+
| `attributesKey` | `string` | `__attr` ||
|
|
110
|
+
| `textKey` | `string` | `__text` ||
|
|
111
|
+
| `commentKey` | `string` | `__note` ||
|
|
112
|
+
| `cdataKey` | `string` | `__cdata` ||
|
|
113
|
+
| `nameKey` | `string` | `__name` ||
|
|
114
|
+
| `typeKey` | `string` | `__type` ||
|
|
115
|
+
| `parentKey` | `string` | `parent` ||
|
|
116
|
+
| `elementsKey` | `string` | `items` ||
|
|
117
|
+
| `ignoreDeclaration` | `boolean` | `false` ||
|
|
118
|
+
| `ignoreDocType` | `boolean` | `false` ||
|
|
119
|
+
| `ignoreInstractions` | `boolean` | `false` | \<*deprecated*> (*use `ignoreInstraction` instead*) |
|
|
120
|
+
| `ignoreInstraction` | `boolean` | `false` ||
|
|
121
|
+
| `ignoreText` | `boolean` | `false` ||
|
|
122
|
+
| `ignoreComments` | `boolean` | `false` | \<*deprecated*> (*use `ignoreComment` instead*) |
|
|
123
|
+
| `ignoreComment` | `boolean` | `false` ||
|
|
124
|
+
| `ignoreCData` | `boolean` | `false` ||
|
|
125
|
+
| `fullTagEmptyElement` | `boolean` | `true` ||
|
|
126
|
+
| `addParent` | `boolean` | `false` ||
|
|
127
|
+
| `trim` | `boolean` | `true` ||
|
|
128
|
+
| `spaces` | `number` | `2` ||
|
|
75
129
|
|
|
76
130
|
### Base functions for read an object parameter value
|
|
77
131
|
|
|
@@ -1176,14 +1230,14 @@ The class constructor receives an arguments listed below:
|
|
|
1176
1230
|
|
|
1177
1231
|
| property type | read only | description |
|
|
1178
1232
|
|---|---|:---|
|
|
1179
|
-
| `
|
|
1233
|
+
| `xml2jsParseOptions` | yes | returns an options for an XML-to-JS converter |
|
|
1180
1234
|
|
|
1181
1235
|
<a name="TXmlContentParseOptions+js2xml"></a>
|
|
1182
1236
|
###### **js2xml**
|
|
1183
1237
|
|
|
1184
1238
|
| property type | read only | description |
|
|
1185
1239
|
|---|---|:---|
|
|
1186
|
-
| `
|
|
1240
|
+
| `js2xmlParseOptions` | yes | returns an options for a JS-to-XML converter |
|
|
1187
1241
|
|
|
1188
1242
|
<a name="TXmlContentParseOptions+reservedKeys"></a>
|
|
1189
1243
|
###### **reservedKeys**
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare const _exports: {
|
|
2
|
+
readXObjParamRaw: typeof import("./lib/xObj-lib").readXObjParamRaw;
|
|
3
|
+
readXObjParam: typeof import("./lib/xObj-lib").readXObjParam;
|
|
4
|
+
readXObjParamAsBool: typeof import("./lib/xObj-lib").readXObjParamAsBool;
|
|
5
|
+
readXObjParamAsNum: typeof import("./lib/xObj-lib").readXObjParamAsNum;
|
|
6
|
+
readXObjParamEx: typeof import("./lib/xObj-lib").readXObjParamEx;
|
|
7
|
+
readXObjParamAsIndex: typeof import("./lib/xObj-lib").readXObjParamAsIndex;
|
|
8
|
+
writeXObjParamRaw: typeof import("./lib/xObj-lib").writeXObjParamRaw;
|
|
9
|
+
writeXObjParam: typeof import("./lib/xObj-lib").writeXObjParam;
|
|
10
|
+
writeXObjParamAsBool: typeof import("./lib/xObj-lib").writeXObjParamAsBool;
|
|
11
|
+
writeXObjParamAsNum: typeof import("./lib/xObj-lib").writeXObjParamAsNum;
|
|
12
|
+
writeXObjParamAsIndex: typeof import("./lib/xObj-lib").writeXObjParamAsIndex;
|
|
13
|
+
writeXObjParamEx: typeof import("./lib/xObj-lib").writeXObjParamEx;
|
|
14
|
+
readXObjAttrRaw: typeof import("./lib/xObj-lib").readXObjAttrRaw;
|
|
15
|
+
readXObjAttr: typeof import("./lib/xObj-lib").readXObjAttr;
|
|
16
|
+
readXObjAttrAsBool: typeof import("./lib/xObj-lib").readXObjAttrAsBool;
|
|
17
|
+
readXObjAttrAsNum: typeof import("./lib/xObj-lib").readXObjAttrAsNum;
|
|
18
|
+
readXObjAttrEx: typeof import("./lib/xObj-lib").readXObjAttrEx;
|
|
19
|
+
readXObjAttrAsIndex: typeof import("./lib/xObj-lib").readXObjAttrAsIndex;
|
|
20
|
+
writeXObjAttrRaw: typeof import("./lib/xObj-lib").writeXObjAttrRaw;
|
|
21
|
+
writeXObjAttr: typeof import("./lib/xObj-lib").writeXObjAttr;
|
|
22
|
+
writeXObjAttrAsBool: typeof import("./lib/xObj-lib").writeXObjAttrAsBool;
|
|
23
|
+
writeXObjAttrAsNum: typeof import("./lib/xObj-lib").writeXObjAttrAsNum;
|
|
24
|
+
writeXObjAttrAsIndex: typeof import("./lib/xObj-lib").writeXObjAttrAsIndex;
|
|
25
|
+
writeXObjAttrEx: typeof import("./lib/xObj-lib").writeXObjAttrEx;
|
|
26
|
+
getXObjAttributes: typeof import("./lib/xObj-lib").getXObjAttributes;
|
|
27
|
+
checkXObjAttribute: typeof import("./lib/xObj-lib").checkXObjAttribute;
|
|
28
|
+
deleteXObjAttribute: typeof import("./lib/xObj-lib").deleteXObjAttribute;
|
|
29
|
+
renameXObjAttribute: typeof import("./lib/xObj-lib").renameXObjAttribute;
|
|
30
|
+
getXObjElement: typeof import("./lib/xObj-lib").getXObjElement;
|
|
31
|
+
addXObjElement: typeof import("./lib/xObj-lib").addXObjElement;
|
|
32
|
+
insertXObjElement: typeof import("./lib/xObj-lib").insertXObjElement;
|
|
33
|
+
insertXObjElementEx: typeof import("./lib/xObj-lib").insertXObjElementEx;
|
|
34
|
+
deleteXObjElement: typeof import("./lib/xObj-lib").deleteXObjElement;
|
|
35
|
+
deleteXObjElementEx: typeof import("./lib/xObj-lib").deleteXObjElementEx;
|
|
36
|
+
renameXObjElement: typeof import("./lib/xObj-lib").renameXObjElement;
|
|
37
|
+
evalXObjEName: typeof import("./lib/xObj-lib").evalXObjEName;
|
|
38
|
+
insertXObjEList: typeof import("./lib/xObj-lib").insertXObjEList;
|
|
39
|
+
insertXObjEListEx: typeof import("./lib/xObj-lib").insertXObjEListEx;
|
|
40
|
+
evalKeyName: typeof import("./lib/xObj-lib").evalKeyName;
|
|
41
|
+
genXObjENameDescr: typeof import("./lib/xObj-lib").genXObjENameDescr;
|
|
42
|
+
insertXObjElements: typeof import("./lib/xObj-lib").insertXObjElements;
|
|
43
|
+
insertXObjEChain: typeof import("./lib/xObj-lib").insertXObjEChain;
|
|
44
|
+
readonly XOBJ_DEF_PARAM_TNAME: string;
|
|
45
|
+
readonly XOBJ_DEF_ATTR_TNAME: string;
|
|
46
|
+
TXmlContentParseOptions: typeof TXmlContentParseOptions;
|
|
47
|
+
DEF_XML_PARSE_OPTIONS: typeof DEF_XML_PARSE_OPTIONS;
|
|
48
|
+
XOBJ_DEF_TNAMES: typeof XOBJ_DEF_TNAMES;
|
|
49
|
+
};
|
|
50
|
+
export = _exports;
|
|
51
|
+
import { TXmlContentParseOptions } from "./lib/xObj-defs";
|
|
52
|
+
import { DEF_XML_PARSE_OPTIONS } from "./lib/xObj-defs";
|
|
53
|
+
import { XOBJ_DEF_TNAMES } from "./lib/xObj-defs";
|
package/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.013-20251213]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
TXmlContentParseOptions,
|
|
7
7
|
DEF_XML_PARSE_OPTIONS,
|
|
8
|
+
XOBJ_DEF_TNAMES,
|
|
8
9
|
} = require('./lib/xObj-defs');
|
|
9
10
|
|
|
10
|
-
// === module
|
|
11
|
+
// === module inner block ===
|
|
11
12
|
|
|
12
13
|
// === module main block ===
|
|
13
14
|
|
|
@@ -16,3 +17,4 @@ const {
|
|
|
16
17
|
module.exports = require('./lib/xObj-lib');
|
|
17
18
|
module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
|
|
18
19
|
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
20
|
+
module.exports.XOBJ_DEF_TNAMES = XOBJ_DEF_TNAMES;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A parser options settings
|
|
3
|
+
*/
|
|
4
|
+
export type OPT_parserOptions = {
|
|
5
|
+
compact?: boolean | undefined;
|
|
6
|
+
declarationKey?: string | undefined;
|
|
7
|
+
attributesKey?: string | undefined;
|
|
8
|
+
textKey?: string | undefined;
|
|
9
|
+
commentKey?: string | undefined;
|
|
10
|
+
cdataKey?: string | undefined;
|
|
11
|
+
nameKey?: string | undefined;
|
|
12
|
+
typeKey?: string | undefined;
|
|
13
|
+
parentKey?: string | undefined;
|
|
14
|
+
elementsKey?: string | undefined;
|
|
15
|
+
ignoreDeclaration?: boolean | undefined;
|
|
16
|
+
ignoreDocType?: boolean | undefined;
|
|
17
|
+
ignoreInstraction?: boolean | undefined;
|
|
18
|
+
ignoreText?: boolean | undefined;
|
|
19
|
+
ignoreComment?: boolean | undefined;
|
|
20
|
+
ignoreCData?: boolean | undefined;
|
|
21
|
+
fullTagEmptyElement?: boolean | undefined;
|
|
22
|
+
addParent?: boolean | undefined;
|
|
23
|
+
trim?: boolean | undefined;
|
|
24
|
+
spaces?: any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A parser options to convert an 'XML'-string into a 'JS'-object
|
|
28
|
+
*/
|
|
29
|
+
export type xml2jsParseOptions = {
|
|
30
|
+
compact?: boolean | undefined;
|
|
31
|
+
declarationKey?: string | undefined;
|
|
32
|
+
attributesKey?: string | undefined;
|
|
33
|
+
textKey?: string | undefined;
|
|
34
|
+
commentKey?: string | undefined;
|
|
35
|
+
cdataKey?: string | undefined;
|
|
36
|
+
nameKey?: string | undefined;
|
|
37
|
+
typeKey?: string | undefined;
|
|
38
|
+
parentKey?: string | undefined;
|
|
39
|
+
elementsKey?: string | undefined;
|
|
40
|
+
ignoreDeclaration?: boolean | undefined;
|
|
41
|
+
ignoreDocType?: boolean | undefined;
|
|
42
|
+
ignoreInstraction?: boolean | undefined;
|
|
43
|
+
ignoreText?: boolean | undefined;
|
|
44
|
+
ignoreComment?: boolean | undefined;
|
|
45
|
+
ignoreCData?: boolean | undefined;
|
|
46
|
+
addParent?: boolean | undefined;
|
|
47
|
+
trim?: boolean | undefined;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A parser options to convert a 'JS'-object into an 'XML'-string
|
|
51
|
+
*/
|
|
52
|
+
export type js2xmlParseOptions = {
|
|
53
|
+
compact?: boolean | undefined;
|
|
54
|
+
declarationKey?: string | undefined;
|
|
55
|
+
attributesKey?: string | undefined;
|
|
56
|
+
textKey?: string | undefined;
|
|
57
|
+
commentKey?: string | undefined;
|
|
58
|
+
cdataKey?: string | undefined;
|
|
59
|
+
nameKey?: string | undefined;
|
|
60
|
+
typeKey?: string | undefined;
|
|
61
|
+
parentKey?: string | undefined;
|
|
62
|
+
elementsKey?: string | undefined;
|
|
63
|
+
ignoreDeclaration?: boolean | undefined;
|
|
64
|
+
ignoreDocType?: boolean | undefined;
|
|
65
|
+
ignoreInstraction?: boolean | undefined;
|
|
66
|
+
ignoreText?: boolean | undefined;
|
|
67
|
+
ignoreComment?: boolean | undefined;
|
|
68
|
+
ignoreCData?: boolean | undefined;
|
|
69
|
+
fullTagEmptyElement?: boolean | undefined;
|
|
70
|
+
spaces?: any;
|
|
71
|
+
};
|
|
72
|
+
export const XOBJ_DEF_PARAM_TNAME: "__text";
|
|
73
|
+
export const XOBJ_DEF_ATTR_TNAME: "__attr";
|
|
74
|
+
export namespace XOBJ_DEF_TNAMES {
|
|
75
|
+
export { XOBJ_DEF_PARAM_TNAME };
|
|
76
|
+
export { XOBJ_DEF_ATTR_TNAME };
|
|
77
|
+
export { XOBJ_DEF_DECL_TNAME };
|
|
78
|
+
export { XOBJ_DEF_CDATA_TNAME };
|
|
79
|
+
}
|
|
80
|
+
export namespace XOBJ_ECODE_TABLE {
|
|
81
|
+
export { XOBJ_TE_NOBJ_EMSG };
|
|
82
|
+
export { XOBJ_TE_NOBJ_ECODE };
|
|
83
|
+
export { XOBJ_TE_NARR_EMSG };
|
|
84
|
+
export { XOBJ_TE_NARR_ECODE };
|
|
85
|
+
export { XOBJ_TE_NSTR_EMSG };
|
|
86
|
+
export { XOBJ_TE_NSTR_ECODE };
|
|
87
|
+
export { XOBJ_TE_NPOBJ_EMSG };
|
|
88
|
+
export { XOBJ_TE_NPOBJ_ECODE };
|
|
89
|
+
export { XOBJ_TE_ANES_EMSG };
|
|
90
|
+
export { XOBJ_TE_ANES_ECODE };
|
|
91
|
+
export { XOBJ_TE_KNES_EMSG };
|
|
92
|
+
export { XOBJ_TE_KNES_ECODE };
|
|
93
|
+
}
|
|
94
|
+
export namespace DEF_XML_PARSE_OPTIONS {
|
|
95
|
+
export let compact: boolean;
|
|
96
|
+
export { XOBJ_DEF_DECL_TNAME as declarationKey };
|
|
97
|
+
export { XOBJ_DEF_ATTR_TNAME as attributesKey };
|
|
98
|
+
export { XOBJ_DEF_PARAM_TNAME as textKey };
|
|
99
|
+
export let commentKey: string;
|
|
100
|
+
export { XOBJ_DEF_CDATA_TNAME as cdataKey };
|
|
101
|
+
export let nameKey: string;
|
|
102
|
+
export let typeKey: string;
|
|
103
|
+
export let parentKey: string;
|
|
104
|
+
export let elementsKey: string;
|
|
105
|
+
export let ignoreDeclaration: boolean;
|
|
106
|
+
export let ignoreDocType: boolean;
|
|
107
|
+
/** @deprecated */
|
|
108
|
+
export let ignoreInstractions: boolean;
|
|
109
|
+
export let ignoreInstraction: boolean;
|
|
110
|
+
export let ignoreText: boolean;
|
|
111
|
+
/** @deprecated */
|
|
112
|
+
export let ignoreComments: boolean;
|
|
113
|
+
export let ignoreComment: boolean;
|
|
114
|
+
export let ignoreCData: boolean;
|
|
115
|
+
export let fullTagEmptyElement: boolean;
|
|
116
|
+
export let addParent: boolean;
|
|
117
|
+
export let trim: boolean;
|
|
118
|
+
export let spaces: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @classdesc Implements a container that provide a functionality to work
|
|
123
|
+
* with options for an XML-parser
|
|
124
|
+
*/
|
|
125
|
+
export class TXmlContentParseOptions {
|
|
126
|
+
/**
|
|
127
|
+
* Creates a container instance
|
|
128
|
+
*/
|
|
129
|
+
static createNewOptionsSet(opt?: any): OPT_parserOptions;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a container instance
|
|
132
|
+
*/
|
|
133
|
+
constructor(param?: any);
|
|
134
|
+
/**
|
|
135
|
+
* Contains a set of a current settings
|
|
136
|
+
*/
|
|
137
|
+
get settings(): OPT_parserOptions;
|
|
138
|
+
/**
|
|
139
|
+
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
140
|
+
*/
|
|
141
|
+
get xml2js(): xml2jsParseOptions;
|
|
142
|
+
/**
|
|
143
|
+
* Contains a set of a settings for converting an 'JS'-object to 'XML'
|
|
144
|
+
*/
|
|
145
|
+
get js2xml(): js2xmlParseOptions;
|
|
146
|
+
/**
|
|
147
|
+
* Contains a set of a reserved key words
|
|
148
|
+
*/
|
|
149
|
+
get reservedKeys(): Set<string>;
|
|
150
|
+
#private;
|
|
151
|
+
}
|
|
152
|
+
declare const XOBJ_DEF_DECL_TNAME: "__decl";
|
|
153
|
+
declare const XOBJ_DEF_CDATA_TNAME: "__cdata";
|
|
154
|
+
declare const XOBJ_TE_NOBJ_EMSG: "invalid argument (an object expected)";
|
|
155
|
+
declare const XOBJ_TE_NOBJ_ECODE: "ERR_XOBJ_NOBJ";
|
|
156
|
+
declare const XOBJ_TE_NARR_EMSG: "invalid argument (an array expected)";
|
|
157
|
+
declare const XOBJ_TE_NARR_ECODE: "ERR_XOBJ_NARR";
|
|
158
|
+
declare const XOBJ_TE_NSTR_EMSG: "invalid argument (a string expected)";
|
|
159
|
+
declare const XOBJ_TE_NSTR_ECODE: "ERR_XOBJ_NSTR";
|
|
160
|
+
declare const XOBJ_TE_NPOBJ_EMSG: "invalid argument (a plain object expected)";
|
|
161
|
+
declare const XOBJ_TE_NPOBJ_ECODE: "ERR_XOBJ_NPOBJ";
|
|
162
|
+
declare const XOBJ_TE_ANES_EMSG: "<attr_name> must be a non-empty string";
|
|
163
|
+
declare const XOBJ_TE_ANES_ECODE: "ERR_XOBJ_INVARG_ATTR";
|
|
164
|
+
declare const XOBJ_TE_KNES_EMSG: "<key_name> must be a non-empty string";
|
|
165
|
+
declare const XOBJ_TE_KNES_ECODE: "ERR_XOBJ_INVARG_KEY";
|
|
166
|
+
export {};
|
package/lib/xObj-defs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.067-20251214]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
isPlainObject,
|
|
7
7
|
} = require('@ygracs/bsfoc-lib-js');
|
|
8
8
|
|
|
9
|
-
// === module
|
|
9
|
+
// === module inner block ===
|
|
10
10
|
|
|
11
11
|
// === module main block ===
|
|
12
12
|
|
|
@@ -16,6 +16,15 @@ const {
|
|
|
16
16
|
|
|
17
17
|
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
18
18
|
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
19
|
+
const XOBJ_DEF_DECL_TNAME = '__decl';
|
|
20
|
+
const XOBJ_DEF_CDATA_TNAME = '__cdata';
|
|
21
|
+
|
|
22
|
+
const XOBJ_DEF_TNAMES = {
|
|
23
|
+
XOBJ_DEF_PARAM_TNAME,
|
|
24
|
+
XOBJ_DEF_ATTR_TNAME,
|
|
25
|
+
XOBJ_DEF_DECL_TNAME,
|
|
26
|
+
XOBJ_DEF_CDATA_TNAME,
|
|
27
|
+
};
|
|
19
28
|
|
|
20
29
|
const XOBJ_TE_INVARG_EMSG = 'invalid argument';
|
|
21
30
|
const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
|
|
@@ -46,22 +55,52 @@ const XOBJ_ECODE_TABLE = {
|
|
|
46
55
|
XOBJ_TE_KNES_ECODE,
|
|
47
56
|
};
|
|
48
57
|
|
|
58
|
+
/**
|
|
59
|
+
* A parser options settings
|
|
60
|
+
* @typedef {Object} OPT_parserOptions
|
|
61
|
+
* @property {boolean} [compact]
|
|
62
|
+
* @property {string} [declarationKey]
|
|
63
|
+
* @property {string} [attributesKey]
|
|
64
|
+
* @property {string} [textKey]
|
|
65
|
+
* @property {string} [commentKey]
|
|
66
|
+
* @property {string} [cdataKey]
|
|
67
|
+
* @property {string} [nameKey]
|
|
68
|
+
* @property {string} [typeKey]
|
|
69
|
+
* @property {string} [parentKey]
|
|
70
|
+
* @property {string} [elementsKey]
|
|
71
|
+
* @property {boolean} [ignoreDeclaration]
|
|
72
|
+
* @property {boolean} [ignoreDocType]
|
|
73
|
+
* @property {boolean} [ignoreInstraction]
|
|
74
|
+
* @property {boolean} [ignoreText]
|
|
75
|
+
* @property {boolean} [ignoreComment]
|
|
76
|
+
* @property {boolean} [ignoreCData]
|
|
77
|
+
* @property {boolean} [fullTagEmptyElement]
|
|
78
|
+
* @property {boolean} [addParent]
|
|
79
|
+
* @property {boolean} [trim]
|
|
80
|
+
* @property {any} [spaces]
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/** @type {OPT_parserOptions} */
|
|
49
84
|
const DEF_XML_PARSE_OPTIONS = {
|
|
50
85
|
compact: true,
|
|
51
|
-
declarationKey:
|
|
86
|
+
declarationKey: XOBJ_DEF_DECL_TNAME,
|
|
52
87
|
attributesKey: XOBJ_DEF_ATTR_TNAME,
|
|
53
88
|
textKey: XOBJ_DEF_PARAM_TNAME,
|
|
54
89
|
commentKey: '__note',
|
|
55
|
-
cdataKey:
|
|
90
|
+
cdataKey: XOBJ_DEF_CDATA_TNAME,
|
|
56
91
|
nameKey: '__name',
|
|
57
92
|
typeKey: '__type',
|
|
58
93
|
parentKey: 'parent',
|
|
59
94
|
elementsKey: 'items',
|
|
60
95
|
ignoreDeclaration: false,
|
|
61
96
|
ignoreDocType: false,
|
|
97
|
+
/** @deprecated */
|
|
62
98
|
ignoreInstractions: false,
|
|
99
|
+
ignoreInstraction: false,
|
|
63
100
|
ignoreText: false,
|
|
101
|
+
/** @deprecated */
|
|
64
102
|
ignoreComments: false,
|
|
103
|
+
ignoreComment: false,
|
|
65
104
|
ignoreCData: false,
|
|
66
105
|
fullTagEmptyElement: true,
|
|
67
106
|
addParent: false,
|
|
@@ -77,13 +116,59 @@ const DEF_XML_PARSE_OPTIONS = {
|
|
|
77
116
|
* (* class definitions *)
|
|
78
117
|
*/
|
|
79
118
|
|
|
119
|
+
/**
|
|
120
|
+
* A parser options to convert an 'XML'-string into a 'JS'-object
|
|
121
|
+
* @typedef {Object} xml2jsParseOptions
|
|
122
|
+
* @property {boolean} [compact]
|
|
123
|
+
* @property {string} [declarationKey]
|
|
124
|
+
* @property {string} [attributesKey]
|
|
125
|
+
* @property {string} [textKey]
|
|
126
|
+
* @property {string} [commentKey]
|
|
127
|
+
* @property {string} [cdataKey]
|
|
128
|
+
* @property {string} [nameKey]
|
|
129
|
+
* @property {string} [typeKey]
|
|
130
|
+
* @property {string} [parentKey]
|
|
131
|
+
* @property {string} [elementsKey]
|
|
132
|
+
* @property {boolean} [ignoreDeclaration]
|
|
133
|
+
* @property {boolean} [ignoreDocType]
|
|
134
|
+
* @property {boolean} [ignoreInstraction]
|
|
135
|
+
* @property {boolean} [ignoreText]
|
|
136
|
+
* @property {boolean} [ignoreComment]
|
|
137
|
+
* @property {boolean} [ignoreCData]
|
|
138
|
+
* @property {boolean} [addParent]
|
|
139
|
+
* @property {boolean} [trim]
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A parser options to convert a 'JS'-object into an 'XML'-string
|
|
144
|
+
* @typedef {Object} js2xmlParseOptions
|
|
145
|
+
* @property {boolean} [compact]
|
|
146
|
+
* @property {string} [declarationKey]
|
|
147
|
+
* @property {string} [attributesKey]
|
|
148
|
+
* @property {string} [textKey]
|
|
149
|
+
* @property {string} [commentKey]
|
|
150
|
+
* @property {string} [cdataKey]
|
|
151
|
+
* @property {string} [nameKey]
|
|
152
|
+
* @property {string} [typeKey]
|
|
153
|
+
* @property {string} [parentKey]
|
|
154
|
+
* @property {string} [elementsKey]
|
|
155
|
+
* @property {boolean} [ignoreDeclaration]
|
|
156
|
+
* @property {boolean} [ignoreDocType]
|
|
157
|
+
* @property {boolean} [ignoreInstraction]
|
|
158
|
+
* @property {boolean} [ignoreText]
|
|
159
|
+
* @property {boolean} [ignoreComment]
|
|
160
|
+
* @property {boolean} [ignoreCData]
|
|
161
|
+
* @property {boolean} [fullTagEmptyElement]
|
|
162
|
+
* @property {any} [spaces]
|
|
163
|
+
*/
|
|
164
|
+
|
|
80
165
|
/**
|
|
81
166
|
* @classdesc Implements a container that provide a functionality to work
|
|
82
167
|
* with options for an XML-parser
|
|
83
168
|
*/
|
|
84
169
|
class TXmlContentParseOptions {
|
|
85
|
-
/** @type {
|
|
86
|
-
#_options
|
|
170
|
+
/** @type {OPT_parserOptions} */
|
|
171
|
+
#_options;
|
|
87
172
|
|
|
88
173
|
/**
|
|
89
174
|
* Creates a container instance
|
|
@@ -95,7 +180,7 @@ class TXmlContentParseOptions {
|
|
|
95
180
|
|
|
96
181
|
/**
|
|
97
182
|
* Contains a set of a current settings
|
|
98
|
-
* @type {
|
|
183
|
+
* @type {OPT_parserOptions}
|
|
99
184
|
*/
|
|
100
185
|
get settings() {
|
|
101
186
|
return this.#_options;
|
|
@@ -103,7 +188,7 @@ class TXmlContentParseOptions {
|
|
|
103
188
|
|
|
104
189
|
/**
|
|
105
190
|
* Contains a set of a settings for converting an 'XML' to 'JS'-object
|
|
106
|
-
* @type {
|
|
191
|
+
* @type {xml2jsParseOptions}
|
|
107
192
|
*/
|
|
108
193
|
get xml2js() {
|
|
109
194
|
let _settings = this.#_options;
|
|
@@ -120,9 +205,9 @@ class TXmlContentParseOptions {
|
|
|
120
205
|
elementsKey: _settings.elementsKey,
|
|
121
206
|
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
122
207
|
ignoreDocType: _settings.ignoreDocType,
|
|
123
|
-
ignoreInstraction: _settings.
|
|
208
|
+
ignoreInstraction: _settings.ignoreInstraction,
|
|
124
209
|
ignoreText: _settings.ignoreText,
|
|
125
|
-
ignoreComment: _settings.
|
|
210
|
+
ignoreComment: _settings.ignoreComment,
|
|
126
211
|
ignoreCData: _settings.ignoreCData,
|
|
127
212
|
addParent: _settings.addParent,
|
|
128
213
|
trim: _settings.trim,
|
|
@@ -131,7 +216,7 @@ class TXmlContentParseOptions {
|
|
|
131
216
|
|
|
132
217
|
/**
|
|
133
218
|
* Contains a set of a settings for converting an 'JS'-object to 'XML'
|
|
134
|
-
* @type {
|
|
219
|
+
* @type {js2xmlParseOptions}
|
|
135
220
|
*/
|
|
136
221
|
get js2xml() {
|
|
137
222
|
let _settings = this.#_options;
|
|
@@ -148,9 +233,9 @@ class TXmlContentParseOptions {
|
|
|
148
233
|
elementsKey: _settings.elementsKey,
|
|
149
234
|
ignoreDeclaration: _settings.ignoreDeclaration,
|
|
150
235
|
ignoreDocType: _settings.ignoreDocType,
|
|
151
|
-
ignoreInstraction: _settings.
|
|
236
|
+
ignoreInstraction: _settings.ignoreInstraction,
|
|
152
237
|
ignoreText: _settings.ignoreText,
|
|
153
|
-
ignoreComment: _settings.
|
|
238
|
+
ignoreComment: _settings.ignoreComment,
|
|
154
239
|
ignoreCData: _settings.ignoreCData,
|
|
155
240
|
fullTagEmptyElement: _settings.fullTagEmptyElement,
|
|
156
241
|
spaces: _settings.spaces,
|
|
@@ -189,6 +274,7 @@ class TXmlContentParseOptions {
|
|
|
189
274
|
/**
|
|
190
275
|
* Creates a container instance
|
|
191
276
|
* @param {any} [opt] - some initial options set
|
|
277
|
+
* @returns {OPT_parserOptions}
|
|
192
278
|
* @static
|
|
193
279
|
*/
|
|
194
280
|
static createNewOptionsSet(opt) {
|
|
@@ -212,9 +298,9 @@ class TXmlContentParseOptions {
|
|
|
212
298
|
elementsKey: opt.elementsKey,
|
|
213
299
|
ignoreDeclaration: opt.ignoreDeclaration,
|
|
214
300
|
ignoreDocType: opt.ignoreDocType,
|
|
215
|
-
|
|
301
|
+
ignoreInstraction: opt.ignoreInstraction,
|
|
216
302
|
ignoreText: opt.ignoreText,
|
|
217
|
-
|
|
303
|
+
ignoreComment: opt.ignoreComment,
|
|
218
304
|
ignoreCData: opt.ignoreCData,
|
|
219
305
|
fullTagEmptyElement: opt.fullTagEmptyElement,
|
|
220
306
|
addParent: opt.addParent,
|
|
@@ -229,6 +315,7 @@ class TXmlContentParseOptions {
|
|
|
229
315
|
|
|
230
316
|
module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
|
|
231
317
|
module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
|
|
318
|
+
module.exports.XOBJ_DEF_TNAMES = XOBJ_DEF_TNAMES;
|
|
232
319
|
module.exports.XOBJ_ECODE_TABLE = XOBJ_ECODE_TABLE;
|
|
233
320
|
module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
|
|
234
321
|
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A result of a value check ops.
|
|
3
|
+
*/
|
|
4
|
+
export type RVAL_reason = {
|
|
5
|
+
/**
|
|
6
|
+
* - message ID
|
|
7
|
+
*/
|
|
8
|
+
code: string;
|
|
9
|
+
/**
|
|
10
|
+
* - message text
|
|
11
|
+
*/
|
|
12
|
+
msg: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A result of a value check ops.
|
|
16
|
+
*/
|
|
17
|
+
export type VCOR_evalkname = {
|
|
18
|
+
/**
|
|
19
|
+
* - ops flag
|
|
20
|
+
*/
|
|
21
|
+
isSucceed: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* - result value or reson if failed
|
|
24
|
+
*/
|
|
25
|
+
value: (string | RVAL_reason);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A result of an xObj modification ops
|
|
29
|
+
*/
|
|
30
|
+
export type RVAL_emodif = {
|
|
31
|
+
/**
|
|
32
|
+
* - flag that indicates whether an ops is succeed or not
|
|
33
|
+
*/
|
|
34
|
+
isSucceed: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* - some element as a result
|
|
37
|
+
*/
|
|
38
|
+
item: (object | object[]) | null;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* An options for an element insertion ops
|
|
42
|
+
*/
|
|
43
|
+
export type OPT_inselops_L = {
|
|
44
|
+
force?: boolean;
|
|
45
|
+
ripOldies?: boolean;
|
|
46
|
+
acceptIfList?: boolean;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* An options for an element insertion ops
|
|
50
|
+
*/
|
|
51
|
+
export type OPT_inselops_S = {
|
|
52
|
+
force?: boolean;
|
|
53
|
+
ripOldies?: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const XOBJ_DEF_PARAM_TNAME: string;
|
|
57
|
+
export const XOBJ_DEF_ATTR_TNAME: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Extracts a parameter 'AS IS' from a given object.
|
|
61
|
+
* @throws {TypeError} if first param is not an object
|
|
62
|
+
* @throws {TypeError} if third param is not a string
|
|
63
|
+
*/
|
|
64
|
+
export function readXObjParamRaw(obj: object, key?: string): any;
|
|
65
|
+
/**
|
|
66
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
67
|
+
* @throws {TypeError} if first param is not an object
|
|
68
|
+
*/
|
|
69
|
+
export function readXObjParam(obj: object, key?: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Extracts a parameter from a given object and returns it as a boolean.
|
|
72
|
+
* @throws {TypeError} if first param is not an object
|
|
73
|
+
*/
|
|
74
|
+
export function readXObjParamAsBool(obj: object, defValue?: boolean, key?: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Extracts a parameter from a given object and returns it as a number.
|
|
77
|
+
* @throws {TypeError} if first param is not an object
|
|
78
|
+
*/
|
|
79
|
+
export function readXObjParamAsNum(obj: object, defValue?: number, key?: string): number;
|
|
80
|
+
/**
|
|
81
|
+
* Extracts a parameter from a given object and returns it as a string.
|
|
82
|
+
* @throws {TypeError} if first param is not an object
|
|
83
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
84
|
+
*/
|
|
85
|
+
export function readXObjParamEx(obj: object, opt?: object, key?: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* Extracts a parameter from a given object and returns it as 'index' value.
|
|
88
|
+
* @throws {TypeError} if first param is not an object
|
|
89
|
+
*/
|
|
90
|
+
export function readXObjParamAsIndex(obj: object, key?: string): number;
|
|
91
|
+
/**
|
|
92
|
+
* Writes a parameter 'AS IS' into a given object.
|
|
93
|
+
* @throws {TypeError} if first param is not an object
|
|
94
|
+
* @throws {TypeError} if third param is not a string
|
|
95
|
+
*/
|
|
96
|
+
export function writeXObjParamRaw(obj: object, value: any, key?: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Tries to convert a given value to a string and writes it as a parameter
|
|
99
|
+
* into a given object.
|
|
100
|
+
* @throws {TypeError} if first param is not an object
|
|
101
|
+
*/
|
|
102
|
+
export function writeXObjParam(obj: object, value: any, key?: string): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Tries to convert a given value to a boolean and writes it as a parameter
|
|
105
|
+
* into a given object.
|
|
106
|
+
* @throws {TypeError} if first param is not an object
|
|
107
|
+
*/
|
|
108
|
+
export function writeXObjParamAsBool(obj: object, value: any, defValue?: boolean, key?: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Tries to convert a given value to a number and writes it as a parameter
|
|
111
|
+
* into a given object.
|
|
112
|
+
* @throws {TypeError} if first param is not an object
|
|
113
|
+
*/
|
|
114
|
+
export function writeXObjParamAsNum(obj: object, value: any, defValue?: number, key?: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
117
|
+
* as a parameter into a given object.
|
|
118
|
+
* @throws {TypeError} if first param is not an object
|
|
119
|
+
*/
|
|
120
|
+
export function writeXObjParamAsIndex(obj: object, value: any, key?: string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Tries to convert a given value to a string and writes it
|
|
123
|
+
* as a parameter into a given object.
|
|
124
|
+
* @throws {TypeError} if first param is not an object
|
|
125
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
126
|
+
*/
|
|
127
|
+
export function writeXObjParamEx(obj: object, value: any, opt?: object, key?: string): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Extracts an attribute 'AS IS' from a given object.
|
|
130
|
+
* @throws {TypeError} if first param is not an object
|
|
131
|
+
* @throws {TypeError} if third param is not a string
|
|
132
|
+
*/
|
|
133
|
+
export function readXObjAttrRaw(obj: object, attr?: string, key?: string): any;
|
|
134
|
+
/**
|
|
135
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
136
|
+
* @throws {TypeError} if first param is not an object
|
|
137
|
+
*/
|
|
138
|
+
export function readXObjAttr(obj: object, attr: string, key?: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* Extracts an attribute from a given object and returns it as a boolean.
|
|
141
|
+
* @throws {TypeError} if first param is not an object
|
|
142
|
+
*/
|
|
143
|
+
export function readXObjAttrAsBool(obj: object, attr: string, defValue?: boolean, key?: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Extracts an attribute from a given object and returns it as a number.
|
|
146
|
+
* @returns {number}
|
|
147
|
+
* @throws {TypeError} if first param is not an object
|
|
148
|
+
*/
|
|
149
|
+
export function readXObjAttrAsNum(obj: object, attr: string, defValue?: number, key?: string): number;
|
|
150
|
+
/**
|
|
151
|
+
* Extracts an attribute from a given object and returns it as a string.
|
|
152
|
+
* @throws {TypeError} if first param is not an object
|
|
153
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
154
|
+
*/
|
|
155
|
+
export function readXObjAttrEx(obj: object, attr: string, opt?: object, key?: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Extracts an attribute from a given object and returns it as 'index' value.
|
|
158
|
+
* @throws {TypeError} if first param is not an object
|
|
159
|
+
*/
|
|
160
|
+
export function readXObjAttrAsIndex(obj: object, attr: string, key?: string): number;
|
|
161
|
+
/**
|
|
162
|
+
* Writes a parameter into a given object.
|
|
163
|
+
* @throws {TypeError} if first param is not an object
|
|
164
|
+
* @throws {TypeError} if third param is not a string
|
|
165
|
+
*/
|
|
166
|
+
export function writeXObjAttrRaw(obj: object, attr: string, value: any, key?: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
169
|
+
* into a given object.
|
|
170
|
+
* @throws {TypeError} if first param is not an object
|
|
171
|
+
*/
|
|
172
|
+
export function writeXObjAttr(obj: object, attr: string, value: any, key?: string): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Tries to convert a given value to a boolean and writes it as an attribute
|
|
175
|
+
* into a given object.
|
|
176
|
+
* @throws {TypeError} if first param is not an object
|
|
177
|
+
*/
|
|
178
|
+
export function writeXObjAttrAsBool(obj: object, attr: string, value: any, defValue?: boolean, key?: string): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Tries to convert a given value to a number and writes it as an attribute
|
|
181
|
+
* into a given object.
|
|
182
|
+
* @throws {TypeError} if first param is not an object
|
|
183
|
+
*/
|
|
184
|
+
export function writeXObjAttrAsNum(obj: object, attr: string, value: any, defValue?: number, key?: string): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Tries to convert a given value into an 'index' value and writes it
|
|
187
|
+
* as an attribute into a given object.
|
|
188
|
+
* @throws {TypeError} if first param is not an object
|
|
189
|
+
*/
|
|
190
|
+
export function writeXObjAttrAsIndex(obj: object, attr: string, value: any, key?: string): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Tries to convert a given value to a string and writes it as an attribute
|
|
193
|
+
* into a given object.
|
|
194
|
+
* @throws {TypeError} if first param is not an object
|
|
195
|
+
* @todo [since `v0.2.1`] deprecate use of `opt` as `string`
|
|
196
|
+
*/
|
|
197
|
+
export function writeXObjAttrEx(obj: object, attr: string, value: any, opt?: object, key?: string): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Extracts an attributes from a given object by its key.
|
|
200
|
+
* @throws {TypeError} if first param is not an object
|
|
201
|
+
*/
|
|
202
|
+
export function getXObjAttributes(obj: object, key?: string): object | null;
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether an attribute is exists.
|
|
205
|
+
* @throws {TypeError} if first param is not an object
|
|
206
|
+
*/
|
|
207
|
+
export function checkXObjAttribute(obj: object, attr?: string, key?: string): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Deletes an attribute addressed by a given name.
|
|
210
|
+
* @throws {TypeError} if first param is not an object
|
|
211
|
+
*/
|
|
212
|
+
export function deleteXObjAttribute(obj: object, attr?: string, key?: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Renames an attribute addressed by a given name.
|
|
215
|
+
* @since 0.2.0
|
|
216
|
+
* @throws {TypeError} if first param is not an object
|
|
217
|
+
* @throws {TypeError} if second param is not an object
|
|
218
|
+
* @throws {TypeError} if third param is not an object
|
|
219
|
+
*/
|
|
220
|
+
export function renameXObjAttribute(obj: object, attr?: string, value?: string, key?: string): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Extracts an element from a given object by its key.
|
|
223
|
+
* @throws {TypeError} if first param is not an object
|
|
224
|
+
* @throws {TypeError} if second param is empty string or not a string at all
|
|
225
|
+
*/
|
|
226
|
+
export function getXObjElement(obj: object, name: string): any | null;
|
|
227
|
+
/**
|
|
228
|
+
* Adds an element addressed by its key to a given object.
|
|
229
|
+
* @throws {TypeError} if first param is not an object
|
|
230
|
+
* @throws {TypeError} if second param is empty string or not a string at all
|
|
231
|
+
*/
|
|
232
|
+
export function addXObjElement(obj: object, name: string): RVAL_emodif;
|
|
233
|
+
/**
|
|
234
|
+
* Inserts an element addressed by its key into a given object.
|
|
235
|
+
* @throws {TypeError} if first param is not an object
|
|
236
|
+
* @see insertXObjElementEx
|
|
237
|
+
*/
|
|
238
|
+
export function insertXObjElement(...args: [obj: object, name: string, opt?: OPT_inselops_L]): object | null;
|
|
239
|
+
/**
|
|
240
|
+
* Inserts an element addressed by its key into a given object.
|
|
241
|
+
* @since 0.2.0
|
|
242
|
+
* @throws {TypeError} if first param is not an object
|
|
243
|
+
* @throws {TypeError} if second param is empty string or not a string at all
|
|
244
|
+
*/
|
|
245
|
+
export function insertXObjElementEx(obj: object, name: string, opt?: OPT_inselops_L): RVAL_emodif;
|
|
246
|
+
/**
|
|
247
|
+
* Deletes an element addressed by its key from a given object.
|
|
248
|
+
* @throws {TypeError} if first param is not an object
|
|
249
|
+
* @see deleteXObjElementEx
|
|
250
|
+
*/
|
|
251
|
+
export function deleteXObjElement(...args: [obj: object, name: string]): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Deletes an element addressed by its key from a given object.
|
|
254
|
+
* @throws {TypeError} if first param is not an object
|
|
255
|
+
* @throws {TypeError} if second param is empty string or not a string at all
|
|
256
|
+
*/
|
|
257
|
+
export function deleteXObjElementEx(obj: object, name: string): RVAL_emodif;
|
|
258
|
+
/**
|
|
259
|
+
* Renames an element addressed by its key.
|
|
260
|
+
* @throws {TypeError} if first param is not an object
|
|
261
|
+
* @throws {TypeError} if second param is not a string
|
|
262
|
+
* @throws {TypeError} if third param is not a string
|
|
263
|
+
*/
|
|
264
|
+
export function renameXObjElement(obj: object, name?: string, value?: string): boolean;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Tries to convert a value into an ID.
|
|
268
|
+
*/
|
|
269
|
+
export function evalXObjEName(value: any): null | number | string;
|
|
270
|
+
/**
|
|
271
|
+
* Inserts a list elements into a given object.
|
|
272
|
+
* @throws {TypeError} if first param is not an object
|
|
273
|
+
* @see insertXObjEListEx
|
|
274
|
+
*/
|
|
275
|
+
export function insertXObjEList(...args: [obj: object, name: string, opt?: OPT_inselops_S]): object | object[] | null;
|
|
276
|
+
/**
|
|
277
|
+
* Inserts a list elements into a given object.
|
|
278
|
+
* @since 0.2.0
|
|
279
|
+
* @throws {TypeError} if first param is not an object
|
|
280
|
+
* @throws {TypeError} if second param is empty string or not a string at all
|
|
281
|
+
*/
|
|
282
|
+
export function insertXObjEListEx(obj: object, name: string, opt?: OPT_inselops_S): RVAL_emodif;
|
|
283
|
+
/**
|
|
284
|
+
* Tries to convert a value into an ID.
|
|
285
|
+
* @inner
|
|
286
|
+
*/
|
|
287
|
+
export function evalKeyName(value: any, opt?: boolean): VCOR_evalkname;
|
|
288
|
+
/**
|
|
289
|
+
* Tries to convert a value into an element name description.
|
|
290
|
+
*/
|
|
291
|
+
export function genXObjENameDescr(value: any): object;
|
|
292
|
+
/**
|
|
293
|
+
* Inserts an elements into a given object.
|
|
294
|
+
* @throws {TypeError} if first param is not an object
|
|
295
|
+
*/
|
|
296
|
+
export function insertXObjElements(obj: object, ...args: any[]): number;
|
|
297
|
+
/**
|
|
298
|
+
* Inserts a chain of an elements into a given object.
|
|
299
|
+
* @throws {TypeError} if first param is not an object
|
|
300
|
+
*/
|
|
301
|
+
export function insertXObjEChain(obj: object, ...args: any[]): any | null;
|
package/lib/xObj-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.2.
|
|
1
|
+
// [v0.2.106-20251213]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -10,6 +10,11 @@ const {
|
|
|
10
10
|
isArray, isObject, isPlainObject,
|
|
11
11
|
} = require('@ygracs/bsfoc-lib-js');
|
|
12
12
|
|
|
13
|
+
const {
|
|
14
|
+
XOBJ_ECODE_TABLE,
|
|
15
|
+
XOBJ_DEF_TNAMES,
|
|
16
|
+
} = require('./xObj-defs');
|
|
17
|
+
|
|
13
18
|
const {
|
|
14
19
|
XOBJ_TE_NSTR_EMSG,
|
|
15
20
|
XOBJ_TE_NSTR_ECODE,
|
|
@@ -17,9 +22,14 @@ const {
|
|
|
17
22
|
XOBJ_TE_NPOBJ_ECODE,
|
|
18
23
|
XOBJ_TE_KNES_EMSG,
|
|
19
24
|
XOBJ_TE_KNES_ECODE,
|
|
20
|
-
} =
|
|
25
|
+
} = XOBJ_ECODE_TABLE;
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
const {
|
|
28
|
+
XOBJ_DEF_PARAM_TNAME,
|
|
29
|
+
XOBJ_DEF_ATTR_TNAME,
|
|
30
|
+
} = XOBJ_DEF_TNAMES;
|
|
31
|
+
|
|
32
|
+
// === module inner block ===
|
|
23
33
|
|
|
24
34
|
/**
|
|
25
35
|
* A result of a value check ops.
|
|
@@ -75,9 +85,6 @@ function evalKeyName(value, opt = true) {
|
|
|
75
85
|
* (* constant definitions *)
|
|
76
86
|
*/
|
|
77
87
|
|
|
78
|
-
const XOBJ_DEF_PARAM_TNAME = '__text';
|
|
79
|
-
const XOBJ_DEF_ATTR_TNAME = '__attr';
|
|
80
|
-
|
|
81
88
|
/***
|
|
82
89
|
* (* function definitions *)
|
|
83
90
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ygracs/xobj-lib-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5-b",
|
|
4
4
|
"description": "A helper library to work with xml-js module",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,28 +9,34 @@
|
|
|
9
9
|
"url": "git+https://gitlab.com/ygracs/xobj-lib-js.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "./index.js",
|
|
12
|
+
"types": "./index.d.ts",
|
|
12
13
|
"files": [
|
|
13
14
|
"doc/xObj.md",
|
|
14
15
|
"lib/xObj-lib.js",
|
|
15
16
|
"lib/xObj-defs.js",
|
|
17
|
+
"lib/*.d.ts",
|
|
16
18
|
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
17
20
|
"CHANGELOG.md"
|
|
18
21
|
],
|
|
19
22
|
"scripts": {
|
|
20
23
|
"test": "jest",
|
|
21
24
|
"build-doc-md": "jsdoc2md",
|
|
22
|
-
"build-doc-html": "jsdoc"
|
|
25
|
+
"build-doc-html": "jsdoc",
|
|
26
|
+
"gen-dts": "npx -p typescript tsc"
|
|
23
27
|
},
|
|
24
28
|
"imports": {
|
|
25
29
|
"#lib/*": "./lib/*",
|
|
26
30
|
"#test-dir/*": "./__test__/*"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@ygracs/bsfoc-lib-js": "^0.
|
|
33
|
+
"@ygracs/bsfoc-lib-js": "^0.3.1-b"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
36
|
+
"@ygracs/test-helper": "~0.0.1-b",
|
|
37
|
+
"jest": "^30.2.0",
|
|
38
|
+
"jsdoc-to-markdown": "^9.1.3",
|
|
39
|
+
"minimist": "^1.2.8",
|
|
40
|
+
"typescript": "~5.9.3"
|
|
35
41
|
}
|
|
36
42
|
}
|