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