@ygracs/chn-alias-list 0.0.7-b → 0.0.8

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,9 +1,21 @@
1
- #### *v0.0.x*
1
+ #### *v0.0.8*
2
2
 
3
3
  Pre-release version.
4
4
 
5
+ > - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.4;
6
+ > - (TChnNamesList) remove deprecated method: `getName`, `addName`, `delName`, `loadNames`;
7
+ > - some fixes.
8
+
9
+ #### *v0.0.7*
10
+
11
+ Pre-release version.
12
+
13
+ > - update `chn-alias-list.md`;
5
14
  > - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
6
15
  > - update dependency on `@cntwg/file-helper` module to v0.0.3;
16
+ > - improve behavior of `saveAliasToFileSync` on handling `content` param;
17
+ > - deprecate methods: `addName` and `loadNames` of a `TChnAliasItem`-class;
18
+ > - other fixes.
7
19
 
8
20
  #### *v0.0.6*
9
21
 
@@ -1,7 +1,7 @@
1
1
 
2
- >|***rev.*:**|0.0.5|
2
+ >|***rev.*:**|0.0.9|
3
3
  >|:---|---:|
4
- >|date:|2025-04-14|
4
+ >|date:|2026-03-08|
5
5
 
6
6
  ## Introduction
7
7
 
@@ -9,6 +9,10 @@ This paper describes a classes and some helper functions provided by `chn-alias-
9
9
 
10
10
  ## Content
11
11
 
12
+ - Base types
13
+ - <a href="#typedef+IChannelRecord">IChannelRecord</a>
14
+ - <a href="#typedef+fsoDescr">fsoDescr</a>
15
+
12
16
  - Classes
13
17
  - <a href="#TChnNameRecord">TChnNameRecord</a>
14
18
  - <a href="#TChnNamesList">TChnNamesList</a>
@@ -19,6 +23,36 @@ This paper describes a classes and some helper functions provided by `chn-alias-
19
23
  - <a href="#loadAliasFromFileSync">loadAliasFromFileSync</a>
20
24
  - <a href="#saveAliasToFileSync">saveAliasToFileSync</a>
21
25
 
26
+ ### Base type definitions
27
+
28
+ This section contains some definitions for a general types of the objects (e.g. options set) that frequently used in a function or a class method descriptions.
29
+
30
+ <a name="typedef+IChannelRecord"></a>
31
+ #### `IChannelRecord` - descriptor
32
+
33
+ This descriptor is an `object` that contains an info of a channel data.
34
+
35
+ | property name | value type | optional | description |
36
+ |:---|---|---:|:---|
37
+ | `id` | `string` | no | a channel ID |
38
+ | `alias` | `string` | no | a target ID for a channel |
39
+ | `name` | `any[]` | no | a list of a channel names |
40
+ | `status` | `string` | no | a channel status |
41
+
42
+ <a name="typedef+fsoDescr"></a>
43
+ #### `fsoDescr` - descriptor
44
+
45
+ This descriptor is an `object` that describes a status for an operation with some FS-object (*e.g. object such as a file*).
46
+
47
+ | property name | value type | optional | description |
48
+ |:---|---|---:|:---|
49
+ | `isERR` | `boolean` | no | a flag which indicates whether an error was happen |
50
+ | `errCode` | `number` | yes | an error code |
51
+ | `errEvent` | `string` | no | an error event identifier |
52
+ | `errMsg` | `string` | yes | an error message |
53
+ | `source` | `string` | yes | path to a file |
54
+ | `content` | `any` | yes | content |
55
+
22
56
  ## Module classes
23
57
 
24
58
  <a name="TChnNameRecord"></a>
@@ -52,7 +86,7 @@ The class constructor creates a new instance of the class. It receives no argume
52
86
 
53
87
  | value type | read only | description |
54
88
  |---|---|:---|
55
- | `array` | no | defines a value of a name record |
89
+ | `string[]` | no | defines a value of a name record |
56
90
 
57
91
  #### class methods
58
92
 
@@ -103,7 +137,7 @@ The class constructor creates a new instance of the class. It receives no argume
103
137
 
104
138
  | value type | read only | description |
105
139
  |---|---|:---|
106
- | `array` | yes | contains a list of a name records |
140
+ | `TChnNameRecord[]` | yes | contains a list of a name records |
107
141
 
108
142
  #### class methods
109
143
 
@@ -135,11 +169,6 @@ Searches an index of a given name in the list.
135
169
  |:---|---|---:|:---|
136
170
  | `value` | `string` | --- | a name to be searched |
137
171
 
138
- <a name="TChnNamesList+getName"></a>
139
- ##### **getName(value)** => `?TChnNameRecord`
140
-
141
- > \[!] NOTE: `[since v0.0.5]` deprecated. Use `getItem` instead.
142
-
143
172
  <a name="TChnNamesList+getItem"></a>
144
173
  ##### **getItem(value)** => `?TChnNameRecord`
145
174
 
@@ -151,11 +180,6 @@ Returns a name record addressed by a given index.
151
180
  |:---|---|---:|:---|
152
181
  | `value` | `number` | --- | an element index in the list |
153
182
 
154
- <a name="TChnNamesList+addName"></a>
155
- #### **addName(data)** => `boolean`
156
-
157
- > \[!] NOTE: `[since v0.0.5]` deprecated. Use `addItem` instead.
158
-
159
183
  <a name="TChnNamesList+addItem"></a>
