@cntwg/xml-lib-js 0.0.35 → 0.0.37-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,12 @@
1
+ #### *v0.0.3x*
2
+
3
+ Pre-release version.
4
+
5
+ > - update `xmldoc-lib.md`;
6
+ > - update dependency on `@ygracs/xml-js6` module to v0.0.6-b;
7
+ > - update dependency on `@cntwg/file-helper` module to v0.0.3;
8
+ > - update dependency on `@ygracs/bsfoc-lib-js` module to v0.3.3;
9
+
1
10
  #### *v0.0.35*
2
11
 
3
12
  Pre-release version.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019-2025 Yuri Grachev
3
+ Copyright (c) 2019-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/xmldoc-lib.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.1.41|
1
+ >|***rev.*:**|0.1.43|
2
2
  >|:---|---:|
3
- >|date:|2025-08-23|
3
+ >|date:|2026-01-18|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -20,9 +20,9 @@ This descriptor is an `object` that describes a status for an operation with som
20
20
  | `isERR` | `boolean` | no | a flag which indicates whether an error was happen |
21
21
  | `errCode` | `number` | yes | an error code |
22
22
  | `errEvent` | `string` | no | an error event identifier |
23
- | `errMsg` | `string` | no | an error message |
24
- | `source` | `string` | no | path to a file |
25
- | `content` | `any` | no | content |
23
+ | `errMsg` | `string` | yes | an error message |
24
+ | `source` | `string` | yes | path to a file |
25
+ | `content` | `any` | yes | content |
26
26
 
27
27
  ## Module constants
28
28
 
@@ -702,7 +702,7 @@ If `object` parameter is not a type of `object` or not given a `TypeError` throw
702
702
 
703
703
  #### class methods (*special*)
704
704
 
705
- ##### **init()** => `boolean`
705
+ ##### **init()** => `void`
706
706
 
707
707
  This method initializes an element with a default values.
708
708
 
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import xObj = require("@ygracs/xobj-lib-js");
2
+ import xmlHelper = require("./lib/xml-helper");
3
+ import xmldoc = require("./lib/xmldoc-lib");
4
+
5
+ import {
6
+ readAsTagName,
7
+ readAsAttrName,
8
+ readAsAttrValue,
9
+ valueToElementID,
10
+ } from "./lib/xml-base";
11
+
12
+ import {
13
+ XML_DEF_PARSE_OPTIONS,
14
+ XML_DEF_ROOT_ETAG_NAME, XML_LANG_ATTR_TNAME,
15
+ TXmlContentParseOptions,
16
+ TXmlAttributesMapper,
17
+ TXmlElementController, TXmlElementsListController,
18
+ TXmlContentDeclaration,
19
+ TXmlContentRootElement,
20
+ TXmlContentContainer,
21
+ } from "./lib/xmldoc-lib";
22
+
23
+ export {
24
+ xObj, xmlHelper, xmldoc as xmlDoc,
25
+ readAsTagName,
26
+ readAsAttrName,
27
+ readAsAttrValue,
28
+ valueToElementID,
29
+ XML_DEF_PARSE_OPTIONS,
30
+ XML_DEF_ROOT_ETAG_NAME, XML_LANG_ATTR_TNAME,
31
+ TXmlContentParseOptions,
32
+ TXmlAttributesMapper,
33
+ TXmlElementController, TXmlElementsListController,
34
+ TXmlContentDeclaration,
35
+ TXmlContentRootElement,
36
+ TXmlContentContainer,
37
+ };
38
+
39
+ import type { fsoDescr } from '@cntwg/file-helper';
40
+ export type { fsoDescr };
package/index.js CHANGED
@@ -7,6 +7,11 @@ const xmldoc = require('./lib/xmldoc-lib');
7
7
  const xmlHelper = require('./lib/xml-helper');
8
8
  const xmlBase = require('./lib/xml-base');
9
9
 
10
+ const {
11
+ // * import types definitions *
12
+ fsoDescr,
13
+ } = require('@cntwg/file-helper');
14
+
10
15
  // === module inner block ===
11
16
 
12
17
  // === module main block ===
@@ -34,3 +39,7 @@ module.exports.TXmlElementsListController = xmldoc.TXmlElementsListController;
34
39
  module.exports.TXmlContentDeclaration = xmldoc.TXmlContentDeclaration;
35
40
  module.exports.TXmlContentRootElement = xmldoc.TXmlContentRootElement;
36
41
  module.exports.TXmlContentContainer = xmldoc.TXmlContentContainer;
