@ygracs/chn-alias-list 0.0.3

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 ADDED
@@ -0,0 +1,3 @@
1
+ #### *v0.0.1-0.0.3*
2
+
3
+ Pre-release version.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024-2024 Yuri Grachev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ |***rev.*:**|0.0.1|
2
+ |:---|---:|
3
+ |***date***:|2024-06-18|
4
+
5
+ ## Introduction
6
+
7
+ This module provide a small helper library which implements some classes used as helper objects to deal with instances of an EPG-sources.
8
+
9
+ ## Content
10
+
11
+ > for detailed description of the classes and function listed below see the [docs](doc/chn-alias-list.md).
12
+
13
+ ### 1. classes:
14
+
15
+ - base elements:
16
+ - TChnNameRecord;
17
+ - TChnNamesList;
18
+
19
+ - lists:
20
+ - TChnAliasItem;
21
+ - TChnAliasList.
22
+
23
+ ### 2. functions:
24
+
25
+ - loadAliasFromFileSync;
26
+ - saveAliasToFileSync.
27
+
28
+ ## Use cases
29
+
30
+ ### Installation
31
+
32
+ `npm install @ygracs/chn-alias-list`
@@ -0,0 +1,443 @@
1
+
2
+ >|***rev.*:**|0.0.3|
3
+ >|:---|---:|
4
+ >|date:|2024-10-21|
5
+
6
+ ## Introduction
7
+
8
+ This paper describes a classes and some helper functions provided by `chn-alias-list.js` module.
9
+
10
+ ## Content
11
+
12
+ - Classes
13
+ - <a href="#TChnNameRecord">TChnNameRecord</a>
14
+ - <a href="#TChnNamesList">TChnNamesList</a>
15
+ - <a href="#TChnAliasItem">TChnAliasItem</a>
16
+ - <a href="#TChnAliasList">TChnAliasList</a>
17
+
18
+ - Functions
19
+ - <a href="#loadAliasFromFileSync">loadAliasFromFileSync</a>
20
+ - <a href="#saveAliasToFileSync">saveAliasToFileSync</a>
21
+
22
+ ## Module classes
23
+
24
+ <a name="TChnNameRecord"></a>
25
+ ### **TChnNameRecord**
26
+
27
+ This class implements an interface of the name record
28
+
29
+ <a name="new_TChnNameRecord_new"></a>
30
+ #### class constructor
31
+
32
+ The class constructor creates a new instance of the class. It receives no arguments.
33
+
34
+ #### class properties
35
+
36
+ <a name="TChnNameRecord+lang"></a>
37
+ ##### **lang**
38
+
39
+ | value type | read only | description |
40
+ |---|---|:---|
41
+ | `string` | yes | defines a language applied to a name record value |
42
+
43
+ <a name="TChnNameRecord+text"></a>
44
+ ##### **text**
45
+
46
+ | value type | read only | description |
47
+ |---|---|:---|
48
+ | `string` | yes | defines a text value of a name record |
49
+
50
+ <a name="TChnNameRecord+value"></a>
51
+ ##### **value**
52
+
53
+ | value type | read only | description |
54
+ |---|---|:---|
55
+ | `array` | no | defines a value of a name record |
56
+
57
+ #### class methods
58
+
59
+ <a name="TChnNameRecord+setValue"></a>
60
+ ##### **setValue(data)** => `boolean`
61
+
62
+ This method sets the value of a name record.
63
+
64
+ | parameter name | value type | default value | description |
65
+ |:---|---|---:|:---|
66
+ | `data` | `any` | --- | a data for a name record to be set |
67
+
68
+ <a name="TChnNameRecord+toFormatString"></a>
69
+ ##### **toFormatString(opt)** => `string`
70
+
71
+ Returns a name record value as a formatted string.
72
+
73
+ | parameter name | value type | default value | description |
74
+ |:---|---|---:|:---|
75
+ | `opt` | `any` | --- | <*reserved*> |
76
+
77
+ <a name="TChnNameRecord+reset"></a>
78
+ ##### **reset()** => `void`
79
+
80
+ Clears the record.
81
+
82
+ <a name="TChnNamesList"></a>
83
+ ### **TChnNamesList**
84
+
85
+ This class implements an interface of the name records list.
86
+
87
+ <a name="new_TChnNamesList_new"></a>
88
+ #### class constructor
89
+
90
+ The class constructor creates a new instance of the class. It receives no arguments.
91
+
92
+ #### class properties
93
+
94
+ <a name="TChnNamesList+count"></a>
95
+ ##### **count**
96
+
97
+ | value type | read only | description |
98
+ |---|---|:---|
99
+ | `number` | yes | contains a quantity of a name records |
100
+
101
+ <a name="TChnNamesList+value"></a>
102
+ ##### **value**
103
+
104
+ | value type | read only | description |
105
+ |---|---|:---|
106
+ | `array` | yes | contains a list of a name records |
107
+
108
+ #### class methods
109
+
110
+ <a name="TChnNamesList+isEmpty"></a>
111
+ ##### **isEmpty()** => `boolean`
112
+
113
+ Returns a flag that indicating whether a list is empty or not.
114
+
115
+ <a name="TChnNamesList+isNotEmpty"></a>
116
+ ##### **isNotEmpty()** => `boolean`
117
+
118
+ Returns a flag that indicating whether a list has any members.
119
+
120
+ <a name="TChnNamesList+chkIndex"></a>
121
+ ##### **chkIndex(value)** => `boolean`
122
+
123
+ Checks whether a given value is an index and fits
124
  an Index range within the instance.
