@ygracs/xepg-lib-js 0.0.22 → 0.0.24
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 +39 -0
- package/README.md +9 -3
- package/doc/xepgdoc-lib.md +154 -22
- package/index.js +6 -5
- package/lib/dts-helper.js +7 -7
- package/lib/xepgdoc-lib.js +592 -308
- package/package.json +9 -10
- package/lib/file-helper.js +0 -278
package/lib/xepgdoc-lib.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// [v0.2.
|
|
1
|
+
// [v0.2.124-20250730]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const xmlParser = require('@ygracs/xml-js6');
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
|
-
valueToIndex,
|
|
9
|
-
readAsString,
|
|
8
|
+
valueToIndex, valueToIDString,
|
|
9
|
+
readAsString, readAsNumber,
|
|
10
10
|
isNotEmptyString,
|
|
11
11
|
isArray, isObject, isPlainObject,
|
|
12
12
|
} = require('@ygracs/bsfoc-lib-js');
|
|
@@ -22,19 +22,21 @@ const {
|
|
|
22
22
|
} = require('./dts-helper.js');
|
|
23
23
|
|
|
24
24
|
const {
|
|
25
|
-
|
|
25
|
+
loadFromFileSync, loadFromFile,
|
|
26
26
|
saveToFileSync, saveToFile,
|
|
27
|
-
} = require('
|
|
27
|
+
} = require('@cntwg/file-helper');
|
|
28
28
|
|
|
29
29
|
const xObj = require('@ygracs/xobj-lib-js');
|
|
30
30
|
|
|
31
|
-
const TXmlContentParseOptions = xObj.TXmlContentParseOptions;
|
|
32
31
|
const {
|
|
32
|
+
TXmlContentParseOptions,
|
|
33
33
|
getXObjElement,
|
|
34
34
|
insertXObjElement,
|
|
35
|
+
writeXObjParam,
|
|
36
|
+
writeXObjAttr,
|
|
35
37
|
} = xObj;
|
|
36
38
|
|
|
37
|
-
// === module
|
|
39
|
+
// === module inner block ===
|
|
38
40
|
|
|
39
41
|
/*
|
|
40
42
|
* === xObj-function wrappers (start) ===
|
|
@@ -44,33 +46,27 @@ function readXObjParam(obj){
|
|
|
44
46
|
return xObj.readXObjParam(obj, defParseOptions.settings.textKey);
|
|
45
47
|
};
|
|
46
48
|
|
|
47
|
-
function writeXObjParam(obj, value){
|
|
48
|
-
return xObj.writeXObjParam(obj, value, defParseOptions.settings.textKey);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function writeXObjAttr(obj, name, value) {
|
|
52
|
-
return xObj.writeXObjAttr(
|
|
53
|
-
obj, name, value, defParseOptions.settings.attributesKey
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
49
|
/*
|
|
58
50
|
* === xObj-function wrappers (end) ===
|
|
59
51
|
*/
|
|
60
52
|
|
|
53
|
+
/***
|
|
54
|
+
* (* helper function definitions *)
|
|
55
|
+
*/
|
|
56
|
+
|
|
61
57
|
/**
|
|
62
|
-
* @param {object} obj
|
|
63
|
-
* @param {string}
|
|
58
|
+
* @param {object} obj - element
|
|
59
|
+
* @param {string} name - child element name
|
|
64
60
|
* @returns {string}
|
|
65
61
|
* @inner
|
|
66
62
|
*/
|
|
67
|
-
function _getXmlChildElementParam(obj,
|
|
68
|
-
const child = obj ? getXObjElement(obj,
|
|
63
|
+
function _getXmlChildElementParam(obj, name) {
|
|
64
|
+
const child = obj ? getXObjElement(obj, name) : null;
|
|
69
65
|
return child ? readXObjParam(child) : '';
|
|
70
66
|
};
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
|
-
* @param {object} obj
|
|
69
|
+
* @param {object} obj - element
|
|
74
70
|
* @returns {number}
|
|
75
71
|
* @inner
|
|
76
72
|
*/
|
|
@@ -81,19 +77,114 @@ function _getDTSTypeValueForXObj(obj) {
|
|
|
81
77
|
return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
|
|
82
78
|
};
|
|
83
79
|
|
|
84
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @param {object} obj - element
|
|
82
|
+
* @param {*} data - data
|
|
83
|
+
* @returns {void}
|
|
84
|
+
* @inner
|
|
85
|
+
*/
|
|
86
|
+
function writeXEpgDocDeclSection(obj, data) {
|
|
87
|
+
const key_name = defParseOptions.settings.declarationKey;
|
|
85
88
|
let xml_ver = XEPG_XML_DOC_VERSION;
|
|
86
89
|
let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
doc_def_enc = readAsString(opt.encoding, { defValue: doc_def_enc });
|
|
90
|
+
if (isPlainObject(data)) {
|
|
91
|
+
xml_ver = readAsString(data.version, { defValue: xml_ver });
|
|
92
|
+
doc_def_enc = readAsString(data.encoding, { defValue: doc_def_enc });
|
|
91
93
|
};
|
|
92
94
|
if (isPlainObject(obj) && isNotEmptyString(key_name)) {
|
|
93
95
|
obj[key_name] = {};
|
|
94
|
-
|
|
95
|
-
writeXObjAttr(obj[key_name], '
|
|
96
|
+
const attr_key = defParseOptions.settings.attributesKey;
|
|
97
|
+
writeXObjAttr(obj[key_name], 'version', xml_ver, attr_key);
|
|
98
|
+
writeXObjAttr(obj[key_name], 'encoding', doc_def_enc, attr_key);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns an object as a string in an XML-format.
|
|
104
|
+
* @since v0.0.24
|
|
105
|
+
* @function serializeXObjToXMLString
|
|
106
|
+
* @param {object} node - some element
|
|
107
|
+
* @param {object} opt - parser options
|
|
108
|
+
* @param {string} tagName - element tag name
|
|
109
|
+
* @returns {string}
|
|
110
|
+
* @inner
|
|
111
|
+
*/
|
|
112
|
+
function serializeXObjToXMLString(node, opt, tagName) {
|
|
113
|
+
let result = '';
|
|
114
|
+
try {
|
|
115
|
+
result = xmlParser.js2xml({ [tagName]: node }, opt);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
//console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
|
|
118
|
+
result = '';
|
|
119
|
+
//throw err;
|
|
120
|
+
};
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Loads an object content from an XML-string.
|
|
126
|
+
* @since v0.0.24
|
|
127
|
+
* @function deserializeXObjFromXMLString
|
|
128
|
+
* @param {object} node - some element
|
|
129
|
+
* @param {object} opt - parser options
|
|
130
|
+
* @param {string} text - some content
|
|
131
|
+
* @param {string} tagName - element tag name
|
|
132
|
+
* @returns {boolean}
|
|
133
|
+
* @throws {Error}
|
|
134
|
+
* @inner
|
|
135
|
+
* @experimental
|
|
136
|
+
*/
|
|
137
|
+
function deserializeXObjFromXMLString(node, opt, text, tagName) {
|
|
138
|
+
let result = false;
|
|
139
|
+
if (typeof text === 'string' && text !== '') {
|
|
140
|
+
try {
|
|
141
|
+
let obj = xmlParser.xml2js(text, opt);
|
|
142
|
+
if (isPlainObject(obj)) {
|
|
143
|
+
obj = obj[tagName];
|
|
144
|
+
if (isPlainObject(obj)) {
|
|
145
|
+
for (let prop in node) {
|
|
146
|
+
// // TODO: catch errors in strict mode
|
|
147
|
+
delete node[prop];
|
|
148
|
+
};
|
|
149
|
+
(Object.entries(obj)).forEach(([key, value]) => {
|
|
150
|
+
node[key] = value;
|
|
151
|
+
});
|
|
152
|
+
result = true;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
} catch (err) {
|
|
156
|
+
//console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
|
|
157
|
+
//console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
|
|
158
|
+
throw err;
|
|
159
|
+
};
|
|
96
160
|
};
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* An XEPG-element options set (base)
|
|
166
|
+
* @typedef {Object} OPT_epgelsett_bs
|
|
167
|
+
* @property {TXmlContentParseOptions} [parseOptions] - parser options
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Evaluates an XML-node base settings
|
|
172
|
+
* @function __evalXMLBaseNodeSettings
|
|
173
|
+
* @param {any} value - element settings to evaluate
|
|
174
|
+
* @returns {OPT_epgelsett_bs}
|
|
175
|
+
* @inner
|
|
176
|
+
*/
|
|
177
|
+
function __evalXMLBaseNodeSettings(value) {
|
|
178
|
+
/** @type {OPT_epgelsett_bs} */
|
|
179
|
+
let settings = isPlainObject(value) ? value : {};
|
|
180
|
+
if (settings instanceof Map) settings = Object.fromEntries(settings);
|
|
181
|
+
let {
|
|
182
|
+
parseOptions,
|
|
183
|
+
} = settings;
|
|
184
|
+
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
185
|
+
settings.parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
186
|
+
};
|
|
187
|
+
return settings;
|
|
97
188
|
};
|
|
98
189
|
|
|
99
190
|
// === module main block ===
|
|
@@ -161,56 +252,141 @@ const defParseOptions = new TXmlContentParseOptions();
|
|
|
161
252
|
* (* function definitions *)
|
|
162
253
|
*/
|
|
163
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Tries to convert a given value to a valid tag name of an XML-element.
|
|
257
|
+
* @since v0.0.23
|
|
258
|
+
* @function readAsTagName
|
|
259
|
+
* @param {any} value - some value
|
|
260
|
+
* @returns {string}
|
|
261
|
+
*/
|
|
262
|
+
function readAsTagName(value) {
|
|
263
|
+
let tagName = valueToIDString(value, { ignoreNumbers: true });
|
|
264
|
+
if (tagName === null) return '';
|
|
265
|
+
if (tagName !== '') {
|
|
266
|
+
// // TODO: do extra checks
|
|
267
|
+
const template = /[\s\/\\\"\'<>=]/;
|
|
268
|
+
const trigger = tagName.match(template);
|
|
269
|
+
if (trigger) {
|
|
270
|
+
//console.log(trigger);
|
|
271
|
+
tagName = '';
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
return tagName;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Tries to convert a given value to a valid name of an XML-attribute.
|
|
279
|
+
* @since v0.0.23
|
|
280
|
+
* @function readAsAttrName
|
|
281
|
+
* @param {any} value - some value
|
|
282
|
+
* @returns {string}
|
|
283
|
+
*/
|
|
284
|
+
function readAsAttrName(value) {
|
|
285
|
+
let attrName = valueToIDString(value, { ignoreNumbers: true });
|
|
286
|
+
if (attrName === null) return '';
|
|
287
|
+
if (attrName !== '') {
|
|
288
|
+
// // TODO: do extra checks
|
|
289
|
+
const template = /[\s\/\\\"\'<>=]/;
|
|
290
|
+
const trigger = attrName.match(template);
|
|
291
|
+
if (trigger) {
|
|
292
|
+
//console.log(trigger);
|
|
293
|
+
attrName = '';
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
return attrName;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Tries to convert a given value to a valid identifier suitable as a value
|
|
301
|
+
* for an "ID-attribute" of an XML-element.
|
|
302
|
+
* @since v0.0.23
|
|
303
|
+
* @function valueToElementID
|
|
304
|
+
* @param {any} value - some value
|
|
305
|
+
* @returns {string}
|
|
306
|
+
*/
|
|
307
|
+
function valueToElementID(value) {
|
|
308
|
+
let id = valueToIDString(value);
|
|
309
|
+
if (id === null) return '';
|
|
310
|
+
if (id !== '') {
|
|
311
|
+
// // TODO: do extra checks
|
|
312
|
+
const template = /[\s\/\\\"\'<>=]/;
|
|
313
|
+
const trigger = id.match(template);
|
|
314
|
+
if (trigger) {
|
|
315
|
+
//console.log(trigger);
|
|
316
|
+
id = '';
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
return id;
|
|
320
|
+
};
|
|
321
|
+
|
|
164
322
|
/***
|
|
165
323
|
* (* class definitions *)
|
|
166
324
|
*/
|
|
167
325
|
|
|
168
326
|
/**
|
|
327
|
+
* A schedule info descriptor
|
|
169
328
|
* @typedef {Object} xepgShedInfoDesc
|
|
170
329
|
* @property {number} time - a schedule start time
|
|
171
330
|
* @property {string} title - schedule title
|
|
172
331
|
* @property {string} [cat] - schedule category
|
|
173
332
|
* @property {number} [pcmark] - schedule rating
|
|
174
333
|
* @property {string} [descr] - schedule description
|
|
175
|
-
* @description A schedule info descriptor
|
|
176
334
|
*/
|
|
177
335
|
|
|
178
336
|
/**
|
|
337
|
+
* An extra options set
|
|
338
|
+
* @typedef {Object} OPT_extra
|
|
339
|
+
* @property {object} [dts_src] - 'DTS'-settings
|
|
340
|
+
* @property {object} [tz_src] - 'TZ'-settings
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* An XEPG-element options set (extend)
|
|
345
|
+
* @typedef {Object} OPT_epgelsett_ex
|
|
346
|
+
* @property {TXmlContentParseOptions} [parseOptions] - parser options
|
|
347
|
+
* @property {object} [dts_src]
|
|
348
|
+
* @property {object} [tz_src]
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* @since 0.0.22
|
|
179
353
|
* @classdesc This class implements an interface of a EPG-schedule element
|
|
180
354
|
*/
|
|
181
355
|
class TXEpgScheduleItem {
|
|
182
|
-
/** @
|
|
183
|
-
#_host
|
|
184
|
-
/** @
|
|
185
|
-
#_options
|
|
186
|
-
/** @
|
|
187
|
-
#_parseOptions
|
|
188
|
-
/** @
|
|
356
|
+
/** @type {object} */
|
|
357
|
+
#_host;
|
|
358
|
+
/** @type {OPT_epgelsett_ex} */
|
|
359
|
+
#_options;
|
|
360
|
+
/** @type {TXmlContentParseOptions} */
|
|
361
|
+
#_parseOptions;
|
|
362
|
+
/** @type {?object} */
|
|
189
363
|
#_dts_src = null;
|
|
190
|
-
/** @
|
|
364
|
+
/** @type {?object} */
|
|
191
365
|
#_tz_src = null;
|
|
192
366
|
|
|
193
367
|
/**
|
|
368
|
+
* Creates an instance of the EPG-schedule element
|
|
194
369
|
* @param {object} obj - host object
|
|
195
|
-
* @param {
|
|
196
|
-
* @param {
|
|
197
|
-
* @param {?object} [opt.dts_src]
|
|
198
|
-
* @param {?object} [opt.tz_src]
|
|
199
|
-
* @description Creates an instance of the EPG-schedule element
|
|
370
|
+
* @param {OPT_epgelsett_ex} [opt] - options
|
|
371
|
+
* @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
|
|
200
372
|
*/
|
|
201
|
-
constructor(obj, opt) {
|
|
373
|
+
constructor(obj, opt, extra) {
|
|
202
374
|
// load content
|
|
203
375
|
const _host = isPlainObject(obj) ? obj : {};
|
|
204
376
|
// load options
|
|
377
|
+
/** @type {OPT_epgelsett_ex} */
|
|
205
378
|
const _options = isPlainObject(opt) ? opt : {};
|
|
206
379
|
let {
|
|
207
380
|
parseOptions,
|
|
208
|
-
dts_src, tz_src,
|
|
209
381
|
} = _options;
|
|
210
382
|
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
211
383
|
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
212
384
|
_options.parseOptions = parseOptions;
|
|
213
385
|
};
|
|
386
|
+
let {
|
|
387
|
+
dts_src = _options.dts_src,
|
|
388
|
+
tz_src = _options.tz_src,
|
|
389
|
+
} = isPlainObject(extra) ? extra : {};
|
|
214
390
|
if (!isPlainObject(dts_src)) dts_src = null;
|
|
215
391
|
if (!isPlainObject(tz_src)) tz_src = null;
|
|
216
392
|
// save content source
|
|
@@ -226,7 +402,7 @@ class TXEpgScheduleItem {
|
|
|
226
402
|
|
|
227
403
|
/**
|
|
228
404
|
* Contains a dtstype ID
|
|
229
|
-
* @
|
|
405
|
+
* @type {number}
|
|
230
406
|
* @readonly
|
|
231
407
|
*/
|
|
232
408
|
get dtstype() {
|
|
@@ -235,7 +411,7 @@ class TXEpgScheduleItem {
|
|
|
235
411
|
|
|
236
412
|
/**
|
|
237
413
|
* Contains a TZ-offset
|
|
238
|
-
* @
|
|
414
|
+
* @type {number}
|
|
239
415
|
* @readonly
|
|
240
416
|
*/
|
|
241
417
|
get curDocTZ() {
|
|
@@ -248,7 +424,7 @@ class TXEpgScheduleItem {
|
|
|
248
424
|
|
|
249
425
|
/**
|
|
250
426
|
* Contains a schedule start time as a timestamp
|
|
251
|
-
* @
|
|
427
|
+
* @type {number}
|
|
252
428
|
* @readonly
|
|
253
429
|
*/
|
|
254
430
|
get time() {
|
|
@@ -260,7 +436,7 @@ class TXEpgScheduleItem {
|
|
|
260
436
|
|
|
261
437
|
/**
|
|
262
438
|
* Contains a schedule title
|
|
263
|
-
* @
|
|
439
|
+
* @type {string}
|
|
264
440
|
* @readonly
|
|
265
441
|
*/
|
|
266
442
|
get title() {
|
|
@@ -269,7 +445,7 @@ class TXEpgScheduleItem {
|
|
|
269
445
|
|
|
270
446
|
/**
|
|
271
447
|
* Contains a schedule category
|
|
272
|
-
* @
|
|
448
|
+
* @type {string}
|
|
273
449
|
* @readonly
|
|
274
450
|
*/
|
|
275
451
|
get category() {
|
|
@@ -278,18 +454,18 @@ class TXEpgScheduleItem {
|
|
|
278
454
|
|
|
279
455
|
/**
|
|
280
456
|
* Contains a schedule rating value (aka pcmark)
|
|
281
|
-
* @
|
|
457
|
+
* @type {number}
|
|
282
458
|
* @readonly
|
|
283
459
|
*/
|
|
284
460
|
get rating() {
|
|
285
|
-
return
|
|
461
|
+
return readAsNumber(
|
|
286
462
|
_getXmlChildElementParam(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME), 0
|
|
287
463
|
);
|
|
288
464
|
}
|
|
289
465
|
|
|
290
466
|
/**
|
|
291
467
|
* Contains a schedule description
|
|
292
|
-
* @
|
|
468
|
+
* @type {string}
|
|
293
469
|
* @readonly
|
|
294
470
|
*/
|
|
295
471
|
get descr() {
|
|
@@ -297,8 +473,8 @@ class TXEpgScheduleItem {
|
|
|
297
473
|
}
|
|
298
474
|
|
|
299
475
|
/**
|
|
476
|
+
* Returns a schedule info item descriptor
|
|
300
477
|
* @returns {xepgShedInfoDesc}
|
|
301
|
-
* @description Returns a schedule info item descriptor
|
|
302
478
|
*/
|
|
303
479
|
getInfo() {
|
|
304
480
|
const {
|
|
@@ -318,9 +494,9 @@ class TXEpgScheduleItem {
|
|
|
318
494
|
}
|
|
319
495
|
|
|
320
496
|
/**
|
|
497
|
+
* Sets a schedule start time.
|
|
321
498
|
* @param {(number|string|Date)} value - some time value
|
|
322
499
|
* @returns {boolean}
|
|
323
|
-
* @description Sets a schedule start time.
|
|
324
500
|
*/
|
|
325
501
|
setTime(value) {
|
|
326
502
|
let { isSucceed, value: dtValue } = tryDTValue(value);
|
|
@@ -330,46 +506,52 @@ class TXEpgScheduleItem {
|
|
|
330
506
|
if (dtValue !== '') {
|
|
331
507
|
const opt = { force: true };
|
|
332
508
|
const item = insertXObjElement(this.#_host, XEPG_SCHEDTIME_ETAG_NAME, opt);
|
|
333
|
-
if (item)
|
|
509
|
+
if (item) {
|
|
510
|
+
result = writeXObjParam(item, dtValue, defParseOptions.settings.textKey);
|
|
511
|
+
};
|
|
334
512
|
};
|
|
335
513
|
};
|
|
336
514
|
return result;
|
|
337
515
|
}
|
|
338
516
|
|
|
339
517
|
/**
|
|
518
|
+
* Sets a schedule title.
|
|
340
519
|
* @param {string} value - some title
|
|
341
520
|
* @returns {boolean}
|
|
342
|
-
* @description Sets a schedule title.
|
|
343
521
|
*/
|
|
344
522
|
setTitle(value) {
|
|
345
523
|
let result = false;
|
|
346
524
|
if (typeof value === 'string') {
|
|
347
525
|
const opt = { force: true };
|
|
348
526
|
const item = insertXObjElement(this.#_host, XEPG_SCHEDTITL_ETAG_NAME, opt);
|
|
349
|
-
if (item)
|
|
527
|
+
if (item) {
|
|
528
|
+
result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
529
|
+
};
|
|
350
530
|
};
|
|
351
531
|
return result;
|
|
352
532
|
}
|
|
353
533
|
|
|
354
534
|
/**
|
|
535
|
+
* Sets a schedule title.
|
|
355
536
|
* @param {string} value - some title
|
|
356
537
|
* @returns {boolean}
|
|
357
|
-
* @description Sets a schedule title.
|
|
358
538
|
*/
|
|
359
539
|
setCategory(value) {
|
|
360
540
|
let result = false;
|
|
361
541
|
if (typeof value === 'string') {
|
|
362
542
|
const opt = { force: true };
|
|
363
543
|
const item = insertXObjElement(this.#_host, XEPG_SCHEDCAT_ETAG_NAME, opt);
|
|
364
|
-
if (item)
|
|
544
|
+
if (item) {
|
|
545
|
+
result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
546
|
+
};
|
|
365
547
|
};
|
|
366
548
|
return result;
|
|
367
549
|
}
|
|
368
550
|
|
|
369
551
|
/**
|
|
552
|
+
* Sets a schedule rating value.
|
|
370
553
|
* @param {(number|string)} value - some value
|
|
371
554
|
* @returns {boolean}
|
|
372
|
-
* @description Sets a schedule rating value.
|
|
373
555
|
*/
|
|
374
556
|
setRating(value) {
|
|
375
557
|
const _value = valueToIndex(value);
|
|
@@ -377,44 +559,63 @@ class TXEpgScheduleItem {
|
|
|
377
559
|
if (_value !== -1) {
|
|
378
560
|
const opt = { force: true };
|
|
379
561
|
const item = insertXObjElement(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME, opt);
|
|
380
|
-
if (item)
|
|
562
|
+
if (item) {
|
|
563
|
+
result = writeXObjParam(item, _value, defParseOptions.settings.textKey);
|
|
564
|
+
};
|
|
381
565
|
};
|
|
382
566
|
return result;
|
|
383
567
|
}
|
|
384
568
|
|
|
385
569
|
/**
|
|
570
|
+
* Sets a schedule description.
|
|
386
571
|
* @param {string} value - some text
|
|
387
572
|
* @returns {boolean}
|
|
388
|
-
* @description Sets a schedule description.
|
|
389
573
|
*/
|
|
390
574
|
setDescr(value) {
|
|
391
575
|
let result = false;
|
|
392
576
|
if (typeof value === 'string') {
|
|
393
577
|
const opt = { force: true };
|
|
394
578
|
const item = insertXObjElement(this.#_host, XEPG_SCHEDDESC_ETAG_NAME, opt);
|
|
395
|
-
if (item)
|
|
579
|
+
if (item) {
|
|
580
|
+
result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
581
|
+
};
|
|
396
582
|
};
|
|
397
583
|
return result;
|
|
398
584
|
}
|
|
399
585
|
|
|
400
586
|
/**
|
|
587
|
+
* Returns an instance content as a string in an XML-format.
|
|
401
588
|
* @returns {string}
|
|
402
|
-
* @description Returns an instance content as a string in an XML-format.
|
|
403
589
|
*/
|
|
404
590
|
saveToXMLString() {
|
|
405
591
|
const options = this.#_parseOptions.js2xml;
|
|
406
592
|
options.ignoreDocType = true;
|
|
407
593
|
options.ignoreDeclaration = true;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
594
|
+
return serializeXObjToXMLString(
|
|
595
|
+
this.#_host,
|
|
596
|
+
options,
|
|
597
|
+
XEPG_SCHED_ETAG_NAME,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Loads an element content from a string.
|
|
603
|
+
* @since v0.0.24
|
|
604
|
+
* @param {string} xmlString - some content
|
|
605
|
+
* @returns {boolean}
|
|
606
|
+
* @throws {Error}
|
|
607
|
+
* @experimental
|
|
608
|
+
*/
|
|
609
|
+
loadFromXMLString(xmlString) {
|
|
610
|
+
const options = this.#_parseOptions.xml2js;
|
|
611
|
+
options.ignoreDocType = true;
|
|
612
|
+
options.ignoreDeclaration = true;
|
|
613
|
+
return deserializeXObjFromXMLString(
|
|
614
|
+
this.#_host,
|
|
615
|
+
options,
|
|
616
|
+
xmlString,
|
|
617
|
+
XEPG_SCHED_ETAG_NAME,
|
|
618
|
+
);
|
|
418
619
|
}
|
|
419
620
|
|
|
420
621
|
};
|
|
@@ -423,26 +624,29 @@ class TXEpgScheduleItem {
|
|
|
423
624
|
* @classdesc This class implements an interface of a EPG-schedules list
|
|
424
625
|
*/
|
|
425
626
|
class TXEpgSchedulesList {
|
|
426
|
-
/** @
|
|
427
|
-
#_content
|
|
428
|
-
/** @
|
|
429
|
-
#_options
|
|
430
|
-
/** @
|
|
627
|
+
/** @type {object[]} */
|
|
628
|
+
#_content;
|
|
629
|
+
/** @type {OPT_epgelsett_ex} */
|
|
630
|
+
#_options;
|
|
631
|
+
/** @type {?object} */
|
|
431
632
|
#_dts_src = null;
|
|
432
|
-
/** @
|
|
633
|
+
/** @type {?object} */
|
|
433
634
|
#_tz_src = null;
|
|
434
635
|
|
|
435
636
|
/**
|
|
637
|
+
* Creates an instance of the schedules list
|
|
436
638
|
* @param {any[]} obj - list of an elements
|
|
437
|
-
* @param {
|
|
438
|
-
* @param {
|
|
439
|
-
* @param {?object} [opt.tz_src]
|
|
440
|
-
* @description Creates an instance of the schedules list
|
|
639
|
+
* @param {OPT_epgelsett_ex} [opt] - options
|
|
640
|
+
* @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
|
|
441
641
|
*/
|
|
442
|
-
constructor(obj, opt) {
|
|
642
|
+
constructor(obj, opt, extra) {
|
|
443
643
|
const _content = isArray(obj) ? obj : [];
|
|
644
|
+
/** @type {OPT_epgelsett_ex} */
|
|
444
645
|
const _options = isPlainObject(opt) ? opt : {};
|
|
445
|
-
let {
|
|
646
|
+
let {
|
|
647
|
+
dts_src = _options.dts_src,
|
|
648
|
+
tz_src = _options.tz_src,
|
|
649
|
+
} = isPlainObject(extra) ? extra : {};
|
|
446
650
|
if (!isPlainObject(dts_src)) dts_src = null;
|
|
447
651
|
if (!isPlainObject(tz_src)) tz_src = null;
|
|
448
652
|
// save content source
|
|
@@ -454,11 +658,27 @@ class TXEpgSchedulesList {
|
|
|
454
658
|
this.#_tz_src = tz_src;
|
|
455
659
|
}
|
|
456
660
|
|
|
661
|
+
[Symbol.iterator]() {
|
|
662
|
+
let index = 0;
|
|
663
|
+
return {
|
|
664
|
+
next: () => {
|
|
665
|
+
if (index < this.count) {
|
|
666
|
+
return { done: false, value: this.schedule(index++) };
|
|
667
|
+
} else {
|
|
668
|
+
return { done: true, value: undefined };
|
|
669
|
+
};
|
|
670
|
+
},
|
|
671
|
+
return() {
|
|
672
|
+
return { done: true, value: undefined };
|
|
673
|
+
},
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
457
677
|
/**
|
|
678
|
+
* Returns a raw schedule element
|
|
458
679
|
* @param {(number|string)} value - element index
|
|
459
680
|
* @returns {any}
|
|
460
681
|
* @private
|
|
461
|
-
* @description Returns a raw schedule element
|
|
462
682
|
*/
|
|
463
683
|
#_getItem = function(value) {
|
|
464
684
|
if (this.chkIndex(value)) {
|
|
@@ -468,16 +688,28 @@ class TXEpgSchedulesList {
|
|
|
468
688
|
|
|
469
689
|
/**
|
|
470
690
|
* Contains a quantity of a schedules
|
|
471
|
-
* @
|
|
691
|
+
* @type {number}
|
|
472
692
|
* @readonly
|
|
693
|
+
* @deprecated
|
|
694
|
+
* @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.count`
|
|
473
695
|
*/
|
|
474
696
|
get schedQty() {
|
|
475
697
|
return this.#_content.length;
|
|
476
698
|
}
|
|
477
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Contains a quantity of a schedules
|
|
702
|
+
* @since v0.0.24
|
|
703
|
+
* @type {number}
|
|
704
|
+
* @readonly
|
|
705
|
+
*/
|
|
706
|
+
get count() {
|
|
707
|
+
return this.#_content.length;
|
|
708
|
+
}
|
|
709
|
+
|
|
478
710
|
/**
|
|
479
711
|
* Contains a dtstype ID
|
|
480
|
-
* @
|
|
712
|
+
* @type {number}
|
|
481
713
|
* @readonly
|
|
482
714
|
*/
|
|
483
715
|
get dtstype() {
|
|
@@ -486,7 +718,7 @@ class TXEpgSchedulesList {
|
|
|
486
718
|
|
|
487
719
|
/**
|
|
488
720
|
* Contains a TZ-offset
|
|
489
|
-
* @
|
|
721
|
+
* @type {number}
|
|
490
722
|
* @readonly
|
|
491
723
|
*/
|
|
492
724
|
get curDocTZ() {
|
|
@@ -498,51 +730,60 @@ class TXEpgSchedulesList {
|
|
|
498
730
|
}
|
|
499
731
|
|
|
500
732
|
/**
|
|
733
|
+
* Indicates whether an instance has none member
|
|
501
734
|
* @returns {boolean}
|
|
502
|
-
* @
|
|
735
|
+
* @deprecated
|
|
736
|
+
* @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isEmpty`
|
|
503
737
|
*/
|
|
504
738
|
hasNoSchedules() {
|
|
505
|
-
return this.
|
|
739
|
+
return this.count === 0;
|
|
506
740
|
}
|
|
507
741
|
|
|
508
742
|
/**
|
|
743
|
+
* Indicates whether an instance has none member
|
|
744
|
+
* @since v0.0.24
|
|
509
745
|
* @returns {boolean}
|
|
510
|
-
* @description Indicates whether an instance has any member
|
|
511
746
|
*/
|
|
512
|
-
|
|
513
|
-
return this.
|
|
747
|
+
isEmpty() {
|
|
748
|
+
return this.count === 0;
|
|
514
749
|
}
|
|
515
750
|
|
|
516
751
|
/**
|
|
517
|
-
*
|
|
752
|
+
* Indicates whether an instance has any member
|
|
518
753
|
* @returns {boolean}
|
|
519
754
|
* @deprecated
|
|
520
|
-
* @
|
|
521
|
-
* and it fits the index range of an instance
|
|
522
|
-
* @done [since v0.0.20] deprecated
|
|
523
|
-
* @todo [from v0.0.23] will be removed
|
|
755
|
+
* @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isNotEmpty`
|
|
524
756
|
*/
|
|
525
|
-
|
|
526
|
-
return this.
|
|
757
|
+
hasSchedules() {
|
|
758
|
+
return this.count > 0;
|
|
527
759
|
}
|
|
528
760
|
|
|
529
761
|
/**
|
|
530
|
-
*
|
|
762
|
+
* Indicates whether an instance has any member
|
|
763
|
+
* @since v0.0.24
|
|
531
764
|
* @returns {boolean}
|
|
765
|
+
*/
|
|
766
|
+
isNotEmpty() {
|
|
767
|
+
return this.count > 0;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Checks whether a given value is a valid index and it fits the index range
|
|
772
|
+
* of an instance
|
|
532
773
|
* @since 0.0.20
|
|
533
|
-
* @
|
|
534
|
-
*
|
|
774
|
+
* @param {(number|string)} value - index of some element
|
|
775
|
+
* @returns {boolean}
|
|
535
776
|
*/
|
|
536
777
|
chkIndex(value) {
|
|
537
778
|
const index = valueToIndex(value);
|
|
538
|
-
return index !== -1 && index < this.
|
|
779
|
+
return index !== -1 && index < this.count;
|
|
539
780
|
}
|
|
540
781
|
|
|
541
782
|
/**
|
|
783
|
+
* Returns a schedule element addressed by a given index
|
|
784
|
+
* @since 0.0.22
|
|
542
785
|
* @param {(number|string)} index - index of some element
|
|
543
786
|
* @returns {?TXEpgScheduleItem}
|
|
544
|
-
* @since 0.0.22
|
|
545
|
-
* @description Returns a schedule element addressed by a given index
|
|
546
787
|
*/
|
|
547
788
|
schedule(index) {
|
|
548
789
|
const curObj = this.#_getItem(index);
|
|
@@ -557,10 +798,10 @@ class TXEpgSchedulesList {
|
|
|
557
798
|
}
|
|
558
799
|
|
|
559
800
|
/**
|
|
801
|
+
* Returns a schedule info item for instance element addressed
|
|
802
|
+
* by a given index
|
|
560
803
|
* @param {(number|string)} index - index of some element
|
|
561
804
|
* @returns {?xepgShedInfoDesc}
|
|
562
|
-
* @description Returns a schedule info item for instance element
|
|
563
|
-
* addressed by a given index
|
|
564
805
|
*/
|
|
565
806
|
getScheduleInfo(index) {
|
|
566
807
|
const obj = this.schedule(index);
|
|
@@ -568,12 +809,12 @@ class TXEpgSchedulesList {
|
|
|
568
809
|
}
|
|
569
810
|
|
|
570
811
|
/**
|
|
812
|
+
* Returns a schedule info for instance members
|
|
571
813
|
* @returns {xepgShedInfoDesc[]}
|
|
572
|
-
* @description Returns a schedule info for instance members
|
|
573
814
|
*/
|
|
574
815
|
getAllSchedulesInfo() {
|
|
575
816
|
let result = [];
|
|
576
|
-
for (let i = 0; i < this.
|
|
817
|
+
for (let i = 0; i < this.count; i++) {
|
|
577
818
|
let item = this.getScheduleInfo(i);
|
|
578
819
|
if (isPlainObject(item)) result.push(item);
|
|
579
820
|
};
|
|
@@ -590,44 +831,38 @@ class TXEpgSchedulesList {
|
|
|
590
831
|
};
|
|
591
832
|
|
|
592
833
|
/**
|
|
834
|
+
* A provider info descriptor
|
|
593
835
|
* @typedef {Object} xepgProvInfoDesc
|
|
594
836
|
* @property {string} [name] - provider name
|
|
595
837
|
* @property {string} [version] - provider version
|
|
596
838
|
* @property {string} schema - document schema
|
|
597
839
|
* @property {string} doctype - document type
|
|
598
|
-
* @description A provider info descriptor
|
|
599
840
|
*/
|
|
600
841
|
|
|
601
842
|
/**
|
|
602
843
|
* @classdesc This class implements an interface of a EPG-provider element
|
|
603
844
|
*/
|
|
604
845
|
class TXEpgProviderContainer {
|
|
605
|
-
/** @
|
|
606
|
-
#_host
|
|
607
|
-
/** @
|
|
608
|
-
#_options
|
|
609
|
-
/** @
|
|
610
|
-
#_parseOptions
|
|
611
|
-
/** @property {?TXEpgDTSProvider} */
|
|
846
|
+
/** @type {Object} */
|
|
847
|
+
#_host;
|
|
848
|
+
/** @type {OPT_epgelsett_bs} */
|
|
849
|
+
#_options;
|
|
850
|
+
/** @type {TXmlContentParseOptions} */
|
|
851
|
+
#_parseOptions;
|
|
612
852
|
|
|
613
853
|
/**
|
|
854
|
+
* Creates an instance of the EPG-provider element
|
|
614
855
|
* @param {object} obj - host object
|
|
615
|
-
* @param {
|
|
616
|
-
* @param {object} [opt.parseOptions]
|
|
617
|
-
* @description Creates an instance of the EPG-provider element
|
|
856
|
+
* @param {OPT_epgelsett_bs} [opt] - options
|
|
618
857
|
*/
|
|
619
858
|
constructor(obj, opt) {
|
|
620
859
|
// load content
|
|
621
860
|
const _host = isPlainObject(obj) ? obj : {};
|
|
622
861
|
// load options
|
|
623
|
-
const _options =
|
|
862
|
+
const _options = __evalXMLBaseNodeSettings(opt);
|
|
624
863
|
let {
|
|
625
864
|
parseOptions,
|
|
626
865
|
} = _options;
|
|
627
|
-
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
628
|
-
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
629
|
-
_options.parseOptions = parseOptions;
|
|
630
|
-
};
|
|
631
866
|
// save options
|
|
632
867
|
this.#_options = _options;
|
|
633
868
|
// save parser options
|
|
@@ -652,7 +887,7 @@ class TXEpgProviderContainer {
|
|
|
652
887
|
|
|
653
888
|
/**
|
|
654
889
|
* Contains a provider name
|
|
655
|
-
* @
|
|
890
|
+
* @type {string}
|
|
656
891
|
*/
|
|
657
892
|
get name() {
|
|
658
893
|
return _getXmlChildElementParam(this.#_host, 'name').trim();
|
|
@@ -664,7 +899,7 @@ class TXEpgProviderContainer {
|
|
|
664
899
|
|
|
665
900
|
/**
|
|
666
901
|
* Contains a version of a provider
|
|
667
|
-
* @
|
|
902
|
+
* @type {string}
|
|
668
903
|
*/
|
|
669
904
|
get version() {
|
|
670
905
|
return _getXmlChildElementParam(this.#_host, 'version').trim();
|
|
@@ -674,13 +909,15 @@ class TXEpgProviderContainer {
|
|
|
674
909
|
if (typeof value === 'string' && this.name !== '') {
|
|
675
910
|
const opt = { force: true };
|
|
676
911
|
const item = insertXObjElement(this.#_host, 'version', opt);
|
|
677
|
-
if (item)
|
|
912
|
+
if (item) {
|
|
913
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
914
|
+
};
|
|
678
915
|
};
|
|
679
916
|
}
|
|
680
917
|
|
|
681
918
|
/**
|
|
682
919
|
* Contains a version of a document schema
|
|
683
|
-
* @
|
|
920
|
+
* @type {string}
|
|
684
921
|
*/
|
|
685
922
|
get schema() {
|
|
686
923
|
return _getXmlChildElementParam(this.#_host, XEPG_DOCSCH_ETAG_NAME).trim();
|
|
@@ -690,13 +927,15 @@ class TXEpgProviderContainer {
|
|
|
690
927
|
if (typeof value === 'string') {
|
|
691
928
|
const opt = { force: true };
|
|
692
929
|
const item = insertXObjElement(this.#_host, XEPG_DOCSCH_ETAG_NAME, opt);
|
|
693
|
-
if (item)
|
|
930
|
+
if (item) {
|
|
931
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
932
|
+
};
|
|
694
933
|
};
|
|
695
934
|
}
|
|
696
935
|
|
|
697
936
|
/**
|
|
698
937
|
* Contains a document type
|
|
699
|
-
* @
|
|
938
|
+
* @type {string}
|
|
700
939
|
*/
|
|
701
940
|
get doctype() {
|
|
702
941
|
return _getXmlChildElementParam(this.#_host, XEPG_DOCTYP_ETAG_NAME).trim();
|
|
@@ -706,28 +945,32 @@ class TXEpgProviderContainer {
|
|
|
706
945
|
if (typeof value === 'string') {
|
|
707
946
|
const opt = { force: true };
|
|
708
947
|
const item = insertXObjElement(this.#_host, XEPG_DOCTYP_ETAG_NAME, opt);
|
|
709
|
-
if (item)
|
|
948
|
+
if (item) {
|
|
949
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
950
|
+
};
|
|
710
951
|
};
|
|
711
952
|
}
|
|
712
953
|
|
|
713
954
|
/**
|
|
955
|
+
* Sets a provider name
|
|
714
956
|
* @param {string} value - provider name
|
|
715
957
|
* @returns {boolean}
|
|
716
|
-
* @description Sets a provider name
|
|
717
958
|
*/
|
|
718
959
|
setName(value) {
|
|
719
960
|
let isSucceed = false;
|
|
720
961
|
if (typeof value === 'string') {
|
|
721
962
|
const name = value.trim();
|
|
722
963
|
const item = insertXObjElement(this.#_host, 'name', { force: true });
|
|
723
|
-
if (item)
|
|
964
|
+
if (item) {
|
|
965
|
+
isSucceed = writeXObjParam(item, name, defParseOptions.settings.textKey);
|
|
966
|
+
};
|
|
724
967
|
};
|
|
725
968
|
return isSucceed;
|
|
726
969
|
}
|
|
727
970
|
|
|
728
971
|
/**
|
|
972
|
+
* Returns a provider info item
|
|
729
973
|
* @returns {xepgProvInfoDesc}
|
|
730
|
-
* @description Returns a provider info item
|
|
731
974
|
*/
|
|
732
975
|
getInfo() {
|
|
733
976
|
return {
|
|
@@ -739,9 +982,9 @@ class TXEpgProviderContainer {
|
|
|
739
982
|
}
|
|
740
983
|
|
|
741
984
|
/**
|
|
985
|
+
* Sets a provider info
|
|
742
986
|
* @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
|
|
743
987
|
* @returns {void}
|
|
744
|
-
* @description Sets a provider info
|
|
745
988
|
* @todo [since v0.0.21] deprecate use of `obj`-param as array
|
|
746
989
|
*/
|
|
747
990
|
setInfo(obj) {
|
|
@@ -776,9 +1019,9 @@ class TXEpgProviderContainer {
|
|
|
776
1019
|
}
|
|
777
1020
|
|
|
778
1021
|
/**
|
|
1022
|
+
* Sets an initial instance state
|
|
779
1023
|
* @param {(xepgProvInfoDesc|string[])} opt - options
|
|
780
1024
|
* @returns {void}
|
|
781
|
-
* @description Sets an initial instance state
|
|
782
1025
|
*/
|
|
783
1026
|
init(opt) {
|
|
784
1027
|
let prov_opt = { ...defXEpgDocOptions.defProviderParam };
|
|
@@ -803,68 +1046,79 @@ class TXEpgProviderContainer {
|
|
|
803
1046
|
}
|
|
804
1047
|
|
|
805
1048
|
/**
|
|
806
|
-
*
|
|
1049
|
+
* Returns an instance content as a string in an XML-format.
|
|
807
1050
|
* @since v0.0.20
|
|
808
|
-
* @
|
|
1051
|
+
* @returns {string}
|
|
809
1052
|
*/
|
|
810
1053
|
saveToXMLString() {
|
|
811
1054
|
const options = this.#_parseOptions.js2xml;
|
|
812
1055
|
options.ignoreDocType = true;
|
|
813
1056
|
options.ignoreDeclaration = true;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1057
|
+
return serializeXObjToXMLString(
|
|
1058
|
+
this.#_host,
|
|
1059
|
+
options,
|
|
1060
|
+
XEPG_PRVINFO_ETAG_NAME,
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Loads a element content from a string.
|
|
1066
|
+
* @since v0.0.24
|
|
1067
|
+
* @param {string} xmlString - some content
|
|
1068
|
+
* @returns {boolean}
|
|
1069
|
+
* @throws {Error}
|
|
1070
|
+
* @experimental
|
|
1071
|
+
*/
|
|
1072
|
+
loadFromXMLString(xmlString) {
|
|
1073
|
+
const options = this.#_parseOptions.xml2js;
|
|
1074
|
+
options.ignoreDocType = true;
|
|
1075
|
+
options.ignoreDeclaration = true;
|
|
1076
|
+
return deserializeXObjFromXMLString(
|
|
1077
|
+
this.#_host,
|
|
1078
|
+
options,
|
|
1079
|
+
xmlString,
|
|
1080
|
+
XEPG_PRVINFO_ETAG_NAME,
|
|
1081
|
+
);
|
|
824
1082
|
}
|
|
825
1083
|
|
|
826
1084
|
};
|
|
827
1085
|
|
|
828
1086
|
/**
|
|
1087
|
+
* A channel info descriptor
|
|
829
1088
|
* @typedef {Object} xepgChnInfoDesc
|
|
830
1089
|
* @property {string} chnid - channel ID
|
|
831
1090
|
* @property {string} chname - channel name
|
|
832
1091
|
* @property {string} [chngid] - channel 'Group ID'
|
|
833
1092
|
* @property {string} [srcurl] - EPG-source URL
|
|
834
|
-
* @description A channel info descriptor
|
|
835
1093
|
*/
|
|
836
1094
|
|
|
837
1095
|
/**
|
|
1096
|
+
* @since 0.0.22
|
|
838
1097
|
* @classdesc This class implements an interface of a channel element
|
|
839
1098
|
*/
|
|
840
1099
|
class TXEpgChannelContainer {
|
|
841
|
-
/** @
|
|
842
|
-
#_host
|
|
843
|
-
/** @
|
|
844
|
-
#_options
|
|
845
|
-
/** @
|
|
846
|
-
#_parseOptions
|
|
847
|
-
/** @
|
|
848
|
-
#_xepgSchema
|
|
1100
|
+
/** @type {object} */
|
|
1101
|
+
#_host;
|
|
1102
|
+
/** @type {OPT_epgelsett_bs} */
|
|
1103
|
+
#_options;
|
|
1104
|
+
/** @type {TXmlContentParseOptions} */
|
|
1105
|
+
#_parseOptions;
|
|
1106
|
+
/** @type {string} */
|
|
1107
|
+
#_xepgSchema;
|
|
849
1108
|
|
|
850
1109
|
/**
|
|
1110
|
+
* Creates an instance of the channel element
|
|
851
1111
|
* @param {object} obj - host object
|
|
852
|
-
* @param {
|
|
853
|
-
* @param {object} [opt.parseOptions]
|
|
854
|
-
* @description Creates an instance of the channel element
|
|
1112
|
+
* @param {OPT_epgelsett_bs} [opt] - options
|
|
855
1113
|
*/
|
|
856
1114
|
constructor(obj, opt) {
|
|
857
1115
|
// load content
|
|
858
1116
|
const _host = isPlainObject(obj) ? obj : {};
|
|
859
1117
|
// load options
|
|
860
|
-
const _options =
|
|
1118
|
+
const _options = __evalXMLBaseNodeSettings(opt);
|
|
861
1119
|
let {
|
|
862
1120
|
parseOptions,
|
|
863
1121
|
} = _options;
|
|
864
|
-
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
865
|
-
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
866
|
-
_options.parseOptions = parseOptions;
|
|
867
|
-
};
|
|
868
1122
|
// set document schema version
|
|
869
1123
|
this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
|
|
870
1124
|
// save options
|
|
@@ -877,7 +1131,7 @@ class TXEpgChannelContainer {
|
|
|
877
1131
|
|
|
878
1132
|
/**
|
|
879
1133
|
* Contains a channel ID
|
|
880
|
-
* @
|
|
1134
|
+
* @type {string}
|
|
881
1135
|
* @readonly
|
|
882
1136
|
*/
|
|
883
1137
|
get id() {
|
|
@@ -886,7 +1140,7 @@ class TXEpgChannelContainer {
|
|
|
886
1140
|
|
|
887
1141
|
/**
|
|
888
1142
|
* Contains a channel name
|
|
889
|
-
* @
|
|
1143
|
+
* @type {string}
|
|
890
1144
|
*/
|
|
891
1145
|
get name() {
|
|
892
1146
|
return _getXmlChildElementParam(this.#_host, XEPG_CHNNAME_ETAG_NAME).trim();
|
|
@@ -899,13 +1153,15 @@ class TXEpgChannelContainer {
|
|
|
899
1153
|
XEPG_CHNNAME_ETAG_NAME,
|
|
900
1154
|
{ force: true },
|
|
901
1155
|
);
|
|
902
|
-
if (item)
|
|
1156
|
+
if (item) {
|
|
1157
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
1158
|
+
};
|
|
903
1159
|
};
|
|
904
1160
|
}
|
|
905
1161
|
|
|
906
1162
|
/**
|
|
907
1163
|
* Contains a channel Group ID
|
|
908
|
-
* @
|
|
1164
|
+
* @type {string}
|
|
909
1165
|
*/
|
|
910
1166
|
get gid() {
|
|
911
1167
|
return _getXmlChildElementParam(this.#_host, XEPG_CHNGID_ETAG_NAME).trim();
|
|
@@ -918,13 +1174,15 @@ class TXEpgChannelContainer {
|
|
|
918
1174
|
XEPG_CHNGID_ETAG_NAME,
|
|
919
1175
|
{ force: true },
|
|
920
1176
|
);
|
|
921
|
-
if (item)
|
|
1177
|
+
if (item) {
|
|
1178
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
1179
|
+
};
|
|
922
1180
|
};
|
|
923
1181
|
}
|
|
924
1182
|
|
|
925
1183
|
/**
|
|
926
1184
|
* Contains a channel source URL
|
|
927
|
-
* @
|
|
1185
|
+
* @type {string}
|
|
928
1186
|
*/
|
|
929
1187
|
get url() {
|
|
930
1188
|
return _getXmlChildElementParam(this.#_host, XEPG_CHNURL_ETAG_NAME).trim();
|
|
@@ -937,14 +1195,16 @@ class TXEpgChannelContainer {
|
|
|
937
1195
|
XEPG_CHNURL_ETAG_NAME,
|
|
938
1196
|
{ force: true },
|
|
939
1197
|
);
|
|
940
|
-
if (item)
|
|
1198
|
+
if (item) {
|
|
1199
|
+
writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
|
|
1200
|
+
};
|
|
941
1201
|
};
|
|
942
1202
|
}
|
|
943
1203
|
|
|
944
1204
|
/**
|
|
1205
|
+
* Tries to set a channel ID
|
|
945
1206
|
* @param {string} value - channel ID
|
|
946
1207
|
* @returns {boolean}
|
|
947
|
-
* @description Tries to set a channel ID
|
|
948
1208
|
*/
|
|
949
1209
|
setID(value) {
|
|
950
1210
|
let isSucceed = false;
|
|
@@ -956,15 +1216,15 @@ class TXEpgChannelContainer {
|
|
|
956
1216
|
{ force: true },
|
|
957
1217
|
);
|
|
958
1218
|
if (item) {
|
|
959
|
-
isSucceed = writeXObjParam(item, chnid);
|
|
1219
|
+
isSucceed = writeXObjParam(item, chnid, defParseOptions.settings.textKey);
|
|
960
1220
|
};
|
|
961
1221
|
};
|
|
962
1222
|
return isSucceed;
|
|
963
1223
|
}
|
|
964
1224
|
|
|
965
1225
|
/**
|
|
1226
|
+
* Returns a channel info
|
|
966
1227
|
* @returns {xepgChnInfoDesc}
|
|
967
|
-
* @description Returns a channel info
|
|
968
1228
|
*/
|
|
969
1229
|
getInfo() {
|
|
970
1230
|
const {
|
|
@@ -983,9 +1243,9 @@ class TXEpgChannelContainer {
|
|
|
983
1243
|
}
|
|
984
1244
|
|
|
985
1245
|
/**
|
|
1246
|
+
* Sets a channel info
|
|
986
1247
|
* @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
|
|
987
1248
|
* @returns {void}
|
|
988
|
-
* @description Sets a channel info
|
|
989
1249
|
*/
|
|
990
1250
|
setInfo(obj) {
|
|
991
1251
|
let chnid = '';
|
|
@@ -1020,14 +1280,15 @@ class TXEpgChannelContainer {
|
|
|
1020
1280
|
};
|
|
1021
1281
|
let item = null;
|
|
1022
1282
|
const _host = this.#_host;
|
|
1283
|
+
const text_key = defParseOptions.settings.textKey;
|
|
1023
1284
|
item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
|
|
1024
|
-
if (item) writeXObjParam(item, chnid);
|
|
1285
|
+
if (item) writeXObjParam(item, chnid, text_key);
|
|
1025
1286
|
item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
|
|
1026
|
-
if (item) writeXObjParam(item, chname);
|
|
1287
|
+
if (item) writeXObjParam(item, chname, text_key);
|
|
1027
1288
|
item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
|
|
1028
|
-
if (item) writeXObjParam(item, chngid);
|
|
1289
|
+
if (item) writeXObjParam(item, chngid, text_key);
|
|
1029
1290
|
item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
|
|
1030
|
-
if (item) writeXObjParam(item, srcurl);
|
|
1291
|
+
if (item) writeXObjParam(item, srcurl, text_key);
|
|
1031
1292
|
}
|
|
1032
1293
|
|
|
1033
1294
|
}
|
|
@@ -1036,29 +1297,24 @@ class TXEpgChannelContainer {
|
|
|
1036
1297
|
* @classdesc This class implements an interface of a DTS-provider element
|
|
1037
1298
|
*/
|
|
1038
1299
|
class TXEpgDTSProvider {
|
|
1039
|
-
/** @
|
|
1040
|
-
#_content
|
|
1041
|
-
/** @
|
|
1042
|
-
#_options
|
|
1300
|
+
/** @type {object} */
|
|
1301
|
+
#_content;
|
|
1302
|
+
/** @type {OPT_epgelsett_bs} */
|
|
1303
|
+
#_options;
|
|
1043
1304
|
|
|
1044
1305
|
/**
|
|
1306
|
+
* Creates an instance of the DTS-provider element
|
|
1045
1307
|
* @param {object} obj - host object
|
|
1046
|
-
* @param {
|
|
1047
|
-
* @param {object} [opt.parseOptions]
|
|
1048
|
-
* @description Creates an instance of the DTS-provider element
|
|
1308
|
+
* @param {OPT_epgelsett_bs} [opt] - options
|
|
1049
1309
|
*/
|
|
1050
1310
|
constructor(obj, opt) {
|
|
1051
1311
|
// load content
|
|
1052
1312
|
const _content = isPlainObject(obj) ? obj : {};
|
|
1053
1313
|
// load options
|
|
1054
|
-
|
|
1314
|
+
const _options = __evalXMLBaseNodeSettings(opt);
|
|
1055
1315
|
let {
|
|
1056
1316
|
parseOptions,
|
|
1057
1317
|
} = _options;
|
|
1058
|
-
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
1059
|
-
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
1060
|
-
_options.parseOptions = parseOptions;
|
|
1061
|
-
};
|
|
1062
1318
|
// save content source
|
|
1063
1319
|
this.#_content = _content;
|
|
1064
1320
|
// save options
|
|
@@ -1077,7 +1333,7 @@ class TXEpgDTSProvider {
|
|
|
1077
1333
|
|
|
1078
1334
|
/**
|
|
1079
1335
|
* Contains a dtstype ID
|
|
1080
|
-
* @
|
|
1336
|
+
* @type {number}
|
|
1081
1337
|
*/
|
|
1082
1338
|
get dtstype() {
|
|
1083
1339
|
const item = getXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
|
|
@@ -1092,7 +1348,7 @@ class TXEpgDTSProvider {
|
|
|
1092
1348
|
|
|
1093
1349
|
/**
|
|
1094
1350
|
* Contains a TZ-offset
|
|
1095
|
-
* @
|
|
1351
|
+
* @type {number}
|
|
1096
1352
|
*/
|
|
1097
1353
|
get curDocTZ() {
|
|
1098
1354
|
const tz = convTZStringToValue(
|
|
@@ -1109,15 +1365,17 @@ class TXEpgDTSProvider {
|
|
|
1109
1365
|
XEPG_DOCTZ_ETAG_NAME,
|
|
1110
1366
|
{ force: true },
|
|
1111
1367
|
);
|
|
1112
|
-
if (item)
|
|
1368
|
+
if (item) {
|
|
1369
|
+
writeXObjParam(item, _value, defParseOptions.settings.textKey);
|
|
1370
|
+
};
|
|
1113
1371
|
};
|
|
1114
1372
|
}
|
|
1115
1373
|
|
|
1116
1374
|
/**
|
|
1375
|
+
* Tries to set a `DTS`-type
|
|
1117
1376
|
* @since 0.0.22
|
|
1118
1377
|
* @property {(number|string)} value - dtstype ID
|
|
1119
1378
|
* @returns {boolean}
|
|
1120
|
-
* @description Tries to set a `DTS`-type
|
|
1121
1379
|
*/
|
|
1122
1380
|
setType(value) {
|
|
1123
1381
|
let { index, name } = getDTSysDescr(value);
|
|
@@ -1132,10 +1390,10 @@ class TXEpgDTSProvider {
|
|
|
1132
1390
|
let curItem = insertXObjElement(item, 'value', { force: true });
|
|
1133
1391
|
if (
|
|
1134
1392
|
curItem
|
|
1135
|
-
&& writeXObjParam(curItem, index)
|
|
1393
|
+
&& writeXObjParam(curItem, index, defParseOptions.settings.textKey)
|
|
1136
1394
|
&& (curItem = insertXObjElement(item, 'name', { force: true }))
|
|
1137
1395
|
) {
|
|
1138
|
-
isSucceed = writeXObjParam(curItem, name);
|
|
1396
|
+
isSucceed = writeXObjParam(curItem, name, defParseOptions.settings.textKey);
|
|
1139
1397
|
};
|
|
1140
1398
|
};
|
|
1141
1399
|
};
|
|
@@ -1148,33 +1406,28 @@ class TXEpgDTSProvider {
|
|
|
1148
1406
|
* @classdesc This class implements an interface of a EPG-header element
|
|
1149
1407
|
*/
|
|
1150
1408
|
class TXEpgHeaderContainer {
|
|
1151
|
-
/** @
|
|
1152
|
-
#_host
|
|
1153
|
-
/** @
|
|
1154
|
-
#_options
|
|
1155
|
-
/** @
|
|
1156
|
-
#_parseOptions
|
|
1157
|
-
/** @
|
|
1158
|
-
#_dtsProv
|
|
1409
|
+
/** @type {Object} */
|
|
1410
|
+
#_host;
|
|
1411
|
+
/** @type {OPT_epgelsett_bs} */
|
|
1412
|
+
#_options;
|
|
1413
|
+
/** @type {TXmlContentParseOptions} */
|
|
1414
|
+
#_parseOptions;
|
|
1415
|
+
/** @type {TXEpgDTSProvider} */
|
|
1416
|
+
#_dtsProv;
|
|
1159
1417
|
|
|
1160
1418
|
/**
|
|
1161
|
-
*
|
|
1162
|
-
* @param {object}
|
|
1163
|
-
* @param {
|
|
1164
|
-
* @description Creates an instance of the EPG-header element
|
|
1419
|
+
* Creates an instance of the EPG-header element
|
|
1420
|
+
* @param {object} obj - host element
|
|
1421
|
+
* @param {OPT_epgelsett_bs} [opt] - options
|
|
1165
1422
|
*/
|
|
1166
1423
|
constructor(obj, opt) {
|
|
1167
1424
|
// load content
|
|
1168
1425
|
const _host = isPlainObject(obj) ? obj : {};
|
|
1169
1426
|
// load options
|
|
1170
|
-
const _options =
|
|
1427
|
+
const _options = __evalXMLBaseNodeSettings(opt);
|
|
1171
1428
|
let {
|
|
1172
1429
|
parseOptions,
|
|
1173
1430
|
} = _options;
|
|
1174
|
-
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
1175
|
-
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
1176
|
-
_options.parseOptions = parseOptions;
|
|
1177
|
-
};
|
|
1178
1431
|
// save options
|
|
1179
1432
|
this.#_options = _options;
|
|
1180
1433
|
// save parser options
|
|
@@ -1187,7 +1440,7 @@ class TXEpgHeaderContainer {
|
|
|
1187
1440
|
|
|
1188
1441
|
/**
|
|
1189
1442
|
* Returns a `TXEpgDTSProvider` instance
|
|
1190
|
-
* @
|
|
1443
|
+
* @type {TXEpgDTSProvider}
|
|
1191
1444
|
* @readonly
|
|
1192
1445
|
*/
|
|
1193
1446
|
get dts() {
|
|
@@ -1196,7 +1449,7 @@ class TXEpgHeaderContainer {
|
|
|
1196
1449
|
|
|
1197
1450
|
/**
|
|
1198
1451
|
* Contains a dtstype ID
|
|
1199
|
-
* @
|
|
1452
|
+
* @type {number}
|
|
1200
1453
|
* @todo [since v0.0.22] becomes readonly
|
|
1201
1454
|
*/
|
|
1202
1455
|
get dtstype() {
|
|
@@ -1209,7 +1462,7 @@ class TXEpgHeaderContainer {
|
|
|
1209
1462
|
|
|
1210
1463
|
/**
|
|
1211
1464
|
* Contains a TZ-offset
|
|
1212
|
-
* @
|
|
1465
|
+
* @type {number}
|
|
1213
1466
|
* @todo [since v0.0.22] becomes readonly
|
|
1214
1467
|
*/
|
|
1215
1468
|
get curDocTZ() {
|
|
@@ -1244,9 +1497,10 @@ class TXEpgHeaderContainer {
|
|
|
1244
1497
|
|
|
1245
1498
|
/**
|
|
1246
1499
|
* Returns a `TXEpgProviderContainer` instance
|
|
1247
|
-
* @
|
|
1500
|
+
* @type {?TXEpgProviderContainer}
|
|
1248
1501
|
* @readonly
|
|
1249
1502
|
* @deprecated
|
|
1503
|
+
* @todo \[since `v0.0.22`] deprecated. Use `TXEpgHeaderContainer.provider`
|
|
1250
1504
|
*/
|
|
1251
1505
|
get Provider() {
|
|
1252
1506
|
return this.provider;
|
|
@@ -1255,7 +1509,7 @@ class TXEpgHeaderContainer {
|
|
|
1255
1509
|
/**
|
|
1256
1510
|
* Returns a `TXEpgProviderContainer` instance
|
|
1257
1511
|
* @since 0.0.22
|
|
1258
|
-
* @
|
|
1512
|
+
* @type {?TXEpgProviderContainer}
|
|
1259
1513
|
* @readonly
|
|
1260
1514
|
*/
|
|
1261
1515
|
get provider() {
|
|
@@ -1270,7 +1524,7 @@ class TXEpgHeaderContainer {
|
|
|
1270
1524
|
/**
|
|
1271
1525
|
* Returns a `TXEpgChannelContainer` instance
|
|
1272
1526
|
* @since 0.0.22
|
|
1273
|
-
* @
|
|
1527
|
+
* @type {?TXEpgChannelContainer}
|
|
1274
1528
|
* @readonly
|
|
1275
1529
|
*/
|
|
1276
1530
|
get channel() {
|
|
@@ -1278,8 +1532,8 @@ class TXEpgHeaderContainer {
|
|
|
1278
1532
|
}
|
|
1279
1533
|
|
|
1280
1534
|
/**
|
|
1535
|
+
* Returns a document creation date as a timestamp
|
|
1281
1536
|
* @returns {number}
|
|
1282
|
-
* @description Returns a document creation date as a timestamp
|
|
1283
1537
|
*/
|
|
1284
1538
|
getDocumentDT() {
|
|
1285
1539
|
let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTO_ETAG_NAME).trim();
|
|
@@ -1291,8 +1545,8 @@ class TXEpgHeaderContainer {
|
|
|
1291
1545
|
}
|
|
1292
1546
|
|
|
1293
1547
|
/**
|
|
1548
|
+
* Sets a document creation date to a current system time
|
|
1294
1549
|
* @returns {void}
|
|
1295
|
-
* @description Sets a document creation date to a current system time
|
|
1296
1550
|
*/
|
|
1297
1551
|
setDocumentDT() {
|
|
1298
1552
|
let dt_str = convDTValueToString(Date.now(), this.dtstype, this.curDocTZ);
|
|
@@ -1301,12 +1555,14 @@ class TXEpgHeaderContainer {
|
|
|
1301
1555
|
XEPG_DOCDTO_ETAG_NAME,
|
|
1302
1556
|
{ force: true },
|
|
1303
1557
|
);
|
|
1304
|
-
if (item)
|
|
1558
|
+
if (item) {
|
|
1559
|
+
writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
|
|
1560
|
+
};
|
|
1305
1561
|
}
|
|
1306
1562
|
|
|
1307
1563
|
/**
|
|
1564
|
+
* Returns a document expire date as a timestamp
|
|
1308
1565
|
* @returns {number}
|
|
1309
|
-
* @description Returns a document expire date as a timestamp
|
|
1310
1566
|
*/
|
|
1311
1567
|
getDocumentEDT() {
|
|
1312
1568
|
let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTE_ETAG_NAME).trim();
|
|
@@ -1318,9 +1574,9 @@ class TXEpgHeaderContainer {
|
|
|
1318
1574
|
}
|
|
1319
1575
|
|
|
1320
1576
|
/**
|
|
1577
|
+
* Sets a document expire date to a given time
|
|
1321
1578
|
* @param {any} value - document expire date
|
|
1322
1579
|
* @returns {void}
|
|
1323
|
-
* @description Sets a document expire date to a given time
|
|
1324
1580
|
*/
|
|
1325
1581
|
setDocumentEDT(value) {
|
|
1326
1582
|
// TODO: check if value is a DateTime-string
|
|
@@ -1330,12 +1586,14 @@ class TXEpgHeaderContainer {
|
|
|
1330
1586
|
XEPG_DOCDTE_ETAG_NAME,
|
|
1331
1587
|
{ force: true },
|
|
1332
1588
|
);
|
|
1333
|
-
if (item)
|
|
1589
|
+
if (item) {
|
|
1590
|
+
writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
|
|
1591
|
+
};
|
|
1334
1592
|
}
|
|
1335
1593
|
|
|
1336
1594
|
/**
|
|
1595
|
+
* Returns a channel info
|
|
1337
1596
|
* @returns {xepgChnInfoDesc}
|
|
1338
|
-
* @description Returns a channel info
|
|
1339
1597
|
*/
|
|
1340
1598
|
getChannelInfo() {
|
|
1341
1599
|
return this.channel.getInfo();
|
|
@@ -1347,7 +1605,7 @@ class TXEpgHeaderContainer {
|
|
|
1347
1605
|
* @description Sets a channel info
|
|
1348
1606
|
* @deprecated
|
|
1349
1607
|
* @todo [since v0.0.21] deprecate use of `obj`-param as array
|
|
1350
|
-
* @todo [since v0.0.22] deprecated
|
|
1608
|
+
* @todo [since v0.0.22] deprecated. Use `TXEpgChannelContainer.setInfo`
|
|
1351
1609
|
*/
|
|
1352
1610
|
setChannelInfo(obj) {
|
|
1353
1611
|
let _obj = obj;
|
|
@@ -1360,20 +1618,22 @@ class TXEpgHeaderContainer {
|
|
|
1360
1618
|
}
|
|
1361
1619
|
|
|
1362
1620
|
/**
|
|
1621
|
+
* Returns a provider info
|
|
1363
1622
|
* @returns {?xepgProvInfoDesc}
|
|
1364
|
-
* @description Returns a provider info
|
|
1365
1623
|
*/
|
|
1366
|
-
getProviderInfo(){
|
|
1624
|
+
getProviderInfo() {
|
|
1367
1625
|
const docProv = this.provider;
|
|
1368
1626
|
return docProv ? docProv.getInfo() : null;
|
|
1369
1627
|
}
|
|
1370
1628
|
|
|
1371
1629
|
/**
|
|
1630
|
+
* Sets a provider info
|
|
1372
1631
|
* @param {xepgProvInfoDesc} obj - provider info descriptor
|
|
1373
1632
|
* @returns {void}
|
|
1374
|
-
* @
|
|
1633
|
+
* @deprecated
|
|
1634
|
+
* @todo \[since `v0.0.24`] deprecated. Use `TXEpgProviderContainer.setInfo`
|
|
1375
1635
|
*/
|
|
1376
|
-
setProviderInfo(obj){
|
|
1636
|
+
setProviderInfo(obj) {
|
|
1377
1637
|
if (isArray(obj) || isObject(obj)) {
|
|
1378
1638
|
let docProv = this.provider;
|
|
1379
1639
|
if (!docProv) {
|
|
@@ -1385,37 +1645,59 @@ class TXEpgHeaderContainer {
|
|
|
1385
1645
|
}
|
|
1386
1646
|
|
|
1387
1647
|
/**
|
|
1388
|
-
*
|
|
1648
|
+
* Returns an instance content as a string in an XML-format.
|
|
1389
1649
|
* @since v0.0.20
|
|
1390
|
-
* @
|
|
1650
|
+
* @returns {string}
|
|
1391
1651
|
*/
|
|
1392
1652
|
saveToXMLString() {
|
|
1393
1653
|
const options = this.#_parseOptions.js2xml;
|
|
1394
1654
|
options.ignoreDocType = true;
|
|
1395
1655
|
options.ignoreDeclaration = true;
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1656
|
+
return serializeXObjToXMLString(
|
|
1657
|
+
this.#_host,
|
|
1658
|
+
options,
|
|
1659
|
+
XEPG_HEADER_ETAG_NAME,
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* Loads an element content from a string.
|
|
1665
|
+
* @since v0.0.24
|
|
1666
|
+
* @param {string} xmlString - some content
|
|
1667
|
+
* @returns {boolean}
|
|
1668
|
+
* @throws {Error}
|
|
1669
|
+
* @experimental
|
|
1670
|
+
*/
|
|
1671
|
+
loadFromXMLString(xmlString) {
|
|
1672
|
+
const options = this.#_parseOptions.xml2js;
|
|
1673
|
+
options.ignoreDocType = true;
|
|
1674
|
+
options.ignoreDeclaration = true;
|
|
1675
|
+
return deserializeXObjFromXMLString(
|
|
1676
|
+
this.#_host,
|
|
1677
|
+
options,
|
|
1678
|
+
xmlString,
|
|
1679
|
+
XEPG_HEADER_ETAG_NAME,
|
|
1680
|
+
);
|
|
1406
1681
|
}
|
|
1407
1682
|
|
|
1408
1683
|
};
|
|
1409
1684
|
|
|
1410
1685
|
/**
|
|
1686
|
+
* A fs ops description.
|
|
1411
1687
|
* @typedef {Object} fsoDescr
|
|
1412
1688
|
* @property {boolean} isERR - flag
|
|
1413
1689
|
* @property {number} [errCode] - error code
|
|
1414
1690
|
* @property {string} errEvent - event ID
|
|
1415
|
-
* @property {string} errMsg - event message
|
|
1416
|
-
* @property {string} source - path to file
|
|
1417
|
-
* @property {any} content - file content
|
|
1418
|
-
|
|
1691
|
+
* @property {string} [errMsg] - event message
|
|
1692
|
+
* @property {string} [source] - path to file
|
|
1693
|
+
* @property {any} [content] - file content
|
|
1694
|
+
*/
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* An options set for `TXEpgContentProvider`-class
|
|
1698
|
+
* @typedef {Object} OPT_epgcpsett
|
|
1699
|
+
* @property {TXmlContentParseOptions} [parseOptions] - parser options
|
|
1700
|
+
* @property {boolean} [autoBindRoot] - <*deprecated*>
|
|
1419
1701
|
*/
|
|
1420
1702
|
|
|
1421
1703
|
/**
|
|
@@ -1423,30 +1705,25 @@ class TXEpgHeaderContainer {
|
|
|
1423
1705
|
* that manages a content of a XEPG-document
|
|
1424
1706
|
*/
|
|
1425
1707
|
class TXEpgContentProvider {
|
|
1426
|
-
/** @
|
|
1427
|
-
#_content
|
|
1428
|
-
/** @
|
|
1429
|
-
#_options
|
|
1430
|
-
/** @
|
|
1431
|
-
#_parseOptions
|
|
1708
|
+
/** @type {Object} */
|
|
1709
|
+
#_content;
|
|
1710
|
+
/** @type {OPT_epgcpsett} */
|
|
1711
|
+
#_options;
|
|
1712
|
+
/** @type {TXmlContentParseOptions} */
|
|
1713
|
+
#_parseOptions;
|
|
1432
1714
|
|
|
1433
1715
|
/**
|
|
1434
|
-
*
|
|
1435
|
-
* @param {
|
|
1436
|
-
* @param {boolean} [opt.autoBindRoot] - <*reserved*> ([?] - deprecate)
|
|
1437
|
-
* @description Creates an instance of the XEPG-content provider
|
|
1716
|
+
* Creates an instance of the XEPG-content provider
|
|
1717
|
+
* @param {OPT_epgcpsett} [opt] - options
|
|
1438
1718
|
*/
|
|
1439
1719
|
constructor(opt) {
|
|
1440
1720
|
// load options
|
|
1441
|
-
const _options =
|
|
1721
|
+
const _options = __evalXMLBaseNodeSettings(opt);
|
|
1722
|
+
/** @type {OPT_epgcpsett} */
|
|
1442
1723
|
let {
|
|
1443
1724
|
parseOptions,
|
|
1444
1725
|
autoBindRoot, // <*reserved*> ([?] - deprecate)
|
|
1445
1726
|
} = _options;
|
|
1446
|
-
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
1447
|
-
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
1448
|
-
_options.parseOptions = parseOptions;
|
|
1449
|
-
};
|
|
1450
1727
|
if (typeof autoBindRoot !== 'boolean') autoBindRoot = false;
|
|
1451
1728
|
// save options
|
|
1452
1729
|
//_options.autoBindRoot = autoBindRoot; //* // TODO:
|
|
@@ -1477,7 +1754,12 @@ class TXEpgContentProvider {
|
|
|
1477
1754
|
if (!docRoot) {
|
|
1478
1755
|
docRoot = insertXObjElement(_content, XEPG_ROOT_ETAG_NAME);
|
|
1479
1756
|
if (docRoot) {
|
|
1480
|
-
writeXObjAttr(
|
|
1757
|
+
writeXObjAttr(
|
|
1758
|
+
docRoot,
|
|
1759
|
+
`xmlns:${XEPG_DEF_NS_NAME}`,
|
|
1760
|
+
XEPG_DEF_NS_PATH,
|
|
1761
|
+
defParseOptions.settings.attributesKey,
|
|
1762
|
+
);
|
|
1481
1763
|
};
|
|
1482
1764
|
};
|
|
1483
1765
|
return isPlainObject(docRoot) ? docRoot : null;
|
|
@@ -1543,23 +1825,19 @@ class TXEpgContentProvider {
|
|
|
1543
1825
|
|
|
1544
1826
|
/**
|
|
1545
1827
|
* Returns a `TXEpgHeaderContainer` instance
|
|
1546
|
-
* @
|
|
1828
|
+
* @type {?TXEpgHeaderContainer}
|
|
1547
1829
|
* @readonly
|
|
1548
1830
|
* @deprecated
|
|
1831
|
+
* @todo \[since `v0.0.22`] deprecated. Use `TXEpgContentProvider.header`
|
|
1549
1832
|
*/
|
|
1550
1833
|
get Header() {
|
|
1551
|
-
|
|
1552
|
-
return (
|
|
1553
|
-
docHdr
|
|
1554
|
-
? new TXEpgHeaderContainer(docHdr, this.#_options)
|
|
1555
|
-
: null
|
|
1556
|
-
);
|
|
1834
|
+
return this.header;
|
|
1557
1835
|
}
|
|
1558
1836
|
|
|
1559
1837
|
/**
|
|
1560
1838
|
* Returns a `TXEpgHeaderContainer` instance
|
|
1561
1839
|
* @since 0.0.22
|
|
1562
|
-
* @
|
|
1840
|
+
* @type {?TXEpgHeaderContainer}
|
|
1563
1841
|
* @readonly
|
|
1564
1842
|
*/
|
|
1565
1843
|
get header() {
|
|
@@ -1573,19 +1851,19 @@ class TXEpgContentProvider {
|
|
|
1573
1851
|
|
|
1574
1852
|
/**
|
|
1575
1853
|
* Returns a `TXEpgProviderContainer` instance
|
|
1576
|
-
* @
|
|
1854
|
+
* @type {?TXEpgProviderContainer}
|
|
1577
1855
|
* @readonly
|
|
1578
1856
|
* @deprecated
|
|
1857
|
+
* @todo \[since `v0.0.22`] deprecated. Use `TXEpgContentProvider.provider`
|
|
1579
1858
|
*/
|
|
1580
1859
|
get Provider() {
|
|
1581
|
-
|
|
1582
|
-
return docHdr ? docHdr.provider : null;
|
|
1860
|
+
return this.provider;
|
|
1583
1861
|
}
|
|
1584
1862
|
|
|
1585
1863
|
/**
|
|
1586
1864
|
* Returns a `TXEpgProviderContainer` instance
|
|
1587
1865
|
* @since 0.0.22
|
|
1588
|
-
* @
|
|
1866
|
+
* @type {?TXEpgProviderContainer}
|
|
1589
1867
|
* @readonly
|
|
1590
1868
|
*/
|
|
1591
1869
|
get provider() {
|
|
@@ -1595,7 +1873,7 @@ class TXEpgContentProvider {
|
|
|
1595
1873
|
|
|
1596
1874
|
/**
|
|
1597
1875
|
* Returns a `TXEpgDTSProvider` instance
|
|
1598
|
-
* @
|
|
1876
|
+
* @type {?TXEpgDTSProvider}
|
|
1599
1877
|
* @readonly
|
|
1600
1878
|
*/
|
|
1601
1879
|
get dts() {
|
|
@@ -1611,10 +1889,22 @@ class TXEpgContentProvider {
|
|
|
1611
1889
|
|
|
1612
1890
|
/**
|
|
1613
1891
|
* Returns a `TXEpgSchedulesList` instance
|
|
1614
|
-
* @
|
|
1892
|
+
* @type {TXEpgSchedulesList}
|
|
1615
1893
|
* @readonly
|
|
1894
|
+
* @deprecated
|
|
1895
|
+
* @todo \[since `v0.0.24`] deprecated. Use `TXEpgContentProvider.schedules`
|
|
1616
1896
|
*/
|
|
1617
1897
|
get SchedulesList() {
|
|
1898
|
+
return this.schedules;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
/**
|
|
1902
|
+
* Returns a `TXEpgSchedulesList` instance
|
|
1903
|
+
* @since 0.0.24
|
|
1904
|
+
* @type {TXEpgSchedulesList}
|
|
1905
|
+
* @readonly
|
|
1906
|
+
*/
|
|
1907
|
+
get schedules() {
|
|
1618
1908
|
const _options = this.#_options;
|
|
1619
1909
|
const docBody = this.#_getBody();
|
|
1620
1910
|
if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
|
|
@@ -1669,8 +1959,8 @@ class TXEpgContentProvider {
|
|
|
1669
1959
|
}
|
|
1670
1960
|
|
|
1671
1961
|
/**
|
|
1962
|
+
* Returns a document content as a string in an XML-format.
|
|
1672
1963
|
* @returns {string}
|
|
1673
|
-
* @description Returns a document content as a string in an XML-format.
|
|
1674
1964
|
*/
|
|
1675
1965
|
saveToXMLString() {
|
|
1676
1966
|
let result = '';
|
|
@@ -1684,11 +1974,11 @@ class TXEpgContentProvider {
|
|
|
1684
1974
|
}
|
|
1685
1975
|
|
|
1686
1976
|
/**
|
|
1977
|
+
* Saves a document content to a file.
|
|
1687
1978
|
* @param {string} source - a path to a file
|
|
1688
1979
|
* @returns {Promise<fsoDescr, Error>}
|
|
1689
1980
|
* @throws {Error}
|
|
1690
1981
|
* @async
|
|
1691
|
-
* @description Saves a document content to a file.
|
|
1692
1982
|
*/
|
|
1693
1983
|
saveToFile(source) {
|
|
1694
1984
|
/**/// main part that return promise as a result
|
|
@@ -1725,9 +2015,9 @@ class TXEpgContentProvider {
|
|
|
1725
2015
|
}
|
|
1726
2016
|
|
|
1727
2017
|
/**
|
|
2018
|
+
* Saves a document content to a file.
|
|
1728
2019
|
* @param {string} source - path to a file
|
|
1729
2020
|
* @returns {fsoDescr}
|
|
1730
|
-
* @description Saves a document content to a file.
|
|
1731
2021
|
*/
|
|
1732
2022
|
saveToFileSync(source) {
|
|
1733
2023
|
/** @type {fsoDescr} */
|
|
@@ -1754,11 +2044,11 @@ class TXEpgContentProvider {
|
|
|
1754
2044
|
}
|
|
1755
2045
|
|
|
1756
2046
|
/**
|
|
2047
|
+
* Loads a document content from a string.
|
|
2048
|
+
* @since 0.0.18
|
|
1757
2049
|
* @param {string} xmlString - a document content in XML-format
|
|
1758
2050
|
* @returns {boolean}
|
|
1759
2051
|
* @throws {Error}
|
|
1760
|
-
* @since 0.0.18
|
|
1761
|
-
* @description Loads a document content from a string.
|
|
1762
2052
|
*/
|
|
1763
2053
|
loadFromXMLString(xmlString) {
|
|
1764
2054
|
let isSUCCEED = false;
|
|
@@ -1791,23 +2081,16 @@ class TXEpgContentProvider {
|
|
|
1791
2081
|
}
|
|
1792
2082
|
|
|
1793
2083
|
/**
|
|
1794
|
-
*
|
|
1795
|
-
*/
|
|
1796
|
-
loadFromString(...args){
|
|
1797
|
-
return this.loadFromXMLString(...args);
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
/**
|
|
2084
|
+
* Loads a document content from a file.
|
|
1801
2085
|
* @param {string} source - path to a file
|
|
1802
2086
|
* @returns {Promise<fsoDescr, Error>}
|
|
1803
2087
|
* @throws {Error}
|
|
1804
2088
|
* @async
|
|
1805
|
-
* @description Loads a document content from a file.
|
|
1806
2089
|
*/
|
|
1807
2090
|
loadFromFile(source) {
|
|
1808
2091
|
/**/// main part that return promise as a result
|
|
1809
2092
|
return new Promise((resolve, reject) => {
|
|
1810
|
-
|
|
2093
|
+
loadFromFile(source).then(data => {
|
|
1811
2094
|
if (!data.isERR) {
|
|
1812
2095
|
if (data.content !== '') {
|
|
1813
2096
|
if (this.loadFromXMLString(data.content)) {
|
|
@@ -1833,12 +2116,12 @@ class TXEpgContentProvider {
|
|
|
1833
2116
|
}
|
|
1834
2117
|
|
|
1835
2118
|
/**
|
|
2119
|
+
* Loads a document content from a file.
|
|
1836
2120
|
* @param {string} source - path to a file
|
|
1837
2121
|
* @returns {fsoDescr}
|
|
1838
|
-
* @description Loads a document content from a file.
|
|
1839
2122
|
*/
|
|
1840
2123
|
loadFromFileSync(source) {
|
|
1841
|
-
const data =
|
|
2124
|
+
const data = loadFromFileSync(source);
|
|
1842
2125
|
if (!data.isERR) {
|
|
1843
2126
|
if (data.content !== '') {
|
|
1844
2127
|
if (this.loadFromXMLString(data.content)) {
|
|
@@ -1868,6 +2151,15 @@ class TXEpgContentProvider {
|
|
|
1868
2151
|
|
|
1869
2152
|
// === module exports block ===
|
|
1870
2153
|
|
|
2154
|
+
module.exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
|
|
2155
|
+
module.exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
|
|
2156
|
+
module.exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
|
|
2157
|
+
module.exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
|
|
2158
|
+
|
|
2159
|
+
module.exports.readAsTagName = readAsTagName;
|
|
2160
|
+
module.exports.readAsAttrName = readAsAttrName;
|
|
2161
|
+
module.exports.valueToElementID = valueToElementID;
|
|
2162
|
+
|
|
1871
2163
|
module.exports.TXEpgDTSProvider = TXEpgDTSProvider;
|
|
1872
2164
|
module.exports.TXEpgScheduleItem = TXEpgScheduleItem;
|
|
1873
2165
|
module.exports.TXEpgSchedulesList = TXEpgSchedulesList;
|
|
@@ -1875,11 +2167,3 @@ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
|
|
|
1875
2167
|
module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
|
|
1876
2168
|
module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
|
|
1877
2169
|
module.exports.TXEpgContentProvider = TXEpgContentProvider;
|
|
1878
|
-
|
|
1879
|
-
module.exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
|
|
1880
|
-
module.exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
|
|
1881
|
-
module.exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
|
|
1882
|
-
module.exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
|
|
1883
|
-
|
|
1884
|
-
/** @deprecated */
|
|
1885
|
-
module.exports.TXepgDTSProvider = TXEpgDTSProvider;
|