@ygracs/xepg-lib-js 0.0.21 → 0.0.23

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.
@@ -1,18 +1,19 @@
1
- // [v0.1.081-20250227]
1
+ // [v0.2.106-20250428]
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, readAsNumberEx,
8
+ valueToIndex, valueToIDString,
9
+ readAsString, readAsNumber,
10
10
  isNotEmptyString,
11
11
  isArray, isObject, isPlainObject,
12
12
  } = require('@ygracs/bsfoc-lib-js');
13
13
 
14
14
  const {
15
15
  convValueToTZString, convTZStringToValue,
16
+ tryDTValue,
16
17
  } = require('@ygracs/dtf-lib-js');
17
18
 
18
19
  const {
@@ -21,15 +22,19 @@ const {
21
22
  } = require('./dts-helper.js');
22
23
 
23
24
  const {
24
- loadFileSync, loadFile,
25
+ loadFromFileSync, loadFromFile,
25
26
  saveToFileSync, saveToFile,
26
- } = require('./file-helper.js');
27
+ } = require('@cntwg/file-helper');
27
28
 
28
29
  const xObj = require('@ygracs/xobj-lib-js');
29
30
 
30
- const TXmlContentParseOptions = xObj.TXmlContentParseOptions;
31
- const insertXObjElement = xObj.insertXObjElement;
32
- const getXObjElement = xObj.getXObjElement;
31
+ const {
32
+ TXmlContentParseOptions,
33
+ getXObjElement,
34
+ insertXObjElement,
35
+ writeXObjParam,
36
+ writeXObjAttr,
37
+ } = xObj;
33
38
 
34
39
  // === module extra block (helper functions) ===
35
40
 
@@ -41,37 +46,52 @@ function readXObjParam(obj){
41
46
  return xObj.readXObjParam(obj, defParseOptions.settings.textKey);
42
47
  };
43
48
 
44
- function writeXObjParam(obj, value){
45
- return xObj.writeXObjParam(obj, value, defParseOptions.settings.textKey);
46
- };
47
-
48
- function writeXObjAttr(obj, name, value) {
49
- return xObj.writeXObjAttr(
50
- obj, name, value, defParseOptions.settings.attributesKey
51
- );
52
- };
53
-
54
49
  /*
55
50
  * === xObj-function wrappers (end) ===
56
51
  */
57
52
 
