@ygracs/xepg-lib-js 0.0.23 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // [v0.2.106-20250428]
1
+ // [v0.2.124-20250730]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -36,7 +36,7 @@ const {
36
36
  writeXObjAttr,
37
37
  } = xObj;
38
38
 
39
- // === module extra block (helper functions) ===
39
+ // === module inner block ===
40
40
 
41
41
  /*
42
42
  * === xObj-function wrappers (start) ===
@@ -50,6 +50,10 @@ function readXObjParam(obj){
50
50
  * === xObj-function wrappers (end) ===
51
51
  */
52
52
 
53
+ /***
54
+ * (* helper function definitions *)
55
+ */
56
+
53
57
  /**
54
58
  * @param {object} obj - element
55
59
  * @param {string} name - child element name
@@ -95,6 +99,94 @@ function writeXEpgDocDeclSection(obj, data) {
95
99
  };
96
100
  };
97
101
 
102
+ /**
103
+ * Returns an object as a string in an XML-format.
104
+ * @since v0.0.24
105
+ * @function serializeXObjToXMLString
106
+ * @param {object} node - some element
107
+ * @param {object} opt - parser options
108
+ * @param {string} tagName - element tag name
109
+ * @returns {string}
110
+ * @inner
111
+ */
112
+ function serializeXObjToXMLString(node, opt, tagName) {
113
+ let result = '';
114
+ try {
115
+ result = xmlParser.js2xml({ [tagName]: node }, opt);
116
+ } catch (err) {
117
+ //console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
118
+ result = '';
119
+ //throw err;
120
+ };
121
+ return result;
122
+ };
123
+
124
+ /**
125
+ * Loads an object content from an XML-string.
126
+ * @since v0.0.24
127
+ * @function deserializeXObjFromXMLString
128
+ * @param {object} node - some element
129
+ * @param {object} opt - parser options
130
+ * @param {string} text - some content
131
+ * @param {string} tagName - element tag name
132
+ * @returns {boolean}
133
+ * @throws {Error}
134
+ * @inner
135
+ * @experimental
136
+ */
137
+ function deserializeXObjFromXMLString(node, opt, text, tagName) {
138
+ let result = false;
139
+ if (typeof text === 'string' && text !== '') {
140
+ try {
141
+ let obj = xmlParser.xml2js(text, opt);
142
+ if (isPlainObject(obj)) {
143
+ obj = obj[tagName];
144
+ if (isPlainObject(obj)) {
145
+ for (let prop in node) {
146
+ // // TODO: catch errors in strict mode
147
+ delete node[prop];
148
+ };
149
+ (Object.entries(obj)).forEach(([key, value]) => {
150
+ node[key] = value;
151
+ });
152
+ result = true;
153
+ };
154
+ };
155
+ } catch (err) {
156
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
157
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
158
+ throw err;
159
+ };
160
+ };
161
+ return result;
162
+ };
163
+
164
+ /**
165
+ * An XEPG-element options set (base)
166
+ * @typedef {Object} OPT_epgelsett_bs
167
+ * @property {TXmlContentParseOptions} [parseOptions] - parser options
168
+ */
169
+
170
+ /**
171
+ * Evaluates an XML-node base settings
172
+ * @function __evalXMLBaseNodeSettings
173
+ * @param {any} value - element settings to evaluate
174
+ * @returns {OPT_epgelsett_bs}
175
+ * @inner
176
+ */
177
+ function __evalXMLBaseNodeSettings(value) {
178
+ /** @type {OPT_epgelsett_bs} */
179
+ let settings = isPlainObject(value) ? value : {};
180
+ if (settings instanceof Map) settings = Object.fromEntries(settings);
181
+ let {
182
+ parseOptions,
183
+ } = settings;
184
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
185
+ settings.parseOptions = new TXmlContentParseOptions(parseOptions);
186
+ };
187
+ return settings;
188
+ };
189
+
98
190
  // === module main block ===
99
191
 
100
192
  /***
@@ -161,12 +253,11 @@ const defParseOptions = new TXmlContentParseOptions();
161
253
  */
162
254
 
163
255
  /**
256
+ * Tries to convert a given value to a valid tag name of an XML-element.
164
257
  * @since v0.0.23
165
258
  * @function readAsTagName
166
259
  * @param {any} value - some value
167
260
  * @returns {string}
168
- * @description Tries to convert a given value to a valid tag name
169
- * of an XML-element.
170
261
  */
