@ygracs/xepg-lib-js 0.0.23 → 0.0.25

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.128-20250825]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -36,7 +36,13 @@ const {
36
36
  writeXObjAttr,
37
37
  } = xObj;
38
38
 
39
- // === module extra block (helper functions) ===
39
+ const {
40
+ readAsTagName,
41
+ readAsAttrName,
42
+ valueToElementID,
43
+ } = require('./xml-base');
44
+
45
+ // === module inner block ===
40
46
 
41
47
  /*
42
48
  * === xObj-function wrappers (start) ===
@@ -50,6 +56,10 @@ function readXObjParam(obj){
50
56
  * === xObj-function wrappers (end) ===
51
57
  */
52
58
 
59
+ /***
60
+ * (* helper function definitions *)
61
+ */
62
+
53
63
  /**
54
64
  * @param {object} obj - element
55
65
  * @param {string} name - child element name
@@ -95,6 +105,94 @@ function writeXEpgDocDeclSection(obj, data) {
95
105
  };
96
106
  };
97
107
 
108
+ /**
109
+ * Returns an object as a string in an XML-format.
110
+ * @since v0.0.24
111
+ * @function serializeXObjToXMLString
112
+ * @param {object} node - some element
113
+ * @param {object} opt - parser options
114
+ * @param {string} tagName - element tag name
115
+ * @returns {string}
116
+ * @inner
117
+ */
118
+ function serializeXObjToXMLString(node, opt, tagName) {
119
+ let result = '';
120
+ try {
121
+ result = xmlParser.js2xml({ [tagName]: node }, opt);
122
+ } catch (err) {
123
+ //console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
124
+ result = '';
125
+ //throw err;
126
+ };
127
+ return result;
128
+ };
129
+
130
+ /**
131
+ * Loads an object content from an XML-string.
132
+ * @since v0.0.24
133
+ * @function deserializeXObjFromXMLString
134
+ * @param {object} node - some element
135
+ * @param {object} opt - parser options
136
+ * @param {string} text - some content
137
+ * @param {string} tagName - element tag name
138
+ * @returns {boolean}
139
+ * @throws {Error}
140
+ * @inner
141
+ * @experimental
142
+ */
143
+ function deserializeXObjFromXMLString(node, opt, text, tagName) {
144
+ let result = false;
145
+ if (typeof text === 'string' && text !== '') {
146
+ try {
147
+ let obj = xmlParser.xml2js(text, opt);
148
+ if (isPlainObject(obj)) {
149
+ obj = obj[tagName];
150
+ if (isPlainObject(obj)) {
151
+ for (let prop in node) {
152
+ // // TODO: catch errors in strict mode
153
+ delete node[prop];
154
+ };
155
+ (Object.entries(obj)).forEach(([key, value]) => {
156
+ node[key] = value;
157
+ });
158
+ result = true;
159
+ };
160
+ };
161
+ } catch (err) {
162
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
163
+ //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
164
+ throw err;
165
+ };
166
+ };
167
+ return result;
168
+ };
169
+
170
+ /**
171
+ * An XEPG-element options set (base)
172
+ * @typedef {Object} OPT_epgelsett_bs
173
+ * @property {TXmlContentParseOptions} [parseOptions] - parser options
174
+ */
175
+
176
+ /**
177
+ * Evaluates an XML-node base settings
178
+ * @function __evalXMLBaseNodeSettings
179
+ * @param {any} value - element settings to evaluate
180
+ * @returns {OPT_epgelsett_bs}
181
+ * @inner
182
+ */
183
+ function __evalXMLBaseNodeSettings(value) {
184
+ /** @type {OPT_epgelsett_bs} */
185
+ let settings = isPlainObject(value) ? value : {};
186
+ if (settings instanceof Map) settings = Object.fromEntries(settings);
187
+ let {
188
+ parseOptions,
189
+ } = settings;
190
+ if (!(parseOptions instanceof TXmlContentParseOptions)) {
191
+ settings.parseOptions = new TXmlContentParseOptions(parseOptions);
192
+ };
193
+ return settings;
194
+ };
195
+
98
196
  // === module main block ===
99
197
 
100
198
  /***
@@ -160,101 +258,33 @@ const defParseOptions = new TXmlContentParseOptions();
160
258
  * (* function definitions *)
161
259
  */
162
260
 
