@ygracs/xepg-lib-js 0.0.27-b → 0.0.30

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/lib/xml-base.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ *
3
+ * @inner
4
+ */
5
+ export function _getXmlChildElementParam(obj: object | null, name: string, parseOptions?: object): string;
1
6
  /**
2
7
  * Tries to convert a given value to a valid tag name of an XML-element.
3
8
  * @since v0.0.23
@@ -19,3 +24,17 @@ export function readAsAttrValue(value: any): string | null;
19
24
  * @since v0.0.23
20
25
  */
21
26
  export function valueToElementID(value: any): string;
27
+ /**
28
+ * Returns an object as a string in an XML-format.
29
+ * @since v0.0.24
30
+ * @inner
31
+ */
32
+ export function serializeXObjToXMLString(node: object, opt: object, tagName: string): string;
33
+ /**
34
+ * Loads an object content from an XML-string.
35
+ * @since v0.0.24
36
+ * @throws {Error}
37
+ * @inner
38
+ * @experimental
39
+ */
40
+ export function deserializeXObjFromXMLString(node: object, opt: object, text: string, tagName: string): boolean;
package/lib/xml-base.js CHANGED
@@ -1,13 +1,47 @@
1
- // [v0.1.003-20260305]
1
+ // [v0.1.005-20260531]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
+ isPlainObject,
6
7
  valueToIDString,
7
8
  } = require('@ygracs/bsfoc-lib-js');
8
9
 
10
+ const xmlParser = require('@ygracs/xml-js6');
11
+
12
+ const {
13
+ getXObjElement,
14
+ readXObjParam,
15
+ } = require('@ygracs/xobj-lib-js');
16
+
17
+ const {
18
+ defParseOptionsSettings,
19
+ } = require('./xepg-defs');
20
+
9
21
  // === module inner block ===
10
22
 
23
+ /**
24
+ * @param {?object} obj - element
25
+ * @param {string} name - child element name
26
+ * @param {object} [parseOptions] - parser options
27
+ * @returns {string}
28
+ * @inner
29
+ */
30
+ function _getXmlChildElementParam(obj, name, parseOptions) {
31
+ const child = obj ? getXObjElement(obj, name) : null;
32
+ if (child) {
33
+ const target = (
34
+ isPlainObject(parseOptions)
35
+ ? parseOptions.textKey
36
+ : defParseOptionsSettings.textKey
37
+ );
38
+ return readXObjParam(child, target);
39
+ } else {
40
+ return '';
41
+ };
42
+ };
43
+ module.exports._getXmlChildElementParam = _getXmlChildElementParam;
44
+
11
45
  // === module main block ===
12
46
 
13
47
  /**
@@ -108,3 +142,67 @@ function valueToElementID(value) {
108
142
  return id;
109
143
  };
110
144
  module.exports.valueToElementID = valueToElementID;
145
+
146
+ /**
147
+ * Returns an object as a string in an XML-format.
148
+ * @since v0.0.24
149
+ * @function serializeXObjToXMLString
150
+ * @param {object} node - some element
151
+ * @param {object} opt - parser options
152
+ * @param {string} tagName - element tag name
153
+ * @returns {string}
154
+ * @inner
155
+ */
156
+ function serializeXObjToXMLString(node, opt, tagName) {
157
+ let result = '';
158
+ try {
159
+ result = xmlParser.js2xml({ [tagName]: node }, opt);
160
+ } catch (err) {
161
+ //console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
162
+ result = '';
163
+ //throw err;
164
+ };
165
+ return result;
166
+ };
167
+ module.exports.serializeXObjToXMLString = serializeXObjToXMLString;
168
+
169
+ /**
170
+ * Loads an object content from an XML-string.
171
+ * @since v0.0.24
172
+ * @function deserializeXObjFromXMLString
173
+ * @param {object} node - some element
174
+ * @param {object} opt - parser options
175
+ * @param {string} text - some content
176
+ * @param {string} tagName - element tag name
177
+ * @returns {boolean}
178
+ * @throws {Error}
179
+ * @inner
180
+ * @experimental
181
+ */
182
+ function deserializeXObjFromXMLString(node, opt, text, tagName) {
183
+ let result = false;
184
+ if (typeof text === 'string' && text !== '') {
185
+ try {
186
+ let obj = xmlParser.xml2js(text, opt);
187
+ if (isPlainObject(obj)) {
188
+ obj = obj[tagName];
189
+ if (isPlainObject(obj)) {
190
+ for (let prop in node) {
191
+ // // TODO: catch errors in strict mode
192
+ delete node[prop];
193
+ };
194
+ (Object.entries(obj)).forEach(([key, value]) => {
195
+ node[key] = value;
196
+ });
197
+ result = true;
198
+ };
199
+ };
200
+ } catch (err) {
201
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
202
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
203
+ throw err;
204
+ };
205
+ };
206
+ return result;
207
+ };
208
+ module.exports.deserializeXObjFromXMLString = deserializeXObjFromXMLString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygracs/xepg-lib-js",
3
- "version": "0.0.27-b",
3
+ "version": "0.0.30",
4
4
  "description": "A library for handling an EPG-sources based on an XEPG-format",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -19,6 +19,9 @@
19
19
  "doc/*.xepg",
20
20
  "doc/*.md",
21
21
  "lib/xepgdoc-lib.js",
22
+ "lib/xepg-defs.js",
23
+ "lib/xepg-sched.js",
24
+ "lib/xepg-channel.js",
22
25
  "lib/dts-helper.js",
23
26
  "lib/xml-base.js",
24
27
  "lib/*.d.ts",
@@ -37,16 +40,16 @@
37
40
  "#test-dir/*": "./__test__/*"
38
41
  },
39
42
  "dependencies": {
40
- "@cntwg/file-helper": "^0.0.3",
41
- "@ygracs/bsfoc-lib-js": "~0.3.3",
42
- "@ygracs/dtf-lib-js": "^0.0.33",
43
- "@ygracs/xml-js6": "^0.0.8-b",
44
- "@ygracs/xobj-lib-js": "~0.3.0"
43
+ "@cntwg/file-helper": "~0.0.4",
44
+ "@ygracs/bsfoc-lib-js": "~0.3.4",
45
+ "@ygracs/dtf-lib-js": "~0.1.0-beta.2",
46
+ "@ygracs/xml-js6": "~0.0.9-b",
47
+ "@ygracs/xobj-lib-js": "~0.3.3"
45
48
  },
46
49
  "devDependencies": {
47
50
  "@ygracs/test-helper": "~0.0.2-b",
48
51
  "cross-env": "^10.1.0",
49
- "jest": "^30.2.0",
52
+ "jest": "^30.4.2",
50
53
  "jsdoc-to-markdown": "^9.1.3",
51
54
  "minimist": "^1.2.8",
52
55
  "typescript": "~5.9.3"