ts-graphviz 1.8.2 → 2.0.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +307 -0
  2. package/README.md +40 -13
  3. package/lib/adapter.cjs +1 -0
  4. package/lib/adapter.d.ts +1 -0
  5. package/lib/adapter.js +1 -0
  6. package/lib/ast.cjs +1 -0
  7. package/lib/ast.d.ts +1 -0
  8. package/lib/ast.js +1 -0
  9. package/lib/attribute.d.ts +2 -0
  10. package/lib/from-dot.d.ts +10 -0
  11. package/lib/model-factory-builder.d.ts +7 -0
  12. package/lib/model-factory.d.ts +6 -0
  13. package/lib/to-dot.d.ts +7 -0
  14. package/lib/ts-graphviz.cjs +1 -0
  15. package/lib/ts-graphviz.d.ts +7 -0
  16. package/lib/ts-graphviz.js +55 -0
  17. package/lib/types.d.ts +14 -0
  18. package/package.json +53 -96
  19. package/SECURITY.md +0 -5
  20. package/lib/adapter/browser/index.cjs +0 -12
  21. package/lib/adapter/browser/index.d.ts +0 -15
  22. package/lib/adapter/browser/index.js +0 -9
  23. package/lib/adapter/deno/mod.d.ts +0 -13
  24. package/lib/adapter/deno/mod.js +0 -36
  25. package/lib/adapter/node/index.cjs +0 -45
  26. package/lib/adapter/node/index.d.ts +0 -15
  27. package/lib/adapter/node/index.js +0 -42
  28. package/lib/adapter/types/index.cjs +0 -1
  29. package/lib/adapter/types/index.d.ts +0 -134
  30. package/lib/adapter/types/index.js +0 -0
  31. package/lib/adapter/utils/index.cjs +0 -58
  32. package/lib/adapter/utils/index.d.ts +0 -11
  33. package/lib/adapter/utils/index.js +0 -56
  34. package/lib/ast/index.cjs +0 -5775
  35. package/lib/ast/index.d.ts +0 -946
  36. package/lib/ast/index.js +0 -5770
  37. package/lib/common/index.cjs +0 -58
  38. package/lib/common/index.d.ts +0 -4981
  39. package/lib/common/index.js +0 -58
  40. package/lib/core/index.cjs +0 -359
  41. package/lib/core/index.d.ts +0 -347
  42. package/lib/core/index.js +0 -364
  43. package/lib/index.cjs +0 -23
  44. package/lib/index.d.ts +0 -3
  45. package/lib/index.js +0 -2
  46. package/lib/utils/index.cjs +0 -41
  47. package/lib/utils/index.d.ts +0 -34
  48. package/lib/utils/index.js +0 -37
package/package.json CHANGED
@@ -1,125 +1,82 @@
1
1
  {
2
2
  "name": "ts-graphviz",
3
- "version": "1.8.2",
4
- "author": "kamiazya <yuki@kamiazya.tech>",
5
- "description": "Graphviz library for TypeScript.",
6
- "homepage": "https://ts-graphviz.github.io/ts-graphviz/",
7
- "type": "module",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/ts-graphviz/ts-graphviz.git"
11
- },
3
+ "version": "2.0.0",
4
+ "description": "Graphviz library for TypeScript",
12
5
  "keywords": [
13
6
  "graphviz",
14
7
  "dot"
15
8
  ],
9
+ "homepage": "https://ts-graphviz.github.io/ts-graphviz/",
16
10
  "bugs": {
17
11
  "url": "https://github.com/ts-graphviz/ts-graphviz/issues"
18
12
  },
19
- "funding": {
20
- "type": "github",
21
- "url": "https://github.com/sponsors/ts-graphviz"
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/ts-graphviz/ts-graphviz.git",
16
+ "directory": "packages/ts-graphviz"
22
17
  },
