@ygracs/xepg-lib-js 0.0.20 → 0.0.21

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.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.0.008-20230326]
1
+ // [v0.0.009-20250225]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -15,9 +15,12 @@ const xObj = require('@ygracs/xobj-lib-js');
15
15
  /**/// v1 branch
16
16
  exports.TXEpgContentProvider = xepg_doc.TXEpgContentProvider;
17
17
  exports.TXEpgSchedulesList = xepg_doc.TXEpgSchedulesList;
18
- exports.TXepgDTSProvider = xepg_doc.TXepgDTSProvider;
18
+ exports.TXEpgDTSProvider = xepg_doc.TXEpgDTSProvider;
19
19
  exports.TXEpgProviderContainer = xepg_doc.TXEpgProviderContainer;
20
20
  exports.TXEpgHeaderContainer = xepg_doc.TXEpgHeaderContainer;
21
21
 
22
22
  // re-export stuff from `@ygracs/xobj-lib-js` module
23
23
  exports.TXmlContentParseOptions = xObj.TXmlContentParseOptions;
24
+
25
+ /**/// will deprecate
26
+ exports.TXepgDTSProvider = xepg_doc.TXepgDTSProvider;
package/lib/dts-helper.js CHANGED
@@ -1,10 +1,9 @@
1
- // [v0.1.045-20240829]
1
+ // [v0.1.047-20250225]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- valueToIndex, readAsString, readAsNumberEx,
7
- isDateObject,
6
+ valueToIndex,
8
7
  } = require('@ygracs/bsfoc-lib-js');
9
8
 
10
9
  const {
@@ -32,22 +31,22 @@ const def_dts_param = [
32
31
 
33
32
  /**
34
33
  * @function chkDTSysID
35
- * @param {(number|string)} value
34
+ * @param {(number|string)} value - value to verify
36
35
  * @returns {boolean}
37
36
  * @description Checs if a given value is a valid dtstype ID
38
37
  */
39
- function chkDTSysID(value){
38
+ function chkDTSysID(value) {
40
39
  const _value = valueToIndex(value);
41
40
  return _value !== -1 && def_dts_param[_value] ? true : false;
42
41
  };
43
42
 
44
43
  /**
45
44
  * @function getDTSysName
46
- * @param {(number|string)} value
45
+ * @param {(number|string)} value - DTS-type identifier
47
46
  * @returns {string}
48
47
  * @description Returns a dtstype name by a given dtstype ID
49
48
  */
50
- function getDTSysName(value){
49
+ function getDTSysName(value) {
51
50
  let result = 'undefined';
52
51
  if (chkDTSysID(value)) {
53
52
  result = def_dts_param[Number(value)];
@@ -56,19 +55,19 @@ function getDTSysName(value){
56
55
  };
57
56
 
58
57
  /**
59
- * @typedef DTSysDescr
60
- * @type {object}
58
+ * @typedef {Object} DTSysDescr
61
59
  * @property {number} index - dtstype ID
62
60
  * @property {string} name - dtstype name
61
+ * @description A DTS-type descriptor
63
62
  */
64
63
 
65
64
  /**
66
65
  * @function getDTSysDescr
67
- * @param {(number|string)} value
66
+ * @param {(number|string)} value - DTS-type identifier
68
67
  * @returns {DTSysDescr}
69
68
  * @description Returns a dtstype description for a given dtstype ID
70
69
  */
71
- function getDTSysDescr(value){
70
+ function getDTSysDescr(value) {
72
71
  let index = valueToIndex(value);
73
72
  let name = 'undefined';
74
73
  if (index !== -1) {
@@ -86,13 +85,14 @@ function getDTSysDescr(value){
86
85
 
87
86
  /**
88
87
  * @function convStringToDTValue
89
- * @param {string} value
90
- * @param {(number|string)} [dts_id=0]
91
- * @param {(number|string)} [tz]
88
+ * @param {string} value - some value
89
+ * @param {(number|string)} [dts_id=0] - DTS-type identifier
90
+ * @param {(number|string)} [tz] - <*reserved*>
92
91
  * @returns {number}
93
92
  * @description Tries to convert a given string to timestamp
93
+ * @todo check TZ
94
94
  */
95
- function convStringToDTValue(value, dts_id = 0, tz){
95
+ function convStringToDTValue(value, dts_id = 0, tz) {
96
96
  const dtstype = getDTSysName(dts_id);
97
97
  let result = 0;
98
98
  if (dtstype !== 'undefined') {
@@ -151,20 +151,17 @@ function convStringToDTValue(value, dts_id = 0, tz){
151
151
 
152
152
  /**
153
153
  * @function convDTValueToString
154
- * @param {(number|string|Date)} value
155
- * @param {(number|string)} dts_id
156
- * @param {(number|string)} tz
154
+ * @param {(number|string|Date)} value - some value
155
+ * @param {(number|string)} [dts_id=0] - DTS-type identifier
156
+ * @param {(number|string)} [tz] - <*reserved*>
157
157
  * @returns {string}
158
158
  * @description Tries to convert a given value to its string representation
159
+ * @todo check TZ
159
160
  */
160
- function convDTValueToString(value, dts_id, tz){
161
+ function convDTValueToString(value, dts_id, tz) {
162
+ let { isSucceed, value: dtValue } = tryDTValue(value);
163
+ let dt_val = isSucceed ? dtValue.getTime() : new Date(0);
161
164
  let result = '';
162
- let dt_val = (
163
- isDateObject(value)
164
- ? value
165
- : (new Date(readAsNumberEx(value, 0)))
166
- ).getTime();
167
- if (Number.isNaN(dt_val)) dt_val = new Date(0);
168
165
  let dtstype = valueToIndex(dts_id);
169
166
  if (!chkDTSysID(dtstype)) dtstype = 0;
170
167
  switch (getDTSysName(dtstype)) {
@@ -208,9 +205,7 @@ function convDTValueToString(value, dts_id, tz){
208
205
  //console.log('convDTValueToString => result:['+result+']');
209
206
  break;
210
207
  }
211
- default: {
212
- break;
213
- }
208
+ default: {}
214
209
  };
215
210
  return result;
216
211
  };