@ygracs/xepg-lib-js 0.0.19 → 0.0.20

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ #### *v0.0.20*
2
+
3
+ Pre-release version.
4
+
5
+ > - `xepgdoc-lib.md` updated;
6
+ > - update dependency on `@ygracs/dtf-lib-js` module to v0.0.26;
7
+ > - updated dependency on `@ygracs/xobj-lib-js` module to v0.2.0;
8
+ > - add method `saveToXMLString` of `TXEpgHeaderContainer` class;
9
+ > - add method `saveToXMLString` of `TXEpgProviderContainer` class;
10
+ > - add method `chkIndex` of `TXEpgSchedulesList` class;
11
+ > - deprecate method `chkScheduleIndex` of `TXEpgSchedulesList` class;
12
+ > - some fixes in `dts-helper.js` lib-module;
13
+ > - `$module/lib/file-helper.js` added.
14
+
1
15
  #### *v0.0.19*
2
16
 
3
17
  Pre-release version.
package/README.md CHANGED
@@ -1,16 +1,12 @@
1
- |***rev.*:**|0.0.5|
1
+ |***rev.*:**|0.0.6|
2
2
  |:---|---:|
3
- |***date***:|2022-12-06|
3
+ |***date***:|2024-10-29|
4
4
 
5
5
  ## Introduction
6
6
 
7
7
  This module provide a base functionality for handling an EPG-sources based on XEPG-format.
8
8
 
