ts-graphviz 1.5.4 → 1.5.5-dev.02afc3340

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/README.md CHANGED
@@ -545,6 +545,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
545
545
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/murawakimitsuhiro"><img src="https://avatars.githubusercontent.com/u/13833242?v=4?s=100" width="100px;" alt="mrwk"/><br /><sub><b>mrwk</b></sub></a><br /><a href="#question-murawakimitsuhiro" title="Answering Questions">💬</a></td>
546
546
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/svdvonde"><img src="https://avatars.githubusercontent.com/u/2751783?v=4?s=100" width="100px;" alt="svdvonde"/><br /><sub><b>svdvonde</b></sub></a><br /><a href="#question-svdvonde" title="Answering Questions">💬</a></td>
547
547
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/seethroughdev"><img src="https://avatars.githubusercontent.com/u/203779?v=4?s=100" width="100px;" alt="Adam"/><br /><sub><b>Adam</b></sub></a><br /><a href="#question-seethroughdev" title="Answering Questions">💬</a></td>
548
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/trevor-scheer"><img src="https://avatars.githubusercontent.com/u/29644393?v=4?s=100" width="100px;" alt="Trevor Scheer"/><br /><sub><b>Trevor Scheer</b></sub></a><br /><a href="#a11y-trevor-scheer" title="Accessibility">️️️️♿️</a></td>
548
549
  </tr>
549
550
  </tbody>
550
551
  </table>
@@ -1,9 +1,9 @@
1
- import { commandBuilder } from '../utils/index.js';
1
+ import { createCommandAndArgs } from '../utils/index.js';
2
2
  /**
3
3
  * Execute the Graphviz dot command and make a Stream of the results.
4
4
  */
