@ygracs/chn-alias-list 0.0.5 → 0.0.6
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 +7 -7
- package/lib/chn-alias-list.js +101 -80
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
#### *v0.0.6*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.0.
|
|
6
|
+
|
|
1
7
|
#### *v0.0.5*
|
|
2
8
|
|
|
3
9
|
Pre-release version.
|
|
@@ -13,12 +19,6 @@ Pre-release version.
|
|
|
13
19
|
> - add 'filter'-method to a `TChnAliasList`-class;
|
|
14
20
|
> - other fixes.
|
|
15
21
|
|
|
16
|
-
#### *v0.0.4*
|
|
17
|
-
|
|
18
|
-
Pre-release version.
|
|
19
|
-
|
|
20
|
-
> - update dependency on `@ygracs/bsfoc-lib-js` module to v0.2.2.
|
|
21
|
-
|
|
22
|
-
#### *v0.0.1-0.0.3*
|
|
22
|
+
#### *v0.0.1-0.0.4*
|
|
23
23
|
|
|
24
24
|
Pre-release version.
|
package/lib/chn-alias-list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.045-20250820]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -12,15 +12,19 @@ const {
|
|
|
12
12
|
loadJSONFromFileSync, saveJSONToFileSync,
|
|
13
13
|
} = require('@cntwg/file-helper');
|
|
14
14
|
|
|
15
|
-
// === module
|
|
15
|
+
// === module inner block ===
|
|
16
|
+
|
|
17
|
+
/***
|
|
18
|
+
* (* helper function definitions *)
|
|
19
|
+
*/
|
|
16
20
|
|
|
17
21
|
/**
|
|
22
|
+
* Converts a <Lang, Text> key-pair to a string
|
|
18
23
|
* @function convertLangTextValueToString
|
|
19
24
|
* @param {array} data - contains a data to be printed
|
|
20
25
|
* @param {object} [opt]
|
|
21
26
|
* @returns {string}
|
|
22
27
|
* @inner
|
|
23
|
-
* @description Converts a <Lang, Text> key-pair to string
|
|
24
28
|
*/
|
|
25
29
|
function convertLangTextValueToString(data, opt) {
|
|
26
30
|
let name = [ '', '' ];
|
|
@@ -46,29 +50,30 @@ function convertLangTextValueToString(data, opt) {
|
|
|
46
50
|
*/
|
|
47
51
|
|
|
48
52
|
/**
|
|
53
|
+
* An 'FS'-ops descriptor.
|
|
49
54
|
* @typedef {Object} fsoDescr
|
|
50
55
|
* @property {boolean} isERR - flag
|
|
51
|
-
* @property {number
|
|
56
|
+
* @property {number} [errCode] - error code
|
|
52
57
|
* @property {string} errEvent - event ID
|
|
53
|
-
* @property {string} errMsg - event message
|
|
54
|
-
* @property {string} source - path to file
|
|
55
|
-
* @property {any} content - file content
|
|
56
|
-
* @description A fs ops description.
|
|
58
|
+
* @property {string} [errMsg] - event message
|
|
59
|
+
* @property {string} [source] - path to file
|
|
60
|
+
* @property {any} [content] - file content
|
|
57
61
|
*/
|
|
58
62
|
|
|
59
63
|
/**
|
|
64
|
+
* A result of `loadAliasFromFile...`
|
|
60
65
|
* @typedef {Object} RVAL_loadaliasff
|
|
61
66
|
* @property {fsoDescr} descr - ops description
|
|
62
67
|
* @property {(null|TChnAliasItem|TChnAliasList)} result - loaded content
|
|
63
|
-
* @description A result of `loadAliasFromFile...`
|
|
64
68
|
*/
|
|
65
69
|
|
|
66
70
|
/**
|
|
71
|
+
* Loads an alias from a file
|
|
67
72
|
* @function loadAliasFromFileSync
|
|
68
73
|
* @param {string} src - a path to some file
|
|
69
74
|
* @param {any} [opt] - <reserved>
|
|
70
75
|
* @returns {RVAL_loadaliasff}
|
|
71
|
-
* @
|
|
76
|
+
* @see {@link loadJSONFromFileSync} for details of an `opt` param
|
|
72
77
|
*/
|
|
73
78
|
function loadAliasFromFileSync(src, opt) {
|
|
74
79
|
let { descr, obj } = loadJSONFromFileSync(src, opt);
|
|
@@ -86,12 +91,13 @@ function loadAliasFromFileSync(src, opt) {
|
|
|
86
91
|
};
|
|
87
92
|
|
|
88
93
|
/**
|
|
94
|
+
* Saves an alias to a file
|
|
89
95
|
* @function saveAliasToFileSync
|
|
90
96
|
* @param {string} src - a path to some file
|
|
91
97
|
* @param {Array} content - content
|
|
92
98
|
* @param {any} [opt] - <reserved>
|
|
93
99
|
* @returns {fsoDescr}
|
|
94
|
-
* @
|
|
100
|
+
* @see {@link saveJSONToFileSync} for details of an `opt` param
|
|
95
101
|
*/
|
|
96
102
|
function saveAliasToFileSync(src, content, opt) {
|
|
97
103
|
const obj = isArray(content) ? content : null;
|
|
@@ -109,20 +115,21 @@ function saveAliasToFileSync(src, content, opt) {
|
|
|
109
115
|
* @classdesc This class implements an interface of the name record
|
|
110
116
|
*/
|
|
111
117
|
class TChnNameRecord {
|
|
112
|
-
/** @
|
|
118
|
+
/** @type {string} */
|
|
113
119
|
#_lang;
|
|
114
|
-
/** @
|
|
120
|
+
/** @type {string} */
|
|
115
121
|
#_value;
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
|
-
*
|
|
124
|
+
* Creates an instance of the name record
|
|
119
125
|
*/
|
|
120
126
|
constructor() {
|
|
121
127
|
this.reset();
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
/**
|
|
125
|
-
*
|
|
131
|
+
* Contains a language
|
|
132
|
+
* @type {string}
|
|
126
133
|
* @readonly
|
|
127
134
|
*/
|
|
128
135
|
get lang() {
|
|
@@ -130,7 +137,8 @@ class TChnNameRecord {
|
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
/**
|
|
133
|
-
*
|
|
140
|
+
* Contains a value of the record
|
|
141
|
+
* @type {string}
|
|
134
142
|
* @readonly
|
|
135
143
|
*/
|
|
136
144
|
get text() {
|
|
@@ -138,7 +146,8 @@ class TChnNameRecord {
|
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
/**
|
|
141
|
-
*
|
|
149
|
+
* Contains a value of the record
|
|
150
|
+
* @type {string[]}
|
|
142
151
|
*/
|
|
143
152
|
get value() {
|
|
144
153
|
return [ this.#_lang, this.#_value ];
|
|
@@ -149,9 +158,9 @@ class TChnNameRecord {
|
|
|
149
158
|
}
|
|
150
159
|
|
|
151
160
|
/**
|
|
161
|
+
* Sets the record value
|
|
152
162
|
* @param {any} data - a value of the record
|
|
153
163
|
* @returns {boolean}
|
|
154
|
-
* @description Sets the record value
|
|
155
164
|
*/
|
|
156
165
|
setValue(data) {
|
|
157
166
|
let _data = data;
|
|
@@ -187,17 +196,17 @@ class TChnNameRecord {
|
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
/**
|
|
199
|
+
* Returns value as a formated string
|
|
190
200
|
* @param {any} opt - <reserved>
|
|
191
201
|
* @returns {string}
|
|
192
|
-
* @description Returns value as a formated string
|
|
193
202
|
*/
|
|
194
203
|
toFormatString(opt) {
|
|
195
204
|
return convertLangTextValueToString(this.value, opt);
|
|
196
205
|
}
|
|
197
206
|
|
|
198
207
|
/**
|
|
208
|
+
* Clears the record
|
|
199
209
|
* @returns {void}
|
|
200
|
-
* @description Clears the record
|
|
201
210
|
*/
|
|
202
211
|
reset() {
|
|
203
212
|
this.#_lang = '';
|
|
@@ -207,32 +216,32 @@ class TChnNameRecord {
|
|
|
207
216
|
};
|
|
208
217
|
|
|
209
218
|
/**
|
|
219
|
+
* A user defined procedure to process an array elements
|
|
210
220
|
* @callback forEachProcEx
|
|
211
|
-
* @param {any} item
|
|
212
|
-
* @param {number} [index]
|
|
221
|
+
* @param {any} item - some element
|
|
222
|
+
* @param {number} [index] - element index
|
|
213
223
|
* @param {any[]} [arr]
|
|
214
224
|
* @returns {void}
|
|
215
|
-
* @description user defined procedure to process an array elements
|
|
216
225
|
*/
|
|
217
226
|
|
|
218
227
|
/**
|
|
228
|
+
* A user defined procedure to process an array elements
|
|
219
229
|
* @callback cbArrECheck
|
|
220
230
|
* @param {any} item - some element
|
|
221
231
|
* @param {number} [index] - element index
|
|
222
232
|
* @param {any[]} [arr] - array a callback was called upon
|
|
223
233
|
* @returns {any}
|
|
224
|
-
* @description user defined procedure to process an array elements
|
|
225
234
|
*/
|
|
226
235
|
|
|
227
236
|
/**
|
|
228
237
|
* @classdesc This class implements an interface of the name records list
|
|
229
238
|
*/
|
|
230
239
|
class TChnNamesList {
|
|
231
|
-
/** @
|
|
240
|
+
/** @type {TChnNameRecord[]} */
|
|
232
241
|
#_items;
|
|
233
242
|
|
|
234
243
|
/**
|
|
235
|
-
*
|
|
244
|
+
* Creates an instance of the name records list
|
|
236
245
|
*/
|
|
237
246
|
constructor() {
|
|
238
247
|
this.#_items = [];
|
|
@@ -255,7 +264,8 @@ class TChnNamesList {
|
|
|
255
264
|
}
|
|
256
265
|
|
|
257
266
|
/**
|
|
258
|
-
*
|
|
267
|
+
* Contains a quantity of a name records
|
|
268
|
+
* @type {number}
|
|
259
269
|
* @readonly
|
|
260
270
|
*/
|
|
261
271
|
get count() {
|
|
@@ -263,7 +273,8 @@ class TChnNamesList {
|
|
|
263
273
|
}
|
|
264
274
|
|
|
265
275
|
/**
|
|
266
|
-
*
|
|
276
|
+
* Contains a list of a name records
|
|
277
|
+
* @type {TChnNameRecord[]}
|
|
267
278
|
* @readonly
|
|
268
279
|
*/
|
|
269
280
|
get value() {
|
|
@@ -275,26 +286,26 @@ class TChnNamesList {
|
|
|
275
286
|
}
|
|
276
287
|
|
|
277
288
|
/**
|
|
289
|
+
* Returns a flag whether a list is empty or not
|
|
278
290
|
* @returns {boolean}
|
|
279
|
-
* @description Returns a flag whether a list is empty or not
|
|
280
291
|
*/
|
|
281
292
|
isEmpty() {
|
|
282
293
|
return this.count === 0;
|
|
283
294
|
}
|
|
284
295
|
|
|
285
296
|
/**
|
|
297
|
+
* Returns a flag whether a list has any members
|
|
286
298
|
* @returns {boolean}
|
|
287
|
-
* @description Returns a flag whether a list has any members
|
|
288
299
|
*/
|
|
289
300
|
isNotEmpty() {
|
|
290
301
|
return this.count > 0;
|
|
291
302
|
}
|
|
292
303
|
|
|
293
304
|
/**
|
|
305
|
+
* Checks whether a given value is an index and fits an index range
|
|
306
|
+
* within the instance
|
|
294
307
|
* @param {any} value - a value to be verified
|
|
295
308
|
* @returns {boolean}
|
|
296
|
-
* @description Checks whether a given value is an index and fits
|
|
297
|
-
* an Index range within the instance
|
|
298
309
|
*/
|
|
299
310
|
chkIndex(value) {
|
|
300
311
|
const index = valueToIndex(value);
|
|
@@ -302,9 +313,9 @@ class TChnNamesList {
|
|
|
302
313
|
}
|
|
303
314
|
|
|
304
315
|
/**
|
|
316
|
+
* Searches an index of a given name
|
|
305
317
|
* @param {string} value - a name
|
|
306
318
|
* @returns {number}
|
|
307
|
-
* @description Searches an index of a given name
|
|
308
319
|
*/
|
|
309
320
|
getIndex(value) {
|
|
310
321
|
const opt = { numberToString: true };
|
|
@@ -326,9 +337,9 @@ class TChnNamesList {
|
|
|
326
337
|
}
|
|
327
338
|
|
|
328
339
|
/**
|
|
340
|
+
* Returns a name record
|
|
329
341
|
* @param {number} value - an element index
|
|
330
342
|
* @returns {?TChnNameRecord}
|
|
331
|
-
* @description Returns a name record
|
|
332
343
|
*/
|
|
333
344
|
getItem(value) {
|
|
334
345
|
return this.chkIndex(value) ? this.#_items[Number(value)] : null;
|
|
@@ -344,9 +355,9 @@ class TChnNamesList {
|
|
|
344
355
|
}
|
|
345
356
|
|
|
346
357
|
/**
|
|
358
|
+
* Adds a new name record to a list members
|
|
347
359
|
* @param {any} data - a value of a name record
|
|
348
360
|
* @returns {boolean}
|
|
349
|
-
* @description Adds a new name record to a list members
|
|
350
361
|
*/
|
|
351
362
|
addItem(data) {
|
|
352
363
|
const _data = data instanceof TChnNameRecord ? data.value : data;
|
|
@@ -366,9 +377,9 @@ class TChnNamesList {
|
|
|
366
377
|
}
|
|
367
378
|
|
|
368
379
|
/**
|
|
380
|
+
* Tries to delete a name record addressed by a given index
|
|
369
381
|
* @param {number} value - an element index
|
|
370
382
|
* @returns {boolean}
|
|
371
|
-
* @description Tries to delete a name record addressed by a given index
|
|
372
383
|
*/
|
|
373
384
|
delItem(value) {
|
|
374
385
|
let isSucceed = this.chkIndex(value)
|
|
@@ -376,7 +387,6 @@ class TChnNamesList {
|
|
|
376
387
|
return isSucceed;
|
|
377
388
|
}
|
|
378
389
|
|
|
379
|
-
//
|
|
380
390
|
/**
|
|
381
391
|
* @deprecated
|
|
382
392
|
* @see TChnNamesList.loadItems
|
|
@@ -387,10 +397,10 @@ class TChnNamesList {
|
|
|
387
397
|
}
|
|
388
398
|
|
|
389
399
|
/**
|
|
400
|
+
* Loads a new name records
|
|
390
401
|
* @param {any} list - an element or a list of an elements
|
|
391
402
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
392
403
|
* @returns {number}
|
|
393
|
-
* @description Loads a new name records
|
|
394
404
|
*/
|
|
395
405
|
loadItems(list, opt) {
|
|
396
406
|
const useClear = typeof opt === 'boolean' ? opt : true;
|
|
@@ -404,27 +414,26 @@ class TChnNamesList {
|
|
|
404
414
|
};
|
|
405
415
|
|
|
406
416
|
/**
|
|
417
|
+
* Removes all of the instance members
|
|
407
418
|
* @returns {void}
|
|
408
|
-
* @description Removes all of the instance members
|
|
409
419
|
*/
|
|
410
420
|
clear() {
|
|
411
421
|
this.#_items.length = 0;
|
|
412
422
|
}
|
|
413
423
|
|
|
414
424
|
/**
|
|
425
|
+
* Calls given function for each name record
|
|
415
426
|
* @param {forEachProcEx} cb - a callback function
|
|
416
427
|
* @returns {void}
|
|
417
|
-
* @description Calls given function for each name record
|
|
418
428
|
*/
|
|
419
429
|
forEach(cb) {
|
|
420
430
|
if (typeof cb === 'function') this.#_items.forEach(cb);
|
|
421
431
|
}
|
|
422
432
|
|
|
423
433
|
/**
|
|
434
|
+
* Returns an array of a name records picked up by a given function
|
|
424
435
|
* @param {cbArrECheck} cb - a callback function
|
|
425
436
|
* @returns {TChnNameRecord[]}
|
|
426
|
-
* @description Returns an array of a name records picked up
|
|
427
|
-
* by a given function
|
|
428
437
|
*/
|
|
429
438
|
filter(cb) {
|
|
430
439
|
return typeof cb === 'function' ? this.#_items.filter(cb) : [];
|
|
@@ -436,13 +445,19 @@ class TChnNamesList {
|
|
|
436
445
|
* @classdesc This class implements an interface of the channel item
|
|
437
446
|
*/
|
|
438
447
|
class TChnAliasItem {
|
|
439
|
-
/** @
|
|
448
|
+
/** @type {string} */
|
|
440
449
|
#_id = '';
|
|
441
|
-
/** @
|
|
450
|
+
/** @type {string} */
|
|
442
451
|
#_alias = '';
|
|
443
|
-
/** @
|
|
452
|
+
/** @type {TChnNamesList} */
|
|
444
453
|
#_names;
|
|
445
|
-
/**
|
|
454
|
+
/**
|
|
455
|
+
* A channel status
|
|
456
|
+
* @typedef {Object} chnStat
|
|
457
|
+
* @property {boolean} isEnabled
|
|
458
|
+
* @property {boolean} isActive
|
|
459
|
+
*/
|
|
460
|
+
/** @type {chnStat} */
|
|
446
461
|
#_status;
|
|
447
462
|
|
|
448
463
|
/**
|
|
@@ -458,7 +473,8 @@ class TChnAliasItem {
|
|
|
458
473
|
}
|
|
459
474
|
|
|
460
475
|
/**
|
|
461
|
-
*
|
|
476
|
+
* Contains a channel ID
|
|
477
|
+
* @type {string}
|
|
462
478
|
*/
|
|
463
479
|
get id() {
|
|
464
480
|
return this.#_id;
|
|
@@ -469,7 +485,8 @@ class TChnAliasItem {
|
|
|
469
485
|
}
|
|
470
486
|
|
|
471
487
|
/**
|
|
472
|
-
*
|
|
488
|
+
* Contains a channel alias
|
|
489
|
+
* @type {string}
|
|
473
490
|
*/
|
|
474
491
|
get alias() {
|
|
475
492
|
return this.#_alias;
|
|
@@ -480,7 +497,8 @@ class TChnAliasItem {
|
|
|
480
497
|
}
|
|
481
498
|
|
|
482
499
|
/**
|
|
483
|
-
*
|
|
500
|
+
* Contains a list of a name records
|
|
501
|
+
* @type {TChnNamesList}
|
|
484
502
|
* @readonly
|
|
485
503
|
*/
|
|
486
504
|
get names() {
|
|
@@ -488,7 +506,8 @@ class TChnAliasItem {
|
|
|
488
506
|
}
|
|
489
507
|
|
|
490
508
|
/**
|
|
491
|
-
*
|
|
509
|
+
* Contains an instance status
|
|
510
|
+
* @type {string}
|
|
492
511
|
* @readonly
|
|
493
512
|
*/
|
|
494
513
|
get status() {
|
|
@@ -498,9 +517,10 @@ class TChnAliasItem {
|
|
|
498
517
|
}
|
|
499
518
|
|
|
500
519
|
/**
|
|
520
|
+
* Sets a channel ID
|
|
501
521
|
* @param {string} value - a channel ID
|
|
502
522
|
* @returns {boolean}
|
|
503
|
-
* @
|
|
523
|
+
* @see valueToIDString
|
|
504
524
|
*/
|
|
505
525
|
setID(value) {
|
|
506
526
|
const id = valueToIDString(value);
|
|
@@ -510,9 +530,10 @@ class TChnAliasItem {
|
|
|
510
530
|
}
|
|
511
531
|
|
|
512
532
|
/**
|
|
533
|
+
* Sets a channel alias
|
|
513
534
|
* @param {string} value - a channel alias
|
|
514
535
|
* @returns {boolean}
|
|
515
|
-
* @
|
|
536
|
+
* @see valueToIDString
|
|
516
537
|
*/
|
|
517
538
|
setAlias(value) {
|
|
518
539
|
const alias = valueToIDString(value);
|
|
@@ -522,10 +543,10 @@ class TChnAliasItem {
|
|
|
522
543
|
}
|
|
523
544
|
|
|
524
545
|
/**
|
|
546
|
+
* Returns a name record
|
|
525
547
|
* @param {number} value
|
|
526
548
|
* @returns {?TChnNameRecord}
|
|
527
549
|
* @deprecated
|
|
528
|
-
* @description Returns a name record
|
|
529
550
|
* @see TChnNamesList.getItem
|
|
530
551
|
*/
|
|
531
552
|
getName(value) {
|
|
@@ -533,9 +554,9 @@ class TChnAliasItem {
|
|
|
533
554
|
}
|
|
534
555
|
|
|
535
556
|
/**
|
|
557
|
+
* Adds a new name record
|
|
536
558
|
* @param {any} data - a name record
|
|
537
559
|
* @returns {boolean}
|
|
538
|
-
* @description Adds a new name record
|
|
539
560
|
* @see TChnNamesList.addItem
|
|
540
561
|
*/
|
|
541
562
|
addName(data) {
|
|
@@ -543,10 +564,10 @@ class TChnAliasItem {
|
|
|
543
564
|
}
|
|
544
565
|
|
|
545
566
|
/**
|
|
567
|
+
* Loads a list of a new name records
|
|
546
568
|
* @param {array} list - a list of an elements
|
|
547
569
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
548
570
|
* @returns {number}
|
|
549
|
-
* @description Loads a list of a new name records
|
|
550
571
|
* @see TChnNamesList.loadItems
|
|
551
572
|
*/
|
|
552
573
|
loadNames(...args) {
|
|
@@ -554,41 +575,41 @@ class TChnAliasItem {
|
|
|
554
575
|
}
|
|
555
576
|
|
|
556
577
|
/**
|
|
578
|
+
* Sets item status to enabled
|
|
557
579
|
* @returns {void}
|
|
558
|
-
* @description Sets item status to enabled
|
|
559
580
|
*/
|
|
560
581
|
enable() {
|
|
561
582
|
this.#_status.isEnabled = true;
|
|
562
583
|
}
|
|
563
584
|
|
|
564
585
|
/**
|
|
586
|
+
* Sets item status to disabled
|
|
565
587
|
* @returns {void}
|
|
566
|
-
* @description Sets item status to disabled
|
|
567
588
|
*/
|
|
568
589
|
disable() {
|
|
569
590
|
this.#_status.isEnabled = false;
|
|
570
591
|
}
|
|
571
592
|
|
|
572
593
|
/**
|
|
594
|
+
* Sets item status to active/running
|
|
573
595
|
* @returns {void}
|
|
574
|
-
* @description Sets item status to active/running
|
|
575
596
|
*/
|
|
576
597
|
up() {
|
|
577
598
|
this.#_status.isActive = true;
|
|
578
599
|
}
|
|
579
600
|
|
|
580
601
|
/**
|
|
602
|
+
* Sets item status to inactive/stopped
|
|
581
603
|
* @returns {void}
|
|
582
|
-
* @description Sets item status to inactive/stopped
|
|
583
604
|
*/
|
|
584
605
|
down() {
|
|
585
606
|
this.#_status.isActive = false;
|
|
586
607
|
}
|
|
587
608
|
|
|
588
609
|
/**
|
|
610
|
+
* Sets item status
|
|
589
611
|
* @param {string} value - a status value
|
|
590
612
|
* @returns {boolean}
|
|
591
|
-
* @description Sets item status
|
|
592
613
|
*/
|
|
593
614
|
setStatus(value) {
|
|
594
615
|
const status = readAsString(value);
|
|
@@ -618,10 +639,9 @@ class TChnAliasItem {
|
|
|
618
639
|
}
|
|
619
640
|
|
|
620
641
|
/**
|
|
642
|
+
* Provides an interface to an instance representation for JSON.stringify()
|
|
621
643
|
* @returns {Object}
|
|
622
644
|
* @protected
|
|
623
|
-
* @description Provides an interface to an instance representation
|
|
624
|
-
* for JSON.stringify()
|
|
625
645
|
*/
|
|
626
646
|
toJSON() {
|
|
627
647
|
const { id, alias, names, status } = this;
|
|
@@ -634,10 +654,10 @@ class TChnAliasItem {
|
|
|
634
654
|
}
|
|
635
655
|
|
|
636
656
|
/**
|
|
657
|
+
* Creates a new alias element
|
|
637
658
|
* @param {object} obj - an init data
|
|
638
659
|
* @returns {?TChnAliasItem}
|
|
639
660
|
* @static
|
|
640
|
-
* @description Creates a new alias element
|
|
641
661
|
*/
|
|
642
662
|
static create(obj) {
|
|
643
663
|
let result = null;
|
|
@@ -667,11 +687,11 @@ class TChnAliasItem {
|
|
|
667
687
|
* @classdesc This class implements an interface of the channel items list
|
|
668
688
|
*/
|
|
669
689
|
class TChnAliasList {
|
|
670
|
-
/** @
|
|
690
|
+
/** @type {TChnAliasItem[]} */
|
|
671
691
|
#_items;
|
|
672
692
|
|
|
673
693
|
/**
|
|
674
|
-
*
|
|
694
|
+
* Creates an instance of the channel items list
|
|
675
695
|
*/
|
|
676
696
|
constructor() {
|
|
677
697
|
this.#_items = [];
|
|
@@ -694,7 +714,8 @@ class TChnAliasList {
|
|
|
694
714
|
}
|
|
695
715
|
|
|
696
716
|
/**
|
|
697
|
-
*
|
|
717
|
+
* Contains a quantity of the elements
|
|
718
|
+
* @type {number}
|
|
698
719
|
* @readonly
|
|
699
720
|
*/
|
|
700
721
|
get count() {
|
|
@@ -702,26 +723,26 @@ class TChnAliasList {
|
|
|
702
723
|
}
|
|
703
724
|
|
|
704
725
|
/**
|
|
726
|
+
* Returns a flag whether a list is empty or not
|
|
705
727
|
* @returns {boolean}
|
|
706
|
-
* @description Returns a flag whether a list is empty or not
|
|
707
728
|
*/
|
|
708
729
|
isEmpty() {
|
|
709
730
|
return this.count === 0;
|
|
710
731
|
}
|
|
711
732
|
|
|
712
733
|
/**
|
|
734
|
+
* Returns a flag whether a list has any members
|
|
713
735
|
* @returns {boolean}
|
|
714
|
-
* @description Returns a flag whether a list has any members
|
|
715
736
|
*/
|
|
716
737
|
isNotEmpty() {
|
|
717
738
|
return this.count > 0;
|
|
718
739
|
}
|
|
719
740
|
|
|
720
741
|
/**
|
|
742
|
+
* Checks whether a given value is an index and fits an index range
|
|
743
|
+
* within the instance
|
|
721
744
|
* @param {any} value - a value to be verified
|
|
722
745
|
* @returns {boolean}
|
|
723
|
-
* @description Checks whether a given value is an index and fits
|
|
724
|
-
* an Index range within the instance
|
|
725
746
|
*/
|
|
726
747
|
chkIndex(value) {
|
|
727
748
|
const index = valueToIndex(value);
|
|
@@ -729,9 +750,10 @@ class TChnAliasList {
|
|
|
729
750
|
}
|
|
730
751
|
|
|
731
752
|
/**
|
|
753
|
+
* Searches an index of an element by its ID
|
|
732
754
|
* @param {string} value - an element ID
|
|
733
755
|
* @returns {number}
|
|
734
|
-
* @
|
|
756
|
+
* @see valueToIDString
|
|
735
757
|
*/
|
|
736
758
|
searchIndexByID(value) {
|
|
737
759
|
const id = valueToIDString(value);
|
|
@@ -743,27 +765,27 @@ class TChnAliasList {
|
|
|
743
765
|
}
|
|
744
766
|
|
|
745
767
|
/**
|
|
768
|
+
* Returns an alias element by its index
|
|
746
769
|
* @param {number} value - an element index
|
|
747
770
|
* @returns {?TChnAliasItem}
|
|
748
|
-
* @description Returns an alias element by its index
|
|
749
771
|
*/
|
|
750
772
|
getItem(value) {
|
|
751
773
|
return this.chkIndex(value) ? this.#_items[Number(value)] : null;
|
|
752
774
|
}
|
|
753
775
|
|
|
754
776
|
/**
|
|
777
|
+
* Returns an alias element by its ID
|
|
755
778
|
* @param {string} value - an element ID
|
|
756
779
|
* @returns {?TChnAliasItem}
|
|
757
|
-
* @description Returns an alias element by its ID
|
|
758
780
|
*/
|
|
759
781
|
getItemByID(value) {
|
|
760
782
|
return this.getItem(this.searchIndexByID(value));
|
|
761
783
|
}
|
|
762
784
|
|
|
763
785
|
/**
|
|
786
|
+
* Adds an alias element
|
|
764
787
|
* @param {object} obj - an element to be added
|
|
765
788
|
* @returns {number}
|
|
766
|
-
* @description Adds an alias element
|
|
767
789
|
*/
|
|
768
790
|
addItem(obj) {
|
|
769
791
|
const item = TChnAliasItem.create(obj);
|
|
@@ -782,9 +804,9 @@ class TChnAliasList {
|
|
|
782
804
|
}
|
|
783
805
|
|
|
784
806
|
/**
|
|
807
|
+
* Tries to delete an element addressed by a given index
|
|
785
808
|
* @param {number} value - an element index
|
|
786
809
|
* @returns {boolean}
|
|
787
|
-
* @description Tries to delete an element addressed by a given index
|
|
788
810
|
*/
|
|
789
811
|
delItem(value) {
|
|
790
812
|
let isSucceed = this.chkIndex(value)
|
|
@@ -793,10 +815,10 @@ class TChnAliasList {
|
|
|
793
815
|
}
|
|
794
816
|
|
|
795
817
|
/**
|
|
818
|
+
* Loads a list of a new alias elements
|
|
796
819
|
* @param {array} list - a list of an elements
|
|
797
820
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
798
821
|
* @returns {number}
|
|
799
|
-
* @description Loads a list of a new alias elements
|
|
800
822
|
*/
|
|
801
823
|
loadItems(list, opt) {
|
|
802
824
|
const useClear = typeof opt === 'boolean' ? opt : true;
|
|
@@ -809,27 +831,26 @@ class TChnAliasList {
|
|
|
809
831
|
};
|
|
810
832
|
|
|
811
833
|
/**
|
|
834
|
+
* Removes all of the instance members
|
|
812
835
|
* @returns {void}
|
|
813
|
-
* @description removes all of the instance members
|
|
814
836
|
*/
|
|
815
837
|
clear() {
|
|
816
838
|
this.#_items.length = 0;
|
|
817
839
|
}
|
|
818
840
|
|
|
819
841
|
/**
|
|
842
|
+
* Calls given function for each alias element
|
|
820
843
|
* @param {forEachProcEx} cb - a callback function
|
|
821
844
|
* @returns {void}
|
|
822
|
-
* @description Calls given function for each alias element
|
|
823
845
|
*/
|
|
824
846
|
forEach(cb) {
|
|
825
847
|
if (typeof cb === 'function') this.#_items.forEach(cb);
|
|
826
848
|
}
|
|
827
849
|
|
|
828
850
|
/**
|
|
851
|
+
* Returns an array of a name records picked up by a given function
|
|
829
852
|
* @param {cbArrECheck} cb - a callback function
|
|
830
853
|
* @returns {TChnAliasItem[]}
|
|
831
|
-
* @description Returns an array of a name records picked up
|
|
832
|
-
* by a given function
|
|
833
854
|
*/
|
|
834
855
|
filter(cb) {
|
|
835
856
|
return typeof cb === 'function' ? this.#_items.filter(cb) : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ygracs/chn-alias-list",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A small library which provides some helper classes for EPG-tools",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@cntwg/file-helper": "^0.0.1",
|
|
29
|
-
"@ygracs/bsfoc-lib-js": "^0.
|
|
29
|
+
"@ygracs/bsfoc-lib-js": "^0.3.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"jest": "^
|
|
33
|
-
"jsdoc-to-markdown": "^9.1.
|
|
32
|
+
"jest": "^30.0.5",
|
|
33
|
+
"jsdoc-to-markdown": "^9.1.2",
|
|
34
34
|
"minimist": "^1.2.8"
|
|
35
35
|
}
|
|
36
36
|
}
|