ts-graphviz 1.4.1-dev.d42db466f → 1.5.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.
@@ -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,124 +1,124 @@
1
1
  {
2
- "name": "ts-graphviz",
3
- "version": "1.4.1-dev.d42db466f",
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"
2
+ "name": "ts-graphviz",
3
+ "version": "1.5.0",
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
+ },
12
+ "keywords": [
13
+ "graphviz",
14
+ "dot"
15
+ ],
16
+ "bugs": {
17
+ "url": "https://github.com/ts-graphviz/ts-graphviz/issues"
18
+ },
19
+ "funding": {
20
+ "type": "github",
21
+ "url": "https://github.com/sponsors/kamiazya"
22
+ },
23
+ "main": "./lib/index.cjs",
24
+ "module": "./lib/index.js",
25
+ "types": "lib/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "require": {
29
+ "types": "./lib/index.d.ts",
30
+ "default": "./lib/index.cjs"
31
+ },
32
+ "import": {
33
+ "types": "./lib/index.d.ts",
34
+ "default": "./lib/index.js"
35
+ }
11
36
  },
12
- "keywords": [
13
- "graphviz",
14
- "dot"
15
- ],
16
- "bugs": {
17
- "url": "https://github.com/ts-graphviz/ts-graphviz/issues"
37
+ "./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
+ }
18
46
  },
19
- "funding": {
20
- "type": "github",
21
- "url": "https://github.com/sponsors/kamiazya"
47
+ "./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
+ }
22
67
  },
23
- "main": "./lib/index.cjs",
24
- "module": "./lib/index.js",
25
- "types": "lib/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "require": {
29
- "types": "./lib/index.d.ts",
30
- "default": "./lib/index.cjs"
31
- },
32
- "import": {
33
- "types": "./lib/index.d.ts",
34
- "default": "./lib/index.js"
35
- }
36
- },
37
- "./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
- }
46
- },
47
- "./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
- }
67
- },
68
- "./package.json": "./package.json"
69
- },
70
- "typesVersions": {
71
- "*": {
72
- "ast": [
73
- "lib/ast"
74
- ],
75
- "adapter": [
76
- "lib/adapter/node"
77
- ]
78
- }
79
- },
80
- "license": "MIT",
81
- "engines": {
82
- "node": ">=14.16"
83
- },
84
- "scripts": {
85
- "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
- "prebuild": "yarn build:peggy",
87
- "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",
88
- "build:node": "tsc -p tsconfig.build.json && rollup -c",
89
- "build": "yarn build:node && yarn build:deno",
90
- "postbuild": "prettier --write ./lib/**/*.{js,cjs,d.ts}",
91
- "pretest": "yarn build:peggy",
92
- "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
93
- "format": "eslint --ext ts src --fix && prettier --write './**/*.{ts,js,json,yaml}' '!lib'",
94
- "lint": "eslint --ext ts src",
95
- "predoc": "yarn build:peggy",
96
- "doc": "typedoc"
97
- },
98
- "devDependencies": {
99
- "@rollup/plugin-replace": "^4.0.0",
100
- "@types/jest": "^28.1.6",
101
- "@types/jest-specific-snapshot": "^0.5.6",
102
- "@typescript-eslint/eslint-plugin": "^5.33.0",
103
- "@typescript-eslint/parser": "^5.33.0",
104
- "eslint": "^8.22.0",
105
- "eslint-config-prettier": "^8.5.0",
106
- "eslint-plugin-import": "^2.26.0",
107
- "eslint-plugin-jest": "^26.8.2",
108
- "eslint-plugin-prettier": "^4.2.1",
109
- "jest": "^28.1.3",
110
- "jest-snapshot-serializer-raw": "^1.2.0",
111
- "jest-specific-snapshot": "^5.0.0",
112
- "peggy": "^2.0.1",
113
- "prettier": "^2.7.1",
114
- "prettier-plugin-pegjs": "^0.5.0",
115
- "rollup": "^2.77.3",
116
- "rollup-plugin-delete": "^2.0.0",
117
- "rollup-plugin-dts": "^4.2.2",
118
- "svgo": "^2.8.0",
119
- "ts-jest": "^28.0.7",
120
- "ts-pegjs": "^2.1.0",
121
- "typedoc": "^0.23.15",
122
- "typescript": "^4.7.4"
68
+ "./package.json": "./package.json"
69
+ },
70
+ "typesVersions": {
71
+ "*": {
72
+ "ast": [
73
+ "lib/ast"
74
+ ],
75
+ "adapter": [
76
+ "lib/adapter/node"
77
+ ]
123
78
  }
124
- }
79
+ },
80
+ "license": "MIT",
81
+ "engines": {
82
+ "node": ">=14.16"
83
+ },
84
+ "scripts": {
85
+ "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
+ "prebuild": "yarn build:peggy",
87
+ "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",
88
+ "build:node": "tsc -p tsconfig.build.json && rollup -c",
89
+ "build": "yarn build:node && yarn build:deno",
90
+ "postbuild": "prettier --write ./lib/**/*.{js,cjs,d.ts}",
91
+ "pretest": "yarn build:peggy",
92
+ "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
93
+ "format": "eslint --ext ts src --fix && prettier --write './**/*.{ts,js,json,yaml}' '!lib'",
94
+ "lint": "eslint --ext ts src",
95
+ "predoc": "yarn build:peggy",
96
+ "doc": "typedoc"
97
+ },
98
+ "devDependencies": {
99
+ "@rollup/plugin-replace": "^4.0.0",
100
+ "@types/jest": "^28.1.6",
101
+ "@types/jest-specific-snapshot": "^0.5.6",
102
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
103
+ "@typescript-eslint/parser": "^5.33.0",
104
+ "eslint": "^8.22.0",
105
+ "eslint-config-prettier": "^8.5.0",
106
+ "eslint-plugin-import": "^2.26.0",
107
+ "eslint-plugin-jest": "^26.8.2",
108
+ "eslint-plugin-prettier": "^4.2.1",
109
+ "jest": "^28.1.3",
110
+ "jest-snapshot-serializer-raw": "^1.2.0",
111
+ "jest-specific-snapshot": "^5.0.0",
112
+ "peggy": "^2.0.1",
113
+ "prettier": "^2.7.1",
114
+ "prettier-plugin-pegjs": "^0.5.0",
115
+ "rollup": "^2.77.3",
116
+ "rollup-plugin-delete": "^2.0.0",
117
+ "rollup-plugin-dts": "^4.2.2",
118
+ "svgo": "^2.8.0",
119
+ "ts-jest": "^28.0.7",
120
+ "ts-pegjs": "^2.1.0",
121
+ "typedoc": "^0.23.15",
122
+ "typescript": "^4.7.4"
123
+ }
124
+ }