ts-graphviz 1.4.1-dev.d42db466f → 1.5.1-dev.32bea0347

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
@@ -48,6 +48,8 @@ $ yarn add ts-graphviz
48
48
  $ pnpm add ts-graphviz
49
49
  ```
50
50
 
51
+ > **Note** Want to try before installing? Check out [Runkit](https://npm.runkit.com/ts-graphviz) to see how it works.
52
+
51
53
  ### Deno 🦕
52
54
 
53
55
  [Deno v1.28 and above supports npm](https://deno.land/manual/node/npm_specifiers).
@@ -0,0 +1,25 @@
1
+ const { attribute: _, digraph, toDot } = require('ts-graphviz');
2
+
3
+ const G = digraph('G', (g) => {
4
+ const a = g.node('aa');
5
+ const b = g.node('bb');
6
+ const c = g.node('cc');
7
+ g.edge([a, b, c], {
8
+ [_.color]: 'red',
9
+ });
10
+ g.subgraph('A', (A) => {
11
+ const Aa = A.node('Aaa', {
12
+ [_.color]: 'pink',
13
+ });
14
+
15
+ const Ab = A.node('Abb', {
16
+ [_.color]: 'violet',
17
+ });
18
+ const Ac = A.node('Acc');
19
+ A.edge([Aa.port('a'), Ab, Ac, 'E'], {
20
+ [_.color]: 'red',
21
+ });
22
+ });
23
+ });
24
+
25
+ toDot(G);
@@ -2,26 +2,33 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ function escapeValue(value) {
6
+ if (value !== true) {
7
+ if (typeof value === 'string' && /\s/g.test(value)) {
8
+ return `="${value}"`;
9
+ } else {
10
+ return `=${value}`;
11
+ }
12
+ }
13
+ return '';
14
+ }
5
15
  function* args(options) {
6
16
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
7
17
  if (suppressWarnings) yield '-q';
8
18
  yield `-T${format}`;
9
19
  if (attributes.graph) {
10
20
  for (const [key, value] of Object.entries(attributes.graph)) {
11
- if (value === true) yield `-G${key}`;
12
- else yield `-G${key}="${value}"`;
21
+ yield `-G${key}${escapeValue(value)}`;
13
22
  }
14
23
  }
15
24
  if (attributes.node) {
16
25
  for (const [key, value] of Object.entries(attributes.node)) {
17
- if (value === true) yield `-N${key}`;
18
- else yield `-N${key}="${value}"`;
26
+ yield `-N${key}${escapeValue(value)}`;
19
27
  }
20
28
  }
21
29
  if (attributes.edge) {
22
30
  for (const [key, value] of Object.entries(attributes.edge)) {
23
- if (value === true) yield `-E${key}`;
24
- else yield `-E${key}="${value}"`;
31
+ yield `-E${key}${escapeValue(value)}`;
25
32
  }
26
33
  }
27
34
  if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
@@ -1,23 +1,30 @@
1
+ function escapeValue(value) {
2
+ if (value !== true) {
3
+ if (typeof value === 'string' && /\s/g.test(value)) {
4
+ return `="${value}"`;
5
+ } else {
6
+ return `=${value}`;
7
+ }
8
+ }
9
+ return '';
10
+ }
1
11
  function* args(options) {
2
12
  const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
3
13
  if (suppressWarnings) yield '-q';
4
14
  yield `-T${format}`;
5
15
  if (attributes.graph) {
6
16
  for (const [key, value] of Object.entries(attributes.graph)) {
7
- if (value === true) yield `-G${key}`;
8
- else yield `-G${key}="${value}"`;
17
+ yield `-G${key}${escapeValue(value)}`;
9
18
  }
10
19
  }
11
20
  if (attributes.node) {
12
21
  for (const [key, value] of Object.entries(attributes.node)) {
13
- if (value === true) yield `-N${key}`;
14
- else yield `-N${key}="${value}"`;
22
+ yield `-N${key}${escapeValue(value)}`;
15
23
  }
16
24
  }
17
25
  if (attributes.edge) {
18
26
  for (const [key, value] of Object.entries(attributes.edge)) {
19
- if (value === true) yield `-E${key}`;
20
- else yield `-E${key}="${value}"`;
27
+ yield `-E${key}${escapeValue(value)}`;
21
28
  }
22
29
  }
23
30
  if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-graphviz",
3
- "version": "1.4.1-dev.d42db466f",
3
+ "version": "1.5.1-dev.32bea0347",
4
4
  "author": "kamiazya <yuki@kamiazya.tech>",
5
5
  "description": "Graphviz library for TypeScript.",
6
6
  "homepage": "https://ts-graphviz.github.io/ts-graphviz/",
@@ -81,6 +81,7 @@
81
81
  "engines": {
82
82
  "node": ">=14.16"
83
83
  },
84
+ "runkitExampleFilename": "example/runkit.cjs",
84
85
  "scripts": {
85
86
  "build:peggy": "peggy --plugin ts-pegjs --extra-options-file src/ast/dot-shim/parser/peggy.options.json -o src/ast/dot-shim/parser/_parse.ts src/ast/dot-shim/parser/dot.peggy",
86
87
  "prebuild": "yarn build:peggy",