@ygracs/xepg-lib-js 0.0.21 → 0.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygracs/xepg-lib-js",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "A library for handling an EPG-sources based on an XEPG-format",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -8,29 +8,22 @@
8
8
  "type": "git",
9
9
  "url": "git+https://gitlab.com/ygracs/xepg-lib-js.git"
10
10
  },
11
+ "keywords": [
12
+ "xml",
13
+ "EPG"
14
+ ],
11
15
  "main": "./index.js",
12
16
  "files": [
13
- "doc/xepgdoc-lib.md",
14
- "doc/xepgdoc-spec.md",
15
17
  "doc/xepgdoc-spec-draft.dtd",
16
- "doc/xepgdoc-example.xepg",
18
+ "doc/*.xepg",
19
+ "doc/*.md",
17
20
  "lib/xepgdoc-lib.js",
18
21
  "lib/dts-helper.js",
19
- "lib/file-helper.js",
20
22
  "index.js",
21
23
  "CHANGELOG.md"
22
24
  ],
23
25
  "scripts": {
24
26
  "test": "cross-env TZ='Etc/UTC' jest",
25
- "test-xepg": "TZ='Etc/UTC' jest ./test",
26
- "test-xepg:sl": "jest TXEpgSchedulesList",
27
- "test-xepg:hc": "TZ='Etc/UTC' jest TXEpgHeader",
28
- "test-xepg:pc": "jest TXEpgProvider",
29
- "test-xepg:dts": "jest TXEpgDTS",
30
- "test-xepg:cp": "jest TXEpgContentProvider",
31
- "win:test": "set TZ='Etc/UTC' && jest",
32
- "win:test-xepg": "set TZ='Etc/UTC' && jest ./test",
33
- "win:test-xepg:hc": "set TZ='Etc/UTC' && jest TXEpgHeader",
34
27
  "build-doc-md": "jsdoc2md",
35
28
  "build-doc-html": "jsdoc"
36
29
  },
@@ -39,10 +32,11 @@
39
32
  "#test-dir/*": "./__test__/*"
40
33
  },
41
34
  "dependencies": {
42
- "@ygracs/bsfoc-lib-js": "^0.2.2",
43
- "@ygracs/dtf-lib-js": "^0.0.27",
44
- "@ygracs/xml-js6": "^0.0.4-b",
45
- "@ygracs/xobj-lib-js": "^0.2.1"
35
+ "@cntwg/file-helper": "^0.0.1",
36
+ "@ygracs/bsfoc-lib-js": "^0.2.3",
37
+ "@ygracs/dtf-lib-js": "^0.0.28",
38
+ "@ygracs/xml-js6": "^0.0.5-b",
39
+ "@ygracs/xobj-lib-js": "^0.2.2"
46
40
  },
