@ygracs/chn-alias-list 0.0.6 → 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 CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  #### *v0.0.6*
2
9
 
3
10
  Pre-release version.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024-2025 Yuri Grachev
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.0.001-20240620]
1
+ // [v0.1.003-20260120]
2
2
 
3
3
  // === module init block ===
4
4
 
5
- const lib = require('#lib/chn-alias-list.js');
5
+ const lib = require('./lib/chn-alias-list');
6
6
 
7
- // === module extra block (helper functions) ===
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
+ }
@@ -1,4 +1,4 @@
1
- // [v0.1.045-20250820]
1
+ // [v0.1.047-20260120]
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
  /***
@@ -49,64 +45,6 @@ function convertLangTextValueToString(data, opt) {
49
45
  * (* function definitions *)
50
46
  */
51
47
 
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
- /**
71
- * Loads an alias from a file
72
- * @function loadAliasFromFileSync
73
- * @param {string} src - a path to some file
74
- * @param {any} [opt] - <reserved>
75
- * @returns {RVAL_loadaliasff}
76
- * @see {@link loadJSONFromFileSync} for details of an `opt` param
77
- */
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
-
93
- /**
94
- * Saves an alias to a file
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
101
- */
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
-
110
48
  /***
111
49
  * (* class definitions *)
112
50
  */
@@ -338,6 +276,7 @@ class TChnNamesList {
338
276
 
339
277
  /**
340
278
  * Returns a name record
279
+ * @since 0.0.5
341
280
  * @param {number} value - an element index
342
281
  * @returns {?TChnNameRecord}
343
282
  */
@@ -356,6 +295,7 @@ class TChnNamesList {
356
295
 
357
296
  /**
358
297
  * Adds a new name record to a list members
298
+ * @since 0.0.5
359
299
  * @param {any} data - a value of a name record
360
300
  * @returns {boolean}
361
301
  */
@@ -378,6 +318,7 @@ class TChnNamesList {
378
318
 
379
319
  /**
380
320
  * Tries to delete a name record addressed by a given index
321
+ * @since 0.0.5
381
322
  * @param {number} value - an element index
382
323
  * @returns {boolean}
383
324
  */
@@ -398,6 +339,7 @@ class TChnNamesList {
398
339
 
399
340
  /**
400
341
  * Loads a new name records
342
+ * @since 0.0.5
401
343
  * @param {any} list - an element or a list of an elements
402
344
  * @param {boolean} [opt=true] - defines whether to clear the list before load a new one
403
345
  * @returns {number}
@@ -860,9 +802,6 @@ class TChnAliasList {
860
802
 
861
803
  // === module exports block ===
862
804
 
863
- module.exports.loadAliasFromFileSync = loadAliasFromFileSync;
864
- module.exports.saveAliasToFileSync = saveAliasToFileSync;
865
-
866
805
  module.exports.TChnNameRecord = TChnNameRecord;
867
806
  module.exports.TChnNamesList = TChnNamesList;
868
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.6",
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.1",
29
- "@ygracs/bsfoc-lib-js": "^0.3.0"
33
+ "@cntwg/file-helper": "^0.0.3",
34
+ "@ygracs/bsfoc-lib-js": "~0.3.3"
30
35
  },
31
36
  "devDependencies": {
32
- "jest": "^30.0.5",
33
- "jsdoc-to-markdown": "^9.1.2",
34
- "minimist": "^1.2.8"
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
  }