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

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: INode | 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,18 @@ 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: INode, 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: INode, opt: object, text: string, tagName: string): boolean;
41
+ import { INode } from "@ygracs/xobj-lib-js";
package/lib/xml-base.js CHANGED
@@ -1,13 +1,49 @@
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
+ // * import types definitions *
16
+ INode,
17
+ } = require('@ygracs/xobj-lib-js');
18
+
19
+ const {
20
+ defParseOptionsSettings,
21
+ } = require('./xepg-defs');
22
+
9
23
  // === module inner block ===
10
24
 
25
+ /**
26
+ * @param {?INode} obj - element
27
+ * @param {string} name - child element name
28
+ * @param {object} [parseOptions] - parser options
29
+ * @returns {string}
30
+ * @inner
31
+ */
32
+ function _getXmlChildElementParam(obj, name, parseOptions) {
33
+ const child = obj ? getXObjElement(obj, name) : null;
34
+ if (child) {
35
+ const target = (
36
+ isPlainObject(parseOptions)
37
+ ? parseOptions.textKey
38
+ : defParseOptionsSettings.textKey
39
+ );
40
+ return readXObjParam(child, target);
41
+ } else {
42
+ return '';
43
+ };
44
+ };
45
+ module.exports._getXmlChildElementParam = _getXmlChildElementParam;
46
+
11
47
  // === module main block ===
12
48
 
13
49
  /**
@@ -108,3 +144,67 @@ function valueToElementID(value) {
108
144
  return id;
109
145
  };
110
146
  module.exports.valueToElementID = valueToElementID;
147
+
148
+ /**
149
+ * Returns an object as a string in an XML-format.
150
+ * @since v0.0.24
151
+ * @function serializeXObjToXMLString
152
+ * @param {INode} node - some element
153
+ * @param {object} opt - parser options
154
+ * @param {string} tagName - element tag name
155
+ * @returns {string}
156
+ * @inner
157
+ */
158
+ function serializeXObjToXMLString(node, opt, tagName) {
159
+ let result = '';
160
+ try {
161
+ result = xmlParser.js2xml({ [tagName]: node }, opt);
162
+ } catch (err) {
163
+ //console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
164
+ result = '';
165
+ //throw err;
166
+ };
167
+ return result;
168
+ };
169
+ module.exports.serializeXObjToXMLString = serializeXObjToXMLString;
170
+
171
+ /**
172
+ * Loads an object content from an XML-string.
173
+ * @since v0.0.24
174
+ * @function deserializeXObjFromXMLString
175
+ * @param {INode} node - some element
176
+ * @param {object} opt - parser options
177
+ * @param {string} text - some content
178
+ * @param {string} tagName - element tag name
179
+ * @returns {boolean}
180
+ * @throws {Error}
181
+ * @inner
182
+ * @experimental
183
+ */
184
+ function deserializeXObjFromXMLString(node, opt, text, tagName) {
185
+ let result = false;
186
+ if (typeof text === 'string' && text !== '') {
187
+ try {
188
+ let obj = xmlParser.xml2js(text, opt);
189
+ if (isPlainObject(obj)) {
190
+ obj = obj[tagName];
191
+ if (isPlainObject(obj)) {
192
+ for (let prop in node) {
193
+ // // TODO: catch errors in strict mode
194
+ delete node[prop];
195
+ };
196
+ (Object.entries(obj)).forEach(([key, value]) => {
197
+ node[key] = value;
198
+ });
199
+ result = true;
200
+ };
201
+ };
202
+ } catch (err) {
203
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
204
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
205
+ throw err;
206
+ };
207
+ };
208
+ return result;
209
+ };
210
+ 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.31",
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.4.0",
45
+ "@ygracs/dtf-lib-js": "~0.1.0",
46
+ "@ygracs/xml-js6": "~0.0.10",
47
+ "@ygracs/xobj-lib-js": "~0.4.1"
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.5.1",
50
53
  "jsdoc-to-markdown": "^9.1.3",
51
54
  "minimist": "^1.2.8",
52
55
  "typescript": "~5.9.3"