58
- function _getXmlChildElementParam(obj, elem){
59
- const child = obj ? getXObjElement(obj, elem) : null;
53
+ /**
54
+ * @param {object} obj - element
55
+ * @param {string} name - child element name
56
+ * @returns {string}
57
+ * @inner
58
+ */
59
+ function _getXmlChildElementParam(obj, name) {
60
+ const child = obj ? getXObjElement(obj, name) : null;
60
61
  return child ? readXObjParam(child) : '';
61
62
  };
62
63
 
63
- function writeXEpgDocDeclSection(obj, opt){
64
+ /**
65
+ * @param {object} obj - element
66
+ * @returns {number}
67
+ * @inner
68
+ */
69
+ function _getDTSTypeValueForXObj(obj) {
70
+ const result = valueToIndex(
71
+ _getXmlChildElementParam(obj, 'value')
72
+ );
73
+ return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
74
+ };
75
+
76
+ /**
77
+ * @param {object} obj - element
78
+ * @param {*} data - data
79
+ * @returns {void}
80
+ * @inner
81
+ */
82
+ function writeXEpgDocDeclSection(obj, data) {
83
+ const key_name = defParseOptions.settings.declarationKey;
64
84
  let xml_ver = XEPG_XML_DOC_VERSION;
65
85
  let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
66
- let key_name = defParseOptions.settings.declarationKey;
67
- if (isPlainObject(opt)) {
68
- xml_ver = readAsString(opt.version, { defValue: xml_ver });
69
- doc_def_enc = readAsString(opt.encoding, { defValue: doc_def_enc });
86
+ if (isPlainObject(data)) {
87
+ xml_ver = readAsString(data.version, { defValue: xml_ver });
88
+ doc_def_enc = readAsString(data.encoding, { defValue: doc_def_enc });
70
89
  };
71
90
  if (isPlainObject(obj) && isNotEmptyString(key_name)) {
72
91
  obj[key_name] = {};
73
- writeXObjAttr(obj[key_name], 'version', xml_ver);
74
- writeXObjAttr(obj[key_name], 'encoding', doc_def_enc);
92
+ const attr_key = defParseOptions.settings.attributesKey;
93
+ writeXObjAttr(obj[key_name], 'version', xml_ver, attr_key);
94
+ writeXObjAttr(obj[key_name], 'encoding', doc_def_enc, attr_key);
75
95
  };
76
96
  };
77
97
 
@@ -81,6 +101,11 @@ function writeXEpgDocDeclSection(obj, opt){
81
101
  * (* constant definitions *)
82
102
  */
83
103
 
104
+ /**
105
+ * A list of a document schema version supported by a library
106
+ */
107
+ const ALLOWED_XEPG_DOCUMENT_SCHEMA = [ '0.2' ];
108
+
84
109
  const XEPG_ROOT_ETAG_NAME = 'epgdoc';
85
110
  const XEPG_DEF_NS_NAME = 'tvp';
86
111
  const XEPG_DEF_NS_PATH = 'urn:e-doc:epg-doc:xepg';
@@ -106,9 +131,9 @@ const XEPG_SCHEDDESC_ETAG_NAME = `${XEPG_DEF_NS_NAME}:desc`;
106
131
  const XEPG_XML_DOC_VERSION = '1.0';
107
132
  const XEPG_DEF_ENCODING_VALUE = 'UTF-8';
108
133
  const XEPG_DEF_DOCUMENT_TYPE = 'xepg';
109
- const XEPG_DEF_DOCUMENT_SCHEMA = '0.2';
134
+ const XEPG_DEF_DOCUMENT_SCHEMA = ALLOWED_XEPG_DOCUMENT_SCHEMA[0];
110
135
  const XEPG_DEF_PROVIDER_NAME = 'xepg-lib-js';
111
- const XEPG_DEF_PROVIDER_VER = '0.0.15';
136
+ const XEPG_DEF_PROVIDER_VER = '0.0.21';
112
137
 
113
138
  const defXEpgDocOptions = {
114
139
  xmlns_xepg_pref: XEPG_DEF_NS_NAME,
@@ -135,6 +160,75 @@ const defParseOptions = new TXmlContentParseOptions();
135
160
  * (* function definitions *)
136
161
  */
137
162
 
163
+ /**
164
+ * @since v0.0.23
165
+ * @function readAsTagName
166
+ * @param {any} value - some value
167
+ * @returns {string}
168
+ * @description Tries to convert a given value to a valid tag name
169
+ * of an XML-element.
170
+ */
171
+ function readAsTagName(value) {
172
+ let tagName = valueToIDString(value, { ignoreNumbers: true });
173
+ if (tagName === null) return '';
174
+ if (tagName !== '') {
175
+ // // TODO: do extra checks
176
+ const template = /[\s\/\\\"\'<>=]/;
177
+ const trigger = tagName.match(template);
178
+ if (trigger) {
179
+ //console.log(trigger);
180
+ tagName = '';
181
+ };
182
+ };
183
+ return tagName;
184
+ };
185
+
186
+ /**
187
+ * @since v0.0.23
188
+ * @function readAsAttrName
189
+ * @param {any} value - some value
190
+ * @returns {string}
191
+ * @description Tries to convert a given value to a valid name
192
+ * of an XML-attribute.
193
+ */
194
+ function readAsAttrName(value) {
195
+ let attrName = valueToIDString(value, { ignoreNumbers: true });
196
+ if (attrName === null) return '';
197
+ if (attrName !== '') {
198
+ // // TODO: do extra checks
199
+ const template = /[\s\/\\\"\'<>=]/;
200
+ const trigger = attrName.match(template);
201
+ if (trigger) {
202
+ //console.log(trigger);
203
+ attrName = '';
204
+ };
205
+ };
206
+ return attrName;
207
+ };
208
+
209
+ /**
210
+ * @since v0.0.23
211
+ * @function valueToElementID
212
+ * @param {any} value - some value
213
+ * @returns {string}
214
+ * @description Tries to convert a given value to a valid identifier
215
+ * suitable as a value for an "ID-attribute" of an XML-element.
216
+ */
217
+ function valueToElementID(value) {
218
+ let id = valueToIDString(value);
219
+ if (id === null) return '';
220
+ if (id !== '') {
221
+ // // TODO: do extra checks
222
+ const template = /[\s\/\\\"\'<>=]/;
223
+ const trigger = id.match(template);
224
+ if (trigger) {
225
+ //console.log(trigger);
226
+ id = '';
227
+ };
228
+ };
229
+ return id;
230
+ };
231
+
138
232
  /***
139
233
  * (* class definitions *)
140
234
  */
@@ -149,28 +243,294 @@ const defParseOptions = new TXmlContentParseOptions();
149
243
  * @description A schedule info descriptor
150
244
  */
151
245
 
246
+ /**
247
+ * @typedef {Object} OPT_epgelsett_bs
248
+ * @property {TXmlContentParseOptions} [parseOptions] - parser options
249
+ * @description An XEPG-element options set (base)
250
+ */
251
+
252
+ /**
253
+ * @typedef {Object} OPT_epgelsett_ex
254
+ * @property {TXmlContentParseOptions} [parseOptions] - parser options
255
+ * @property {object} [opt.dts_src]
256
+ * @property {object} [opt.tz_src]
257
+ * @description An XEPG-element options set (extend)
258
+ */
259
+
260
+ /**
261
+ * @since 0.0.22
262
+ * @classdesc This class implements an interface of a EPG-schedule element
263
+ */
264
+ class TXEpgScheduleItem {
265
+ /** @type {object} */
266
+ #_host;// = null;
267
+ /** @type {OPT_epgelsett_ex} */
268
+ #_options;// = null;
269
+ /** @type {TXmlContentParseOptions} */
270
+ #_parseOptions;// = null;
271
+ /** @type {?object} */
272
+ #_dts_src = null;
273
+ /** @type {?object} */
274
+ #_tz_src = null;
275
+
276
+ /**
277
+ * @param {object} obj - host object
278
+ * @param {OPT_epgelsett_ex} [opt] - options
279
+ * @description Creates an instance of the EPG-schedule element
280
+ */
281
+ constructor(obj, opt) {
282
+ // load content
283
+ const _host = isPlainObject(obj) ? obj : {};
284
+ // load options
285
+ /** @type {OPT_epgelsett_ex} */
286
+ const _options = isPlainObject(opt) ? opt : {};
287
+ let {
288
+ parseOptions,
289
+ dts_src, tz_src,
290
+ } = _options;
291
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
292
+ parseOptions = new TXmlContentParseOptions(parseOptions);
293
+ _options.parseOptions = parseOptions;
294
+ };
295
+ if (!isPlainObject(dts_src)) dts_src = null;
296
+ if (!isPlainObject(tz_src)) tz_src = null;
297
+ // save content source
298
+ this.#_host = _host;
299
+ // save options
300
+ this.#_options = _options;
301
+ // save parser options
302
+ this.#_parseOptions = parseOptions;
303
+ // save refs to a time source priveders
304
+ this.#_dts_src = dts_src;
305
+ this.#_tz_src = tz_src;
306
+ }
307
+
308
+ /**
309
+ * Contains a dtstype ID
310
+ * @type {number}
311
+ * @readonly
312
+ */
313
+ get dtstype() {
314
+ return _getDTSTypeValueForXObj(this.#_dts_src);
315
+ }
316
+
317
+ /**
318
+ * Contains a TZ-offset
319
+ * @type {number}
320
+ * @readonly
321
+ */
322
+ get curDocTZ() {
323
+ return (
324
+ this.#_tz_src
325
+ ? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
326
+ : 0
327
+ );
328
+ }
329
+
330
+ /**
331
+ * Contains a schedule start time as a timestamp
332
+ * @type {number}
333
+ * @readonly
334
+ */
335
+ get time() {
336
+ return convStringToDTValue(
337
+ _getXmlChildElementParam(this.#_host, XEPG_SCHEDTIME_ETAG_NAME).trim(),
338
+ this.dtstype, this.curDocTZ
339
+ );
340
+ }
341
+
342
+ /**
343
+ * Contains a schedule title
344
+ * @type {string}
345
+ * @readonly
346
+ */
347
+ get title() {
348
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDTITL_ETAG_NAME).trim();
349
+ }
350
+
351
+ /**
352
+ * Contains a schedule category
353
+ * @type {string}
354
+ * @readonly
355
+ */
356
+ get category() {
357
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDCAT_ETAG_NAME).trim();
358
+ }
359
+
360
+ /**
361
+ * Contains a schedule rating value (aka pcmark)
362
+ * @type {number}
363
+ * @readonly
364
+ */
365
+ get rating() {
366
+ return readAsNumber(
367
+ _getXmlChildElementParam(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME), 0
368
+ );
369
+ }
370
+
371
+ /**
372
+ * Contains a schedule description
373
+ * @type {string}
374
+ * @readonly
375
+ */
376
+ get descr() {
377
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDDESC_ETAG_NAME);
378
+ }
379
+
380
+ /**
381
+ * @returns {xepgShedInfoDesc}
382
+ * @description Returns a schedule info item descriptor
383
+ */
384
+ getInfo() {
385
+ const {
386
+ time,
387
+ title,
388
+ category: cat,
389
+ rating: pcmark,
390
+ descr,
391
+ } = this;
392
+ return {
393
+ time,
394
+ title,
395
+ cat,
396
+ pcmark,
397
+ descr,
398
+ };
399
+ }
400
+
401
+ /**
402
+ * @param {(number|string|Date)} value - some time value
403
+ * @returns {boolean}
404
+ * @description Sets a schedule start time.
405
+ */
406
+ setTime(value) {
407
+ let { isSucceed, value: dtValue } = tryDTValue(value);
408
+ let result = false;
409
+ if (isSucceed) {
410
+ dtValue = convDTValueToString(dtValue, this.dtstype, this.curDocTZ);
411
+ if (dtValue !== '') {
412
+ const opt = { force: true };
413
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDTIME_ETAG_NAME, opt);
414
+ if (item) {
415
+ result = writeXObjParam(item, dtValue, defParseOptions.settings.textKey);
416
+ };
417
+ };
418
+ };
419
+ return result;
420
+ }
421
+
422
+ /**
423
+ * @param {string} value - some title
424
+ * @returns {boolean}
425
+ * @description Sets a schedule title.
426
+ */
427
+ setTitle(value) {
428
+ let result = false;
429
+ if (typeof value === 'string') {
430
+ const opt = { force: true };
431
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDTITL_ETAG_NAME, opt);
432
+ if (item) {
433
+ result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
434
+ };
435
+ };
436
+ return result;
437
+ }
438
+
439
+ /**
440
+ * @param {string} value - some title
441
+ * @returns {boolean}
442
+ * @description Sets a schedule title.
443
+ */
444
+ setCategory(value) {
445
+ let result = false;
446
+ if (typeof value === 'string') {
447
+ const opt = { force: true };
448
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDCAT_ETAG_NAME, opt);
449
+ if (item) {
450
+ result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
451
+ };
452
+ };
453
+ return result;
454
+ }
455
+
456
+ /**
457
+ * @param {(number|string)} value - some value
458
+ * @returns {boolean}
459
+ * @description Sets a schedule rating value.
460
+ */
461
+ setRating(value) {
462
+ const _value = valueToIndex(value);
463
+ let result = false;
464
+ if (_value !== -1) {
465
+ const opt = { force: true };
466
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME, opt);
467
+ if (item) {
468
+ result = writeXObjParam(item, _value, defParseOptions.settings.textKey);
469
+ };
470
+ };
471
+ return result;
472
+ }
473
+
474
+ /**
475
+ * @param {string} value - some text
476
+ * @returns {boolean}
477
+ * @description Sets a schedule description.
478
+ */
479
+ setDescr(value) {
480
+ let result = false;
481
+ if (typeof value === 'string') {
482
+ const opt = { force: true };
483
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDDESC_ETAG_NAME, opt);
484
+ if (item) {
485
+ result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
486
+ };
487
+ };
488
+ return result;
489
+ }
490
+
491
+ /**
492
+ * @returns {string}
493
+ * @description Returns an instance content as a string in an XML-format.
494
+ */
495
+ saveToXMLString() {
496
+ const options = this.#_parseOptions.js2xml;
497
+ options.ignoreDocType = true;
498
+ options.ignoreDeclaration = true;
499
+ const content = { [`${XEPG_SCHED_ETAG_NAME}`]: this.#_host };
500
+ let result = '';
501
+ try {
502
+ result = xmlParser.js2xml(content, options);
503
+ } catch (err) {
504
+ //console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
505
+ result = '';
506
+ //throw err;
507
+ };
508
+ return result;
509
+ }
510
+
511
+ };
512
+
152
513
  /**
153
514
  * @classdesc This class implements an interface of a EPG-schedules list
154
515
  */
155
516
  class TXEpgSchedulesList {
156
- /** @property {object[]} */
517
+ /** @type {object[]} */
157
518
  #_content;// = null;
158
- /** @property {object} */
519
+ /** @type {OPT_epgelsett_ex} */
159
520
  #_options;// = null;
160
- /** @property {?object} */
521
+ /** @type {?object} */
161
522
  #_dts_src = null;
162
- /** @property {?object} */
523
+ /** @type {?object} */
163
524
  #_tz_src = null;
164
525
 
165
526
  /**
166
527
  * @param {any[]} obj - list of an elements
167
- * @param {object} [opt] - options
168
- * @param {?object} [opt.dts_src]
169
- * @param {?object} [opt.tz_src]
528
+ * @param {OPT_epgelsett_ex} [opt] - options
170
529
  * @description Creates an instance of the schedules list
171
530
  */
172
531
  constructor(obj, opt) {
173
532
  const _content = isArray(obj) ? obj : [];
533
+ /** @type {OPT_epgelsett_ex} */
174
534
  const _options = isPlainObject(opt) ? opt : {};
175
535
  let { dts_src, tz_src } = _options;
176
536
  if (!isPlainObject(dts_src)) dts_src = null;
@@ -198,31 +558,25 @@ class TXEpgSchedulesList {
198
558
 
199
559
  /**
200
560
  * Contains a quantity of a schedules
201
- * @property {number}
561
+ * @type {number}
202
562
  * @readonly
203
563
  */
204
564
  get schedQty() {
205
565
  return this.#_content.length;
206
566
  }
207
567
 
208
- // will deprecate
209
- //get SchedulesQty(){ return this.#_content.length; }
210
-
211
568
  /**
212
569
  * Contains a dtstype ID
213
- * @property {number}
570
+ * @type {number}
214
571
  * @readonly
215
572
  */
216
573
  get dtstype() {
217
- let result = valueToIndex(
218
- _getXmlChildElementParam(this.#_dts_src, 'value')
219
- );
220
- return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
574
+ return _getDTSTypeValueForXObj(this.#_dts_src);
221
575
  }
222
576
 
223
577
  /**
224
578
  * Contains a TZ-offset
225
- * @property {number}
579
+ * @type {number}
226
580
  * @readonly
227
581
  */
228
582
  get curDocTZ() {
@@ -255,15 +609,17 @@ class TXEpgSchedulesList {
255
609
  * @deprecated
256
610
  * @description Checks whether a given value is a valid index
257
611
  * and it fits the index range of an instance
612
+ * @done [since v0.0.20] deprecated
613
+ * @todo [from v0.0.23] will be removed
258
614
  */
259
615
  chkScheduleIndex(value) {
260
616
  return this.chkIndex(value);
261
617
  }
262
618
 
263
619
  /**
620
+ * @since 0.0.20
264
621
  * @param {(number|string)} value - index of some element
265
622
  * @returns {boolean}
266
- * @since 0.0.18
267
623
  * @description Checks whether a given value is a valid index
268
624
  * and it fits the index range of an instance
269
625
  */
@@ -273,37 +629,32 @@ class TXEpgSchedulesList {
273
629
  }
274
630
 
275
631
  /**
632
+ * @since 0.0.22
276
633
  * @param {(number|string)} index - index of some element
277
- * @returns {xepgShedInfoDesc}
634
+ * @returns {?TXEpgScheduleItem}
635
+ * @description Returns a schedule element addressed by a given index
636
+ */
637
+ schedule(index) {
638
+ const curObj = this.#_getItem(index);
639
+ let item = null;
640
+ if (isPlainObject(curObj)) {
641
+ item = new TXEpgScheduleItem(curObj, {
642
+ dts_src: this.#_dts_src,
643
+ tz_src: this.#_tz_src,
644
+ });
645
+ };
646
+ return item;
647
+ }
648
+
649
+ /**
650
+ * @param {(number|string)} index - index of some element
651
+ * @returns {?xepgShedInfoDesc}
278
652
  * @description Returns a schedule info item for instance element
279
653
  * addressed by a given index
280
654
  */
281
655
  getScheduleInfo(index) {
282
- //console.log('TXEpgSchedulesList => getScheduleInfo() => was called...');
283
- const curObj = this.#_getItem(index);
284
- let tmpObj = {};
285
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+']');
286
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(curObj, null, 2));
287
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [time]');
288
- tmpObj.time = convStringToDTValue(
289
- _getXmlChildElementParam(curObj, XEPG_SCHEDTIME_ETAG_NAME).trim(),
290
- this.dtstype, this.curDocTZ
291
- );
292
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [title]');
293
- tmpObj.title = _getXmlChildElementParam(curObj, XEPG_SCHEDTITL_ETAG_NAME).trim();
294
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [category]');
295
- tmpObj.cat = _getXmlChildElementParam(curObj, XEPG_SCHEDCAT_ETAG_NAME).trim();
296
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [pcmark]');
297
- tmpObj.pcmark = readAsNumberEx(
298
- _getXmlChildElementParam(curObj, XEPG_SCHEDPMARK_ETAG_NAME), 0
299
- );
300
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [description]');
301
- tmpObj.descr = _getXmlChildElementParam(curObj, XEPG_SCHEDDESC_ETAG_NAME);
302
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(curObj, null, 2));
303
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(tmpObj, null, 2));
304
- // TODO: wrap tmpObj into container object
305
- //console.log('TXEpgSchedulesList => getScheduleInfo() => was left...');
306
- return tmpObj;
656
+ const obj = this.schedule(index);
657
+ return obj ? obj.getInfo() : null;
307
658
  }
308
659
 
309
660
  /**
@@ -341,24 +692,24 @@ class TXEpgSchedulesList {
341
692
  * @classdesc This class implements an interface of a EPG-provider element
342
693
  */
343
694
  class TXEpgProviderContainer {
344
- /** @property {Object} */
695
+ /** @type {Object} */
345
696
  #_host;// = null;
346
- /** @property {Object} */
697
+ /** @type {OPT_epgelsett_bs} */
347
698
  #_options;// = null;
348
- /** @property {TXmlContentParseOptions} */
699
+ /** @type {TXmlContentParseOptions} */
349
700
  #_parseOptions;// = null;
350
- /** @property {?TXEpgDTSProvider} */
701
+ /** @type {?TXEpgDTSProvider} */
351
702
 
352
703
  /**
353
- * @param {object} obj
354
- * @param {object} [opt] - options
355
- * @param {object} [opt.parseOptions]
704
+ * @param {object} obj - host object
705
+ * @param {OPT_epgelsett_bs} [opt] - options
356
706
  * @description Creates an instance of the EPG-provider element
357
707
  */
358
708
  constructor(obj, opt) {
359
709
  // load content
360
710
  const _host = isPlainObject(obj) ? obj : {};
361
711
  // load options
712
+ /** @type {OPT_epgelsett_bs} */
362
713
  const _options = isPlainObject(opt) ? opt : {};
363
714
  let {
364
715
  parseOptions,
@@ -391,7 +742,7 @@ class TXEpgProviderContainer {
391
742
 
392
743
  /**
393
744
  * Contains a provider name
394
- * @property {string}
745
+ * @type {string}
395
746
  */
396
747
  get name() {
397
748
  return _getXmlChildElementParam(this.#_host, 'name').trim();
@@ -403,7 +754,7 @@ class TXEpgProviderContainer {
403
754
 
404
755
  /**
405
756
  * Contains a version of a provider
406
- * @property {string}
757
+ * @type {string}
407
758
  */
408
759
  get version() {
409
760
  return _getXmlChildElementParam(this.#_host, 'version').trim();
@@ -413,13 +764,15 @@ class TXEpgProviderContainer {
413
764
  if (typeof value === 'string' && this.name !== '') {
414
765
  const opt = { force: true };
415
766
  const item = insertXObjElement(this.#_host, 'version', opt);
416
- if (item) writeXObjParam(item, value.trim());
767
+ if (item) {
768
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
769
+ };
417
770
  };
418
771
  }
419
772
 
420
773
  /**
421
774
  * Contains a version of a document schema
422
- * @property {string}
775
+ * @type {string}
423
776
  */
424
777
  get schema() {
425
778
  return _getXmlChildElementParam(this.#_host, XEPG_DOCSCH_ETAG_NAME).trim();
@@ -429,13 +782,15 @@ class TXEpgProviderContainer {
429
782
  if (typeof value === 'string') {
430
783
  const opt = { force: true };
431
784
  const item = insertXObjElement(this.#_host, XEPG_DOCSCH_ETAG_NAME, opt);
432
- if (item) writeXObjParam(item, value.trim());
785
+ if (item) {
786
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
787
+ };
433
788
  };
434
789
  }
435
790
 
436
791
  /**
437
792
  * Contains a document type
438
- * @property {string}
793
+ * @type {string}
439
794
  */
440
795
  get doctype() {
441
796
  return _getXmlChildElementParam(this.#_host, XEPG_DOCTYP_ETAG_NAME).trim();
@@ -445,144 +800,363 @@ class TXEpgProviderContainer {
445
800
  if (typeof value === 'string') {
446
801
  const opt = { force: true };
447
802
  const item = insertXObjElement(this.#_host, XEPG_DOCTYP_ETAG_NAME, opt);
448
- if (item) writeXObjParam(item, value.trim());
803
+ if (item) {
804
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
805
+ };
449
806
  };
450
807
  }
451
808
 
452
809
  /**
453
810
  * @param {string} value - provider name
454
811
  * @returns {boolean}
455
- * @description Sets a provider name
812
+ * @description Sets a provider name
813
+ */
814
+ setName(value) {
815
+ let isSucceed = false;
816
+ if (typeof value === 'string') {
817
+ const name = value.trim();
818
+ const item = insertXObjElement(this.#_host, 'name', { force: true });
819
+ if (item) {
820
+ isSucceed = writeXObjParam(item, name, defParseOptions.settings.textKey);
821
+ };
822
+ };
823
+ return isSucceed;
824
+ }
825
+
826
+ /**
827
+ * @returns {xepgProvInfoDesc}
828
+ * @description Returns a provider info item
829
+ */
830
+ getInfo() {
831
+ return {
832
+ name: this.name,
833
+ version: this.version,
834
+ schema: this.schema,
835
+ doctype: this.doctype,
836
+ };
837
+ }
838
+
839
+ /**
840
+ * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
841
+ * @returns {void}
842
+ * @description Sets a provider info
843
+ * @todo [since v0.0.21] deprecate use of `obj`-param as array
844
+ */
845
+ setInfo(obj) {
846
+ if (!isObject(obj)) return;
847
+ let name = '';
848
+ let version = '';
849
+ let schema = '';
850
+ let doctype = '';
851
+ if (isArray(obj)) {
852
+ // // TODO: [!] deprecate
853
+ [ name, version, schema, doctype ] = obj;
854
+ } else {
855
+ if (typeof obj.name === 'string') {
856
+ ({ name, version, schema, doctype } = obj);
857
+ } else {
858
+ // // TODO: [?] deprecate
859
+ name = _getXmlChildElementParam(obj, 'name');
860
+ version = _getXmlChildElementParam(obj, 'version');
861
+ schema = _getXmlChildElementParam(obj, XEPG_DOCSCH_ETAG_NAME);
862
+ doctype = _getXmlChildElementParam(obj, XEPG_DOCTYP_ETAG_NAME);
863
+ };
864
+ };
865
+ name = typeof name === 'string' ? name.trim() : '';
866
+ version = typeof version === 'string' ? version.trim() : '';
867
+ schema = typeof schema === 'string' ? schema.trim() : '';
868
+ doctype = typeof doctype === 'string' ? doctype.trim() : '';
869
+ if (name === '') version = '';
870
+ this.setName(name);
871
+ this.version = version;
872
+ this.schema = schema;
873
+ this.doctype = doctype;
874
+ }
875
+
876
+ /**
877
+ * @param {(xepgProvInfoDesc|string[])} opt - options
878
+ * @returns {void}
879
+ * @description Sets an initial instance state
880
+ */
881
+ init(opt) {
882
+ let prov_opt = { ...defXEpgDocOptions.defProviderParam };
883
+ let name = '';
884
+ let version = '';
885
+ let schema = '';
886
+ let doctype = '';
887
+ const _options = isObject(opt) ? opt : {};
888
+ if (isArray(_options)) {
889
+ [ name, version, schema, doctype ] = _options;
890
+ } else {
891
+ ({ name, version, schema, doctype } = _options);
892
+ };
893
+ name = readAsString(name, { defValue: prov_opt.name, useTrim: true });
894
+ version = readAsString(version, { defValue: prov_opt.version, useTrim: true });
895
+ doctype = readAsString(doctype, { defValue: prov_opt.doctype, useTrim: true });
896
+ schema = readAsString(schema, { defValue: prov_opt.schema, useTrim: true });
897
+ this.name = name;
898
+ this.version = version;
899
+ this.schema = schema;
900
+ this.doctype = doctype;
901
+ }
902
+
903
+ /**
904
+ * @since v0.0.20
905
+ * @returns {string}
906
+ * @description Returns an instance content as a string in an XML-format.
907
+ */
908
+ saveToXMLString() {
909
+ const options = this.#_parseOptions.js2xml;
910
+ options.ignoreDocType = true;
911
+ options.ignoreDeclaration = true;
912
+ const content = { [`${XEPG_PRVINFO_ETAG_NAME}`]: this.#_host };
913
+ let result = '';
914
+ try {
915
+ result = xmlParser.js2xml(content, options);
916
+ } catch (err) {
917
+ //console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
918
+ result = '';
919
+ //throw err;
920
+ };
921
+ return result;
922
+ }
923
+
924
+ };
925
+
926
+ /**
927
+ * @typedef {Object} xepgChnInfoDesc
928
+ * @property {string} chnid - channel ID
929
+ * @property {string} chname - channel name
930
+ * @property {string} [chngid] - channel 'Group ID'
931
+ * @property {string} [srcurl] - EPG-source URL
932
+ * @description A channel info descriptor
933
+ */
934
+
935
+ /**
936
+ * @since 0.0.22
937
+ * @classdesc This class implements an interface of a channel element
938
+ */
939
+ class TXEpgChannelContainer {
940
+ /** @type {object} */
941
+ #_host;// = null;
942
+ /** @type {OPT_epgelsett_bs} */
943
+ #_options;// = null;
944
+ /** @type {TXmlContentParseOptions} */
945
+ #_parseOptions;// = null;
946
+ /** @type {string} */
947
+ #_xepgSchema;// = null;
948
+
949
+ /**
950
+ * @param {object} obj - host object
951
+ * @param {OPT_epgelsett_bs} [opt] - options
952
+ * @description Creates an instance of the channel element
953
+ */
954
+ constructor(obj, opt) {
955
+ // load content
956
+ const _host = isPlainObject(obj) ? obj : {};
957
+ // load options
958
+ /** @type {OPT_epgelsett_bs} */
959
+ const _options = isPlainObject(opt) ? opt : {};
960
+ let {
961
+ parseOptions,
962
+ } = _options;
963
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
964
+ parseOptions = new TXmlContentParseOptions(parseOptions);
965
+ _options.parseOptions = parseOptions;
966
+ };
967
+ // set document schema version
968
+ this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
969
+ // save options
970
+ this.#_options = _options;
971
+ // save parser options
972
+ this.#_parseOptions = parseOptions;
973
+ // save content source
974
+ this.#_host = _host;
975
+ }
976
+
977
+ /**
978
+ * Contains a channel ID
979
+ * @type {string}
980
+ * @readonly
981
+ */
982
+ get id() {
983
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNID_ETAG_NAME).trim();
984
+ }
985
+
986
+ /**
987
+ * Contains a channel name
988
+ * @type {string}
989
+ */
990
+ get name() {
991
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNNAME_ETAG_NAME).trim();
992
+ }
993
+
994
+ set name(value) {
995
+ if (typeof value === 'string' && this.id !== '') {
996
+ const item = insertXObjElement(
997
+ this.#_host,
998
+ XEPG_CHNNAME_ETAG_NAME,
999
+ { force: true },
1000
+ );
1001
+ if (item) {
1002
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1003
+ };
1004
+ };
1005
+ }
1006
+
1007
+ /**
1008
+ * Contains a channel Group ID
1009
+ * @type {string}
1010
+ */
1011
+ get gid() {
1012
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNGID_ETAG_NAME).trim();
1013
+ }
1014
+
1015
+ set gid(value) {
1016
+ if (typeof value === 'string' && this.id !== '') {
1017
+ const item = insertXObjElement(
1018
+ this.#_host,
1019
+ XEPG_CHNGID_ETAG_NAME,
1020
+ { force: true },
1021
+ );
1022
+ if (item) {
1023
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1024
+ };
1025
+ };
1026
+ }
1027
+
1028
+ /**
1029
+ * Contains a channel source URL
1030
+ * @type {string}
1031
+ */
1032
+ get url() {
1033
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNURL_ETAG_NAME).trim();
1034
+ }
1035
+
1036
+ set url(value) {
1037
+ if (typeof value === 'string' && this.id !== '') {
1038
+ const item = insertXObjElement(
1039
+ this.#_host,
1040
+ XEPG_CHNURL_ETAG_NAME,
1041
+ { force: true },
1042
+ );
1043
+ if (item) {
1044
+ writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1045
+ };
1046
+ };
1047
+ }
1048
+
1049
+ /**
1050
+ * @param {string} value - channel ID
1051
+ * @returns {boolean}
1052
+ * @description Tries to set a channel ID
456
1053
  */
457
- setName(value) {
1054
+ setID(value) {
458
1055
  let isSucceed = false;
459
1056
  if (typeof value === 'string') {
460
- const name = value.trim();
461
- const item = insertXObjElement(this.#_host, 'name', { force: true });
462
- if (item) isSucceed = writeXObjParam(item, name);
1057
+ const chnid = value.trim();
1058
+ const item = insertXObjElement(
1059
+ this.#_host,
1060
+ XEPG_CHNID_ETAG_NAME,
1061
+ { force: true },
1062
+ );
1063
+ if (item) {
1064
+ isSucceed = writeXObjParam(item, chnid, defParseOptions.settings.textKey);
1065
+ };
463
1066
  };
464
1067
  return isSucceed;
465
1068
  }
466
1069
 
467
1070
  /**
468
- * @returns {xepgProvInfoDesc}
469
- * @description Returns a provider info item
1071
+ * @returns {xepgChnInfoDesc}
1072
+ * @description Returns a channel info
470
1073
  */
471
1074
  getInfo() {
1075
+ const {
1076
+ id: chnid,
1077
+ name: chname,
1078
+ gid: chngid,
1079
+ url: srcurl,
1080
+ } = this;
1081
+ /** @type {xepgChnInfoDesc} */
472
1082
  return {
473
- name: this.name,
474
- version: this.version,
475
- schema: this.schema,
476
- doctype: this.doctype,
1083
+ chnid,
1084
+ chname,
1085
+ chngid,
1086
+ srcurl,
477
1087
  };
478
1088
  }
479
1089
 
480
1090
  /**
481
- * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
1091
+ * @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
482
1092
  * @returns {void}
483
- * @description Sets a provider info
484
- * @todo [since v0.0.21] deprecate use of `obj`-param as array
1093
+ * @description Sets a channel info
485
1094
  */
486
1095
  setInfo(obj) {
487
- if (!isObject(obj)) return;
488
- let name = '';
489
- let version = '';
490
- let schema = '';
491
- let doctype = '';
492
- if (isArray(obj)) {
493
- // // TODO: [!] deprecate
494
- [ name, version, schema, doctype ] = obj;
495
- } else {
496
- if (typeof obj.name === 'string') {
497
- ({ name, version, schema, doctype } = obj);
1096
+ let chnid = '';
1097
+ let chname = '';
1098
+ let chngid = '';
1099
+ let srcurl = '';
1100
+ if (isObject(obj)) {
1101
+ ({ chnid } = obj);
1102
+ if (typeof chnid === 'string') {
1103
+ ({ chname, chngid, srcurl } = obj);
498
1104
  } else {
499
1105
  // // TODO: [?] deprecate
500
- name = _getXmlChildElementParam(obj, 'name');
501
- version = _getXmlChildElementParam(obj, 'version');
502
- schema = _getXmlChildElementParam(obj, XEPG_DOCSCH_ETAG_NAME);
503
- doctype = _getXmlChildElementParam(obj, XEPG_DOCTYP_ETAG_NAME);
1106
+ chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
1107
+ chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
1108
+ chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
1109
+ srcurl = _getXmlChildElementParam(obj, XEPG_CHNURL_ETAG_NAME).trim();
504
1110
  };
505
- };
506
- name = typeof name === 'string' ? name.trim() : '';
507
- version = typeof version === 'string' ? version.trim() : '';
508
- schema = typeof schema === 'string' ? schema.trim() : '';
509
- doctype = typeof doctype === 'string' ? doctype.trim() : '';
510
- if (name === '') version = '';
511
- this.setName(name);
512
- this.version = version;
513
- this.schema = schema;
514
- this.doctype = doctype;
515
- }
516
-
517
- /**
518
- * @param {(xepgProvInfoDesc|string[])} opt - options
519
- * @returns {void}
520
- * @description Sets an initial instance state
521
- */
522
- init(opt) {
523
- let prov_opt = { ...defXEpgDocOptions.defProviderParam };
524
- let name = '';
525
- let version = '';
526
- let schema = '';
527
- let doctype = '';
528
- const _options = isObject(opt) ? opt : {};
529
- if (isArray(_options)) {
530
- [ name, version, schema, doctype ] = _options;
1111
+ } else if (typeof obj === 'string') {
1112
+ chnid = obj;
531
1113
  } else {
532
- ({ name, version, schema, doctype } = _options);
1114
+ return;
533
1115
  };
534
- name = readAsString(name, { defValue: prov_opt.name, useTrim: true });
535
- version = readAsString(version, { defValue: prov_opt.version, useTrim: true });
536
- doctype = readAsString(doctype, { defValue: prov_opt.doctype, useTrim: true });
537
- schema = readAsString(schema, { defValue: prov_opt.schema, useTrim: true });
538
- this.name = name;
539
- this.version = version;
540
- this.schema = schema;
541
- this.doctype = doctype;
542
- }
543
-
544
- /**
545
- * @returns {string}
546
- * @since v0.0.20
547
- * @description Returns an instance content as a string in an XML-format.
548
- */
549
- saveToXMLString() {
550
- const options = this.#_parseOptions.js2xml;
551
- options.ignoreDocType = true;
552
- options.ignoreDeclaration = true;
553
- const content = { [`${XEPG_PRVINFO_ETAG_NAME}`]: this.#_host };
554
- let result = '';
555
- try {
556
- result = xmlParser.js2xml(content, options);
557
- } catch (err) {
558
- //console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
559
- result = '';
560
- //throw err;
1116
+ chnid = typeof chnid === 'string' ? chnid.trim() : '';
1117
+ if (chnid === '') {
1118
+ chname = '';
1119
+ chngid = '';
1120
+ srcurl = '';
1121
+ } else {
1122
+ chname = typeof chname === 'string' ? chname.trim() : '';
1123
+ chngid = typeof chngid === 'string' ? chngid.trim() : '';
1124
+ srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
561
1125
  };
562
- return result;
1126
+ let item = null;
1127
+ const _host = this.#_host;
1128
+ const text_key = defParseOptions.settings.textKey;
1129
+ item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
1130
+ if (item) writeXObjParam(item, chnid, text_key);
1131
+ item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
1132
+ if (item) writeXObjParam(item, chname, text_key);
1133
+ item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
1134
+ if (item) writeXObjParam(item, chngid, text_key);
1135
+ item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
1136
+ if (item) writeXObjParam(item, srcurl, text_key);
563
1137
  }
564
1138
 
565
- };
1139
+ }
566
1140
 
567
1141
  /**
568
- * @classdesc This class implements an instance of a DTS-provider element
1142
+ * @classdesc This class implements an interface of a DTS-provider element
569
1143
  */
570
1144
  class TXEpgDTSProvider {
571
- /** @property {object} */
1145
+ /** @type {object} */
572
1146
  #_content;// = null;
573
- /** @property {object} */
1147
+ /** @type {OPT_epgelsett_bs} */
574
1148
  #_options;// = null;
575
1149
 
576
1150
  /**
577
- * @param {object} obj
578
- * @param {object} [opt] - options
579
- * @param {object} [opt.parseOptions]
1151
+ * @param {object} obj - host object
1152
+ * @param {OPT_epgelsett_bs} [opt] - options
580
1153
  * @description Creates an instance of the DTS-provider element
581
1154
  */
582
1155
  constructor(obj, opt) {
583
1156
  // load content
584
1157
  const _content = isPlainObject(obj) ? obj : {};
585
1158
  // load options
1159
+ /** @type {OPT_epgelsett_bs} */
586
1160
  let _options = isPlainObject(opt) ? opt : {};
587
1161
  let {
588
1162
  parseOptions,
@@ -609,42 +1183,22 @@ class TXEpgDTSProvider {
609
1183
 
610
1184
  /**
611
1185
  * Contains a dtstype ID
612
- * @property {number}
1186
+ * @type {number}
613
1187
  */
614
1188
  get dtstype() {
615
1189
  const item = getXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
616
1190
  let result = 0; //-1; // // TODO: [?]
617
- if (isPlainObject(item)) {
618
- result = valueToIndex(_getXmlChildElementParam(item, 'value'));
619
- if (!chkDTSysID(result)) result = 0; //-1; // // TODO: [?]
620
- };
1191
+ if (isPlainObject(item)) result = _getDTSTypeValueForXObj(item);
621
1192
  return result;
622
1193
  }
623
1194
 
624
1195
  set dtstype(value) {
625
- let { index, name } = getDTSysDescr(value);
626
- if (index !== -1) {
627
- const item = insertXObjElement(
628
- this.#_content,
629
- XEPG_DTSINFO_ETAG_NAME,
630
- { force: true },
631
- );
632
- if (item) {
633
- let curItem = insertXObjElement(item, 'value', { force: true });
634
- if (
635
- curItem
636
- && writeXObjParam(curItem, index)
637
- && (curItem = insertXObjElement(item, 'name', { force: true }))
638
- ) {
639
- writeXObjParam(curItem, name);
640
- };
641
- };
642
- };
1196
+ return this.setType(value);
643
1197
  }
644
1198
 
645
1199
  /**
646
1200
  * Contains a TZ-offset
647
- * @property {number}
1201
+ * @type {number}
648
1202
  */
649
1203
  get curDocTZ() {
650
1204
  const tz = convTZStringToValue(
@@ -661,44 +1215,66 @@ class TXEpgDTSProvider {
661
1215
  XEPG_DOCTZ_ETAG_NAME,
662
1216
  { force: true },
663
1217
  );
664
- if (item) writeXObjParam(item, _value);
1218
+ if (item) {
1219
+ writeXObjParam(item, _value, defParseOptions.settings.textKey);
1220
+ };
665
1221
  };
666
1222
  }
667
1223
 
668
- };
1224
+ /**
1225
+ * @since 0.0.22
1226
+ * @property {(number|string)} value - dtstype ID
1227
+ * @returns {boolean}
1228
+ * @description Tries to set a `DTS`-type
1229
+ */
1230
+ setType(value) {
1231
+ let { index, name } = getDTSysDescr(value);
1232
+ let isSucceed = false;
1233
+ if (index !== -1) {
1234
+ const item = insertXObjElement(
1235
+ this.#_content,
1236
+ XEPG_DTSINFO_ETAG_NAME,
1237
+ { force: true },
1238
+ );
1239
+ if (item) {
1240
+ let curItem = insertXObjElement(item, 'value', { force: true });
1241
+ if (
1242
+ curItem
1243
+ && writeXObjParam(curItem, index, defParseOptions.settings.textKey)
1244
+ && (curItem = insertXObjElement(item, 'name', { force: true }))
1245
+ ) {
1246
+ isSucceed = writeXObjParam(curItem, name, defParseOptions.settings.textKey);
1247
+ };
1248
+ };
1249
+ };
1250
+ return isSucceed;
1251
+ }
669
1252
 
670
- /**
671
- * @typedef {Object} xepgChnInfoDesc
672
- * @property {string} chnid - channel ID
673
- * @property {string} chname - channel name
674
- * @property {string} [chngid] - channel 'Group ID'
675
- * @property {string} [srcurl] - EPG-source URL
676
- * @description A channel info descriptor
677
- */
1253
+ };
678
1254
 
679
1255
  /**
680
- * @classdesc This class implements an instance of a EPG-header element
1256
+ * @classdesc This class implements an interface of a EPG-header element
681
1257
  */
682
1258
  class TXEpgHeaderContainer {
683
- /** @property {Object} */
1259
+ /** @type {Object} */
684
1260
  #_host;// = null;
685
- /** @property {Object} */
1261
+ /** @type {OPT_epgelsett_bs} */
686
1262
  #_options;// = null;
687
- /** @property {TXmlContentParseOptions} */
1263
+ /** @type {TXmlContentParseOptions} */
688
1264
  #_parseOptions;// = null;
689
- /** @property {TXEpgDTSProvider} */
1265
+ /** @type {TXEpgDTSProvider} */
690
1266
  #_dtsProv;// = null;
691
1267
 
692
1268
  /**
693
- * @param {object} obj
694
- * @param {object} [opt] - options
695
- * @param {object} [opt.parseOptions]
1269
+ * @param {object} obj - host element
1270
+ * @param {OPT_epgelsett_bs} [opt] - options
696
1271
  * @description Creates an instance of the EPG-header element
697
1272
  */
698
1273
  constructor(obj, opt) {
699
1274
  // load content
700
1275
  const _host = isPlainObject(obj) ? obj : {};
701
1276
  // load options
1277
+ /** @type {OPT_epgelsett_bs} */
702
1278
  const _options = isPlainObject(opt) ? opt : {};
703
1279
  let {
704
1280
  parseOptions,
@@ -719,7 +1295,7 @@ class TXEpgHeaderContainer {
719
1295
 
720
1296
  /**
721
1297
  * Returns a `TXEpgDTSProvider` instance
722
- * @property {TXEpgDTSProvider}
1298
+ * @type {TXEpgDTSProvider}
723
1299
  * @readonly
724
1300
  */
725
1301
  get dts() {
@@ -728,7 +1304,7 @@ class TXEpgHeaderContainer {
728
1304
 
729
1305
  /**
730
1306
  * Contains a dtstype ID
731
- * @property {number}
1307
+ * @type {number}
732
1308
  * @todo [since v0.0.22] becomes readonly
733
1309
  */
734
1310
  get dtstype() {
@@ -741,7 +1317,7 @@ class TXEpgHeaderContainer {
741
1317
 
742
1318
  /**
743
1319
  * Contains a TZ-offset
744
- * @property {number}
1320
+ * @type {number}
745
1321
  * @todo [since v0.0.22] becomes readonly
746
1322
  */
747
1323
  get curDocTZ() {
@@ -775,11 +1351,22 @@ class TXEpgHeaderContainer {
775
1351
  }
776
1352
 
777
1353
  /**
778
- * @property {?TXEpgProviderContainer}
1354
+ * Returns a `TXEpgProviderContainer` instance
1355
+ * @type {?TXEpgProviderContainer}
779
1356
  * @readonly
780
- * @description Returns a `TXEpgProviderContainer` instance
1357
+ * @deprecated
781
1358
  */
782
1359
  get Provider() {
1360
+ return this.provider;
1361
+ }
1362
+
1363
+ /**
1364
+ * Returns a `TXEpgProviderContainer` instance
1365
+ * @since 0.0.22
1366
+ * @type {?TXEpgProviderContainer}
1367
+ * @readonly
1368
+ */
1369
+ get provider() {
783
1370
  const docProv = this.#_getProv();
784
1371
  return (
785
1372
  docProv
@@ -788,6 +1375,16 @@ class TXEpgHeaderContainer {
788
1375
  );
789
1376
  }
790
1377
 
1378
+ /**
1379
+ * Returns a `TXEpgChannelContainer` instance
1380
+ * @since 0.0.22
1381
+ * @type {?TXEpgChannelContainer}
1382
+ * @readonly
1383
+ */
1384
+ get channel() {
1385
+ return new TXEpgChannelContainer(this.#_host, this.#_options);
1386
+ }
1387
+
791
1388
  /**
792
1389
  * @returns {number}
793
1390
  * @description Returns a document creation date as a timestamp
@@ -812,7 +1409,9 @@ class TXEpgHeaderContainer {
812
1409
  XEPG_DOCDTO_ETAG_NAME,
813
1410
  { force: true },
814
1411
  );
815
- if (item) writeXObjParam(item, dt_str);
1412
+ if (item) {
1413
+ writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
1414
+ };
816
1415
  }
817
1416
 
818
1417
  /**
@@ -841,7 +1440,9 @@ class TXEpgHeaderContainer {
841
1440
  XEPG_DOCDTE_ETAG_NAME,
842
1441
  { force: true },
843
1442
  );
844
- if (item) writeXObjParam(item, dt_str);
1443
+ if (item) {
1444
+ writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
1445
+ };
845
1446
  }
846
1447
 
847
1448
  /**
@@ -849,67 +1450,25 @@ class TXEpgHeaderContainer {
849
1450
  * @description Returns a channel info
850
1451
  */
851
1452
  getChannelInfo() {
852
- const _host = this.#_host;
853
- /** @type {xepgChnInfoDesc} */
854
- let item = {
855
- chnid: _getXmlChildElementParam(_host, XEPG_CHNID_ETAG_NAME).trim(),
856
- chname: _getXmlChildElementParam(_host, XEPG_CHNNAME_ETAG_NAME).trim(),
857
- chngid: _getXmlChildElementParam(_host, XEPG_CHNGID_ETAG_NAME).trim(),
858
- srcurl: _getXmlChildElementParam(_host, XEPG_CHNURL_ETAG_NAME).trim(),
859
- };
860
- return item;
1453
+ return this.channel.getInfo();
861
1454
  }
862
1455
 
863
1456
  /**
864
1457
  * @param {xepgChnInfoDesc} obj - channel info descriptor
865
1458
  * @returns {void}
866
1459
  * @description Sets a channel info
1460
+ * @deprecated
867
1461
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
1462
+ * @todo [since v0.0.22] deprecated
868
1463
  */
869
1464
  setChannelInfo(obj) {
870
- let chnid = '';
871
- let chname = '';
872
- let chngid = '';
873
- let srcurl = '';
1465
+ let _obj = obj;
874
1466
  if (isArray(obj)) {
875
1467
  // // TODO: [!] deprecate
876
- [ chnid, chname, chngid, srcurl ] = obj;
877
- } else if (isObject(obj)) {
878
- ({ chnid } = obj);
879
- if (typeof chnid === 'string') {
880
- ({ chname, chngid, srcurl } = obj);
881
- } else {
882
- // // TODO: [?] deprecate
883
- chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
884
- chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
885
- chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
886
- srcurl = _getXmlChildElementParam(obj, XEPG_CHNURL_ETAG_NAME).trim();
887
- };
888
- } else if (typeof obj === 'string') {
889
- chnid = obj;
890
- } else {
891
- return;
892
- };
893
- chnid = typeof chnid === 'string' ? chnid.trim() : '';
894
- if (chnid === '') {
895
- chname = '';
896
- chngid = '';
897
- srcurl = '';
898
- } else {
899
- chname = typeof chname === 'string' ? chname.trim() : '';
900
- chngid = typeof chngid === 'string' ? chngid.trim() : '';
901
- srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
1468
+ const [ chnid, chname, chngid, srcurl ] = _obj;
1469
+ _obj = { chnid, chname, chngid, srcurl };
902
1470
  };
903
- let item = null;
904
- const _host = this.#_host;
905
- item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
906
- if (item) writeXObjParam(item, chnid);
907
- item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
908
- if (item) writeXObjParam(item, chname);
909
- item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
910
- if (item) writeXObjParam(item, chngid);
911
- item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
912
- if (item) writeXObjParam(item, srcurl);
1471
+ return this.channel.setInfo(_obj);
913
1472
  }
914
1473
 
915
1474
  /**
@@ -917,7 +1476,7 @@ class TXEpgHeaderContainer {
917
1476
  * @description Returns a provider info
918
1477
  */
919
1478
  getProviderInfo(){
920
- const docProv = this.Provider;
1479
+ const docProv = this.provider;
921
1480
  return docProv ? docProv.getInfo() : null;
922
1481
  }
923
1482
 
@@ -928,18 +1487,18 @@ class TXEpgHeaderContainer {
928
1487
  */
929
1488
  setProviderInfo(obj){
930
1489
  if (isArray(obj) || isObject(obj)) {
931
- let docProv = this.Provider;
1490
+ let docProv = this.provider;
932
1491
  if (!docProv) {
933
1492
  docProv = this.#_initProv();
934
- if (docProv) docProv = this.Provider;
1493
+ if (docProv) docProv = this.provider;
935
1494
  };
936
1495
  if (docProv) docProv.setInfo(obj);
937
1496
  };
938
1497
  }
939
1498
 
940
1499
  /**
941
- * @returns {string}
942
1500
  * @since v0.0.20
1501
+ * @returns {string}
943
1502
  * @description Returns an instance content as a string in an XML-format.
944
1503
  */
945
1504
  saveToXMLString() {
@@ -965,32 +1524,37 @@ class TXEpgHeaderContainer {
965
1524
  * @property {boolean} isERR - flag
966
1525
  * @property {number} [errCode] - error code
967
1526
  * @property {string} errEvent - event ID
968
- * @property {string} errMsg - event message
969
- * @property {string} source - path to file
970
- * @property {any} content - file content
1527
+ * @property {string} [errMsg] - event message
1528
+ * @property {string} [source] - path to file
1529
+ * @property {any} [content] - file content
971
1530
  * @description A fs ops description.
972
1531
  */
973
1532
 
1533
+ /**
1534
+ * @typedef {Object} OPT_epgcpsett
1535
+ * @property {TXmlContentParseOptions} [parseOptions] - parser options
1536
+ * @property {boolean} [autoBindRoot] - <*deprecated*>
1537
+ * @description An options set for `TXEpgContentProvider`-class
1538
+
974
1539
  /**
975
1540
  * @classdesc This class implements an interface of the container
976
1541
  * that manages a content of a XEPG-document
977
1542
  */
978
1543
  class TXEpgContentProvider {
979
- /** @property {Object} */
1544
+ /** @type {Object} */
980
1545
  #_content;// = null;
981
- /** @property {Object} */
1546
+ /** @type {OPT_epgcpsett} */
982
1547
  #_options;// = null;
983
- /** @property {?TXmlContentParseOptions} */
1548
+ /** @type {TXmlContentParseOptions} */
984
1549
  #_parseOptions;// = null;
985
1550
 
986
1551
  /**
987
- * @param {object} [opt] - options
988
- * @param {object} [opt.parseOptions]
989
- * @param {boolean} [opt.autoBindRoot] - <*reserved*> ([?] - deprecate)
1552
+ * @param {OPT_epgcpsett} [opt] - options
990
1553
  * @description Creates an instance of the XEPG-content provider
991
1554
  */
992
1555
  constructor(opt) {
993
1556
  // load options
1557
+ /** @type {OPT_epgcpsett} */
994
1558
  const _options = isPlainObject(opt) ? opt : {};
995
1559
  let {
996
1560
  parseOptions,
@@ -1030,7 +1594,12 @@ class TXEpgContentProvider {
1030
1594
  if (!docRoot) {
1031
1595
  docRoot = insertXObjElement(_content, XEPG_ROOT_ETAG_NAME);
1032
1596
  if (docRoot) {
1033
- writeXObjAttr(docRoot, `xmlns:${XEPG_DEF_NS_NAME}`, XEPG_DEF_NS_PATH);
1597
+ writeXObjAttr(
1598
+ docRoot,
1599
+ `xmlns:${XEPG_DEF_NS_NAME}`,
1600
+ XEPG_DEF_NS_PATH,
1601
+ defParseOptions.settings.attributesKey,
1602
+ );
1034
1603
  };
1035
1604
  };
1036
1605
  return isPlainObject(docRoot) ? docRoot : null;
@@ -1096,8 +1665,9 @@ class TXEpgContentProvider {
1096
1665
 
1097
1666
  /**
1098
1667
  * Returns a `TXEpgHeaderContainer` instance
1099
- * @property {?TXEpgHeaderContainer}
1668
+ * @type {?TXEpgHeaderContainer}
1100
1669
  * @readonly
1670
+ * @deprecated
1101
1671
  */
1102
1672
  get Header() {
1103
1673
  const docHdr = this.#_getHdr();
@@ -1108,23 +1678,50 @@ class TXEpgContentProvider {
1108
1678
  );
1109
1679
  }
1110
1680
 
1681
+ /**
1682
+ * Returns a `TXEpgHeaderContainer` instance
1683
+ * @since 0.0.22
1684
+ * @type {?TXEpgHeaderContainer}
1685
+ * @readonly
1686
+ */
1687
+ get header() {
1688
+ const docHdr = this.#_getHdr();
1689
+ return (
1690
+ docHdr
1691
+ ? new TXEpgHeaderContainer(docHdr, this.#_options)
1692
+ : null
1693
+ );
1694
+ }
1695
+
1111
1696
  /**
1112
1697
  * Returns a `TXEpgProviderContainer` instance
1113
- * @property {?TXEpgProviderContainer}
1698
+ * @type {?TXEpgProviderContainer}
1114
1699
  * @readonly
1700
+ * @deprecated
1115
1701
  */
1116
1702
  get Provider() {
1117
- const docHdr = this.Header;
1118
- return docHdr ? docHdr.Provider : null;
1703
+ const docHdr = this.header;
1704
+ return docHdr ? docHdr.provider : null;
1705
+ }
1706
+
1707
+ /**
1708
+ * Returns a `TXEpgProviderContainer` instance
1709
+ * @since 0.0.22
1710
+ * @type {?TXEpgProviderContainer}
1711
+ * @readonly
1712
+ */
1713
+ get provider() {
1714
+ const docHdr = this.header;
1715
+ return docHdr ? docHdr.provider : null;
1119
1716
  }
1120
1717
 
1121
1718
  /**
1122
1719
  * Returns a `TXEpgDTSProvider` instance
1123
- * @property {?TXEpgDTSProvider}
1720
+ * @type {?TXEpgDTSProvider}
1124
1721
  * @readonly
1125
1722
  */
1126
1723
  get dts() {
1127
- const docHdr = this.Header;
1724
+ const docHdr = this.header;
1128
1725
  return docHdr ? docHdr.dts : null;
1129
1726
  }
1130
1727
 
@@ -1136,7 +1733,7 @@ class TXEpgContentProvider {
1136
1733
 
1137
1734
  /**
1138
1735
  * Returns a `TXEpgSchedulesList` instance
1139
- * @property {TXEpgSchedulesList}
1736
+ * @type {TXEpgSchedulesList}
1140
1737
  * @readonly
1141
1738
  */
1142
1739
  get SchedulesList() {
@@ -1181,7 +1778,7 @@ class TXEpgContentProvider {
1181
1778
  docHdr,
1182
1779
  XEPG_PRVINFO_ETAG_NAME,
1183
1780
  );
1184
- if (docProv) this.Provider.init();
1781
+ if (docProv) this.provider.init();
1185
1782
  // initiate document body element
1186
1783
  let docBody = this.#_getBody();
1187
1784
  if (!docBody) docBody = this.#_initBody();
@@ -1279,10 +1876,10 @@ class TXEpgContentProvider {
1279
1876
  }
1280
1877
 
1281
1878
  /**
1879
+ * @since 0.0.18
1282
1880
  * @param {string} xmlString - a document content in XML-format
1283
1881
  * @returns {boolean}
1284
1882
  * @throws {Error}
1285
- * @since 0.0.18
1286
1883
  * @description Loads a document content from a string.
1287
1884
  */
1288
1885
  loadFromXMLString(xmlString) {
@@ -1332,7 +1929,7 @@ class TXEpgContentProvider {
1332
1929
  loadFromFile(source) {
1333
1930
  /**/// main part that return promise as a result
1334
1931
  return new Promise((resolve, reject) => {
1335
- loadFile(source).then(data => {
1932
+ loadFromFile(source).then(data => {
1336
1933
  if (!data.isERR) {
1337
1934
  if (data.content !== '') {
1338
1935
  if (this.loadFromXMLString(data.content)) {
@@ -1363,7 +1960,7 @@ class TXEpgContentProvider {
1363
1960
  * @description Loads a document content from a file.
1364
1961
  */
1365
1962
  loadFromFileSync(source) {
1366
- const data = loadFileSync(source);
1963
+ const data = loadFromFileSync(source);
1367
1964
  if (!data.isERR) {
1368
1965
  if (data.content !== '') {
1369
1966
  if (this.loadFromXMLString(data.content)) {
@@ -1393,16 +1990,22 @@ class TXEpgContentProvider {
1393
1990
 
1394
1991
  // === module exports block ===
1395
1992
 
1396
- exports.TXEpgDTSProvider = TXEpgDTSProvider;
1397
- exports.TXEpgSchedulesList = TXEpgSchedulesList;
1398
- exports.TXEpgProviderContainer = TXEpgProviderContainer;
1399
- exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
1400
- exports.TXEpgContentProvider = TXEpgContentProvider;
1993
+ module.exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
1994
+ module.exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
1995
+ module.exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
1996
+ module.exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
1997
+
1998
+ module.exports.readAsTagName = readAsTagName;
1999
+ module.exports.readAsAttrName = readAsAttrName;
2000
+ module.exports.valueToElementID = valueToElementID;
1401
2001
 
1402
- exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
1403
- exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
1404
- exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
1405
- exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
2002
+ module.exports.TXEpgDTSProvider = TXEpgDTSProvider;
2003
+ module.exports.TXEpgScheduleItem = TXEpgScheduleItem;
2004
+ module.exports.TXEpgSchedulesList = TXEpgSchedulesList;
2005
+ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
2006
+ module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
2007
+ module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
2008
+ module.exports.TXEpgContentProvider = TXEpgContentProvider;
1406
2009
 
1407
2010
  /** @deprecated */
1408
- exports.TXepgDTSProvider = TXEpgDTSProvider;
2011
+ module.exports.TXepgDTSProvider = TXEpgDTSProvider;