@ygracs/chn-alias-list 0.0.6 → 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 +11 -0
- package/LICENSE +1 -1
- package/doc/chn-alias-list.md +48 -18
- package/index.d.ts +24 -0
- package/index.js +21 -4
- package/lib/chn-alias-list.d.ts +318 -0
- package/lib/chn-alias-list.js +23 -70
- package/lib/file-helper-ext.d.ts +28 -0
- package/lib/file-helper-ext.js +102 -0
- package/package.json +15 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
#### *v0.0.7*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - update `chn-alias-list.md`;
|
|
6
|
+
> - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
|
|
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.
|
|
11
|
+
|
|
1
12
|
#### *v0.0.6*
|
|
2
13
|
|
|
3
14
|
Pre-release version.
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024-
|
|
3
|
+
Copyright (c) 2024-2026 Yuri Grachev
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/doc/chn-alias-list.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
>|***rev.*:**|0.0.
|
|
2
|
+
>|***rev.*:**|0.0.8|
|
|
3
3
|
>|:---|---:|
|
|
4
|
-
>|date:|
|
|
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
|
-
| `
|
|
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
|
-
| `
|
|
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
|
-
|
|
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
|
-
|
|
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` | `
|
|
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` | `
|
|
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` | `
|
|
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])** => `
|
|
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` | `
|
|
522
|
+
| `content` | `object` or `object[]` | --- | a content to save |
|
|
493
523
|
| `opt` | `any` | --- | <*reserved*> |
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
};
|
package/index.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
// [v0.
|
|
1
|
+
// [v0.1.003-20260120]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
|
-
const lib = require('
|
|
5
|
+
const lib = require('./lib/chn-alias-list');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const fileHelper = require('./lib/file-helper-ext');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
// * import types definitions *
|
|
11
|
+
fsoDescr,
|
|
12
|
+
} = require('@cntwg/file-helper');
|
|
13
|
+
|
|
14
|
+
// === module inner block ===
|
|
8
15
|
|
|
9
16
|
// === module main block ===
|
|
10
17
|
|
|
11
18
|
// === module exports block ===
|
|
12
19
|
|
|
13
|
-
module.exports = lib;
|
|
20
|
+
module.exports.TChnNameRecord = lib.TChnNameRecord;
|
|
21
|
+
module.exports.TChnNamesList = lib.TChnNamesList;
|
|
22
|
+
module.exports.TChnAliasItem = lib.TChnAliasItem;
|
|
23
|
+
module.exports.TChnAliasList = lib.TChnAliasList;
|
|
24
|
+
|
|
25
|
+
module.exports.loadAliasFromFileSync = fileHelper.loadAliasFromFileSync;
|
|
26
|
+
module.exports.saveAliasToFileSync = fileHelper.saveAliasToFileSync;
|
|
27
|
+
|
|
28
|
+
// * export types definitions *
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
module.exports.fsoDescr = fsoDescr;
|
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
}
|
package/lib/chn-alias-list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.050-20260130]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -8,10 +8,6 @@ const {
|
|
|
8
8
|
readAsString,
|
|
9
9
|
} = require('@ygracs/bsfoc-lib-js');
|
|
10
10
|
|
|
11
|
-
const {
|
|
12
|
-
loadJSONFromFileSync, saveJSONToFileSync,
|
|
13
|
-
} = require('@cntwg/file-helper');
|
|
14
|
-
|
|
15
11
|
// === module inner block ===
|
|
16
12
|
|
|
17
13
|
/***
|
|
@@ -45,67 +41,18 @@ function convertLangTextValueToString(data, opt) {
|
|
|
45
41
|
* (* constant definitions *)
|
|
46
42
|
*/
|
|
47
43
|
|
|
48
|
-
/***
|
|
49
|
-
* (* function definitions *)
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* An 'FS'-ops descriptor.
|
|
54
|
-
* @typedef {Object} fsoDescr
|
|
55
|
-
* @property {boolean} isERR - flag
|
|
56
|
-
* @property {number} [errCode] - error code
|
|
57
|
-
* @property {string} errEvent - event ID
|
|
58
|
-
* @property {string} [errMsg] - event message
|
|
59
|
-
* @property {string} [source] - path to file
|
|
60
|
-
* @property {any} [content] - file content
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* A result of `loadAliasFromFile...`
|
|
65
|
-
* @typedef {Object} RVAL_loadaliasff
|
|
66
|
-
* @property {fsoDescr} descr - ops description
|
|
67
|
-
* @property {(null|TChnAliasItem|TChnAliasList)} result - loaded content
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
44
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
76
|
-
* @
|
|
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
|
|
77
51
|
*/
|
|
78
|
-
function loadAliasFromFileSync(src, opt) {
|
|
79
|
-
let { descr, obj } = loadJSONFromFileSync(src, opt);
|
|
80
|
-
let result = null;
|
|
81
|
-
if (!descr.isERR) {
|
|
82
|
-
if (isArray(obj)) {
|
|
83
|
-
result = new TChnAliasList();
|
|
84
|
-
let count = result.loadItems(obj);
|
|
85
|
-
// // TODO: [?]
|
|
86
|
-
} else {
|
|
87
|
-
result = TChnAliasItem.create(obj);
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
return { descr, result };
|
|
91
|
-
};
|
|
92
52
|
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
* @function saveAliasToFileSync
|
|
96
|
-
* @param {string} src - a path to some file
|
|
97
|
-
* @param {Array} content - content
|
|
98
|
-
* @param {any} [opt] - <reserved>
|
|
99
|
-
* @returns {fsoDescr}
|
|
100
|
-
* @see {@link saveJSONToFileSync} for details of an `opt` param
|
|
53
|
+
/***
|
|
54
|
+
* (* function definitions *)
|
|
101
55
|
*/
|
|
102
|
-
function saveAliasToFileSync(src, content, opt) {
|
|
103
|
-
const obj = isArray(content) ? content : null;
|
|
104
|
-
let result = null;
|
|
105
|
-
//===
|
|
106
|
-
result = saveJSONToFileSync(src, obj, opt);
|
|
107
|
-
return result;
|
|
108
|
-
};
|
|
109
56
|
|
|
110
57
|
/***
|
|
111
58
|
* (* class definitions *)
|
|
@@ -338,6 +285,7 @@ class TChnNamesList {
|
|
|
338
285
|
|
|
339
286
|
/**
|
|
340
287
|
* Returns a name record
|
|
288
|
+
* @since 0.0.5
|
|
341
289
|
* @param {number} value - an element index
|
|
342
290
|
* @returns {?TChnNameRecord}
|
|
343
291
|
*/
|
|
@@ -356,6 +304,7 @@ class TChnNamesList {
|
|
|
356
304
|
|
|
357
305
|
/**
|
|
358
306
|
* Adds a new name record to a list members
|
|
307
|
+
* @since 0.0.5
|
|
359
308
|
* @param {any} data - a value of a name record
|
|
360
309
|
* @returns {boolean}
|
|
361
310
|
*/
|
|
@@ -378,6 +327,7 @@ class TChnNamesList {
|
|
|
378
327
|
|
|
379
328
|
/**
|
|
380
329
|
* Tries to delete a name record addressed by a given index
|
|
330
|
+
* @since 0.0.5
|
|
381
331
|
* @param {number} value - an element index
|
|
382
332
|
* @returns {boolean}
|
|
383
333
|
*/
|
|
@@ -398,6 +348,7 @@ class TChnNamesList {
|
|
|
398
348
|
|
|
399
349
|
/**
|
|
400
350
|
* Loads a new name records
|
|
351
|
+
* @since 0.0.5
|
|
401
352
|
* @param {any} list - an element or a list of an elements
|
|
402
353
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
403
354
|
* @returns {number}
|
|
@@ -548,6 +499,7 @@ class TChnAliasItem {
|
|
|
548
499
|
* @returns {?TChnNameRecord}
|
|
549
500
|
* @deprecated
|
|
550
501
|
* @see TChnNamesList.getItem
|
|
502
|
+
* @todo [from v0.0.6] make obsolete
|
|
551
503
|
*/
|
|
552
504
|
getName(value) {
|
|
553
505
|
return this.#_names.getItem(value);
|
|
@@ -557,7 +509,9 @@ class TChnAliasItem {
|
|
|
557
509
|
* Adds a new name record
|
|
558
510
|
* @param {any} data - a name record
|
|
559
511
|
* @returns {boolean}
|
|
512
|
+
* @deprecated
|
|
560
513
|
* @see TChnNamesList.addItem
|
|
514
|
+
* @todo [from v0.0.7] deprecated. Use `TChnNamesList.addItem` instead.
|
|
561
515
|
*/
|
|
562
516
|
addName(data) {
|
|
563
517
|
return this.#_names.addItem(data);
|
|
@@ -568,7 +522,9 @@ class TChnAliasItem {
|
|
|
568
522
|
* @param {array} list - a list of an elements
|
|
569
523
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
570
524
|
* @returns {number}
|
|
525
|
+
* @deprecated
|
|
571
526
|
* @see TChnNamesList.loadItems
|
|
527
|
+
* @todo [from v0.0.7] deprecated. Use `TChnNamesList.loadItems` instead.
|
|
572
528
|
*/
|
|
573
529
|
loadNames(...args) {
|
|
574
530
|
return this.#_names.loadItems(...args);
|
|
@@ -640,7 +596,7 @@ class TChnAliasItem {
|
|
|
640
596
|
|
|
641
597
|
/**
|
|
642
598
|
* Provides an interface to an instance representation for JSON.stringify()
|
|
643
|
-
* @returns {
|
|
599
|
+
* @returns {IChannelRecord}
|
|
644
600
|
* @protected
|
|
645
601
|
*/
|
|
646
602
|
toJSON() {
|
|
@@ -655,7 +611,7 @@ class TChnAliasItem {
|
|
|
655
611
|
|
|
656
612
|
/**
|
|
657
613
|
* Creates a new alias element
|
|
658
|
-
* @param {
|
|
614
|
+
* @param {IChannelRecord} obj - an init data
|
|
659
615
|
* @returns {?TChnAliasItem}
|
|
660
616
|
* @static
|
|
661
617
|
*/
|
|
@@ -784,7 +740,7 @@ class TChnAliasList {
|
|
|
784
740
|
|
|
785
741
|
/**
|
|
786
742
|
* Adds an alias element
|
|
787
|
-
* @param {
|
|
743
|
+
* @param {IChannelRecord} obj - an element to be added
|
|
788
744
|
* @returns {number}
|
|
789
745
|
*/
|
|
790
746
|
addItem(obj) {
|
|
@@ -792,7 +748,7 @@ class TChnAliasList {
|
|
|
792
748
|
let index = -1;
|
|
793
749
|
if (item !== null) {
|
|
794
750
|
const id = valueToIDString(item.id);
|
|
795
|
-
index = this.searchIndexByID(id);
|
|
751
|
+
if (id != null) index = this.searchIndexByID(id);
|
|
796
752
|
if (index === -1) {
|
|
797
753
|
index = this.count;
|
|
798
754
|
this.#_items.push(item);
|
|
@@ -816,7 +772,7 @@ class TChnAliasList {
|
|
|
816
772
|
|
|
817
773
|
/**
|
|
818
774
|
* Loads a list of a new alias elements
|
|
819
|
-
* @param {
|
|
775
|
+
* @param {IChannelRecord[]} list - a list of an elements
|
|
820
776
|
* @param {boolean} [opt=true] - defines whether to clear the list before load a new one
|
|
821
777
|
* @returns {number}
|
|
822
778
|
*/
|
|
@@ -860,9 +816,6 @@ class TChnAliasList {
|
|
|
860
816
|
|
|
861
817
|
// === module exports block ===
|
|
862
818
|
|
|
863
|
-
module.exports.loadAliasFromFileSync = loadAliasFromFileSync;
|
|
864
|
-
module.exports.saveAliasToFileSync = saveAliasToFileSync;
|
|
865
|
-
|
|
866
819
|
module.exports.TChnNameRecord = TChnNameRecord;
|
|
867
820
|
module.exports.TChnNamesList = TChnNamesList;
|
|
868
821
|
module.exports.TChnAliasItem = TChnAliasItem;
|
|
@@ -0,0 +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: 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";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// [v0.1.049-20260130]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isArray, isObject,
|
|
7
|
+
} = require('@ygracs/bsfoc-lib-js');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
loadJSONFromFileSync, saveJSONToFileSync,
|
|
11
|
+
// * import types definitions *
|
|
12
|
+
/** @see fsoDescr from `@cntwg/file-helper` */
|
|
13
|
+
fsoDescr,
|
|
14
|
+
} = require('@cntwg/file-helper');
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
TChnAliasItem, TChnAliasList,
|
|
18
|
+
} = require('./chn-alias-list');
|
|
19
|
+
|
|
20
|
+
// === module inner block ===
|
|
21
|
+
|
|
22
|
+
// === module main block ===
|
|
23
|
+
|
|
24
|
+
/***
|
|
25
|
+
* (* constant definitions *)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/***
|
|
29
|
+
* (* function definitions *)
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A result of `loadAliasFromFile...`
|
|
34
|
+
* @typedef {Object} RVAL_loadaliasff
|
|
35
|
+
* @property {fsoDescr} descr - ops description
|
|
36
|
+
* @property {(null|TChnAliasItem|TChnAliasList)} result - loaded content
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Loads an alias from a file
|
|
41
|
+
* @function loadAliasFromFileSync
|
|
42
|
+
* @param {string} src - a path to some file
|
|
43
|
+
* @param {any} [opt] - <reserved>
|
|
44
|
+
* @returns {RVAL_loadaliasff}
|
|
45
|
+
* @see {@link loadJSONFromFileSync} for details of an `opt` param
|
|
46
|
+
*/
|
|
47
|
+
function loadAliasFromFileSync(src, opt) {
|
|
48
|
+
let { descr, obj } = loadJSONFromFileSync(src, opt);
|
|
49
|
+
let result = null;
|
|
50
|
+
if (!descr.isERR) {
|
|
51
|
+
if (isArray(obj)) {
|
|
52
|
+
result = new TChnAliasList();
|
|
53
|
+
let count = result.loadItems(obj);
|
|
54
|
+
// // TODO: [?]
|
|
55
|
+
} else {
|
|
56
|
+
result = TChnAliasItem.create(obj);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
return { descr, result };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Saves an alias to a file
|
|
64
|
+
* @function saveAliasToFileSync
|
|
65
|
+
* @param {string} src - a path to some file
|
|
66
|
+
* @param {(object|object[])} content - content
|
|
67
|
+
* @param {any} [opt] - <reserved>
|
|
68
|
+
* @returns {fsoDescr}
|
|
69
|
+
* @see {@link saveJSONToFileSync} for details of an `opt` param
|
|
70
|
+
*/
|
|
71
|
+
function saveAliasToFileSync(src, content, opt) {
|
|
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;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/***
|
|
96
|
+
* (* class definitions *)
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
// === module exports block ===
|
|
100
|
+
|
|
101
|
+
module.exports.loadAliasFromFileSync = loadAliasFromFileSync;
|
|
102
|
+
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.
|
|
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",
|
|
@@ -9,28 +9,35 @@
|
|
|
9
9
|
"url": "git+https://gitlab.com/ygracs/chn-alias-list.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "./index.js",
|
|
12
|
+
"types": "./index.d.ts",
|
|
12
13
|
"files": [
|
|
13
|
-
"doc
|
|
14
|
+
"doc/*.md",
|
|
14
15
|
"lib/chn-alias-list.js",
|
|
16
|
+
"lib/file-helper-ext.js",
|
|
17
|
+
"lib/*.d.ts",
|
|
15
18
|
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
16
20
|
"CHANGELOG.md"
|
|
17
21
|
],
|
|
18
22
|
"scripts": {
|
|
19
23
|
"test": "jest",
|
|
20
24
|
"build-doc-md": "jsdoc2md",
|
|
21
|
-
"build-doc-html": "jsdoc"
|
|
25
|
+
"build-doc-html": "jsdoc",
|
|
26
|
+
"gen-dts": "npx -p typescript tsc"
|
|
22
27
|
},
|
|
23
28
|
"imports": {
|
|
24
29
|
"#lib/*": "./lib/*",
|
|
25
30
|
"#test-dir/*": "./__test__/*"
|
|
26
31
|
},
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"@cntwg/file-helper": "^0.0.
|
|
29
|
-
"@ygracs/bsfoc-lib-js": "
|
|
33
|
+
"@cntwg/file-helper": "^0.0.3",
|
|
34
|
+
"@ygracs/bsfoc-lib-js": "~0.3.3"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
37
|
+
"@ygracs/test-helper": "~0.0.2-b",
|
|
38
|
+
"jest": "^30.2.0",
|
|
39
|
+
"jsdoc-to-markdown": "^9.1.3",
|
|
40
|
+
"minimist": "^1.2.8",
|
|
41
|
+
"typescript": "~5.9.3"
|
|
35
42
|
}
|
|
36
43
|
}
|