42
+
43
+ // * export types definitions *
44
+ // @ts-ignore
45
+ module.exports.fsoDescr = fsoDescr;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Tries to convert a given value to a valid tag name of an XML-element.
3
+ * @since v0.0.28
4
+ */
5
+ export function readAsTagName(value: any): string;
6
+ /**
7
+ * Tries to convert a given value to a valid name of an XML-attribute.
8
+ * @since v0.0.28
9
+ */
10
+ export function readAsAttrName(value: any): string;
11
+ /**
12
+ * Tries to convert a given value to a valid "attribute value".
13
+ * @since v0.0.35
14
+ */
15
+ export function readAsAttrValue(value: any): string | null;
16
+ /**
17
+ * Tries to convert a given value to a valid identifier
18
+ * suitable as a value for an "ID-attribute" of an XML-element.
19
+ * @since v0.0.28
20
+ * @see valueToIDString
21
+ */
22
+ export function valueToElementID(value: any): string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Tries to get a child element.
3
+ */
4
+ export function getChildByPath(obj: TXmlElementController, chain: string[]): TXmlElementController | null;
5
+ /**
6
+ * Tries to get a child element.
7
+ */
8
+ export function addChildByPath(obj: TXmlElementController, chain: string[]): TXmlElementController | null;
9
+ /**
10
+ * Reads a text values from a given XML-element.
11
+ */
12
+ export function extractTextValues(obj: TXmlElementController | TXmlElementsListController): string[];
13
+ /**
14
+ * Reads a text values with a `lang` attribute from a given XML-element.
15
+ */
16
+ export function extractTextValuesLn(obj: TXmlElementController | TXmlElementsListController): any[];
17
+ import { TXmlElementController } from "./xmldoc-lib";
18
+ import { TXmlElementsListController } from "./xmldoc-lib";
@@ -0,0 +1,483 @@
1
+ import {
2
+ DEF_XML_PARSE_OPTIONS,
3
+ } from "@ygracs/xobj-lib-js";
4
+ /**
5
+ * An XML-element controller settings.
6
+ */
7
+ export type OPT_xmlelemsett = {
8
+ /**
9
+ * - parser options
10
+ */
11
+ parseOptions?: InstanceType<typeof TXmlContentParseOptions>;
12
+ /**
13
+ * - mode flag
14
+ */
15
+ proxyModeEnable?: boolean;
16
+ /**
17
+ * - <reserved>
18
+ */
19
+ isNullItemsAllowed?: boolean;
20
+ };
21
+ /**
22
+ * An XML-element controller configuration.
23
+ */
24
+ export type XMLElementConfig = {
25
+ /**
26
+ * - parser options
27
+ */
28
+ parseOptions: InstanceType<typeof TXmlContentParseOptions>;
29
+ /**
30
+ * - mode flag
31
+ */
32
+ proxyModeEnable?: boolean;
33
+ /**
34
+ * - <reserved>
35
+ */
36
+ isNullItemsAllowed?: boolean;
37
+ };
38
+ /**
39
+ * An XML-content container settings.
40
+ */
41
+ export type OPT_xmlcontsett = {
42
+ /**
43
+ * - parser options
44
+ */
45
+ parseOptions?: InstanceType<typeof TXmlContentParseOptions>;
46
+ /**
47
+ * - mode flag
48
+ */
49
+ proxyModeEnable?: boolean;
50
+ /**
51
+ * - <reserved>
52
+ */
53
+ isNullItemsAllowed?: boolean;
54
+ /**
55
+ * - tag name of the root element
56
+ */
57
+ rootETagName?: string;
58
+ /**
59
+ * - mode flag
60
+ */
61
+ autoBindRoot?: boolean;
62
+ };
63
+ /**
64
+ * An XML-content container settings.
65
+ */
66
+ export type XMLContainerSettings = {
67
+ /**
68
+ * - parser options
69
+ */
70
+ parseOptions: InstanceType<typeof TXmlContentParseOptions>;
71
+ /**
72
+ * - mode flag
73
+ */
74
+ proxyModeEnable?: boolean;
75
+ /**
76
+ * - <reserved>
77
+ */
78
+ isNullItemsAllowed?: boolean;
79
+ /**
80
+ * - tag name of the root element
81
+ */
82
+ rootETagName: string;
83
+ /**
84
+ * - mode flag
85
+ */
86
+ autoBindRoot?: boolean;
87
+ };
88
+
89
+ export const XML_DEF_PARSE_OPTIONS: typeof DEF_XML_PARSE_OPTIONS;
90
+ export const XML_DEF_ROOT_ETAG_NAME: "root";
91
+ export const XML_LANG_ATTR_TNAME: "lang";
92
+
93
+ /**
94
+ * Settings for the list load ops
95
+ */
96
+ export type OPT_ELC_loaditems = {
97
+ /** - indicates whether to clear the list before load */
98
+ useClear?: boolean;
99
+ }
100
+
101
+ /**
102
+ * @classdesc This class implements an attributes mapper instance
103
+ */
104
+ export class TXmlAttributesMapper {
105
+ /**
106
+ * Creates an attributes mapper instance
107
+ * @throws {TypeError}
108
+ */
109
+ constructor(obj: object, opt?: OPT_xmlelemsett);
110
+ /**
111
+ * Contains a list of all instance attributes as a `<name>-<value>` pairs
112
+ */
113
+ get entries(): string[][];
114
+ /**
115
+ * Checks whether an attribute exists.
116
+ */
117
+ hasAttribute(name: string): boolean;
118
+ /**
119
+ * Returns an attribute value.
120
+ */
121
+ getAttribute(name: string): string;
122
+ /**
123
+ * Sets an attribute value.
124
+ */
125
+ setAttribute(name: string, value: any): boolean;
126
+ /**
127
+ * Deletes an attribute.
128
+ */
129
+ delAttribute(name: string): boolean;
130
+ /**
131
+ * Renames an attribute.
132
+ * @since v0.0.30
133
+ */
134
+ renameAttribute(name: string, value: string): boolean;
135
+ /**
136
+ * Deletes all attributes.
137
+ */
138
+ clear(): void;
139
+ #private;
140
+ }
141
+
142
+ /**
143
+ * @classdesc This class implements an instance of an element controller
144
+ */
145
+ export class TXmlElementController {
146
+ /**
147
+ * Tries to unwraps a given object.
148
+ */
149
+ protected static __unwrap(item: object): object | null;
150
+ /**
151
+ * Returns a child element.
152
+ * @since v0.0.31
153
+ */
154
+ protected static __getChildRaw(node: TXmlElementController, name: string): any | null;
155
+ /**
156
+ * Adds a new child element.
157
+ * @since v0.0.31
158
+ */
159
+ protected static __addChildRaw(node: TXmlElementController, name: string): any | null;
160
+ /**
161
+ * Sets a child element.
162
+ */
163
+ protected static __setChildRaw(node: TXmlElementController, name: string, obj: object): boolean;
164
+ /**
165
+ * Tries to clean a given object.
166
+ */
167
+ static clear(obj: object): void;
168
+ /**
169
+ * Creates new controller element.
170
+ * @since v0.0.30
171
+ */
172
+ static create(obj: object, opt?: object): TXmlElementController | TXmlElementsListController | null;
173
+ /**
174
+ * Creates an instance of an element controller
175
+ * @throws {TypeError}
176
+ */
177
+ constructor(obj: object, opt?: OPT_xmlelemsett);
178
+ /**
179
+ * Contains an element attribute mapper instance
180
+ */
181
+ get attributes(): TXmlAttributesMapper;
182
+ /**
183
+ * @experimental
184
+ */
185
+ get name(): string;
186
+ /**
187
+ * Contains an element text value
188
+ */
189
+ get textValue(): string;
190
+ set textValue(value: string);
191
+ /**
192
+ * Checks whether an attribute exists.
193
+ * @see TXmlAttributesMapper.hasAttribute
194
+ */
195
+ hasAttribute(name: string): boolean;
196
+ /**
197
+ * Returns an attribute value.
198
+ * @see TXmlAttributesMapper.getAttribute
199
+ */
200
+ getAttribute(name: string): string;
201
+ /**
202
+ * Sets an attribute value.
203
+ * @see TXmlAttributesMapper.setAttribute
204
+ */
205
+ setAttribute(...args: [name: string, value: any]): boolean;
206
+ /**
207
+ * Deletes an attribute.
208
+ * @see TXmlAttributesMapper.delAttribute
209
+ */
210
+ delAttribute(name: string): boolean;
211
+ /**
212
+ * Renames an attribute.
213
+ * @since v0.0.30
214
+ * @see TXmlAttributesMapper.renameAttribute
215
+ */
216
+ renameAttribute(...args: [name: string, value: string]): boolean;
217
+ /**
218
+ * Returns a text value in format of a `[ <lang>, <text> ]` pair.
219
+ */
220
+ getTextValue(): string[];
221
+ /**
222
+ * Sets a text value.
223
+ */
224
+ setTextValue(value: string | string[]): boolean;
225
+ /**
226
+ * Checks whether an element has a child element.
227
+ */
228
+ hasChild(name: string): boolean;
229
+ /**
230
+ * Returns a child element.
231
+ */
232
+ getChild(name: string): TXmlElementController | TXmlElementsListController | null;
233
+ /**
234
+ * Adds a new child element.
235
+ */
236
+ addChild(name: string): TXmlElementController | null;
237
+ /**
238
+ * Deletes a child element.
239
+ */
240
+ delChild(name: string): boolean;
241
+ /**
242
+ * Deletes all child elements and attributes.
243
+ */
244
+ clear(): void;
245
+ /**
246
+ * Loads a element content from a string.
247
+ * @since v0.0.30
248
+ * @throws {Error}
249
+ * @experimental
250
+ */
251
+ loadFromXMLString(xmlString: string): boolean;
252
+ #private;
253
+ }
254
+
255
+ /**
256
+ * @classdesc This class implements an instance of a list controller
257
+ */
258
+ export class TXmlElementsListController {
259
+ /**
260
+ * Returns an element.
261
+ * @since v0.0.34
262
+ */
263
+ protected static __getItemRaw(node: TXmlElementsListController, index: number | string): object | null;
264
+ /**
265
+ * Sets a new element.
266
+ * @since v0.0.34
267
+ */
268
+ protected static __setItemRaw(node: TXmlElementsListController, index: number | string, item: any): boolean;
269
+ /**
270
+ * Creates an instance of a list controller
271
+ * @throws {TypeError}
272
+ */
273
+ constructor(obj: object[], opt?: OPT_xmlelemsett);
274
+ /**
275
+ * Contains a quantity of an elements
276
+ */
277
+ get count(): number;
278
+ /**
279
+ * Contains a quantity of an elements
280
+ */
281
+ get size(): number;
282
+ /**
283
+ * Contains a maximum possible element index in the list
284
+ */
285
+ get maxIndex(): number;
286
+ /**
287
+ * Indicates whether a `null`-element is allowed
288
+ */
289
+ get isNullItemsAllowed(): boolean;
290
+ /**
291
+ * Deletes all child elements and attributes.
292
+ */
293
+ clear(): void;
294
+ /**
295
+ * Checks whether an instance holds none element.
296
+ */
297
+ isEmpty(): boolean;
298
+ /**
299
+ * Checks whether an instance holds at least one element.
300
+ */
301
+ isNotEmpty(): boolean;
302
+ /**
303
+ * Checks whether a given value is a valid index value
304
+ * and it is not exceeds an index range within the instance.
305
+ */
306
+ chkIndex(value: number | string): boolean;
307
+ /**
308
+ * Checks whether or not a given element is valid.
309
+ */
310
+ isValidItem(obj: any): boolean;
311
+ /**
312
+ * Returns an element.
313
+ * @deprecated
314
+ * @todo \[since `v0.0.34`] deprecated and will be removed later, consider
315
+ * to use `TXmlElementsListController.__getItemRaw` instead.
316
+ */
317
+ protected _getItemRaw(index: number | string): object | null;
318
+ /**
319
+ * Returns an element.
320
+ */
321
+ getItem(index: number | string): TXmlElementController | null;
322
+ /**
323
+ * Adds a new element.
324
+ */
325
+ protected _addItemRaw(item: any): number;
326
+ /**
327
+ * Adds a new element.
328
+ */
329
+ addItem(item: any): number;
330
+ /**
331
+ * Sets a new element.
332
+ * @deprecated
333
+ * @todo \[since `v0.0.34`] deprecated and will be removed later, consider
334
+ * to use `TXmlElementsListController.__setItemRaw` instead.
335
+ */
336
+ protected _setItemRaw(index: number | string, item: any): boolean;
337
+ /**
338
+ * Sets a new element.
339
+ */
340
+ setItem(index: number | string, item: any): boolean;
341
+ /**
342
+ * Insertes a new element.
343
+ */
344
+ protected _insItemRaw(index: number | string, item: any): boolean;
345
+ /**
346
+ * Insertes a new element.
347
+ */
348
+ insItem(index: number | string, item: any): boolean;
349
+ /**
350
+ * Deletes an element.
351
+ */
352
+ delItem(value: number | string): boolean;
353
+ /**
354
+ * Loads a list of an elements.
355
+ */
356
+ loadItems(items: any, opt?: OPT_ELC_loaditems): number;
357
+ [Symbol.iterator](): {
358
+ next: () => {
359
+ done: boolean;
360
+ value: TXmlElementController | null;
361
+ } | {
362
+ done: boolean;
363
+ value: undefined;
364
+ };
365
+ return(): {
366
+ done: boolean;
367
+ value: undefined;
368
+ };
369
+ };
370
+ #private;
371
+ }
372
+
373
+ import { TXmlContentParseOptions } from "@ygracs/xobj-lib-js";
374
+
375
+ /**
376
+ * @classdesc This class implements an instance of an element
377
+ * that managea content of a document declaration
378
+ */
379
+ export class TXmlContentDeclaration {
380
+ /**
381
+ * Creates an instance of the element
382
+ * @throws {TypeError}
383
+ */
384
+ constructor(obj: object, opt?: OPT_xmlcontsett);
385
+ /**
386
+ * Contains a version of an XML
387
+ */
388
+ get version(): string;
389
+ set version(value: string);
390
+ /**
391
+ * Contains a document character set
392
+ */
393
+ get encoding(): string;
394
+ set encoding(value: string);
395
+ /**
396
+ * Initializes an instance content.
397
+ */
398
+ init(): void;
399
+ #private;
400
+ }
401
+
402
+ /**
403
+ * @augments TXmlElementController
404
+ * @classdesc This class implements an instance of a root element
405
+ */
406
+ export class TXmlContentRootElement extends TXmlElementController {
407
+ /**
408
+ * Tries to unwraps a given object.
409
+ */
410
+ protected static __unwrap(item: object, opt?: boolean): object | null;
411
+ /**
412
+ * Creates an instance of a root element.
413
+ * @throws {TypeError}
414
+ */
415
+ constructor(obj: object, opt?: OPT_xmlcontsett);
416
+ /**
417
+ * @experimental
418
+ */
419
+ get tagName(): string;
420
+ set tagName(value: string);
421
+ #private;
422
+ }
423
+
424
+ /**
425
+ * @classdesc This class implements an instance of a container
426
+ * that managea content of a document
427
+ */
428
+ export class TXmlContentContainer {
429
+ /**
430
+ * Creates an instance of the container
431
+ */
432
+ constructor(opt?: OPT_xmlcontsett);
433
+ /**
434
+ * Returns a root element
435
+ */
436
+ get rootElement(): TXmlContentRootElement;
437
+ /**
438
+ * Cleans a document content.
439
+ */
440
+ clear(): void;
441
+ /**
442
+ * Initializes an instance with a given content.
443
+ */
444
+ protected _bindContent(obj: object, opt?: OPT_xmlcontsett): boolean;
445
+ /**
446
+ * Returns a document content as a string in an XML-format.
447
+ * @throws {Error}
448
+ */
449
+ saveToXMLString(): string;
450
+ /**
451
+ * Saves a document content to a file.
452
+ * @throws {Error}
453
+ */
454
+ saveToFile(source: string): Promise<fsoDescr>;
455
+ /**
456
+ * Saves a document content to a file.
457
+ */
458
+ saveToFileSync(source: string): fsoDescr;
459
+ /**
460
+ * Loads a document content from a string.
461
+ * @throws {Error}
462
+ */
463
+ loadFromXMLString(xmlString: string): boolean;
464
+ /**
465
+ * Loads a document content from a file.
466
+ * @throws {Error}
467
+ */
468
+ loadFromFile(source: string): Promise<fsoDescr>;
469
+ /**
470
+ * Loads a document content from a file.
471
+ * @throws {Error}
472
+ */
473
+ loadFromFileSync(source: string): fsoDescr;
474
+ /**
475
+ * Returns a document content a string in a JSON-format.
476
+ */
477
+ protected asJSON(): string;
478
+ #private;
479
+ }
480
+
481
+ import type { fsoDescr } from '@cntwg/file-helper';
482
+
483
+ export { TXmlContentParseOptions };
package/lib/xmldoc-lib.js CHANGED
@@ -1,4 +1,4 @@
1
- // [v0.2.118-20250823]
1
+ // [v0.2.124-20260118]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -14,6 +14,9 @@ const {
14
14
  const {
15
15
  loadFromFileSync, loadFromFile,
16
16
  saveToFileSync, saveToFile,
17
+ // * import types definitions *
18
+ /** @see fsoDescr from `@cntwg/file-helper` */
19
+ fsoDescr,
17
20
  } = require('@cntwg/file-helper');