160
184
  #### **addItem(data)** => `boolean`
161
185
 
@@ -167,11 +191,6 @@ Adds a new name record to a list members.
167
191
  |:---|---|---:|:---|
168
192
  | `data` | `any` | --- | a data for a name record to be added in the list |
169
193
 
170
- <a name="TChnNamesList+delName"></a>
171
- ##### **delName(value)** => `boolean`
172
-
173
- > \[!] NOTE: `[since v0.0.5]` deprecated. Use `delItem` instead.
174
-
175
194
  <a name="TChnNamesList+delItem"></a>
176
195
  ##### **delItem(value)** => `boolean`
177
196
 
@@ -183,11 +202,6 @@ Tries to delete a name record addressed by a given index.
183
202
  |:---|---|---:|:---|
184
203
  | `value` | `number` | --- | an element index in the list |
185
204
 
186
- <a name="TChnNamesList+loadNames"></a>
187
- ##### **loadNames(list, \[opt])** => `number`
188
-
189
- > \[!] NOTE: `[since v0.0.5]` deprecated. Use `loadItems` instead.
190
-
191
205
  <a name="TChnNamesList+loadItems"></a>
192
206
  ##### **loadItems(list, \[opt])** => `number`
193
207
 
@@ -288,16 +302,12 @@ Sets a channel alias.
288
302
  <a name="TChnAliasItem+addName"></a>
289
303
  ##### **addName(data)** => `boolean`
290
304
 