47
41
  "devDependencies": {
48
42
  "cross-env": "^7.0.3",
@@ -1,278 +0,0 @@
1
- // [v0.1.030-20241029]
2
-
3
- // === module init block ===
4
-
5
- const fs = require('fs');
6
- const fse = require('fs').promises;
7
-
8
- const {
9
- isPlainObject,
10
- } = require('@ygracs/bsfoc-lib-js');
11
-
12
- // === module extra block (helper functions) ===
13
-
14
- /**
15
- * @typedef {Object} fsoDescr
16
- * @property {boolean} isERR - flag
17
- * @property {number|undefined} errCode - error code
18
- * @property {string} errEvent - event ID
19
- * @property {string} errMsg - event message
20
- * @property {string} source - path to file
21
- * @property {any} content - file content
22
- * @description A fs ops description.
23
- */
24
-
25
- /**
26
- * @typedef {Object} VCOR_evalerrfs
27
- * @property {boolean} isSucceed - ops flag
28
- * @property {fsoDescr} descr - description
29
- * @description A result of an error check ops.
30
- */
31
-
32
- /**
33
- * @function checkFsError
34
- * @param {fsoDescr} descr
35
- * @param {Error} err
36
- * @returns {VCOR_evalerrfs}
37
- * @inner
38
- * @description Checks an error code of a fs ops and sets descr info if succeed
39
- */
40
- function checkFsError(descr, err) {
41
- let isSucceed = false;
42
- if (isPlainObject(err) && isPlainObject(descr)) {
43
- switch (err.code) {
44
- case 'ENOENT':
45
- case 'EISDIR':
46
- case 'ENOTDIR':
47
- case 'EPERM': {
48
- descr.errCode = err.errno;
49
- descr.errEvent = err.code;
50
- descr.errMsg = `ERR_FILE_${err.code}`;
51
- isSucceed = true;
52
- break;
53
- }
54
- default: {}
55
- };
56
- if (isSucceed) descr.isERR = true;
57
- };
58
- return { isSucceed, descr };
59
- };
60
-
61
- // === module main block ===
62
-
63
- /***
64
- * (* constant definitions *)
65
- */
66
-
67
- /***
68
- * (* function definitions *)
69
- */
70
-
71
- /**
72
- * @function loadFileSync
73
- * @param {string} src - a path to some file
74
- * @returns {fsoDescr}
75
- * @inner
76
- * @description Loads file by a given path
77
- */
78
- function loadFileSync(src) {
79
- /** @type {fsoDescr} */
80
- const data = {
81
- isERR: false,
82
- errCode: 0,
83
- errEvent: '',
84
- errMsg: '',
85
- source: '',
86
- content: '',
87
- };
88
- if (typeof src !== 'string') {
89
- if (src !== undefined) {
90
- data.isERR = true;
91
- data.errEvent = 'ERR_INVARG';
92
- data.errMsg = 'The "source" argument must be a string';
93
- };
94
- } else {
95
- const srcPath = src.trim();
96
- if (srcPath !== '') {
97
- data.source = srcPath;
98
- try {
99
- data.content = fs.readFileSync(srcPath, 'utf8');
100
- } catch (err) {
101
- const { isSucceed } = checkFsError(data, err);
102
- if (!isSucceed) {
103
- // // TODO: [?] consider check others
104
- //console.log(`TEST_ERR-MSG:loadFileSync: ${err}`);
105
- //throw err;
106
- };
107
- };
108
- };
109
- };
110
- return data;
111
- };
112
-
113
- /**
114
- * @function loadFile
115
- * @param {string} src - a path to some file
116
- * @returns {Promise<fsoDescr, Error>}
117
- * @async
118
- * @inner
119
- * @description Loads file by a given path
120
- */
121
- function loadFile(src) {
122
- /**/// main part that return promise as a result
123
- return new Promise((resolve, reject) => {
124
- /** @type {fsoDescr} */
125
- const data = {
126
- isERR: false,
127
- errCode: 0,
128
- errEvent: '',
129
- errMsg: '',
130
- source: '',
131
- content: '',
132
- };
133
- if (typeof src !== 'string') {
134
- if (src !== undefined) {
135
- data.isERR = true;
136
- data.errEvent = 'ERR_INVARG';
137
- data.errMsg = 'The "source" argument must be a string';
138
- };
139
- resolve(data);
140
- } else {
141
- const srcPath = src.trim();
142
- if (srcPath === '') resolve(data);
143
- data.source = srcPath;
144
- fse.readFile(srcPath, 'utf8').then(result => {
145
- data.content = result;
146
- resolve(data);
147
- }).catch(err => {
148
- let { isSucceed } = checkFsError(data, err);
149
- if (isSucceed) {
150
- data.content = '';
151
- resolve(data);
152
- } else {
153
- //console.log('CHECK: loadFile() => Error => '+err);
154
- //console.log('CHECK: loadFile() => Error => '+err.code);
155
- reject(err);
156
- };
157
- });
158
- };
159
- });
160
- };
161
-
162
- /**
163
- * @function saveToFileSync
164
- * @param {string} src - a path to some file
165
- * @param {string} content - some file content
166
- * @param {any} [opt] - <reserved>
167
- * @returns {fsoDescr}
168
- * @inner
169
- * @description Saves a content to a file
170
- */
171
- function saveToFileSync(src, content = '', opt) {
172
- /** @type {fsoDescr} */
173
- const data = {
174
- isERR: false,
175
- errCode: 0,
176
- errEvent: '',
177
- errMsg: '',
178
- source: '',
179
- content: '',
180
- };
181
- if (typeof src !== 'string') {
182
- data.isERR = true;
183
- data.errEvent = src === undefined ? 'ERR_NOSRC' : 'ERR_INVARG';
184
- data.errMsg = 'The "source" argument must be a string';
185
- } else if (typeof content === 'string') {
186
- const srcPath = src.trim();
187
- if (srcPath === '') {
188
- data.isERR = true;
189
- data.errEvent = 'ERR_NOSRC';
190
- data.errMsg = 'No "source" path given';
191
- } else {
192
- data.source = srcPath;
193
- try {
194
- fs.writeFileSync(srcPath, content, 'utf8');
195
- } catch (err) {
196
- const { isSucceed } = checkFsError(data, err);
197
- if (!isSucceed) {
198
- // // TODO: [?] consider check others
199
- //console.log(`TEST_ERR-MSG:saveToFileSync: ${err}`);
200
- //throw err;
201
- };
202
- };
203
- };
204
- } else {
205
- data.isERR = true;
206
- data.errEvent = 'ERR_INVARG';
207
- data.errMsg = 'The "content" argument must be a string';
208
- };
209
- return data;
210
- };
211
-
212
- /**
213
- * @function saveToFile
214
- * @param {string} src - a path to some file
215
- * @param {string} content - some file content
216
- * @param {any} [opt] - <reserved>
217
- * @returns {Promise<fsoDescr, Error>}
218
- * @async
219
- * @inner
220
- * @description Saves a content to a file
221
- */
222
- function saveToFile(src, content = '', opt) {
223
- /**/// main part that return promise as a result
224
- return new Promise((resolve, reject) => {
225
- /** @type {fsoDescr} */
226
- const data = {
227
- isERR: false,
228
- errCode: 0,
229
- errEvent: '',
230
- errMsg: '',
231
- source: '',
232
- content: '',
233
- };
234
- if (typeof src !== 'string') {
235
- data.isERR = true;
236
- data.errEvent = src === undefined ? 'ERR_NOSRC' : 'ERR_INVARG';
237
- data.errMsg = 'The "source" argument must be a string';
238
- resolve(data);
239
- } else if (typeof content === 'string') {
240
- const srcPath = src.trim();
241
- if (srcPath === '') {
242
- data.isERR = true;
243
- data.errEvent = 'ERR_NOSRC';
244
- data.errMsg = 'No "source" path given';
245
- resolve(data);
246
- } else {
247
- data.source = srcPath;
248
- fse.writeFile(srcPath, content, 'utf8').then(result => {
249
- resolve(data);
250
- }).catch(err => {
251
- const { isSucceed } = checkFsError(data, err);
252
- if (isSucceed) resolve(data);
253
- // // TODO: [?] consider check others
254
- //console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err);
255
- //console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err.code);
256
- reject(err);
257
- });
258
- };
259
- } else {
260
- data.isERR = true;
261
- data.errEvent = 'ERR_INVARG';
262
- data.errMsg = 'The "content" argument must be a string';
263
- resolve(data);
264
- };
265
- });
266
- };
267
-
268
- /***
269
- * (* class definitions *)
270
- */
271
-
272
- // === module exports block ===
273
-
274
- module.exports.checkFsError = checkFsError;
275
- module.exports.loadFile = loadFile;
276
- module.exports.loadFileSync = loadFileSync;
277
- module.exports.saveToFile = saveToFile;
278
- module.exports.saveToFileSync = saveToFileSync;