@ygracs/xepg-lib-js 0.0.26-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,21 +1,40 @@
1
- /**
2
- * Tries to convert a given value to a valid tag name of an XML-element.
3
- * @since v0.0.23
4
- */
5
- export function readAsTagName(value: any): string;
6
- /**
7
- * Tries to convert a given value to a valid name of an XML-attribute.
8
- * @since v0.0.23
9
- */
10
- export function readAsAttrName(value: any): string;
11
- /**
12
- * Tries to convert a given value to a valid "attribute value".
13
- * @since v0.0.25
14
- */
15
- export function readAsAttrValue(value: any): string | null;
16
- /**
17
- * Tries to convert a given value to a valid identifier suitable as a value
18
- * for an "ID-attribute" of an XML-element.
19
- * @since v0.0.23
20
- */
21
- export function valueToElementID(value: any): string;
1
+ /**
2
+ *
3
+ * @inner
4
+ */
5
+ export function _getXmlChildElementParam(obj: object | null, name: string, parseOptions?: object): string;
6
+ /**
7
+ * Tries to convert a given value to a valid tag name of an XML-element.
8
+ * @since v0.0.23
9
+ */
10
+ export function readAsTagName(value: any): string;
11
+ /**
12
+ * Tries to convert a given value to a valid name of an XML-attribute.
13
+ * @since v0.0.23
14
+ */
15
+ export function readAsAttrName(value: any): string;
16
+ /**
17
+ * Tries to convert a given value to a valid "attribute value".
18
+ * @since v0.0.25
19
+ */
20
+ export function readAsAttrValue(value: any): string | null;
21
+ /**
22
+ * Tries to convert a given value to a valid identifier suitable as a value
23
+ * for an "ID-attribute" of an XML-element.
24
+ * @since v0.0.23
25
+ */
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,30 +1,48 @@
1
- // [v0.1.002-20250825]
1
+ // [v0.1.005-20260531]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- //valueToIndex,
6
+ isPlainObject,
7
7
  valueToIDString,
8
- //readAsString, readAsNumber,
9
- //isNotEmptyString,
10
- //isArray, isObject, isPlainObject,
11
8
  } = require('@ygracs/bsfoc-lib-js');
12
9
 
13
- // === module inner block ===
10
+ const xmlParser = require('@ygracs/xml-js6');
14
11
 
15
- /***
16
- * (* helper function definitions *)
17
- */
12
+ const {
13
+ getXObjElement,
14
+ readXObjParam,
15
+ } = require('@ygracs/xobj-lib-js');
18
16
 
19
- // === module main block ===
17
+ const {
18
+ defParseOptionsSettings,
19
+ } = require('./xepg-defs');
20
20
 
21
- /***
22
- * (* constant definitions *)
23
- */
21
+ // === module inner block ===
24
22
 
25
- /***
26
- * (* function definitions *)
23
+ /**
24
+ * @param {?object} obj - element
25
+ * @param {string} name - child element name
26
+ * @param {object} [parseOptions] - parser options
27
+ * @returns {string}
28
+ * @inner
27
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
+
45
+ // === module main block ===
28
46
 
29
47
  /**
30
48
  * Tries to convert a given value to a valid tag name of an XML-element.
@@ -47,6 +65,7 @@ function readAsTagName(value) {
47
65
  };
48
66
  return tagName;
49
67
  };
68
+ module.exports.readAsTagName = readAsTagName;
50
69
 
51
70
  /**
52
71
  * Tries to convert a given value to a valid name of an XML-attribute.
@@ -69,6 +88,7 @@ function readAsAttrName(value) {
69
88
  };
70
89
  return attrName;
71
90
  };
91
+ module.exports.readAsAttrName = readAsAttrName;
72
92
 
73
93
  /**
74
94
  * Tries to convert a given value to a valid "attribute value".
@@ -97,6 +117,7 @@ function readAsAttrValue(value) {
97
117
  };
98
118
  return result;
99
119
  };
120
+ module.exports.readAsAttrValue = readAsAttrValue;
100
121
 
101
122
  /**
102
123
  * Tries to convert a given value to a valid identifier suitable as a value
@@ -120,14 +141,68 @@ function valueToElementID(value) {
120
141
  };
121
142
  return id;
122
143
  };
144
+ module.exports.valueToElementID = valueToElementID;
123
145
 
124
- /***
125
- * (* class definitions *)
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
126
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;
127
168
 
128
- // === module exports block ===
129
-
130
- module.exports.readAsTagName = readAsTagName;
131
- module.exports.readAsAttrName = readAsAttrName;
132
- module.exports.readAsAttrValue = readAsAttrValue;
133
- module.exports.valueToElementID = valueToElementID;
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.26-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.6-b",
44
- "@ygracs/xobj-lib-js": "^0.2.8-b"
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
- "@ygracs/test-helper": "~0.0.1-b",
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"
File without changes