@ygracs/xepg-lib-js 0.0.21 → 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,4 +1,4 @@
1
- // [v0.1.081-20250227]
1
+ // [v0.2.098-20250306]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -13,6 +13,7 @@ const {
13
13
 
14
14
  const {
15
15
  convValueToTZString, convTZStringToValue,
16
+ tryDTValue,
16
17
  } = require('@ygracs/dtf-lib-js');
17
18
 
18
19
  const {
@@ -28,8 +29,10 @@ const {
28
29
  const xObj = require('@ygracs/xobj-lib-js');
29
30
 
30
31
  const TXmlContentParseOptions = xObj.TXmlContentParseOptions;
31
- const insertXObjElement = xObj.insertXObjElement;
32
- const getXObjElement = xObj.getXObjElement;
32
+ const {
33
+ getXObjElement,
34
+ insertXObjElement,
35
+ } = xObj;
33
36
 
34
37
  // === module extra block (helper functions) ===
35
38
 
@@ -55,12 +58,30 @@ function writeXObjAttr(obj, name, value) {
55
58
  * === xObj-function wrappers (end) ===
56
59
  */
57
60
 
58
- function _getXmlChildElementParam(obj, elem){
61
+ /**
62
+ * @param {object} obj
63
+ * @param {string} elem
64
+ * @returns {string}
65
+ * @inner
66
+ */
67
+ function _getXmlChildElementParam(obj, elem) {
59
68
  const child = obj ? getXObjElement(obj, elem) : null;
60
69
  return child ? readXObjParam(child) : '';
61
70
  };
62
71
 
63
- 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) {
64
85
  let xml_ver = XEPG_XML_DOC_VERSION;
65
86
  let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
66
87
  let key_name = defParseOptions.settings.declarationKey;
@@ -81,6 +102,11 @@ function writeXEpgDocDeclSection(obj, opt){
81
102
  * (* constant definitions *)
82
103
  */
83
104
 
105
+ /**
106
+ * A list of a document schema version supported by a library
107
+ */
108
+ const ALLOWED_XEPG_DOCUMENT_SCHEMA = [ '0.2' ];
109
+
84
110
  const XEPG_ROOT_ETAG_NAME = 'epgdoc';
85
111
  const XEPG_DEF_NS_NAME = 'tvp';
86
112
  const XEPG_DEF_NS_PATH = 'urn:e-doc:epg-doc:xepg';
@@ -106,9 +132,9 @@ const XEPG_SCHEDDESC_ETAG_NAME = `${XEPG_DEF_NS_NAME}:desc`;
106
132
  const XEPG_XML_DOC_VERSION = '1.0';
107
133
  const XEPG_DEF_ENCODING_VALUE = 'UTF-8';
108
134
  const XEPG_DEF_DOCUMENT_TYPE = 'xepg';
109
- const XEPG_DEF_DOCUMENT_SCHEMA = '0.2';
135
+ const XEPG_DEF_DOCUMENT_SCHEMA = ALLOWED_XEPG_DOCUMENT_SCHEMA[0];
110
136
  const XEPG_DEF_PROVIDER_NAME = 'xepg-lib-js';
111
- const XEPG_DEF_PROVIDER_VER = '0.0.15';
137
+ const XEPG_DEF_PROVIDER_VER = '0.0.21';
112
138
 
113
139
  const defXEpgDocOptions = {
114
140
  xmlns_xepg_pref: XEPG_DEF_NS_NAME,
@@ -149,6 +175,250 @@ const defParseOptions = new TXmlContentParseOptions();
149
175
  * @description A schedule info descriptor
150
176
  */
151
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
+
152
422
  /**
153
423
  * @classdesc This class implements an interface of a EPG-schedules list
154
424
  */
@@ -205,19 +475,13 @@ class TXEpgSchedulesList {
205
475
  return this.#_content.length;
206
476
  }
207
477
 
208
- // will deprecate
209
- //get SchedulesQty(){ return this.#_content.length; }
210
-
211
478
  /**
212
479
  * Contains a dtstype ID
213
480
  * @property {number}
214
481
  * @readonly
215
482
  */
216
483
  get dtstype() {
217
- let result = valueToIndex(
218
- _getXmlChildElementParam(this.#_dts_src, 'value')
219
- );
220
- return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
484
+ return _getDTSTypeValueForXObj(this.#_dts_src);
221
485
  }
222
486
 
223
487
  /**
@@ -255,6 +519,8 @@ class TXEpgSchedulesList {
255
519
  * @deprecated
256
520
  * @description Checks whether a given value is a valid index
257
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
258
524
  */
259
525
  chkScheduleIndex(value) {
260
526
  return this.chkIndex(value);
@@ -263,7 +529,7 @@ class TXEpgSchedulesList {
263
529
  /**
264
530
  * @param {(number|string)} value - index of some element
265
531
  * @returns {boolean}
266
- * @since 0.0.18
532
+ * @since 0.0.20
267
533
  * @description Checks whether a given value is a valid index
268
534
  * and it fits the index range of an instance
269
535
  */
@@ -274,36 +540,31 @@ class TXEpgSchedulesList {
274
540
 
275
541
  /**
276
542
  * @param {(number|string)} index - index of some element
277
- * @returns {xepgShedInfoDesc}
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}
278
562
  * @description Returns a schedule info item for instance element
279
563
  * addressed by a given index
280
564
  */
281
565
  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;
566
+ const obj = this.schedule(index);
567
+ return obj ? obj.getInfo() : null;
307
568
  }
308
569
 
309
570
  /**
@@ -350,7 +611,7 @@ class TXEpgProviderContainer {
350
611
  /** @property {?TXEpgDTSProvider} */
351
612
 
352
613
  /**
353
- * @param {object} obj
614
+ * @param {object} obj - host object
354
615
  * @param {object} [opt] - options
355
616
  * @param {object} [opt.parseOptions]
356
617
  * @description Creates an instance of the EPG-provider element
@@ -565,7 +826,214 @@ class TXEpgProviderContainer {
565
826
  };
566
827
 
567
828
  /**
568
- * @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
835
+ */
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;
849
+
850
+ /**
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
569
1037
  */
570
1038
  class TXEpgDTSProvider {
571
1039
  /** @property {object} */
@@ -574,7 +1042,7 @@ class TXEpgDTSProvider {
574
1042
  #_options;// = null;
575
1043
 
576
1044
  /**
577
- * @param {object} obj
1045
+ * @param {object} obj - host object
578
1046
  * @param {object} [opt] - options
579
1047
  * @param {object} [opt.parseOptions]
580
1048
  * @description Creates an instance of the DTS-provider element
@@ -614,32 +1082,12 @@ class TXEpgDTSProvider {
614
1082
  get dtstype() {
615
1083
  const item = getXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
616
1084
  let result = 0; //-1; // // TODO: [?]
617
- if (isPlainObject(item)) {
618
- result = valueToIndex(_getXmlChildElementParam(item, 'value'));
619
- if (!chkDTSysID(result)) result = 0; //-1; // // TODO: [?]
620
- };
1085
+ if (isPlainObject(item)) result = _getDTSTypeValueForXObj(item);
621
1086
  return result;
622
1087
  }
623
1088
 
624
1089
  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
- };
1090
+ return this.setType(value);
643
1091
  }
644
1092
 
645
1093
  /**
@@ -665,19 +1113,39 @@ class TXEpgDTSProvider {
665
1113
  };
666
1114
  }
667
1115
 
668
- };
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
+ }
669
1144
 
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
- */
1145
+ };
678
1146
 
679
1147
  /**
680
- * @classdesc This class implements an instance of a EPG-header element
1148
+ * @classdesc This class implements an interface of a EPG-header element
681
1149
  */
682
1150
  class TXEpgHeaderContainer {
683
1151
  /** @property {Object} */
@@ -775,11 +1243,22 @@ class TXEpgHeaderContainer {
775
1243
  }
776
1244
 
777
1245
  /**
1246
+ * Returns a `TXEpgProviderContainer` instance
778
1247
  * @property {?TXEpgProviderContainer}
779
1248
  * @readonly
780
- * @description Returns a `TXEpgProviderContainer` instance
1249
+ * @deprecated
781
1250
  */
782
1251
  get Provider() {
1252
+ return this.provider;
1253
+ }
1254
+
1255
+ /**
1256
+ * Returns a `TXEpgProviderContainer` instance
1257
+ * @since 0.0.22
1258
+ * @property {?TXEpgProviderContainer}
1259
+ * @readonly
1260
+ */
1261
+ get provider() {
783
1262
  const docProv = this.#_getProv();
784
1263
  return (
785
1264
  docProv
@@ -788,6 +1267,16 @@ class TXEpgHeaderContainer {
788
1267
  );
789
1268
  }
790
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
+
791
1280
  /**
792
1281
  * @returns {number}
793
1282
  * @description Returns a document creation date as a timestamp
@@ -849,67 +1338,25 @@ class TXEpgHeaderContainer {
849
1338
  * @description Returns a channel info
850
1339
  */
851
1340
  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;
1341
+ return this.channel.getInfo();
861
1342
  }
862
1343
 
863
1344
  /**
864
1345
  * @param {xepgChnInfoDesc} obj - channel info descriptor
865
1346
  * @returns {void}
866
1347
  * @description Sets a channel info
1348
+ * @deprecated
867
1349
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
1350
+ * @todo [since v0.0.22] deprecated
868
1351
  */
869
1352
  setChannelInfo(obj) {
870
- let chnid = '';
871
- let chname = '';
872
- let chngid = '';
873
- let srcurl = '';
1353
+ let _obj = obj;
874
1354
  if (isArray(obj)) {
875
1355
  // // 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;
1356
+ const [ chnid, chname, chngid, srcurl ] = _obj;
1357
+ _obj = { chnid, chname, chngid, srcurl };
892
1358
  };
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() : '';
902
- };
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);
1359
+ return this.channel.setInfo(_obj);
913
1360
  }
914
1361
 
915
1362
  /**
@@ -917,7 +1364,7 @@ class TXEpgHeaderContainer {
917
1364
  * @description Returns a provider info
918
1365
  */
919
1366
  getProviderInfo(){
920
- const docProv = this.Provider;
1367
+ const docProv = this.provider;
921
1368
  return docProv ? docProv.getInfo() : null;
922
1369
  }
923
1370
 
@@ -928,10 +1375,10 @@ class TXEpgHeaderContainer {
928
1375
  */
929
1376
  setProviderInfo(obj){
930
1377
  if (isArray(obj) || isObject(obj)) {
931
- let docProv = this.Provider;
1378
+ let docProv = this.provider;
932
1379
  if (!docProv) {
933
1380
  docProv = this.#_initProv();
934
- if (docProv) docProv = this.Provider;
1381
+ if (docProv) docProv = this.provider;
935
1382
  };
936
1383
  if (docProv) docProv.setInfo(obj);
937
1384
  };
@@ -1098,6 +1545,7 @@ class TXEpgContentProvider {
1098
1545
  * Returns a `TXEpgHeaderContainer` instance
1099
1546
  * @property {?TXEpgHeaderContainer}
1100
1547
  * @readonly
1548
+ * @deprecated
1101
1549
  */
1102
1550
  get Header() {
1103
1551
  const docHdr = this.#_getHdr();
@@ -1108,14 +1556,41 @@ class TXEpgContentProvider {
1108
1556
  );
1109
1557
  }
1110
1558
 
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
+
1111
1574
  /**
1112
1575
  * Returns a `TXEpgProviderContainer` instance
1113
1576
  * @property {?TXEpgProviderContainer}
1114
1577
  * @readonly
1578
+ * @deprecated
1115
1579
  */
1116
1580
  get Provider() {
1117
- const docHdr = this.Header;
1118
- return docHdr ? docHdr.Provider : null;
1581
+ const docHdr = this.header;
1582
+ return docHdr ? docHdr.provider : null;
1583
+ }
1584
+
1585
+ /**
1586
+ * Returns a `TXEpgProviderContainer` instance
1587
+ * @since 0.0.22
1588
+ * @property {?TXEpgProviderContainer}
1589
+ * @readonly
1590
+ */
1591
+ get provider() {
1592
+ const docHdr = this.header;
1593
+ return docHdr ? docHdr.provider : null;
1119
1594
  }
1120
1595
 
1121
1596
  /**
@@ -1124,7 +1599,7 @@ class TXEpgContentProvider {
1124
1599
  * @readonly
1125
1600
  */
1126
1601
  get dts() {
1127
- const docHdr = this.Header;
1602
+ const docHdr = this.header;
1128
1603
  return docHdr ? docHdr.dts : null;
1129
1604
  }
1130
1605
 
@@ -1181,7 +1656,7 @@ class TXEpgContentProvider {
1181
1656
  docHdr,
1182
1657
  XEPG_PRVINFO_ETAG_NAME,
1183
1658
  );
1184
- if (docProv) this.Provider.init();
1659
+ if (docProv) this.provider.init();
1185
1660
  // initiate document body element
1186
1661
  let docBody = this.#_getBody();
1187
1662
  if (!docBody) docBody = this.#_initBody();
@@ -1393,16 +1868,18 @@ class TXEpgContentProvider {
1393
1868
 
1394
1869
  // === module exports block ===
1395
1870
 
1396
- exports.TXEpgDTSProvider = TXEpgDTSProvider;
1397
- exports.TXEpgSchedulesList = TXEpgSchedulesList;
1398
- exports.TXEpgProviderContainer = TXEpgProviderContainer;
1399
- exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
1400
- exports.TXEpgContentProvider = TXEpgContentProvider;
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;
1401
1878
 
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;
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;
1406
1883
 
1407
1884
  /** @deprecated */
1408
- exports.TXepgDTSProvider = TXEpgDTSProvider;
1885
+ module.exports.TXepgDTSProvider = TXEpgDTSProvider;