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

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,13 @@
1
- #### *v0.0.x*
1
+ #### *v0.0.7*
2
2
 
3
3
  Pre-release version.
4
4
 
5
+ > - update `chn-alias-list.md`;
5
6
  > - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
6
7
  > - update dependency on `@cntwg/file-helper` module to v0.0.3;
8
+ > - improve behavior of `saveAliasToFileSync` on handling `content` param;
9
+ > - deprecate methods: `addName` and `loadNames` of a `TChnAliasItem`-class;
10
+ > - other fixes.
7
11
 
8
12
  #### *v0.0.6*
9
13
 
@@ -1,7 +1,7 @@
1
1
 
2
- >|***rev.*:**|0.0.5|
2
+ >|***rev.*:**|0.0.8|
3
3
  >|:---|---:|
4
- >|date:|2025-04-14|
4
+ >|date:|2026-01-30|
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
 
@@ -288,16 +322,12 @@ Sets a channel alias.
288
322
  <a name="TChnAliasItem+addName"></a>
289
323
  ##### **addName(data)** => `boolean`
290
324
 
291
- Adds a new name record.
292
-
293
- > **See**: [TChnNamesList.addName](#TChnNamesList+addName)
325
+ > \[!] NOTE: `[since v0.0.7]` deprecated. Use [`TChnNamesList.addItem`](#TChnNamesList+addItem) instead.
294
326
 
295
327
  <a name="TChnAliasItem+loadNames"></a>
296
328
  ##### **loadNames(list, \[opt])** => `number`
297
329
 
298
- Loads a list of a new name records.
299
-
300
- > **See**: [TChnNamesList.loadNames](#TChnNamesList+loadNames)
330
+ > \[!] NOTE: `[since v0.0.7]` deprecated. Use [`TChnNamesList.loadItems`](#TChnNamesList+loadItems) instead.
301
331
 
302
332
  <a name="TChnAliasItem+enable"></a>
303
333
  ##### **enable()** => `void`
@@ -333,7 +363,7 @@ Sets item status.
333
363
  #### class methods (*special*)
334
364
 
335
365
  <a name="TChnAliasItem+toJSON"></a>
336
- ##### **toJSON()**
366
+ ##### **toJSON()** => `IChannelRecord`
337
367
 
338
368
  A special method that provides an interface to an instance representation
339
369
  for a `JSON.stringify()`.
340
370
 
@@ -346,7 +376,7 @@ Creates a new alias element.
346
376
 
347
377
  | parameter name | value type | default value | description |
348
378
  |:---|---|---:|:---|
349
- | `obj` | `object` | --- | an initial data |
379
+ | `obj` | `IChannelRecord` | --- | an initial data |
350
380
 
351
381
  <a name="TChnAliasList"></a>
352
382
  ### **TChnAliasList**
@@ -423,7 +453,7 @@ Adds an alias element.
423
453
 
424
454
  | parameter name | value type | default value | description |
425
455
  |:---|---|---:|:---|
426
- | `obj` | `object` | --- | an element to be added |
456
+ | `obj` | `IChannelRecord` | --- | an element to be added |
427
457
 
428
458
  <a name="TChnAliasList+delItem"></a>
429
459
  ##### **delItem(value)** => `boolean`
@@ -441,7 +471,7 @@ Loads a list of a new alias elements.
441
471
 
442
472
  | parameter name | value type | default value | description |
443
473
  |:---|---|---:|:---|
444
- | `list` | `array` | --- | a list of an elements |
474
+ | `list` | `IChannelRecord[]` | --- | a list of an elements |
445
475
  | `opt` | `boolean` | `true` | a flag that defines whether to clear the list before load a new one |
446
476
 
447
477
  <a name="TChnAliasList+clear"></a>
@@ -474,7 +504,7 @@ Returns an array of a channel items picked up by a given function.
474
504
  <a name="loadAliasFromFileSync"></a>
475
505
  #### **loadAliasFromFileSync(src, [opt])** => `object`
476
506
 
477
- Loads an alias from a file.
507
+ Loads an alias data from a file.
478
508
 
479
509
  | parameter name | value type | default value | description |
480
510
  |:---|---|---:|:---|
@@ -482,12 +512,12 @@ Loads an alias from a file.
482
512
  | `opt` | `any` | --- | <*reserved*> |
483
513
 
484
514
  <a name="saveAliasToFileSync"></a>
485
- #### **saveAliasToFileSync(src, content, [opt])** => `object`
515
+ #### **saveAliasToFileSync(src, content, [opt])** => `fsoDescr`
486
516
 
487
- Saves an alias to a file
517
+ Saves an alias data to a file.
488
518
 
489
519
  | parameter name | value type | default value | description |
490
520
  |:---|---|---:|:---|
491
521
  | `src` | `string` | --- | a path to some file |
492
- | `content` | `array` | --- | a content to save |
522
+ | `content` | `object` or `object[]` | --- | a content to save |
493
523
  | `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,318 @@
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
+ * @deprecated
94
+ * @see TChnNamesList.getItem
95
+ * @todo [from v0.0.5] make obsolete
96
+ */
97
+ getName(value: any): TChnNameRecord;
98
+ /**
99
+ * Returns a name record
100
+ * @since 0.0.5
101
+ */
102
+ getItem(value: number): TChnNameRecord | null;
103
+ /**
104
+ * @deprecated
105
+ * @see TChnNamesList.addItem
106
+ * @todo [from v0.0.5] make obsolete
107
+ */
108
+ addName(data: any): boolean;
109
+ /**
110
+ * Adds a new name record to a list members
111
+ * @since 0.0.5
112
+ */
113
+ addItem(data: any): boolean;
114
+ /**
115
+ * @deprecated
116
+ * @see TChnNamesList.delItem
117
+ * @todo [from v0.0.5] make obsolete
118
+ */
119
+ delName(value: any): boolean;
120
+ /**
121
+ * Tries to delete a name record addressed by a given index
122
+ * @since 0.0.5
123
+ */
124
+ delItem(value: number): boolean;
125
+ /**
126
+ * @deprecated
127
+ * @see TChnNamesList.loadItems
128
+ * @todo [from v0.0.5] make obsolete
129
+ */
130
+ loadNames(...args: any[]): number;
131
+ /**
132
+ * Loads a new name records
133
+ * @since 0.0.5
134
+ */
135
+ loadItems(list: any, opt?: boolean): number;
136
+ /**
137
+ * Removes all of the instance members
138
+ */
139
+ clear(): void;
140
+ /**
141
+ * Calls given function for each name record
142
+ */
143
+ forEach(cb: forEachProcEx): void;
144
+ /**
145
+ * Returns an array of a name records picked up by a given function
146
+ */
147
+ filter(cb: cbArrECheck): TChnNameRecord[];
148
+ [Symbol.iterator](): {
149
+ next: () => {
150
+ done: boolean;
151
+ value: TChnNameRecord | null;
152
+ } | {
153
+ done: boolean;
154
+ value?: undefined;
155
+ };
156
+ return(): {
157
+ done: boolean;
158
+ };
159
+ };
160
+ #private;
161
+ }
162
+
163
+ /**
164
+ * @classdesc This class implements an interface of the channel item
165
+ */
166
+ export class TChnAliasItem {
167
+ /**
168
+ * Creates a new alias element
169
+ */
170
+ static create(obj: IChannelRecord): TChnAliasItem | null;
171
+ /**
172
+ * Contains a channel ID
173
+ */
174
+ get id(): string;
175
+ set id(value: string);
176
+ /**
177
+ * Contains a channel alias
178
+ */
179
+ get alias(): string;
180
+ set alias(value: string);
181
+ /**
182
+ * Contains a list of a name records
183
+ */
184
+ get names(): TChnNamesList;
185
+ /**
186
+ * Contains an instance status
187
+ */
188
+ get status(): string;
189
+ /**
190
+ * Sets a channel ID
191
+ * @see valueToIDString
192
+ */
193
+ setID(value: string): boolean;
194
+ /**
195
+ * Sets a channel alias
196
+ * @see valueToIDString
197
+ */
198
+ setAlias(value: string): boolean;
199
+ /**
200
+ * Returns a name record
201
+ * @deprecated
202
+ * @see TChnNamesList.getItem
203
+ * @todo [from v0.0.6] make obsolete
204
+ */
205
+ getName(value: number): TChnNameRecord | null;
206
+ /**
207
+ * Adds a new name record
208
+ * @deprecated
209
+ * @see TChnNamesList.addItem
210
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.addItem` instead.
211
+ */
212
+ addName(data: any): boolean;
213
+ /**
214
+ * Loads a list of a new name records
215
+ * @deprecated
216
+ * @see TChnNamesList.loadItems
217
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.loadItems` instead.
218
+ */
219
+ loadNames(...args: [list: any, opt?: boolean]): number;
220
+ /**
221
+ * Sets item status to enabled
222
+ */
223
+ enable(): void;
224
+ /**
225
+ * Sets item status to disabled
226
+ */
227
+ disable(): void;
228
+ /**
229
+ * Sets item status to active/running
230
+ */
231
+ up(): void;
232
+ /**
233
+ * Sets item status to inactive/stopped
234
+ */
235
+ down(): void;
236
+ /**
237
+ * Sets item status
238
+ */
239
+ setStatus(value: string): boolean;
240
+ /**
241
+ * Provides an interface to an instance representation for JSON.stringify()
242
+ */
243
+ protected toJSON(): IChannelRecord;
244
+ #private;
245
+ }
246
+
247
+ /**
248
+ * @classdesc This class implements an interface of the channel items list
249
+ */
250
+ export class TChnAliasList {
251
+ /**
252
+ * Contains a quantity of the elements
253
+ */
254
+ get count(): number;
255
+ /**
256
+ * Returns a flag whether a list is empty or not
257
+ */
258
+ isEmpty(): boolean;
259
+ /**
260
+ * Returns a flag whether a list has any members
261
+ */
262
+ isNotEmpty(): boolean;
263
+ /**
264
+ * Checks whether a given value is an index and fits an index range
265
+ * within the instance
266
+ */
267
+ chkIndex(value: any): boolean;
268
+ /**
269
+ * Searches an index of an element by its ID
270
+ * @see valueToIDString
271
+ */
272
+ searchIndexByID(value: string): number;
273
+ /**
274
+ * Returns an alias element by its index
275
+ */
276
+ getItem(value: number): TChnAliasItem | null;
277
+ /**
278
+ * Returns an alias element by its ID
279
+ */
280
+ getItemByID(value: string): TChnAliasItem | null;
281
+ /**
282
+ * Adds an alias element
283
+ */
284
+ addItem(obj: IChannelRecord): number;
285
+ /**
286
+ * Tries to delete an element addressed by a given index
287
+ */
288
+ delItem(value: number): boolean;
289
+ /**
290
+ * Loads a list of a new alias elements
291
+ */
292
+ loadItems(list: IChannelRecord[], opt?: boolean): number;
293
+ /**
294
+ * Removes all of the instance members
295
+ */
296
+ clear(): void;
297
+ /**
298
+ * Calls given function for each alias element
299
+ */
300
+ forEach(cb: forEachProcEx): void;
301
+ /**
302
+ * Returns an array of a name records picked up by a given function
303
+ */
304
+ filter(cb: cbArrECheck): TChnAliasItem[];
305
+ [Symbol.iterator](): {
306
+ next: () => {
307
+ done: boolean;
308
+ value: TChnAliasItem | null;
309
+ } | {
310
+ done: boolean;
311
+ value?: undefined;
312
+ };
313
+ return(): {
314
+ done: boolean;
315
+ };
316
+ };
317
+ #private;
318
+ }
@@ -1,4 +1,4 @@
1
- // [v0.1.047-20260120]
1
+ // [v0.1.050-20260130]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -41,6 +41,15 @@ function convertLangTextValueToString(data, opt) {
41
41
  * (* constant definitions *)
42
42
  */
43
43
 
44
+ /**
45
+ * Defines an object for storing a channel data
46
+ * @typedef {Object} IChannelRecord
47
+ * @property {string} id - channel ID
48
+ * @property {string} alias - target ID
49
+ * @property {any[]} name - list of a channel names
50
+ * @property {string} status - channel status
51
+ */
52
+
44
53
  /***
45
54
  * (* function definitions *)
46
55
  */
@@ -490,6 +499,7 @@ class TChnAliasItem {
490
499
  * @returns {?TChnNameRecord}
491
500
  * @deprecated
492
501
  * @see TChnNamesList.getItem
502
+ * @todo [from v0.0.6] make obsolete
493
503
  */
494
504
  getName(value) {
495
505
  return this.#_names.getItem(value);
@@ -499,7 +509,9 @@ class TChnAliasItem {
499
509
  * Adds a new name record
500
510
  * @param {any} data - a name record
501
511
  * @returns {boolean}
512
+ * @deprecated
502
513
  * @see TChnNamesList.addItem
514
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.addItem` instead.
503
515
  */
504
516
  addName(data) {
505
517
  return this.#_names.addItem(data);
@@ -510,7 +522,9 @@ class TChnAliasItem {
510
522
  * @param {array} list - a list of an elements
511
523
  * @param {boolean} [opt=true] - defines whether to clear the list before load a new one
512
524
  * @returns {number}
525
+ * @deprecated
513
526
  * @see TChnNamesList.loadItems
527
+ * @todo [from v0.0.7] deprecated. Use `TChnNamesList.loadItems` instead.
514
528
  */
515
529
  loadNames(...args) {
516
530
  return this.#_names.loadItems(...args);
@@ -582,7 +596,7 @@ class TChnAliasItem {
582
596
 
583
597
  /**
584
598
  * Provides an interface to an instance representation for JSON.stringify()
585
- * @returns {Object}
599
+ * @returns {IChannelRecord}
586
600
  * @protected
587
601
  */
588
602
  toJSON() {
@@ -597,7 +611,7 @@ class TChnAliasItem {
597
611
 
598
612
  /**
599
613
  * Creates a new alias element
600
- * @param {object} obj - an init data
614
+ * @param {IChannelRecord} obj - an init data
601
615
  * @returns {?TChnAliasItem}
602
616
  * @static
603
617
  */
@@ -726,7 +740,7 @@ class TChnAliasList {
726
740
 
727
741
  /**
728
742
  * Adds an alias element
729
- * @param {object} obj - an element to be added
743
+ * @param {IChannelRecord} obj - an element to be added
730
744
  * @returns {number}
731
745
  */
732
746
  addItem(obj) {
@@ -734,7 +748,7 @@ class TChnAliasList {
734
748
  let index = -1;
735
749
  if (item !== null) {
736
750
  const id = valueToIDString(item.id);
737
- index = this.searchIndexByID(id);
751
+ if (id != null) index = this.searchIndexByID(id);
738
752
  if (index === -1) {
739
753
  index = this.count;
740
754
  this.#_items.push(item);
@@ -758,7 +772,7 @@ class TChnAliasList {
758
772
 
759
773
  /**
760
774
  * Loads a list of a new alias elements
761
- * @param {array} list - a list of an elements
775
+ * @param {IChannelRecord[]} list - a list of an elements
762
776
  * @param {boolean} [opt=true] - defines whether to clear the list before load a new one
763
777
  * @returns {number}
764
778
  */
@@ -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.049-20260130]
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 {
@@ -63,17 +63,33 @@ function loadAliasFromFileSync(src, opt) {
63
63
  * Saves an alias to a file
64
64
  * @function saveAliasToFileSync
65
65
  * @param {string} src - a path to some file
66
- * @param {Array} content - content
66
+ * @param {(object|object[])} content - content
67
67
  * @param {any} [opt] - <reserved>
68
68
  * @returns {fsoDescr}
69
69
  * @see {@link saveJSONToFileSync} for details of an `opt` param
70
70
  */
71
71
  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;
72
+ /** @type {fsoDescr} */
73
+ let data = {
74
+ isERR: false,
75
+ errCode: 0,
76
+ errEvent: '',
77
+ errMsg: '',
78
+ source: '',
79
+ content: '',
80
+ };
81
+ if (isArray(content) || isObject(content)) {
82
+ //const obj = isArray(content) ? content : null;
83
+ //===
84
+ data = saveJSONToFileSync(src, content, opt);
85
+ } else {
86
+ if (content !== undefined) {
87
+ // // TODO: define `errCode` and `errMsg`
88
+ data.isERR = true;
89
+ data.errEvent = 'ERR_BAD_CONTENT';
90
+ };
91
+ };
92
+ return data;
77
93
  };
78
94
 
79
95
  /***
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.7",
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",
@@ -34,7 +34,7 @@
34
34
  "@ygracs/bsfoc-lib-js": "~0.3.3"
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",