23
- "main": "./lib/index.cjs",
24
- "module": "./lib/index.js",
25
- "types": "lib/index.d.ts",
18
+ "funding": [
19
+ {
20
+ "type": "github",
21
+ "url": "https://github.com/sponsors/ts-graphviz"
22
+ },
23
+ {
24
+ "type": "opencollective",
25
+ "url": "https://opencollective.com/ts-graphviz"
26
+ }
27
+ ],
28
+ "license": "MIT",
29
+ "author": "kamiazya <yuki@kamiazya.tech>",
30
+ "sideEffects": true,
31
+ "type": "module",
26
32
  "exports": {
27
33
  ".": {
28
34
  "require": {
29
- "types": "./lib/index.d.ts",
30
- "default": "./lib/index.cjs"
35
+ "types": "./lib/ts-graphviz.d.ts",
36
+ "default": "./lib/ts-graphviz.cjs"
31
37
  },
32
38
  "import": {
33
- "types": "./lib/index.d.ts",
34
- "default": "./lib/index.js"
39
+ "types": "./lib/ts-graphviz.d.ts",
40
+ "default": "./lib/ts-graphviz.js"
35
41
  }
36
42
  },
37
43
  "./ast": {
38
- "require": {
39
- "types": "./lib/ast/index.d.ts",
40
- "default": "./lib/ast/index.cjs"
41
- },
42
- "import": {
43
- "types": "./lib/ast/index.d.ts",
44
- "default": "./lib/ast/index.js"
45
- }
44
+ "types": "./lib/ast.d.ts",
45
+ "require": "./lib/ast.cjs",
46
+ "default": "./lib/ast.js"
46
47
  },
47
48
  "./adapter": {
48
- "browser": {
49
- "require": "./lib/adapter/browser/index.cjs",
50
- "import": "./lib/adapter/browser/index.js",
51
- "types": "./lib/adapter/browser/index.d.ts"
52
- },
53
- "deno": {
54
- "types": "./lib/adapter/deno/mod.d.ts",
55
- "default": "./lib/adapter/deno/mod.js"
56
- },
57
- "node": {
58
- "require": "./lib/adapter/node/index.cjs",
59
- "import": "./lib/adapter/node/index.js",
60
- "types": "./lib/adapter/node/index.d.ts"
61
- },
62
- "default": {
63
- "types": "./lib/adapter/node/index.d.ts",
64
- "require": "./lib/adapter/node/index.cjs",
65
- "import": "./lib/adapter/node/index.js"
66
- }
49
+ "types": "./lib/adapter.d.ts",
50
+ "require": "./lib/adapter.cjs",
51
+ "default": "./lib/adapter.js"
67
52
  },
68
53
  "./package.json": "./package.json"
69
54
  },