125
+
126
+ | parameter name | value type | default value | description |
127
+ |:---|---|---:|:---|
128
+ | `value` | `any` | --- | a value to be verified |
129
+
130
+ <a name="TChnNamesList+getIndex"></a>
131
+ ##### **getIndex(value)** => `number`
132
+
133
+ Searches an index of a given name in the list.
134
+
135
+ | parameter name | value type | default value | description |
136
+ |:---|---|---:|:---|
137
+ | `value` | `string` | --- | a name to be searched |
138
+
139
+ <a name="TChnNamesList+getName"></a>
140
+ ##### **getName(value)** => `?TChnNameRecord`
141
+
142
+ Returns a name record addressed by a given index.
143
+
144
+ | parameter name | value type | default value | description |
145
+ |:---|---|---:|:---|
146
+ | `value` | `number` | --- | an element index in the list |
147
+
148
+ <a name="TChnNamesList+addName"></a>
149
+ #### **addName(data)** => `boolean`
150
+
151
+ Adds a new name record to a list members.
152
+
153
+ | parameter name | value type | default value | description |
154
+ |:---|---|---:|:---|
155
+ | `data` | `any` | --- | a data for a name record to be added in the list |
156
+
157
+ <a name="TChnNamesList+delName"></a>
158
+ ##### **delName(value)** => `boolean`
159
+
160
+ Tries to delete a name record addressed by a given index.
161
+
162
+ | parameter name | value type | default value | description |
163
+ |:---|---|---:|:---|
164
+ | `value` | `number` | --- | an element index in the list |
165
+
166
+ <a name="TChnNamesList+loadNames"></a>
167
+ ##### **loadNames(list, \[opt])** => `number`
168
+
169
+ Loads a list of a new name records.
170
+
171
+ | parameter name | value type | default value | description |
172
+ |:---|---|---:|:---|
173
+ | `list` | `array` | --- | a list of an elements to load |
174
+ | `opt` | `boolean` | `true` | defines whether to clear the list before load a new one |
175
+
176
+ <a name="TChnNamesList+clear"></a>
177
+ ##### **clear()** => `void`
178
+
179
+ Removes all of the instance members.
180
+
181
+ <a name="TChnNamesList+forEach"></a>
182
+ ##### **forEach(cb)** => `void`
183
+
184
+ Calls given function for each name record in the list.
185
+
186
+ | parameter name | value type | default value | description |
187
+ |:---|---|---:|:---|
188
+ | `cb` | `callback` | --- | a callback function defined by a user |
189
+
190
+ <a name="TChnAliasItem"></a>
191
+ ### **TChnAliasItem**
192
+
193
+ This class implements an interface of the channel item.
194
+
195
+ <a name="new_TChnAliasItem_new"></a>
196
+ #### class constructor
197
+
198
+ The class constructor creates a new instance of the class. It receives no arguments.
199
+
200
+ #### class properties
201
+
202
+ <a name="TChnAliasItem+id"></a>
203
+ ##### **id**
204
+
205
+ | value type | read only | description |
206
+ |---|---|:---|
207
+ | `string` | no | defines a channel ID |
208
+
209
+ <a name="TChnAliasItem+alias"></a>
210
+ ##### **alias**
211
+
212
+ | value type | read only | description |
213
+ |---|---|:---|
214
+ | `string` | no | defines a channel alias |
215
+
216
+ <a name="TChnAliasItem+names"></a>
217
+ ##### **names**
218
+
219
+ | value type | read only | description |
220
+ |---|---|:---|
221
+ | `TChnNamesList` | yes | contains a list of a name records |
222
+
223
+ <a name="TChnAliasItem+status"></a>
224
+ ##### **status**
225
+
226
+ | value type | read only | description |
227
+ |---|---|:---|
228
+ | `string` | yes | defines an instance status |
229
+
230
+ #### class methods
231
+
232
+ <a name="TChnAliasItem+setID"></a>
233
+ ##### **setID(value)** => `boolean`
234
+
235
+ Sets a channel ID.
236
+
237
+ | parameter name | value type | default value | description |
238
+ |:---|---|---:|:---|
239
+ | `value` | `string` | --- | a channel ID |
240
+
241
+ <a name="TChnAliasItem+setAlias"></a>
242
+ ##### **setAlias(value)** => `boolean`
243
+
244
+ Sets a channel alias.
245
+
246
+ | parameter name | value type | default value | description |
247
+ |:---|---|---:|:---|
248
+ | `value` | `string` | --- | a channel alias |
249
+
250
+ <a name="TChnAliasItem+addName"></a>
251
+ ##### **addName(data)** => `boolean`
252
+
253
+ Adds a new name record.
254
+
255
+ > **See**: [TChnNamesList.addName](#TChnNamesList+addName)
256
+
257
+ <a name="TChnAliasItem+loadNames"></a>
258
+ ##### **loadNames(list, \[opt])** => `number`
259
+
260
+ Loads a list of a new name records.
261
+
262
+ > **See**: [TChnNamesList.loadNames](#TChnNamesList+loadNames)
263
+
264
+ <a name="TChnAliasItem+enable"></a>
265
+ ##### **enable()** => `void`
266
+
267
+ Sets item status to "enabled".
268
+
269
+ <a name="TChnAliasItem+disable"></a>
270
+ ##### **disable()** => `void`
271
+
272
+ Sets item status to "disabled".
273
+
274
+ <a name="TChnAliasItem+up"></a>
275
+ ##### **up()** => `void`
276
+
277
+ Sets item status to "active"/"running".
278
+
279
+ <a name="TChnAliasItem+down"></a>
280
+ ##### **down()** => `void`
281
+
282
+ Sets item status to "inactive"/"stopped".
283
+
284
+ #### class methods
285
+
286
+ <a name="TChnAliasItem+setStatus"></a>
287
+ ##### **setStatus(value)** => `boolean`
288
+
289
+ Sets item status.
290
+
291
+ | parameter name | value type | default value | description |
292
+ |:---|---|---:|:---|
293
+ | `value` | `string` | --- | a name of predefined status value (a possible value may be: `enabled`, `disabled`, `up` or `down`) |
294
+
295
+ #### class methods (*special*)
296
+
297
+ <a name="TChnAliasItem+toJSON"></a>
298
+ ##### **toJSON()**
299
+
300
+ A special method that provides an interface to an instance representation
1
301
  for a `JSON.stringify()`.
302
+
303
+ #### class methods (*static*)
304
+
305
+ <a name="TChnAliasItem.create"></a>
306
+ ##### **create(obj)** => `?TChnAliasItem`
307
+
308
+ Creates a new alias element.
309
+
310
+ | parameter name | value type | default value | description |
311
+ |:---|---|---:|:---|
312
+ | `obj` | `object` | --- | an initial data |
313
+
314
+ <a name="TChnAliasList"></a>
315
+ ### **TChnAliasList**
316
+
317
+ This class implements an interface of the channel items list.
318
+
319
+ <a name="new_TChnAliasList_new"></a>
320
+ #### class constructor
321
+
322
+ The class constructor creates a new instance of the class. It receives no arguments.
323
+
324
+ #### class properties
325
+
326
+ <a name="TChnAliasList+count"></a>
327
+ ##### **count**
328
+
329
+ | value type | read only | description |
330
+ |---|---|:---|
331
+ | `number` | yes | contains a quantity of the elements |
332
+
333
+ #### class methods
334
+
335
+ <a name="TChnAliasList+isEmpty"></a>
336
+ ##### **isEmpty()** => `boolean`
337
+
338
+ Returns a flag that indicating whether a list is empty or not.
339
+
340
+ <a name="TChnAliasList+isNotEmpty"></a>
341
+ ##### **isNotEmpty()** => `boolean`
342
+
343
+ Returns a flag that indicating whether a list has any members.
344
+
345
+ <a name="TChnAliasList+chkIndex"></a>
346
+ ##### **chkIndex(value)** => `boolean`
347
+
348
+ Checks whether a given value is an index and fits
349
+ an Index range within the instance.
350
+
351
+ | parameter name | value type | default value | description |
352
+ |:---|---|---:|:---|
353
+ | `value` | `any` | --- | a value to be verified |
354
+
355
+ <a name="TChnAliasList+searchIndexByID"></a>
356
+ ##### **searchIndexByID(value)** => `number`
357
+
358
+ Searches an index of an element by its given ID.
359
+
360
+ | parameter name | value type | default value | description |
361
+ |:---|---|---:|:---|
362
+ | `value` | `string` | --- | a value of ID to be searched |
363
+
364
+ <a name="TChnAliasList+getItem"></a>
365
+ ##### **getItem(value)** => `?TChnAliasItem`
366
+
367
+ Returns an alias element by its index.
368
+
369
+ | parameter name | value type | default value | description |
370
+ |:---|---|---:|:---|
371
+ | `value` | `number` | --- | an element index |
372
+
373
+ <a name="TChnAliasList+getItemByID"></a>
374
+ ##### **getItemByID(value)** => `?TChnAliasItem`
375
+
376
+ Returns an alias element by its ID.
377
+
378
+ | parameter name | value type | default value | description |
379
+ |:---|---|---:|:---|
380
+ | `value` | `string` | --- | an element ID |
381
+
382
+ <a name="TChnAliasList+addItem"></a>
383
+ ##### **addItem(obj)** => `number`
384
+
385
+ Adds an alias element.
386
+
387
+ | parameter name | value type | default value | description |
388
+ |:---|---|---:|:---|
389
+ | `obj` | `object` | --- | an element to be added |
390
+
391
+ <a name="TChnAliasList+delItem"></a>
392
+ ##### **delItem(value)** => `boolean`
393
+
394
+ Tries to delete an element addressed by a given index.
395
+
396
+ | parameter name | value type | default value | description |
397
+ |:---|---|---:|:---|
398
+ | `value` | `number` | --- | an element index |
399
+
400
+ <a name="TChnAliasList+loadItems"></a>
401
+ ##### **loadItems(list, \[opt])** => `number`
402
+
403
+ Loads a list of a new alias elements.
404
+
405
+ | parameter name | value type | default value | description |
406
+ |:---|---|---:|:---|
407
+ | `list` | `array` | --- | a list of an elements |
408
+ | `opt` | `boolean` | `true` | a flag that defines whether to clear the list before load a new one |
409
+
410
+ <a name="TChnAliasList+clear"></a>
411
+ ##### **clear()** => `void`
412
+
413
+ Removes all of the instance members.
414
+
415
+ <a name="TChnAliasList+forEach"></a>
416
+ ##### **forEach(cb)** => `void`
417
+
418
+ Calls given function for each alias element in the list.
419
+
420
+ | parameter name | value type | default value | description |
421
+ |:---|---|---:|:---|
422
+ | `cb` | `callback` | --- | a callback function defined by a user |
423
+
424
+ ## Module functions
425
+
426
+ <a name="loadAliasFromFileSync"></a>
427
+ #### **loadAliasFromFileSync(src, [opt])** => `object`
428
+
429
+ Loads an alias from a file.
430
+
431
+ | parameter name | value type | default value | description |
432
+ |:---|---|---:|:---|
433
+ | `src` | `string` | --- | a path to some file |
434
+ | `opt` | `any` | --- | <*reserved*> |
435
+
436
+ <a name="saveAliasToFileSync"></a>
437
+ #### **saveAliasToFileSync(src, content, [opt])** => `object`
438
+
439
+ Saves an alias to a file
440
+
441
+ | parameter name | value type | default value | description |
442
+ |:---|---|---:|:---|
443
+ | `src` | `string` | --- | a path to some file |
444
+ | `content` | `array` | --- | a content to save |
445
+ | `opt` | `any` | --- | <*reserved*> |
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // [v0.0.001-20240620]
2
+
3
+ // === module init block ===
4
+
5
+ const lib = require('#lib/chn-alias-list.js');
6
+
7
+ // === module extra block (helper functions) ===
8
+
9
+ // === module main block ===
10
+
11
+ // === module exports block ===
12
+
13
+ module.exports = lib;