9
- > For more information about a XEPG-format see `xepgdoc-spec.md`in the project `doc` directory.
10
-
11
- ## Use cases
12
-
13
- This module was make for use as a library in a development of a Web-apps based on [Electron](https://en.wikipedia.org/wiki/Electron_(software_framework)) as main target.
9
+ > For more information about a XEPG-format see `xepgdoc-spec.md` in the project `doc` directory.
14
10
 
15
11
  ## Description
16
12
 
@@ -37,3 +33,9 @@ For more read the `xepgdoc-lib.md` in the project `doc` directory.
37
33
  - classes:
38
34
 
39
35
  + `TXmlContentParseOptions`;
36
+
37
+ ## Use cases
38
+
39
+ ### Installation
40
+
41
+ `npm install @ygracs/xepg-lib-js`
@@ -1,6 +1,6 @@
1
- |***rev.*:**|0.0.14|
1
+ |***rev.*:**|0.0.15|
2
2
  |:---|---:|
3
- |***date***:|2024-07-17|
3
+ |***date***:|2024-10-28|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -16,11 +16,15 @@ This class provides a functionality for handle an EPG-schedules list.
16
16
 
17
17
  #### class constructor
18
18
 
19
- The class constructor creates a new instance of the class. It receives arguments listed below:
19
+ The class constructor creates a new instance of the class.
20
+
21
+ ##### constructor parameters
22
+
23
+ The class constructor receives arguments listed below:
20
24
 
21
25
  |name|type|default value|description|
22
26
  |:---|---|---:|:---|
23
- |`object`|---|---|a host object|
27
+ |`object`|`array`|---|a host object|
24
28
  |`options`|`object`|---|an options settings|
25
29
 
26
30
  #### class properties
@@ -35,23 +39,29 @@ The table below describes a properties of a `TXEpgSchedulesList` class:
35
39
 
36
40
  #### class methods
37
41
 
38
- ##### **hasNoSchedules()**
42
+ ##### **hasNoSchedules()** => `boolean`
39
43
 
40
44
  This method returns `true` if a document contains no schedules.
41
45
 
42
- ##### **hasSchedules()**
46
+ ##### **hasSchedules()** => `boolean`
43
47
 
44
48
  This method returns `true` if a document contains at least one schedule.
45
49
 
46
- ##### **chkScheduleIndex(value)**
50
+ ##### **chkScheduleIndex(value)** => `boolean`
51
+
52
+ > WARNING: This method deprecated (*since `v0.0.20`*). Use `chkIndex` instead.
53
+
54
+ ##### **chkIndex(value)** => `boolean`
55
+
56
+ > since: `v0.0.20`
47
57
 
48
58
  This method checks if a given `value` represents a valid schedule index and if so returns `true`.
49
59
 
50
- ##### **getScheduleInfo(index)**
60
+ ##### **getScheduleInfo(index)** => `object`
51
61
 
52
62
  This method returns an object that contains a schedule information.
53
63
 
54
- ##### **getAllSchedulesInfo()**
64
+ ##### **getAllSchedulesInfo()** => `object[]`
55
65
 
56
66
  This method returns an array that contains an information for all available schedules.
57
67
 
@@ -65,12 +75,16 @@ This class implements a structure that holds an information about a program prov
65
75
 
66
76
  #### class constructor
67
77
 
68
- The class constructor creates a new instance of the class. It receives arguments listed below:
78
+ The class constructor creates a new instance of the class.
79
+
80
+ ##### constructor parameters
81
+
82
+ The class constructor receives arguments listed below:
69
83
 
70
84
  |name|type|default value|description|
71
85
  |:---|---|---:|:---|
72
- |`object`|---|---|a host object|
73
- |`options`|---|---|an option settings|
86
+ |`object`|`object`|---|a host object|
87
+ |`options`|`object`|---|an option settings|
74
88
 
75
89
  The `options` structure is listed below:
76
90
 
@@ -91,18 +105,32 @@ The table below describes a properties of a `TXEpgProviderContainer` class:
91
105
 
92
106
  #### class methods
93
107
 
94
- ##### **setName(value)**
108
+ ##### **setName(value)** => `boolean`
95
109
 
96
110
  This method sets a name of a provider to a given `value`.
97
111
 
98
- ##### **getInfo()**
112
+ ##### **getInfo()** => `object`
99
113
 
100
- This method returns an `object` that contains information about content provider.
114
+ This method returns an `object` that contains information about content provider. An object contains a field listed in the table below:
101
115
 
102
- ##### **setInfo(obj)**
116
+ |property name|value type|description|
117
+ |:---|---|:---|
118
+ |`name`|`string`|a provider name|
119
+ |`version`|`string`|a provider version|
120
+ |`schema`|`string`|a document schema version|
121
+ |`doctype`|`string`|a document type|
122
+
123
+
124
+ ##### **setInfo(obj)** => `void`
103
125
 
104
126
  This method loads information about content provider.
105
127
 
128
+ ##### **saveToXMLString()** => `string`
129
+
130
+ > since: `v0.0.20`
131
+
132
+ This method saves an element content to a string.
133
+
106
134
  #### class methods (*special*)
107
135
 
108
136
  ##### **init()**
@@ -111,7 +139,11 @@ This method loads information about content provider.
111
139
 
112
140
  #### class constructor
113
141
 
114
- The class constructor creates a new instance of the class. It receives arguments listed below:
142
+ The class constructor creates a new instance of the class.
143
+
144
+ ##### constructor parameters
145
+
146
+ The class constructor receives arguments listed below:
115
147
 
116
148
  |name|type|default value|description|
117
149
  |:---|---|---:|:---|
@@ -137,7 +169,11 @@ The table below describes a properties of a `TXEpgDTSProvider` class:
137
169
 
138
170
  #### class constructor
139
171
 
140
- The class constructor creates a new instance of the class. It receives arguments listed below:
172
+ The class constructor creates a new instance of the class.
173
+
174
+ ##### constructor parameters
175
+
176
+ The class constructor receives arguments listed below:
141
177
 
142
178
  |name|type|default value|description|
143
179
  |:---|---|---:|:---|
@@ -163,23 +199,23 @@ The table below describes a properties of a `TXEpgHeaderContainer` class:
163
199
 
164
200
  #### class methods
165
201
 
166
- ##### **getDocumentDT()**
202
+ ##### **getDocumentDT()** => `number`
167
203
 
168
- This method returns a time value of a document creation.
204
+ This method returns a time value of a document creation as a timestamp.
169
205
 
170
- ##### **setDocumentDT()**
206
+ ##### **setDocumentDT()** => `void`
171
207
 
172
208
  This method sets a time value of a document creation.
173
209
 
174
- ##### **getDocumentEDT()**
210
+ ##### **getDocumentEDT()** => `number`
175
211
 
176
- This method returns a time value from which a document is expired.
212
+ This method returns a time value from which a document is expired as a timestamp.
177
213
 
178
- ##### **setDocumentEDT(value)**
214
+ ##### **setDocumentEDT(value)** => `void`
179
215
 
180
216
  This method sets a time value at which a document will be expired.
181
217
 
182
- ##### **getChannelInfo()**
218
+ ##### **getChannelInfo()** => `object`
183
219
 
184
220
  This method returns an object which contains a channel information.
185
221
 
@@ -187,12 +223,12 @@ An object contains the following fields:
187
223
 
188
224
  |field name|field type|description|
189
225
  |:---|---|:---|
190
- |`chnid`|`ID_STRING`|a channel ID|
226
+ |`chnid`|`srting`|a channel ID|
227
+ |`chngid`|`string`|a channel 'Group ID'|
191
228
  |`chname`|`string`|a name of the channel|
192
- |`chngid`|`ID_STRING`|a channel group|
193
229
  |`srcurl`|`string`|a link to source|
194
230
 
195
- ##### **setChannelInfo(obj)**
231
+ ##### **setChannelInfo(obj)** => `void`
196
232
 
197
233
  This method fills a channel information with a given data.
198
234
 
@@ -208,22 +244,32 @@ If an object is given it contains the following fields:
208
244
 
209
245
  |field name|field type|description|
210
246
  |:---|---|:---|
211
- |`chnid`|`ID_STRING`|a channel ID|
247
+ |`chnid`|`string`|a channel ID|
212
248
  |`chname`|`string`|a name of the channel|
213
- |`chngid`|`ID_STRING`|a channel group|
249
+ |`chngid`|`string`|a channel group|
214
250
  |`srcurl`|`string`|a link to source|
215
251
 
216
- ##### **getProviderInfo()**
252
+ ##### **getProviderInfo()** => `object`
217
253
 
218
254
  This method returns an object which contains an information about document provider.
219
255
 
220
256
  ##### **setProviderInfo(obj)**
221
257
 
258
+ ##### **saveToXMLString()** => `string`
259
+
260
+ > since: `v0.0.20`
261
+
262
+ This method saves an element content to a string.
263
+
222
264
  ### **TXEpgContentProvider**
223
265
 
224
266
  #### class constructor
225
267
 
226
- The class constructor creates a new instance of the class. It receives arguments listed below:
268
+ The class constructor creates a new instance of the class.
269
+
270
+ ##### constructor parameters
271
+
272
+ The class constructor receives arguments listed below:
227
273
 
228
274
  |name|type|default value|description|
229
275
  |:---|---|---:|:---|
@@ -249,41 +295,39 @@ The table below describes a properties of a `TXEpgContentProvider` class:
249
295
 
250
296
  #### class methods
251
297
 
252
- ##### **loadFromString(xmlString, options)**
298
+ ##### **loadFromString(xmlString, options)** => `boolean`
253
299
 
254
300
  > WARNING: This method deprecated (*since `v0.0.18`*). Use `loadFromXMLString` instead.
255
301
 
256
- ##### **loadFromXMLString(xmlString, options)**
302
+ ##### **loadFromXMLString(xmlString, options)** => `boolean`
257
303
 
258
304
  > since: `v0.0.18`
259
305
 
260
306
  This method loads a document content from string containing text in XML format.
261
307
 
262
- ##### **loadFromFile(src)**
308
+ ##### **loadFromFile(src)** => `object`
263
309
 
264
310
  This method loads a document content from a file. A `src` provided a string that is a path to the file.
265
311
 
266
- ##### **loadFromFileSync(src)**
312
+ ##### **loadFromFileSync(src)** => `object`
267
313
 
268
314
  This method loads a document content from a file. A `src` provided a string that is a path to the file.
269
315
 
270
- ##### **saveToXMLString()**
316
+ ##### **saveToXMLString()** => `string`
271
317
 
272
318
  This method saves a document content to a string.
273
319
 
274
- ##### **saveToFile(src)**
320
+ ##### **saveToFile(src)** => `object`
275
321
 
276
322
  This method saves a document content to a file. A `src` provided a string that is a path to the file.
277
323
 
278
- ##### **saveToFileSync(src)**
324
+ ##### **saveToFileSync(src)** => `object`
279
325
 
280
326
  This method saves a document content to a file. A `src` provided a string that is a path to the file.
281
327
 
282
328
  ##### **asXML(options)**
283
329
 
284
- This method saves a document content to a string.
285
-
286
- > Note: will deprecate. Use `saveToXMLString` instead.
330
+ > WARNING: This method deprecated (*since `v0.0.18`*). Use `saveToXMLString` instead.
287
331
 
288
332
  #### class methods (*special*)
289
333
 
package/lib/dts-helper.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.1.043-20230711]
1
+ // [v0.1.045-20240829]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -11,21 +11,42 @@ const {
11
11
  convDTValueToISO8601,