18
21
 
19
22
  const xObj = require('@ygracs/xobj-lib-js');
@@ -21,9 +24,11 @@ const {
21
24
  evalXObjEName,
22
25
  getXObjElement, addXObjElement, insertXObjElement,
23
26
  readXObjParam, writeXObjParam,
24
- TXmlContentParseOptions,
27
+ //TXmlContentParseOptions,
25
28
  DEF_XML_PARSE_OPTIONS: XML_DEF_PARSE_OPTIONS,
26
29
  } = xObj;
30
+ // keep the next line for a type checking work properly :(
31
+ const { TXmlContentParseOptions } = require('@ygracs/xobj-lib-js/lib/xObj-defs');
27
32
 
28
33
  const {
29
34
  readAsTagName,
@@ -45,26 +50,37 @@ const {
45
50
  * @property {boolean} [isNullItemsAllowed=false] - <reserved>
46
51
  */
47
52
 
53
+ /**
54
+ * An XML-element controller configuration.
55
+ * @typedef {Object} XMLElementConfig
56
+ * @property {TXmlContentParseOptions} parseOptions - parser options
57
+ * @property {boolean} [proxyModeEnable=false] - mode flag
58
+ * @property {boolean} [isNullItemsAllowed=false] - <reserved>
59
+ */
60
+
48
61
  /**
49
62
  * Evaluates an XML-element settings
50
63
  * @function __evalXMLElementSettings
51
- * @param {any} value - element settings to evaluate
52
- * @returns {OPT_xmlelemsett}
64
+ * @param {Object} value - element settings to evaluate
65
+ * @returns {XMLElementConfig}
53
66
  * @inner
54
67
  */
55
68
  function __evalXMLElementSettings(value) {
56
69
  /** @type {OPT_xmlelemsett} */
57
70
  const settings = isPlainObject(value) ? value : {};
58
71
  let {
72
+ parseOptions,
59
73
  proxyModeEnable,
60
74
  isNullItemsAllowed,
61
- parseOptions,
62
75
  } = settings;
63
- if (!(parseOptions instanceof TXmlContentParseOptions)) {
64
- settings.parseOptions = new TXmlContentParseOptions(parseOptions);
65
- };
76
+ settings.parseOptions = (
77
+ parseOptions instanceof TXmlContentParseOptions
78
+ ? parseOptions
79
+ : new TXmlContentParseOptions(parseOptions)
80
+ );
66
81
  if (typeof proxyModeEnable !== 'boolean') settings.proxyModeEnable = false;
67
82
  if (typeof isNullItemsAllowed !== 'boolean') settings.isNullItemsAllowed = false;
83
+ // @ts-expect-error
68
84
  return settings;
69
85
  };
70
86
 
@@ -79,11 +95,22 @@ function __evalXMLElementSettings(value) {
79
95
  * @see OPT_xmlelemsett
80
96
  */
81
97
 
98
+ /**
99
+ * An XML-content container settings.
100
+ * @typedef {Object} XMLContainerSettings
101
+ * @property {TXmlContentParseOptions} parseOptions - parser options
102
+ * @property {boolean} [proxyModeEnable=false] - mode flag
103
+ * @property {boolean} [isNullItemsAllowed=false] - <reserved>
104
+ * @property {string} rootETagName - tag name of the root element
105
+ * @property {boolean} [autoBindRoot=true] - mode flag
106
+ * @see OPT_xmlelemsett
107
+ */
108
+
82
109
  /**
83
110
  * Evaluates an XML-container settings
84
111
  * @function __evalXMLContainerSettings
85
112
  * @param {any} value - container settings to evaluate
86
- * @returns {OPT_xmlcontsett}
113
+ * @returns {XMLContainerSettings}
87
114
  * @inner
88
115
  */
89
116
  function __evalXMLContainerSettings(value) {
@@ -98,6 +125,7 @@ function __evalXMLContainerSettings(value) {
98
125
  };
99
126
  settings.rootETagName = rootETagName;
100
127
  if (typeof autoBindRoot !== 'boolean') settings.autoBindRoot = true;
128
+ // @ts-expect-error
101
129
  return settings;
102
130
  };
103
131
 
@@ -129,8 +157,10 @@ const XML_TE_NROOT_EMSG = 'root element not found';
129
157
  class TXmlAttributesMapper {
130
158
  /** @type {object} */
131
159
  #_host;
132
- /** @type {OPT_xmlelemsett} */
133
- #_options;
160
+ ///** @type {OPT_xmlelemsett} */
161
+ //#_options;
162
+ /** @type {TXmlContentParseOptions} */
163
+ #_parseOptions;
134
164
 
135
165
  /**
136
166
  * Creates an attributes mapper instance
@@ -154,7 +184,7 @@ class TXmlAttributesMapper {
154
184
  };
155
185
  // save options
156
186
  settings.attributesKey = attributesKey;
157
- this.#_options = parseOptions;
187
+ this.#_parseOptions = parseOptions;
158
188
  }
159
189
 
160
190
  /**
@@ -165,7 +195,7 @@ class TXmlAttributesMapper {
165
195
  get entries() {
166
196
  let items = xObj.getXObjAttributes(
167
197
  this.#_host,
168
- this.#_options.settings.attributesKey,
198
+ this.#_parseOptions.settings.attributesKey,
169
199
  );
170
200
  return isPlainObject(items) ? Object.entries(items) : [];
171
201
  }
@@ -181,7 +211,7 @@ class TXmlAttributesMapper {
181
211
  result = xObj.checkXObjAttribute(
182
212
  this.#_host,
183
213
  name,
184
- this.#_options.settings.attributesKey,
214
+ this.#_parseOptions.settings.attributesKey,
185
215
  );
186
216
  } catch (err) {
187
217
  // // TODO: verify what error is thrown
@@ -201,7 +231,7 @@ class TXmlAttributesMapper {
201
231
  result = xObj.readXObjAttr(
202
232
  this.#_host,
203
233
  name,
204
- this.#_options.settings.attributesKey,
234
+ this.#_parseOptions.settings.attributesKey,
205
235
  );
206
236
  } catch (err) {
207
237
  // // TODO: verify what error is thrown
@@ -225,7 +255,7 @@ class TXmlAttributesMapper {
225
255
  this.#_host,
226
256
  name,
227
257
  value,
228
- this.#_options.settings.attributesKey,
258
+ this.#_parseOptions.settings.attributesKey,
229
259
  );
230
260
  } catch (err) {
231
261
  // // TODO: verify what error is thrown
@@ -246,7 +276,7 @@ class TXmlAttributesMapper {
246
276
  result = xObj.deleteXObjAttribute(
247
277
  this.#_host,
248
278
  name,
249
- this.#_options.settings.attributesKey,
279
+ this.#_parseOptions.settings.attributesKey,
250
280
  );
251
281
  } catch (err) {
252
282
  // // TODO: verify what error is thrown
@@ -271,7 +301,7 @@ class TXmlAttributesMapper {
271
301
  this.#_host,
272
302
  name,
273
303
  newName,
274
- this.#_options.settings.attributesKey,
304
+ this.#_parseOptions.settings.attributesKey,
275
305
  );
276
306
  } catch (err) {
277
307
  // // TODO: verify what error is thrown
@@ -288,7 +318,7 @@ class TXmlAttributesMapper {
288
318
  clear() {
289
319
  insertXObjElement(
290
320
  this.#_host,
291
- this.#_options.settings.attributesKey,
321
+ this.#_parseOptions.settings.attributesKey,
292
322
  {
293
323
  force: true,
294
324
  ripOldies: true,
@@ -304,9 +334,9 @@ class TXmlAttributesMapper {
304
334
  class TXmlElementController {
305
335
  /** @type {object} */
306
336
  #_host;
307
- /** @type {OPT_xmlelemsett} */
337
+ /** @type {XMLElementConfig} */
308
338
  #_options;
309
- /** @type {object} */
339
+ /** @type {TXmlContentParseOptions} */
310
340
  #_parseOptions;
311
341
  /** @type {TXmlAttributesMapper} */
312
342
  #_attributes;
@@ -593,11 +623,11 @@ class TXmlElementController {
593
623
  proxyModeEnable,
594
624
  parseOptions,
595
625
  } = _options;
596
- parseOptions = parseOptions.xml2js;
597
- parseOptions.ignoreDocType = true;
598
- parseOptions.ignoreDeclaration = true;
626
+ const xml2jsOptions = parseOptions.xml2js;
627
+ xml2jsOptions.ignoreDocType = true;
628
+ xml2jsOptions.ignoreDeclaration = true;
599
629
  try {
600
- let obj = xmlParser.xml2js(xmlString, parseOptions);
630
+ let obj = xmlParser.xml2js(xmlString, xml2jsOptions);
601
631
  if (isPlainObject(obj)) {
602
632
  let list = Object.entries(obj);
603
633
  let item = list[0];
@@ -761,7 +791,7 @@ class TXmlElementController {
761
791
  class TXmlElementsListController {
762
792
  /** @type {object[]} */
763
793
  #_host;
764
- /** @type {OPT_xmlelemsett} */
794
+ /** @type {XMLElementConfig} */
765
795
  #_options;
766
796
  #_count = null;
767
797
 
@@ -1116,7 +1146,7 @@ class TXmlElementsListController {
1116
1146
  class TXmlContentDeclaration {
1117
1147
  /** @type {object} */
1118
1148
  #_host;
1119
- /** @type {OPT_xmlcontsett} */
1149
+ /** @type {XMLContainerSettings} */
1120
1150
  #_options;
1121
1151
  /** @type {TXmlElementController} */
1122
1152
  #_ctrls;
@@ -1179,7 +1209,7 @@ class TXmlContentDeclaration {
1179
1209
 
1180
1210
  /**
1181
1211
  * Initializes an instance content.
1182
- * @returns {boolean}
1212
+ * @returns {void}
1183
1213
  */
1184
1214
  init() {
1185
1215
  const _options = this.#_options;
@@ -1204,7 +1234,7 @@ class TXmlContentDeclaration {
1204
1234
  class TXmlContentRootElement extends TXmlElementController {
1205
1235
  /** @type {?object} */
1206
1236
  #_content;
1207
- /** @type {OPT_xmlcontsett} */
1237
+ /** @type {XMLContainerSettings} */
1208
1238
  #_options;
1209
1239
 
1210
1240
  /**
@@ -1295,17 +1325,6 @@ class TXmlContentRootElement extends TXmlElementController {
1295
1325
 
1296
1326
  }
1297
1327
 
1298
- /**
1299
- * A fs ops description.
1300
- * @typedef {Object} fsoDescr
1301
- * @property {boolean} isERR - flag
1302
- * @property {number} [errCode] - error code
1303
- * @property {string} errEvent - event ID
1304
- * @property {string} [errMsg] - event message
1305
- * @property {string} [source] - path to file
1306
- * @property {any} [content] - file content
1307
- */
1308
-
1309
1328
  /**
1310
1329
  * @classdesc This class implements an instance of a container
1311
1330
  * that managea content of a document
@@ -1313,9 +1332,9 @@ class TXmlContentRootElement extends TXmlElementController {
1313
1332
  class TXmlContentContainer {
1314
1333
  /** @type {?object} */
1315
1334
  #_content;
1316
- /** @type {OPT_xmlcontsett} */
1335
+ /** @type {XMLContainerSettings} */
1317
1336
  #_options;
1318
- /** @type {?object} */
1337
+ /** @type {TXmlContentParseOptions} */
1319
1338
  #_parseOptions;
1320
1339
  /** @type {TXmlContentDeclaration} */
1321
1340
  #_docDecl;
@@ -1363,7 +1382,7 @@ class TXmlContentContainer {
1363
1382
  /**
1364
1383
  * Initializes an instance with a given content.
1365
1384
  * @param {object} obj
1366
- * @param {object} [opt]
1385
+ * @param {OPT_xmlcontsett} [opt] - options
1367
1386
  * @returns {boolean}
1368
1387
  * @protected
1369
1388
  */
@@ -1590,8 +1609,3 @@ module.exports.TXmlContentParseOptions = TXmlContentParseOptions;
1590
1609
  module.exports.TXmlContentDeclaration = TXmlContentDeclaration;
1591
1610
  module.exports.TXmlContentRootElement = TXmlContentRootElement;
1592
1611
  module.exports.TXmlContentContainer = TXmlContentContainer;
1593
-
1594
- // * re-expected *
1595
- module.exports.readAsTagName = readAsTagName;
1596
- module.exports.readAsAttrName = readAsAttrName;
1597
- module.exports.valueToElementID = valueToElementID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/xml-lib-js",
3
- "version": "0.0.35",
3
+ "version": "0.0.37-b",
4
4
  "description": "A library for handling an XML-documents",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -12,39 +12,38 @@
12
12
  "xml"
13
13
  ],
14
14
  "main": "./index.js",
15
+ "types": "./index.d.ts",
15
16
  "files": [
16
17
  "doc/xmldoc-lib.md",
17
18
  "lib/xmldoc-lib.js",
18
19
  "lib/xml-helper.js",
19
20
  "lib/xml-base.js",
21
+ "lib/*.d.ts",
20
22
  "index.js",
23
+ "index.d.ts",
21
24
  "CHANGELOG.md"
22
25
  ],
23
26
  "scripts": {
24
27
  "test": "jest",
25
- "test-xml": "jest",
26
- "test-xml:amap": "jest TXmlAttributesMapper",
27
- "test-xml:ec": "jest TXmlElementController",
28
- "test-xml:lc": "jest TXmlElementsListController",
29
- "test-xml:re": "jest TXmlContentRootElement",
30
- "test-xml:cdec": "jest TXmlContentDeclaration",
31
- "test-xml:cc": "jest TXmlContentContainer",
32
28
  "build-doc-md": "jsdoc2md",
33
- "build-doc-html": "jsdoc"
29
+ "build-doc-html": "jsdoc",
30
+ "gen-dts": "npx -p typescript tsc"
34
31
  },
35
32
  "imports": {
36
33
  "#lib/*": "./lib/*",
37
34
  "#test-dir/*": "./__test__/*"
38
35
  },
39
36
  "dependencies": {
40
- "@cntwg/file-helper": "^0.0.1",
41
- "@ygracs/bsfoc-lib-js": "^0.3.0",
42
- "@ygracs/xml-js6": "^0.0.5-b",
43
- "@ygracs/xobj-lib-js": "^0.2.4"
37
+ "@cntwg/file-helper": "^0.0.3",
38
+ "@ygracs/bsfoc-lib-js": "^0.3.3",
39
+ "@ygracs/xml-js6": "^0.0.6-b",
40
+ "@ygracs/xobj-lib-js": "^0.2.8-b"
44
41
  },
45
42
  "devDependencies": {
46
- "jest": "^30.0.5",
47
- "jsdoc-to-markdown": "^9.1.2",
48
- "minimist": "^1.2.8"
43
+ "@ygracs/test-helper": "~0.0.1-b",
44
+ "jest": "^30.2.0",
45
+ "jsdoc-to-markdown": "^9.1.3",
46
+ "minimist": "^1.2.8",
47
+ "typescript": "~5.9.3"
49
48
  }
50
49
  }