node-opcua-modeler 2.164.2 → 2.165.0

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.
@@ -1,19 +1,18 @@
1
1
  import {
2
- BaseNode,
3
- UAReference,
4
- UAObjectType,
5
- UAVariable,
2
+ type BaseNode,
6
3
  resolveReferenceNode,
7
4
  resolveReferenceType,
8
- UAVariableType,
9
- UAObject
5
+ type UAObject,
6
+ type UAObjectType,
7
+ type UAReference,
8
+ type UAVariable,
9
+ type UAVariableType
10
10
  } from "node-opcua-address-space";
11
11
  import { BrowseDirection, NodeClass } from "node-opcua-data-model";
12
12
  import { NodeId, resolveNodeId } from "node-opcua-nodeid";
13
13
  import { DataType } from "node-opcua-variant";
14
14
  import { TableHelper } from "./tableHelper";
15
15
 
16
-
17
16
  function symbol(nodeClass: NodeClass) {
18
17
  switch (nodeClass) {
19
18
  case NodeClass.DataType:
@@ -46,9 +45,9 @@ function encodeXML(s: string) {
46
45
  interface Data {
47
46
  table: TableHelper;
48
47
  node: BaseNode;
49
- alreadyDumped: Record<string, any>;
48
+ alreadyDumped: Record<string, number>;
50
49
  descriptions: Description[];
51
- subElements?: any[];
50
+ subElements?: unknown[];
52
51
  }
53
52
  interface Description {
54
53
  description: string;
@@ -62,7 +61,7 @@ interface DumpReferenceOptions {
62
61
  prefix?: string;
63
62
  }
64
63
 
65
- function _dumpReferenceVariable(v: UAVariable, value: any, dataType: string): { value: any; dataType: string } {
64
+ function _dumpReferenceVariable(v: UAVariable, value: string, dataType: string): { value: string; dataType: string } {
66
65
  const val = v.readValue().value.value;
67
66
  if (v.dataType.isEmpty()) {
68
67
  return { value, dataType };
@@ -72,17 +71,17 @@ function _dumpReferenceVariable(v: UAVariable, value: any, dataType: string): {
72
71
  // don't do anything
73
72
  } else if (v.isEnumeration() && val !== null) {
74
73
  const enumValue = v.readEnumValue();
75
- value = enumValue.value + " (" + enumValue.name + ")";
74
+ value = `${enumValue.value} (${enumValue.name})`;
76
75
  } else if (val instanceof Date) {
77
76
  value = val ? val.toUTCString() : "";
78
77
  } else {
79
78
  value = val ? val.toString() : "null";
80
79
  }
81
- const actualDataType = DataType[v.readValue().value.dataType];
80
+ const _actualDataType = DataType[v.readValue().value.dataType];
82
81
  const basicDataType = DataType[v.dataTypeObj.basicDataType];
83
82
  dataType = v.dataTypeObj.browseName.toString();
84
83
  if (basicDataType !== dataType) {
85
- dataType = dataType + "(" + basicDataType + ")";
84
+ dataType = `${dataType}(${basicDataType})`;
86
85
  }
87
86
  return { value, dataType };
88
87
  }
@@ -104,15 +103,14 @@ function dumpReference(data: Data, ref: UAReference, options: DumpReferenceOptio
104
103
  // ignore subtype references
105
104
  /* c8 ignore next */
106
105
  if (!ref.node) {
107
- // tslint:disable-next-line: no-console
108
106
  console.log(" Halt ", ref.toString({ addressSpace: data.node.addressSpace }));
109
107
  return;
110
108
  }
111
109
  const dir = ref.isForward ? " " : " ";
112
- const refNode = ref.node!;
110
+ const refNode = ref.node;
113
111
 
114
112
  const refType = resolveReferenceType(data.node.addressSpace, ref);
115
- if (options && options.filter && refType.browseName.name !== options.filter) {
113
+ if (options?.filter && refType.browseName.name !== options.filter) {
116
114
  return;
117
115
  }
118
116
  const key = ref.nodeId.toString() + ref.referenceType.toString();
@@ -131,8 +129,8 @@ function dumpReference(data: Data, ref: UAReference, options: DumpReferenceOptio
131
129
  dataType = t.dataType;
132
130
  // findBasicDataType(v.dataTypeObj);
133
131
  }
134
-
135
- const prefix = options.prefix ? options.prefix + "." : "";
132
+
133
+ const prefix = options.prefix ? `${options.prefix}.` : "";
136
134
  const row = [
137
135
  "".padEnd(prefix.length) + refType.browseName.toString() + dir + symbol(refNode.nodeClass),
138
136
  refNode.nodeId.toString(),
@@ -147,7 +145,7 @@ function dumpReference(data: Data, ref: UAReference, options: DumpReferenceOptio
147
145
 
148
146
  data.descriptions.push({
149
147
  description: refNode.description ? refNode.description.text || "" : "",
150
- name: refNode.browseName.name!,
148
+ name: refNode.browseName.name ?? "",
151
149
  type: dataType
152
150
  });
153
151
 
@@ -217,15 +215,15 @@ export function displayNodeElement(node: BaseNode, options?: DisplayNodeOptions)
217
215
  table.push(["Base", superType.browseName.toString(), { colSpan: 6, content: node.browseName.toString() }]);
218
216
  }
219
217
 
220
- if (node.description) {
221
- table.push(["Description", { colspan: 6, content: shortDescription(node.description.text! || "") }]);
218
+ if (node.description?.text) {
219
+ table.push(["Description", { colspan: 6, content: shortDescription(node.description?.text ?? "") }]);
222
220
  }
223
221
  return table;
224
222
  }
225
223
 
226
224
  const table = createTable();
227
225
 
228
- const alreadyDumped: Record<string, any> = {};
226
+ const alreadyDumped: Record<string, number> = {};
229
227
 
230
228
  const descriptions: Description[] = [];
231
229
 
@@ -248,7 +246,7 @@ export function displayNodeElement(node: BaseNode, options?: DisplayNodeOptions)
248
246
  tables.push(table);
249
247
 
250
248
  if (node.description) {
251
- str.push(node.description.text! || "");
249
+ str.push(node.description.text ?? "");
252
250
  str.push("");
253
251
  }
254
252
  str.push(toText(table));
@@ -262,13 +260,13 @@ export function displayNodeElement(node: BaseNode, options?: DisplayNodeOptions)
262
260
  let subtypeOf = (curNode as UAObjectType | UAVariableType).subtypeOfObj;
263
261
  while (subtypeOf) {
264
262
  data.table = createTable();
265
- data.table.push([subtypeOf.browseName.toString() + ":", "--", "--", "--"]);
263
+ data.table.push([`${subtypeOf.browseName.toString()}:`, "--", "--", "--"]);
266
264
  const references2 = subtypeOf.allReferences();
267
265
 
268
266
  dumpReferences(data, references2, { recursive: false });
269
267
 
270
268
  str.push("<details>");
271
- str.push("<summary>Base type: " + subtypeOf.browseName.toString() + "</summary>");
269
+ str.push(`<summary>Base type: ${subtypeOf.browseName.toString()}</summary>`);
272
270
  str.push("");
273
271
  str.push(toText(data.table));
274
272
  str.push("");
@@ -1,5 +1,4 @@
1
- /* eslint-disable max-statements */
2
- import {
1
+ import type {
3
2
  BaseNode,
4
3
  INamespace,
5
4
  UADataType,
@@ -11,7 +10,7 @@ import {
11
10
  } from "node-opcua-address-space";
12
11
  import { coerceUInt32 } from "node-opcua-basic-types";
13
12
  import { NodeClass } from "node-opcua-data-model";
14
- import { StructureField } from "node-opcua-types";
13
+ import type { StructureField } from "node-opcua-types";
15
14
  import { DataType } from "node-opcua-variant";
16
15
 
17
16
  import { displayNodeElement } from "./displayNodeElement";
@@ -30,15 +29,11 @@ interface NamespacePriv2 extends INamespace {
30
29
  _aliasCount(): number;
31
30
  }
32
31
  export interface IWriter {
33
- // eslint-disable-next-line no-unused-vars
34
32
  writeLine(_str: string): void;
35
33
  }
36
34
 
37
35
  export class Writer implements IWriter {
38
36
  private readonly stream: string[] = [];
39
- constructor() {
40
- /* empty */
41
- }
42
37
  public writeLine(str: string): void {
43
38
  this.stream.push(str);
44
39
  }
@@ -62,7 +57,7 @@ export async function buildDocumentationToString(namespace: INamespace, options?
62
57
  const toDataTypeStr = (p: BaseNode): string => {
63
58
  if (p.nodeClass === NodeClass.Variable) {
64
59
  const v = p as UAVariable;
65
- const arr = v.valueRank == 1 ? "[]" : "";
60
+ const arr = v.valueRank === 1 ? "[]" : "";
66
61
  const brn = toDataTypeStr((p as UAVariable).dataTypeObj);
67
62
  return brn + arr;
68
63
  }
@@ -85,7 +80,7 @@ function dataTypeEnumerationToMarkdown(dataType: UADataType): string {
85
80
 
86
81
  writer.writeLine("");
87
82
  const definition = dataType.getEnumDefinition();
88
- writer.writeLine("\nBasic Type: " + (DataType as any)[DataType.Int32]);
83
+ writer.writeLine(`\nBasic Type: ${DataType[DataType.Int32]}`);
89
84
  writer.writeLine("");
90
85
 
91
86
  const table = new TableHelper(["Name", "Value", "Description"]);
@@ -111,10 +106,10 @@ function dumpTypeRepresentation(uaType: UAObjectType | UADataType | UAReferenceT
111
106
  const table = new TableHelper(["Name", "Attribute"]);
112
107
  table.push(["NodeId", uaType.nodeId.toString()]);
113
108
  table.push(["NamespaceUri", uaType.addressSpace.getNamespaceUri(uaType.nodeId.namespace)]);
114
- table.push(["BrowseName", uaType.browseName.name!.toString()]);
109
+ table.push(["BrowseName", uaType.browseName.name?.toString()]);
115
110
  table.push(["NodeClass", NodeClass[uaType.nodeClass]]);
116
111
  if (uaType.nodeClass === NodeClass.ReferenceType) {
117
- table.push(["InverseName", (uaType as UAReferenceType).inverseName!.text]);
112
+ table.push(["InverseName", (uaType as UAReferenceType).inverseName?.text]);
118
113
  // table.push(["IsSymmetric", (uaType as UAReferenceType).isSymetric ? "Yes" : "No"]);
119
114
  }
120
115
  table.push(["IsAbstract", uaType.isAbstract ? "Yes" : "No"]);
@@ -130,7 +125,7 @@ function dumpTypeRepresentation(uaType: UAObjectType | UADataType | UAReferenceT
130
125
 
131
126
  if (uaType.subtypeOfObj) {
132
127
  const referenceName = "HasSubType";
133
- const p = uaType.subtypeOfObj!;
128
+ const p = uaType.subtypeOfObj;
134
129
  const nodeClass = NodeClass[p.nodeClass];
135
130
  const browseName = p.browseName.toString();
136
131
  const dataTypeStr = toDataTypeStr(p);
@@ -167,16 +162,16 @@ function dataTypeStructureToMarkdown(dataType: UADataType): string {
167
162
  }
168
163
 
169
164
  const definition = dataType.getStructureDefinition();
170
- writer.writeLine("\nBasic Type: " + (DataType as any)[dataType.basicDataType]);
165
+ writer.writeLine(`\nBasic Type: ${DataType[dataType.basicDataType]}`);
171
166
  writer.writeLine("");
172
167
  writer.writeLine(`The fields of the ${dataType.browseName.name} DataType are defined in the following table:`);
173
168
 
174
169
  const c = (f: StructureField) => {
175
- let dataTypeString = addressSpace.findDataType(f.dataType)!.browseName.toString();
170
+ let dataTypeString = addressSpace.findDataType(f.dataType)?.browseName.toString();
176
171
  if (f.valueRank === 1) {
177
172
  dataTypeString += "[]";
178
173
  } else if (f.valueRank >= 2) {
179
- dataTypeString += "[" + f.arrayDimensions?.map((d) => "" + d).join(" ") + "]";
174
+ dataTypeString += `[${f.arrayDimensions?.map((d) => `${d}`).join(" ")}]`;
180
175
  }
181
176
  // f.maxStringLength ? f.maxStringLength : "",
182
177
  // f.arrayDimensions ? f.arrayDimensions : "",
@@ -185,7 +180,7 @@ function dataTypeStructureToMarkdown(dataType: UADataType): string {
185
180
  const table = new TableHelper(["Name", "Type", "Description"]);
186
181
  table.push([dataType.browseName.name, "Structure"]);
187
182
  for (const f of definition.fields || []) {
188
- table.push([" " + f.name, c(f), (f.description.text || "").replace(/\n/g, "<br>")]);
183
+ table.push([` ${f.name}`, c(f), (f.description.text || "").replace(/\n/g, "<br>")]);
189
184
  }
190
185
  writer.writeLine(table.toMarkdownTable());
191
186
 
@@ -205,7 +200,7 @@ function dataTypeToMarkdown(dataType: UADataType): string {
205
200
  if (dataType.description) {
206
201
  writer.writeLine(dataType.description.text || "");
207
202
  }
208
- writer.writeLine("\nBasic Type: " + (DataType as any)[dataType.basicDataType]);
203
+ writer.writeLine(`\nBasic Type: ${DataType[dataType.basicDataType]}`);
209
204
  writer.writeLine("");
210
205
  return writer.toString();
211
206
  }
@@ -279,7 +274,7 @@ export async function buildDocumentation(
279
274
  const { dataTypes, objectTypes, variableTypes } = extractTypes(namespace, options);
280
275
 
281
276
  writer.writeLine("");
282
- writer.writeLine("# Namespace " + namespaceUri);
277
+ writer.writeLine(`# Namespace ${namespaceUri}`);
283
278
  writer.writeLine("");
284
279
 
285
280
  // -------------- writeReferences
@@ -288,13 +283,13 @@ export async function buildDocumentation(
288
283
  writer.writeLine("## References ");
289
284
  writer.writeLine("");
290
285
  for (const referenceType of namespacePriv._referenceTypeIterator()) {
291
- writer.writeLine("\n\n### reference " + referenceType.browseName.name!);
286
+ writer.writeLine(`\n\n### reference ${referenceType.browseName.name ?? ""}`);
292
287
  dumpReferenceType(referenceType);
293
288
  }
294
289
  }
295
290
 
296
291
  function d(node: BaseNode): string {
297
- return node.description && node.description.text ? node.description!.text!.toString() : "";
292
+ return node.description?.text ? node.description?.text?.toString() : "";
298
293
  }
299
294
 
300
295
  // -------------- writeDataType
@@ -303,7 +298,7 @@ export async function buildDocumentation(
303
298
  writer.writeLine("## DataTypes");
304
299
  writer.writeLine("");
305
300
  for (const dataType of dataTypes) {
306
- writer.writeLine("\n\n### " + dataType.browseName.name!.toString());
301
+ writer.writeLine(`\n\n### ${dataType.browseName.name?.toString()}`);
307
302
  writer.writeLine("");
308
303
  writer.writeLine(dataTypeToMarkdown(dataType));
309
304
  }
@@ -314,7 +309,7 @@ export async function buildDocumentation(
314
309
  writer.writeLine("## ObjectTypes");
315
310
  writer.writeLine("");
316
311
  for (const objectType of objectTypes) {
317
- writer.writeLine("\n\n### " + objectType.browseName.name!.toString());
312
+ writer.writeLine(`\n\n### ${objectType.browseName.name?.toString()}`);
318
313
  writer.writeLine(d(objectType));
319
314
 
320
315
  if (options.dumpGraphics) {
@@ -325,12 +320,12 @@ export async function buildDocumentation(
325
320
  writer.writeLine(displayNodeElement(objectType, { format: "markdown" }));
326
321
 
327
322
  for (const comp of objectType.getComponents()) {
328
- writer.writeLine("\n\n#### " + comp.browseName.name!.toString());
323
+ writer.writeLine(`\n\n#### ${comp.browseName.name?.toString()}`);
329
324
  writer.writeLine("");
330
325
  writer.writeLine(d(comp));
331
326
  }
332
327
  for (const comp of objectType.getProperties()) {
333
- writer.writeLine("\n\n#### " + comp.browseName.name!.toString());
328
+ writer.writeLine(`\n\n#### ${comp.browseName.name?.toString()}`);
334
329
  writer.writeLine("");
335
330
  writer.writeLine(d(comp));
336
331
  }
@@ -342,7 +337,7 @@ export async function buildDocumentation(
342
337
  writer.writeLine("## VariableTypes");
343
338
  writer.writeLine("");
344
339
  for (const variableType of variableTypes) {
345
- writer.writeLine("\n\n### " + variableType.browseName.name!.toString());
340
+ writer.writeLine(`\n\n### ${variableType.browseName.name?.toString()}`);
346
341
  writer.writeLine(d(variableType));
347
342
  writer.writeLine("");
348
343
 
@@ -352,8 +347,9 @@ export async function buildDocumentation(
352
347
  // enumerate components
353
348
  writer.writeLine(displayNodeElement(variableType, { format: "markdown" }));
354
349
  for (const reference of variableType.allReferences()) {
355
- const n = reference.node!;
356
- writer.writeLine("\n\n#### " + n.browseName.name!.toString());
350
+ const n = reference.node;
351
+ if (!n) continue;
352
+ writer.writeLine(`\n\n#### ${n.browseName.name?.toString()}`);
357
353
  writer.writeLine("");
358
354
  writer.writeLine(d(n));
359
355
  }
package/source/index.ts CHANGED
@@ -1,30 +1,24 @@
1
- export * from "./types";
2
- export * from "./displayNodeElement";
3
- export * from "./promoteToMandatory";
4
- export * from "./setNamespaceMetaData";
5
- export * from "./build_model_inner";
6
- export * from "./addExtensionObjectDataType";
7
- export * from "./symbol";
8
- export * from "./to_cvs";
9
- export * from "./generate_markdown_doc";
10
- export * from "./tableHelper";
11
-
12
1
  //
13
2
  export * from "node-opcua-address-space";
14
- export * from "node-opcua-nodesets";
15
- export * from "node-opcua-variant";
16
3
  export * from "node-opcua-assert";
4
+ export * from "node-opcua-assert";
5
+ export * from "node-opcua-basic-types";
6
+ export * from "node-opcua-constants";
7
+ export {
8
+ DataTypeIds,
9
+ MethodIds,
10
+ ObjectIds,
11
+ ObjectTypeIds,
12
+ ReferenceTypeIds,
13
+ VariableIds,
14
+ VariableTypeIds
15
+ } from "node-opcua-constants";
17
16
  export * from "node-opcua-data-model";
18
17
  export * from "node-opcua-nodeid";
18
+ export * from "node-opcua-nodesets";
19
19
  export * from "node-opcua-numeric-range";
20
- export * from "node-opcua-status-code";
21
- export * from "node-opcua-basic-types";
22
- export * from "node-opcua-constants";
23
- export * from "node-opcua-assert";
24
20
  export * from "node-opcua-service-translate-browse-path";
25
-
26
- export { MethodIds, DataTypeIds, ReferenceTypeIds, VariableIds, VariableTypeIds, ObjectTypeIds, ObjectIds } from "node-opcua-constants";
27
-
21
+ export * from "node-opcua-status-code";
28
22
  export {
29
23
  DataTypeDefinition,
30
24
  EnumDefinition,
@@ -32,3 +26,14 @@ export {
32
26
  StructureDefinition,
33
27
  StructureDefinitionOptions
34
28
  } from "node-opcua-types";
29
+ export * from "node-opcua-variant";
30
+ export * from "./addExtensionObjectDataType";
31
+ export * from "./build_model_inner";
32
+ export * from "./displayNodeElement";
33
+ export * from "./generate_markdown_doc";
34
+ export * from "./promoteToMandatory";
35
+ export * from "./setNamespaceMetaData";
36
+ export * from "./symbol";
37
+ export * from "./tableHelper";
38
+ export * from "./to_cvs";
39
+ export * from "./types";
@@ -1,5 +1,6 @@
1
- import {
1
+ import type {
2
2
  BaseNode,
3
+ ModellingRuleType,
3
4
  UADataType,
4
5
  UAMethod,
5
6
  UAObject,
@@ -7,12 +8,11 @@ import {
7
8
  UAReference,
8
9
  UAReferenceType,
9
10
  UAVariable,
10
- UAVariableType,
11
- ModellingRuleType
11
+ UAVariableType
12
12
  } from "node-opcua-address-space";
13
13
  import { NodeClass } from "node-opcua-data-model";
14
- import { makeBrowsePath } from "node-opcua-service-translate-browse-path";
15
14
  import { make_warningLog } from "node-opcua-debug";
15
+ import { makeBrowsePath } from "node-opcua-service-translate-browse-path";
16
16
 
17
17
  import { displayNodeElement } from "./displayNodeElement";
18
18
 
@@ -43,7 +43,7 @@ function findReferenceToNode(node1: BaseNode, node2: BaseNode): UAReference {
43
43
  }
44
44
  }
45
45
 
46
- throw new Error("Internal Error cannot find ref from node " + node1.nodeId.toString() + " " + node2.nodeId.toString());
46
+ throw new Error(`Internal Error cannot find ref from node ${node1.nodeId.toString()} ${node2.nodeId.toString()}`);
47
47
  }
48
48
  return ref;
49
49
  }
@@ -55,26 +55,26 @@ export function getChildInTypeOrBaseType(
55
55
  ): { propInSuperType: UAConcrete; reference: UAReference } {
56
56
  const addressSpace = node.addressSpace;
57
57
 
58
- const subtypeOf = node.subtypeOfObj!;
58
+ const subtypeOf = node.subtypeOfObj;
59
59
  /* c8 ignore next */
60
60
  if (!subtypeOf) {
61
61
  throw new Error("Expecting a super type");
62
62
  }
63
63
 
64
64
  const browseResult = addressSpace.browsePath(makeBrowsePath(subtypeOf.nodeId, `.${namespaceIndex}:${propertyName}`));
65
- const propNodeId = !browseResult.targets || !browseResult.targets[0] ? null : browseResult.targets[0].targetId!;
65
+ const propNodeId = !browseResult.targets || !browseResult.targets[0] ? null : browseResult.targets[0].targetId;
66
66
 
67
67
  /* c8 ignore next */
68
68
  if (!propNodeId) {
69
69
  displayNodeElement(subtypeOf);
70
- throw new Error("property " + propertyName + " do not exists on " + subtypeOf.browseName.toString() + " or any superType");
70
+ throw new Error(`property ${propertyName} do not exists on ${subtypeOf.browseName.toString()} or any superType`);
71
71
  }
72
72
 
73
- const propInSuperType = addressSpace.findNode(propNodeId)! as UAVariable | UAMethod | UAObject;
73
+ const propInSuperType = addressSpace.findNode(propNodeId) as UAVariable | UAMethod | UAObject;
74
74
 
75
75
  /* c8 ignore next */
76
76
  if (!propInSuperType) {
77
- throw new Error("cannot find " + propNodeId.toString());
77
+ throw new Error(`cannot find ${propNodeId.toString()}`);
78
78
  }
79
79
  // replicate property
80
80
  const reference = findReferenceToNode(subtypeOf, propInSuperType);
@@ -94,11 +94,10 @@ export function promoteToMandatory(node: UAObjectType | UAVariableType, property
94
94
  // check mandatory
95
95
  /* c8 ignore next */
96
96
  if (propInSuperType.modellingRule === "Mandatory") {
97
- warningLog("property " + propertyName + " is already Mandatory in super type");
97
+ warningLog(`property ${propertyName} is already Mandatory in super type`);
98
98
  }
99
99
 
100
100
  return promoteChild(node, propertyName, namespaceIndex, "Mandatory");
101
-
102
101
  }
103
102
 
104
103
  export function promoteChild(
@@ -1,46 +1,28 @@
1
- // tslint:disable-next-line: no-var-requires
2
1
  const Table = require("cli-table3");
3
2
 
4
- const chars1 = {
5
- // tslint:disable-next-line: object-literal-sort-keys
6
- "top": "-", "top-mid": "+", "top-left": "+", "top-right": "+"
7
- , "bottom": "-", "bottom-mid": "+", "bottom-left": "+", "bottom-right": "+"
8
- , "left": "|", "left-mid": "+", "mid": "-", "mid-mid": "+"
9
- , "right": "|", "right-mid": "+", "middle": "|"
10
- };
11
-
12
- const chars2 = {
13
- // tslint:disable-next-line: object-literal-sort-keys
14
- "top": " ", "top-mid": " ", "top-left": " ", "top-right": " "
15
- , "bottom": " ", "bottom-mid": " ", "bottom-left": " ", "bottom-right": " "
16
- , "left": "| ", "left-mid": "| ", "mid": "-", "mid-mid": " | "
17
- , "right": " |", "right-mid": "| ", "middle": " | "
18
- };
19
- const chars3 = {
20
- // tslint:disable-next-line: object-literal-sort-keys
21
- "top": "", "top-mid": "", "top-left": "", "top-right": ""
22
- , "bottom": "", "bottom-mid": "", "bottom-left": "", "bottom-right": ""
23
- , "left": "| ", "left-mid": "", "mid": "-", "mid-mid": " | "
24
- , "right": " |", "right-mid": "", "middle": " | "
25
- };
26
- chars1;
27
- chars2;
28
- chars3;
29
-
30
- function toMarkdownTable(table: { head: string[], rows: string[][] }): string {
31
-
3
+ function toMarkdownTable(table: { head: string[]; rows: string[][] }): string {
32
4
  const t = [];
33
5
 
34
- t.push("| " + table.head.join(" | ") + " |");
35
- t.push("| " + table.head.map(() => "---").join(" | ") + " |");
6
+ t.push(`| ${table.head.join(" | ")} |`);
7
+ t.push(`| ${table.head.map(() => "---").join(" | ")} |`);
36
8
  for (const r of table.rows) {
37
- t.push("| " + r.join(" | ") + " |");
9
+ t.push(`| ${r.join(" | ")} |`);
38
10
  }
39
11
  return t.join("\n");
40
12
  }
41
13
 
42
- export class TableHelper {
14
+ interface CellWithContent {
15
+ content: string;
16
+ }
43
17
 
18
+ function extractContent(c: unknown): string {
19
+ if (typeof c === "object" && c !== null && "content" in c) {
20
+ return (c as CellWithContent).content;
21
+ }
22
+ return String(c);
23
+ }
24
+
25
+ export class TableHelper {
44
26
  private readonly rows: string[][] = [];
45
27
  private readonly table: typeof Table;
46
28
  private readonly head: string[];
@@ -48,15 +30,13 @@ export class TableHelper {
48
30
  this.rows = [];
49
31
  // instantiate
50
32
  this.table = new Table({
51
- // chars,
52
- head,
53
- // colWidths: [100, 200, 50, 50,]
33
+ head
54
34
  });
55
35
  this.head = head;
56
36
  }
57
37
  public push(row: unknown[]): void {
58
38
  this.table.push(row);
59
- const row2 = row.map((c: any) => (c.content) ? c.content : c);
39
+ const row2 = row.map(extractContent);
60
40
  this.rows.push(row2);
61
41
  }
62
42
  public toString(): string {
package/source/to_cvs.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Symbols } from "./symbol";
1
+ import type { Symbols } from "./symbol";
2
2
 
3
3
  export function toCSV(arr: Symbols) {
4
4
  const line: string[] = [];
package/source/types.ts CHANGED
@@ -1 +1 @@
1
- export { UANamespaceMetadata } from "node-opcua-address-space";
1
+ export { UANamespaceMetadata } from "node-opcua-address-space";