@ygracs/xobj-lib-js 0.1.2 → 0.2.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/index.js CHANGED
@@ -1,18 +1,18 @@
1
- // [v0.1.012-20240624]
2
-
3
- // === module init block ===
4
-
5
- const {
6
- TXmlContentParseOptions,
7
- DEF_XML_PARSE_OPTIONS,
8
- } = require('./lib/xObj-defs');
9
-
10
- // === module extra block (helper functions) ===
11
-
12
- // === module main block ===
13
-
14
- // === module exports block ===
15
-
16
- module.exports = require('./lib/xObj-lib');
17
- module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
18
- module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
1
+ // [v0.1.012-20240624]
2
+
3
+ // === module init block ===
4
+
5
+ const {
6
+ TXmlContentParseOptions,
7
+ DEF_XML_PARSE_OPTIONS,
8
+ } = require('./lib/xObj-defs');
9
+
10
+ // === module extra block (helper functions) ===
11
+
12
+ // === module main block ===
13
+
14
+ // === module exports block ===
15
+
16
+ module.exports = require('./lib/xObj-lib');
17
+ module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
18
+ module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
package/lib/xObj-defs.js CHANGED
@@ -1,166 +1,166 @@
1
- // [v0.1.060-20240623]
2
-
3
- // === module init block ===
4
-
5
- const {
6
- //valueToIndex,
7
- //readAsString, readAsBoolEx, readAsNumberEx,
8
- //isNullOrUndef,
9
- //isArray, isObject,
10
- isPlainObject, //readAsListS,
11
- } = require('@ygracs/bsfoc-lib-js');
12
-
13
- // === module extra block (helper functions) ===
14
-
15
- // === module main block ===
16
-
17
- /***
18
- * (* constant definitions *)
19
- */
20
-
21
- const XOBJ_DEF_PARAM_TNAME = '__text';
22
- const XOBJ_DEF_ATTR_TNAME = '__attr';
23
-
24
- const XOBJ_TE_INVARG_EMSG = 'invalid argument';
25
- const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
26
- const XOBJ_TE_NOBJ_ECODE = 'ERR_XOBJ_NOBJ';
27
- const XOBJ_TE_NARR_EMSG = `${XOBJ_TE_INVARG_EMSG} (an array expected)`;
28
- const XOBJ_TE_NARR_ECODE = 'ERR_XOBJ_NARR';
29
- const XOBJ_TE_NSTR_EMSG = `${XOBJ_TE_INVARG_EMSG} (a string expected)`;
30
- const XOBJ_TE_NSTR_ECODE = 'ERR_XOBJ_NSTR';
31
- const XOBJ_TE_NPOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (a plain object expected)`;
32
- const XOBJ_TE_NPOBJ_ECODE = 'ERR_XOBJ_NPOBJ';
33
- const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
34
- const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
35
- const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
36
- const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
37
-
38
- const DEF_XML_PARSE_OPTIONS = {
39
- compact: true,
40
- declarationKey: '__decl',
41
- attributesKey: XOBJ_DEF_ATTR_TNAME,
42
- textKey: XOBJ_DEF_PARAM_TNAME,
43
- commentKey: '__note',
44
- cdataKey: '__cdata',
45
- nameKey: '__name',
46
- typeKey: '__type',
47
- parentKey: 'parent',
48
- elementsKey: 'items',
49
- ignoreDeclaration: false,
50
- ignoreDocType: false,
51
- ignoreInstractions: false,
52
- ignoreText: false,
53
- ignoreComments: false,
54
- ignoreCData: false,
55
- fullTagEmptyElement: true,
56
- addParent: false,
57
- trim: true,
58
- spaces: 2,
59
- };
60
-
61
- /***
62
- * (* function definitions *)
63
- */
64
-
65
- /***
66
- * (* class definitions *)
67
- */
68
-
69
- class TXmlContentParseOptions {
70
- #_options = null;
71
-
72
- constructor(param){
73
- this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
74
- }
75
-
76
- get settings(){ return this.#_options }
77
-
78
- get xml2js(){
79
- let _settings = this.#_options;
80
- return {
81
- compact: _settings.compact,
82
- declarationKey: _settings.declarationKey,
83
- attributesKey: _settings.attributesKey,
84
- textKey: _settings.textKey,
85
- commentKey: _settings.commentKey,
86
- cdataKey: _settings.cdataKey,
87
- nameKey: _settings.nameKey,
88
- typeKey: _settings.typeKey,
89
- parentKey: _settings.parentKey,
90
- elementsKey: _settings.elementsKey,
91
- ignoreDeclaration: _settings.ignoreDeclaration,
92
- ignoreDocType: _settings.ignoreDocType,
93
- ignoreInstraction: _settings.ignoreInstractions,
94
- ignoreText: _settings.ignoreText,
95
- ignoreComment: _settings.ignoreComments,
96
- ignoreCData: _settings.ignoreCData,
97
- addParent: _settings.addParent,
98
- trim: _settings.trim,
99
- };
100
- }
101
-
102
- get js2xml(){
103
- let _settings = this.#_options;
104
- return {
105
- compact: _settings.compact,
106
- declarationKey: _settings.declarationKey,
107
- attributesKey: _settings.attributesKey,
108
- textKey: _settings.textKey,
109
- commentKey: _settings.commentKey,
110
- cdataKey: _settings.cdataKey,
111
- nameKey: _settings.nameKey,
112
- typeKey: _settings.typeKey,
113
- parentKey: _settings.parentKey,
114
- elementsKey: _settings.elementsKey,
115
- ignoreDeclaration: _settings.ignoreDeclaration,
116
- ignoreDocType: _settings.ignoreDocType,
117
- ignoreInstraction: _settings.ignoreInstractions,
118
- ignoreText: _settings.ignoreText,
119
- ignoreComment: _settings.ignoreComments,
120
- ignoreCData: _settings.ignoreCData,
121
- fullTagEmptyElement: _settings.fullTagEmptyElement,
122
- spaces: _settings.spaces,
123
- };
124
- }
125
-
126
- static createNewOptionsSet(opt){
127
- if (opt instanceof TXmlContentParseOptions) {
128
- opt = opt.settings;
129
- } else if (isPlainObject(opt)) {
130
- opt = isPlainObject(opt.settings) ? opt.settings : opt;
131
- } else {
132
- opt = DEF_XML_PARSE_OPTIONS;
133
- };
134
- return {
135
- compact: opt.compact,
136
- declarationKey: opt.declarationKey,
137
- attributesKey: opt.attributesKey,
138
- textKey: opt.textKey,
139
- commentKey: opt.commentKey,
140
- cdataKey: opt.cdataKey,
141
- nameKey: opt.nameKey,
142
- typeKey: opt.typeKey,
143
- parentKey: opt.parentKey,
144
- elementsKey: opt.elementsKey,
145
- ignoreDeclaration: opt.ignoreDeclaration,
146
- ignoreDocType: opt.ignoreDocType,
147
- ignoreInstractions: opt.ignoreInstractions,
148
- ignoreText: opt.ignoreText,
149
- ignoreComments: opt.ignoreComments,
150
- ignoreCData: opt.ignoreCData,
151
- fullTagEmptyElement: opt.fullTagEmptyElement,
152
- addParent: opt.addParent,
153
- trim: opt.trim,
154
- spaces: opt.spaces,
155
- };
156
- }
157
-
158
- }
159
-
160
- // === module exports block ===
161
-
162
- module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
163
- module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
164
- module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
165
-
166
- module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
1
+ // [v0.1.060-20240623]
2
+
3
+ // === module init block ===
4
+
5
+ const {
6
+ //valueToIndex,
7
+ //readAsString, readAsBoolEx, readAsNumberEx,
8
+ //isNullOrUndef,
9
+ //isArray, isObject,
10
+ isPlainObject, //readAsListS,
11
+ } = require('@ygracs/bsfoc-lib-js');
12
+
13
+ // === module extra block (helper functions) ===
14
+
15
+ // === module main block ===
16
+
17
+ /***
18
+ * (* constant definitions *)
19
+ */
20
+
21
+ const XOBJ_DEF_PARAM_TNAME = '__text';
22
+ const XOBJ_DEF_ATTR_TNAME = '__attr';
23
+
24
+ const XOBJ_TE_INVARG_EMSG = 'invalid argument';
25
+ const XOBJ_TE_NOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (an object expected)`;
26
+ const XOBJ_TE_NOBJ_ECODE = 'ERR_XOBJ_NOBJ';
27
+ const XOBJ_TE_NARR_EMSG = `${XOBJ_TE_INVARG_EMSG} (an array expected)`;
28
+ const XOBJ_TE_NARR_ECODE = 'ERR_XOBJ_NARR';
29
+ const XOBJ_TE_NSTR_EMSG = `${XOBJ_TE_INVARG_EMSG} (a string expected)`;
30
+ const XOBJ_TE_NSTR_ECODE = 'ERR_XOBJ_NSTR';
31
+ const XOBJ_TE_NPOBJ_EMSG = `${XOBJ_TE_INVARG_EMSG} (a plain object expected)`;
32
+ const XOBJ_TE_NPOBJ_ECODE = 'ERR_XOBJ_NPOBJ';
33
+ const XOBJ_TE_ANES_EMSG = '<attr_name> must be a non-empty string';
34
+ const XOBJ_TE_ANES_ECODE = 'ERR_XOBJ_INVARG_ATTR';
35
+ const XOBJ_TE_KNES_EMSG = '<key_name> must be a non-empty string';
36
+ const XOBJ_TE_KNES_ECODE = 'ERR_XOBJ_INVARG_KEY';
37
+
38
+ const DEF_XML_PARSE_OPTIONS = {
39
+ compact: true,
40
+ declarationKey: '__decl',
41
+ attributesKey: XOBJ_DEF_ATTR_TNAME,
42
+ textKey: XOBJ_DEF_PARAM_TNAME,
43
+ commentKey: '__note',
44
+ cdataKey: '__cdata',
45
+ nameKey: '__name',
46
+ typeKey: '__type',
47
+ parentKey: 'parent',
48
+ elementsKey: 'items',
49
+ ignoreDeclaration: false,
50
+ ignoreDocType: false,
51
+ ignoreInstractions: false,
52
+ ignoreText: false,
53
+ ignoreComments: false,
54
+ ignoreCData: false,
55
+ fullTagEmptyElement: true,
56
+ addParent: false,
57
+ trim: true,
58
+ spaces: 2,
59
+ };
60
+
61
+ /***
62
+ * (* function definitions *)
63
+ */
64
+
65
+ /***
66
+ * (* class definitions *)
67
+ */
68
+
69
+ class TXmlContentParseOptions {
70
+ #_options = null;
71
+
72
+ constructor(param){
73
+ this.#_options = TXmlContentParseOptions.createNewOptionsSet(param);
74
+ }
75
+
76
+ get settings(){ return this.#_options }
77
+
78
+ get xml2js(){
79
+ let _settings = this.#_options;
80
+ return {
81
+ compact: _settings.compact,
82
+ declarationKey: _settings.declarationKey,
83
+ attributesKey: _settings.attributesKey,
84
+ textKey: _settings.textKey,
85
+ commentKey: _settings.commentKey,
86
+ cdataKey: _settings.cdataKey,
87
+ nameKey: _settings.nameKey,
88
+ typeKey: _settings.typeKey,
89
+ parentKey: _settings.parentKey,
90
+ elementsKey: _settings.elementsKey,
91
+ ignoreDeclaration: _settings.ignoreDeclaration,
92
+ ignoreDocType: _settings.ignoreDocType,
93
+ ignoreInstraction: _settings.ignoreInstractions,
94
+ ignoreText: _settings.ignoreText,
95
+ ignoreComment: _settings.ignoreComments,
96
+ ignoreCData: _settings.ignoreCData,
97
+ addParent: _settings.addParent,
98
+ trim: _settings.trim,
99
+ };
100
+ }
101
+
102
+ get js2xml(){
103
+ let _settings = this.#_options;
104
+ return {
105
+ compact: _settings.compact,
106
+ declarationKey: _settings.declarationKey,
107
+ attributesKey: _settings.attributesKey,
108
+ textKey: _settings.textKey,
109
+ commentKey: _settings.commentKey,
110
+ cdataKey: _settings.cdataKey,
111
+ nameKey: _settings.nameKey,
112
+ typeKey: _settings.typeKey,
113
+ parentKey: _settings.parentKey,
114
+ elementsKey: _settings.elementsKey,
115
+ ignoreDeclaration: _settings.ignoreDeclaration,
116
+ ignoreDocType: _settings.ignoreDocType,
117
+ ignoreInstraction: _settings.ignoreInstractions,
118
+ ignoreText: _settings.ignoreText,
119
+ ignoreComment: _settings.ignoreComments,
120
+ ignoreCData: _settings.ignoreCData,
121
+ fullTagEmptyElement: _settings.fullTagEmptyElement,
122
+ spaces: _settings.spaces,
123
+ };
124
+ }
125
+
126
+ static createNewOptionsSet(opt){
127
+ if (opt instanceof TXmlContentParseOptions) {
128
+ opt = opt.settings;
129
+ } else if (isPlainObject(opt)) {
130
+ opt = isPlainObject(opt.settings) ? opt.settings : opt;
131
+ } else {
132
+ opt = DEF_XML_PARSE_OPTIONS;
133
+ };
134
+ return {
135
+ compact: opt.compact,
136
+ declarationKey: opt.declarationKey,
137
+ attributesKey: opt.attributesKey,
138
+ textKey: opt.textKey,
139
+ commentKey: opt.commentKey,
140
+ cdataKey: opt.cdataKey,
141
+ nameKey: opt.nameKey,
142
+ typeKey: opt.typeKey,
143
+ parentKey: opt.parentKey,
144
+ elementsKey: opt.elementsKey,
145
+ ignoreDeclaration: opt.ignoreDeclaration,
146
+ ignoreDocType: opt.ignoreDocType,
147
+ ignoreInstractions: opt.ignoreInstractions,
148
+ ignoreText: opt.ignoreText,
149
+ ignoreComments: opt.ignoreComments,
150
+ ignoreCData: opt.ignoreCData,
151
+ fullTagEmptyElement: opt.fullTagEmptyElement,
152
+ addParent: opt.addParent,
153
+ trim: opt.trim,
154
+ spaces: opt.spaces,
155
+ };
156
+ }
157
+
158
+ }
159
+
160
+ // === module exports block ===
161
+
162
+ module.exports.XOBJ_DEF_PARAM_TNAME = XOBJ_DEF_PARAM_TNAME;
163
+ module.exports.XOBJ_DEF_ATTR_TNAME = XOBJ_DEF_ATTR_TNAME;
164
+ module.exports.DEF_XML_PARSE_OPTIONS = DEF_XML_PARSE_OPTIONS;
165
+
166
+ module.exports.TXmlContentParseOptions = TXmlContentParseOptions;