70
- "typesVersions": {
71
- "*": {
72
- "ast": [
73
- "lib/ast"
74
- ],
75
- "adapter": [
76
- "lib/adapter/node"
77
- ]
78
- }
55
+ "main": "./lib/ts-graphviz.cjs",
56
+ "module": "./lib/ts-graphviz.js",
57
+ "types": "lib/ts-graphviz.d.ts",
58
+ "dependencies": {
59
+ "@ts-graphviz/adapter": "^2.0.0",
60
+ "@ts-graphviz/ast": "^2.0.0",
61
+ "@ts-graphviz/common": "^2.0.0",
62
+ "@ts-graphviz/core": "^2.0.0"
63
+ },
64
+ "devDependencies": {
65
+ "peggy": "^3.0.2",
66
+ "ts-pegjs": "^4.2.1",
67
+ "typescript": "^5.3.3",
68
+ "vite": "^5.1.3",
69
+ "vite-plugin-dts": "^3.7.3"
79
70
  },
80
- "license": "MIT",
81
71
  "engines": {
82
- "node": ">=14.16"
72
+ "node": ">=18"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public",
76
+ "provenance": true
83
77
  },
84
78
  "runkitExampleFilename": "example/runkit.cjs",
85
79
  "scripts": {
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",
87
- "prebuild": "yarn build:peggy",
88
- "build:deno": "mkdir -p lib/adapter/deno && cp -r src/adapter/deno/* lib/adapter/deno && sed -i \"s/index.ts/index.js/g\" lib/adapter/deno/mod.js && sed -i \"s/index.ts/index.d.ts/g\" lib/adapter/deno/mod.d.ts",
89
- "build:node": "tsc -p tsconfig.build.json --declaration && tsc -p tsconfig.build.json --removeComments && rollup -c",
90
- "build": "yarn build:node && yarn build:deno",
91
- "postbuild": "prettier --write ./lib/**/*.{js,cjs,d.ts}",
92
- "pretest": "yarn build:peggy",
93
- "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
94
- "format": "eslint --ext ts src --fix && prettier --write './**/*.{ts,js,json,yaml}' '!lib'",
95
- "lint": "eslint --ext ts src",
96
- "predoc": "yarn build:peggy",
97
- "doc": "typedoc"
98
- },
99
- "devDependencies": {
100
- "@rollup/plugin-replace": "^5.0.2",
101
- "@types/jest": "^29.4.0",
102
- "@types/jest-specific-snapshot": "^0.5.6",
103
- "@typescript-eslint/eslint-plugin": "^5.49.0",
104
- "@typescript-eslint/parser": "^5.49.0",
105
- "eslint": "^8.32.0",
106
- "eslint-config-prettier": "^8.6.0",
107
- "eslint-plugin-import": "^2.27.5",
108
- "eslint-plugin-jest": "^27.2.1",
109
- "eslint-plugin-prettier": "^4.2.1",
110
- "jest": "^29.4.1",
111
- "jest-snapshot-serializer-raw": "^1.2.0",
112
- "jest-specific-snapshot": "^7.0.0",
113
- "peggy": "^2.0.1",
114
- "prettier": "^2.8.3",
115
- "prettier-plugin-pegjs": "^0.5.0",
116
- "rollup": "^3.11.0",
117
- "rollup-plugin-delete": "^2.0.0",
118
- "rollup-plugin-dts": "5.1.1",
119
- "svgo": "^3.0.2",
120
- "ts-jest": "^29.0.5",
121
- "ts-pegjs": "^3.0.0",
122
- "typedoc": "^0.23.15",
123
- "typescript": "^4.7.4"
80
+ "build": "vite build"
124
81
  }
125
- }
82
+ }
package/SECURITY.md DELETED
@@ -1,5 +0,0 @@
1
- ## Security contact information
2
-
3
- To report a security vulnerability, please use the
4
- [Tidelift security contact](https://tidelift.com/security).
5
- Tidelift will coordinate the fix and disclosure.
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const ERROR_MESSAGE = 'This module cannot be run in a browser.';
4
- function toStream(dot, options) {
5
- throw new Error(ERROR_MESSAGE);
6
- }
7
- function toFile(dot, path, options) {
8
- throw new Error(ERROR_MESSAGE);
9
- }
10
-
11
- exports.toFile = toFile;
12
- exports.toStream = toStream;
@@ -1,15 +0,0 @@
1
- /**
2
- * @module ts-graphviz/adapter
3
- * @beta
4
- */
5
- type Options = any;
6
- /**
7
- * Execute the Graphviz dot command and make a Stream of the results.
8
- */
9
- declare function toStream(dot: string, options?: Options): never;
10
- /**
11
- * Execute the Graphviz dot command and output the results to a file.
12
- */
13
- declare function toFile(dot: string, path: string, options?: Options): never;
14
-
15
- export { Options, toFile, toStream };
@@ -1,9 +0,0 @@
1
- const ERROR_MESSAGE = 'This module cannot be run in a browser.';
2
- function toStream(dot, options) {
3
- throw new Error(ERROR_MESSAGE);
4
- }
5
- function toFile(dot, path, options) {
6
- throw new Error(ERROR_MESSAGE);
7
- }
8
-
9
- export { toFile, toStream };
@@ -1,13 +0,0 @@
1
- import { Options, Format, Layout } from '../types/index.d.ts';
2
-
3
- /**
4
- * Execute the Graphviz dot command and make a Stream of the results.
5
- */
6
- export function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<ReadableStream<Uint8Array>>;
7
-
8
- /**
9
- * Execute the Graphviz dot command and output the results to a file.
10
- */
11
- export function toFile<T extends Layout>(dot: string, path: string, options?: Options<T>): Promise<void>;
12
-
13
- export { Options, Format, Layout };
@@ -1,36 +0,0 @@
1
- import { createCommandAndArgs } from '../utils/index.js';
2
- /**
3
- * Execute the Graphviz dot command and make a Stream of the results.
4
- */
5
- export async function toStream(dot, options) {
6
- const [command, args] = createCommandAndArgs(options);
7
- const cp = new Deno.Command(command, {
8
- args: args,
9
- stdin: 'piped',
10
- stdout: 'piped',
11
- }).spawn();
12
- const stdin = cp.stdin.getWriter();
13
- await stdin.write(new TextEncoder().encode(dot));
14
- await stdin.close();
15
- return cp.stdout;
16
- }
17
-
18
- function open(path) {
19
- try {
20
- return Deno.open(path, { write: true });
21
- } catch (e) {
22
- if (e instanceof Deno.errors.NotFound) {
23
- return Deno.open(path, { createNew: true, write: true });
24
- }
25
- throw e;
26
- }
27
- }
28
-
29
- /**
30
- * Execute the Graphviz dot command and output the results to a file.
31
- */
32
- export async function toFile(dot, path, options) {
33
- const output = await open(path);
34
- const stream = await toStream(dot, options);
35
- await stream.pipeTo(output.writable);
36
- }
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- var node_stream = require('node:stream');
4
- var node_child_process = require('node:child_process');
5
- var index_js = require('../utils/index.cjs');
6
- var node_util = require('node:util');
7
- var node_fs = require('node:fs');
8
-
9
- const pipeline = node_util.promisify(node_stream.pipeline);
10
-
11
- async function toStream(dot, options) {
12
- const [command, args] = index_js.createCommandAndArgs(options ?? {});
13
- return new Promise(async function toStreamInternal(resolve, reject) {
14
- const p = node_child_process.spawn(command, args, { stdio: 'pipe' });
15
- p.on('error', (e) => {
16
- reject(
17
- new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
18
- cause: e,
19
- }),
20
- );
21
- });
22
- const stderrChunks = [];
23
- p.stdout.on('pause', () => p.stdout.resume());
24
- p.stderr.on('data', (chunk) => stderrChunks.push(chunk));
25
- p.stderr.on('pause', () => p.stderr.resume());
26
- const dist = p.stdout.pipe(new node_stream.PassThrough());
27
- p.on('close', async (code, signal) => {
28
- if (code === 0) {
29
- resolve(dist);
30
- } else {
31
- const message = Buffer.concat(stderrChunks).toString();
32
- reject(new Error(`Command "${command}" failed.\nCODE: ${code}\nSIGNAL: ${signal}\nMESSAGE: ${message}`));
33
- }
34
- });
35
- await pipeline(node_stream.Readable.from([dot]), p.stdin);
36
- });
37
- }
38
-
39
- async function toFile(dot, path, options) {
40
- const stream = await toStream(dot, options);
41
- await pipeline(stream, node_fs.createWriteStream(path));
42
- }
43
-
44
- exports.toFile = toFile;
45
- exports.toStream = toStream;
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- import { Layout, Options } from '../types/index.js';
3
- export { Format, Layout, Options } from '../types/index.js';
4
-
5
- /**
6
- * Execute the Graphviz dot command and make a Stream of the results.
7
- */
8
- declare function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<NodeJS.ReadableStream>;
9
-
10
- /**
11
- * Execute the Graphviz dot command and output the results to a file.
12
- */
13
- declare function toFile<T extends Layout>(dot: string, path: string, options?: Options<T>): Promise<void>;
14
-
15
- export { toFile, toStream };
@@ -1,42 +0,0 @@
1
- import { pipeline as pipeline$1, PassThrough, Readable } from 'node:stream';
2
- import { spawn } from 'node:child_process';
3
- import { createCommandAndArgs } from '../utils/index.js';
4
- import { promisify } from 'node:util';
5
- import { createWriteStream } from 'node:fs';
6
-
7
- const pipeline = promisify(pipeline$1);
8
-
9
- async function toStream(dot, options) {
10
- const [command, args] = createCommandAndArgs(options ?? {});
11
- return new Promise(async function toStreamInternal(resolve, reject) {
12
- const p = spawn(command, args, { stdio: 'pipe' });
13
- p.on('error', (e) => {
14
- reject(
15
- new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
16
- cause: e,
17
- }),
18
- );
19
- });
20
- const stderrChunks = [];
21
- p.stdout.on('pause', () => p.stdout.resume());
22
- p.stderr.on('data', (chunk) => stderrChunks.push(chunk));
23
- p.stderr.on('pause', () => p.stderr.resume());
24
- const dist = p.stdout.pipe(new PassThrough());
25
- p.on('close', async (code, signal) => {
26
- if (code === 0) {
27
- resolve(dist);
28
- } else {
29
- const message = Buffer.concat(stderrChunks).toString();
30
- reject(new Error(`Command "${command}" failed.\nCODE: ${code}\nSIGNAL: ${signal}\nMESSAGE: ${message}`));
31
- }
32
- });
33
- await pipeline(Readable.from([dot]), p.stdin);
34
- });
35
- }
36
-
37
- async function toFile(dot, path, options) {
38
- const stream = await toStream(dot, options);
39
- await pipeline(stream, createWriteStream(path));
40
- }
41
-
42
- export { toFile, toStream };
@@ -1 +0,0 @@
1
- 'use strict';
@@ -1,134 +0,0 @@
1
- import {
2
- EdgeAttributesObject,
3
- NodeAttributesObject,
4
- GraphAttributesObject,
5
- SubgraphAttributesObject,
6
- } from '../../common/index.js';
7
- import { $keywords, $keywordsValidation } from '../../utils/index.js';
8
-
9
- type Format = Format.values;
10
- declare namespace Format {
11
- type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
12
- interface $values extends $keywords<'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json'> {}
13
- interface $exclude extends $keywordsValidation {}
14
- }
15
- type Layout = Layout.values;
16
- declare namespace Layout {
17
- type values = Exclude<keyof $values, keyof $exclude | symbol | number>;
18
- interface $values
19
- extends $keywords<'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork'> {}
20
- interface $exclude extends $keywordsValidation {}
21
- }
22
- /**
23
- * NeatoOptions interface provides options for the neato layout.
24
- */
25
- interface NeatoOptions {
26
- layout: 'neato';
27
- /**
28
- * Sets no-op flag in neato.
29
- */
30
- noop?: number;
31
- /**
32
- * Reduce graph.
33
- */
34
- reduce?: boolean;
35
- }
36
- /**
37
- * FdpOptions interface provides options for the fdp layout.
38
- */
39
- interface FdpOptions {
40
- layout: 'fdp';
41
- /**
42
- * Use grid.
43
- *
44
- * @default true
45
- */
46
- grid?: boolean;
47
- /**
48
- * Use old attractive force
49
- *
50
- * @default true
51
- */
52
- oldAttractive?: boolean;
53
- /**
54
- * Set number of iterations.
55
- */
56
- iterations?: number;
57
- /**
58
- * Set unscaled factor
59
- */
60
- unscaledFactor?: number;
61
- /**
62
- * Set overlap expansion factor.
63
- */
64
- overlapExpansionFactor?: number;
65
- /**
66
- * Set temperature.
67
- */
68
- temperature?: number;
69
- }
70
- /**
71
- * @description
72
- * This interface describes an optional parameter called "layout" which is used to set a layout engine.
73
- * The default value for this parameter is 'dot', and it must be an option of the Layout type,
74
- * excluding 'neato' and 'fdp'.
75
- */
76
- interface OtherOptions {
77
- /**
78
- * Set layout engine.
79
- *
80
- * @default 'dot'
81
- */
82
- layout?: Exclude<Layout, 'neato' | 'fdp'>;
83
- }
84
- /**
85
- * This interface represents the CommonOptions for setting output format.
86
- */
87
- interface CommonOptions {
88
- /**
89
- * Set output format.
90
- *
91
- * @default 'svg'
92
- */
93
- format?: Format;
94
- /**
95
- * If true, set level of message suppression (=1).
96
- *
97
- * @default true
98
- */
99
- suppressWarnings?: boolean;
100
- /**
101
- * Path of graphviz dot command.
102
- */
103
- dotCommand?: string;
104
- attributes?: {
105
- /**
106
- * Set edge attribute.
107
- */
108
- edge?: EdgeAttributesObject;
109
- /**
110
- * Set node attribute.
111
- */
112
- node?: NodeAttributesObject;
113
- /**
114
- * Set graph attribute.
115
- */
116
- graph?: GraphAttributesObject & SubgraphAttributesObject;
117
- };
118
- /**
119
- * Scale input
120
- */
121
- scale?: number;
122
- /**
123
- * Use external library.
124
- */
125
- library?: string[];
126
- /**
127
- * Invert y coordinate in output.
128
- */
129
- y?: boolean;
130
- }
131
- type Options<T extends Layout = Layout> = CommonOptions &
132
- (T extends 'neato' ? NeatoOptions : T extends 'fdp' ? FdpOptions : OtherOptions);
133
-
134
- export { CommonOptions, FdpOptions, Format, Layout, NeatoOptions, Options, OtherOptions };
File without changes
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- function escapeValue(value) {
4
- if (value !== true) {
5
- if (typeof value === 'string' && /\s/g.test(value)) {
6
- return `="${value}"`;
7
- } else {
8
- return `=${value}`;
9
- }
10
- }
11
- return '';
12
- }
13
- function* createCommandArgs(options) {
14
- const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
15
- if (suppressWarnings) yield '-q';
16
- yield `-T${format}`;
17
- if (attributes.graph) {
18
- for (const [key, value] of Object.entries(attributes.graph)) {
19
- yield `-G${key}${escapeValue(value)}`;
20
- }
21
- }
22
- if (attributes.node) {
23
- for (const [key, value] of Object.entries(attributes.node)) {
24
- yield `-N${key}${escapeValue(value)}`;
25
- }
26
- }
27
- if (attributes.edge) {
28
- for (const [key, value] of Object.entries(attributes.edge)) {
29
- yield `-E${key}${escapeValue(value)}`;
30
- }
31
- }
32
- if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
33
- if (Array.isArray(library)) for (const lib of library) yield `-l${lib}`;
34
- if (y === true) yield `-y`;
35
- if (typeof options.layout === 'string') {
36
- yield `-K${options.layout}`;
37
- switch (options.layout) {
38
- case 'neato':
39
- const { reduce, noop } = options;
40
- if (reduce === true) yield '-x';
41
- if (typeof noop === 'number') yield `-n${noop}`;
42
- break;
43
- case 'fdp':
44
- const { grid, oldAttractive, iterations, unscaledFactor, overlapExpansionFactor, temperature } = options;
45
- yield ['-L', grid ? '' : 'g', oldAttractive ? 'O' : ''].join('');
46
- if (typeof iterations === 'number') yield `-Ln${iterations}`;
47
- if (typeof unscaledFactor === 'number') yield `-LU${unscaledFactor}`;
48
- if (typeof overlapExpansionFactor === 'number') yield `-LC${overlapExpansionFactor}`;
49
- if (typeof temperature === 'number') yield `-LT${temperature}`;
50
- }
51
- }
52
- }
53
-
54
- function createCommandAndArgs(options) {
55
- return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
56
- }
57
-
58
- exports.createCommandAndArgs = createCommandAndArgs;
@@ -1,11 +0,0 @@
1
- import { Layout, Options } from '../types/index.js';
2
-
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[]];
10
-
11
- export { createCommandAndArgs };
@@ -1,56 +0,0 @@
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
- }
11
- function* createCommandArgs(options) {
12
- const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
13
- if (suppressWarnings) yield '-q';
14
- yield `-T${format}`;
15
- if (attributes.graph) {
16
- for (const [key, value] of Object.entries(attributes.graph)) {
17
- yield `-G${key}${escapeValue(value)}`;
18
- }
19
- }
20
- if (attributes.node) {
21
- for (const [key, value] of Object.entries(attributes.node)) {
22
- yield `-N${key}${escapeValue(value)}`;
23
- }
24
- }
25
- if (attributes.edge) {
26
- for (const [key, value] of Object.entries(attributes.edge)) {
27
- yield `-E${key}${escapeValue(value)}`;
28
- }
29
- }
30
- if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
31
- if (Array.isArray(library)) for (const lib of library) yield `-l${lib}`;
32
- if (y === true) yield `-y`;
33
- if (typeof options.layout === 'string') {
34
- yield `-K${options.layout}`;
35
- switch (options.layout) {
36
- case 'neato':
37
- const { reduce, noop } = options;
38
- if (reduce === true) yield '-x';
39
- if (typeof noop === 'number') yield `-n${noop}`;
40
- break;
41
- case 'fdp':
42
- const { grid, oldAttractive, iterations, unscaledFactor, overlapExpansionFactor, temperature } = options;
43
- yield ['-L', grid ? '' : 'g', oldAttractive ? 'O' : ''].join('');
44
- if (typeof iterations === 'number') yield `-Ln${iterations}`;
45
- if (typeof unscaledFactor === 'number') yield `-LU${unscaledFactor}`;
46
- if (typeof overlapExpansionFactor === 'number') yield `-LC${overlapExpansionFactor}`;
47
- if (typeof temperature === 'number') yield `-LT${temperature}`;
48
- }
49
- }
50
- }
51
-
52
- function createCommandAndArgs(options) {
53
- return [options.dotCommand ?? 'dot', Array.from(createCommandArgs(options))];
54
- }
55
-
56
- export { createCommandAndArgs };