@ygracs/xepg-lib-js 0.0.20 → 0.0.22

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,9 +1,7 @@
1
- // [v0.1.077-20241028]
1
+ // [v0.2.098-20250306]
2
2
 
3
3
  // === module init block ===
4
4
 
5
- const fs = require('fs');
6
- const fse = require('fs').promises;
7
5
  const xmlParser = require('@ygracs/xml-js6');
8
6
 
9
7
  const {
@@ -15,15 +13,15 @@ const {
15
13
 
16
14
  const {
17
15
  convValueToTZString, convTZStringToValue,
16
+ tryDTValue,
18
17
  } = require('@ygracs/dtf-lib-js');
19
18
 
20
19
  const {
21
- chkDTSysID, getDTSysName, getDTSysDescr,
20
+ chkDTSysID, getDTSysDescr,
22
21
  convStringToDTValue, convDTValueToString,
23
22
  } = require('./dts-helper.js');
24
23
 
25
24
  const {
26
- checkFsError,
27
25
  loadFileSync, loadFile,
28
26
  saveToFileSync, saveToFile,
29
27
  } = require('./file-helper.js');
@@ -31,8 +29,10 @@ const {
31
29
  const xObj = require('@ygracs/xobj-lib-js');
32
30
 
33
31
  const TXmlContentParseOptions = xObj.TXmlContentParseOptions;
34
- const insertXObjElement = xObj.insertXObjElement;
35
- const getXObjElement = xObj.getXObjElement;
32
+ const {
33
+ getXObjElement,
34
+ insertXObjElement,
35
+ } = xObj;
36
36
 
37
37
  // === module extra block (helper functions) ===
38
38
 
@@ -58,18 +58,36 @@ function writeXObjAttr(obj, name, value) {
58
58
  * === xObj-function wrappers (end) ===
59
59
  */
60
60
 
61
- function _getXmlChildElementParam(obj, elem){
61
+ /**
62
+ * @param {object} obj
63
+ * @param {string} elem
64
+ * @returns {string}
65
+ * @inner
66
+ */
67
+ function _getXmlChildElementParam(obj, elem) {
62
68
  const child = obj ? getXObjElement(obj, elem) : null;
63
69
  return child ? readXObjParam(child) : '';
64
70
  };
65
71
 
66
- function writeXEpgDocDeclSection(obj, opt){
72
+ /**
73
+ * @param {object} obj
74
+ * @returns {number}
75
+ * @inner
76
+ */
77
+ function _getDTSTypeValueForXObj(obj) {
78
+ const result = valueToIndex(
79
+ _getXmlChildElementParam(obj, 'value')
80
+ );
81
+ return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
82
+ };
83
+
84
+ function writeXEpgDocDeclSection(obj, opt) {
67
85
  let xml_ver = XEPG_XML_DOC_VERSION;
68
86
  let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
69
87
  let key_name = defParseOptions.settings.declarationKey;
70
88
  if (isPlainObject(opt)) {
71
- xml_ver = readAsString(opt.version, xml_ver);
72
- doc_def_enc = readAsString(opt.encoding, doc_def_enc);
89
+ xml_ver = readAsString(opt.version, { defValue: xml_ver });
90
+ doc_def_enc = readAsString(opt.encoding, { defValue: doc_def_enc });
73
91
  };
74
92
  if (isPlainObject(obj) && isNotEmptyString(key_name)) {
75
93
  obj[key_name] = {};
@@ -84,6 +102,11 @@ function writeXEpgDocDeclSection(obj, opt){
84
102
  * (* constant definitions *)
85
103
  */
86
104
 
105
+ /**
106
+ * A list of a document schema version supported by a library
107
+ */
108
+ const ALLOWED_XEPG_DOCUMENT_SCHEMA = [ '0.2' ];
109
+
87
110
  const XEPG_ROOT_ETAG_NAME = 'epgdoc';
88
111
  const XEPG_DEF_NS_NAME = 'tvp';
89
112
  const XEPG_DEF_NS_PATH = 'urn:e-doc:epg-doc:xepg';
@@ -109,9 +132,9 @@ const XEPG_SCHEDDESC_ETAG_NAME = `${XEPG_DEF_NS_NAME}:desc`;
109
132
  const XEPG_XML_DOC_VERSION = '1.0';
110
133
  const XEPG_DEF_ENCODING_VALUE = 'UTF-8';
111
134
  const XEPG_DEF_DOCUMENT_TYPE = 'xepg';
112
- const XEPG_DEF_DOCUMENT_SCHEMA = '0.2';
135
+ const XEPG_DEF_DOCUMENT_SCHEMA = ALLOWED_XEPG_DOCUMENT_SCHEMA[0];
113
136
  const XEPG_DEF_PROVIDER_NAME = 'xepg-lib-js';
114
- const XEPG_DEF_PROVIDER_VER = '0.0.15';
137
+ const XEPG_DEF_PROVIDER_VER = '0.0.21';
115
138
 
116
139
  const defXEpgDocOptions = {
117
140
  xmlns_xepg_pref: XEPG_DEF_NS_NAME,
@@ -143,17 +166,275 @@ const defParseOptions = new TXmlContentParseOptions();
143
166
  */
144
167
 
145
168
  /**
146
- * @classdesc This class implements an instance of a EPG-schedules list
169
+ * @typedef {Object} xepgShedInfoDesc
170
+ * @property {number} time - a schedule start time
171
+ * @property {string} title - schedule title
172
+ * @property {string} [cat] - schedule category
173
+ * @property {number} [pcmark] - schedule rating
174
+ * @property {string} [descr] - schedule description
175
+ * @description A schedule info descriptor
176
+ */
177
+
178
+ /**
179
+ * @classdesc This class implements an interface of a EPG-schedule element
180
+ */
181
+ class TXEpgScheduleItem {
182
+ /** @property {object} */
183
+ #_host;// = null;
184
+ /** @property {object} */
185
+ #_options;// = null;
186
+ /** @property {TXmlContentParseOptions} */
187
+ #_parseOptions;// = null;
188
+ /** @property {?object} */
189
+ #_dts_src = null;
190
+ /** @property {?object} */
191
+ #_tz_src = null;
192
+
193
+ /**
194
+ * @param {object} obj - host object
195
+ * @param {object} [opt] - options
196
+ * @param {object} [opt.parseOptions]
197
+ * @param {?object} [opt.dts_src]
198
+ * @param {?object} [opt.tz_src]
199
+ * @description Creates an instance of the EPG-schedule element
200
+ */
201
+ constructor(obj, opt) {
202
+ // load content
203
+ const _host = isPlainObject(obj) ? obj : {};
204
+ // load options
205
+ const _options = isPlainObject(opt) ? opt : {};
206
+ let {
207
+ parseOptions,
208
+ dts_src, tz_src,
209
+ } = _options;
210
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
211
+ parseOptions = new TXmlContentParseOptions(parseOptions);
212
+ _options.parseOptions = parseOptions;
213
+ };
214
+ if (!isPlainObject(dts_src)) dts_src = null;
215
+ if (!isPlainObject(tz_src)) tz_src = null;
216
+ // save content source
217
+ this.#_host = _host;
218
+ // save options
219
+ this.#_options = _options;
220
+ // save parser options
221
+ this.#_parseOptions = parseOptions;
222
+ // save refs to a time source priveders
223
+ this.#_dts_src = dts_src;
224
+ this.#_tz_src = tz_src;
225
+ }
226
+
227
+ /**
228
+ * Contains a dtstype ID
229
+ * @property {number}
230
+ * @readonly
231
+ */
232
+ get dtstype() {
233
+ return _getDTSTypeValueForXObj(this.#_dts_src);
234
+ }
235
+
236
+ /**
237
+ * Contains a TZ-offset
238
+ * @property {number}
239
+ * @readonly
240
+ */
241
+ get curDocTZ() {
242
+ return (
243
+ this.#_tz_src
244
+ ? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
245
+ : 0
246
+ );
247
+ }
248
+
249
+ /**
250
+ * Contains a schedule start time as a timestamp
251
+ * @property {number}
252
+ * @readonly
253
+ */
254
+ get time() {
255
+ return convStringToDTValue(
256
+ _getXmlChildElementParam(this.#_host, XEPG_SCHEDTIME_ETAG_NAME).trim(),
257
+ this.dtstype, this.curDocTZ
258
+ );
259
+ }
260
+
261
+ /**
262
+ * Contains a schedule title
263
+ * @property {string}
264
+ * @readonly
265
+ */
266
+ get title() {
267
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDTITL_ETAG_NAME).trim();
268
+ }
269
+
270
+ /**
271
+ * Contains a schedule category
272
+ * @property {string}
273
+ * @readonly
274
+ */
275
+ get category() {
276
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDCAT_ETAG_NAME).trim();
277
+ }
278
+
279
+ /**
280
+ * Contains a schedule rating value (aka pcmark)
281
+ * @property {number}
282
+ * @readonly
283
+ */
284
+ get rating() {
285
+ return readAsNumberEx(
286
+ _getXmlChildElementParam(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME), 0
287
+ );
288
+ }
289
+
290
+ /**
291
+ * Contains a schedule description
292
+ * @property {string}
293
+ * @readonly
294
+ */
295
+ get descr() {
296
+ return _getXmlChildElementParam(this.#_host, XEPG_SCHEDDESC_ETAG_NAME);
297
+ }
298
+
299
+ /**
300
+ * @returns {xepgShedInfoDesc}
301
+ * @description Returns a schedule info item descriptor
302
+ */
303
+ getInfo() {
304
+ const {
305
+ time,
306
+ title,
307
+ category: cat,
308
+ rating: pcmark,
309
+ descr,
310
+ } = this;
311
+ return {
312
+ time,
313
+ title,
314
+ cat,
315
+ pcmark,
316
+ descr,
317
+ };
318
+ }
319
+
320
+ /**
321
+ * @param {(number|string|Date)} value - some time value
322
+ * @returns {boolean}
323
+ * @description Sets a schedule start time.
324
+ */
325
+ setTime(value) {
326
+ let { isSucceed, value: dtValue } = tryDTValue(value);
327
+ let result = false;
328
+ if (isSucceed) {
329
+ dtValue = convDTValueToString(dtValue, this.dtstype, this.curDocTZ);
330
+ if (dtValue !== '') {
331
+ const opt = { force: true };
332
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDTIME_ETAG_NAME, opt);
333
+ if (item) result = writeXObjParam(item, dtValue);
334
+ };
335
+ };
336
+ return result;
337
+ }
338
+
339
+ /**
340
+ * @param {string} value - some title
341
+ * @returns {boolean}
342
+ * @description Sets a schedule title.
343
+ */
344
+ setTitle(value) {
345
+ let result = false;
346
+ if (typeof value === 'string') {
347
+ const opt = { force: true };
348
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDTITL_ETAG_NAME, opt);
349
+ if (item) result = writeXObjParam(item, value.trim());
350
+ };
351
+ return result;
352
+ }
353
+
354
+ /**
355
+ * @param {string} value - some title
356
+ * @returns {boolean}
357
+ * @description Sets a schedule title.
358
+ */
359
+ setCategory(value) {
360
+ let result = false;
361
+ if (typeof value === 'string') {
362
+ const opt = { force: true };
363
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDCAT_ETAG_NAME, opt);
364
+ if (item) result = writeXObjParam(item, value.trim());
365
+ };
366
+ return result;
367
+ }
368
+
369
+ /**
370
+ * @param {(number|string)} value - some value
371
+ * @returns {boolean}
372
+ * @description Sets a schedule rating value.
373
+ */
374
+ setRating(value) {
375
+ const _value = valueToIndex(value);
376
+ let result = false;
377
+ if (_value !== -1) {
378
+ const opt = { force: true };
379
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME, opt);
380
+ if (item) result = writeXObjParam(item, _value);
381
+ };
382
+ return result;
383
+ }
384
+
385
+ /**
386
+ * @param {string} value - some text
387
+ * @returns {boolean}
388
+ * @description Sets a schedule description.
389
+ */
390
+ setDescr(value) {
391
+ let result = false;
392
+ if (typeof value === 'string') {
393
+ const opt = { force: true };
394
+ const item = insertXObjElement(this.#_host, XEPG_SCHEDDESC_ETAG_NAME, opt);
395
+ if (item) result = writeXObjParam(item, value.trim());
396
+ };
397
+ return result;
398
+ }
399
+
400
+ /**
401
+ * @returns {string}
402
+ * @description Returns an instance content as a string in an XML-format.
403
+ */
404
+ saveToXMLString() {
405
+ const options = this.#_parseOptions.js2xml;
406
+ options.ignoreDocType = true;
407
+ options.ignoreDeclaration = true;
408
+ const content = { [`${XEPG_SCHED_ETAG_NAME}`]: this.#_host };
409
+ let result = '';
410
+ try {
411
+ result = xmlParser.js2xml(content, options);
412
+ } catch (err) {
413
+ //console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
414
+ result = '';
415
+ //throw err;
416
+ };
417
+ return result;
418
+ }
419
+
420
+ };
421
+
422
+ /**
423
+ * @classdesc This class implements an interface of a EPG-schedules list
147
424
  */
148
425
  class TXEpgSchedulesList {
149
- #_content = null;
150
- #_options = null;
426
+ /** @property {object[]} */
427
+ #_content;// = null;
428
+ /** @property {object} */
429
+ #_options;// = null;
430
+ /** @property {?object} */
151
431
  #_dts_src = null;
432
+ /** @property {?object} */
152
433
  #_tz_src = null;
153
434
 
154
435
  /**
155
- * @param {any[]} obj
156
- * @param {object} [opt]
436
+ * @param {any[]} obj - list of an elements
437
+ * @param {object} [opt] - options
157
438
  * @param {?object} [opt.dts_src]
158
439
  * @param {?object} [opt.tz_src]
159
440
  * @description Creates an instance of the schedules list
@@ -174,46 +455,41 @@ class TXEpgSchedulesList {
174
455
  }
175
456
 
176
457
  /**
177
- * @param {(number|string)} value
178
- * @returns {void}
458
+ * @param {(number|string)} value - element index
459
+ * @returns {any}
179
460
  * @private
461
+ * @description Returns a raw schedule element
180
462
  */
181
- #_getItem = function(value){
463
+ #_getItem = function(value) {
182
464
  if (this.chkIndex(value)) {
183
465
  return this.#_content[Number(value)];
184
466
  };
185
467
  };
186
468
 
187
469
  /**
470
+ * Contains a quantity of a schedules
188
471
  * @property {number}
189
472
  * @readonly
190
- * @description Contains a quantity of a schedules
191
473
  */
192
- get schedQty(){
474
+ get schedQty() {
193
475
  return this.#_content.length;
194
476
  }
195
477
 
196
- // will deprecate
197
- //get SchedulesQty(){ return this.#_content.length; }
198
-
199
478
  /**
479
+ * Contains a dtstype ID
200
480
  * @property {number}
201
481
  * @readonly
202
- * @description Contains a dtstype ID
203
482
  */
204
- get dtstype(){
205
- let result = valueToIndex(
206
- _getXmlChildElementParam(this.#_dts_src, 'value')
207
- );
208
- return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
483
+ get dtstype() {
484
+ return _getDTSTypeValueForXObj(this.#_dts_src);
209
485
  }
210
486
 
211
487
  /**
488
+ * Contains a TZ-offset
212
489
  * @property {number}
213
490
  * @readonly
214
- * @description Contains a TZ-offset
215
491
  */
216
- get curDocTZ(){
492
+ get curDocTZ() {
217
493
  return (
218
494
  this.#_tz_src
219
495
  ? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
@@ -225,7 +501,7 @@ class TXEpgSchedulesList {
225
501
  * @returns {boolean}
226
502
  * @description Indicates whether an instance has none member
227
503
  */
228
- hasNoSchedules(){
504
+ hasNoSchedules() {
229
505
  return this.schedQty === 0;
230
506
  }
231
507
 
@@ -233,7 +509,7 @@ class TXEpgSchedulesList {
233
509
  * @returns {boolean}
234
510
  * @description Indicates whether an instance has any member
235
511
  */
236
- hasSchedules(){
512
+ hasSchedules() {
237
513
  return this.schedQty > 0;
238
514
  }
239
515
 
@@ -243,15 +519,17 @@ class TXEpgSchedulesList {
243
519
  * @deprecated
244
520
  * @description Checks whether a given value is a valid index
245
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
246
524
  */
247
525
  chkScheduleIndex(value) {
248
526
  return this.chkIndex(value);
249
527
  }
250
528
 
251
529
  /**
252
- * @param {(number|string)} value
530
+ * @param {(number|string)} value - index of some element
253
531
  * @returns {boolean}
254
- * @since 0.0.18
532
+ * @since 0.0.20
255
533
  * @description Checks whether a given value is a valid index
256
534
  * and it fits the index range of an instance
257
535
  */
@@ -261,44 +539,39 @@ class TXEpgSchedulesList {
261
539
  }
262
540
 
263
541
  /**
264
- * @param {(number|string)} index
265
- * @returns {object}
542
+ * @param {(number|string)} index - index of some element
543
+ * @returns {?TXEpgScheduleItem}
544
+ * @since 0.0.22
545
+ * @description Returns a schedule element addressed by a given index
546
+ */
547
+ schedule(index) {
548
+ const curObj = this.#_getItem(index);
549
+ let item = null;
550
+ if (isPlainObject(curObj)) {
551
+ item = new TXEpgScheduleItem(curObj, {
552
+ dts_src: this.#_dts_src,
553
+ tz_src: this.#_tz_src,
554
+ });
555
+ };
556
+ return item;
557
+ }
558
+
559
+ /**
560
+ * @param {(number|string)} index - index of some element
561
+ * @returns {?xepgShedInfoDesc}
266
562
  * @description Returns a schedule info item for instance element
267
563
  * addressed by a given index
268
564
  */
269
- getScheduleInfo(index){
270
- //console.log('TXEpgSchedulesList => getScheduleInfo() => was called...');
271
- const curObj = this.#_getItem(index);
272
- let tmpObj = {};
273
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+']');
274
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(curObj, null, 2));
275
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [time]');
276
- tmpObj.time = convStringToDTValue(
277
- _getXmlChildElementParam(curObj, XEPG_SCHEDTIME_ETAG_NAME).trim(),
278
- this.dtstype, this.curDocTZ
279
- );
280
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [title]');
281
- tmpObj.title = _getXmlChildElementParam(curObj, XEPG_SCHEDTITL_ETAG_NAME).trim();
282
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [category]');
283
- tmpObj.cat = _getXmlChildElementParam(curObj, XEPG_SCHEDCAT_ETAG_NAME).trim();
284
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [pcmark]');
285
- tmpObj.pcmark = readAsNumberEx(
286
- _getXmlChildElementParam(curObj, XEPG_SCHEDPMARK_ETAG_NAME), 0
287
- );
288
- //console.log('TXEpgSchedulesList => getScheduleInfo() => index:['+index+'] - [description]');
289
- tmpObj.descr = _getXmlChildElementParam(curObj, XEPG_SCHEDDESC_ETAG_NAME);
290
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(curObj, null, 2));
291
- //console.log('TXEpgSchedulesList => getScheduleInfo('+index+') => '+JSON.stringify(tmpObj, null, 2));
292
- // TODO: wrap tmpObj into container object
293
- //console.log('TXEpgSchedulesList => getScheduleInfo() => was left...');
294
- return tmpObj;
565
+ getScheduleInfo(index) {
566
+ const obj = this.schedule(index);
567
+ return obj ? obj.getInfo() : null;
295
568
  }
296
569
 
297
570
  /**
298
- * @returns {object[]}
571
+ * @returns {xepgShedInfoDesc[]}
299
572
  * @description Returns a schedule info for instance members
300
573
  */
301
- getAllSchedulesInfo(){
574
+ getAllSchedulesInfo() {
302
575
  let result = [];
303
576
  for (let i = 0; i < this.schedQty; i++) {
304
577
  let item = this.getScheduleInfo(i);
@@ -307,27 +580,39 @@ class TXEpgSchedulesList {
307
580
  return result;
308
581
  }
309
582
 
310
- asJSON(){
583
+ /**
584
+ * @protected
585
+ */
586
+ asJSON() {
311
587
  return JSON.stringify(this.#_content, null, 2);
312
588
  }
313
589
 
314
590
  };
315
591
 
316
592
  /**
317
- * @classdesc This class implements an instance of a EPG-provider element
593
+ * @typedef {Object} xepgProvInfoDesc
594
+ * @property {string} [name] - provider name
595
+ * @property {string} [version] - provider version
596
+ * @property {string} schema - document schema
597
+ * @property {string} doctype - document type
598
+ * @description A provider info descriptor
599
+ */
600
+
601
+ /**
602
+ * @classdesc This class implements an interface of a EPG-provider element
318
603
  */
319
604
  class TXEpgProviderContainer {
320
605
  /** @property {Object} */
321
606
  #_host;// = null;
322
607
  /** @property {Object} */
323
608
  #_options;// = null;
324
- /** @property {?TXmlContentParseOptions} */
609
+ /** @property {TXmlContentParseOptions} */
325
610
  #_parseOptions;// = null;
326
- /** @property {?TXepgDTSProvider} */
611
+ /** @property {?TXEpgDTSProvider} */
327
612
 
328
613
  /**
329
- * @param {object} obj
330
- * @param {object} [opt]
614
+ * @param {object} obj - host object
615
+ * @param {object} [opt] - options
331
616
  * @param {object} [opt.parseOptions]
332
617
  * @description Creates an instance of the EPG-provider element
333
618
  */
@@ -366,8 +651,8 @@ class TXEpgProviderContainer {
366
651
  }
367
652
 
368
653
  /**
654
+ * Contains a provider name
369
655
  * @property {string}
370
- * @description Contains a provider name
371
656
  */
372
657
  get name() {
373
658
  return _getXmlChildElementParam(this.#_host, 'name').trim();
@@ -378,8 +663,8 @@ class TXEpgProviderContainer {
378
663
  }
379
664
 
380
665
  /**
666
+ * Contains a version of a provider
381
667
  * @property {string}
382
- * @description Contains a version of a provider
383
668
  */
384
669
  get version() {
385
670
  return _getXmlChildElementParam(this.#_host, 'version').trim();
@@ -394,8 +679,8 @@ class TXEpgProviderContainer {
394
679
  }
395
680
 
396
681
  /**
682
+ * Contains a version of a document schema
397
683
  * @property {string}
398
- * @description Contains a version of a document schema
399
684
  */
400
685
  get schema() {
401
686
  return _getXmlChildElementParam(this.#_host, XEPG_DOCSCH_ETAG_NAME).trim();
@@ -410,8 +695,8 @@ class TXEpgProviderContainer {
410
695
  }
411
696
 
412
697
  /**
698
+ * Contains a document type
413
699
  * @property {string}
414
- * @description Contains a document type
415
700
  */
416
701
  get doctype() {
417
702
  return _getXmlChildElementParam(this.#_host, XEPG_DOCTYP_ETAG_NAME).trim();
@@ -440,15 +725,6 @@ class TXEpgProviderContainer {
440
725
  return isSucceed;
441
726
  }
442
727
 
443
- /**
444
- * @typedef {Object} xepgProvInfoDesc
445
- * @property {string} name - provider name
446
- * @property {string} version - provider version
447
- * @property {string} schema - document schema
448
- * @property {string} doctype - document type
449
- * @description Contains a provider description
450
- */
451
-
452
728
  /**
453
729
  * @returns {xepgProvInfoDesc}
454
730
  * @description Returns a provider info item
@@ -463,22 +739,25 @@ class TXEpgProviderContainer {
463
739
  }
464
740
 
465
741
  /**
466
- * @param {object} obj
742
+ * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
467
743
  * @returns {void}
468
744
  * @description Sets a provider info
745
+ * @todo [since v0.0.21] deprecate use of `obj`-param as array
469
746
  */
470
- setInfo(obj){
747
+ setInfo(obj) {
471
748
  if (!isObject(obj)) return;
472
749
  let name = '';
473
750
  let version = '';
474
751
  let schema = '';
475
752
  let doctype = '';
476
753
  if (isArray(obj)) {
754
+ // // TODO: [!] deprecate
477
755
  [ name, version, schema, doctype ] = obj;
478
756
  } else {
479
757
  if (typeof obj.name === 'string') {
480
758
  ({ name, version, schema, doctype } = obj);
481
759
  } else {
760
+ // // TODO: [?] deprecate
482
761
  name = _getXmlChildElementParam(obj, 'name');
483
762
  version = _getXmlChildElementParam(obj, 'version');
484
763
  schema = _getXmlChildElementParam(obj, XEPG_DOCSCH_ETAG_NAME);
@@ -497,11 +776,11 @@ class TXEpgProviderContainer {
497
776
  }
498
777
 
499
778
  /**
500
- * @param {object|string[]} opt
779
+ * @param {(xepgProvInfoDesc|string[])} opt - options
501
780
  * @returns {void}
502
781
  * @description Sets an initial instance state
503
782
  */
504
- init(opt){
783
+ init(opt) {
505
784
  let prov_opt = { ...defXEpgDocOptions.defProviderParam };
506
785
  let name = '';
507
786
  let version = '';
@@ -547,15 +826,224 @@ class TXEpgProviderContainer {
547
826
  };
548
827
 
549
828
  /**
550
- * @classdesc This class implements an instance of a DTS-provider element
829
+ * @typedef {Object} xepgChnInfoDesc
830
+ * @property {string} chnid - channel ID
831
+ * @property {string} chname - channel name
832
+ * @property {string} [chngid] - channel 'Group ID'
833
+ * @property {string} [srcurl] - EPG-source URL
834
+ * @description A channel info descriptor
551
835
  */
552
- class TXepgDTSProvider {
553
- #_content = null;
554
- #_options = null;
836
+
837
+ /**
838
+ * @classdesc This class implements an interface of a channel element
839
+ */
840
+ class TXEpgChannelContainer {
841
+ /** @property {object} */
842
+ #_host;// = null;
843
+ /** @property {object} */
844
+ #_options;// = null;
845
+ /** @property {TXmlContentParseOptions} */
846
+ #_parseOptions;// = null;
847
+ /** @property {string} */
848
+ #_xepgSchema;// = null;
555
849
 
556
850
  /**
557
- * @param {object} obj
558
- * @param {object} [opt]
851
+ * @param {object} obj - host object
852
+ * @param {object} [opt] - options
853
+ * @param {object} [opt.parseOptions]
854
+ * @description Creates an instance of the channel element
855
+ */
856
+ constructor(obj, opt) {
857
+ // load content
858
+ const _host = isPlainObject(obj) ? obj : {};
859
+ // load options
860
+ const _options = isPlainObject(opt) ? opt : {};
861
+ let {
862
+ parseOptions,
863
+ } = _options;
864
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
865
+ parseOptions = new TXmlContentParseOptions(parseOptions);
866
+ _options.parseOptions = parseOptions;
867
+ };
868
+ // set document schema version
869
+ this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
870
+ // save options
871
+ this.#_options = _options;
872
+ // save parser options
873
+ this.#_parseOptions = parseOptions;
874
+ // save content source
875
+ this.#_host = _host;
876
+ }
877
+
878
+ /**
879
+ * Contains a channel ID
880
+ * @returns {string}
881
+ * @readonly
882
+ */
883
+ get id() {
884
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNID_ETAG_NAME).trim();
885
+ }
886
+
887
+ /**
888
+ * Contains a channel name
889
+ * @returns {string}
890
+ */
891
+ get name() {
892
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNNAME_ETAG_NAME).trim();
893
+ }
894
+
895
+ set name(value) {
896
+ if (typeof value === 'string' && this.id !== '') {
897
+ const item = insertXObjElement(
898
+ this.#_host,
899
+ XEPG_CHNNAME_ETAG_NAME,
900
+ { force: true },
901
+ );
902
+ if (item) writeXObjParam(item, value.trim());
903
+ };
904
+ }
905
+
906
+ /**
907
+ * Contains a channel Group ID
908
+ * @returns {string}
909
+ */
910
+ get gid() {
911
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNGID_ETAG_NAME).trim();
912
+ }
913
+
914
+ set gid(value) {
915
+ if (typeof value === 'string' && this.id !== '') {
916
+ const item = insertXObjElement(
917
+ this.#_host,
918
+ XEPG_CHNGID_ETAG_NAME,
919
+ { force: true },
920
+ );
921
+ if (item) writeXObjParam(item, value.trim());
922
+ };
923
+ }
924
+
925
+ /**
926
+ * Contains a channel source URL
927
+ * @returns {string}
928
+ */
929
+ get url() {
930
+ return _getXmlChildElementParam(this.#_host, XEPG_CHNURL_ETAG_NAME).trim();
931
+ }
932
+
933
+ set url(value) {
934
+ if (typeof value === 'string' && this.id !== '') {
935
+ const item = insertXObjElement(
936
+ this.#_host,
937
+ XEPG_CHNURL_ETAG_NAME,
938
+ { force: true },
939
+ );
940
+ if (item) writeXObjParam(item, value.trim());
941
+ };
942
+ }
943
+
944
+ /**
945
+ * @param {string} value - channel ID
946
+ * @returns {boolean}
947
+ * @description Tries to set a channel ID
948
+ */
949
+ setID(value) {
950
+ let isSucceed = false;
951
+ if (typeof value === 'string') {
952
+ const chnid = value.trim();
953
+ const item = insertXObjElement(
954
+ this.#_host,
955
+ XEPG_CHNID_ETAG_NAME,
956
+ { force: true },
957
+ );
958
+ if (item) {
959
+ isSucceed = writeXObjParam(item, chnid);
960
+ };
961
+ };
962
+ return isSucceed;
963
+ }
964
+
965
+ /**
966
+ * @returns {xepgChnInfoDesc}
967
+ * @description Returns a channel info
968
+ */
969
+ getInfo() {
970
+ const {
971
+ id: chnid,
972
+ name: chname,
973
+ gid: chngid,
974
+ url: srcurl,
975
+ } = this;
976
+ /** @type {xepgChnInfoDesc} */
977
+ return {
978
+ chnid,
979
+ chname,
980
+ chngid,
981
+ srcurl,
982
+ };
983
+ }
984
+
985
+ /**
986
+ * @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
987
+ * @returns {void}
988
+ * @description Sets a channel info
989
+ */
990
+ setInfo(obj) {
991
+ let chnid = '';
992
+ let chname = '';
993
+ let chngid = '';
994
+ let srcurl = '';
995
+ if (isObject(obj)) {
996
+ ({ chnid } = obj);
997
+ if (typeof chnid === 'string') {
998
+ ({ chname, chngid, srcurl } = obj);
999
+ } else {
1000
+ // // TODO: [?] deprecate
1001
+ chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
1002
+ chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
1003
+ chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
1004
+ srcurl = _getXmlChildElementParam(obj, XEPG_CHNURL_ETAG_NAME).trim();
1005
+ };
1006
+ } else if (typeof obj === 'string') {
1007
+ chnid = obj;
1008
+ } else {
1009
+ return;
1010
+ };
1011
+ chnid = typeof chnid === 'string' ? chnid.trim() : '';
1012
+ if (chnid === '') {
1013
+ chname = '';
1014
+ chngid = '';
1015
+ srcurl = '';
1016
+ } else {
1017
+ chname = typeof chname === 'string' ? chname.trim() : '';
1018
+ chngid = typeof chngid === 'string' ? chngid.trim() : '';
1019
+ srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
1020
+ };
1021
+ let item = null;
1022
+ const _host = this.#_host;
1023
+ item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
1024
+ if (item) writeXObjParam(item, chnid);
1025
+ item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
1026
+ if (item) writeXObjParam(item, chname);
1027
+ item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
1028
+ if (item) writeXObjParam(item, chngid);
1029
+ item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
1030
+ if (item) writeXObjParam(item, srcurl);
1031
+ }
1032
+
1033
+ }
1034
+
1035
+ /**
1036
+ * @classdesc This class implements an interface of a DTS-provider element
1037
+ */
1038
+ class TXEpgDTSProvider {
1039
+ /** @property {object} */
1040
+ #_content;// = null;
1041
+ /** @property {object} */
1042
+ #_options;// = null;
1043
+
1044
+ /**
1045
+ * @param {object} obj - host object
1046
+ * @param {object} [opt] - options
559
1047
  * @param {object} [opt.parseOptions]
560
1048
  * @description Creates an instance of the DTS-provider element
561
1049
  */
@@ -583,57 +1071,37 @@ class TXepgDTSProvider {
583
1071
  * @returns {void}
584
1072
  * @private
585
1073
  */
586
- #_init(){
1074
+ #_init() {
587
1075
  insertXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
588
1076
  }
589
1077
 
590
1078
  /**
1079
+ * Contains a dtstype ID
591
1080
  * @property {number}
592
- * @description Contains a dtstype ID
593
1081
  */
594
- get dtstype(){
1082
+ get dtstype() {
595
1083
  const item = getXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
596
1084
  let result = 0; //-1; // // TODO: [?]
597
- if (isPlainObject(item)) {
598
- result = valueToIndex(_getXmlChildElementParam(item, 'value'));
599
- if (!chkDTSysID(result)) result = 0; //-1; // // TODO: [?]
600
- };
1085
+ if (isPlainObject(item)) result = _getDTSTypeValueForXObj(item);
601
1086
  return result;
602
1087
  }
603
1088
 
604
- set dtstype(value){
605
- let { index, name } = getDTSysDescr(value);
606
- if (index !== -1) {
607
- const item = insertXObjElement(
608
- this.#_content,
609
- XEPG_DTSINFO_ETAG_NAME,
610
- { force: true },
611
- );
612
- if (item) {
613
- let curItem = insertXObjElement(item, 'value', { force: true });
614
- if (
615
- curItem
616
- && writeXObjParam(curItem, index)
617
- && (curItem = insertXObjElement(item, 'name', { force: true }))
618
- ) {
619
- writeXObjParam(curItem, name);
620
- };
621
- };
622
- };
1089
+ set dtstype(value) {
1090
+ return this.setType(value);
623
1091
  }
624
1092
 
625
1093
  /**
1094
+ * Contains a TZ-offset
626
1095
  * @property {number}
627
- * @description Contains a TZ-offset
628
1096
  */
629
- get curDocTZ(){
1097
+ get curDocTZ() {
630
1098
  const tz = convTZStringToValue(
631
1099
  _getXmlChildElementParam(this.#_content, XEPG_DOCTZ_ETAG_NAME)
632
1100
  );
633
1101
  return Number.isNaN(tz) ? 0 : tz;
634
1102
  }
635
1103
 
636
- set curDocTZ(value){
1104
+ set curDocTZ(value) {
637
1105
  let _value = convValueToTZString(value);
638
1106
  if (_value !== '') {
639
1107
  let item = insertXObjElement(
@@ -645,24 +1113,53 @@ class TXepgDTSProvider {
645
1113
  };
646
1114
  }
647
1115
 
1116
+ /**
1117
+ * @since 0.0.22
1118
+ * @property {(number|string)} value - dtstype ID
1119
+ * @returns {boolean}
1120
+ * @description Tries to set a `DTS`-type
1121
+ */
1122
+ setType(value) {
1123
+ let { index, name } = getDTSysDescr(value);
1124
+ let isSucceed = false;
1125
+ if (index !== -1) {
1126
+ const item = insertXObjElement(
1127
+ this.#_content,
1128
+ XEPG_DTSINFO_ETAG_NAME,
1129
+ { force: true },
1130
+ );
1131
+ if (item) {
1132
+ let curItem = insertXObjElement(item, 'value', { force: true });
1133
+ if (
1134
+ curItem
1135
+ && writeXObjParam(curItem, index)
1136
+ && (curItem = insertXObjElement(item, 'name', { force: true }))
1137
+ ) {
1138
+ isSucceed = writeXObjParam(curItem, name);
1139
+ };
1140
+ };
1141
+ };
1142
+ return isSucceed;
1143
+ }
1144
+
648
1145
  };
649
1146
 
650
1147
  /**
651
- * @classdesc This class implements an instance of a EPG-header element
1148
+ * @classdesc This class implements an interface of a EPG-header element
652
1149
  */
653
1150
  class TXEpgHeaderContainer {
654
1151
  /** @property {Object} */
655
1152
  #_host;// = null;
656
1153
  /** @property {Object} */
657
1154
  #_options;// = null;
658
- /** @property {?TXmlContentParseOptions} */
1155
+ /** @property {TXmlContentParseOptions} */
659
1156
  #_parseOptions;// = null;
660
- /** @property {?TXepgDTSProvider} */
1157
+ /** @property {TXEpgDTSProvider} */
661
1158
  #_dtsProv;// = null;
662
1159
 
663
1160
  /**
664
1161
  * @param {object} obj
665
- * @param {object} [opt]
1162
+ * @param {object} [opt] - options
666
1163
  * @param {object} [opt.parseOptions]
667
1164
  * @description Creates an instance of the EPG-header element
668
1165
  */
@@ -685,39 +1182,41 @@ class TXEpgHeaderContainer {
685
1182
  // save content source
686
1183
  this.#_host = _host;
687
1184
  // init DTS-provider
688
- this.#_dtsProv = new TXepgDTSProvider(_host, _options);
1185
+ this.#_dtsProv = new TXEpgDTSProvider(_host, _options);
689
1186
  }
690
1187
 
691
1188
  /**
692
- * @property {TXepgDTSProvider}
1189
+ * Returns a `TXEpgDTSProvider` instance
1190
+ * @property {TXEpgDTSProvider}
693
1191
  * @readonly
694
- * @description Returns a `TXepgDTSProvider` instance
695
1192
  */
696
- get dts(){
1193
+ get dts() {
697
1194
  return this.#_dtsProv;
698
1195
  }
699
1196
 
700
1197
  /**
1198
+ * Contains a dtstype ID
701
1199
  * @property {number}
702
- * @description Contains a dtstype ID
1200
+ * @todo [since v0.0.22] becomes readonly
703
1201
  */
704
- get dtstype(){
1202
+ get dtstype() {
705
1203
  return this.#_dtsProv.dtstype;
706
1204
  }
707
1205
 
708
- set dtstype(value){
1206
+ set dtstype(value) {
709
1207
  this.#_dtsProv.dtstype = value;
710
1208
  }
711
1209
 
712
1210
  /**
1211
+ * Contains a TZ-offset
713
1212
  * @property {number}
714
- * @description Contains a TZ-offset
1213
+ * @todo [since v0.0.22] becomes readonly
715
1214
  */
716
- get curDocTZ(){
1215
+ get curDocTZ() {
717
1216
  return this.#_dtsProv.curDocTZ;
718
1217
  }
719
1218
 
720
- set curDocTZ(value){
1219
+ set curDocTZ(value) {
721
1220
  this.#_dtsProv.curDocTZ = value;
722
1221
  }
723
1222
 
@@ -744,11 +1243,22 @@ class TXEpgHeaderContainer {
744
1243
  }
745
1244
 
746
1245
  /**
1246
+ * Returns a `TXEpgProviderContainer` instance
1247
+ * @property {?TXEpgProviderContainer}
1248
+ * @readonly
1249
+ * @deprecated
1250
+ */
1251
+ get Provider() {
1252
+ return this.provider;
1253
+ }
1254
+
1255
+ /**
1256
+ * Returns a `TXEpgProviderContainer` instance
1257
+ * @since 0.0.22
747
1258
  * @property {?TXEpgProviderContainer}
748
1259
  * @readonly
749
- * @description Returns a `TXEpgProviderContainer` instance
750
1260
  */
751
- get Provider(){
1261
+ get provider() {
752
1262
  const docProv = this.#_getProv();
753
1263
  return (
754
1264
  docProv
@@ -757,6 +1267,16 @@ class TXEpgHeaderContainer {
757
1267
  );
758
1268
  }
759
1269
 
1270
+ /**
1271
+ * Returns a `TXEpgChannelContainer` instance
1272
+ * @since 0.0.22
1273
+ * @property {?TXEpgChannelContainer}
1274
+ * @readonly
1275
+ */
1276
+ get channel() {
1277
+ return new TXEpgChannelContainer(this.#_host, this.#_options);
1278
+ }
1279
+
760
1280
  /**
761
1281
  * @returns {number}
762
1282
  * @description Returns a document creation date as a timestamp
@@ -798,7 +1318,7 @@ class TXEpgHeaderContainer {
798
1318
  }
799
1319
 
800
1320
  /**
801
- * @param {any} value
1321
+ * @param {any} value - document expire date
802
1322
  * @returns {void}
803
1323
  * @description Sets a document expire date to a given time
804
1324
  */
@@ -813,100 +1333,52 @@ class TXEpgHeaderContainer {
813
1333
  if (item) writeXObjParam(item, dt_str);
814
1334
  }
815
1335
 
816
- /**
817
- * @typedef {Object} xepgChnInfoDesc
818
- * @property {string} chnid - channel ID
819
- * @property {string} chngid - channel 'Group ID'
820
- * @property {string} chname - channel name
821
- * @property {string} srcurl - EPG-source URL
822
- * @description Contains a channel description
823
- */
824
-
825
1336
  /**
826
1337
  * @returns {xepgChnInfoDesc}
827
1338
  * @description Returns a channel info
828
1339
  */
829
1340
  getChannelInfo() {
830
- const _host = this.#_host;
831
- /** @type {xepgChnInfoDesc} */
832
- let item = {
833
- chnid: _getXmlChildElementParam(_host, XEPG_CHNID_ETAG_NAME).trim(),
834
- chname: _getXmlChildElementParam(_host, XEPG_CHNNAME_ETAG_NAME).trim(),
835
- chngid: _getXmlChildElementParam(_host, XEPG_CHNGID_ETAG_NAME).trim(),
836
- srcurl: _getXmlChildElementParam(_host, XEPG_CHNURL_ETAG_NAME).trim(),
837
- };
838
- return item;
1341
+ return this.channel.getInfo();
839
1342
  }
840
1343
 
841
1344
  /**
842
- * @param {object} obj
1345
+ * @param {xepgChnInfoDesc} obj - channel info descriptor
843
1346
  * @returns {void}
844
1347
  * @description Sets a channel info
1348
+ * @deprecated
1349
+ * @todo [since v0.0.21] deprecate use of `obj`-param as array
1350
+ * @todo [since v0.0.22] deprecated
845
1351
  */
846
- setChannelInfo(obj){
847
- let chnid = '';
848
- let chname = '';
849
- let chngid = '';
850
- let srcurl = '';
1352
+ setChannelInfo(obj) {
1353
+ let _obj = obj;
851
1354
  if (isArray(obj)) {
852
- [ chnid, chname, chngid, srcurl ] = obj;
853
- } else if (isObject(obj)) {
854
- ({ chnid } = obj);
855
- if (typeof chnid === 'string') {
856
- ({ chname, chngid, srcurl } = obj);
857
- } else {
858
- chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
859
- chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
860
- chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
861
- srcurl = _getXmlChildElementParam(obj, XEPG_CHNURL_ETAG_NAME).trim();
862
- };
863
- } else if (typeof obj === 'string') {
864
- chnid = obj;
865
- } else {
866
- return;
867
- };
868
- chnid = typeof chnid === 'string' ? chnid.trim() : '';
869
- if (chnid === '') {
870
- chname = '';
871
- chngid = '';
872
- srcurl = '';
873
- } else {
874
- chname = typeof chname === 'string' ? chname.trim() : '';
875
- chngid = typeof chngid === 'string' ? chngid.trim() : '';
876
- srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
1355
+ // // TODO: [!] deprecate
1356
+ const [ chnid, chname, chngid, srcurl ] = _obj;
1357
+ _obj = { chnid, chname, chngid, srcurl };
877
1358
  };
878
- let item = null;
879
- const _host = this.#_host;
880
- item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
881
- if (item) writeXObjParam(item, chnid);
882
- item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
883
- if (item) writeXObjParam(item, chname);
884
- item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
885
- if (item) writeXObjParam(item, chngid);
886
- item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
887
- if (item) writeXObjParam(item, srcurl);
1359
+ return this.channel.setInfo(_obj);
888
1360
  }
889
1361
 
890
1362
  /**
891
- * @returns {?object}
1363
+ * @returns {?xepgProvInfoDesc}
892
1364
  * @description Returns a provider info
893
1365
  */
894
1366
  getProviderInfo(){
895
- const docProv = this.Provider;
1367
+ const docProv = this.provider;
896
1368
  return docProv ? docProv.getInfo() : null;
897
1369
  }
898
1370
 
899
1371
  /**
900
- * @param {object} obj
1372
+ * @param {xepgProvInfoDesc} obj - provider info descriptor
901
1373
  * @returns {void}
902
1374
  * @description Sets a provider info
903
1375
  */
904
1376
  setProviderInfo(obj){
905
1377
  if (isArray(obj) || isObject(obj)) {
906
- let docProv = this.Provider;
1378
+ let docProv = this.provider;
907
1379
  if (!docProv) {
908
1380
  docProv = this.#_initProv();
909
- if (docProv) docProv = this.Provider;
1381
+ if (docProv) docProv = this.provider;
910
1382
  };
911
1383
  if (docProv) docProv.setInfo(obj);
912
1384
  };
@@ -935,6 +1407,17 @@ class TXEpgHeaderContainer {
935
1407
 
936
1408
  };
937
1409
 
1410
+ /**
1411
+ * @typedef {Object} fsoDescr
1412
+ * @property {boolean} isERR - flag
1413
+ * @property {number} [errCode] - error code
1414
+ * @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
+ * @description A fs ops description.
1419
+ */
1420
+
938
1421
  /**
939
1422
  * @classdesc This class implements an interface of the container
940
1423
  * that manages a content of a XEPG-document
@@ -948,7 +1431,7 @@ class TXEpgContentProvider {
948
1431
  #_parseOptions;// = null;
949
1432
 
950
1433
  /**
951
- * @param {object} [opt]
1434
+ * @param {object} [opt] - options
952
1435
  * @param {object} [opt.parseOptions]
953
1436
  * @param {boolean} [opt.autoBindRoot] - <*reserved*> ([?] - deprecate)
954
1437
  * @description Creates an instance of the XEPG-content provider
@@ -988,7 +1471,7 @@ class TXEpgContentProvider {
988
1471
  * @returns {?object}
989
1472
  * @private
990
1473
  */
991
- #_initRoot(){
1474
+ #_initRoot() {
992
1475
  const _content = this.#_content;
993
1476
  let docRoot = getXObjElement(_content, XEPG_ROOT_ETAG_NAME);
994
1477
  if (!docRoot) {
@@ -1017,7 +1500,7 @@ class TXEpgContentProvider {
1017
1500
  * @returns {?object}
1018
1501
  * @private
1019
1502
  */
1020
- #_initHdr(){
1503
+ #_initHdr() {
1021
1504
  let docHdr = this.#_getHdr();
1022
1505
  if (!docHdr) {
1023
1506
  let docRoot = this.#_getRoot();
@@ -1046,7 +1529,7 @@ class TXEpgContentProvider {
1046
1529
  * @returns {?object}
1047
1530
  * @private
1048
1531
  */
1049
- #_initBody(){
1532
+ #_initBody() {
1050
1533
  let docBody = this.#_getBody();
1051
1534
  if (!docBody) {
1052
1535
  let docRoot = this.#_getRoot();
@@ -1059,9 +1542,10 @@ class TXEpgContentProvider {
1059
1542
  }
1060
1543
 
1061
1544
  /**
1545
+ * Returns a `TXEpgHeaderContainer` instance
1062
1546
  * @property {?TXEpgHeaderContainer}
1063
1547
  * @readonly
1064
- * @description Returns a `TXEpgHeaderContainer` instance
1548
+ * @deprecated
1065
1549
  */
1066
1550
  get Header() {
1067
1551
  const docHdr = this.#_getHdr();
@@ -1073,22 +1557,49 @@ class TXEpgContentProvider {
1073
1557
  }
1074
1558
 
1075
1559
  /**
1560
+ * Returns a `TXEpgHeaderContainer` instance
1561
+ * @since 0.0.22
1562
+ * @property {?TXEpgHeaderContainer}
1563
+ * @readonly
1564
+ */
1565
+ get header() {
1566
+ const docHdr = this.#_getHdr();
1567
+ return (
1568
+ docHdr
1569
+ ? new TXEpgHeaderContainer(docHdr, this.#_options)
1570
+ : null
1571
+ );
1572
+ }
1573
+
1574
+ /**
1575
+ * Returns a `TXEpgProviderContainer` instance
1576
+ * @property {?TXEpgProviderContainer}
1577
+ * @readonly
1578
+ * @deprecated
1579
+ */
1580
+ get Provider() {
1581
+ const docHdr = this.header;
1582
+ return docHdr ? docHdr.provider : null;
1583
+ }
1584
+
1585
+ /**
1586
+ * Returns a `TXEpgProviderContainer` instance
1587
+ * @since 0.0.22
1076
1588
  * @property {?TXEpgProviderContainer}
1077
1589
  * @readonly
1078
- * @description Returns a `TXEpgProviderContainer` instance
1079
1590
  */
1080
- get Provider(){
1081
- const docHdr = this.Header;
1082
- return docHdr ? docHdr.Provider : null;
1591
+ get provider() {
1592
+ const docHdr = this.header;
1593
+ return docHdr ? docHdr.provider : null;
1083
1594
  }
1084
1595
 
1085
1596
  /**
1086
- * @property {?TXepgDTSProvider}
1597
+ * Returns a `TXEpgDTSProvider` instance
1598
+ * @property {?TXEpgDTSProvider}
1087
1599
  * @readonly
1088
- * @description Returns a `TXepgDTSProvider` instance
1089
1600
  */
1090
- get dts(){
1091
- const docHdr = this.Header;
1601
+ get dts() {
1602
+ const docHdr = this.header;
1092
1603
  return docHdr ? docHdr.dts : null;
1093
1604
  }
1094
1605
 
@@ -1099,11 +1610,11 @@ class TXEpgContentProvider {
1099
1610
  get Content(){ return this; }
1100
1611
 
1101
1612
  /**
1613
+ * Returns a `TXEpgSchedulesList` instance
1102
1614
  * @property {TXEpgSchedulesList}
1103
1615
  * @readonly
1104
- * @description Returns a `TXEpgSchedulesList` instance
1105
1616
  */
1106
- get SchedulesList(){
1617
+ get SchedulesList() {
1107
1618
  const _options = this.#_options;
1108
1619
  const docBody = this.#_getBody();
1109
1620
  if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
@@ -1121,7 +1632,7 @@ class TXEpgContentProvider {
1121
1632
  /**
1122
1633
  * @returns {void}
1123
1634
  */
1124
- init(){
1635
+ init() {
1125
1636
  const _options = this.#_options;
1126
1637
  const _content = this.#_content;
1127
1638
  const {
@@ -1145,7 +1656,7 @@ class TXEpgContentProvider {
1145
1656
  docHdr,
1146
1657
  XEPG_PRVINFO_ETAG_NAME,
1147
1658
  );
1148
- if (docProv) this.Provider.init();
1659
+ if (docProv) this.provider.init();
1149
1660
  // initiate document body element
1150
1661
  let docBody = this.#_getBody();
1151
1662
  if (!docBody) docBody = this.#_initBody();
@@ -1172,20 +1683,9 @@ class TXEpgContentProvider {
1172
1683
  return result;
1173
1684
  }
1174
1685
 
1175
- /**
1176
- * @typedef {Object} fsoDescr
1177
- * @property {boolean} isERR - flag
1178
- * @property {number|undefined} errCode - error code
1179
- * @property {string} errEvent - event ID
1180
- * @property {string} errMsg - event message
1181
- * @property {string} source - path to file
1182
- * @property {any} content - file content
1183
- * @description A fs ops description.
1184
- */
1185
-
1186
1686
  /**
1187
1687
  * @param {string} source - a path to a file
1188
- * @returns {fsoDescr}
1688
+ * @returns {Promise<fsoDescr, Error>}
1189
1689
  * @throws {Error}
1190
1690
  * @async
1191
1691
  * @description Saves a document content to a file.
@@ -1299,7 +1799,7 @@ class TXEpgContentProvider {
1299
1799
 
1300
1800
  /**
1301
1801
  * @param {string} source - path to a file
1302
- * @returns {fsoDescr}
1802
+ * @returns {Promise<fsoDescr, Error>}
1303
1803
  * @throws {Error}
1304
1804
  * @async
1305
1805
  * @description Loads a document content from a file.
@@ -1357,19 +1857,10 @@ class TXEpgContentProvider {
1357
1857
  return data;
1358
1858
  }
1359
1859
 
1360
- // will deprecate
1361
- /**
1362
- * @deprecated
1363
- */
1364
- asXML(opt){
1365
- let parseOptions = isPlainObject(opt) ? opt : defParseOptions.js2xml;
1366
- return xmlParser.js2xml(this.#_content, parseOptions);
1367
- }
1368
-
1369
1860
  /**
1370
1861
  * @protected
1371
1862
  */
1372
- asJSON(){
1863
+ asJSON() {
1373
1864
  return JSON.stringify(this.#_content, null, 2);
1374
1865
  }
1375
1866
 
@@ -1377,13 +1868,18 @@ class TXEpgContentProvider {
1377
1868
 
1378
1869
  // === module exports block ===
1379
1870
 
1380
- exports.TXepgDTSProvider = TXepgDTSProvider;
1381
- exports.TXEpgSchedulesList = TXEpgSchedulesList;
1382
- exports.TXEpgProviderContainer = TXEpgProviderContainer;
1383
- exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
1384
- exports.TXEpgContentProvider = TXEpgContentProvider;
1385
-
1386
- exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
1387
- exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
1388
- exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
1389
- exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
1871
+ module.exports.TXEpgDTSProvider = TXEpgDTSProvider;
1872
+ module.exports.TXEpgScheduleItem = TXEpgScheduleItem;
1873
+ module.exports.TXEpgSchedulesList = TXEpgSchedulesList;
1874
+ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
1875
+ module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
1876
+ module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
1877
+ 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;