163
- /**
164
- * @since v0.0.23
165
- * @function readAsTagName
166
- * @param {any} value - some value
167
- * @returns {string}
168
- * @description Tries to convert a given value to a valid tag name
169
- * of an XML-element.
170
- */
171
- function readAsTagName(value) {
172
- let tagName = valueToIDString(value, { ignoreNumbers: true });
173
- if (tagName === null) return '';
174
- if (tagName !== '') {
175
- // // TODO: do extra checks
176
- const template = /[\s\/\\\"\'<>=]/;
177
- const trigger = tagName.match(template);
178
- if (trigger) {
179
- //console.log(trigger);
180
- tagName = '';
181
- };
182
- };
183
- return tagName;
184
- };
185
-
186
- /**
187
- * @since v0.0.23
188
- * @function readAsAttrName
189
- * @param {any} value - some value
190
- * @returns {string}
191
- * @description Tries to convert a given value to a valid name
192
- * of an XML-attribute.
193
- */
194
- function readAsAttrName(value) {
195
- let attrName = valueToIDString(value, { ignoreNumbers: true });
196
- if (attrName === null) return '';
197
- if (attrName !== '') {
198
- // // TODO: do extra checks
199
- const template = /[\s\/\\\"\'<>=]/;
200
- const trigger = attrName.match(template);
201
- if (trigger) {
202
- //console.log(trigger);
203
- attrName = '';
204
- };
205
- };
206
- return attrName;
207
- };
208
-
209
- /**
210
- * @since v0.0.23
211
- * @function valueToElementID
212
- * @param {any} value - some value
213
- * @returns {string}
214
- * @description Tries to convert a given value to a valid identifier
215
- * suitable as a value for an "ID-attribute" of an XML-element.
216
- */
217
- function valueToElementID(value) {
218
- let id = valueToIDString(value);
219
- if (id === null) return '';
220
- if (id !== '') {
221
- // // TODO: do extra checks
222
- const template = /[\s\/\\\"\'<>=]/;
223
- const trigger = id.match(template);
224
- if (trigger) {
225
- //console.log(trigger);
226
- id = '';
227
- };
228
- };
229
- return id;
230
- };
231
-
232
261
  /***
233
262
  * (* class definitions *)
234
263
  */
235
264
 
236
265
  /**
266
+ * A schedule info descriptor
237
267
  * @typedef {Object} xepgShedInfoDesc
238
268
  * @property {number} time - a schedule start time
239
269
  * @property {string} title - schedule title
240
270
  * @property {string} [cat] - schedule category
241
271
  * @property {number} [pcmark] - schedule rating
242
272
  * @property {string} [descr] - schedule description
243
- * @description A schedule info descriptor
244
273
  */
245
274
 
246
275
  /**
247
- * @typedef {Object} OPT_epgelsett_bs
248
- * @property {TXmlContentParseOptions} [parseOptions] - parser options
249
- * @description An XEPG-element options set (base)
276
+ * An extra options set
277
+ * @typedef {Object} OPT_extra
278
+ * @property {object} [dts_src] - 'DTS'-settings
279
+ * @property {object} [tz_src] - 'TZ'-settings
250
280
  */
251
281
 
252
282
  /**
283
+ * An XEPG-element options set (extend)
253
284
  * @typedef {Object} OPT_epgelsett_ex
254
285
  * @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)
286
+ * @property {object} [dts_src]
287
+ * @property {object} [tz_src]
258
288
  */
259
289
 
260
290
  /**
@@ -263,22 +293,23 @@ function valueToElementID(value) {
263
293
  */
264
294
  class TXEpgScheduleItem {
265
295
  /** @type {object} */
266
- #_host;// = null;
296
+ #_host;
267
297
  /** @type {OPT_epgelsett_ex} */
268
- #_options;// = null;
298
+ #_options;
269
299
  /** @type {TXmlContentParseOptions} */
270
- #_parseOptions;// = null;
300
+ #_parseOptions;
271
301
  /** @type {?object} */
272
302
  #_dts_src = null;
273
303
  /** @type {?object} */
274
304
  #_tz_src = null;
275
305
 
276
306
  /**
307
+ * Creates an instance of the EPG-schedule element
277
308
  * @param {object} obj - host object
278
309
  * @param {OPT_epgelsett_ex} [opt] - options
279
- * @description Creates an instance of the EPG-schedule element
310
+ * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
280
311
  */
281
- constructor(obj, opt) {
312
+ constructor(obj, opt, extra) {
282
313
  // load content
283
314
  const _host = isPlainObject(obj) ? obj : {};
284
315
  // load options
@@ -286,12 +317,15 @@ class TXEpgScheduleItem {
286
317
  const _options = isPlainObject(opt) ? opt : {};
287
318
  let {
288
319
  parseOptions,
289
- dts_src, tz_src,
290
320
  } = _options;
291
321
  if (!(parseOptions instanceof TXmlContentParseOptions)) {
292
322
  parseOptions = new TXmlContentParseOptions(parseOptions);
293
323
  _options.parseOptions = parseOptions;
294
324
  };
325
+ let {
326
+ dts_src = _options.dts_src,
327
+ tz_src = _options.tz_src,
328
+ } = isPlainObject(extra) ? extra : {};
295
329
  if (!isPlainObject(dts_src)) dts_src = null;
296
330
  if (!isPlainObject(tz_src)) tz_src = null;
297
331
  // save content source
@@ -378,8 +412,8 @@ class TXEpgScheduleItem {
378
412
  }
379
413
 
380
414
  /**
415
+ * Returns a schedule info item descriptor
381
416
  * @returns {xepgShedInfoDesc}
382
- * @description Returns a schedule info item descriptor
383
417
  */
384
418
  getInfo() {
385
419
  const {
@@ -399,9 +433,9 @@ class TXEpgScheduleItem {
399
433
  }
400
434
 
401
435
  /**
436
+ * Sets a schedule start time.
402
437
  * @param {(number|string|Date)} value - some time value
403
438
  * @returns {boolean}
404
- * @description Sets a schedule start time.
405
439
  */
406
440
  setTime(value) {
407
441
  let { isSucceed, value: dtValue } = tryDTValue(value);
@@ -420,9 +454,9 @@ class TXEpgScheduleItem {
420
454
  }
421
455
 
422
456
  /**
457
+ * Sets a schedule title.
423
458
  * @param {string} value - some title
424
459
  * @returns {boolean}
425
- * @description Sets a schedule title.
426
460
  */
427
461
  setTitle(value) {
428
462
  let result = false;
@@ -437,9 +471,9 @@ class TXEpgScheduleItem {
437
471
  }
438
472
 
439
473
  /**
474
+ * Sets a schedule title.
440
475
  * @param {string} value - some title
441
476
  * @returns {boolean}
442
- * @description Sets a schedule title.
443
477
  */
444
478
  setCategory(value) {
445
479
  let result = false;
@@ -454,9 +488,9 @@ class TXEpgScheduleItem {
454
488
  }
455
489
 
456
490
  /**
491
+ * Sets a schedule rating value.
457
492
  * @param {(number|string)} value - some value
458
493
  * @returns {boolean}
459
- * @description Sets a schedule rating value.
460
494
  */
461
495
  setRating(value) {
462
496
  const _value = valueToIndex(value);
@@ -472,9 +506,9 @@ class TXEpgScheduleItem {
472
506
  }
473
507
 
474
508
  /**
509
+ * Sets a schedule description.
475
510
  * @param {string} value - some text
476
511
  * @returns {boolean}
477
- * @description Sets a schedule description.
478
512
  */
479
513
  setDescr(value) {
480
514
  let result = false;
@@ -489,23 +523,38 @@ class TXEpgScheduleItem {
489
523
  }
490
524
 
491
525
  /**
526
+ * Returns an instance content as a string in an XML-format.
492
527
  * @returns {string}
493
- * @description Returns an instance content as a string in an XML-format.
494
528
  */
495
529
  saveToXMLString() {
496
530
  const options = this.#_parseOptions.js2xml;
497
531
  options.ignoreDocType = true;
498
532
  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;
533
+ return serializeXObjToXMLString(
534
+ this.#_host,
535
+ options,
536
+ XEPG_SCHED_ETAG_NAME,
537
+ );
538
+ }
539
+
540
+ /**
541
+ * Loads an element content from a string.
542
+ * @since v0.0.24
543
+ * @param {string} xmlString - some content
544
+ * @returns {boolean}
545
+ * @throws {Error}
546
+ * @experimental
547
+ */
548
+ loadFromXMLString(xmlString) {
549
+ const options = this.#_parseOptions.xml2js;
550
+ options.ignoreDocType = true;
551
+ options.ignoreDeclaration = true;
552
+ return deserializeXObjFromXMLString(
553
+ this.#_host,
554
+ options,
555
+ xmlString,
556
+ XEPG_SCHED_ETAG_NAME,
557
+ );
509
558
  }
510
559
 
511
560
  };
@@ -515,24 +564,28 @@ class TXEpgScheduleItem {
515
564
  */
516
565
  class TXEpgSchedulesList {
517
566
  /** @type {object[]} */
518
- #_content;// = null;
567
+ #_content;
519
568
  /** @type {OPT_epgelsett_ex} */
520
- #_options;// = null;
569
+ #_options;
521
570
  /** @type {?object} */
522
571
  #_dts_src = null;
523
572
  /** @type {?object} */
524
573
  #_tz_src = null;
525
574
 
526
575
  /**
576
+ * Creates an instance of the schedules list
527
577
  * @param {any[]} obj - list of an elements
528
578
  * @param {OPT_epgelsett_ex} [opt] - options
529
- * @description Creates an instance of the schedules list
579
+ * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
530
580
  */
531
- constructor(obj, opt) {
581
+ constructor(obj, opt, extra) {
532
582
  const _content = isArray(obj) ? obj : [];
533
583
  /** @type {OPT_epgelsett_ex} */
534
584
  const _options = isPlainObject(opt) ? opt : {};
535
- let { dts_src, tz_src } = _options;
585
+ let {
586
+ dts_src = _options.dts_src,
587
+ tz_src = _options.tz_src,
588
+ } = isPlainObject(extra) ? extra : {};
536
589
  if (!isPlainObject(dts_src)) dts_src = null;
537
590
  if (!isPlainObject(tz_src)) tz_src = null;
538
591
  // save content source
@@ -544,11 +597,27 @@ class TXEpgSchedulesList {
544
597
  this.#_tz_src = tz_src;
545
598
  }
546
599
 
600
+ [Symbol.iterator]() {
601
+ let index = 0;
602
+ return {
603
+ next: () => {
604
+ if (index < this.count) {
605
+ return { done: false, value: this.schedule(index++) };
606
+ } else {
607
+ return { done: true, value: undefined };
608
+ };
609
+ },
610
+ return() {
611
+ return { done: true, value: undefined };
612
+ },
613
+ };
614
+ }
615
+
547
616
  /**
617
+ * Returns a raw schedule element
548
618
  * @param {(number|string)} value - element index
549
619
  * @returns {any}
550
620
  * @private
551
- * @description Returns a raw schedule element
552
621
  */
553
622
  #_getItem = function(value) {
554
623
  if (this.chkIndex(value)) {
@@ -560,11 +629,23 @@ class TXEpgSchedulesList {
560
629
  * Contains a quantity of a schedules
561
630
  * @type {number}
562
631
  * @readonly
632
+ * @deprecated
633
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.count`
563
634
  */
564
635
  get schedQty() {
565
636
  return this.#_content.length;
566
637
  }
567
638
 
639
+ /**
640
+ * Contains a quantity of a schedules
641
+ * @since v0.0.24
642
+ * @type {number}
643
+ * @readonly
644
+ */
645
+ get count() {
646
+ return this.#_content.length;
647
+ }
648
+
568
649
  /**
569
650
  * Contains a dtstype ID
570
651
  * @type {number}
@@ -588,51 +669,60 @@ class TXEpgSchedulesList {
588
669
  }
589
670
 
590
671
  /**
672
+ * Indicates whether an instance has none member
591
673
  * @returns {boolean}
592
- * @description Indicates whether an instance has none member
674
+ * @deprecated
675
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isEmpty`
593
676
  */
594
677
  hasNoSchedules() {
595
- return this.schedQty === 0;
678
+ return this.count === 0;
596
679
  }
597
680
 
598
681
  /**
682
+ * Indicates whether an instance has none member
683
+ * @since v0.0.24
599
684
  * @returns {boolean}
600
- * @description Indicates whether an instance has any member
601
685
  */
602
- hasSchedules() {
603
- return this.schedQty > 0;
686
+ isEmpty() {
687
+ return this.count === 0;
604
688
  }
605
689
 
606
690
  /**
607
- * @param {(number|string)} value
691
+ * Indicates whether an instance has any member
608
692
  * @returns {boolean}
609
693
  * @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
694
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isNotEmpty`
614
695
  */
615
- chkScheduleIndex(value) {
616
- return this.chkIndex(value);
696
+ hasSchedules() {
697
+ return this.count > 0;
617
698
  }
618
699
 
619
700
  /**
701
+ * Indicates whether an instance has any member
702
+ * @since v0.0.24
703
+ * @returns {boolean}
704
+ */
705
+ isNotEmpty() {
706
+ return this.count > 0;
707
+ }
708
+
709
+ /**
710
+ * Checks whether a given value is a valid index and it fits the index range
711
+ * of an instance
620
712
  * @since 0.0.20
621
713
  * @param {(number|string)} value - index of some element
622
714
  * @returns {boolean}
623
- * @description Checks whether a given value is a valid index
624
- * and it fits the index range of an instance
625
715
  */
626
716
  chkIndex(value) {
627
717
  const index = valueToIndex(value);
628
- return index !== -1 && index < this.schedQty;
718
+ return index !== -1 && index < this.count;
629
719
  }
630
720
 
631
721
  /**
722
+ * Returns a schedule element addressed by a given index
632
723
  * @since 0.0.22
633
724
  * @param {(number|string)} index - index of some element
634
725
  * @returns {?TXEpgScheduleItem}
635
- * @description Returns a schedule element addressed by a given index
636
726
  */
637
727
  schedule(index) {
638
728
  const curObj = this.#_getItem(index);
@@ -647,10 +737,10 @@ class TXEpgSchedulesList {
647
737
  }
648
738
 
649
739
  /**
740
+ * Returns a schedule info item for instance element addressed
741
+ * by a given index
650
742
  * @param {(number|string)} index - index of some element
651
743
  * @returns {?xepgShedInfoDesc}
652
- * @description Returns a schedule info item for instance element
653
- * addressed by a given index
654
744
  */
655
745
  getScheduleInfo(index) {
656
746
  const obj = this.schedule(index);
@@ -658,12 +748,12 @@ class TXEpgSchedulesList {
658
748
  }
659
749
 
660
750
  /**
751
+ * Returns a schedule info for instance members
661
752
  * @returns {xepgShedInfoDesc[]}
662
- * @description Returns a schedule info for instance members
663
753
  */
664
754
  getAllSchedulesInfo() {
665
755
  let result = [];
666
- for (let i = 0; i < this.schedQty; i++) {
756
+ for (let i = 0; i < this.count; i++) {
667
757
  let item = this.getScheduleInfo(i);
668
758
  if (isPlainObject(item)) result.push(item);
669
759
  };
@@ -680,12 +770,12 @@ class TXEpgSchedulesList {
680
770
  };
681
771
 
682
772
  /**
773
+ * A provider info descriptor
683
774
  * @typedef {Object} xepgProvInfoDesc
684
775
  * @property {string} [name] - provider name
685
776
  * @property {string} [version] - provider version
686
777
  * @property {string} schema - document schema
687
778
  * @property {string} doctype - document type
688
- * @description A provider info descriptor
689
779
  */
690
780
 
691
781
  /**
@@ -693,31 +783,25 @@ class TXEpgSchedulesList {
693
783
  */
694
784
  class TXEpgProviderContainer {
695
785
  /** @type {Object} */
696
- #_host;// = null;
786
+ #_host;
697
787
  /** @type {OPT_epgelsett_bs} */
698
- #_options;// = null;
788
+ #_options;
699
789
  /** @type {TXmlContentParseOptions} */
700
- #_parseOptions;// = null;
701
- /** @type {?TXEpgDTSProvider} */
790
+ #_parseOptions;
702
791
 
703
792
  /**
793
+ * Creates an instance of the EPG-provider element
704
794
  * @param {object} obj - host object
705
795
  * @param {OPT_epgelsett_bs} [opt] - options
706
- * @description Creates an instance of the EPG-provider element
707
796
  */
708
797
  constructor(obj, opt) {
709
798
  // load content
710
799
  const _host = isPlainObject(obj) ? obj : {};
711
800
  // load options
712
- /** @type {OPT_epgelsett_bs} */
713
- const _options = isPlainObject(opt) ? opt : {};
801
+ const _options = __evalXMLBaseNodeSettings(opt);
714
802
  let {
715
803
  parseOptions,
716
804
  } = _options;
717
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
718
- parseOptions = new TXmlContentParseOptions(parseOptions);
719
- _options.parseOptions = parseOptions;
720
- };
721
805
  // save options
722
806
  this.#_options = _options;
723
807
  // save parser options
@@ -807,9 +891,9 @@ class TXEpgProviderContainer {
807
891
  }
808
892
 
809
893
  /**
894
+ * Sets a provider name
810
895
  * @param {string} value - provider name
811
896
  * @returns {boolean}
812
- * @description Sets a provider name
813
897
  */
814
898
  setName(value) {
815
899
  let isSucceed = false;
@@ -824,8 +908,8 @@ class TXEpgProviderContainer {
824
908
  }
825
909
 
826
910
  /**
911
+ * Returns a provider info item
827
912
  * @returns {xepgProvInfoDesc}
828
- * @description Returns a provider info item
829
913
  */
830
914
  getInfo() {
831
915
  return {
@@ -837,9 +921,9 @@ class TXEpgProviderContainer {
837
921
  }
838
922
 
839
923
  /**
924
+ * Sets a provider info
840
925
  * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
841
926
  * @returns {void}
842
- * @description Sets a provider info
843
927
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
844
928
  */
845
929
  setInfo(obj) {
@@ -874,9 +958,9 @@ class TXEpgProviderContainer {
874
958
  }
875
959
 
876
960
  /**
961
+ * Sets an initial instance state
877
962
  * @param {(xepgProvInfoDesc|string[])} opt - options
878
963
  * @returns {void}
879
- * @description Sets an initial instance state
880
964
  */
881
965
  init(opt) {
882
966
  let prov_opt = { ...defXEpgDocOptions.defProviderParam };
@@ -901,35 +985,50 @@ class TXEpgProviderContainer {
901
985
  }
902
986
 
903
987
  /**
988
+ * Returns an instance content as a string in an XML-format.
904
989
  * @since v0.0.20
905
990
  * @returns {string}
906
- * @description Returns an instance content as a string in an XML-format.
907
991
  */
908
992
  saveToXMLString() {
909
993
  const options = this.#_parseOptions.js2xml;
910
994
  options.ignoreDocType = true;
911
995
  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;
996
+ return serializeXObjToXMLString(
997
+ this.#_host,
998
+ options,
999
+ XEPG_PRVINFO_ETAG_NAME,
1000
+ );
1001
+ }
1002
+
1003
+ /**
1004
+ * Loads a element content from a string.
1005
+ * @since v0.0.24
1006
+ * @param {string} xmlString - some content
1007
+ * @returns {boolean}
1008
+ * @throws {Error}
1009
+ * @experimental
1010
+ */
1011
+ loadFromXMLString(xmlString) {
1012
+ const options = this.#_parseOptions.xml2js;
1013
+ options.ignoreDocType = true;
1014
+ options.ignoreDeclaration = true;
1015
+ return deserializeXObjFromXMLString(
1016
+ this.#_host,
1017
+ options,
1018
+ xmlString,
1019
+ XEPG_PRVINFO_ETAG_NAME,
1020
+ );
922
1021
  }
923
1022
 
924
1023
  };
925
1024
 
926
1025
  /**
1026
+ * A channel info descriptor
927
1027
  * @typedef {Object} xepgChnInfoDesc
928
1028
  * @property {string} chnid - channel ID
929
1029
  * @property {string} chname - channel name
930
1030
  * @property {string} [chngid] - channel 'Group ID'
931
1031
  * @property {string} [srcurl] - EPG-source URL
932
- * @description A channel info descriptor
933
1032
  */
934
1033
 
935
1034
  /**
@@ -938,32 +1037,27 @@ class TXEpgProviderContainer {
938
1037
  */
939
1038
  class TXEpgChannelContainer {
940
1039
  /** @type {object} */
941
- #_host;// = null;
1040
+ #_host;
942
1041
  /** @type {OPT_epgelsett_bs} */
943
- #_options;// = null;
1042
+ #_options;
944
1043
  /** @type {TXmlContentParseOptions} */
945
- #_parseOptions;// = null;
1044
+ #_parseOptions;
946
1045
  /** @type {string} */
947
- #_xepgSchema;// = null;
1046
+ #_xepgSchema;
948
1047
 
949
1048
  /**
1049
+ * Creates an instance of the channel element
950
1050
  * @param {object} obj - host object
951
1051
  * @param {OPT_epgelsett_bs} [opt] - options
952
- * @description Creates an instance of the channel element
953
1052
  */
954
1053
  constructor(obj, opt) {
955
1054
  // load content
956
1055
  const _host = isPlainObject(obj) ? obj : {};
957
1056
  // load options
958
- /** @type {OPT_epgelsett_bs} */
959
- const _options = isPlainObject(opt) ? opt : {};
1057
+ const _options = __evalXMLBaseNodeSettings(opt);
960
1058
  let {
961
1059
  parseOptions,
962
1060
  } = _options;
963
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
964
- parseOptions = new TXmlContentParseOptions(parseOptions);
965
- _options.parseOptions = parseOptions;
966
- };
967
1061
  // set document schema version
968
1062
  this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
969
1063
  // save options
@@ -1047,9 +1141,9 @@ class TXEpgChannelContainer {
1047
1141
  }
1048
1142
 
1049
1143
  /**
1144
+ * Tries to set a channel ID
1050
1145
  * @param {string} value - channel ID
1051
1146
  * @returns {boolean}
1052
- * @description Tries to set a channel ID
1053
1147
  */
1054
1148
  setID(value) {
1055
1149
  let isSucceed = false;
@@ -1068,8 +1162,8 @@ class TXEpgChannelContainer {
1068
1162
  }
1069
1163
 
1070
1164
  /**
1165
+ * Returns a channel info
1071
1166
  * @returns {xepgChnInfoDesc}
1072
- * @description Returns a channel info
1073
1167
  */
1074
1168
  getInfo() {
1075
1169
  const {
@@ -1088,9 +1182,9 @@ class TXEpgChannelContainer {
1088
1182
  }
1089
1183
 
1090
1184
  /**
1185
+ * Sets a channel info
1091
1186
  * @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
1092
1187
  * @returns {void}
1093
- * @description Sets a channel info
1094
1188
  */
1095
1189
  setInfo(obj) {
1096
1190
  let chnid = '';
@@ -1143,28 +1237,23 @@ class TXEpgChannelContainer {
1143
1237
  */
1144
1238
  class TXEpgDTSProvider {
1145
1239
  /** @type {object} */
1146
- #_content;// = null;
1240
+ #_content;
1147
1241
  /** @type {OPT_epgelsett_bs} */
1148
- #_options;// = null;
1242
+ #_options;
1149
1243
 
1150
1244
  /**
1245
+ * Creates an instance of the DTS-provider element
1151
1246
  * @param {object} obj - host object
1152
1247
  * @param {OPT_epgelsett_bs} [opt] - options
1153
- * @description Creates an instance of the DTS-provider element
1154
1248
  */
1155
1249
  constructor(obj, opt) {
1156
1250
  // load content
1157
1251
  const _content = isPlainObject(obj) ? obj : {};
1158
1252
  // load options
1159
- /** @type {OPT_epgelsett_bs} */
1160
- let _options = isPlainObject(opt) ? opt : {};
1253
+ const _options = __evalXMLBaseNodeSettings(opt);
1161
1254
  let {
1162
1255
  parseOptions,
1163
1256
  } = _options;
1164
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1165
- parseOptions = new TXmlContentParseOptions(parseOptions);
1166
- _options.parseOptions = parseOptions;
1167
- };
1168
1257
  // save content source
1169
1258
  this.#_content = _content;
1170
1259
  // save options
@@ -1222,10 +1311,10 @@ class TXEpgDTSProvider {
1222
1311
  }
1223
1312
 
1224
1313
  /**
1314
+ * Tries to set a `DTS`-type
1225
1315
  * @since 0.0.22
1226
1316
  * @property {(number|string)} value - dtstype ID
1227
1317
  * @returns {boolean}
1228
- * @description Tries to set a `DTS`-type
1229
1318
  */
1230
1319
  setType(value) {
1231
1320
  let { index, name } = getDTSysDescr(value);
@@ -1257,32 +1346,27 @@ class TXEpgDTSProvider {
1257
1346
  */
1258
1347
  class TXEpgHeaderContainer {
1259
1348
  /** @type {Object} */
1260
- #_host;// = null;
1349
+ #_host;
1261
1350
  /** @type {OPT_epgelsett_bs} */
1262
- #_options;// = null;
1351
+ #_options;
1263
1352
  /** @type {TXmlContentParseOptions} */
1264
- #_parseOptions;// = null;
1353
+ #_parseOptions;
1265
1354
  /** @type {TXEpgDTSProvider} */
1266
- #_dtsProv;// = null;
1355
+ #_dtsProv;
1267
1356
 
1268
1357
  /**
1358
+ * Creates an instance of the EPG-header element
1269
1359
  * @param {object} obj - host element
1270
1360
  * @param {OPT_epgelsett_bs} [opt] - options
1271
- * @description Creates an instance of the EPG-header element
1272
1361
  */
1273
1362
  constructor(obj, opt) {
1274
1363
  // load content
1275
1364
  const _host = isPlainObject(obj) ? obj : {};
1276
1365
  // load options
1277
- /** @type {OPT_epgelsett_bs} */
1278
- const _options = isPlainObject(opt) ? opt : {};
1366
+ const _options = __evalXMLBaseNodeSettings(opt);
1279
1367
  let {
1280
1368
  parseOptions,
1281
1369
  } = _options;
1282
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1283
- parseOptions = new TXmlContentParseOptions(parseOptions);
1284
- _options.parseOptions = parseOptions;
1285
- };
1286
1370
  // save options
1287
1371
  this.#_options = _options;
1288
1372
  // save parser options
@@ -1350,16 +1434,6 @@ class TXEpgHeaderContainer {
1350
1434
  return isPlainObject(docProv) ? docProv : null;
1351
1435
  }
1352
1436
 
1353
- /**
1354
- * Returns a `TXEpgProviderContainer` instance
1355
- * @type {?TXEpgProviderContainer}
1356
- * @readonly
1357
- * @deprecated
1358
- */
1359
- get Provider() {
1360
- return this.provider;
1361
- }
1362
-
1363
1437
  /**
1364
1438
  * Returns a `TXEpgProviderContainer` instance
1365
1439
  * @since 0.0.22
@@ -1386,8 +1460,8 @@ class TXEpgHeaderContainer {
1386
1460
  }
1387
1461
 
1388
1462
  /**
1463
+ * Returns a document creation date as a timestamp
1389
1464
  * @returns {number}
1390
- * @description Returns a document creation date as a timestamp
1391
1465
  */
1392
1466
  getDocumentDT() {
1393
1467
  let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTO_ETAG_NAME).trim();
@@ -1399,8 +1473,8 @@ class TXEpgHeaderContainer {
1399
1473
  }
1400
1474
 
1401
1475
  /**
1476
+ * Sets a document creation date to a current system time
1402
1477
  * @returns {void}
1403
- * @description Sets a document creation date to a current system time
1404
1478
  */
1405
1479
  setDocumentDT() {
1406
1480
  let dt_str = convDTValueToString(Date.now(), this.dtstype, this.curDocTZ);
@@ -1415,8 +1489,8 @@ class TXEpgHeaderContainer {
1415
1489
  }
1416
1490
 
1417
1491
  /**
1492
+ * Returns a document expire date as a timestamp
1418
1493
  * @returns {number}
1419
- * @description Returns a document expire date as a timestamp
1420
1494
  */
1421
1495
  getDocumentEDT() {
1422
1496
  let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTE_ETAG_NAME).trim();
@@ -1428,9 +1502,9 @@ class TXEpgHeaderContainer {
1428
1502
  }
1429
1503
 
1430
1504
  /**
1505
+ * Sets a document expire date to a given time
1431
1506
  * @param {any} value - document expire date
1432
1507
  * @returns {void}
1433
- * @description Sets a document expire date to a given time
1434
1508
  */
1435
1509
  setDocumentEDT(value) {
1436
1510
  // TODO: check if value is a DateTime-string
@@ -1446,8 +1520,8 @@ class TXEpgHeaderContainer {
1446
1520
  }
1447
1521
 
1448
1522
  /**
1523
+ * Returns a channel info
1449
1524
  * @returns {xepgChnInfoDesc}
1450
- * @description Returns a channel info
1451
1525
  */
1452
1526
  getChannelInfo() {
1453
1527
  return this.channel.getInfo();
@@ -1459,7 +1533,7 @@ class TXEpgHeaderContainer {
1459
1533
  * @description Sets a channel info
1460
1534
  * @deprecated
1461
1535
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
1462
- * @todo [since v0.0.22] deprecated
1536
+ * @todo [since v0.0.22] deprecated. Use `TXEpgChannelContainer.setInfo`
1463
1537
  */
1464
1538
  setChannelInfo(obj) {
1465
1539
  let _obj = obj;
@@ -1472,20 +1546,22 @@ class TXEpgHeaderContainer {
1472
1546
  }
1473
1547
 
1474
1548
  /**
1549
+ * Returns a provider info
1475
1550
  * @returns {?xepgProvInfoDesc}
1476
- * @description Returns a provider info
1477
1551
  */
1478
- getProviderInfo(){
1552
+ getProviderInfo() {
1479
1553
  const docProv = this.provider;
1480
1554
  return docProv ? docProv.getInfo() : null;
1481
1555
  }
1482
1556
 
1483
1557
  /**
1558
+ * Sets a provider info
1484
1559
  * @param {xepgProvInfoDesc} obj - provider info descriptor
1485
1560
  * @returns {void}
1486
- * @description Sets a provider info
1561
+ * @deprecated
1562
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgProviderContainer.setInfo`
1487
1563
  */
1488
- setProviderInfo(obj){
1564
+ setProviderInfo(obj) {
1489
1565
  if (isArray(obj) || isObject(obj)) {
1490
1566
  let docProv = this.provider;
1491
1567
  if (!docProv) {
@@ -1497,29 +1573,45 @@ class TXEpgHeaderContainer {
1497
1573
  }
1498
1574
 
1499
1575
  /**
1576
+ * Returns an instance content as a string in an XML-format.
1500
1577
  * @since v0.0.20
1501
1578
  * @returns {string}
1502
- * @description Returns an instance content as a string in an XML-format.
1503
1579
  */
1504
1580
  saveToXMLString() {
1505
1581
  const options = this.#_parseOptions.js2xml;
1506
1582
  options.ignoreDocType = true;
1507
1583
  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;
1584
+ return serializeXObjToXMLString(
1585
+ this.#_host,
1586
+ options,
1587
+ XEPG_HEADER_ETAG_NAME,
1588
+ );
1589
+ }
1590
+
1591
+ /**
1592
+ * Loads an element content from a string.
1593
+ * @since v0.0.24
1594
+ * @param {string} xmlString - some content
1595
+ * @returns {boolean}
1596
+ * @throws {Error}
1597
+ * @experimental
1598
+ */
1599
+ loadFromXMLString(xmlString) {
1600
+ const options = this.#_parseOptions.xml2js;
1601
+ options.ignoreDocType = true;
1602
+ options.ignoreDeclaration = true;
1603
+ return deserializeXObjFromXMLString(
1604
+ this.#_host,
1605
+ options,
1606
+ xmlString,
1607
+ XEPG_HEADER_ETAG_NAME,
1608
+ );
1518
1609
  }
1519
1610
 
1520
1611
  };
1521
1612
 
1522
1613
  /**
1614
+ * A fs ops description.
1523
1615
  * @typedef {Object} fsoDescr
1524
1616
  * @property {boolean} isERR - flag
1525
1617
  * @property {number} [errCode] - error code
@@ -1527,14 +1619,14 @@ class TXEpgHeaderContainer {
1527
1619
  * @property {string} [errMsg] - event message
1528
1620
  * @property {string} [source] - path to file
1529
1621
  * @property {any} [content] - file content
1530
- * @description A fs ops description.
1531
1622
  */
1532
1623
 
1533
1624
  /**
1625
+ * An options set for `TXEpgContentProvider`-class
1534
1626
  * @typedef {Object} OPT_epgcpsett
1535
1627
  * @property {TXmlContentParseOptions} [parseOptions] - parser options
1536
1628
  * @property {boolean} [autoBindRoot] - <*deprecated*>
1537
- * @description An options set for `TXEpgContentProvider`-class
1629
+ */
1538
1630
 
1539
1631
  /**
1540
1632
  * @classdesc This class implements an interface of the container
@@ -1542,28 +1634,24 @@ class TXEpgHeaderContainer {
1542
1634
  */
1543
1635
  class TXEpgContentProvider {
1544
1636
  /** @type {Object} */
1545
- #_content;// = null;
1637
+ #_content;
1546
1638
  /** @type {OPT_epgcpsett} */
1547
- #_options;// = null;
1639
+ #_options;
1548
1640
  /** @type {TXmlContentParseOptions} */
1549
- #_parseOptions;// = null;
1641
+ #_parseOptions;
1550
1642
 
1551
1643
  /**
1644
+ * Creates an instance of the XEPG-content provider
1552
1645
  * @param {OPT_epgcpsett} [opt] - options
1553
- * @description Creates an instance of the XEPG-content provider
1554
1646
  */
1555
1647
  constructor(opt) {
1556
1648
  // load options
1649
+ const _options = __evalXMLBaseNodeSettings(opt);
1557
1650
  /** @type {OPT_epgcpsett} */
1558
- const _options = isPlainObject(opt) ? opt : {};
1559
1651
  let {
1560
1652
  parseOptions,
1561
1653
  autoBindRoot, // <*reserved*> ([?] - deprecate)
1562
1654
  } = _options;
1563
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
1564
- parseOptions = new TXmlContentParseOptions(parseOptions);
1565
- _options.parseOptions = parseOptions;
1566
- };
1567
1655
  if (typeof autoBindRoot !== 'boolean') autoBindRoot = false;
1568
1656
  // save options
1569
1657
  //_options.autoBindRoot = autoBindRoot; //* // TODO:
@@ -1663,21 +1751,6 @@ class TXEpgContentProvider {
1663
1751
  return isPlainObject(docBody) ? docBody : null;
1664
1752
  }
1665
1753
 
1666
- /**
1667
- * Returns a `TXEpgHeaderContainer` instance
1668
- * @type {?TXEpgHeaderContainer}
1669
- * @readonly
1670
- * @deprecated
1671
- */
1672
- get Header() {
1673
- const docHdr = this.#_getHdr();
1674
- return (
1675
- docHdr
1676
- ? new TXEpgHeaderContainer(docHdr, this.#_options)
1677
- : null
1678
- );
1679
- }
1680
-
1681
1754
  /**
1682
1755
  * Returns a `TXEpgHeaderContainer` instance
1683
1756
  * @since 0.0.22
@@ -1693,17 +1766,6 @@ class TXEpgContentProvider {
1693
1766
  );
1694
1767
  }
1695
1768
 
1696
- /**
1697
- * Returns a `TXEpgProviderContainer` instance
1698
- * @type {?TXEpgProviderContainer}
1699
- * @readonly
1700
- * @deprecated
1701
- */
1702
- get Provider() {
1703
- const docHdr = this.header;
1704
- return docHdr ? docHdr.provider : null;
1705
- }
1706
-
1707
1769
  /**
1708
1770
  * Returns a `TXEpgProviderContainer` instance
1709
1771
  * @since 0.0.22
@@ -1735,8 +1797,20 @@ class TXEpgContentProvider {
1735
1797
  * Returns a `TXEpgSchedulesList` instance
1736
1798
  * @type {TXEpgSchedulesList}
1737
1799
  * @readonly
1800
+ * @deprecated
1801
+ * @todo \[since `v0.0.24`] deprecated. Use `TXEpgContentProvider.schedules`
1738
1802
  */
1739
1803
  get SchedulesList() {
1804
+ return this.schedules;
1805
+ }
1806
+
1807
+ /**
1808
+ * Returns a `TXEpgSchedulesList` instance
1809
+ * @since 0.0.24
1810
+ * @type {TXEpgSchedulesList}
1811
+ * @readonly
1812
+ */
1813
+ get schedules() {
1740
1814
  const _options = this.#_options;
1741
1815
  const docBody = this.#_getBody();
1742
1816
  if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
@@ -1791,8 +1865,8 @@ class TXEpgContentProvider {
1791
1865
  }
1792
1866
 
1793
1867
  /**
1868
+ * Returns a document content as a string in an XML-format.
1794
1869
  * @returns {string}
1795
- * @description Returns a document content as a string in an XML-format.
1796
1870
  */
1797
1871
  saveToXMLString() {
1798
1872
  let result = '';
@@ -1806,11 +1880,11 @@ class TXEpgContentProvider {
1806
1880
  }
1807
1881
 
1808
1882
  /**
1883
+ * Saves a document content to a file.
1809
1884
  * @param {string} source - a path to a file
1810
1885
  * @returns {Promise<fsoDescr, Error>}
1811
1886
  * @throws {Error}
1812
1887
  * @async
1813
- * @description Saves a document content to a file.
1814
1888
  */
1815
1889
  saveToFile(source) {
1816
1890
  /**/// main part that return promise as a result
@@ -1847,9 +1921,9 @@ class TXEpgContentProvider {
1847
1921
  }
1848
1922
 
1849
1923
  /**
1924
+ * Saves a document content to a file.
1850
1925
  * @param {string} source - path to a file
1851
1926
  * @returns {fsoDescr}
1852
- * @description Saves a document content to a file.
1853
1927
  */
1854
1928
  saveToFileSync(source) {
1855
1929
  /** @type {fsoDescr} */
@@ -1876,11 +1950,11 @@ class TXEpgContentProvider {
1876
1950
  }
1877
1951
 
1878
1952
  /**
1953
+ * Loads a document content from a string.
1879
1954
  * @since 0.0.18
1880
1955
  * @param {string} xmlString - a document content in XML-format
1881
1956
  * @returns {boolean}
1882
1957
  * @throws {Error}
1883
- * @description Loads a document content from a string.
1884
1958
  */
1885
1959
  loadFromXMLString(xmlString) {
1886
1960
  let isSUCCEED = false;
@@ -1913,18 +1987,11 @@ class TXEpgContentProvider {
1913
1987
  }
1914
1988
 
1915
1989
  /**
1916
- * @deprecated
1917
- */
1918
- loadFromString(...args){
1919
- return this.loadFromXMLString(...args);
1920
- }
1921
-
1922
- /**
1990
+ * Loads a document content from a file.
1923
1991
  * @param {string} source - path to a file
1924
1992
  * @returns {Promise<fsoDescr, Error>}
1925
1993
  * @throws {Error}
1926
1994
  * @async
1927
- * @description Loads a document content from a file.
1928
1995
  */
1929
1996
  loadFromFile(source) {
1930
1997
  /**/// main part that return promise as a result
@@ -1955,9 +2022,9 @@ class TXEpgContentProvider {
1955
2022
  }
1956
2023
 
1957
2024
  /**
2025
+ * Loads a document content from a file.
1958
2026
  * @param {string} source - path to a file
1959
2027
  * @returns {fsoDescr}
1960
- * @description Loads a document content from a file.
1961
2028
  */
1962
2029
  loadFromFileSync(source) {
1963
2030
  const data = loadFromFileSync(source);
@@ -1995,10 +2062,6 @@ module.exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
1995
2062
  module.exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
1996
2063
  module.exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
1997
2064
 
1998
- module.exports.readAsTagName = readAsTagName;
1999
- module.exports.readAsAttrName = readAsAttrName;
2000
- module.exports.valueToElementID = valueToElementID;
2001
-
2002
2065
  module.exports.TXEpgDTSProvider = TXEpgDTSProvider;
2003
2066
  module.exports.TXEpgScheduleItem = TXEpgScheduleItem;
2004
2067
  module.exports.TXEpgSchedulesList = TXEpgSchedulesList;
@@ -2007,5 +2070,7 @@ module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
2007
2070
  module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
2008
2071
  module.exports.TXEpgContentProvider = TXEpgContentProvider;
2009
2072
 
2010
- /** @deprecated */
2011
- module.exports.TXepgDTSProvider = TXEpgDTSProvider;
2073
+ // * re-exported *
2074
+ module.exports.readAsTagName = readAsTagName;
2075
+ module.exports.readAsAttrName = readAsAttrName;
2076
+ module.exports.valueToElementID = valueToElementID;