291
- Adds a new name record.
292
-
293
- > **See**: [TChnNamesList.addName](#TChnNamesList+addName)
305
+ > \[!] NOTE: `[since v0.0.7]` deprecated. Use [`TChnNamesList.addItem`](#TChnNamesList+addItem) instead.
294
306
 
295
307
  <a name="TChnAliasItem+loadNames"></a>
296
308
  ##### **loadNames(list, \[opt])** => `number`
297
309
 
298
- Loads a list of a new name records.
299
-
300
- > **See**: [TChnNamesList.loadNames](#TChnNamesList+loadNames)
310
+ > \[!] NOTE: `[since v0.0.7]` deprecated. Use [`TChnNamesList.loadItems`](#TChnNamesList+loadItems) instead.
301
311
 
302
312
  <a name="TChnAliasItem+enable"></a>
303
313
  ##### **enable()** => `void`
@@ -333,7 +343,7 @@ Sets item status.
333
343
  #### class methods (*special*)
334
344
 
335
345
  <a name="TChnAliasItem+toJSON"></a>
336
- ##### **toJSON()**
346
+ ##### **toJSON()** => `IChannelRecord`
337
347
 
338
348
  A special method that provides an interface to an instance representation
339
349
  for a `JSON.stringify()`.
340
350
 
@@ -346,7 +356,7 @@ Creates a new alias element.
346
356
 
347
357
  | parameter name | value type | default value | description |
348
358
  |:---|---|---:|:---|
349
- | `obj` | `object` | --- | an initial data |
359
+ | `obj` | `IChannelRecord` | --- | an initial data |
350
360
 
351
361
  <a name="TChnAliasList"></a>
352
362
  ### **TChnAliasList**
@@ -423,7 +433,7 @@ Adds an alias element.
423
433
 
424
434
  | parameter name | value type | default value | description |
425
435
  |:---|---|---:|:---|
426
- | `obj` | `object` | --- | an element to be added |
436
+ | `obj` | `IChannelRecord` | --- | an element to be added |
427
437
 
428
438
  <a name="TChnAliasList+delItem"></a>
429
439
  ##### **delItem(value)** => `boolean`
@@ -441,7 +451,7 @@ Loads a list of a new alias elements.
441
451
 
442
452
  | parameter name | value type | default value | description |
443
453
  |:---|---|---:|:---|
444
- | `list` | `array` | --- | a list of an elements |
454
+ | `list` | `IChannelRecord[]` | --- | a list of an elements |
445
455
  | `opt` | `boolean` | `true` | a flag that defines whether to clear the list before load a new one |
446
456
 
447
457
  <a name="TChnAliasList+clear"></a>
@@ -474,7 +484,7 @@ Returns an array of a channel items picked up by a given function.
474
484
  <a name="loadAliasFromFileSync"></a>
475
485
  #### **loadAliasFromFileSync(src, [opt])** => `object`
476
486
 
477
- Loads an alias from a file.
487
+ Loads an alias data from a file.
478
488
 
479
489
  | parameter name | value type | default value | description |
480
490
  |:---|---|---:|:---|
@@ -482,12 +492,12 @@ Loads an alias from a file.
482
492
  | `opt` | `any` | --- | <*reserved*> |
483
493
 
484
494
  <a name="saveAliasToFileSync"></a>
485
- #### **saveAliasToFileSync(src, content, [opt])** => `object`
495
+ #### **saveAliasToFileSync(src, content, [opt])** => `fsoDescr`
486
496
 
487
- Saves an alias to a file
497
+ Saves an alias data to a file.
488
498
 
489
499
  | parameter name | value type | default value | description |
490
500
  |:---|---|---:|:---|
491
501
  | `src` | `string` | --- | a path to some file |
492
- | `content` | `array` | --- | a content to save |
502
+ | `content` | `object` or `object[]` | --- | a content to save |
493
503
  | `opt` | `any` | --- | <*reserved*> |
package/index.d.ts CHANGED
@@ -1,17 +1,24 @@
1
- import {
2
- TChnNameRecord, TChnNamesList,
3
- TChnAliasItem, TChnAliasList,
4
- } from './lib/chn-alias-list';
5
-
6
- import {
7
- loadAliasFromFileSync, saveAliasToFileSync,
8
- } from './lib/file-helper-ext';
9
-
10
- export {
11
- TChnNameRecord, TChnNamesList,
12
- TChnAliasItem, TChnAliasList,
13
- loadAliasFromFileSync, saveAliasToFileSync,
14
- };
15
-
16
- import type { fsoDescr } from '@cntwg/file-helper';
17
- export type { fsoDescr };
1
+ import type { fsoDescr } from '@cntwg/file-helper';
2
+
3
+ import {
4
+ TChnNameRecord, TChnNamesList,
5
+ TChnAliasItem, TChnAliasList,
6
+ type IChannelRecord,
7
+ } from './lib/chn-alias-list';
8
+
9
+ import {
10
+ loadAliasFromFileSync, saveAliasToFileSync,
11
+ type RVAL_loadaliasff,
12
+ } from './lib/file-helper-ext';
13
+
14
+ export {
15
+ TChnNameRecord, TChnNamesList,
16
+ TChnAliasItem, TChnAliasList,
17
+ loadAliasFromFileSync, saveAliasToFileSync,
18
+ };
19
+
20
+ export type {
21
+ fsoDescr,
22
+ IChannelRecord,
23
+ RVAL_loadaliasff,
24
+ };
@@ -1,292 +1,294 @@
1
- /**
2
- * A user defined procedure to process an array elements
3
- */
4
- export type forEachProcEx = (item: any, index?: number, arr?: any[]) => void;
5
- /**
6
- * A user defined procedure to process an array elements
7
- */
8
- export type cbArrECheck = (item: any, index?: number, arr?: any[]) => any;
9
-
10
- /**
11
- * @classdesc This class implements an interface of the name record
12
- */
13
- export class TChnNameRecord {
14
- /**
15
- * Contains a language
16
- */
17
- get lang(): string;
18
- /**
19
- * Contains a value of the record
20
- */
21
- get text(): string;
22
- /**
23
- * Contains a value of the record
24
- */
25
- get value(): string[];
26
- set value(data: string[]);
27
- /**
28
- * Sets the record value
29
- */
30
- setValue(data: any): boolean;
31
- /**
32
- * Returns value as a formated string
33
- */
34
- toFormatString(opt: any): string;
35
- /**
36
- * Clears the record
37
- */
38
- reset(): void;
39
- #private;
40
- }
41
-
42
- /**
43
- * @classdesc This class implements an interface of the name records list
44
- */
45
- export class TChnNamesList {
46
- /**
47
- * Contains a quantity of a name records
48
- */
49
- get count(): number;
50
- /**
51
- * Contains a list of a name records
52
- */
53
- get value(): TChnNameRecord[];
54
- /**
55
- * Returns a flag whether a list is empty or not
56
- */
57
- isEmpty(): boolean;
58
- /**
59
- * Returns a flag whether a list has any members
60
- */
61
- isNotEmpty(): boolean;
62
- /**
63
- * Checks whether a given value is an index and fits an index range
64
- * within the instance
65
- */
66
- chkIndex(value: any): boolean;
67
- /**
68
- * Searches an index of a given name
69
- */
70
- getIndex(value: string): number;
71
- /**
72
- * @deprecated
73
- * @see TChnNamesList.getItem
74
- * @todo [from v0.0.5] make obsolete
75
- */
76
- getName(value: any): TChnNameRecord;
77
- /**
78
- * Returns a name record
79
- * @since 0.0.5
80
- */
81
- getItem(value: number): TChnNameRecord | null;
82
- /**
83
- * @deprecated
84
- * @see TChnNamesList.addItem
85
- * @todo [from v0.0.5] make obsolete
86
- */
87
- addName(data: any): boolean;
88
- /**
89
- * Adds a new name record to a list members
90
- * @since 0.0.5
91
- */
92
- addItem(data: any): boolean;
93
- /**
94
- * @deprecated
95
- * @see TChnNamesList.delItem
96
- * @todo [from v0.0.5] make obsolete
97
- */
98
- delName(value: any): boolean;
99
- /**
100
- * Tries to delete a name record addressed by a given index
101
- * @since 0.0.5
102
- */
103
- delItem(value: number): boolean;
104
- /**
105
- * @deprecated
106
- * @see TChnNamesList.loadItems
107
- * @todo [from v0.0.5] make obsolete
108
- */
109
- loadNames(...args: any[]): number;
110
- /**
111
- * Loads a new name records
112
- * @since 0.0.5
113
- */
114
- loadItems(list: any, opt?: boolean): number;
115
- /**
116
- * Removes all of the instance members
117
- */
118
- clear(): void;
119
- /**
120
- * Calls given function for each name record
121
- */
122
- forEach(cb: forEachProcEx): void;
123
- /**
124
- * Returns an array of a name records picked up by a given function
125
- */
126
- filter(cb: cbArrECheck): TChnNameRecord[];
127
- [Symbol.iterator](): {
128
- next: () => {
129
- done: boolean;
130
- value: TChnNameRecord | null;
131
- } | {
132
- done: boolean;
133
- value?: undefined;
134
- };
135
- return(): {
136
- done: boolean;
137
- };
138
- };
139
- #private;
140
- }
141
-
142
- /**
143
- * @classdesc This class implements an interface of the channel item
144
- */
145
- export class TChnAliasItem {
146
- /**
147
- * Creates a new alias element
148
- */
149
- static create(obj: object): TChnAliasItem | null;
150
- /**
151
- * Contains a channel ID
152
- */
153
- get id(): string;
154
- set id(value: string);
155
- /**
156
- * Contains a channel alias
157
- */
158
- get alias(): string;
159
- set alias(value: string);
160
- /**
161
- * Contains a list of a name records
162
- */
163
- get names(): TChnNamesList;
164
- /**
165
- * Contains an instance status
166
- */
167
- get status(): string;
168
- /**
169
- * Sets a channel ID
170
- * @see valueToIDString
171
- */
172
- setID(value: string): boolean;
173
- /**
174
- * Sets a channel alias
175
- * @see valueToIDString
176
- */
177
- setAlias(value: string): boolean;
178
- /**
179
- * Returns a name record
180
- * @deprecated
181
- * @see TChnNamesList.getItem
182
- */
183
- getName(value: number): TChnNameRecord | null;
184
- /**
185
- * Adds a new name record
186
- * @see TChnNamesList.addItem
187
- */
188
- addName(data: any): boolean;
189
- /**
190
- * Loads a list of a new name records
191
- * @see TChnNamesList.loadItems
192
- */
193
- loadNames(...args: [list: any, opt?: boolean]): number;
194
- /**
195
- * Sets item status to enabled
196
- */
197
- enable(): void;
198
- /**
199
- * Sets item status to disabled
200
- */
201
- disable(): void;
202
- /**
203
- * Sets item status to active/running
204
- */
205
- up(): void;
206
- /**
207
- * Sets item status to inactive/stopped
208
- */
209
- down(): void;
210
- /**
211
- * Sets item status
212
- */
213
- setStatus(value: string): boolean;
214
- /**
215
- * Provides an interface to an instance representation for JSON.stringify()
216
- */
217
- protected toJSON(): any;
218
- #private;
219
- }
220
-
221
- /**
222
- * @classdesc This class implements an interface of the channel items list
223
- */
224
- export class TChnAliasList {
225
- /**
226
- * Contains a quantity of the elements
227
- */
228
- get count(): number;
229
- /**
230
- * Returns a flag whether a list is empty or not
231
- */
232
- isEmpty(): boolean;
233
- /**
234
- * Returns a flag whether a list has any members
235
- */
236
- isNotEmpty(): boolean;
237
- /**
238
- * Checks whether a given value is an index and fits an index range
239
- * within the instance
240
- */
241
- chkIndex(value: any): boolean;
242
- /**
243
- * Searches an index of an element by its ID
244
- * @see valueToIDString
245
- */
246
- searchIndexByID(value: string): number;
247
- /**
248
- * Returns an alias element by its index
249
- */
250
- getItem(value: number): TChnAliasItem | null;
251
- /**
252
- * Returns an alias element by its ID
253
- */
254
- getItemByID(value: string): TChnAliasItem | null;
255
- /**
256
- * Adds an alias element
257
- */
258
- addItem(obj: object): number;
259
- /**
260
- * Tries to delete an element addressed by a given index
261
- */
262
- delItem(value: number): boolean;
263
- /**
264
- * Loads a list of a new alias elements
265
- */
266
- loadItems(list: any[], opt?: boolean): number;
267
- /**
268
- * Removes all of the instance members
269
- */
270
- clear(): void;
271
- /**
272
- * Calls given function for each alias element
273
- */
274
- forEach(cb: forEachProcEx): void;
275
- /**
276
- * Returns an array of a name records picked up by a given function
277
- */
278
- filter(cb: cbArrECheck): TChnAliasItem[];
279
- [Symbol.iterator](): {
280
- next: () => {
281
- done: boolean;
282
- value: TChnAliasItem | null;
283
- } | {
284
- done: boolean;
285
- value?: undefined;
286
- };
287
- return(): {
288
- done: boolean;
289
- };
290
- };
291
- #private;
292
- }
1
+ /**
2
+ * Defines an object for storing a channel data
3
+ */
4
+ export type IChannelRecord = {
5
+ /**
6
+ * - channel ID
7
+ */
8
+ id: string;
9
+ /**
10
+ * - target ID
11
+ */
12
+ alias: string;
13
+ /**
14
+ * - list of a channel names
15
+ */
16
+ name: any[];
17
+ /**
18
+ * - channel status
19
+ */
20
+ status: string;
21
+ };
22
+ /**
23
+ * A user defined procedure to process an array elements
24
+ */
25
+ export type forEachProcEx = (item: any, index?: number, arr?: any[]) => void;
26
+ /**
27
+ * A user defined procedure to process an array elements
28
+ */
29
+ export type cbArrECheck = (item: any, index?: number, arr?: any[]) => any;
30
+
31
+ /**
32
+ * @classdesc This class implements an interface of the name record
33
+ */
34
+ export class TChnNameRecord {
35
+ /**
36
+ * Contains a language
37
+ */
38
+ get lang(): string;
39
+ /**
40
+ * Contains a value of the record
41
+ */
42
+ get text(): string;
43
+ /**
44
+ * Contains a value of the record
45
+ */
46
+ get value(): string[];
47
+ set value(data: string[]);
48
+ /**
49
+ * Sets the record value
50
+ */
51
+ setValue(data: any): boolean;
52
+ /**
53
+ * Returns value as a formated string
54
+ */
55
+ toFormatString(opt: any): string;
56
+ /**
57
+ * Clears the record
58
+ */
59
+ reset(): void;
60
+ #private;
61
+ }
62
+
63
+ /**
64
+ * @classdesc This class implements an interface of the name records list
65
+ */
66
+ export class TChnNamesList {
67
+ /**
68
+ * Contains a quantity of a name records
69
+ */
70
+ get count(): number;
71
+ /**
72
+ * Contains a list of a name records
73
+ */
74
+ get value(): TChnNameRecord[];
75
+ /**
76
+ * Returns a flag whether a list is empty or not
77
+ */
78
+ isEmpty(): boolean;
79
+ /**
80
+ * Returns a flag whether a list has any members
81
+ */
82
+ isNotEmpty(): boolean;
83
+ /**
84
+ * Checks whether a given value is an index and fits an index range
85
+ * within the instance
86
+ */
87
+ chkIndex(value: any): boolean;
88
+ /**
89
+ * Searches an index of a given name
90
+ */
91
+ getIndex(value: string): number;
92
+ /**
93
+ * Returns a name record
94
+ * @since 0.0.5
95
+ */
96
+ getItem(value: number): TChnNameRecord | null;
97
+ /**
98
+ * Adds a new name record to a list members
99
+ * @since 0.0.5
100
+ */
101
+ addItem(data: any): boolean;
102
+ /**
103
+ * Tries to delete a name record addressed by a given index
104
+ * @since 0.0.5
105
+ */
106
+ delItem(value: number): boolean;
107
+ /**
108
+ * Loads a new name records
109
+ * @since 0.0.5
110
+ */
111
+ loadItems(list: any, opt?: boolean): number;
112
+ /**
113
+ * Removes all of the instance members
114
+ */
115
+ clear(): void;
116
+ /**
117
+ * Calls given function for each name record
118
+ */
119
+ forEach(cb: forEachProcEx): void;
120
+ /**
121
+ * Returns an array of a name records picked up by a given function
122
+ */
123
+ filter(cb: cbArrECheck): TChnNameRecord[];
124
+ [Symbol.iterator](): {
125
+ next: () => {
126
+ done: boolean;
127
+ value: TChnNameRecord | null;
128
+ } | {
129
+ done: boolean;
130
+ value?: undefined;
131
+ };
132
+ return(): {
133
+ done: boolean;
134
+ };
135
+ };
136
+ #private;
137
+ }
138
+
139
+ /**
140
+ * @classdesc This class implements an interface of the channel item
141
+ */
142
+ export class TChnAliasItem {
143
+ /**
144
+ * Creates a new alias element
145
+ */
146
+ static create(obj: IChannelRecord): TChnAliasItem | null;
147
+ /**
148
+ * Contains a channel ID
149
+ */
150
+ get id(): string;
151
+ set id(value: string);
152
+ /**
153
+ * Contains a channel alias
154
+ */
155
+ get alias(): string;
156
+ set alias(value: string);
157
+ /**
158
+ * Contains a list of a name records
159
+ */
160
+ get names(): TChnNamesList;
161
+ /**
162
+ * Contains an instance status
163
+ */
164
+ get status(): string;
165
+ /**
166
+ * Sets a channel ID
167
+ * @see valueToIDString
168
+ */
169
+ setID(value: string): boolean;
170
+ /**
171
+ * Sets a channel alias
172
+ * @see valueToIDString
173
+ */
174
+ setAlias(value: string): boolean;
175
+ /**
176
+ * Returns a name record
177
+ * @deprecated
178
+ * @see TChnNamesList.getItem
179
+ * @todo [from v0.0.6] make obsolete
180
+ */
181
+ getName(value: number): TChnNameRecord | null;
182
+ /**
183
+ * Adds a new name record
184
+ * @deprecated
185
+ * @see TChnNamesList.addItem
186
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.addItem` instead.
187
+ */
188
+ addName(data: any): boolean;
189
+ /**
190
+ * Loads a list of a new name records
191
+ * @deprecated
192
+ * @see TChnNamesList.loadItems
193
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.loadItems` instead.
194
+ */
195
+ loadNames(...args: [list: any, opt?: boolean]): number;
196
+ /**
197
+ * Sets item status to enabled
198
+ */
199
+ enable(): void;
200
+ /**
201
+ * Sets item status to disabled
202
+ */
203
+ disable(): void;
204
+ /**
205
+ * Sets item status to active/running
206
+ */
207
+ up(): void;
208
+ /**
209
+ * Sets item status to inactive/stopped
210
+ */
211
+ down(): void;
212
+ /**
213
+ * Sets item status
214
+ */
215
+ setStatus(value: string): boolean;
216
+ /**
217
+ * Provides an interface to an instance representation for JSON.stringify()
218
+ */
219
+ protected toJSON(): IChannelRecord;
220
+ #private;
221
+ }
222
+
223
+ /**
224
+ * @classdesc This class implements an interface of the channel items list
225
+ */
226
+ export class TChnAliasList {
227
+ /**
228
+ * Contains a quantity of the elements
229
+ */
230
+ get count(): number;
231
+ /**
232
+ * Returns a flag whether a list is empty or not
233
+ */
234
+ isEmpty(): boolean;
235
+ /**
236
+ * Returns a flag whether a list has any members
237
+ */
238
+ isNotEmpty(): boolean;
239
+ /**
240
+ * Checks whether a given value is an index and fits an index range
241
+ * within the instance
242
+ */
243
+ chkIndex(value: any): boolean;
244
+ /**
245
+ * Searches an index of an element by its ID
246
+ * @see valueToIDString
247
+ */
248
+ searchIndexByID(value: string): number;
249
+ /**
250
+ * Returns an alias element by its index
251
+ */
252
+ getItem(value: number): TChnAliasItem | null;
253
+ /**
254
+ * Returns an alias element by its ID
255
+ */
256
+ getItemByID(value: string): TChnAliasItem | null;
257
+ /**
258
+ * Adds an alias element
259
+ */
260
+ addItem(obj: IChannelRecord): number;
261
+ /**
262
+ * Tries to delete an element addressed by a given index
263
+ */
264
+ delItem(value: number): boolean;
265
+ /**
266
+ * Loads a list of a new alias elements
267
+ */
268
+ loadItems(list: IChannelRecord[], opt?: boolean): number;
269
+ /**
270
+ * Removes all of the instance members
271
+ */
272
+ clear(): void;
273
+ /**
274
+ * Calls given function for each alias element
275
+ */
276
+ forEach(cb: forEachProcEx): void;
277
+ /**
278
+ * Returns an array of a name records picked up by a given function
279
+ */
280
+ filter(cb: cbArrECheck): TChnAliasItem[];
281
+ [Symbol.iterator](): {
282
+ next: () => {
283
+ done: boolean;
284
+ value: TChnAliasItem | null;
285
+ } | {
286
+ done: boolean;
287
+ value?: undefined;
288
+ };
289
+ return(): {
290
+ done: boolean;
291
+ };
292
+ };
293
+ #private;
294
+ }
@@ -1,4 +1,4 @@
1
- // [v0.1.047-20260120]
1
+ // [v0.1.053-20260308]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -10,10 +10,6 @@ const {
10
10
 
11
11
  // === module inner block ===
12
12
 
13
- /***
14
- * (* helper function definitions *)
15
- */
16
-
17
13
  /**
18
14
  * Converts a <Lang, Text> key-pair to a string
19
15
  * @function convertLangTextValueToString
@@ -37,16 +33,13 @@ function convertLangTextValueToString(data, opt) {
37
33
 
38
34
  // === module main block ===
39
35
 
40
- /***
41
- * (* constant definitions *)
42
- */
43
-
44
- /***
45
- * (* function definitions *)
46
- */
47
-
48
- /***
49
- * (* class definitions *)
36
+ /**
37
+ * Defines an object for storing a channel data
38
+ * @typedef {Object} IChannelRecord
39
+ * @property {string} id - channel ID
40
+ * @property {string} alias - target ID
41
+ * @property {any[]} name - list of a channel names
42
+ * @property {string} status - channel status
50
43
  */
51
44
 
52
45
  /**
@@ -152,6 +145,7 @@ class TChnNameRecord {
152
145
  }
153
146
 
154
147
  };
148
+ module.exports.TChnNameRecord = TChnNameRecord;
155
149
 
156
150
  /**
157
151
  * A user defined procedure to process an array elements
@@ -265,15 +259,6 @@ class TChnNamesList {
265
259
  return index;
266
260
  }
267
261
 
268
- /**
269
- * @deprecated
270
- * @see TChnNamesList.getItem
271
- * @todo [from v0.0.5] make obsolete
272
- */
273
- getName(value) {
274
- return this.getItem(value);
275
- }
276
-
277
262
  /**
278
263
  * Returns a name record
279
264
  * @since 0.0.5
@@ -284,15 +269,6 @@ class TChnNamesList {
284
269
  return this.chkIndex(value) ? this.#_items[Number(value)] : null;
285
270
  }
286
271
 
287
- /**
288
- * @deprecated
289
- * @see TChnNamesList.addItem
290
- * @todo [from v0.0.5] make obsolete
291
- */
292
- addName(data) {
293
- return this.addItem(data);
294
- }
295
-
296
272
  /**
297
273
  * Adds a new name record to a list members
298
274
  * @since 0.0.5
@@ -307,15 +283,6 @@ class TChnNamesList {
307
283
  return isSucceed;
308
284
  }
309
285
 
310
- /**
311
- * @deprecated
312
- * @see TChnNamesList.delItem
313
- * @todo [from v0.0.5] make obsolete
314
- */
315
- delName(value) {
316
- return this.delItem(value);
317
- }
318
-
319
286
  /**
320
287
  * Tries to delete a name record addressed by a given index
321
288
  * @since 0.0.5
@@ -328,15 +295,6 @@ class TChnNamesList {
328
295
  return isSucceed;
329
296
  }
330
297
 
331
- /**
332
- * @deprecated
333
- * @see TChnNamesList.loadItems
334
- * @todo [from v0.0.5] make obsolete
335
- */
336
- loadNames(...args) {
337
- return this.loadItems(...args);
338
- }
339
-
340
298
  /**
341
299
  * Loads a new name records
342
300
  * @since 0.0.5
@@ -382,6 +340,7 @@ class TChnNamesList {
382
340
  }
383
341
 
384
342
  };
343
+ module.exports.TChnNamesList = TChnNamesList;
385
344
 
386
345
  /**
387
346
  * @classdesc This class implements an interface of the channel item
@@ -490,6 +449,7 @@ class TChnAliasItem {
490
449
  * @returns {?TChnNameRecord}
491
450
  * @deprecated
492
451
  * @see TChnNamesList.getItem
452
+ * @todo [from v0.0.6] make obsolete
493
453
  */
494
454
  getName(value) {
495
455
  return this.#_names.getItem(value);
@@ -499,7 +459,9 @@ class TChnAliasItem {
499
459
  * Adds a new name record
500
460
  * @param {any} data - a name record
501
461
  * @returns {boolean}
462
+ * @deprecated
502
463
  * @see TChnNamesList.addItem
464
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.addItem` instead.
503
465
  */
504
466
  addName(data) {
505
467
  return this.#_names.addItem(data);
@@ -510,7 +472,9 @@ class TChnAliasItem {
510
472
  * @param {array} list - a list of an elements
511
473
  * @param {boolean} [opt=true] - defines whether to clear the list before load a new one
512
474
  * @returns {number}
475
+ * @deprecated
513
476
  * @see TChnNamesList.loadItems
477
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.loadItems` instead.
514
478
  */
515
479
  loadNames(...args) {
516
480
  return this.#_names.loadItems(...args);
@@ -582,7 +546,7 @@ class TChnAliasItem {
582
546
 
583
547
  /**
584
548
  * Provides an interface to an instance representation for JSON.stringify()
585
- * @returns {Object}
549
+ * @returns {IChannelRecord}
586
550
  * @protected
587
551
  */
588
552
  toJSON() {
@@ -597,7 +561,7 @@ class TChnAliasItem {
597
561
 
598
562
  /**
599
563
  * Creates a new alias element
600
- * @param {object} obj - an init data
564
+ * @param {IChannelRecord} obj - an init data
601
565
  * @returns {?TChnAliasItem}
602
566
  * @static
603
567
  */
@@ -610,7 +574,7 @@ class TChnAliasItem {
610
574
  let { alias, name, status } = obj;
611
575
  if (obj instanceof TChnAliasItem) name = obj.names.value;
612
576
  item.setAlias(alias);
613
- item.loadNames(name);
577
+ item.names.loadItems(name);
614
578
  if (typeof isDisabled === 'boolean') {
615
579
  // // TODO: process "status"
616
580
  if (isDisabled) item.disable();
@@ -624,6 +588,7 @@ class TChnAliasItem {
624
588
  }
625
589
 
626
590
  };
591
+ module.exports.TChnAliasItem = TChnAliasItem;
627
592
 
628
593
  /**
629
594
  * @classdesc This class implements an interface of the channel items list
@@ -726,7 +691,7 @@ class TChnAliasList {
726
691
 
727
692
  /**
728
693
  * Adds an alias element
729
- * @param {object} obj - an element to be added
694
+ * @param {IChannelRecord} obj - an element to be added
730
695
  * @returns {number}
731
696
  */
732
697
  addItem(obj) {
@@ -734,7 +699,7 @@ class TChnAliasList {
734
699
  let index = -1;
735
700
  if (item !== null) {
736
701
  const id = valueToIDString(item.id);
737
- index = this.searchIndexByID(id);
702
+ if (id != null) index = this.searchIndexByID(id);
738
703
  if (index === -1) {
739
704
  index = this.count;
740
705
  this.#_items.push(item);
@@ -758,7 +723,7 @@ class TChnAliasList {
758
723
 
759
724
  /**
760
725
  * Loads a list of a new alias elements
761
- * @param {array} list - a list of an elements
726
+ * @param {IChannelRecord[]} list - a list of an elements
762
727
  * @param {boolean} [opt=true] - defines whether to clear the list before load a new one
763
728
  * @returns {number}
764
729
  */
@@ -799,10 +764,4 @@ class TChnAliasList {
799
764
  }
800
765
 
801
766
  };
802
-
803
- // === module exports block ===
804
-
805
- module.exports.TChnNameRecord = TChnNameRecord;
806
- module.exports.TChnNamesList = TChnNamesList;
807
- module.exports.TChnAliasItem = TChnAliasItem;
808
767
  module.exports.TChnAliasList = TChnAliasList;
@@ -1,28 +1,28 @@
1
- /**
2
- * A result of `loadAliasFromFile...`
3
- */
4
- export type RVAL_loadaliasff = {
5
- /**
6
- * - ops description
7
- */
8
- descr: fsoDescr;
9
- /**
10
- * - loaded content
11
- */
12
- result: null | TChnAliasItem | TChnAliasList;
13
- };
14
-
15
- /**
16
- * Loads an alias from a file
17
- * @see {@link loadJSONFromFileSync} for details of an `opt` param
18
- */
19
- export function loadAliasFromFileSync(src: string, opt?: any): RVAL_loadaliasff;
20
- /**
21
- * Saves an alias to a file
22
- * @see {@link saveJSONToFileSync} for details of an `opt` param
23
- */
24
- export function saveAliasToFileSync(src: string, content: any[], opt?: any): fsoDescr;
25
-
26
- import type { fsoDescr } from '@cntwg/file-helper';
27
- import { TChnAliasItem } from "./chn-alias-list";
28
- import { TChnAliasList } from "./chn-alias-list";
1
+ /**
2
+ * A result of `loadAliasFromFile...`
3
+ */
4
+ export type RVAL_loadaliasff = {
5
+ /**
6
+ * - ops description
7
+ */
8
+ descr: fsoDescr;
9
+ /**
10
+ * - loaded content
11
+ */
12
+ result: null | TChnAliasItem | TChnAliasList;
13
+ };
14
+
15
+ /**
16
+ * Loads an alias from a file
17
+ * @see {@link loadJSONFromFileSync} for details of an `opt` param
18
+ */
19
+ export function loadAliasFromFileSync(src: string, opt?: any): RVAL_loadaliasff;
20
+ /**
21
+ * Saves an alias to a file
22
+ * @see {@link saveJSONToFileSync} for details of an `opt` param
23
+ */
24
+ export function saveAliasToFileSync(src: string, content: object | object[], opt?: any): fsoDescr;
25
+
26
+ import type { fsoDescr } from "@cntwg/file-helper";
27
+ import { TChnAliasItem } from "./chn-alias-list";
28
+ import { TChnAliasList } from "./chn-alias-list";
@@ -1,9 +1,9 @@
1
- // [v0.1.047-20260120]
1
+ // [v0.1.050-20260308]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
- isArray,
6
+ isArray, isObject,
7
7
  } = require('@ygracs/bsfoc-lib-js');
8
8
 
9
9
  const {
@@ -21,14 +21,6 @@ const {
21
21
 
22
22
  // === module main block ===
23
23
 
24
- /***
25
- * (* constant definitions *)
26
- */
27
-
28
- /***
29
- * (* function definitions *)
30
- */
31
-
32
24
  /**
33
25
  * A result of `loadAliasFromFile...`
34
26
  * @typedef {Object} RVAL_loadaliasff
@@ -58,29 +50,38 @@ function loadAliasFromFileSync(src, opt) {
58
50
  };
59
51
  return { descr, result };
60
52
  };
53
+ module.exports.loadAliasFromFileSync = loadAliasFromFileSync;
61
54
 
62
55
  /**
63
56
  * Saves an alias to a file
64
57
  * @function saveAliasToFileSync
65
58
  * @param {string} src - a path to some file
66
- * @param {Array} content - content
59
+ * @param {(object|object[])} content - content
67
60
  * @param {any} [opt] - <reserved>
68
61
  * @returns {fsoDescr}
69
62
  * @see {@link saveJSONToFileSync} for details of an `opt` param
70
63
  */
71
64
  function saveAliasToFileSync(src, content, opt) {
72
- const obj = isArray(content) ? content : null;
73
- let result = null;
74
- //===
75
- result = saveJSONToFileSync(src, obj, opt);
76
- return result;
65
+ /** @type {fsoDescr} */
66
+ let data = {
67
+ isERR: false,
68
+ errCode: 0,
69
+ errEvent: '',
70
+ errMsg: '',
71
+ source: '',
72
+ content: '',
73
+ };
74
+ if (isArray(content) || isObject(content)) {
75
+ //const obj = isArray(content) ? content : null;
76
+ //===
77
+ data = saveJSONToFileSync(src, content, opt);
78
+ } else {
79
+ if (content !== undefined) {
80
+ // // TODO: define `errCode` and `errMsg`
81
+ data.isERR = true;
82
+ data.errEvent = 'ERR_BAD_CONTENT';
83
+ };
84
+ };
85
+ return data;
77
86
  };
78
-
79
- /***
80
- * (* class definitions *)
81
- */
82
-
83
- // === module exports block ===
84
-
85
- module.exports.loadAliasFromFileSync = loadAliasFromFileSync;
86
87
  module.exports.saveAliasToFileSync = saveAliasToFileSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygracs/chn-alias-list",
3
- "version": "0.0.7-b",
3
+ "version": "0.0.8",
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",
@@ -11,7 +11,7 @@
11
11
  "main": "./index.js",
12
12
  "types": "./index.d.ts",
13
13
  "files": [
14
- "doc/chn-alias-list.md",
14
+ "doc/*.md",
15
15
  "lib/chn-alias-list.js",
16
16
  "lib/file-helper-ext.js",
17
17
  "lib/*.d.ts",
@@ -31,10 +31,10 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@cntwg/file-helper": "^0.0.3",
34
- "@ygracs/bsfoc-lib-js": "~0.3.3"
34
+ "@ygracs/bsfoc-lib-js": "~0.3.4"
35
35
  },
36
36
  "devDependencies": {
37
- "@ygracs/test-helper": "~0.0.1-b",
37
+ "@ygracs/test-helper": "~0.0.2-b",
38
38
  "jest": "^30.2.0",
39
39
  "jsdoc-to-markdown": "^9.1.3",
40
40
  "minimist": "^1.2.8",