@ygracs/xepg-lib-js 0.0.25 → 0.0.27-b

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.128-20250825]
1
+ // [v0.3.145-20260305]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -24,17 +24,22 @@ const {
24
24
  const {
25
25
  loadFromFileSync, loadFromFile,
26
26
  saveToFileSync, saveToFile,
27
+ // * import types definitions *
28
+ /** @see fsoDescr from `@cntwg/file-helper` */
29
+ fsoDescr,
27
30
  } = require('@cntwg/file-helper');
28
31
 
29
32
  const xObj = require('@ygracs/xobj-lib-js');
30
-
31
33
  const {
32
- TXmlContentParseOptions,
33
34
  getXObjElement,
34
35
  insertXObjElement,
35
36
  writeXObjParam,
36
- writeXObjAttr,
37
+ readXObjAttr, writeXObjAttr,
38
+ //TXmlContentParseOptions,
39
+ DEF_XML_PARSE_OPTIONS: XML_DEF_PARSE_OPTIONS,
37
40
  } = xObj;
41
+ // keep the next line for a type checking work properly :(
42
+ const { TXmlContentParseOptions } = require('@ygracs/xobj-lib-js/lib/xObj-defs');
38
43
 
39
44
  const {
40
45
  readAsTagName,
@@ -83,28 +88,6 @@ function _getDTSTypeValueForXObj(obj) {
83
88
  return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
84
89
  };
85
90
 
86
- /**
87
- * @param {object} obj - element
88
- * @param {*} data - data
89
- * @returns {void}
90
- * @inner
91
- */
92
- function writeXEpgDocDeclSection(obj, data) {
93
- const key_name = defParseOptions.settings.declarationKey;
94
- let xml_ver = XEPG_XML_DOC_VERSION;
95
- let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
96
- if (isPlainObject(data)) {
97
- xml_ver = readAsString(data.version, { defValue: xml_ver });
98
- doc_def_enc = readAsString(data.encoding, { defValue: doc_def_enc });
99
- };
100
- if (isPlainObject(obj) && isNotEmptyString(key_name)) {
101
- obj[key_name] = {};
102
- const attr_key = defParseOptions.settings.attributesKey;
103
- writeXObjAttr(obj[key_name], 'version', xml_ver, attr_key);
104
- writeXObjAttr(obj[key_name], 'encoding', doc_def_enc, attr_key);
105
- };
106
- };
107
-
108
91
  /**
109
92
  * Returns an object as a string in an XML-format.
110
93
  * @since v0.0.24
@@ -173,11 +156,17 @@ function deserializeXObjFromXMLString(node, opt, text, tagName) {
173
156
  * @property {TXmlContentParseOptions} [parseOptions] - parser options
174
157
  */
175
158
 
159
+ /**
160
+ * An XEPG-element options set (base)
161
+ * @typedef {Object} XEpgElementConfigBase
162
+ * @property {TXmlContentParseOptions} parseOptions - parser options
163
+ */
164
+
176
165
  /**
177
166
  * Evaluates an XML-node base settings
178
167
  * @function __evalXMLBaseNodeSettings
179
168
  * @param {any} value - element settings to evaluate
180
- * @returns {OPT_epgelsett_bs}
169
+ * @returns {XEpgElementConfigBase}
181
170
  * @inner
182
171
  */
183
172
  function __evalXMLBaseNodeSettings(value) {
@@ -190,14 +179,14 @@ function __evalXMLBaseNodeSettings(value) {
190
179
  if (!(parseOptions instanceof TXmlContentParseOptions)) {
191
180
  settings.parseOptions = new TXmlContentParseOptions(parseOptions);
192
181
  };
182
+ // @ts-expect-error
193
183
  return settings;
194
184
  };
195
185
 
196
186
  // === module main block ===
197
187
 
198
- /***
199
- * (* constant definitions *)
200
- */
188
+ const XML_TE_INVARG_EMSG = 'invalid argument';
189
+ const XML_TE_NOBJ_EMSG = `${XML_TE_INVARG_EMSG} (an object is expected)`;
201
190
 
202
191
  /**
203
192
  * A list of a document schema version supported by a library
@@ -440,13 +429,13 @@ class TXEpgScheduleItem {
440
429
  setTime(value) {
441
430
  let { isSucceed, value: dtValue } = tryDTValue(value);
442
431
  let result = false;
443
- if (isSucceed) {
444
- dtValue = convDTValueToString(dtValue, this.dtstype, this.curDocTZ);
445
- if (dtValue !== '') {
432
+ if (isSucceed && dtValue != null) {
433
+ const text = convDTValueToString(dtValue, this.dtstype, this.curDocTZ);
434
+ if (text !== '') {
446
435
  const opt = { force: true };
447
436
  const item = insertXObjElement(this.#_host, XEPG_SCHEDTIME_ETAG_NAME, opt);
448
437
  if (item) {
449
- result = writeXObjParam(item, dtValue, defParseOptions.settings.textKey);
438
+ result = writeXObjParam(item, text, defParseOptions.settings.textKey);
450
439
  };
451
440
  };
452
441
  };
@@ -617,7 +606,6 @@ class TXEpgSchedulesList {
617
606
  * Returns a raw schedule element
618
607
  * @param {(number|string)} value - element index
619
608
  * @returns {any}
620
- * @private
621
609
  */
622
610
  #_getItem = function(value) {
623
611
  if (this.chkIndex(value)) {
@@ -668,16 +656,6 @@ class TXEpgSchedulesList {
668
656
  );
669
657
  }
670
658
 
671
- /**
672
- * Indicates whether an instance has none member
673
- * @returns {boolean}
674
- * @deprecated
675
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isEmpty`
676
- */
677
- hasNoSchedules() {
678
- return this.count === 0;
679
- }
680
-
681
659
  /**
682
660
  * Indicates whether an instance has none member
683
661
  * @since v0.0.24
@@ -687,16 +665,6 @@ class TXEpgSchedulesList {
687
665
  return this.count === 0;
688
666
  }
689
667
 
690
- /**
691
- * Indicates whether an instance has any member
692
- * @returns {boolean}
693
- * @deprecated
694
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isNotEmpty`
695
- */
696
- hasSchedules() {
697
- return this.count > 0;
698
- }
699
-
700
668
  /**
701
669
  * Indicates whether an instance has any member
702
670
  * @since v0.0.24
@@ -959,7 +927,7 @@ class TXEpgProviderContainer {
959
927
 
960
928
  /**
961
929
  * Sets an initial instance state
962
- * @param {(xepgProvInfoDesc|string[])} opt - options
930
+ * @param {(xepgProvInfoDesc|string[])} [opt] - options
963
931
  * @returns {void}
964
932
  */
965
933
  init(opt) {
@@ -1264,7 +1232,6 @@ class TXEpgDTSProvider {
1264
1232
 
1265
1233
  /**
1266
1234
  * @returns {void}
1267
- * @private
1268
1235
  */
1269
1236
  #_init() {
1270
1237
  insertXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
@@ -1282,7 +1249,7 @@ class TXEpgDTSProvider {
1282
1249
  }
1283
1250
 
1284
1251
  set dtstype(value) {
1285
- return this.setType(value);
1252
+ this.setType(value);
1286
1253
  }
1287
1254
 
1288
1255
  /**
@@ -1373,6 +1340,8 @@ class TXEpgHeaderContainer {
1373
1340
  this.#_parseOptions = parseOptions;
1374
1341
  // save content source
1375
1342
  this.#_host = _host;
1343
+ // init required elements
1344
+ this.#_initProv();
1376
1345
  // init DTS-provider
1377
1346
  this.#_dtsProv = new TXEpgDTSProvider(_host, _options);
1378
1347
  }
@@ -1414,7 +1383,6 @@ class TXEpgHeaderContainer {
1414
1383
 
1415
1384
  /**
1416
1385
  * @returns {?object}
1417
- * @private
1418
1386
  */
1419
1387
  #_getProv() {
1420
1388
  const docProv = getXObjElement(this.#_host, XEPG_PRVINFO_ETAG_NAME);
@@ -1423,7 +1391,6 @@ class TXEpgHeaderContainer {
1423
1391
 
1424
1392
  /**
1425
1393
  * @returns {?object}
1426
- * @private
1427
1394
  */
1428
1395
  #_initProv() {
1429
1396
  const _host = this.#_host;
@@ -1452,7 +1419,7 @@ class TXEpgHeaderContainer {
1452
1419
  /**
1453
1420
  * Returns a `TXEpgChannelContainer` instance
1454
1421
  * @since 0.0.22
1455
- * @type {?TXEpgChannelContainer}
1422
+ * @type {TXEpgChannelContainer}
1456
1423
  * @readonly
1457
1424
  */
1458
1425
  get channel() {
@@ -1527,24 +1494,6 @@ class TXEpgHeaderContainer {
1527
1494
  return this.channel.getInfo();
1528
1495
  }
1529
1496
 
1530
- /**
1531
- * @param {xepgChnInfoDesc} obj - channel info descriptor
1532
- * @returns {void}
1533
- * @description Sets a channel info
1534
- * @deprecated
1535
- * @todo [since v0.0.21] deprecate use of `obj`-param as array
1536
- * @todo [since v0.0.22] deprecated. Use `TXEpgChannelContainer.setInfo`
1537
- */
1538
- setChannelInfo(obj) {
1539
- let _obj = obj;
1540
- if (isArray(obj)) {
1541
- // // TODO: [!] deprecate
1542
- const [ chnid, chname, chngid, srcurl ] = _obj;
1543
- _obj = { chnid, chname, chngid, srcurl };
1544
- };
1545
- return this.channel.setInfo(_obj);
1546
- }
1547
-
1548
1497
  /**
1549
1498
  * Returns a provider info
1550
1499
  * @returns {?xepgProvInfoDesc}
@@ -1554,24 +1503,6 @@ class TXEpgHeaderContainer {
1554
1503
  return docProv ? docProv.getInfo() : null;
1555
1504
  }
1556
1505
 
1557
- /**
1558
- * Sets a provider info
1559
- * @param {xepgProvInfoDesc} obj - provider info descriptor
1560
- * @returns {void}
1561
- * @deprecated
1562
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgProviderContainer.setInfo`
1563
- */
1564
- setProviderInfo(obj) {
1565
- if (isArray(obj) || isObject(obj)) {
1566
- let docProv = this.provider;
1567
- if (!docProv) {
1568
- docProv = this.#_initProv();
1569
- if (docProv) docProv = this.provider;
1570
- };
1571
- if (docProv) docProv.setInfo(obj);
1572
- };
1573
- }
1574
-
1575
1506
  /**
1576
1507
  * Returns an instance content as a string in an XML-format.
1577
1508
  * @since v0.0.20
@@ -1611,15 +1542,109 @@ class TXEpgHeaderContainer {
1611
1542
  };
1612
1543
 
1613
1544
  /**
1614
- * A fs ops description.
1615
- * @typedef {Object} fsoDescr
1616
- * @property {boolean} isERR - flag
1617
- * @property {number} [errCode] - error code
1618
- * @property {string} errEvent - event ID
1619
- * @property {string} [errMsg] - event message
1620
- * @property {string} [source] - path to file
1621
- * @property {any} [content] - file content
1545
+ * @since v0.0.2x
1546
+ * @classdesc This class implements an instance of an element
1547
+ * that managea content of a document declaration
1622
1548
  */
1549
+ class TXmlContentDeclaration {
1550
+ /** @type {object} */
1551
+ #_host;
1552
+ /** @type {XEpgElementConfigBase} */
1553
+ #_config;
1554
+ /** @type {object} */
1555
+ #_ctrls;
1556
+
1557
+ /**
1558
+ * Creates an instance of the element
1559
+ * @param {object} obj - some object
1560
+ * @param {OPT_epgelsett_bs} [opt] - options
1561
+ * @throws {TypeError}
1562
+ */
1563
+ constructor(obj, opt) {
1564
+ if (!isPlainObject(obj)) {
1565
+ throw new TypeError(`TXmlContentDeclaration : ${XML_TE_NOBJ_EMSG}`);
1566
+ };
1567
+ // load options
1568
+ //const _options = __evalXMLContainerSettings(opt);
1569
+ const config = __evalXMLBaseNodeSettings(opt);
1570
+ // set parser options
1571
+ let { settings } = config.parseOptions;
1572
+ let { declarationKey } = settings;
1573
+ // // TODO: [!] need to be rewritten
1574
+ // // ([!] need support from `TXmlContentParseOptions` for correct ops)
1575
+ if (
1576
+ typeof declarationKey !== 'string'
1577
+ || ((declarationKey = declarationKey.trim()) === '')
1578
+ ) {
1579
+ declarationKey = XML_DEF_PARSE_OPTIONS.declarationKey;
1580
+ settings.declarationKey = declarationKey;
1581
+ };
1582
+ // save options
1583
+ this.#_config = config;
1584
+ // bind a documents content
1585
+ this.#_host = obj;
1586
+ // init a content declaration element
1587
+ this.init();
1588
+ }
1589
+
1590
+ /**
1591
+ * Contains a version of an XML
1592
+ * @type {string}
1593
+ */
1594
+ get version() {
1595
+ return readXObjAttr(
1596
+ this.#_ctrls,
1597
+ 'version',
1598
+ this.#_config.parseOptions.settings.attributesKey,
1599
+ );
1600
+ }
1601
+
1602
+ set version(value) {
1603
+ writeXObjAttr(
1604
+ this.#_ctrls,
1605
+ 'version',
1606
+ value,
1607
+ this.#_config.parseOptions.settings.attributesKey,
1608
+ );
1609
+ }
1610
+
1611
+ /**
1612
+ * Contains a document character set
1613
+ * @type {string}
1614
+ */
1615
+ get encoding() {
1616
+ return readXObjAttr(
1617
+ this.#_ctrls,
1618
+ 'encoding',
1619
+ this.#_config.parseOptions.settings.attributesKey,
1620
+ );
1621
+ }
1622
+
1623
+ set encoding(value) {
1624
+ writeXObjAttr(
1625
+ this.#_ctrls,
1626
+ 'encoding',
1627
+ value,
1628
+ this.#_config.parseOptions.settings.attributesKey,
1629
+ );
1630
+ }
1631
+
1632
+ /**
1633
+ * Initializes an instance content.
1634
+ * @returns {void}
1635
+ */
1636
+ init() {
1637
+ this.#_ctrls = insertXObjElement(
1638
+ this.#_host,
1639
+ this.#_config.parseOptions.settings.declarationKey,
1640
+ );
1641
+ // set version & encoding
1642
+ if (!isNotEmptyString(this.version)) this.version = XEPG_XML_DOC_VERSION;
1643
+ if (!isNotEmptyString(this.encoding)) this.encoding = XEPG_DEF_ENCODING_VALUE;
1644
+ }
1645
+
1646
+ };
1647
+ module.exports.TXmlContentDeclaration = TXmlContentDeclaration;
1623
1648
 
1624
1649
  /**
1625
1650
  * An options set for `TXEpgContentProvider`-class
@@ -1628,6 +1653,13 @@ class TXEpgHeaderContainer {
1628
1653
  * @property {boolean} [autoBindRoot] - <*deprecated*>
1629
1654
  */
1630
1655
 
1656
+ /**
1657
+ * An options set for `TXEpgContentProvider`-class
1658
+ * @typedef {Object} XEpgContainerConfig
1659
+ * @property {TXmlContentParseOptions} parseOptions - parser options
1660
+ * @property {boolean} [autoBindRoot] - <*deprecated*>
1661
+ */
1662
+
1631
1663
  /**
1632
1664
  * @classdesc This class implements an interface of the container
1633
1665
  * that manages a content of a XEPG-document
@@ -1635,10 +1667,16 @@ class TXEpgHeaderContainer {
1635
1667
  class TXEpgContentProvider {
1636
1668
  /** @type {Object} */
1637
1669
  #_content;
1638
- /** @type {OPT_epgcpsett} */
1670
+ /** @type {XEpgContainerConfig} */
1639
1671
  #_options;
1640
1672
  /** @type {TXmlContentParseOptions} */
1641
1673
  #_parseOptions;
1674
+ /** @type {TXmlContentDeclaration} */
1675
+ #_docDecl;
1676
+ /** @type {TXEpgHeaderContainer} */
1677
+ #_hdrSect;
1678
+ /** @type {TXEpgSchedulesList} */
1679
+ #_schedSect;
1642
1680
 
1643
1681
  /**
1644
1682
  * Creates an instance of the XEPG-content provider
@@ -1646,47 +1684,43 @@ class TXEpgContentProvider {
1646
1684
  */
1647
1685
  constructor(opt) {
1648
1686
  // load options
1649
- const _options = __evalXMLBaseNodeSettings(opt);
1650
- /** @type {OPT_epgcpsett} */
1687
+ /** @type {XEpgContainerConfig} */
1688
+ const config = __evalXMLBaseNodeSettings(opt);
1651
1689
  let {
1652
1690
  parseOptions,
1653
1691
  autoBindRoot, // <*reserved*> ([?] - deprecate)
1654
- } = _options;
1692
+ } = config;
1655
1693
  if (typeof autoBindRoot !== 'boolean') autoBindRoot = false;
1656
1694
  // save options
1657
1695
  //_options.autoBindRoot = autoBindRoot; //* // TODO:
1658
- this.#_options = _options;
1696
+ this.#_options = config;
1659
1697
  // save parser options
1660
1698
  this.#_parseOptions = parseOptions;
1661
1699
  // init document content
1662
- this.#_content = {};
1700
+ const content = this.#_content = {};
1701
+ // init a content declaration element
1702
+ this.#_docDecl = new TXmlContentDeclaration(content, config);
1663
1703
  this.init();
1664
1704
  }
1665
1705
 
1666
1706
  /**
1667
- * @returns {?Object}
1668
- * @private
1669
- */
1670
- #_getRoot() {
1671
- const docRoot = getXObjElement(this.#_content, XEPG_ROOT_ETAG_NAME);
1672
- return isPlainObject(docRoot) ? docRoot : null;
1673
- }
1674
-
1675
- /**
1707
+ * Initializes a content root element
1708
+ * @param {object} [obj] - object to initialize
1709
+ * @param {TXmlContentParseOptions} [opt] - parser options
1676
1710
  * @returns {?object}
1677
- * @private
1678
1711
  */
1679
- #_initRoot() {
1680
- const _content = this.#_content;
1681
- let docRoot = getXObjElement(_content, XEPG_ROOT_ETAG_NAME);
1712
+ #_initRoot(obj, opt) {
1713
+ const content = obj ?? this.#_content;
1714
+ let docRoot = getXObjElement(content, XEPG_ROOT_ETAG_NAME);
1682
1715
  if (!docRoot) {
1683
- docRoot = insertXObjElement(_content, XEPG_ROOT_ETAG_NAME);
1716
+ docRoot = insertXObjElement(content, XEPG_ROOT_ETAG_NAME);
1684
1717
  if (docRoot) {
1718
+ const config = opt ?? defParseOptions;
1685
1719
  writeXObjAttr(
1686
1720
  docRoot,
1687
1721
  `xmlns:${XEPG_DEF_NS_NAME}`,
1688
1722
  XEPG_DEF_NS_PATH,
1689
- defParseOptions.settings.attributesKey,
1723
+ config.settings.attributesKey,
1690
1724
  );
1691
1725
  };
1692
1726
  };
@@ -1694,76 +1728,72 @@ class TXEpgContentProvider {
1694
1728
  }
1695
1729
 
1696
1730
  /**
1697
- * @returns {?Object}
1698
- * @private
1731
+ * Initializes a document content.
1732
+ * @since 0.0.2x
1733
+ * @param {object} content - some object to initialize
1734
+ * @param {XEpgContainerConfig} opt - options
1735
+ * @param {boolean} mode - flag
1736
+ * @returns {fsoDescr}
1699
1737
  */
1700
- #_getHdr() {
1701
- const docRoot = this.#_getRoot();
1702
- let docHdr = null;
1703
- if (docRoot) {
1704
- docHdr = getXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
1738
+ #_initContent(content, opt, mode) {
1739
+ /** @type {fsoDescr} */
1740
+ const result = {
1741
+ isERR: false,
1742
+ errCode: undefined,
1743
+ errEvent: '',
1744
+ errMsg: '',
1705
1745
  };
1706
- return isPlainObject(docHdr) ? docHdr : null;
1707
- }
1708
-
1709
- /**
1710
- * @returns {?object}
1711
- * @private
1712
- */
1713
- #_initHdr() {
1714
- let docHdr = this.#_getHdr();
1715
- if (!docHdr) {
1716
- let docRoot = this.#_getRoot();
1717
- if (!docRoot) docRoot = this.#_initRoot();
1718
- if (docRoot) {
1746
+ // initiate document root element
1747
+ let docRoot = getXObjElement(content, XEPG_ROOT_ETAG_NAME);
1748
+ if (!docRoot) docRoot = this.#_initRoot(content, opt.parseOptions);
1749
+ if (docRoot) {
1750
+ // init a document header element
1751
+ let docHdr = getXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
1752
+ if (!docHdr) {
1719
1753
  docHdr = insertXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
1720
1754
  };
1721
- };
1722
- return isPlainObject(docHdr) ? docHdr : null;
1723
- }
1724
-
1725
- /**
1726
- * @returns {?Object}
1727
- * @private
1728
- */
1729
- #_getBody() {
1730
- const docRoot = this.#_getRoot();
1731
- let docBody = null;
1732
- if (docRoot) {
1733
- docBody = getXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
1734
- };
1735
- return isPlainObject(docBody) ? docBody : null;
1736
- }
1737
-
1738
- /**
1739
- * @returns {?object}
1740
- * @private
1741
- */
1742
- #_initBody() {
1743
- let docBody = this.#_getBody();
1744
- if (!docBody) {
1745
- let docRoot = this.#_getRoot();
1746
- if (!docRoot) docRoot = this.#_initRoot();
1747
- if (docRoot) {
1755
+ // init a document body element
1756
+ let docBody = getXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
1757
+ if (!docBody) {
1748
1758
  docBody = insertXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
1749
1759
  };
1760
+ if (docBody) {
1761
+ if (typeof docBody[XEPG_SCHED_ETAG_NAME] !== 'object') {
1762
+ docBody[XEPG_SCHED_ETAG_NAME] = [];
1763
+ } else if (!isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
1764
+ let tmpObj = [];
1765
+ tmpObj.push(docBody[XEPG_SCHED_ETAG_NAME]);
1766
+ docBody[XEPG_SCHED_ETAG_NAME] = tmpObj;
1767
+ };
1768
+ //isSUCCEED = true;
1769
+ };
1770
+ if (docHdr && docBody) {
1771
+ // init controllers
1772
+ const hdrSect = new TXEpgHeaderContainer(docHdr, opt);
1773
+ const schedSect = new TXEpgSchedulesList(
1774
+ docBody[XEPG_SCHED_ETAG_NAME],
1775
+ opt,
1776
+ {
1777
+ dts_src: getXObjElement(docHdr, XEPG_DTSINFO_ETAG_NAME),
1778
+ tz_src: getXObjElement(docHdr, XEPG_DOCTZ_ETAG_NAME),
1779
+ },
1780
+ );
1781
+ this.#_hdrSect = hdrSect;
1782
+ this.#_schedSect = schedSect;
1783
+ };
1750
1784
  };
1751
- return isPlainObject(docBody) ? docBody : null;
1785
+ //==
1786
+ return result;
1752
1787
  }
1753
1788
 
1754
1789
  /**
1755
1790
  * Returns a `TXEpgHeaderContainer` instance
1756
1791
  * @since 0.0.22
1757
- * @type {?TXEpgHeaderContainer}
1792
+ * @type {TXEpgHeaderContainer}
1758
1793
  * @readonly
1759
1794
  */
1760
1795
  get header() {
1761
- const docHdr = this.#_getHdr();
1762
- return (
1763
- docHdr
1764
- ? new TXEpgHeaderContainer(docHdr, this.#_options)
1765
- : null
1766
- );
1796
+ return this.#_hdrSect;
1767
1797
  }
1768
1798
 
1769
1799
  /**
@@ -1787,23 +1817,6 @@ class TXEpgContentProvider {
1787
1817
  return docHdr ? docHdr.dts : null;
1788
1818
  }
1789
1819
 
1790
- /* [!] a temporary special method */
1791
- /**
1792
- * @deprecated
1793
- */
1794
- get Content(){ return this; }
1795
-
1796
- /**
1797
- * Returns a `TXEpgSchedulesList` instance
1798
- * @type {TXEpgSchedulesList}
1799
- * @readonly
1800
- * @deprecated
1801
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgContentProvider.schedules`
1802
- */
1803
- get SchedulesList() {
1804
- return this.schedules;
1805
- }
1806
-
1807
1820
  /**
1808
1821
  * Returns a `TXEpgSchedulesList` instance
1809
1822
  * @since 0.0.24
@@ -1811,56 +1824,27 @@ class TXEpgContentProvider {
1811
1824
  * @readonly
1812
1825
  */
1813
1826
  get schedules() {
1814
- const _options = this.#_options;
1815
- const docBody = this.#_getBody();
1816
- if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
1817
- const docHdr = this.#_getHdr();
1818
- return new TXEpgSchedulesList(
1819
- docBody[XEPG_SCHED_ETAG_NAME],
1820
- {
1821
- dts_src: getXObjElement(docHdr, XEPG_DTSINFO_ETAG_NAME),
1822
- tz_src: getXObjElement(docHdr, XEPG_DOCTZ_ETAG_NAME),
1823
- },
1824
- );
1825
- };
1827
+ return this.#_schedSect;
1826
1828
  }
1827
1829
 
1828
1830
  /**
1829
1831
  * @returns {void}
1830
1832
  */
1831
1833
  init() {
1832
- const _options = this.#_options;
1833
- const _content = this.#_content;
1834
+ const config = this.#_options;
1835
+ const content = this.#_content;
1834
1836
  const {
1835
1837
  parseOptions,
1836
- } = _options;
1838
+ } = config;
1837
1839
  const { settings } = parseOptions;
1838
- const { ignoreDeclaration } = settings;
1839
- if (!ignoreDeclaration) {
1840
- // write document declaration section
1841
- writeXEpgDocDeclSection(_content);
1842
- };
1843
- // initiate document root element
1844
- let docRoot = this.#_getRoot();
1845
- if (!docRoot) docRoot = this.#_initRoot();
1846
- if (docRoot) {
1847
- // initiate document header element
1848
- let docHdr = this.#_getHdr();
1849
- if (!docHdr) docHdr = this.#_initHdr();
1840
+ // initiate document content declaration element
1841
+ this.#_docDecl.init();
1842
+ // init document content
1843
+ const { isERR } = this.#_initContent(content, config, true);
1844
+ // // TODO: ...
1845
+ if (!isERR) {
1850
1846
  // initiate document provider element
1851
- let docProv = insertXObjElement(
1852
- docHdr,
1853
- XEPG_PRVINFO_ETAG_NAME,
1854
- );
1855
- if (docProv) this.provider.init();
1856
- // initiate document body element
1857
- let docBody = this.#_getBody();
1858
- if (!docBody) docBody = this.#_initBody();
1859
- if (
1860
- docBody && !isArray(docBody[XEPG_SCHED_ETAG_NAME])
1861
- ) {
1862
- docBody[XEPG_SCHED_ETAG_NAME] = [];
1863
- };
1847
+ this.provider.init();
1864
1848
  };
1865
1849
  }
1866
1850
 
@@ -1962,20 +1946,14 @@ class TXEpgContentProvider {
1962
1946
  const { parseOptions } = this.#_options;
1963
1947
  try {
1964
1948
  this.#_content = xmlParser.xml2js(xmlString, parseOptions.xml2js);
1965
- // init a document header element
1966
- let docHdr = this.#_getHdr();
1967
- if (!docHdr) docHdr = this.#_initHdr();
1968
- // init a document body element
1969
- let docBody = this.#_getBody();
1970
- if (!docBody) docBody = this.#_initBody();
1971
- if (docBody) {
1972
- if (typeof docBody[XEPG_SCHED_ETAG_NAME] !== 'object') {
1973
- docBody[XEPG_SCHED_ETAG_NAME] = [];
1974
- } else if (!isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
1975
- let tmpObj = [];
1976
- tmpObj.push(docBody[XEPG_SCHED_ETAG_NAME]);
1977
- docBody[XEPG_SCHED_ETAG_NAME] = tmpObj;
1978
- };
1949
+ // init a document content
1950
+ const { isERR } = this.#_initContent(
1951
+ this.#_content,
1952
+ this.#_options,
1953
+ false,
1954
+ );
1955
+ // // TODO: ...
1956
+ if (!isERR) {
1979
1957
  isSUCCEED = true;
1980
1958
  };
1981
1959
  } catch (err) {
@@ -2001,7 +1979,7 @@ class TXEpgContentProvider {
2001
1979
  if (data.content !== '') {
2002
1980
  if (this.loadFromXMLString(data.content)) {
2003
1981
  // // TODO:
2004
- data.isLoaded = true;
1982
+ //data.isLoaded = true;
2005
1983
  data.errEvent = 'OPS_IS_SUCCEED';
2006
1984
  } else {
2007
1985
  data.isERR = true;
@@ -2032,7 +2010,7 @@ class TXEpgContentProvider {
2032
2010
  if (data.content !== '') {
2033
2011
  if (this.loadFromXMLString(data.content)) {
2034
2012
  // // TODO:
2035
- data.isLoaded = true;
2013
+ //data.isLoaded = true;
2036
2014
  data.errEvent = 'OPS_IS_SUCCEED';
2037
2015
  } else {
2038
2016
  data.isERR = true;
@@ -2069,8 +2047,3 @@ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
2069
2047
  module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
2070
2048
  module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
2071
2049
  module.exports.TXEpgContentProvider = TXEpgContentProvider;
2072
-
2073
- // * re-exported *
2074
- module.exports.readAsTagName = readAsTagName;
2075
- module.exports.readAsAttrName = readAsAttrName;
2076
- module.exports.valueToElementID = valueToElementID;