12
12
  convDTValueToXMLTV, convXMLTVToDTValue,
13
13
  convDTValueToDateString,
14
+ tryDTValue,
14
15
  } = require('@ygracs/dtf-lib-js');
15
16
 
17
+ // === module extra block (helper functions) ===
18
+
19
+ // === module main block ===
20
+
21
+ /***
22
+ * (* constant definitions *)
23
+ */
24
+
16
25
  const def_dts_param = [
17
26
  'default', 'iso8601', 'xmltv', 'timestamp', 'utc',
18
27
  ];
19
28
 
20
- // === module extra block (helper functions) ===
21
-
22
- // === module main block (function definitions) ===
29
+ /***
30
+ * (* function definitions *)
31
+ */
23
32
 
33
+ /**
34
+ * @function chkDTSysID
35
+ * @param {(number|string)} value
36
+ * @returns {boolean}
37
+ * @description Checs if a given value is a valid dtstype ID
38
+ */
24
39
  function chkDTSysID(value){
25
40
  const _value = valueToIndex(value);
26
41
  return _value !== -1 && def_dts_param[_value] ? true : false;
27
42
  };
28
43
 
44
+ /**
45
+ * @function getDTSysName
46
+ * @param {(number|string)} value
47
+ * @returns {string}
48
+ * @description Returns a dtstype name by a given dtstype ID
49
+ */
29
50
  function getDTSysName(value){
30
51
  let result = 'undefined';
31
52
  if (chkDTSysID(value)) {
@@ -34,6 +55,19 @@ function getDTSysName(value){
34
55
  return result;
35
56
  };
36
57
 
58
+ /**
59
+ * @typedef DTSysDescr
60
+ * @type {object}
61
+ * @property {number} index - dtstype ID
62
+ * @property {string} name - dtstype name
63
+ */
64
+
65
+ /**
66
+ * @function getDTSysDescr
67
+ * @param {(number|string)} value
68
+ * @returns {DTSysDescr}
69
+ * @description Returns a dtstype description for a given dtstype ID
70
+ */
37
71
  function getDTSysDescr(value){
38
72
  let index = valueToIndex(value);
39
73
  let name = 'undefined';
@@ -50,15 +84,23 @@ function getDTSysDescr(value){
50
84
  return { index, name };
51
85
  };
52
86
 
53
- function convStringToDTValue(value, dts_id, tz){
87
+ /**
88
+ * @function convStringToDTValue
89
+ * @param {string} value
90
+ * @param {(number|string)} [dts_id=0]
91
+ * @param {(number|string)} [tz]
92
+ * @returns {number}
93
+ * @description Tries to convert a given string to timestamp
94
+ */
95
+ function convStringToDTValue(value, dts_id = 0, tz){
96
+ const dtstype = getDTSysName(dts_id);
54
97
  let result = 0;
55
- let dtstype = valueToIndex(dts_id);
56
- let dt_str = typeof value === 'string' ? value : '';
57
- if (chkDTSysID(dtstype)) {
58
- switch (getDTSysName(dtstype)) {
98
+ if (dtstype !== 'undefined') {
99
+ switch (dtstype) {
59
100
  case 'default': {
60
101
  // TODO: check TZ
61
102
  //console.log('convStringToDTValue => dtstype:[default]');
103
+ let dt_str = typeof value === 'string' ? value : '';
62
104
  result = (new Date(dt_str)).getTime();
63
105
  //console.log('convStringToDTValue => value:['+value+']');
64
106
  //console.log('convStringToDTValue => result:['+result+']');
@@ -67,7 +109,8 @@ function convStringToDTValue(value, dts_id, tz){
67
109
  case 'iso8601': {
68
110
  // TODO: check TZ
69
111
  //console.log('convStringToDTValue => dtstype:[iso8601]');
70
- result = (new Date(dt_str)).getTime();
112
+ let dtStr = typeof value === 'string' ? value : '';
113
+ if (dtStr !== '') result = (new Date(dtStr)).getTime();
71
114
  //console.log('convStringToDTValue => value:['+value+']');
72
115
  //console.log('convStringToDTValue => result:['+result+']');
73
116
  break;
@@ -75,7 +118,8 @@ function convStringToDTValue(value, dts_id, tz){
75
118
  case 'xmltv': {
76
119
  // TODO: check TZ
77
120
  //console.log('convStringToDTValue => dtstype:[xmltv]');
78
- result = (new Date(convXMLTVToDTValue(dt_str))).getTime();
121
+ const dtValue = convXMLTVToDTValue(value, true);
122
+ if (dtValue !== null) result = dtValue;
79
123
  //console.log('convStringToDTValue => value:['+value+']');
80
124
  //console.log('convStringToDTValue => result:['+result+']');
81
125
  break;
@@ -83,7 +127,8 @@ function convStringToDTValue(value, dts_id, tz){
83
127
  case 'timestamp': {
84
128
  // TODO: check TZ
85
129
  //console.log('convStringToDTValue => dtstype:[timestamp]');
86
- result = Number(dt_str);
130
+ const { isSucceed, value: dtValue } = tryDTValue(value);
131
+ if (isSucceed) result = dtValue.getTime();
87
132
  //console.log('convStringToDTValue => value:['+value+']');
88
133
  //console.log('convStringToDTValue => result:['+result+']');
89
134
  break;
@@ -91,20 +136,27 @@ function convStringToDTValue(value, dts_id, tz){
91
136
  case 'utc': {
92
137
  // TODO: check TZ
93
138
  //console.log('convStringToDTValue => dtstype:[utc]');
94
- result = (new Date(Date.UTC(dt_str))).getTime();
139
+ let dtStr = typeof value === 'string' ? value : '';
140
+ if (dtStr !== '') result = (new Date(Date.UTC(dtStr))).getTime();
95
141
  //console.log('convStringToDTValue => value:['+value+']');
96
142
  //console.log('convStringToDTValue => result:['+result+']');
97
143
  break;
98
144
  }
99
- default: {
100
- break;
101
- }
145
+ default: {}
102
146
  };
103
147
  if (Number.isNaN(result)) result = 0;
104
148
  };
105
149
  return result;
106
150
  };
107
151
 
152
+ /**
153
+ * @function convDTValueToString
154
+ * @param {(number|string|Date)} value
155
+ * @param {(number|string)} dts_id
156
+ * @param {(number|string)} tz
157
+ * @returns {string}
158
+ * @description Tries to convert a given value to its string representation
159
+ */
108
160
  function convDTValueToString(value, dts_id, tz){
109
161
  let result = '';
110
162
  let dt_val = (
@@ -163,7 +215,9 @@ function convDTValueToString(value, dts_id, tz){
163
215
  return result;
164
216
  };
165
217
 
166
- // === module main block (class definitions) ===
218
+ /***
219
+ * (* class definitions *)
220
+ */
167
221
 
168
222
  // === module exports block ===
169
223