@ygracs/xepg-lib-js 0.0.26-b → 0.0.30

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,24 +1,23 @@
1
- // [v0.2.132-20260122]
1
+ // [v0.3.153-20260612]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const xmlParser = require('@ygracs/xml-js6');
6
6
 
7
7
  const {
8
- valueToIndex, valueToIDString,
9
- readAsString, readAsNumber,
8
+ readAsString,
10
9
  isNotEmptyString,
11
10
  isArray, isObject, isPlainObject,
12
11
  } = require('@ygracs/bsfoc-lib-js');
13
12
 
14
13
  const {
15
14
  convValueToTZString, convTZStringToValue,
16
- tryDTValue,
17
15
  } = require('@ygracs/dtf-lib-js');
18
16
 
19
17
  const {
20
- chkDTSysID, getDTSysDescr,
18
+ getDTSysDescr,
21
19
  convStringToDTValue, convDTValueToString,
20
+ _getDTSTypeValueForXObj,
22
21
  } = require('./dts-helper.js');
23
22
 
24
23
  const {
@@ -34,142 +33,64 @@ const {
34
33
  getXObjElement,
35
34
  insertXObjElement,
36
35
  writeXObjParam,
37
- writeXObjAttr,
36
+ readXObjAttr, writeXObjAttr,
38
37
  //TXmlContentParseOptions,
38
+ DEF_XML_PARSE_OPTIONS: XML_DEF_PARSE_OPTIONS,
39
39
  } = xObj;
40
40
  // keep the next line for a type checking work properly :(
41
41
  const { TXmlContentParseOptions } = require('@ygracs/xobj-lib-js/lib/xObj-defs');
42
+ // keep the next line for a type checking work properly :(
43
+ const { INode } = require('@ygracs/xobj-lib-js/lib/xObj-lib');
42
44
 
43
45
  const {
44
- readAsTagName,
45
- readAsAttrName,
46
- valueToElementID,
46
+ //readAsTagName,
47
+ //readAsAttrName,
48
+ //valueToElementID,
49
+ serializeXObjToXMLString, deserializeXObjFromXMLString,
50
+ _getXmlChildElementParam,
47
51
  } = require('./xml-base');
48
52
 
49
- // === module inner block ===
50
-
51
- /*
52
- * === xObj-function wrappers (start) ===
53
- */
54
-
55
- function readXObjParam(obj){
56
- return xObj.readXObjParam(obj, defParseOptions.settings.textKey);
57
- };
58
-
59
- /*
60
- * === xObj-function wrappers (end) ===
61
- */
62
-
63
- /***
64
- * (* helper function definitions *)
65
- */
53
+ const {
54
+ XEPG_CONSTANTS, XEPG_DEF_TNAMES,
55
+ defParseOptionsSettings,
56
+ } = require('./xepg-defs');
66
57
 
67
- /**
68
- * @param {object} obj - element
69
- * @param {string} name - child element name
70
- * @returns {string}
71
- * @inner
72
- */
73
- function _getXmlChildElementParam(obj, name) {
74
- const child = obj ? getXObjElement(obj, name) : null;
75
- return child ? readXObjParam(child) : '';
76
- };
58
+ const {
59
+ TXEpgSchedulesList,
60
+ } = require('./xepg-sched');
77
61
 
78
- /**
79
- * @param {object} obj - element
80
- * @returns {number}
81
- * @inner
82
- */
83
- function _getDTSTypeValueForXObj(obj) {
84
- const result = valueToIndex(
85
- _getXmlChildElementParam(obj, 'value')
86
- );
87
- return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
88
- };
62
+ const {
63
+ TXEpgChannelContainer,
64
+ // * import types definitions *
65
+ IXEpgChnInfoDesc,
66
+ } = require('./xepg-channel');
89
67
 
90
- /**
91
- * @param {object} obj - element
92
- * @param {*} data - data
93
- * @returns {void}
94
- * @inner
95
- */
96
- function writeXEpgDocDeclSection(obj, data) {
97
- const key_name = defParseOptions.settings.declarationKey;
98
- let xml_ver = XEPG_XML_DOC_VERSION;
99
- let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
100
- if (isPlainObject(data)) {
101
- xml_ver = readAsString(data.version, { defValue: xml_ver });
102
- doc_def_enc = readAsString(data.encoding, { defValue: doc_def_enc });
103
- };
104
- if (isPlainObject(obj) && isNotEmptyString(key_name)) {
105
- obj[key_name] = {};
106
- const attr_key = defParseOptions.settings.attributesKey;
107
- writeXObjAttr(obj[key_name], 'version', xml_ver, attr_key);
108
- writeXObjAttr(obj[key_name], 'encoding', doc_def_enc, attr_key);
109
- };
110
- };
68
+ // === module inner block ===
111
69
 
112
- /**
113
- * Returns an object as a string in an XML-format.
114
- * @since v0.0.24
115
- * @function serializeXObjToXMLString
116
- * @param {object} node - some element
117
- * @param {object} opt - parser options
118
- * @param {string} tagName - element tag name
119
- * @returns {string}
120
- * @inner
121
- */
122
- function serializeXObjToXMLString(node, opt, tagName) {
123
- let result = '';
124
- try {
125
- result = xmlParser.js2xml({ [tagName]: node }, opt);
126
- } catch (err) {
127
- //console.log('CHECK: serializeXObjToXMLString() => Error => '+err);
128
- result = '';
129
- //throw err;
130
- };
131
- return result;
132
- };
70
+ const {
71
+ XEPG_DEF_NS_NAME,
72
+ XEPG_DEF_NS_PATH,
73
+ XEPG_XML_DOC_VERSION,
74
+ XEPG_DEF_ENCODING_VALUE,
75
+ XEPG_DEF_DOCUMENT_TYPE,
76
+ XEPG_DEF_DOCUMENT_SCHEMA,
77
+ XEPG_DEF_PROVIDER_NAME,
78
+ XEPG_DEF_PROVIDER_VER,
79
+ } = XEPG_CONSTANTS;
133
80
 
134
- /**
135
- * Loads an object content from an XML-string.
136
- * @since v0.0.24
137
- * @function deserializeXObjFromXMLString
138
- * @param {object} node - some element
139
- * @param {object} opt - parser options
140
- * @param {string} text - some content
141
- * @param {string} tagName - element tag name
142
- * @returns {boolean}
143
- * @throws {Error}
144
- * @inner
145
- * @experimental
146
- */
147
- function deserializeXObjFromXMLString(node, opt, text, tagName) {
148
- let result = false;
149
- if (typeof text === 'string' && text !== '') {
150
- try {
151
- let obj = xmlParser.xml2js(text, opt);
152
- if (isPlainObject(obj)) {
153
- obj = obj[tagName];
154
- if (isPlainObject(obj)) {
155
- for (let prop in node) {
156
- // // TODO: catch errors in strict mode
157
- delete node[prop];
158
- };
159
- (Object.entries(obj)).forEach(([key, value]) => {
160
- node[key] = value;
161
- });
162
- result = true;
163
- };
164
- };
165
- } catch (err) {
166
- //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err);
167
- //console.log('CHECK: deserializeXObjFromXMLString() => Error => '+err.code);
168
- throw err;
169
- };
170
- };
171
- return result;
172
- };
81
+ const {
82
+ XEPG_ROOT_ETAG_NAME,
83
+ XEPG_HEADER_ETAG_NAME,
84
+ XEPG_BODY_ETAG_NAME,
85
+ XEPG_SCHED_ETAG_NAME,
86
+ XEPG_PRVINFO_ETAG_NAME,
87
+ XEPG_DTSINFO_ETAG_NAME,
88
+ XEPG_DOCDTO_ETAG_NAME,
89
+ XEPG_DOCDTE_ETAG_NAME,
90
+ XEPG_DOCTZ_ETAG_NAME,
91
+ XEPG_DOCSCH_ETAG_NAME,
92
+ XEPG_DOCTYP_ETAG_NAME,
93
+ } = XEPG_DEF_TNAMES;
173
94
 
174
95
  /**
175
96
  * An XEPG-element options set (base)
@@ -206,43 +127,8 @@ function __evalXMLBaseNodeSettings(value) {
206
127
 
207
128
  // === module main block ===
208
129
 
209
- /***
210
- * (* constant definitions *)
211
- */
212
-
213
- /**
214
- * A list of a document schema version supported by a library
215
- */
216
- const ALLOWED_XEPG_DOCUMENT_SCHEMA = [ '0.2' ];
217
-
218
- const XEPG_ROOT_ETAG_NAME = 'epgdoc';
219
- const XEPG_DEF_NS_NAME = 'tvp';
220
- const XEPG_DEF_NS_PATH = 'urn:e-doc:epg-doc:xepg';
221
- const XEPG_HEADER_ETAG_NAME = `${XEPG_DEF_NS_NAME}:info`;
222
- const XEPG_BODY_ETAG_NAME = `${XEPG_DEF_NS_NAME}:list`;
223
- const XEPG_SCHED_ETAG_NAME = `${XEPG_DEF_NS_NAME}:item`;
224
- const XEPG_PRVINFO_ETAG_NAME = `${XEPG_DEF_NS_NAME}:provider`;
225
- const XEPG_DTSINFO_ETAG_NAME = `${XEPG_DEF_NS_NAME}:dtstype`;
226
- const XEPG_DOCDTO_ETAG_NAME = `${XEPG_DEF_NS_NAME}:time`;
227
- const XEPG_DOCDTE_ETAG_NAME = `${XEPG_DEF_NS_NAME}:expire`;
228
- const XEPG_DOCTZ_ETAG_NAME = `${XEPG_DEF_NS_NAME}:timezone`;
229
- const XEPG_DOCSCH_ETAG_NAME = `${XEPG_DEF_NS_NAME}:schema`;
230
- const XEPG_DOCTYP_ETAG_NAME = `${XEPG_DEF_NS_NAME}:doctype`;
231
- const XEPG_CHNID_ETAG_NAME = `${XEPG_DEF_NS_NAME}:chnid`;
232
- const XEPG_CHNNAME_ETAG_NAME = `${XEPG_DEF_NS_NAME}:chname`;
233
- const XEPG_CHNGID_ETAG_NAME = `${XEPG_DEF_NS_NAME}:chngid`;
234
- const XEPG_CHNURL_ETAG_NAME = `${XEPG_DEF_NS_NAME}:srcurl`;
235
- const XEPG_SCHEDTIME_ETAG_NAME = `${XEPG_DEF_NS_NAME}:time`;
236
- const XEPG_SCHEDTITL_ETAG_NAME = `${XEPG_DEF_NS_NAME}:title`;
237
- const XEPG_SCHEDCAT_ETAG_NAME = `${XEPG_DEF_NS_NAME}:cat`;
238
- const XEPG_SCHEDPMARK_ETAG_NAME = `${XEPG_DEF_NS_NAME}:pcmark`;
239
- const XEPG_SCHEDDESC_ETAG_NAME = `${XEPG_DEF_NS_NAME}:desc`;
240
- const XEPG_XML_DOC_VERSION = '1.0';
241
- const XEPG_DEF_ENCODING_VALUE = 'UTF-8';
242
- const XEPG_DEF_DOCUMENT_TYPE = 'xepg';
243
- const XEPG_DEF_DOCUMENT_SCHEMA = ALLOWED_XEPG_DOCUMENT_SCHEMA[0];
244
- const XEPG_DEF_PROVIDER_NAME = 'xepg-lib-js';
245
- const XEPG_DEF_PROVIDER_VER = '0.0.21';
130
+ const XML_TE_INVARG_EMSG = 'invalid argument';
131
+ const XML_TE_NOBJ_EMSG = `${XML_TE_INVARG_EMSG} (an object is expected)`;
246
132
 
247
133
  const defXEpgDocOptions = {
248
134
  xmlns_xepg_pref: XEPG_DEF_NS_NAME,
@@ -262,537 +148,37 @@ const defXEpgDocOptions = {
262
148
  },
263
149
  };
264
150
 
265
- const defParseOptions = new TXmlContentParseOptions();
266
- //console.log('CHECK: defParseOptions => '+JSON.stringify(defParseOptions, null, 2));
267
-
268
- /***
269
- * (* function definitions *)
270
- */
271
-
272
- /***
273
- * (* class definitions *)
274
- */
275
-
276
- /**
277
- * A schedule info descriptor
278
- * @typedef {Object} xepgShedInfoDesc
279
- * @property {number} time - a schedule start time
280
- * @property {string} title - schedule title
281
- * @property {string} [cat] - schedule category
282
- * @property {number} [pcmark] - schedule rating
283
- * @property {string} [descr] - schedule description
284
- */
285
-
286
- /**
287
- * An extra options set
288
- * @typedef {Object} OPT_extra
289
- * @property {object} [dts_src] - 'DTS'-settings
290
- * @property {object} [tz_src] - 'TZ'-settings
291
- */
292
-
293
- /**
294
- * An XEPG-element options set (extend)
295
- * @typedef {Object} OPT_epgelsett_ex
296
- * @property {TXmlContentParseOptions} [parseOptions] - parser options
297
- * @property {object} [dts_src]
298
- * @property {object} [tz_src]
299
- */
300
-
301
- /**
302
- * @since 0.0.22
303
- * @classdesc This class implements an interface of a EPG-schedule element
304
- */
305
- class TXEpgScheduleItem {
306
- /** @type {object} */
307
- #_host;
308
- /** @type {OPT_epgelsett_ex} */
309
- #_options;
310
- /** @type {TXmlContentParseOptions} */
311
- #_parseOptions;
312
- /** @type {?object} */
313
- #_dts_src = null;
314
- /** @type {?object} */
315
- #_tz_src = null;
316
-
317
- /**
318
- * Creates an instance of the EPG-schedule element
319
- * @param {object} obj - host object
320
- * @param {OPT_epgelsett_ex} [opt] - options
321
- * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
322
- */
323
- constructor(obj, opt, extra) {
324
- // load content
325
- const _host = isPlainObject(obj) ? obj : {};
326
- // load options
327
- /** @type {OPT_epgelsett_ex} */
328
- const _options = isPlainObject(opt) ? opt : {};
329
- let {
330
- parseOptions,
331
- } = _options;
332
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
333
- parseOptions = new TXmlContentParseOptions(parseOptions);
334
- _options.parseOptions = parseOptions;
335
- };
336
- let {
337
- dts_src = _options.dts_src,
338
- tz_src = _options.tz_src,
339
- } = isPlainObject(extra) ? extra : {};
340
- if (!isPlainObject(dts_src)) dts_src = null;
341
- if (!isPlainObject(tz_src)) tz_src = null;
342
- // save content source
343
- this.#_host = _host;
344
- // save options
345
- this.#_options = _options;
346
- // save parser options
347
- this.#_parseOptions = parseOptions;
348
- // save refs to a time source priveders
349
- this.#_dts_src = dts_src;
350
- this.#_tz_src = tz_src;
351
- }
352
-
353
- /**
354
- * Contains a dtstype ID
355
- * @type {number}
356
- * @readonly
357
- */
358
- get dtstype() {
359
- return _getDTSTypeValueForXObj(this.#_dts_src);
360
- }
361
-
362
- /**
363
- * Contains a TZ-offset
364
- * @type {number}
365
- * @readonly
366
- */
367
- get curDocTZ() {
368
- return (
369
- this.#_tz_src
370
- ? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
371
- : 0
372
- );
373
- }
374
-
375
- /**
376
- * Contains a schedule start time as a timestamp
377
- * @type {number}
378
- * @readonly
379
- */
380
- get time() {
381
- return convStringToDTValue(
382
- _getXmlChildElementParam(this.#_host, XEPG_SCHEDTIME_ETAG_NAME).trim(),
383
- this.dtstype, this.curDocTZ
384
- );
385
- }
386
-
387
- /**
388
- * Contains a schedule title
389
- * @type {string}
390
- * @readonly
391
- */
392
- get title() {
393
- return _getXmlChildElementParam(this.#_host, XEPG_SCHEDTITL_ETAG_NAME).trim();
394
- }
395
-
396
- /**
397
- * Contains a schedule category
398
- * @type {string}
399
- * @readonly
400
- */
401
- get category() {
402
- return _getXmlChildElementParam(this.#_host, XEPG_SCHEDCAT_ETAG_NAME).trim();
403
- }
404
-
405
- /**
406
- * Contains a schedule rating value (aka pcmark)
407
- * @type {number}
408
- * @readonly
409
- */
410
- get rating() {
411
- return readAsNumber(
412
- _getXmlChildElementParam(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME), 0
413
- );
414
- }
415
-
416
- /**
417
- * Contains a schedule description
418
- * @type {string}
419
- * @readonly
420
- */
421
- get descr() {
422
- return _getXmlChildElementParam(this.#_host, XEPG_SCHEDDESC_ETAG_NAME);
423
- }
424
-
425
- /**
426
- * Returns a schedule info item descriptor
427
- * @returns {xepgShedInfoDesc}
428
- */
429
- getInfo() {
430
- const {
431
- time,
432
- title,
433
- category: cat,
434
- rating: pcmark,
435
- descr,
436
- } = this;
437
- return {
438
- time,
439
- title,
440
- cat,
441
- pcmark,
442
- descr,
443
- };
444
- }
445
-
446
- /**
447
- * Sets a schedule start time.
448
- * @param {(number|string|Date)} value - some time value
449
- * @returns {boolean}
450
- */
451
- setTime(value) {
452
- let { isSucceed, value: dtValue } = tryDTValue(value);
453
- let result = false;
454
- if (isSucceed && dtValue != null) {
455
- const text = convDTValueToString(dtValue, this.dtstype, this.curDocTZ);
456
- if (text !== '') {
457
- const opt = { force: true };
458
- const item = insertXObjElement(this.#_host, XEPG_SCHEDTIME_ETAG_NAME, opt);
459
- if (item) {
460
- result = writeXObjParam(item, text, defParseOptions.settings.textKey);
461
- };
462
- };
463
- };
464
- return result;
465
- }
466
-
467
- /**
468
- * Sets a schedule title.
469
- * @param {string} value - some title
470
- * @returns {boolean}
471
- */
472
- setTitle(value) {
473
- let result = false;
474
- if (typeof value === 'string') {
475
- const opt = { force: true };
476
- const item = insertXObjElement(this.#_host, XEPG_SCHEDTITL_ETAG_NAME, opt);
477
- if (item) {
478
- result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
479
- };
480
- };
481
- return result;
482
- }
483
-
484
- /**
485
- * Sets a schedule title.
486
- * @param {string} value - some title
487
- * @returns {boolean}
488
- */
489
- setCategory(value) {
490
- let result = false;
491
- if (typeof value === 'string') {
492
- const opt = { force: true };
493
- const item = insertXObjElement(this.#_host, XEPG_SCHEDCAT_ETAG_NAME, opt);
494
- if (item) {
495
- result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
496
- };
497
- };
498
- return result;
499
- }
500
-
501
- /**
502
- * Sets a schedule rating value.
503
- * @param {(number|string)} value - some value
504
- * @returns {boolean}
505
- */
506
- setRating(value) {
507
- const _value = valueToIndex(value);
508
- let result = false;
509
- if (_value !== -1) {
510
- const opt = { force: true };
511
- const item = insertXObjElement(this.#_host, XEPG_SCHEDPMARK_ETAG_NAME, opt);
512
- if (item) {
513
- result = writeXObjParam(item, _value, defParseOptions.settings.textKey);
514
- };
515
- };
516
- return result;
517
- }
518
-
519
- /**
520
- * Sets a schedule description.
521
- * @param {string} value - some text
522
- * @returns {boolean}
523
- */
524
- setDescr(value) {
525
- let result = false;
526
- if (typeof value === 'string') {
527
- const opt = { force: true };
528
- const item = insertXObjElement(this.#_host, XEPG_SCHEDDESC_ETAG_NAME, opt);
529
- if (item) {
530
- result = writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
531
- };
532
- };
533
- return result;
534
- }
535
-
536
- /**
537
- * Returns an instance content as a string in an XML-format.
538
- * @returns {string}
539
- */
540
- saveToXMLString() {
541
- const options = this.#_parseOptions.js2xml;
542
- options.ignoreDocType = true;
543
- options.ignoreDeclaration = true;
544
- return serializeXObjToXMLString(
545
- this.#_host,
546
- options,
547
- XEPG_SCHED_ETAG_NAME,
548
- );
549
- }
550
-
551
- /**
552
- * Loads an element content from a string.
553
- * @since v0.0.24
554
- * @param {string} xmlString - some content
555
- * @returns {boolean}
556
- * @throws {Error}
557
- * @experimental
558
- */
559
- loadFromXMLString(xmlString) {
560
- const options = this.#_parseOptions.xml2js;
561
- options.ignoreDocType = true;
562
- options.ignoreDeclaration = true;
563
- return deserializeXObjFromXMLString(
564
- this.#_host,
565
- options,
566
- xmlString,
567
- XEPG_SCHED_ETAG_NAME,
568
- );
569
- }
570
-
571
- };
572
-
573
151
  /**
574
- * @classdesc This class implements an interface of a EPG-schedules list
152
+ * A list of fields in order: `name`, `version`, `schema`, `doctype`
153
+ * @typedef {string[]} arrProviderInfo
154
+ * @deprecated
155
+ * @todo \[since v0.0.21] deprecated and will be removed
575
156
  */
576
- class TXEpgSchedulesList {
577
- /** @type {object[]} */
578
- #_content;
579
- /** @type {OPT_epgelsett_ex} */
580
- #_options;
581
- /** @type {?object} */
582
- #_dts_src = null;
583
- /** @type {?object} */
584
- #_tz_src = null;
585
-
586
- /**
587
- * Creates an instance of the schedules list
588
- * @param {any[]} obj - list of an elements
589
- * @param {OPT_epgelsett_ex} [opt] - options
590
- * @param {OPT_extra} [extra] - \[since `v0.0.24`] extra options
591
- */
592
- constructor(obj, opt, extra) {
593
- const _content = isArray(obj) ? obj : [];
594
- /** @type {OPT_epgelsett_ex} */
595
- const _options = isPlainObject(opt) ? opt : {};
596
- let {
597
- dts_src = _options.dts_src,
598
- tz_src = _options.tz_src,
599
- } = isPlainObject(extra) ? extra : {};
600
- if (!isPlainObject(dts_src)) dts_src = null;
601
- if (!isPlainObject(tz_src)) tz_src = null;
602
- // save content source
603
- this.#_content = _content;
604
- // save options
605
- this.#_options = _options;
606
- // save refs to a time source priveders
607
- this.#_dts_src = dts_src;
608
- this.#_tz_src = tz_src;
609
- }
610
-
611
- [Symbol.iterator]() {
612
- let index = 0;
613
- return {
614
- next: () => {
615
- if (index < this.count) {
616
- return { done: false, value: this.schedule(index++) };
617
- } else {
618
- return { done: true, value: undefined };
619
- };
620
- },
621
- return() {
622
- return { done: true, value: undefined };
623
- },
624
- };
625
- }
626
-
627
- /**
628
- * Returns a raw schedule element
629
- * @param {(number|string)} value - element index
630
- * @returns {any}
631
- */
632
- #_getItem = function(value) {
633
- if (this.chkIndex(value)) {
634
- return this.#_content[Number(value)];
635
- };
636
- };
637
-
638
- /**
639
- * Contains a quantity of a schedules
640
- * @type {number}
641
- * @readonly
642
- * @deprecated
643
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.count`
644
- */
645
- get schedQty() {
646
- return this.#_content.length;
647
- }
648
-
649
- /**
650
- * Contains a quantity of a schedules
651
- * @since v0.0.24
652
- * @type {number}
653
- * @readonly
654
- */
655
- get count() {
656
- return this.#_content.length;
657
- }
658
-
659
- /**
660
- * Contains a dtstype ID
661
- * @type {number}
662
- * @readonly
663
- */
664
- get dtstype() {
665
- return _getDTSTypeValueForXObj(this.#_dts_src);
666
- }
667
-
668
- /**
669
- * Contains a TZ-offset
670
- * @type {number}
671
- * @readonly
672
- */
673
- get curDocTZ() {
674
- return (
675
- this.#_tz_src
676
- ? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
677
- : 0
678
- );
679
- }
680
-
681
- /**
682
- * Indicates whether an instance has none member
683
- * @returns {boolean}
684
- * @deprecated
685
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isEmpty`
686
- */
687
- hasNoSchedules() {
688
- return this.count === 0;
689
- }
690
-
691
- /**
692
- * Indicates whether an instance has none member
693
- * @since v0.0.24
694
- * @returns {boolean}
695
- */
696
- isEmpty() {
697
- return this.count === 0;
698
- }
699
-
700
- /**
701
- * Indicates whether an instance has any member
702
- * @returns {boolean}
703
- * @deprecated
704
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgSchedulesList.isNotEmpty`
705
- */
706
- hasSchedules() {
707
- return this.count > 0;
708
- }
709
-
710
- /**
711
- * Indicates whether an instance has any member
712
- * @since v0.0.24
713
- * @returns {boolean}
714
- */
715
- isNotEmpty() {
716
- return this.count > 0;
717
- }
718
-
719
- /**
720
- * Checks whether a given value is a valid index and it fits the index range
721
- * of an instance
722
- * @since 0.0.20
723
- * @param {(number|string)} value - index of some element
724
- * @returns {boolean}
725
- */
726
- chkIndex(value) {
727
- const index = valueToIndex(value);
728
- return index !== -1 && index < this.count;
729
- }
730
-
731
- /**
732
- * Returns a schedule element addressed by a given index
733
- * @since 0.0.22
734
- * @param {(number|string)} index - index of some element
735
- * @returns {?TXEpgScheduleItem}
736
- */
737
- schedule(index) {
738
- const curObj = this.#_getItem(index);
739
- let item = null;
740
- if (isPlainObject(curObj)) {
741
- item = new TXEpgScheduleItem(curObj, {
742
- dts_src: this.#_dts_src,
743
- tz_src: this.#_tz_src,
744
- });
745
- };
746
- return item;
747
- }
748
-
749
- /**
750
- * Returns a schedule info item for instance element addressed
751
- * by a given index
752
- * @param {(number|string)} index - index of some element
753
- * @returns {?xepgShedInfoDesc}
754
- */
755
- getScheduleInfo(index) {
756
- const obj = this.schedule(index);
757
- return obj ? obj.getInfo() : null;
758
- }
759
-
760
- /**
761
- * Returns a schedule info for instance members
762
- * @returns {xepgShedInfoDesc[]}
763
- */
764
- getAllSchedulesInfo() {
765
- let result = [];
766
- for (let i = 0; i < this.count; i++) {
767
- let item = this.getScheduleInfo(i);
768
- if (isPlainObject(item)) result.push(item);
769
- };
770
- return result;
771
- }
772
-
773
- /**
774
- * @protected
775
- */
776
- asJSON() {
777
- return JSON.stringify(this.#_content, null, 2);
778
- }
779
-
780
- };
157
+ /**
158
+ * A virtual constant meant for support jsdoc notation:
159
+ * @type {arrProviderInfo}
160
+ */
161
+ module.exports.arrProviderInfo = [];
781
162
 
782
163
  /**
783
164
  * A provider info descriptor
784
- * @typedef {Object} xepgProvInfoDesc
165
+ * @typedef {Object} IXEpgProvInfoDesc
785
166
  * @property {string} [name] - provider name
786
167
  * @property {string} [version] - provider version
787
168
  * @property {string} schema - document schema
788
169
  * @property {string} doctype - document type
789
170
  */
171
+ /**
172
+ * A virtual constant meant for support jsdoc notation:
173
+ * @type {IXEpgProvInfoDesc}
174
+ */
175
+ module.exports.IXEpgProvInfoDesc = { schema: '', doctype: '' };
790
176
 
791
177
  /**
792
178
  * @classdesc This class implements an interface of a EPG-provider element
793
179
  */
794
180
  class TXEpgProviderContainer {
795
- /** @type {Object} */
181
+ /** @type {INode} */
796
182
  #_host;
797
183
  /** @type {OPT_epgelsett_bs} */
798
184
  #_options;
@@ -801,7 +187,7 @@ class TXEpgProviderContainer {
801
187
 
802
188
  /**
803
189
  * Creates an instance of the EPG-provider element
804
- * @param {object} obj - host object
190
+ * @param {INode} obj - host object
805
191
  * @param {OPT_epgelsett_bs} [opt] - options
806
192
  */
807
193
  constructor(obj, opt) {
@@ -859,7 +245,7 @@ class TXEpgProviderContainer {
859
245
  const opt = { force: true };
860
246
  const item = insertXObjElement(this.#_host, 'version', opt);
861
247
  if (item) {
862
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
248
+ writeXObjParam(item, value.trim(), defParseOptionsSettings.textKey);
863
249
  };
864
250
  };
865
251
  }
@@ -877,7 +263,7 @@ class TXEpgProviderContainer {
877
263
  const opt = { force: true };
878
264
  const item = insertXObjElement(this.#_host, XEPG_DOCSCH_ETAG_NAME, opt);
879
265
  if (item) {
880
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
266
+ writeXObjParam(item, value.trim(), defParseOptionsSettings.textKey);
881
267
  };
882
268
  };
883
269
  }
@@ -895,7 +281,7 @@ class TXEpgProviderContainer {
895
281
  const opt = { force: true };
896
282
  const item = insertXObjElement(this.#_host, XEPG_DOCTYP_ETAG_NAME, opt);
897
283
  if (item) {
898
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
284
+ writeXObjParam(item, value.trim(), defParseOptionsSettings.textKey);
899
285
  };
900
286
  };
901
287
  }
@@ -911,7 +297,7 @@ class TXEpgProviderContainer {
911
297
  const name = value.trim();
912
298
  const item = insertXObjElement(this.#_host, 'name', { force: true });
913
299
  if (item) {
914
- isSucceed = writeXObjParam(item, name, defParseOptions.settings.textKey);
300
+ isSucceed = writeXObjParam(item, name, defParseOptionsSettings.textKey);
915
301
  };
916
302
  };
917
303
  return isSucceed;
@@ -919,7 +305,7 @@ class TXEpgProviderContainer {
919
305
 
920
306
  /**
921
307
  * Returns a provider info item
922
- * @returns {xepgProvInfoDesc}
308
+ * @returns {IXEpgProvInfoDesc}
923
309
  */
924
310
  getInfo() {
925
311
  return {
@@ -932,7 +318,7 @@ class TXEpgProviderContainer {
932
318
 
933
319
  /**
934
320
  * Sets a provider info
935
- * @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
321
+ * @param {arrProviderInfo|IXEpgProvInfoDesc} obj - provider info descriptor
936
322
  * @returns {void}
937
323
  * @todo [since v0.0.21] deprecate use of `obj`-param as array
938
324
  */
@@ -969,20 +355,20 @@ class TXEpgProviderContainer {
969
355
 
970
356
  /**
971
357
  * Sets an initial instance state
972
- * @param {(xepgProvInfoDesc|string[])} [opt] - options
358
+ * @param {arrProviderInfo|IXEpgProvInfoDesc} [data] - options
973
359
  * @returns {void}
360
+ * @todo [since v0.0.30] deprecate use of `obj`-param as array
974
361
  */
975
- init(opt) {
362
+ init(data) {
976
363
  let prov_opt = { ...defXEpgDocOptions.defProviderParam };
977
364
  let name = '';
978
365
  let version = '';
979
366
  let schema = '';
980
367
  let doctype = '';
981
- const _options = isObject(opt) ? opt : {};
982
- if (isArray(_options)) {
983
- [ name, version, schema, doctype ] = _options;
368
+ if (isArray(data)) {
369
+ [ name, version, schema, doctype ] = data;
984
370
  } else {
985
- ({ name, version, schema, doctype } = _options);
371
+ ({ name, version, schema, doctype } = isObject(data) ? data : {});
986
372
  };
987
373
  name = readAsString(name, { defValue: prov_opt.name, useTrim: true });
988
374
  version = readAsString(version, { defValue: prov_opt.version, useTrim: true });
@@ -1031,229 +417,20 @@ class TXEpgProviderContainer {
1031
417
  }
1032
418
 
1033
419
  };
1034
-
1035
- /**
1036
- * A channel info descriptor
1037
- * @typedef {Object} xepgChnInfoDesc
1038
- * @property {string} chnid - channel ID
1039
- * @property {string} chname - channel name
1040
- * @property {string} [chngid] - channel 'Group ID'
1041
- * @property {string} [srcurl] - EPG-source URL
1042
- */
1043
-
1044
- /**
1045
- * @since 0.0.22
1046
- * @classdesc This class implements an interface of a channel element
1047
- */
1048
- class TXEpgChannelContainer {
1049
- /** @type {object} */
1050
- #_host;
1051
- /** @type {OPT_epgelsett_bs} */
1052
- #_options;
1053
- /** @type {TXmlContentParseOptions} */
1054
- #_parseOptions;
1055
- /** @type {string} */
1056
- #_xepgSchema;
1057
-
1058
- /**
1059
- * Creates an instance of the channel element
1060
- * @param {object} obj - host object
1061
- * @param {OPT_epgelsett_bs} [opt] - options
1062
- */
1063
- constructor(obj, opt) {
1064
- // load content
1065
- const _host = isPlainObject(obj) ? obj : {};
1066
- // load options
1067
- const _options = __evalXMLBaseNodeSettings(opt);
1068
- let {
1069
- parseOptions,
1070
- } = _options;
1071
- // set document schema version
1072
- this.#_xepgSchema = XEPG_DEF_DOCUMENT_SCHEMA;
1073
- // save options
1074
- this.#_options = _options;
1075
- // save parser options
1076
- this.#_parseOptions = parseOptions;
1077
- // save content source
1078
- this.#_host = _host;
1079
- }
1080
-
1081
- /**
1082
- * Contains a channel ID
1083
- * @type {string}
1084
- * @readonly
1085
- */
1086
- get id() {
1087
- return _getXmlChildElementParam(this.#_host, XEPG_CHNID_ETAG_NAME).trim();
1088
- }
1089
-
1090
- /**
1091
- * Contains a channel name
1092
- * @type {string}
1093
- */
1094
- get name() {
1095
- return _getXmlChildElementParam(this.#_host, XEPG_CHNNAME_ETAG_NAME).trim();
1096
- }
1097
-
1098
- set name(value) {
1099
- if (typeof value === 'string' && this.id !== '') {
1100
- const item = insertXObjElement(
1101
- this.#_host,
1102
- XEPG_CHNNAME_ETAG_NAME,
1103
- { force: true },
1104
- );
1105
- if (item) {
1106
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1107
- };
1108
- };
1109
- }
1110
-
1111
- /**
1112
- * Contains a channel Group ID
1113
- * @type {string}
1114
- */
1115
- get gid() {
1116
- return _getXmlChildElementParam(this.#_host, XEPG_CHNGID_ETAG_NAME).trim();
1117
- }
1118
-
1119
- set gid(value) {
1120
- if (typeof value === 'string' && this.id !== '') {
1121
- const item = insertXObjElement(
1122
- this.#_host,
1123
- XEPG_CHNGID_ETAG_NAME,
1124
- { force: true },
1125
- );
1126
- if (item) {
1127
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1128
- };
1129
- };
1130
- }
1131
-
1132
- /**
1133
- * Contains a channel source URL
1134
- * @type {string}
1135
- */
1136
- get url() {
1137
- return _getXmlChildElementParam(this.#_host, XEPG_CHNURL_ETAG_NAME).trim();
1138
- }
1139
-
1140
- set url(value) {
1141
- if (typeof value === 'string' && this.id !== '') {
1142
- const item = insertXObjElement(
1143
- this.#_host,
1144
- XEPG_CHNURL_ETAG_NAME,
1145
- { force: true },
1146
- );
1147
- if (item) {
1148
- writeXObjParam(item, value.trim(), defParseOptions.settings.textKey);
1149
- };
1150
- };
1151
- }
1152
-
1153
- /**
1154
- * Tries to set a channel ID
1155
- * @param {string} value - channel ID
1156
- * @returns {boolean}
1157
- */
1158
- setID(value) {
1159
- let isSucceed = false;
1160
- if (typeof value === 'string') {
1161
- const chnid = value.trim();
1162
- const item = insertXObjElement(
1163
- this.#_host,
1164
- XEPG_CHNID_ETAG_NAME,
1165
- { force: true },
1166
- );
1167
- if (item) {
1168
- isSucceed = writeXObjParam(item, chnid, defParseOptions.settings.textKey);
1169
- };
1170
- };
1171
- return isSucceed;
1172
- }
1173
-
1174
- /**
1175
- * Returns a channel info
1176
- * @returns {xepgChnInfoDesc}
1177
- */
1178
- getInfo() {
1179
- const {
1180
- id: chnid,
1181
- name: chname,
1182
- gid: chngid,
1183
- url: srcurl,
1184
- } = this;
1185
- /** @type {xepgChnInfoDesc} */
1186
- return {
1187
- chnid,
1188
- chname,
1189
- chngid,
1190
- srcurl,
1191
- };
1192
- }
1193
-
1194
- /**
1195
- * Sets a channel info
1196
- * @param {(string|xepgChnInfoDesc)} obj - channel info descriptor
1197
- * @returns {void}
1198
- */
1199
- setInfo(obj) {
1200
- let chnid = '';
1201
- let chname = '';
1202
- let chngid = '';
1203
- let srcurl = '';
1204
- if (isObject(obj)) {
1205
- ({ chnid } = obj);
1206
- if (typeof chnid === 'string') {
1207
- ({ chname, chngid, srcurl } = obj);
1208
- } else {
1209
- // // TODO: [?] deprecate
1210
- chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
1211
- chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
1212
- chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
1213
- srcurl = _getXmlChildElementParam(obj, XEPG_CHNURL_ETAG_NAME).trim();
1214
- };
1215
- } else if (typeof obj === 'string') {
1216
- chnid = obj;
1217
- } else {
1218
- return;
1219
- };
1220
- chnid = typeof chnid === 'string' ? chnid.trim() : '';
1221
- if (chnid === '') {
1222
- chname = '';
1223
- chngid = '';
1224
- srcurl = '';
1225
- } else {
1226
- chname = typeof chname === 'string' ? chname.trim() : '';
1227
- chngid = typeof chngid === 'string' ? chngid.trim() : '';
1228
- srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
1229
- };
1230
- let item = null;
1231
- const _host = this.#_host;
1232
- const text_key = defParseOptions.settings.textKey;
1233
- item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
1234
- if (item) writeXObjParam(item, chnid, text_key);
1235
- item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
1236
- if (item) writeXObjParam(item, chname, text_key);
1237
- item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
1238
- if (item) writeXObjParam(item, chngid, text_key);
1239
- item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
1240
- if (item) writeXObjParam(item, srcurl, text_key);
1241
- }
1242
-
1243
- }
420
+ module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
1244
421
 
1245
422
  /**
1246
423
  * @classdesc This class implements an interface of a DTS-provider element
1247
424
  */
1248
425
  class TXEpgDTSProvider {
1249
- /** @type {object} */
426
+ /** @type {INode} */
1250
427
  #_content;
1251
428
  /** @type {OPT_epgelsett_bs} */
1252
429
  #_options;
1253
430
 
1254
431
  /**
1255
432
  * Creates an instance of the DTS-provider element
1256
- * @param {object} obj - host object
433
+ * @param {INode} obj - host object
1257
434
  * @param {OPT_epgelsett_bs} [opt] - options
1258
435
  */
1259
436
  constructor(obj, opt) {
@@ -1314,7 +491,7 @@ class TXEpgDTSProvider {
1314
491
  { force: true },
1315
492
  );
1316
493
  if (item) {
1317
- writeXObjParam(item, _value, defParseOptions.settings.textKey);
494
+ writeXObjParam(item, _value, defParseOptionsSettings.textKey);
1318
495
  };
1319
496
  };
1320
497
  }
@@ -1322,7 +499,7 @@ class TXEpgDTSProvider {
1322
499
  /**
1323
500
  * Tries to set a `DTS`-type
1324
501
  * @since 0.0.22
1325
- * @property {(number|string)} value - dtstype ID
502
+ * @param {number|string} value - dtstype ID
1326
503
  * @returns {boolean}
1327
504
  */
1328
505
  setType(value) {
@@ -1338,10 +515,10 @@ class TXEpgDTSProvider {
1338
515
  let curItem = insertXObjElement(item, 'value', { force: true });
1339
516
  if (
1340
517
  curItem
1341
- && writeXObjParam(curItem, index, defParseOptions.settings.textKey)
518
+ && writeXObjParam(curItem, index, defParseOptionsSettings.textKey)
1342
519
  && (curItem = insertXObjElement(item, 'name', { force: true }))
1343
520
  ) {
1344
- isSucceed = writeXObjParam(curItem, name, defParseOptions.settings.textKey);
521
+ isSucceed = writeXObjParam(curItem, name, defParseOptionsSettings.textKey);
1345
522
  };
1346
523
  };
1347
524
  };
@@ -1354,7 +531,7 @@ class TXEpgDTSProvider {
1354
531
  * @classdesc This class implements an interface of a EPG-header element
1355
532
  */
1356
533
  class TXEpgHeaderContainer {
1357
- /** @type {Object} */
534
+ /** @type {INode} */
1358
535
  #_host;
1359
536
  /** @type {OPT_epgelsett_bs} */
1360
537
  #_options;
@@ -1365,7 +542,7 @@ class TXEpgHeaderContainer {
1365
542
 
1366
543
  /**
1367
544
  * Creates an instance of the EPG-header element
1368
- * @param {object} obj - host element
545
+ * @param {INode} obj - host element
1369
546
  * @param {OPT_epgelsett_bs} [opt] - options
1370
547
  */
1371
548
  constructor(obj, opt) {
@@ -1382,6 +559,8 @@ class TXEpgHeaderContainer {
1382
559
  this.#_parseOptions = parseOptions;
1383
560
  // save content source
1384
561
  this.#_host = _host;
562
+ // init required elements
563
+ this.#_initProv();
1385
564
  // init DTS-provider
1386
565
  this.#_dtsProv = new TXEpgDTSProvider(_host, _options);
1387
566
  }
@@ -1459,7 +638,7 @@ class TXEpgHeaderContainer {
1459
638
  /**
1460
639
  * Returns a `TXEpgChannelContainer` instance
1461
640
  * @since 0.0.22
1462
- * @type {?TXEpgChannelContainer}
641
+ * @type {TXEpgChannelContainer}
1463
642
  * @readonly
1464
643
  */
1465
644
  get channel() {
@@ -1491,7 +670,7 @@ class TXEpgHeaderContainer {
1491
670
  { force: true },
1492
671
  );
1493
672
  if (item) {
1494
- writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
673
+ writeXObjParam(item, dt_str, defParseOptionsSettings.textKey);
1495
674
  };
1496
675
  }
1497
676
 
@@ -1522,63 +701,27 @@ class TXEpgHeaderContainer {
1522
701
  { force: true },
1523
702
  );
1524
703
  if (item) {
1525
- writeXObjParam(item, dt_str, defParseOptions.settings.textKey);
704
+ writeXObjParam(item, dt_str, defParseOptionsSettings.textKey);
1526
705
  };
1527
706
  }
1528
707
 
1529
708
  /**
1530
709
  * Returns a channel info
1531
- * @returns {xepgChnInfoDesc}
710
+ * @returns {IXEpgChnInfoDesc}
1532
711
  */
1533
712
  getChannelInfo() {
1534
713
  return this.channel.getInfo();
1535
714
  }
1536
715
 
1537
- /**
1538
- * @param {xepgChnInfoDesc} obj - channel info descriptor
1539
- * @returns {void}
1540
- * @description Sets a channel info
1541
- * @deprecated
1542
- * @todo [since v0.0.21] deprecate use of `obj`-param as array
1543
- * @todo [since v0.0.22] deprecated. Use `TXEpgChannelContainer.setInfo`
1544
- */
1545
- setChannelInfo(obj) {
1546
- let _obj = obj;
1547
- if (isArray(obj)) {
1548
- // // TODO: [!] deprecate
1549
- const [ chnid, chname, chngid, srcurl ] = _obj;
1550
- _obj = { chnid, chname, chngid, srcurl };
1551
- };
1552
- return this.channel.setInfo(_obj);
1553
- }
1554
-
1555
716
  /**
1556
717
  * Returns a provider info
1557
- * @returns {?xepgProvInfoDesc}
718
+ * @returns {?IXEpgProvInfoDesc}
1558
719
  */
1559
720
  getProviderInfo() {
1560
721
  const docProv = this.provider;
1561
722
  return docProv ? docProv.getInfo() : null;
1562
723
  }
1563
724
 
1564
- /**
1565
- * Sets a provider info
1566
- * @param {xepgProvInfoDesc} obj - provider info descriptor
1567
- * @returns {void}
1568
- * @deprecated
1569
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgProviderContainer.setInfo`
1570
- */
1571
- setProviderInfo(obj) {
1572
- if (isArray(obj) || isObject(obj)) {
1573
- let docProv = this.provider;
1574
- if (!docProv) {
1575
- docProv = this.#_initProv();
1576
- if (docProv) docProv = this.provider;
1577
- };
1578
- if (docProv) docProv.setInfo(obj);
1579
- };
1580
- }
1581
-
1582
725
  /**
1583
726
  * Returns an instance content as a string in an XML-format.
1584
727
  * @since v0.0.20
@@ -1616,6 +759,112 @@ class TXEpgHeaderContainer {
1616
759
  }
1617
760
 
1618
761
  };
762
+ module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
763
+
764
+ /**
765
+ * @since v0.0.30
766
+ * @classdesc This class implements an instance of an element
767
+ * that managea content of a document declaration
768
+ */
769
+ class TXmlContentDeclaration {
770
+ /** @type {INode} */
771
+ #_host;
772
+ /** @type {XEpgElementConfigBase} */
773
+ #_config;
774
+ /** @type {object} */
775
+ #_ctrls;
776
+
777
+ /**
778
+ * Creates an instance of the element
779
+ * @param {INode} obj - some object
780
+ * @param {OPT_epgelsett_bs} [opt] - options
781
+ * @throws {TypeError}
782
+ */
783
+ constructor(obj, opt) {
784
+ if (!isPlainObject(obj)) {
785
+ throw new TypeError(`TXmlContentDeclaration : ${XML_TE_NOBJ_EMSG}`);
786
+ };
787
+ // load options
788
+ //const _options = __evalXMLContainerSettings(opt);
789
+ const config = __evalXMLBaseNodeSettings(opt);
790
+ // set parser options
791
+ let { settings } = config.parseOptions;
792
+ let { declarationKey } = settings;
793
+ // // TODO: [!] need to be rewritten
794
+ // // ([!] need support from `TXmlContentParseOptions` for correct ops)
795
+ if (
796
+ typeof declarationKey !== 'string'
797
+ || ((declarationKey = declarationKey.trim()) === '')
798
+ ) {
799
+ declarationKey = XML_DEF_PARSE_OPTIONS.declarationKey;
800
+ settings.declarationKey = declarationKey;
801
+ };
802
+ // save options
803
+ this.#_config = config;
804
+ // bind a documents content
805
+ this.#_host = obj;
806
+ // init a content declaration element
807
+ this.init();
808
+ }
809
+
810
+ /**
811
+ * Contains a version of an XML
812
+ * @type {string}
813
+ */
814
+ get version() {
815
+ return readXObjAttr(
816
+ this.#_ctrls,
817
+ 'version',
818
+ this.#_config.parseOptions.settings.attributesKey,
819
+ );
820
+ }
821
+
822
+ set version(value) {
823
+ writeXObjAttr(
824
+ this.#_ctrls,
825
+ 'version',
826
+ value,
827
+ this.#_config.parseOptions.settings.attributesKey,
828
+ );
829
+ }
830
+
831
+ /**
832
+ * Contains a document character set
833
+ * @type {string}
834
+ */
835
+ get encoding() {
836
+ return readXObjAttr(
837
+ this.#_ctrls,
838
+ 'encoding',
839
+ this.#_config.parseOptions.settings.attributesKey,
840
+ );
841
+ }
842
+
843
+ set encoding(value) {
844
+ writeXObjAttr(
845
+ this.#_ctrls,
846
+ 'encoding',
847
+ value,
848
+ this.#_config.parseOptions.settings.attributesKey,
849
+ );
850
+ }
851
+
852
+ /**
853
+ * Initializes an instance content.
854
+ * @returns {void}
855
+ */
856
+ init() {
857
+ this.#_ctrls = insertXObjElement(
858
+ this.#_host,
859
+ this.#_config.parseOptions.settings.declarationKey,
860
+ );
861
+ // set version & encoding
862
+ if (!isNotEmptyString(this.version)) this.version = XEPG_XML_DOC_VERSION;
863
+ if (!isNotEmptyString(this.encoding)) this.encoding = XEPG_DEF_ENCODING_VALUE;
864
+ }
865
+
866
+ };
867
+ module.exports.TXmlContentDeclaration = TXmlContentDeclaration;
1619
868
 
1620
869
  /**
1621
870
  * An options set for `TXEpgContentProvider`-class
@@ -1626,7 +875,7 @@ class TXEpgHeaderContainer {
1626
875
 
1627
876
  /**
1628
877
  * An options set for `TXEpgContentProvider`-class
1629
- * @typedef {Object} XEpgContainerSettings
878
+ * @typedef {Object} XEpgContainerConfig
1630
879
  * @property {TXmlContentParseOptions} parseOptions - parser options
1631
880
  * @property {boolean} [autoBindRoot] - <*deprecated*>
1632
881
  */
@@ -1636,12 +885,18 @@ class TXEpgHeaderContainer {
1636
885
  * that manages a content of a XEPG-document
1637
886
  */
1638
887
  class TXEpgContentProvider {
1639
- /** @type {Object} */
888
+ /** @type {INode} */
1640
889
  #_content;
1641
- /** @type {XEpgContainerSettings} */
890
+ /** @type {XEpgContainerConfig} */
1642
891
  #_options;
1643
892
  /** @type {TXmlContentParseOptions} */
1644
893
  #_parseOptions;
894
+ /** @type {TXmlContentDeclaration} */
895
+ #_docDecl;
896
+ /** @type {TXEpgHeaderContainer} */
897
+ #_hdrSect;
898
+ /** @type {TXEpgSchedulesList} */
899
+ #_schedSect;
1645
900
 
1646
901
  /**
1647
902
  * Creates an instance of the XEPG-content provider
@@ -1649,45 +904,47 @@ class TXEpgContentProvider {
1649
904
  */
1650
905
  constructor(opt) {
1651
906
  // load options
1652
- const _options = __evalXMLBaseNodeSettings(opt);
1653
- /** @type {XEpgContainerSettings} */
907
+ /** @type {XEpgContainerConfig} */
908
+ const config = __evalXMLBaseNodeSettings(opt);
1654
909
  let {
1655
910
  parseOptions,
1656
911
  autoBindRoot, // <*reserved*> ([?] - deprecate)
1657
- } = _options;
912
+ } = config;
1658
913
  if (typeof autoBindRoot !== 'boolean') autoBindRoot = false;
1659
914
  // save options
1660
915
  //_options.autoBindRoot = autoBindRoot; //* // TODO:
1661
- this.#_options = _options;
916
+ this.#_options = config;
1662
917
  // save parser options
1663
918
  this.#_parseOptions = parseOptions;
1664
919
  // init document content
1665
- this.#_content = {};
920
+ const content = this.#_content = {};
921
+ // init a content declaration element
922
+ this.#_docDecl = new TXmlContentDeclaration(content, config);
1666
923
  this.init();
1667
924
  }
1668
925
 
1669
926
  /**
1670
- * @returns {?Object}
1671
- */
1672
- #_getRoot() {
1673
- const docRoot = getXObjElement(this.#_content, XEPG_ROOT_ETAG_NAME);
1674
- return isPlainObject(docRoot) ? docRoot : null;
1675
- }
1676
-
1677
- /**
927
+ * Initializes a content root element
928
+ * @param {object} [obj] - object to initialize
929
+ * @param {TXmlContentParseOptions} [opt] - parser options
1678
930
  * @returns {?object}
1679
931
  */
1680
- #_initRoot() {
1681
- const _content = this.#_content;
1682
- let docRoot = getXObjElement(_content, XEPG_ROOT_ETAG_NAME);
932
+ #_initRoot(obj, opt) {
933
+ const content = obj ?? this.#_content;
934
+ let docRoot = getXObjElement(content, XEPG_ROOT_ETAG_NAME);
1683
935
  if (!docRoot) {
1684
- docRoot = insertXObjElement(_content, XEPG_ROOT_ETAG_NAME);
936
+ docRoot = insertXObjElement(content, XEPG_ROOT_ETAG_NAME);
1685
937
  if (docRoot) {
938
+ const config = (
939
+ opt && opt.settings
940
+ ? opt.settings
941
+ : defParseOptionsSettings
942
+ );
1686
943
  writeXObjAttr(
1687
944
  docRoot,
1688
945
  `xmlns:${XEPG_DEF_NS_NAME}`,
1689
946
  XEPG_DEF_NS_PATH,
1690
- defParseOptions.settings.attributesKey,
947
+ config.attributesKey,
1691
948
  );
1692
949
  };
1693
950
  };
@@ -1695,72 +952,72 @@ class TXEpgContentProvider {
1695
952
  }
1696
953
 
1697
954
  /**
1698
- * @returns {?Object}
955
+ * Initializes a document content.
956
+ * @since 0.0.30
957
+ * @param {object} content - some object to initialize
958
+ * @param {XEpgContainerConfig} opt - options
959
+ * @param {boolean} mode - flag
960
+ * @returns {fsoDescr}
1699
961
  */
1700
- #_getHdr() {
1701
- const docRoot = this.#_getRoot();
1702
- let docHdr = null;
1703
- if (docRoot) {
1704
- docHdr = getXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
962
+ #_initContent(content, opt, mode) {
963
+ /** @type {fsoDescr} */
964
+ const result = {
965
+ isERR: false,
966
+ errCode: undefined,
967
+ errEvent: '',
968
+ errMsg: '',
1705
969
  };
1706
- return isPlainObject(docHdr) ? docHdr : null;
1707
- }
1708
-
1709
- /**
1710
- * @returns {?object}
1711
- */
1712
- #_initHdr() {
1713
- let docHdr = this.#_getHdr();
1714
- if (!docHdr) {
1715
- let docRoot = this.#_getRoot();
1716
- if (!docRoot) docRoot = this.#_initRoot();
1717
- if (docRoot) {
970
+ // initiate document root element
971
+ let docRoot = getXObjElement(content, XEPG_ROOT_ETAG_NAME);
972
+ if (!docRoot) docRoot = this.#_initRoot(content, opt.parseOptions);
973
+ if (docRoot) {
974
+ // init a document header element
975
+ let docHdr = getXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
976
+ if (!docHdr) {
1718
977
  docHdr = insertXObjElement(docRoot, XEPG_HEADER_ETAG_NAME);
1719
978
  };
1720
- };
1721
- return isPlainObject(docHdr) ? docHdr : null;
1722
- }
1723
-
1724
- /**
1725
- * @returns {?Object}
1726
- */
1727
- #_getBody() {
1728
- const docRoot = this.#_getRoot();
1729
- let docBody = null;
1730
- if (docRoot) {
1731
- docBody = getXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
1732
- };
1733
- return isPlainObject(docBody) ? docBody : null;
1734
- }
1735
-
1736
- /**
1737
- * @returns {?object}
1738
- */
1739
- #_initBody() {
1740
- let docBody = this.#_getBody();
1741
- if (!docBody) {
1742
- let docRoot = this.#_getRoot();
1743
- if (!docRoot) docRoot = this.#_initRoot();
1744
- if (docRoot) {
979
+ // init a document body element
980
+ let docBody = getXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
981
+ if (!docBody) {
1745
982
  docBody = insertXObjElement(docRoot, XEPG_BODY_ETAG_NAME);
1746
983
  };
984
+ if (docBody) {
985
+ if (typeof docBody[XEPG_SCHED_ETAG_NAME] !== 'object') {
986
+ docBody[XEPG_SCHED_ETAG_NAME] = [];
987
+ } else if (!isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
988
+ let tmpObj = [];
989
+ tmpObj.push(docBody[XEPG_SCHED_ETAG_NAME]);
990
+ docBody[XEPG_SCHED_ETAG_NAME] = tmpObj;
991
+ };
992
+ //isSUCCEED = true;
993
+ };
994
+ if (docHdr && docBody) {
995
+ // init controllers
996
+ const hdrSect = new TXEpgHeaderContainer(docHdr, opt);
997
+ const schedSect = new TXEpgSchedulesList(
998
+ docBody[XEPG_SCHED_ETAG_NAME],
999
+ opt,
1000
+ {
1001
+ dts_src: getXObjElement(docHdr, XEPG_DTSINFO_ETAG_NAME),
1002
+ tz_src: getXObjElement(docHdr, XEPG_DOCTZ_ETAG_NAME),
1003
+ },
1004
+ );
1005
+ this.#_hdrSect = hdrSect;
1006
+ this.#_schedSect = schedSect;
1007
+ };
1747
1008
  };
1748
- return isPlainObject(docBody) ? docBody : null;
1009
+ //==
1010
+ return result;
1749
1011
  }
1750
1012
 
1751
1013
  /**
1752
1014
  * Returns a `TXEpgHeaderContainer` instance
1753
1015
  * @since 0.0.22
1754
- * @type {?TXEpgHeaderContainer}
1016
+ * @type {TXEpgHeaderContainer}
1755
1017
  * @readonly
1756
1018
  */
1757
1019
  get header() {
1758
- const docHdr = this.#_getHdr();
1759
- return (
1760
- docHdr
1761
- ? new TXEpgHeaderContainer(docHdr, this.#_options)
1762
- : null
1763
- );
1020
+ return this.#_hdrSect;
1764
1021
  }
1765
1022
 
1766
1023
  /**
@@ -1784,23 +1041,6 @@ class TXEpgContentProvider {
1784
1041
  return docHdr ? docHdr.dts : null;
1785
1042
  }
1786
1043
 
1787
- /* [!] a temporary special method */
1788
- /**
1789
- * @deprecated
1790
- */
1791
- get Content(){ return this; }
1792
-
1793
- /**
1794
- * Returns a `TXEpgSchedulesList` instance
1795
- * @type {TXEpgSchedulesList}
1796
- * @readonly
1797
- * @deprecated
1798
- * @todo \[since `v0.0.24`] deprecated. Use `TXEpgContentProvider.schedules`
1799
- */
1800
- get SchedulesList() {
1801
- return this.schedules;
1802
- }
1803
-
1804
1044
  /**
1805
1045
  * Returns a `TXEpgSchedulesList` instance
1806
1046
  * @since 0.0.24
@@ -1808,56 +1048,27 @@ class TXEpgContentProvider {
1808
1048
  * @readonly
1809
1049
  */
1810
1050
  get schedules() {
1811
- const _options = this.#_options;
1812
- const docBody = this.#_getBody();
1813
- if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
1814
- const docHdr = this.#_getHdr();
1815
- return new TXEpgSchedulesList(
1816
- docBody[XEPG_SCHED_ETAG_NAME],
1817
- {
1818
- dts_src: getXObjElement(docHdr, XEPG_DTSINFO_ETAG_NAME),
1819
- tz_src: getXObjElement(docHdr, XEPG_DOCTZ_ETAG_NAME),
1820
- },
1821
- );
1822
- };
1051
+ return this.#_schedSect;
1823
1052
  }
1824
1053
 
1825
1054
  /**
1826
1055
  * @returns {void}
1827
1056
  */
1828
1057
  init() {
1829
- const _options = this.#_options;
1830
- const _content = this.#_content;
1058
+ const config = this.#_options;
1059
+ const content = this.#_content;
1831
1060
  const {
1832
1061
  parseOptions,
1833
- } = _options;
1062
+ } = config;
1834
1063
  const { settings } = parseOptions;
1835
- const { ignoreDeclaration } = settings;
1836
- if (!ignoreDeclaration) {
1837
- // write document declaration section
1838
- writeXEpgDocDeclSection(_content);
1839
- };
1840
- // initiate document root element
1841
- let docRoot = this.#_getRoot();
1842
- if (!docRoot) docRoot = this.#_initRoot();
1843
- if (docRoot) {
1844
- // initiate document header element
1845
- let docHdr = this.#_getHdr();
1846
- if (!docHdr) docHdr = this.#_initHdr();
1064
+ // initiate document content declaration element
1065
+ this.#_docDecl.init();
1066
+ // init document content
1067
+ const { isERR } = this.#_initContent(content, config, true);
1068
+ // // TODO: ...
1069
+ if (!isERR) {
1847
1070
  // initiate document provider element
1848
- let docProv = insertXObjElement(
1849
- docHdr,
1850
- XEPG_PRVINFO_ETAG_NAME,
1851
- );
1852
- if (docProv) this.provider.init();
1853
- // initiate document body element
1854
- let docBody = this.#_getBody();
1855
- if (!docBody) docBody = this.#_initBody();
1856
- if (
1857
- docBody && !isArray(docBody[XEPG_SCHED_ETAG_NAME])
1858
- ) {
1859
- docBody[XEPG_SCHED_ETAG_NAME] = [];
1860
- };
1071
+ this.provider.init();
1861
1072
  };
1862
1073
  }
1863
1074
 
@@ -1879,7 +1090,7 @@ class TXEpgContentProvider {
1879
1090
  /**
1880
1091
  * Saves a document content to a file.
1881
1092
  * @param {string} source - a path to a file
1882
- * @returns {Promise<fsoDescr, Error>}
1093
+ * @returns {Promise<fsoDescr>}
1883
1094
  * @throws {Error}
1884
1095
  * @async
1885
1096
  */
@@ -1959,20 +1170,14 @@ class TXEpgContentProvider {
1959
1170
  const { parseOptions } = this.#_options;
1960
1171
  try {
1961
1172
  this.#_content = xmlParser.xml2js(xmlString, parseOptions.xml2js);
1962
- // init a document header element
1963
- let docHdr = this.#_getHdr();
1964
- if (!docHdr) docHdr = this.#_initHdr();
1965
- // init a document body element
1966
- let docBody = this.#_getBody();
1967
- if (!docBody) docBody = this.#_initBody();
1968
- if (docBody) {
1969
- if (typeof docBody[XEPG_SCHED_ETAG_NAME] !== 'object') {
1970
- docBody[XEPG_SCHED_ETAG_NAME] = [];
1971
- } else if (!isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
1972
- let tmpObj = [];
1973
- tmpObj.push(docBody[XEPG_SCHED_ETAG_NAME]);
1974
- docBody[XEPG_SCHED_ETAG_NAME] = tmpObj;
1975
- };
1173
+ // init a document content
1174
+ const { isERR } = this.#_initContent(
1175
+ this.#_content,
1176
+ this.#_options,
1177
+ false,
1178
+ );
1179
+ // // TODO: ...
1180
+ if (!isERR) {
1976
1181
  isSUCCEED = true;
1977
1182
  };
1978
1183
  } catch (err) {
@@ -1986,7 +1191,7 @@ class TXEpgContentProvider {
1986
1191
  /**
1987
1192
  * Loads a document content from a file.
1988
1193
  * @param {string} source - path to a file
1989
- * @returns {Promise<fsoDescr, Error>}
1194
+ * @returns {Promise<fsoDescr>}
1990
1195
  * @throws {Error}
1991
1196
  * @async
1992
1197
  */
@@ -1998,7 +1203,7 @@ class TXEpgContentProvider {
1998
1203
  if (data.content !== '') {
1999
1204
  if (this.loadFromXMLString(data.content)) {
2000
1205
  // // TODO:
2001
- data.isLoaded = true;
1206
+ //data.isLoaded = true;
2002
1207
  data.errEvent = 'OPS_IS_SUCCEED';
2003
1208
  } else {
2004
1209
  data.isERR = true;
@@ -2029,7 +1234,7 @@ class TXEpgContentProvider {
2029
1234
  if (data.content !== '') {
2030
1235
  if (this.loadFromXMLString(data.content)) {
2031
1236
  // // TODO:
2032
- data.isLoaded = true;
1237
+ //data.isLoaded = true;
2033
1238
  data.errEvent = 'OPS_IS_SUCCEED';
2034
1239
  } else {
2035
1240
  data.isERR = true;
@@ -2051,6 +1256,7 @@ class TXEpgContentProvider {
2051
1256
  }
2052
1257
 
2053
1258
  }
1259
+ module.exports.TXEpgContentProvider = TXEpgContentProvider;
2054
1260
 
2055
1261
  // === module exports block ===
2056
1262
 
@@ -2060,9 +1266,3 @@ module.exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
2060
1266
  module.exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
2061
1267
 
2062
1268
  module.exports.TXEpgDTSProvider = TXEpgDTSProvider;
2063
- module.exports.TXEpgScheduleItem = TXEpgScheduleItem;
2064
- module.exports.TXEpgSchedulesList = TXEpgSchedulesList;
2065
- module.exports.TXEpgProviderContainer = TXEpgProviderContainer;
2066
- module.exports.TXEpgChannelContainer = TXEpgChannelContainer;
2067
- module.exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
2068
- module.exports.TXEpgContentProvider = TXEpgContentProvider;