5
5
  export async function toStream(dot, options) {
6
- const [command, args] = commandBuilder(options);
6
+ const [command, args] = createCommandAndArgs(options);
7
7
  const cp = new Deno.Command(command, {
8
8
  args: args,
9
9
  stdin: 'piped',
@@ -17,7 +17,7 @@ const pipeline = node_util.promisify(node_stream.pipeline);
17
17
  * Execute the Graphviz dot command and make a Stream of the results.
18
18
  */
19
19
  async function toStream(dot, options) {
20
- const [command, args] = index_js.commandBuilder(options ?? {});
20
+ const [command, args] = index_js.createCommandAndArgs(options ?? {});
21
21
  return new Promise(async function toStreamInternal(resolve, reject) {
22
22
  const p = node_child_process.spawn(command, args, { stdio: 'pipe' });
23
23
  // error handling
@@ -1,6 +1,6 @@
1
1
  import { pipeline as pipeline$1, PassThrough, Readable } from 'node:stream';
2
2
  import { spawn } from 'node:child_process';
3
- import { commandBuilder } from '../utils/index.js';
3
+ import { createCommandAndArgs } from '../utils/index.js';
4
4
  import { promisify } from 'node:util';
5
5
  import { createWriteStream } from 'node:fs';
6
6
 
@@ -15,7 +15,7 @@ const pipeline = promisify(pipeline$1);
15
15
  * Execute the Graphviz dot command and make a Stream of the results.
16
16
  */
17
17
  async function toStream(dot, options) {
18
- const [command, args] = commandBuilder(options ?? {});
18
+ const [command, args] = createCommandAndArgs(options ?? {});
19
19
  return new Promise(async function toStreamInternal(resolve, reject) {
20
20
  const p = spawn(command, args, { stdio: 'pipe' });
21
21
  // error handling
@@ -7,6 +7,9 @@ import {
7
7
 
8
8
  type Format = 'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json';
9
9
  type Layout = 'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork';
10
+ /**
11
+ * NeatoOptions interface provides options for the neato layout.
12
+ */
10
13
  interface NeatoOptions {
11
14
  layout: 'neato';
12
15
  /**
@@ -18,6 +21,9 @@ interface NeatoOptions {
18
21
  */
19
22
  reduce?: boolean;
20
23
  }
24
+ /**
25
+ * FdpOptions interface provides options for the fdp layout.
26
+ */
21
27
  interface FdpOptions {
22
28
  layout: 'fdp';
23
29
  /**
@@ -49,6 +55,12 @@ interface FdpOptions {
49
55
  */
50
56
  temperature?: number;
51
57
  }
58
+ /**
59
+ * @description
60
+ * This interface describes an optional parameter called "layout" which is used to set a layout engine.
61
+ * The default value for this parameter is 'dot', and it must be an option of the Layout type,
62
+ * excluding 'neato' and 'fdp'.
63
+ */
52
64
  interface OtherOptions {
53
65
  /**
54
66
  * Set layout engine.
@@ -57,6 +69,9 @@ interface OtherOptions {
57
69
  */
58
70
  layout?: Exclude<Layout, 'neato' | 'fdp'>;
59
71
  }
72
+ /**
73
+ * This interface represents the CommonOptions for setting output format.
74
+ */
60
75
  interface CommonOptions {
61
76
  /**
62
77
  * Set output format.
@@ -1,5 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * escapeValue is a function that escapes a given Attribute value of a given AttributeKey.
5
+ * It checks the type of the value and adds quotes if the value is of type string and contains whitespace.
6
+ *
7
+ * @param value The value of an Attribute of type T that extends AttributeKey
8
+ * @returns The escaped Attribute value
9
+ */
3
10
  function escapeValue(value) {
4
11
  if (value !== true) {
5
12
  if (typeof value === 'string' && /\s/g.test(value)) {
@@ -10,7 +17,14 @@ function escapeValue(value) {
10
17
  }
11
18
  return '';
12
19
  }
13
- function* args(options) {
20
+ /**
21
+ * createCommandArgs is a function that creates command arguments from a given Options object.
22
+ * It reads the properties of the Options object and creates corresponding command line arguments accordingly.
23
+ *
24
+ * @param options The Options object used to create command arguments
25
+ * @returns A generator that yields strings for command arguments
26
+ */
27
+ function* createCommandArgs(options) {
14
28
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
15
29
  if (suppressWarnings) yield '-q';
16
30
  yield `-T${format}`;
@@ -50,8 +64,15 @@ function* args(options) {
50
64
  }
51
65
  }
52
66
  }
53
- function commandBuilder(options) {
54
- return [options.dotCommand ?? 'dot', Array.from(args(options))];
67
+
68
+ /**
69
+ * createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
70
+ *
71
+ * @param options Options to create the command and args from.
72
+ * @returns A tuple containing the command and an array of arguments.
73
+ */
74
+ function createCommandAndArgs(options) {
75
+ return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
55
76
  }
56
77
 
57
- exports.commandBuilder = commandBuilder;
78
+ exports.createCommandAndArgs = createCommandAndArgs;
@@ -1,5 +1,11 @@
1
1
  import { Layout, Options } from '../types/index.js';
2
2
 
3
- declare function commandBuilder<T extends Layout>(options: Options<T>): [command: string, args: string[]];
3
+ /**
4
+ * createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
5
+ *
6
+ * @param options Options to create the command and args from.
7
+ * @returns A tuple containing the command and an array of arguments.
8
+ */
9
+ declare function createCommandAndArgs<T extends Layout>(options: Options<T>): [command: string, args: string[]];
4
10
 
5
- export { commandBuilder };
11
+ export { createCommandAndArgs };
@@ -1,3 +1,10 @@
1
+ /**
2
+ * escapeValue is a function that escapes a given Attribute value of a given AttributeKey.
3
+ * It checks the type of the value and adds quotes if the value is of type string and contains whitespace.
4
+ *
5
+ * @param value The value of an Attribute of type T that extends AttributeKey
6
+ * @returns The escaped Attribute value
7
+ */
1
8
  function escapeValue(value) {
2
9
  if (value !== true) {
3
10
  if (typeof value === 'string' && /\s/g.test(value)) {
@@ -8,7 +15,14 @@ function escapeValue(value) {
8
15
  }
9
16
  return '';
10
17
  }
11
- function* args(options) {
18
+ /**
19
+ * createCommandArgs is a function that creates command arguments from a given Options object.
20
+ * It reads the properties of the Options object and creates corresponding command line arguments accordingly.
21
+ *
22
+ * @param options The Options object used to create command arguments
23
+ * @returns A generator that yields strings for command arguments
24
+ */
25
+ function* createCommandArgs(options) {
12
26
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
13
27
  if (suppressWarnings) yield '-q';
14
28
  yield `-T${format}`;
@@ -48,8 +62,15 @@ function* args(options) {
48
62
  }
49
63
  }
50
64
  }
51
- function commandBuilder(options) {
52
- return [options.dotCommand ?? 'dot', Array.from(args(options))];
65
+
66
+ /**
67
+ * createCommandAndArgs creates a command and an array of arguments, based on the given {@link Options}.
68
+ *
69
+ * @param options Options to create the command and args from.
70
+ * @returns A tuple containing the command and an array of arguments.
71
+ */
72
+ function createCommandAndArgs(options) {
73
+ return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
53
74
  }
54
75
 
55
- export { commandBuilder };
76
+ export { createCommandAndArgs };
package/lib/ast/index.cjs CHANGED
@@ -4,17 +4,34 @@ var index_js = require('../utils/index.cjs');
4
4
  var index_js$1 = require('../common/index.cjs');
5
5
 
6
6
  /**
7
+ * Builder is an ASTBuilder that provides a method to create an ASTNode.
8
+ *
7
9
  * @group Create AST
8
10
  */
9
11
  class Builder {
10
12
  options;
11
- /** @internal */
13
+ /**
14
+ * Get the current file range or null
15
+ * @internal
16
+ */
12
17
  getLocation() {
13
18
  return this.options?.locationFunction?.() ?? null;
14
19
  }
20
+ /**
21
+ * Constructor of Builder
22
+ * @param options - Options to initialize Builder
23
+ */
15
24
  constructor(options) {
16
25
  this.options = options;
17
26
  }
27
+ /**
28
+ * Create an {@link ASTNode} of the specified type
29
+ *
30
+ * @param type - Type of the {@link ASTNode}
31
+ * @param props - Properties of the {@link ASTNode}
32
+ * @param children - Children of the {@link ASTNode}
33
+ * @returns An {@link ASTNode}
34
+ */
18
35
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
36
  createElement(type, props, children) {
20
37
  return {
@@ -27,7 +44,13 @@ class Builder {
27
44
  }
28
45
 
29
46
  /**
47
+ * Create an {@link ASTNode} of the specified type
48
+ *
49
+ * @param type - Type of the {@link ASTNode}
50
+ * @param props - Properties of the {@link ASTNode}
51
+ * @param children - Children of the {@link ASTNode}
30
52
  * @group Create AST
53
+ * @returns An {@link ASTNode}
31
54
  */
32
55
  const createElement = Builder.prototype.createElement.bind(new Builder());
33
56
 
@@ -266,15 +289,24 @@ const defaultPlugins$2 = [
266
289
  ];
267
290
 
268
291
  /**
292
+ * Printer is a class responsible for converting an AST into a DOT string.
269
293
  * @group Convert AST to DOT
270
294
  */
271
295
  class Printer {
272
296
  options;
273
297
  /** @internal */
274
298
  #plugins = [...defaultPlugins$2];
299
+ /**
300
+ * @param options Options to be used when generating the DOT string.
301
+ */
275
302
  constructor(options = {}) {
276
303
  this.options = options;
277
304
  }
305
+ /**
306
+ * Generates a DOT string from an ASTNode.
307
+ * @param ast The ASTNode to be converted into a DOT string.
308
+ * @returns The DOT string generated from the ASTNode.
309
+ */
278
310
  print(ast) {
279
311
  const plugins = [...this.#plugins];
280
312
  const { indentSize = 2, indentStyle = 'space', endOfLine = 'lf' } = this.options;
@@ -297,10 +329,11 @@ class Printer {
297
329
  }
298
330
 
299
331
  /**
300
- * Stringify Graphviz AST Node.
332
+ * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
301
333
  *
302
- * @param ast Graphviz AST node.
303
- * @returns DOT language string.
334
+ * @param ast Graphviz AST node that is to be converted.
335
+ * @param options PrintOptions object containing formatting options.
336
+ * @returns A string in DOT language.
304
337
  * @group Convert AST to DOT
305
338
  */
306
339
  function stringify(ast, options) {
@@ -5563,6 +5596,8 @@ const SubgraphPlugin$1 = {
5563
5596
  const defaultPlugins$1 = [AttributeListPlugin, EdgePlugin$1, NodePlugin$1, GraphPlugin$1, SubgraphPlugin$1];
5564
5597
 
5565
5598
  /**
5599
+ * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
5600
+ *
5566
5601
  * @group Convert Model to AST
5567
5602
  */
5568
5603
  class FromModelConverter {
@@ -5572,6 +5607,12 @@ class FromModelConverter {
5572
5607
  constructor(options = {}) {
5573
5608
  this.options = options;
5574
5609
  }
5610
+ /**
5611
+ * Converts a DotObjectModel into an AST.
5612
+ *
5613
+ * @param model The {@link DotObjectModel} to be converted.
5614
+ * @returns The AST generated from the model.
5615
+ */
5575
5616
  convert(model) {
5576
5617
  const plugins = [...this.#plugins];
5577
5618
  const { commentKind = 'Slash' } = this.options;
@@ -5591,6 +5632,12 @@ class FromModelConverter {
5591
5632
  }
5592
5633
 
5593
5634
  /**
5635
+ * A function used to convert a DotObjectModel into an AST.
5636
+ *
5637
+ * @param model - The {@link DotObjectModel} to be converted.
5638
+ * @param options - An optional {@link ConvertFromModelOptions} object.
5639
+ * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
5640
+ *
5594
5641
  * @group Convert Model to AST
5595
5642
  */
5596
5643
  function fromModel(model, options) {