171
262
  function readAsTagName(value) {
172
263
  let tagName = valueToIDString(value, { ignoreNumbers: true });
@@ -184,12 +275,11 @@ function readAsTagName(value) {
184
275
  };
185
276
 
186
277
  /**
278
+ * Tries to convert a given value to a valid name of an XML-attribute.
187
279
  * @since v0.0.23
188
280
  * @function readAsAttrName
189
281
  * @param {any} value - some value
190
282
  * @returns {string}
191
- * @description Tries to convert a given value to a valid name
192
- * of an XML-attribute.
193
283
  */
194
284
  function readAsAttrName(value) {
195
285
  let attrName = valueToIDString(value, { ignoreNumbers: true });
@@ -207,12 +297,12 @@ function readAsAttrName(value) {
207
297
  };
208
298
 
209
299
  /**
300
+ * Tries to convert a given value to a valid identifier suitable as a value
301
+ * for an "ID-attribute" of an XML-element.
210
302
  * @since v0.0.23
211
303
  * @function valueToElementID
212
304
  * @param {any} value - some value
213
305
  * @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
306
  */
217
307
  function valueToElementID(value) {
218
308
  let id = valueToIDString(value);
@@ -234,27 +324,28 @@ function valueToElementID(value) {
234
324
  */
235
325
 
236
326
  /**
327
+ * A schedule info descriptor
237
328
  * @typedef {Object} xepgShedInfoDesc
238
329
  * @property {number} time - a schedule start time
239
330
  * @property {string} title - schedule title
240
331
  * @property {string} [cat] - schedule category
241
332
  * @property {number} [pcmark] - schedule rating
242
333
  * @property {string} [descr] - schedule description
243
- * @description A schedule info descriptor
244
334
  */
245
335
 
246
336
  /**
247
- * @typedef {Object} OPT_epgelsett_bs
248
- * @property {TXmlContentParseOptions} [parseOptions] - parser options
249
- * @description An XEPG-element options set (base)
337
+ * An extra options set
338
+ * @typedef {Object} OPT_extra
339
+ * @property {object} [dts_src] - 'DTS'-settings
340
+ * @property {object} [tz_src] - 'TZ'-settings
250
341
  */
251
342
 
252
343
  /**
344
+ * An XEPG-element options set (extend)
253
345
  * @typedef {Object} OPT_epgelsett_ex
254
346
  * @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)
347
+ * @property {object} [dts_src]
348
+ * @property {object} [tz_src]
258
349
  */
259
350
 
260
351
  /**
@@ -263,22 +354,23 @@ function valueToElementID(value) {
263
354
  */
264
355
  class TXEpgScheduleItem {
265
356
  /** @type {object} */
266
- #_host;// = null;
357
+ #_host;
267
358
  /** @type {OPT_epgelsett_ex} */
268
- #_options;// = null;
359
+ #_options;
269
360
  /** @type {TXmlContentParseOptions} */
270
- #_parseOptions;// = null;
361
+ #_parseOptions;
271
362
  /** @type {?object} */
272
363
  #_dts_src = null;
273
364
  /** @type {?object} */
274
365
  #_tz_src = null;
275
366
 
276
367
  /**
368
+ * Creates an instance of the EPG-schedule element
277
369
  * @param {object} obj - host object
278
370
  * @param {OPT_epgelsett_ex} [opt] - options
279
- * @description Creates an instance of the EPG-schedule element
371
+ * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
280
372
  */
281
- constructor(obj, opt) {
373
+ constructor(obj, opt, extra) {
282
374
  // load content
283
375
  const _host = isPlainObject(obj) ? obj : {};
284
376
  // load options
@@ -286,12 +378,15 @@ class TXEpgScheduleItem {
286
378
  const _options = isPlainObject(opt) ? opt : {};
287
379
  let {
288
380
  parseOptions,
289
- dts_src, tz_src,
290
381
  } = _options;
291
382
  if (!(parseOptions instanceof TXmlContentParseOptions)) {
292
383
  parseOptions = new TXmlContentParseOptions(parseOptions);
293
384
  _options.parseOptions = parseOptions;
294
385
  };
386
+ let {
387
+ dts_src = _options.dts_src,
388
+ tz_src = _options.tz_src,
389
+ } = isPlainObject(extra) ? extra : {};
295
390
  if (!isPlainObject(dts_src)) dts_src = null;
296
391
  if (!isPlainObject(tz_src)) tz_src = null;
297
392
  // save content source
@@ -378,8 +473,8 @@ class TXEpgScheduleItem {
378
473
  }
379
474
 
380
475
  /**
476
+ * Returns a schedule info item descriptor
381
477
  * @returns {xepgShedInfoDesc}
382
- * @description Returns a schedule info item descriptor
383
478
  */
384
479
  getInfo() {
385
480
  const {
@@ -399,9 +494,9 @@ class TXEpgScheduleItem {
399
494
  }
400
495
 
401
496
  /**
497
+ * Sets a schedule start time.
402
498
  * @param {(number|string|Date)} value - some time value
403
499
  * @returns {boolean}
404
- * @description Sets a schedule start time.
405
500
  */
406
501
  setTime(value) {
407
502
  let { isSucceed, value: dtValue } = tryDTValue(value);
@@ -420,9 +515,9 @@ class TXEpgScheduleItem {
420
515
  }
421
516
 
422
517
  /**
518
+ * Sets a schedule title.
423
519
  * @param {string} value - some title
424
520
  * @returns {boolean}
425
- * @description Sets a schedule title.
426
521
  */
427
522
  setTitle(value) {
428
523
  let result = false;
@@ -437,9 +532,9 @@ class TXEpgScheduleItem {
437
532
  }
438
533
 
439
534
  /**
535
+ * Sets a schedule title.
440
536
  * @param {string} value - some title
441
537
  * @returns {boolean}
442
- * @description Sets a schedule title.
443
538
  */
444
539
  setCategory(value) {
445
540
  let result = false;
@@ -454,9 +549,9 @@ class TXEpgScheduleItem {
454
549
  }
455
550
 
456
551
  /**
552
+ * Sets a schedule rating value.
457
553
  * @param {(number|string)} value - some value
458
554
  * @returns {boolean}
459
- * @description Sets a schedule rating value.
460
555
  */
461
556
  setRating(value) {
462
557
  const _value = valueToIndex(value);
@@ -472,9 +567,9 @@ class TXEpgScheduleItem {
472
567
  }
473
568
 
474
569
  /**
570
+ * Sets a schedule description.
475
571
  * @param {string} value - some text
476
572
  * @returns {boolean}
477
- * @description Sets a schedule description.
478
573
  */
479
574
  setDescr(value) {
480
575
  let result = false;
@@ -489,23 +584,38 @@ class TXEpgScheduleItem {
489
584
  }
490
585
 
491
586
  /**
587
+ * Returns an instance content as a string in an XML-format.
492
588
  * @returns {string}
493
- * @description Returns an instance content as a string in an XML-format.
494
589
  */
495
590
  saveToXMLString() {
496
591
  const options = this.#_parseOptions.js2xml;
497
592
  options.ignoreDocType = true;
498
593
  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;
594
+ return serializeXObjToXMLString(
595
+ this.#_host,
596
+ options,
597
+ XEPG_SCHED_ETAG_NAME,
598
+ );
599
+ }
600
+
601
+ /**
602
+ * Loads an element content from a string.
603
+ * @since v0.0.24
604
+ * @param {string} xmlString - some content
605
+ * @returns {boolean}
606
+ * @throws {Error}
607
+ * @experimental
608
+ */
609
+ loadFromXMLString(xmlString) {
610
+ const options = this.#_parseOptions.xml2js;
611
+ options.ignoreDocType = true;
612
+ options.ignoreDeclaration = true;
613
+ return deserializeXObjFromXMLString(
614
+ this.#_host,
615
+ options,
616
+ xmlString,
617
+ XEPG_SCHED_ETAG_NAME,
618
+ );
509
619
  }
510
620
 
511
621
  };
@@ -515,24 +625,28 @@ class TXEpgScheduleItem {
515
625
  */
516
626
  class TXEpgSchedulesList {
517
627
  /** @type {object[]} */
518
- #_content;// = null;
628
+ #_content;
519
629
  /** @type {OPT_epgelsett_ex} */
520
- #_options;// = null;
630
+ #_options;
521
631
  /** @type {?object} */
522
632
  #_dts_src = null;
523
633
  /** @type {?object} */
524
634
  #_tz_src = null;
525
635
 
526
636
  /**
637
+ * Creates an instance of the schedules list
527
638
  * @param {any[]} obj - list of an elements
528
639
  * @param {OPT_epgelsett_ex} [opt] - options
529
- * @description Creates an instance of the schedules list
640
+ * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
530
641
  */
531
- constructor(obj, opt) {
642
+ constructor(obj, opt, extra) {
532
643
  const _content = isArray(obj) ? obj : [];
533
644
  /** @type {OPT_epgelsett_ex} */
534
645
  const _options = isPlainObject(opt) ? opt : {};
535
- let { dts_src, tz_src } = _options;
646
+ let {
647
+ dts_src = _options.dts_src,
648
+ tz_src = _options.tz_src,
649
+ } = isPlainObject(extra) ? extra : {};
536
650
  if (!isPlainObject(dts_src)) dts_src = null;
537
651
  if (!isPlainObject(tz_src)) tz_src = null;
538
652
  // save content source
@@ -544,11 +658,27 @@ class TXEpgSchedulesList {
544
658
  this.#_tz_src = tz_src;
545
659
  }
546
660
 
661
+ [Symbol.iterator]() {
662
+ let index = 0;
663
+ return {
664
+ next: () => {
665
+ if (index < this.count) {
666
+ return { done: false, value: this.schedule(index++) };
667
+ } else {
668
+ return { done: true, value: undefined };
669
+ };
670
+ },
671
+ return() {
672
+ return { done: true, value: undefined };
673
+ },
674
+ };
675
+ }
676
+
547
677
  /**
678
+ * Returns a raw schedule element
548
679
  * @param {(number|string)} value - element index
549
680
  * @returns {any}
550
681
  * @private
551
- * @description Returns a raw schedule element
552
682
  */
553
683
  #_getItem = function(value) {
554
684
  if (this.chkIndex(value)) {
@@ -560,11 +690,23 @@ class TXEpgSchedulesList {
560
690
  * Contains a quantity of a schedules
561
691
  * @type {number}
562
692
  * @readonly
693
+ * @deprecated
694
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.count`
563
695
  */
564
696
  get schedQty() {
565
697
  return this.#_content.length;
566
698
  }
567
699
 
700
+ /**
701
+ * Contains a quantity of a schedules
702
+ * @since v0.0.24
703
+ * @type {number}
704
+ * @readonly
705
+ */
706
+ get count() {
707
+ return this.#_content.length;
708
+ }
709
+
568
710
  /**
569
711
  * Contains a dtstype ID
570
712
  * @type {number}
@@ -588,51 +730,60 @@ class TXEpgSchedulesList {
588
730
  }
589
731
 
590
732
  /**
733
+ * Indicates whether an instance has none member
591
734
  * @returns {boolean}
592
- * @description Indicates whether an instance has none member
735
+ * @deprecated
736
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isEmpty`
593
737
  */
594
738
  hasNoSchedules() {
595
- return this.schedQty === 0;
739
+ return this.count === 0;
596
740
  }
597
741
 
598
742
  /**
743
+ * Indicates whether an instance has none member
744
+ * @since v0.0.24
599
745
  * @returns {boolean}
600
- * @description Indicates whether an instance has any member
601
746
  */
602
- hasSchedules() {
603
- return this.schedQty > 0;
747
+ isEmpty() {
748
+ return this.count === 0;
604
749
  }
605
750
 
606
751
  /**
607
- * @param {(number|string)} value
752
+ * Indicates whether an instance has any member
608
753
  * @returns {boolean}
609
754
  * @deprecated
610
- * @description Checks whether a given value is a valid index
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
755
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isNotEmpty`
756
+ */
757
+ hasSchedules() {
758
+ return this.count > 0;
759
+ }
760
+
761
+ /**
762
+ * Indicates whether an instance has any member
763
+ * @since v0.0.24
764
+ * @returns {boolean}
614
765
  */
615
- chkScheduleIndex(value) {
616
- return this.chkIndex(value);
766
+ isNotEmpty() {
767
+ return this.count > 0;
617
768
  }
618
769
 
619
770
  /**
771
+ * Checks whether a given value is a valid index and it fits the index range
772
+ * of an instance
620
773
  * @since 0.0.20
621
774
  * @param {(number|string)} value - index of some element
622
775
  * @returns {boolean}
623
- * @description Checks whether a given value is a valid index
624
- * and it fits the index range of an instance
625
776
  */
626
777
  chkIndex(value) {
627
778
  const index = valueToIndex(value);
628
- return index !== -1 && index < this.schedQty;
779
+ return index !== -1 && index < this.count;
629
780
  }
630
781
 
631
782
  /**
783
+ * Returns a schedule element addressed by a given index
632
784
  * @since 0.0.22
633
785
  * @param {(number|string)} index - index of some element
634
786
  * @returns {?TXEpgScheduleItem}
635
- * @description Returns a schedule element addressed by a given index
636
787
  */
637
788
  schedule(index) {
638
789
  const curObj = this.#_getItem(index);
@@ -647,10 +798,10 @@ class TXEpgSchedulesList {
647
798
  }
648
799
 
649
800
  /**
801
+ * Returns a schedule info item for instance element addressed
802
+ * by a given index
650
803
  * @param {(number|string)} index - index of some element
651
804
  * @returns {?xepgShedInfoDesc}
652
- * @description Returns a schedule info item for instance element
653
- * addressed by a given index
654
805
  */
655
806
  getScheduleInfo(index) {
656
807
  const obj = this.schedule(index);
@@ -658,12 +809,12 @@ class TXEpgSchedulesList {
658
809
  }
659
810
 
660
811
  /**
812
+ * Returns a schedule info for instance members
661
813
  * @returns {xepgShedInfoDesc[]}
662
- * @description Returns a schedule info for instance members
663
814
  */
664
815
  getAllSchedulesInfo() {
665
816
  let result = [];
666
- for (let i = 0; i < this.schedQty; i++) {
817
+ for (let i = 0; i < this.count; i++) {
667
818
  let item = this.getScheduleInfo(i);
668
819
  if (isPlainObject(item)) result.push(item);
669
820
  };
@@ -680,12 +831,12 @@ class TXEpgSchedulesList {
680
831
  };
681
832
 
682
833
  /**
834
+ * A provider info descriptor
683
835
  * @typedef {Object} xepgProvInfoDesc
684
836
  * @property {string} [name] - provider name
685
837
  * @property {string} [version] - provider version
686
838
  * @property {string} schema - document schema
687
839
  * @property {string} doctype - document type
688
- * @description A provider info descriptor
689
840
  */
690
841
 
691
842
  /**
@@ -693,31 +844,25 @@ class TXEpgSchedulesList {
693
844
  */
694
845
  class TXEpgProviderContainer {
695
846
  /** @type {Object} */
696
- #_host;// = null;
847
+ #_host;
697
848
  /** @type {OPT_epgelsett_bs} */
698
- #_options;// = null;
849
+ #_options;
699
850
  /** @type {TXmlContentParseOptions} */
700
- #_parseOptions;// = null;
701
- /** @type {?TXEpgDTSProvider} */
851
+ #_parseOptions;
702
852
 
703
853
  /**
854
+ * Creates an instance of the EPG-provider element
704
855
  * @param {object} obj - host object
705
856
  * @param {OPT_epgelsett_bs} [opt] - options
706
- * @description Creates an instance of the EPG-provider element
707
857
  */
708
858
  constructor(obj, opt) {
709
859
  // load content
710
860
  const _host = isPlainObject(obj) ? obj : {};
711
861
  // load options
712
- /** @type {OPT_epgelsett_bs} */
713
- const _options = isPlainObject(opt) ? opt : {};
862
+ const _options = __evalXMLBaseNodeSettings(opt);
714
863
  let {
715
864
  parseOptions,
716
865
  } = _options;
717
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
718
- parseOptions = new TXmlContentParseOptions(parseOptions);
719
- _options.parseOptions = parseOptions;
720
- };
721
866
  // save options
722
867
  this.#_options = _options;
723
868
  // save parser options
@@ -807,9 +952,9 @@ class TXEpgProviderContainer {
807
952
  }
808
953
 
809
954
  /**
955
+ * Sets a provider name
810
956
  * @param {string} value - provider name
811
957
  * @returns {boolean}
812
- * @description Sets a provider name
813
958
  */
814
959
  setName(value) {
815
960
  let isSucceed = false;
@@ -824,8 +969,8 @@ class TXEpgProviderContainer {
824
969
  }
825
970
 
826
971
  /**
972
+ * Returns a provider info item
827
973
  * @returns {xepgProvInfoDesc}
828
- * @description Returns a provider info item
829
974
  */
830
975
  getInfo() {
831
976
  return {
@@ -837,9 +982,9 @@ class TXEpgProviderContainer {
837
982
  }
838
983
 
839
984
  /**
985
+ * Sets a provider info
840
986
  * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
841
987
  * @returns {void}
842
- * @description Sets a provider info
843
988
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
844
989
  */
845
990
  setInfo(obj) {
@@ -874,9 +1019,9 @@ class TXEpgProviderContainer {
874
1019
  }
875
1020
 
876
1021
  /**
1022
+ * Sets an initial instance state
877
1023
  * @param {(xepgProvInfoDesc|string[])} opt - options
878
1024
  * @returns {void}
879
- * @description Sets an initial instance state
880
1025
  */
881
1026
  init(opt) {
882
1027
  let prov_opt = { ...defXEpgDocOptions.defProviderParam };
@@ -901,35 +1046,50 @@ class TXEpgProviderContainer {
901
1046
  }
902
1047
 
903
1048
  /**
1049
+ * Returns an instance content as a string in an XML-format.
904
1050
  * @since v0.0.20
905
1051
  * @returns {string}
906
- * @description Returns an instance content as a string in an XML-format.
907
1052
  */
908
1053
  saveToXMLString() {
909
1054
  const options = this.#_parseOptions.js2xml;
910
1055
  options.ignoreDocType = true;
911
1056
  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;
1057
+ return serializeXObjToXMLString(
1058
+ this.#_host,
1059
+ options,
1060
+ XEPG_PRVINFO_ETAG_NAME,
1061
+ );
1062
+ }
1063
+
1064
+ /**
1065
+ * Loads a element content from a string.
1066
+ * @since v0.0.24
1067
+ * @param {string} xmlString - some content
1068
+ * @returns {boolean}
1069
+ * @throws {Error}
1070
+ * @experimental
1071
+ */
1072
+ loadFromXMLString(xmlString) {
1073
+ const options = this.#_parseOptions.xml2js;
1074
+ options.ignoreDocType = true;
1075
+ options.ignoreDeclaration = true;
1076
+ return deserializeXObjFromXMLString(
1077
+ this.#_host,
1078
+ options,
1079
+ xmlString,
1080
+ XEPG_PRVINFO_ETAG_NAME,
1081
+ );
922
1082
  }
923
1083
 
924
1084
  };
925
1085
 
926
1086
  /**
1087
+ * A channel info descriptor
927
1088
  * @typedef {Object} xepgChnInfoDesc
928
1089
  * @property {string} chnid - channel ID
929
1090
  * @property {string} chname - channel name
930
1091
  * @property {string} [chngid] - channel 'Group ID'
931
1092
  * @property {string} [srcurl] - EPG-source URL
932
- * @description A channel info descriptor
933
1093
  */
934
1094
 
935
1095
  /**
@@ -938,32 +1098,27 @@ class TXEpgProviderContainer {
938
1098
  */
939
1099
  class TXEpgChannelContainer {
940
1100
  /** @type {object} */
941
- #_host;// = null;
1101
+ #_host;
942
1102
  /** @type {OPT_epgelsett_bs} */
943
- #_options;// = null;
1103
+ #_options;
944
1104
  /** @type {TXmlContentParseOptions} */
945
- #_parseOptions;// = null;
1105
+ #_parseOptions;
946
1106
  /** @type {string} */
947
- #_xepgSchema;// = null;
1107
+ #_xepgSchema;
948
1108
 
949
1109
  /**
1110
+ * Creates an instance of the channel element
950
1111
  * @param {object} obj - host object
951
1112
  * @param {OPT_epgelsett_bs} [opt] - options
952
- * @description Creates an instance of the channel element
953
1113
  */
954
1114
  constructor(obj, opt) {
955
1115
  // load content
956
1116
  const _host = isPlainObject(obj) ? obj : {};
957
1117
  // load options
958
- /** @type {OPT_epgelsett_bs} */
959
- const _options = isPlainObject(opt) ? opt : {};
1118
+ const _options = __evalXMLBaseNodeSettings(opt);
960
1119
  let {
961
1120
  parseOptions,
962
1121
  } = _options;
963
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
964
- parseOptions = new TXmlContentParseOptions(parseOptions);
965
- _options.parseOptions = parseOptions;
966
- };
967
1122
  // set document schema version
968
1123
  this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
969
1124
  // save options
@@ -1047,9 +1202,9 @@ class TXEpgChannelContainer {
1047
1202
  }
1048
1203
 
1049
1204
  /**
1205
+ * Tries to set a channel ID
1050
1206
  * @param {string} value - channel ID
1051
1207
  * @returns {boolean}
1052
- * @description Tries to set a channel ID
1053
1208
  */
1054
1209
  setID(value) {
1055
1210
  let isSucceed = false;
@@ -1068,8 +1223,8 @@ class TXEpgChannelContainer {
1068
1223
  }
1069
1224
 
1070
1225
  /**
1226
+ * Returns a channel info
1071
1227
  * @returns {xepgChnInfoDesc}
1072
- * @description Returns a channel info
1073
1228
  */
1074
1229
  getInfo() {
1075
1230
  const {
@@ -1088,9 +1243,9 @@ class TXEpgChannelContainer {
1088
1243
  }
1089
1244
 
1090
1245
  /**
1246
+ * Sets a channel info
1091
1247
  * @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
1092
1248
  * @returns {void}
1093
- * @description Sets a channel info
1094
1249
  */
1095
1250
  setInfo(obj) {
1096
1251
  let chnid = '';
@@ -1143,28 +1298,23 @@ class TXEpgChannelContainer {
1143
1298
  */
1144
1299
  class TXEpgDTSProvider {
1145
1300
  /** @type {object} */
1146
- #_content;// = null;
1301
+ #_content;
1147
1302
  /** @type {OPT_epgelsett_bs} */
1148
- #_options;// = null;
1303
+ #_options;
1149
1304
 
1150
1305
  /**
1306
+ * Creates an instance of the DTS-provider element
1151
1307
  * @param {object} obj - host object
1152
1308
  * @param {OPT_epgelsett_bs} [opt] - options
1153
- * @description Creates an instance of the DTS-provider element
1154
1309
  */
1155
1310
  constructor(obj, opt) {
1156
1311
  // load content
1157
1312
  const _content = isPlainObject(obj) ? obj : {};
1158
1313
  // load options
1159
- /** @type {OPT_epgelsett_bs} */
1160
- let _options = isPlainObject(opt) ? opt : {};
1314
+ const _options = __evalXMLBaseNodeSettings(opt);
1161
1315
  let {
1162
1316
  parseOptions,
1163
1317
  } = _options;
1164
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1165
- parseOptions = new TXmlContentParseOptions(parseOptions);
1166
- _options.parseOptions = parseOptions;
1167
- };
1168
1318
  // save content source
1169
1319
  this.#_content = _content;
1170
1320
  // save options
@@ -1222,10 +1372,10 @@ class TXEpgDTSProvider {
1222
1372
  }
1223
1373
 
1224
1374
  /**
1375
+ * Tries to set a `DTS`-type
1225
1376
  * @since 0.0.22
1226
1377
  * @property {(number|string)} value - dtstype ID
1227
1378
  * @returns {boolean}
1228
- * @description Tries to set a `DTS`-type
1229
1379
  */
1230
1380
  setType(value) {
1231
1381
  let { index, name } = getDTSysDescr(value);
@@ -1257,32 +1407,27 @@ class TXEpgDTSProvider {
1257
1407
  */
1258
1408
  class TXEpgHeaderContainer {
1259
1409
  /** @type {Object} */
1260
- #_host;// = null;
1410
+ #_host;
1261
1411
  /** @type {OPT_epgelsett_bs} */
1262
- #_options;// = null;
1412
+ #_options;
1263
1413
  /** @type {TXmlContentParseOptions} */
1264
- #_parseOptions;// = null;
1414
+ #_parseOptions;
1265
1415
  /** @type {TXEpgDTSProvider} */
1266
- #_dtsProv;// = null;
1416
+ #_dtsProv;
1267
1417
 
1268
1418
  /**
1419
+ * Creates an instance of the EPG-header element
1269
1420
  * @param {object} obj - host element
1270
1421
  * @param {OPT_epgelsett_bs} [opt] - options
1271
- * @description Creates an instance of the EPG-header element
1272
1422
  */
1273
1423
  constructor(obj, opt) {
1274
1424
  // load content
1275
1425
  const _host = isPlainObject(obj) ? obj : {};
1276
1426
  // load options
1277
- /** @type {OPT_epgelsett_bs} */
1278
- const _options = isPlainObject(opt) ? opt : {};
1427
+ const _options = __evalXMLBaseNodeSettings(opt);
1279
1428
  let {
1280
1429
  parseOptions,
1281
1430
  } = _options;
1282
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1283
- parseOptions = new TXmlContentParseOptions(parseOptions);
1284
- _options.parseOptions = parseOptions;
1285
- };
1286
1431
  // save options
1287
1432
  this.#_options = _options;
1288
1433
  // save parser options
@@ -1355,6 +1500,7 @@ class TXEpgHeaderContainer {
1355
1500
  * @type {?TXEpgProviderContainer}
1356
1501
  * @readonly
1357
1502
  * @deprecated
1503
+ * @todo \[since `v0.0.22`] deprecated. Use `TXEpgHeaderContainer.provider`
1358
1504
  */
1359
1505
  get Provider() {
1360
1506
  return this.provider;
@@ -1386,8 +1532,8 @@ class TXEpgHeaderContainer {
1386
1532
  }
1387
1533
 
1388
1534
  /**
1535
+ * Returns a document creation date as a timestamp
1389
1536
  * @returns {number}
1390
- * @description Returns a document creation date as a timestamp
1391
1537
  */
1392
1538
  getDocumentDT() {
1393
1539
  let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTO_ETAG_NAME).trim();
@@ -1399,8 +1545,8 @@ class TXEpgHeaderContainer {
1399
1545
  }
1400
1546
 
1401
1547
  /**
1548
+ * Sets a document creation date to a current system time
1402
1549
  * @returns {void}
1403
- * @description Sets a document creation date to a current system time
1404
1550
  */
1405
1551
  setDocumentDT() {
1406
1552
  let dt_str = convDTValueToString(Date.now(), this.dtstype, this.curDocTZ);
@@ -1415,8 +1561,8 @@ class TXEpgHeaderContainer {
1415
1561
  }
1416
1562
 
1417
1563
  /**
1564
+ * Returns a document expire date as a timestamp
1418
1565
  * @returns {number}
1419
- * @description Returns a document expire date as a timestamp
1420
1566
  */
1421
1567
  getDocumentEDT() {
1422
1568
  let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTE_ETAG_NAME).trim();
@@ -1428,9 +1574,9 @@ class TXEpgHeaderContainer {
1428
1574
  }
1429
1575
 
1430
1576
  /**
1577
+ * Sets a document expire date to a given time
1431
1578
  * @param {any} value - document expire date
1432
1579
  * @returns {void}
1433
- * @description Sets a document expire date to a given time
1434
1580
  */
1435
1581
  setDocumentEDT(value) {
1436
1582
  // TODO: check if value is a DateTime-string
@@ -1446,8 +1592,8 @@ class TXEpgHeaderContainer {
1446
1592
  }
1447
1593
 
1448
1594
  /**
1595
+ * Returns a channel info
1449
1596
  * @returns {xepgChnInfoDesc}
1450
- * @description Returns a channel info
1451
1597
  */
1452
1598
  getChannelInfo() {
1453
1599
  return this.channel.getInfo();
@@ -1459,7 +1605,7 @@ class TXEpgHeaderContainer {
1459
1605
  * @description Sets a channel info
1460
1606
  * @deprecated
1461
1607
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
1462
- * @todo [since v0.0.22] deprecated
1608
+ * @todo [since v0.0.22] deprecated. Use `TXEpgChannelContainer.setInfo`
1463
1609
  */
1464
1610
  setChannelInfo(obj) {
1465
1611
  let _obj = obj;
@@ -1472,20 +1618,22 @@ class TXEpgHeaderContainer {
1472
1618
  }
1473
1619
 
1474
1620
  /**
1621
+ * Returns a provider info
1475
1622
  * @returns {?xepgProvInfoDesc}
1476
- * @description Returns a provider info
1477
1623
  */
1478
- getProviderInfo(){
1624
+ getProviderInfo() {
1479
1625
  const docProv = this.provider;
1480
1626
  return docProv ? docProv.getInfo() : null;
1481
1627
  }
1482
1628
 
1483
1629
  /**
1630
+ * Sets a provider info
1484
1631
  * @param {xepgProvInfoDesc} obj - provider info descriptor
1485
1632
  * @returns {void}
1486
- * @description Sets a provider info
1633
+ * @deprecated
1634
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgProviderContainer.setInfo`
1487
1635
  */
1488
- setProviderInfo(obj){
1636
+ setProviderInfo(obj) {
1489
1637
  if (isArray(obj) || isObject(obj)) {
1490
1638
  let docProv = this.provider;
1491
1639
  if (!docProv) {
@@ -1497,29 +1645,45 @@ class TXEpgHeaderContainer {
1497
1645
  }
1498
1646
 
1499
1647
  /**
1648
+ * Returns an instance content as a string in an XML-format.
1500
1649
  * @since v0.0.20
1501
1650
  * @returns {string}
1502
- * @description Returns an instance content as a string in an XML-format.
1503
1651
  */
1504
1652
  saveToXMLString() {
1505
1653
  const options = this.#_parseOptions.js2xml;
1506
1654
  options.ignoreDocType = true;
1507
1655
  options.ignoreDeclaration = true;
1508
- const content = { [`${XEPG_HEADER_ETAG_NAME}`]: this.#_host };
1509
- let result = '';
1510
- try {
1511
- result = xmlParser.js2xml(content, options);
1512
- } catch (err) {
1513
- //console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
1514
- result = '';
1515
- //throw err;
1516
- };
1517
- return result;
1656
+ return serializeXObjToXMLString(
1657
+ this.#_host,
1658
+ options,
1659
+ XEPG_HEADER_ETAG_NAME,
1660
+ );
1661
+ }
1662
+
1663
+ /**
1664
+ * Loads an element content from a string.
1665
+ * @since v0.0.24
1666
+ * @param {string} xmlString - some content
1667
+ * @returns {boolean}
1668
+ * @throws {Error}
1669
+ * @experimental
1670
+ */
1671
+ loadFromXMLString(xmlString) {
1672
+ const options = this.#_parseOptions.xml2js;
1673
+ options.ignoreDocType = true;
1674
+ options.ignoreDeclaration = true;
1675
+ return deserializeXObjFromXMLString(
1676
+ this.#_host,
1677
+ options,
1678
+ xmlString,
1679
+ XEPG_HEADER_ETAG_NAME,
1680
+ );
1518
1681
  }
1519
1682
 
1520
1683
  };
1521
1684
 
1522
1685
  /**
1686
+ * A fs ops description.
1523
1687
  * @typedef {Object} fsoDescr
1524
1688
  * @property {boolean} isERR - flag
1525
1689
  * @property {number} [errCode] - error code
@@ -1527,14 +1691,14 @@ class TXEpgHeaderContainer {
1527
1691
  * @property {string} [errMsg] - event message
1528
1692
  * @property {string} [source] - path to file
1529
1693
  * @property {any} [content] - file content
1530
- * @description A fs ops description.
1531
1694
  */
1532
1695
 
1533
1696
  /**
1697
+ * An options set for `TXEpgContentProvider`-class
1534
1698
  * @typedef {Object} OPT_epgcpsett
1535
1699
  * @property {TXmlContentParseOptions} [parseOptions] - parser options
1536
1700
  * @property {boolean} [autoBindRoot] - <*deprecated*>
1537
- * @description An options set for `TXEpgContentProvider`-class
1701
+ */
1538
1702
 
1539
1703
  /**
1540
1704
  * @classdesc This class implements an interface of the container
@@ -1542,28 +1706,24 @@ class TXEpgHeaderContainer {
1542
1706
  */
1543
1707
  class TXEpgContentProvider {
1544
1708
  /** @type {Object} */
1545
- #_content;// = null;
1709
+ #_content;
1546
1710
  /** @type {OPT_epgcpsett} */
1547
- #_options;// = null;
1711
+ #_options;
1548
1712
  /** @type {TXmlContentParseOptions} */
1549
- #_parseOptions;// = null;
1713
+ #_parseOptions;
1550
1714
 
1551
1715
  /**
1716
+ * Creates an instance of the XEPG-content provider
1552
1717
  * @param {OPT_epgcpsett} [opt] - options
1553
- * @description Creates an instance of the XEPG-content provider
1554
1718
  */
1555
1719
  constructor(opt) {
1556
1720
  // load options
1721
+ const _options = __evalXMLBaseNodeSettings(opt);
1557
1722
  /** @type {OPT_epgcpsett} */
1558
- const _options = isPlainObject(opt) ? opt : {};
1559
1723
  let {
1560
1724
  parseOptions,
1561
1725
  autoBindRoot, // <*reserved*> ([?] - deprecate)
1562
1726
  } = _options;
1563
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1564
- parseOptions = new TXmlContentParseOptions(parseOptions);
1565
- _options.parseOptions = parseOptions;
1566
- };
1567
1727
  if (typeof autoBindRoot !== 'boolean') autoBindRoot = false;
1568
1728
  // save options
1569
1729
  //_options.autoBindRoot = autoBindRoot; //* // TODO:
@@ -1668,14 +1828,10 @@ class TXEpgContentProvider {
1668
1828
  * @type {?TXEpgHeaderContainer}
1669
1829
  * @readonly
1670
1830
  * @deprecated
1831
+ * @todo \[since `v0.0.22`] deprecated. Use `TXEpgContentProvider.header`
1671
1832
  */
1672
1833
  get Header() {
1673
- const docHdr = this.#_getHdr();
1674
- return (
1675
- docHdr
1676
- ? new TXEpgHeaderContainer(docHdr, this.#_options)
1677
- : null
1678
- );
1834
+ return this.header;
1679
1835
  }
1680
1836
 
1681
1837
  /**
@@ -1698,10 +1854,10 @@ class TXEpgContentProvider {
1698
1854
  * @type {?TXEpgProviderContainer}
1699
1855
  * @readonly
1700
1856
  * @deprecated
1857
+ * @todo \[since `v0.0.22`] deprecated. Use `TXEpgContentProvider.provider`
1701
1858
  */
1702
1859
  get Provider() {
1703
- const docHdr = this.header;
1704
- return docHdr ? docHdr.provider : null;
1860
+ return this.provider;
1705
1861
  }
1706
1862
 
1707
1863
  /**
@@ -1735,8 +1891,20 @@ class TXEpgContentProvider {
1735
1891
  * Returns a `TXEpgSchedulesList` instance
1736
1892
  * @type {TXEpgSchedulesList}
1737
1893
  * @readonly
1894
+ * @deprecated
1895
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgContentProvider.schedules`
1738
1896
  */
1739
1897
  get SchedulesList() {
1898
+ return this.schedules;
1899
+ }
1900
+
1901
+ /**
1902
+ * Returns a `TXEpgSchedulesList` instance
1903
+ * @since 0.0.24
1904
+ * @type {TXEpgSchedulesList}
1905
+ * @readonly
1906
+ */
1907
+ get schedules() {
1740
1908
  const _options = this.#_options;
1741
1909
  const docBody = this.#_getBody();
1742
1910
  if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
@@ -1791,8 +1959,8 @@ class TXEpgContentProvider {
1791
1959
  }
1792
1960
 
1793
1961
  /**
1962
+ * Returns a document content as a string in an XML-format.
1794
1963
  * @returns {string}
1795
- * @description Returns a document content as a string in an XML-format.
1796
1964
  */
1797
1965
  saveToXMLString() {
1798
1966
  let result = '';
@@ -1806,11 +1974,11 @@ class TXEpgContentProvider {
1806
1974
  }
1807
1975
 
1808
1976
  /**
1977
+ * Saves a document content to a file.
1809
1978
  * @param {string} source - a path to a file
1810
1979
  * @returns {Promise<fsoDescr, Error>}
1811
1980
  * @throws {Error}
1812
1981
  * @async
1813
- * @description Saves a document content to a file.
1814
1982
  */
1815
1983
  saveToFile(source) {
1816
1984
  /**/// main part that return promise as a result
@@ -1847,9 +2015,9 @@ class TXEpgContentProvider {
1847
2015
  }
1848
2016
 
1849
2017
  /**
2018
+ * Saves a document content to a file.
1850
2019
  * @param {string} source - path to a file
1851
2020
  * @returns {fsoDescr}
1852
- * @description Saves a document content to a file.
1853
2021
  */
1854
2022
  saveToFileSync(source) {
1855
2023
  /** @type {fsoDescr} */
@@ -1876,11 +2044,11 @@ class TXEpgContentProvider {
1876
2044
  }
1877
2045
 
1878
2046
  /**
2047
+ * Loads a document content from a string.
1879
2048
  * @since 0.0.18
1880
2049
  * @param {string} xmlString - a document content in XML-format
1881
2050
  * @returns {boolean}
1882
2051
  * @throws {Error}
1883
- * @description Loads a document content from a string.
1884
2052
  */
1885
2053
  loadFromXMLString(xmlString) {
1886
2054
  let isSUCCEED = false;
@@ -1913,18 +2081,11 @@ class TXEpgContentProvider {
1913
2081
  }
1914
2082
 
1915
2083
  /**
1916
- * @deprecated
1917
- */
1918
- loadFromString(...args){
1919
- return this.loadFromXMLString(...args);
1920
- }
1921
-
1922
- /**
2084
+ * Loads a document content from a file.
1923
2085
  * @param {string} source - path to a file
1924
2086
  * @returns {Promise<fsoDescr, Error>}
1925
2087
  * @throws {Error}
1926
2088
  * @async
1927
- * @description Loads a document content from a file.
1928
2089
  */
1929
2090
  loadFromFile(source) {
1930
2091
  /**/// main part that return promise as a result
@@ -1955,9 +2116,9 @@ class TXEpgContentProvider {
1955
2116
  }
1956
2117
 
1957
2118
  /**
2119
+ * Loads a document content from a file.
1958
2120
  * @param {string} source - path to a file
1959
2121
  * @returns {fsoDescr}
1960
- * @description Loads a document content from a file.
1961
2122
  */
1962
2123
  loadFromFileSync(source) {
1963
2124
  const data = loadFromFileSync(source);
@@ -2006,6 +2167,3 @@ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
2006
2167
  module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
2007
2168
  module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
2008
2169
  module.exports.TXEpgContentProvider = TXEpgContentProvider;
2009
-
2010
- /** @deprecated */
2011
- module.exports.TXepgDTSProvider = TXEpgDTSProvider;