@graphty/graph-io 0.3.18 → 0.3.20

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 (235) hide show
  1. package/README.md +80 -2
  2. package/dist/chunks/{escape-D-gZWO26.js → escape-B-tkk_Cl.js} +74 -16
  3. package/dist/chunks/escape-B-tkk_Cl.js.map +1 -0
  4. package/dist/chunks/{writer-GAdltGmC.js → export-Bh60Dv-n.js} +7 -252
  5. package/dist/chunks/export-Bh60Dv-n.js.map +1 -0
  6. package/dist/chunks/exporter-BGrsWamJ.js +736 -0
  7. package/dist/chunks/exporter-BGrsWamJ.js.map +1 -0
  8. package/dist/chunks/exporter-DIeGJXAZ.js +834 -0
  9. package/dist/chunks/exporter-DIeGJXAZ.js.map +1 -0
  10. package/dist/chunks/{importer-Br_QeAeE.js → importer-BWY2FFc5.js} +28 -6
  11. package/dist/chunks/importer-BWY2FFc5.js.map +1 -0
  12. package/dist/chunks/importer-BaQpCEcJ.js +2194 -0
  13. package/dist/chunks/importer-BaQpCEcJ.js.map +1 -0
  14. package/dist/chunks/importer-DD-xv9_Y.js +1471 -0
  15. package/dist/chunks/importer-DD-xv9_Y.js.map +1 -0
  16. package/dist/chunks/{importer-aNJfe0qu.js → importer-DEcKhsmQ.js} +2 -2
  17. package/dist/chunks/{importer-aNJfe0qu.js.map → importer-DEcKhsmQ.js.map} +1 -1
  18. package/dist/chunks/{importer-DHagxvDD.js → importer-DIrbbnAf.js} +6 -4
  19. package/dist/chunks/{importer-DHagxvDD.js.map → importer-DIrbbnAf.js.map} +1 -1
  20. package/dist/chunks/importer-D_e7e7LX.js +3055 -0
  21. package/dist/chunks/importer-D_e7e7LX.js.map +1 -0
  22. package/dist/chunks/{importer-Du5crN9l.js → importer-Wv4C4gaF.js} +278 -82
  23. package/dist/chunks/importer-Wv4C4gaF.js.map +1 -0
  24. package/dist/chunks/importer-vi3bSdtw.js +1713 -0
  25. package/dist/chunks/importer-vi3bSdtw.js.map +1 -0
  26. package/dist/chunks/{importer-d0uQxFp6.js → importer-zGLo8Dg_.js} +6 -4
  27. package/dist/chunks/{importer-d0uQxFp6.js.map → importer-zGLo8Dg_.js.map} +1 -1
  28. package/dist/chunks/json-elements-DDS8N2Dd.js +779 -0
  29. package/dist/chunks/json-elements-DDS8N2Dd.js.map +1 -0
  30. package/dist/chunks/{records-Bk9jgodz.js → records-dbRkxwaq.js} +2 -2
  31. package/dist/chunks/{records-Bk9jgodz.js.map → records-dbRkxwaq.js.map} +1 -1
  32. package/dist/chunks/{report-BOk0p5y8.js → report-B1z4WT9e.js} +143 -111
  33. package/dist/chunks/{report-BOk0p5y8.js.map → report-B1z4WT9e.js.map} +1 -1
  34. package/dist/chunks/weights-Dzba96G3.js +176 -0
  35. package/dist/chunks/weights-Dzba96G3.js.map +1 -0
  36. package/dist/chunks/writer-C7flM-Ih.js +77 -0
  37. package/dist/chunks/writer-C7flM-Ih.js.map +1 -0
  38. package/dist/csv.js +6 -4
  39. package/dist/csv.js.map +1 -1
  40. package/dist/cx.d.ts +1 -0
  41. package/dist/cx.js +6 -0
  42. package/dist/cx.js.map +1 -0
  43. package/dist/cx2.d.ts +1 -0
  44. package/dist/cx2.js +10 -0
  45. package/dist/cx2.js.map +1 -0
  46. package/dist/cys.d.ts +1 -0
  47. package/dist/cys.js +6 -0
  48. package/dist/cys.js.map +1 -0
  49. package/dist/dot.js +1 -1
  50. package/dist/gexf.js +16 -4
  51. package/dist/gexf.js.map +1 -1
  52. package/dist/gml.js +13 -14
  53. package/dist/gml.js.map +1 -1
  54. package/dist/graph-io.js +302 -399
  55. package/dist/graph-io.js.map +1 -1
  56. package/dist/graphml.js +1 -1
  57. package/dist/json.js +1 -1
  58. package/dist/neo4j.js +6 -4
  59. package/dist/neo4j.js.map +1 -1
  60. package/dist/obo.js +1 -1
  61. package/dist/pajek.js +1 -1
  62. package/dist/src/common/cell-budget.d.ts +84 -0
  63. package/dist/src/common/cell-budget.d.ts.map +1 -0
  64. package/dist/src/common/cell-budget.js +138 -0
  65. package/dist/src/common/cell-budget.js.map +1 -0
  66. package/dist/src/common/input.d.ts +10 -0
  67. package/dist/src/common/input.d.ts.map +1 -1
  68. package/dist/src/common/input.js +39 -0
  69. package/dist/src/common/input.js.map +1 -1
  70. package/dist/src/common/json-elements.d.ts +286 -0
  71. package/dist/src/common/json-elements.d.ts.map +1 -0
  72. package/dist/src/common/json-elements.js +926 -0
  73. package/dist/src/common/json-elements.js.map +1 -0
  74. package/dist/src/common/options.d.ts +6 -0
  75. package/dist/src/common/options.d.ts.map +1 -1
  76. package/dist/src/common/options.js +1 -1
  77. package/dist/src/common/options.js.map +1 -1
  78. package/dist/src/common/xml.d.ts +37 -3
  79. package/dist/src/common/xml.d.ts.map +1 -1
  80. package/dist/src/common/xml.js +86 -6
  81. package/dist/src/common/xml.js.map +1 -1
  82. package/dist/src/common/zip.d.ts +92 -0
  83. package/dist/src/common/zip.d.ts.map +1 -0
  84. package/dist/src/common/zip.js +399 -0
  85. package/dist/src/common/zip.js.map +1 -0
  86. package/dist/src/formats/cx/importer.d.ts +133 -0
  87. package/dist/src/formats/cx/importer.d.ts.map +1 -0
  88. package/dist/src/formats/cx/importer.js +2220 -0
  89. package/dist/src/formats/cx/importer.js.map +1 -0
  90. package/dist/src/formats/cx/index.d.ts +7 -0
  91. package/dist/src/formats/cx/index.d.ts.map +1 -0
  92. package/dist/src/formats/cx/index.js +7 -0
  93. package/dist/src/formats/cx/index.js.map +1 -0
  94. package/dist/src/formats/cx2/exporter.d.ts +59 -0
  95. package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
  96. package/dist/src/formats/cx2/exporter.js +864 -0
  97. package/dist/src/formats/cx2/exporter.js.map +1 -0
  98. package/dist/src/formats/cx2/importer.d.ts +169 -0
  99. package/dist/src/formats/cx2/importer.d.ts.map +1 -0
  100. package/dist/src/formats/cx2/importer.js +1652 -0
  101. package/dist/src/formats/cx2/importer.js.map +1 -0
  102. package/dist/src/formats/cx2/index.d.ts +7 -0
  103. package/dist/src/formats/cx2/index.d.ts.map +1 -0
  104. package/dist/src/formats/cx2/index.js +7 -0
  105. package/dist/src/formats/cx2/index.js.map +1 -0
  106. package/dist/src/formats/cys/constants.d.ts +68 -0
  107. package/dist/src/formats/cys/constants.d.ts.map +1 -0
  108. package/dist/src/formats/cys/constants.js +76 -0
  109. package/dist/src/formats/cys/constants.js.map +1 -0
  110. package/dist/src/formats/cys/importer.d.ts +38 -0
  111. package/dist/src/formats/cys/importer.d.ts.map +1 -0
  112. package/dist/src/formats/cys/importer.js +830 -0
  113. package/dist/src/formats/cys/importer.js.map +1 -0
  114. package/dist/src/formats/cys/index.d.ts +7 -0
  115. package/dist/src/formats/cys/index.d.ts.map +1 -0
  116. package/dist/src/formats/cys/index.js +7 -0
  117. package/dist/src/formats/cys/index.js.map +1 -0
  118. package/dist/src/formats/cys/session.d.ts +132 -0
  119. package/dist/src/formats/cys/session.d.ts.map +1 -0
  120. package/dist/src/formats/cys/session.js +315 -0
  121. package/dist/src/formats/cys/session.js.map +1 -0
  122. package/dist/src/formats/cys/tables.d.ts +90 -0
  123. package/dist/src/formats/cys/tables.d.ts.map +1 -0
  124. package/dist/src/formats/cys/tables.js +293 -0
  125. package/dist/src/formats/cys/tables.js.map +1 -0
  126. package/dist/src/formats/dot/exporter.d.ts +2 -0
  127. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  128. package/dist/src/formats/dot/exporter.js +12 -0
  129. package/dist/src/formats/dot/exporter.js.map +1 -1
  130. package/dist/src/formats/dot/importer.js +6 -2
  131. package/dist/src/formats/dot/importer.js.map +1 -1
  132. package/dist/src/formats/gexf/exporter.d.ts +2 -0
  133. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  134. package/dist/src/formats/gexf/exporter.js +6 -0
  135. package/dist/src/formats/gexf/exporter.js.map +1 -1
  136. package/dist/src/formats/gexf/importer.d.ts +0 -2
  137. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  138. package/dist/src/formats/gexf/importer.js +1 -3
  139. package/dist/src/formats/gexf/importer.js.map +1 -1
  140. package/dist/src/formats/gexf/index.d.ts +1 -1
  141. package/dist/src/formats/gexf/index.js +2 -2
  142. package/dist/src/formats/gexf/index.js.map +1 -1
  143. package/dist/src/formats/gml/exporter.d.ts +0 -8
  144. package/dist/src/formats/gml/exporter.d.ts.map +1 -1
  145. package/dist/src/formats/gml/exporter.js +8 -18
  146. package/dist/src/formats/gml/exporter.js.map +1 -1
  147. package/dist/src/formats/json/importer.d.ts.map +1 -1
  148. package/dist/src/formats/json/importer.js +6 -104
  149. package/dist/src/formats/json/importer.js.map +1 -1
  150. package/dist/src/formats/xgmml/columns.d.ts +152 -0
  151. package/dist/src/formats/xgmml/columns.d.ts.map +1 -0
  152. package/dist/src/formats/xgmml/columns.js +593 -0
  153. package/dist/src/formats/xgmml/columns.js.map +1 -0
  154. package/dist/src/formats/xgmml/constants.d.ts +196 -0
  155. package/dist/src/formats/xgmml/constants.d.ts.map +1 -0
  156. package/dist/src/formats/xgmml/constants.js +197 -0
  157. package/dist/src/formats/xgmml/constants.js.map +1 -0
  158. package/dist/src/formats/xgmml/document.d.ts +361 -0
  159. package/dist/src/formats/xgmml/document.d.ts.map +1 -0
  160. package/dist/src/formats/xgmml/document.js +695 -0
  161. package/dist/src/formats/xgmml/document.js.map +1 -0
  162. package/dist/src/formats/xgmml/emit.d.ts +341 -0
  163. package/dist/src/formats/xgmml/emit.d.ts.map +1 -0
  164. package/dist/src/formats/xgmml/emit.js +1275 -0
  165. package/dist/src/formats/xgmml/emit.js.map +1 -0
  166. package/dist/src/formats/xgmml/exporter.d.ts +24 -0
  167. package/dist/src/formats/xgmml/exporter.d.ts.map +1 -0
  168. package/dist/src/formats/xgmml/exporter.js +999 -0
  169. package/dist/src/formats/xgmml/exporter.js.map +1 -0
  170. package/dist/src/formats/xgmml/importer.d.ts +58 -0
  171. package/dist/src/formats/xgmml/importer.d.ts.map +1 -0
  172. package/dist/src/formats/xgmml/importer.js +360 -0
  173. package/dist/src/formats/xgmml/importer.js.map +1 -0
  174. package/dist/src/formats/xgmml/index.d.ts +8 -0
  175. package/dist/src/formats/xgmml/index.d.ts.map +1 -0
  176. package/dist/src/formats/xgmml/index.js +8 -0
  177. package/dist/src/formats/xgmml/index.js.map +1 -0
  178. package/dist/src/formats/xgmml/values.d.ts +60 -0
  179. package/dist/src/formats/xgmml/values.d.ts.map +1 -0
  180. package/dist/src/formats/xgmml/values.js +148 -0
  181. package/dist/src/formats/xgmml/values.js.map +1 -0
  182. package/dist/src/index.d.ts +4 -0
  183. package/dist/src/index.d.ts.map +1 -1
  184. package/dist/src/index.js +4 -0
  185. package/dist/src/index.js.map +1 -1
  186. package/dist/src/registry.d.ts +7 -0
  187. package/dist/src/registry.d.ts.map +1 -1
  188. package/dist/src/registry.js +30 -10
  189. package/dist/src/registry.js.map +1 -1
  190. package/dist/src/sniff.d.ts +1 -1
  191. package/dist/src/sniff.d.ts.map +1 -1
  192. package/dist/src/sniff.js +4 -0
  193. package/dist/src/sniff.js.map +1 -1
  194. package/dist/xgmml.d.ts +1 -0
  195. package/dist/xgmml.js +9 -0
  196. package/dist/xgmml.js.map +1 -0
  197. package/package.json +25 -2
  198. package/src/common/cell-budget.ts +170 -0
  199. package/src/common/input.ts +40 -0
  200. package/src/common/json-elements.ts +1147 -0
  201. package/src/common/options.ts +1 -1
  202. package/src/common/xml.ts +127 -6
  203. package/src/common/zip.ts +472 -0
  204. package/src/formats/cx/importer.ts +2733 -0
  205. package/src/formats/cx/index.ts +7 -0
  206. package/src/formats/cx2/exporter.ts +1036 -0
  207. package/src/formats/cx2/importer.ts +2187 -0
  208. package/src/formats/cx2/index.ts +7 -0
  209. package/src/formats/cys/constants.ts +99 -0
  210. package/src/formats/cys/importer.ts +1100 -0
  211. package/src/formats/cys/index.ts +7 -0
  212. package/src/formats/cys/session.ts +428 -0
  213. package/src/formats/cys/tables.ts +400 -0
  214. package/src/formats/dot/exporter.ts +17 -0
  215. package/src/formats/dot/importer.ts +6 -2
  216. package/src/formats/gexf/exporter.ts +11 -0
  217. package/src/formats/gexf/importer.ts +1 -2
  218. package/src/formats/gexf/index.ts +1 -1
  219. package/src/formats/gml/exporter.ts +8 -19
  220. package/src/formats/json/importer.ts +6 -105
  221. package/src/formats/xgmml/columns.ts +747 -0
  222. package/src/formats/xgmml/constants.ts +265 -0
  223. package/src/formats/xgmml/document.ts +975 -0
  224. package/src/formats/xgmml/emit.ts +1563 -0
  225. package/src/formats/xgmml/exporter.ts +1215 -0
  226. package/src/formats/xgmml/importer.ts +491 -0
  227. package/src/formats/xgmml/index.ts +8 -0
  228. package/src/formats/xgmml/values.ts +183 -0
  229. package/src/index.ts +19 -0
  230. package/src/registry.ts +46 -15
  231. package/src/sniff.ts +18 -1
  232. package/dist/chunks/escape-D-gZWO26.js.map +0 -1
  233. package/dist/chunks/importer-Br_QeAeE.js.map +0 -1
  234. package/dist/chunks/importer-Du5crN9l.js.map +0 -1
  235. package/dist/chunks/writer-GAdltGmC.js.map +0 -1
@@ -0,0 +1,176 @@
1
+ import { GraphFormatError } from "@graphty/graph-format";
2
+ import { aH as parseDecimalText } from "./report-B1z4WT9e.js";
3
+ function formatF32(value) {
4
+ if (!Number.isFinite(value)) {
5
+ return String(value);
6
+ }
7
+ if (value === 0) {
8
+ return Object.is(value, -0) ? "-0" : "0";
9
+ }
10
+ for (let digits = 1; digits <= 9; digits++) {
11
+ const text = value.toPrecision(digits);
12
+ if (Math.fround(Number(text)) === value) {
13
+ return String(Number(text));
14
+ }
15
+ }
16
+ return String(value);
17
+ }
18
+ function formatF64(value) {
19
+ return Object.is(value, -0) ? "-0" : String(value);
20
+ }
21
+ function formatDecimal(value, dtype = "f64") {
22
+ if (!Number.isFinite(value)) {
23
+ return String(value);
24
+ }
25
+ if (Object.is(value, -0)) {
26
+ return "-0.0";
27
+ }
28
+ const text = formatNumber(value, dtype);
29
+ return text.includes(".") || text.includes("e") ? text : `${text}.0`;
30
+ }
31
+ function formatGmlReal(value, dtype = "f64") {
32
+ if (Number.isNaN(value)) {
33
+ return "NAN";
34
+ }
35
+ if (!Number.isFinite(value)) {
36
+ return value > 0 ? "+INF" : "-INF";
37
+ }
38
+ const text = formatDecimal(value, dtype);
39
+ if (text.includes(".")) {
40
+ return text;
41
+ }
42
+ const e = text.indexOf("e");
43
+ return `${text.slice(0, e)}.0${text.slice(e)}`;
44
+ }
45
+ function formatInteger(value) {
46
+ if (Number.isSafeInteger(value) || !Number.isFinite(value)) {
47
+ return String(value);
48
+ }
49
+ return BigInt(value).toString();
50
+ }
51
+ function formatNumber(value, dtype) {
52
+ return dtype === "f32" ? formatF32(value) : formatF64(value);
53
+ }
54
+ const DEFAULT_WEIGHT = 1;
55
+ function isWeightField(name, weightFrom) {
56
+ return weightFrom !== null && name === weightFrom;
57
+ }
58
+ function parseWeightText(text) {
59
+ const trimmed = text.trim();
60
+ if (trimmed.length === 0) {
61
+ return void 0;
62
+ }
63
+ let value;
64
+ try {
65
+ value = parseDecimalText(trimmed);
66
+ } catch (err) {
67
+ throw invalidWeight(text, err);
68
+ }
69
+ if (Number.isNaN(value)) {
70
+ throw invalidWeight(text, null);
71
+ }
72
+ return value;
73
+ }
74
+ function weightFromValue(value) {
75
+ if (value === void 0 || value === null) {
76
+ return void 0;
77
+ }
78
+ if (typeof value === "number") {
79
+ if (Number.isNaN(value)) {
80
+ throw invalidWeight(value, null);
81
+ }
82
+ return value;
83
+ }
84
+ if (typeof value === "string") {
85
+ return parseWeightText(value);
86
+ }
87
+ throw invalidWeight(value, null);
88
+ }
89
+ function invalidWeight(value, cause) {
90
+ let shown;
91
+ switch (typeof value) {
92
+ case "string":
93
+ shown = JSON.stringify(value);
94
+ break;
95
+ case "number":
96
+ shown = String(value);
97
+ break;
98
+ default:
99
+ shown = typeof value;
100
+ }
101
+ return new GraphFormatError("E_INVALID_WEIGHT", `invalid edge weight ${shown}`, {
102
+ value: typeof value === "object" ? typeof value : value,
103
+ cause: cause instanceof Error ? cause.message : null
104
+ });
105
+ }
106
+ const NEGATIVE_ZERO_TEXT = "-0";
107
+ const NUMERIC_DTYPES = /* @__PURE__ */ new Set(["f32", "f64", "i32", "u32", "u8"]);
108
+ function weightFormatter(dtype) {
109
+ switch (dtype) {
110
+ case "f32":
111
+ return formatF32;
112
+ case "f64":
113
+ return formatF64;
114
+ default:
115
+ return formatInteger;
116
+ }
117
+ }
118
+ function explicitWeights(snapshot) {
119
+ const shadowColumn = snapshot.edges.byRole("weight");
120
+ const shadow = shadowColumn !== null && NUMERIC_DTYPES.has(shadowColumn.dtype) ? shadowColumn : null;
121
+ if (shadow !== null) {
122
+ const dtype = shadow.dtype === "f32" ? "f32" : "f64";
123
+ const format = weightFormatter(shadow.dtype);
124
+ return {
125
+ weighted: true,
126
+ dtype,
127
+ isExplicit: (e) => shadow.isSet(e),
128
+ value: (e) => shadow.value(e),
129
+ text: (e, integral = false) => {
130
+ if (!shadow.isSet(e)) {
131
+ return null;
132
+ }
133
+ const value = shadow.value(e);
134
+ if (Object.is(value, -0)) {
135
+ return NEGATIVE_ZERO_TEXT;
136
+ }
137
+ return integral && Number.isInteger(value) ? formatInteger(value) : format(value);
138
+ }
139
+ };
140
+ }
141
+ const { weights } = snapshot.edgeList();
142
+ if (weights === null || !snapshot.flags.weighted) {
143
+ return {
144
+ weighted: false,
145
+ dtype: "f32",
146
+ isExplicit: () => false,
147
+ value: () => DEFAULT_WEIGHT,
148
+ text: () => null
149
+ };
150
+ }
151
+ return {
152
+ weighted: true,
153
+ dtype: "f32",
154
+ isExplicit: () => true,
155
+ value: (e) => weights[e],
156
+ text: (e, integral = false) => {
157
+ const value = weights[e];
158
+ if (Object.is(value, -0)) {
159
+ return NEGATIVE_ZERO_TEXT;
160
+ }
161
+ return integral && Number.isInteger(value) ? formatInteger(value) : formatF32(value);
162
+ }
163
+ };
164
+ }
165
+ export {
166
+ formatF64 as a,
167
+ formatDecimal as b,
168
+ formatGmlReal as c,
169
+ formatInteger as d,
170
+ explicitWeights as e,
171
+ formatF32 as f,
172
+ isWeightField as i,
173
+ parseWeightText as p,
174
+ weightFromValue as w
175
+ };
176
+ //# sourceMappingURL=weights-Dzba96G3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weights-Dzba96G3.js","sources":["../../src/common/format.ts","../../src/common/weights.ts"],"sourcesContent":["/**\n * Number formatting for exporters (design section 3.7): an f32 weight is written as the shortest\n * decimal that round-trips through Math.fround (never `String(x)`, which prints\n * 0.10000000149011612 for a stored 0.1); an f64 value as its shortest JS text; a GML real always\n * with a decimal point so the dtype survives (design section 8.5); non-finite values as the\n * spelling the target syntax accepts.\n */\n\n/**\n * The shortest decimal text that reads back to the same f32 value through Math.fround.\n * @param value - an f32 value (a JS number holding one)\n * @returns the text; \"Infinity\" / \"-Infinity\" / \"NaN\" for the non-finite values, \"-0\" for negative zero\n */\nexport function formatF32(value: number): string {\n if (!Number.isFinite(value)) {\n return String(value);\n }\n if (value === 0) {\n return Object.is(value, -0) ? \"-0\" : \"0\";\n }\n for (let digits = 1; digits <= 9; digits++) {\n const text = value.toPrecision(digits);\n if (Math.fround(Number(text)) === value) {\n return String(Number(text));\n }\n }\n return String(value);\n}\n\n/**\n * The shortest text of an f64 value: `String(x)`, which is already the shortest round-tripping\n * decimal in JS, except for negative zero, which `String()` writes as \"0\".\n * @param value - the value\n * @returns the text; \"Infinity\" / \"-Infinity\" / \"NaN\" for the non-finite values, \"-0\" for negative zero\n */\nexport function formatF64(value: number): string {\n return Object.is(value, -0) ? \"-0\" : String(value);\n}\n\n/**\n * A decimal text with a decimal point or an exponent guaranteed for a finite value (`2.0`,\n * `1e+21`, `1.5e-7`), so an\n * untyped re-import keeps the column f64 rather than i32 (design section 8.5); negative zero is\n * written `-0.0` so it reads back as -0; non-finite values are the JS spellings (`Infinity`,\n * `-Infinity`, `NaN`), which the CSV / DOT / Pajek importers read back as text. The one\n * implementation of the \"decimal point guaranteed\" rule for every text format; GML has its own\n * spellings of the non-finite values in formatGmlReal().\n * @param value - the value\n * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text\n * @returns the text\n */\nexport function formatDecimal(value: number, dtype: \"f32\" | \"f64\" | \"i32\" | \"u32\" | \"u8\" = \"f64\"): string {\n if (!Number.isFinite(value)) {\n return String(value);\n }\n if (Object.is(value, -0)) {\n return \"-0.0\";\n }\n const text = formatNumber(value, dtype);\n // an exponent form (`1e+21`, `1.5e-7`) is already f64 text under the 5.1 grammar\n return text.includes(\".\") || text.includes(\"e\") ? text : `${text}.0`;\n}\n\n/**\n * A GML real: the shortest text with a decimal point guaranteed (`2.0`, `1.0e-7`), so a re-import\n * keeps the column real rather than int. Non-finite values have no GML spelling and are written\n * as the texts NetworkX's writer emits and its reader accepts, `+INF`, `-INF` and `NAN` (the\n * lowercase `inf` / `nan` would lex as keys there).\n * @param value - the value\n * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text\n * @returns the text\n */\nexport function formatGmlReal(value: number, dtype: \"f32\" | \"f64\" | \"i32\" | \"u32\" | \"u8\" = \"f64\"): string {\n if (Number.isNaN(value)) {\n return \"NAN\";\n }\n if (!Number.isFinite(value)) {\n return value > 0 ? \"+INF\" : \"-INF\";\n }\n const text = formatDecimal(value, dtype);\n if (text.includes(\".\")) {\n return text;\n }\n // NetworkX's real pattern requires a decimal point even in the exponent form (`1.0e-7`)\n const e = text.indexOf(\"e\");\n return `${text.slice(0, e)}.0${text.slice(e)}`;\n}\n\n/**\n * An integer text for a value known to be integral (an i32 / u32 / u8 cell, an f64 that holds an\n * integer), avoiding the exponent form `String()` uses above 1e21.\n * @param value - an integral value\n * @returns the digits\n */\nexport function formatInteger(value: number): string {\n if (Number.isSafeInteger(value) || !Number.isFinite(value)) {\n return String(value);\n }\n return BigInt(value).toString();\n}\n\n/**\n * The text of a numeric cell of any numeric dtype, dispatching on the dtype: f32 through\n * formatF32, everything else through formatF64.\n * @param value - the value\n * @param dtype - the column dtype the value came from\n * @returns the text\n */\nexport function formatNumber(value: number, dtype: \"f32\" | \"f64\" | \"i32\" | \"u32\" | \"u8\"): string {\n return dtype === \"f32\" ? formatF32(value) : formatF64(value);\n}\n","/**\n * Weight resolution shared by every importer (design sections 3.7 and 8.4): which source field is\n * THE weight (`weightFrom`, per-format default, null = unweighted), how its text or JSON value\n * becomes the number passed to `addEdge`, and the E_INVALID_WEIGHT boundary.\n *\n * An edge whose weight field is absent or blank is pushed WITHOUT a weight argument, never with an\n * explicit 1: the builder's weightSet bitmap then records that the weight was defaulted, and the\n * exporter re-emits no weight for it (decision D-WSET). NaN and non-numeric text are\n * E_INVALID_WEIGHT before the sink is touched, so the importer records the issue and skips the edge\n * with the sink unchanged; Infinity and negative values are legal weights (design section 3.7).\n */\n\nimport { type Column, GraphFormatError, type GraphSnapshot } from \"@graphty/graph-format\";\n\nimport { parseDecimalText } from \"./declared-types.js\";\nimport { formatF32, formatF64, formatInteger } from \"./format.js\";\n\n/** The weight of an edge added without one (design section 3.7). */\nexport const DEFAULT_WEIGHT = 1;\n\n/**\n * Whether a source field is the weight field under the resolved `weightFrom` option.\n * @param name - the field name (attribute title, CSV header, JSON key)\n * @param weightFrom - the resolved option; null means unweighted\n * @returns true when the field is THE weight\n */\nexport function isWeightField(name: string, weightFrom: string | null): boolean {\n return weightFrom !== null && name === weightFrom;\n}\n\n/**\n * The weight argument of addEdge from a text cell: undefined for a blank cell (the weight is\n * omitted), the number otherwise.\n * @param text - the cell text\n * @returns the weight, or undefined when blank; E_INVALID_WEIGHT for NaN or non-numeric text\n */\nexport function parseWeightText(text: string): number | undefined {\n const trimmed = text.trim();\n if (trimmed.length === 0) {\n return undefined;\n }\n let value: number;\n try {\n value = parseDecimalText(trimmed);\n } catch (err) {\n throw invalidWeight(text, err);\n }\n if (Number.isNaN(value)) {\n throw invalidWeight(text, null);\n }\n return value;\n}\n\n/**\n * The weight argument of addEdge from a typed value (JSON, a record field): undefined for null /\n * undefined, the number for a finite or infinite number, the parsed number for numeric text.\n * @param value - the field value\n * @returns the weight, or undefined when absent; E_INVALID_WEIGHT for NaN, a boolean, an object or non-numeric text\n */\nexport function weightFromValue(value: unknown): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n if (typeof value === \"number\") {\n if (Number.isNaN(value)) {\n throw invalidWeight(value, null);\n }\n return value;\n }\n if (typeof value === \"string\") {\n return parseWeightText(value);\n }\n throw invalidWeight(value, null);\n}\n\n/**\n * The E_INVALID_WEIGHT error of a rejected value.\n * @param value - the rejected value\n * @param cause - the parse error, or null\n * @returns the error\n */\nfunction invalidWeight(value: unknown, cause: unknown): GraphFormatError {\n let shown: string;\n switch (typeof value) {\n case \"string\":\n shown = JSON.stringify(value);\n break;\n case \"number\":\n shown = String(value);\n break;\n default:\n shown = typeof value;\n }\n return new GraphFormatError(\"E_INVALID_WEIGHT\", `invalid edge weight ${shown}`, {\n value: typeof value === \"object\" ? typeof value : value,\n cause: cause instanceof Error ? cause.message : null,\n });\n}\n\n// ============================================================ the exporter side\n\n/**\n * The explicit weights of a snapshot for exporters (design sections 3.7 and 8.5): the weight\n * role column when present (its validity says which edges had an explicit weight, its dtype how\n * the value is written), else `edgeList().weights` as f32 for every edge of a weighted snapshot;\n * nothing for an unweighted one. One implementation for every exporter.\n * Consumed by the per-format exporters under src/formats.\n * @public\n */\nexport interface ExplicitWeights {\n /** Whether any edge can have an explicit weight (the snapshot is weighted). */\n readonly weighted: boolean;\n /** The dtype the values are read from: the shadow column's, or f32 for the arc array. */\n readonly dtype: \"f32\" | \"f64\";\n /**\n * Whether an edge's weight was explicit in the source.\n * @param e - the logical edge index\n * @returns true when the exporter must write it\n */\n isExplicit(e: number): boolean;\n /**\n * The weight value of an edge (meaningful when explicit).\n * @param e - the logical edge index\n * @returns the value\n */\n value(e: number): number;\n /**\n * The weight text of an edge: the shortest round-tripping decimal for its dtype, or the\n * integer digits when `integral` is requested and the value is an integer; null when the\n * weight was defaulted.\n * @param e - the logical edge index\n * @param integral - write an integral value without a decimal part (formats declaring an int weight)\n * @returns the text, or null\n */\n text(e: number, integral?: boolean): string | null;\n}\n\n/** A weight of -0 keeps its sign: every importer's weight grammar reads \"-0\" back as -0. */\nconst NEGATIVE_ZERO_TEXT = \"-0\";\n\n/** The dtypes a weight role column may have (an integer column declared by a caller included). */\nconst NUMERIC_DTYPES: ReadonlySet<string> = new Set([\"f32\", \"f64\", \"i32\", \"u32\", \"u8\"]);\n\n/**\n * The shortest round-tripping text of a weight by the shadow column's dtype.\n * @param dtype - the shadow column's dtype\n * @returns the formatter\n */\nfunction weightFormatter(dtype: string): (value: number) => string {\n switch (dtype) {\n case \"f32\":\n return formatF32;\n case \"f64\":\n return formatF64;\n default:\n return formatInteger;\n }\n}\n\n/**\n * Build the explicit-weight view of a snapshot.\n * @param snapshot - the snapshot\n * @returns the view\n */\nexport function explicitWeights(snapshot: GraphSnapshot): ExplicitWeights {\n const shadowColumn = snapshot.edges.byRole(\"weight\");\n const shadow: Column | null = shadowColumn !== null && NUMERIC_DTYPES.has(shadowColumn.dtype) ? shadowColumn : null;\n if (shadow !== null) {\n const dtype = shadow.dtype === \"f32\" ? \"f32\" : \"f64\";\n const format = weightFormatter(shadow.dtype);\n return {\n weighted: true,\n dtype,\n isExplicit: (e: number): boolean => shadow.isSet(e),\n value: (e: number): number => shadow.value(e) as number,\n text: (e: number, integral = false): string | null => {\n if (!shadow.isSet(e)) {\n return null;\n }\n const value = shadow.value(e) as number;\n if (Object.is(value, -0)) {\n return NEGATIVE_ZERO_TEXT;\n }\n return integral && Number.isInteger(value) ? formatInteger(value) : format(value);\n },\n };\n }\n const { weights } = snapshot.edgeList();\n if (weights === null || !snapshot.flags.weighted) {\n return {\n weighted: false,\n dtype: \"f32\",\n isExplicit: (): boolean => false,\n value: (): number => DEFAULT_WEIGHT,\n text: (): string | null => null,\n };\n }\n return {\n weighted: true,\n dtype: \"f32\",\n isExplicit: (): boolean => true,\n value: (e: number): number => weights[e],\n text: (e: number, integral = false): string => {\n const value = weights[e];\n if (Object.is(value, -0)) {\n return NEGATIVE_ZERO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AM,UAAU;AAC9C,WAAO;AAAA,MACH,UAAU;AAAA,MACV,OAAO;AAAA,MACP,YAAY,MAAe;AAAA,MAC3B,OAAO,MAAc;AAAA,MACrB,MAAM,MAAqB;AAAA,IAAA;AAAA,EAEnC;AACA,SAAO;AAAA,IACH,UAAU;AAAA,IACV,OAAO;AAAA,IACP,YAAY,MAAe;AAAA,IAC3B,OAAO,CAAC,MAAsB,QAAQ,CAAC;AAAA,IACvC,MAAM,CAAC,GAAW,WAAW,UAAkB;AAC3C,YAAM,QAAQ,QAAQ,CAAC;AACvB,UAAI,OAAO,GAAG,OAAO,EAAE,GAAG;AACtB,eAAO;AAAA,MACX;AACA,aAAO,YAAY,OAAO,UAAU,KAAK,IAAI,cAAc,KAAK,IAAI,UAAU,KAAK;AAAA,IACvF;AAAA,EAAA;AAER;"}
@@ -0,0 +1,77 @@
1
+ const DEFAULT_CHUNK_BYTES = 64 * 1024;
2
+ async function* encodeChunks(parts, chunkBytes = DEFAULT_CHUNK_BYTES) {
3
+ const encoder = new TextEncoder();
4
+ let pending = [];
5
+ let pendingUnits = 0;
6
+ for await (const part of parts) {
7
+ if (part.length === 0) {
8
+ continue;
9
+ }
10
+ pending.push(part);
11
+ pendingUnits += part.length;
12
+ if (pendingUnits >= chunkBytes) {
13
+ yield encoder.encode(pending.length === 1 ? pending[0] : pending.join(""));
14
+ pending = [];
15
+ pendingUnits = 0;
16
+ }
17
+ }
18
+ if (pending.length > 0) {
19
+ yield encoder.encode(pending.length === 1 ? pending[0] : pending.join(""));
20
+ }
21
+ }
22
+ async function joinText(parts) {
23
+ const collected = [];
24
+ for await (const part of parts) {
25
+ collected.push(part);
26
+ }
27
+ return collected.join("");
28
+ }
29
+ async function decodeChunks(chunks) {
30
+ const decoder = new TextDecoder("utf-8", { fatal: true });
31
+ const parts = [];
32
+ for await (const chunk of chunks) {
33
+ parts.push(decoder.decode(chunk, { stream: true }));
34
+ }
35
+ parts.push(decoder.decode());
36
+ return parts.join("");
37
+ }
38
+ async function collectBytes(chunks) {
39
+ const parts = [];
40
+ let total = 0;
41
+ for await (const chunk of chunks) {
42
+ parts.push(chunk);
43
+ total += chunk.byteLength;
44
+ }
45
+ const out = new Uint8Array(total);
46
+ let offset = 0;
47
+ for (const part of parts) {
48
+ out.set(part, offset);
49
+ offset += part.byteLength;
50
+ }
51
+ return out;
52
+ }
53
+ function toReadableStream(chunks) {
54
+ const iterator = chunks[Symbol.asyncIterator]();
55
+ return new ReadableStream({
56
+ async pull(controller) {
57
+ const { done, value } = await iterator.next();
58
+ if (done) {
59
+ controller.close();
60
+ return;
61
+ }
62
+ controller.enqueue(value);
63
+ },
64
+ async cancel() {
65
+ await iterator.return?.(void 0);
66
+ }
67
+ });
68
+ }
69
+ export {
70
+ DEFAULT_CHUNK_BYTES as D,
71
+ collectBytes as c,
72
+ decodeChunks as d,
73
+ encodeChunks as e,
74
+ joinText as j,
75
+ toReadableStream as t
76
+ };
77
+ //# sourceMappingURL=writer-C7flM-Ih.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer-C7flM-Ih.js","sources":["../../src/common/writer.ts"],"sourcesContent":["/**\n * The output side of the exporter contract (design sections 8.5 and 12.4): an exporter produces\n * its document as a sequence of text parts (a sync or async generator of strings, one per line or\n * element); these helpers turn that sequence into `export()`'s `AsyncIterable<Uint8Array>` of\n * UTF-8 chunks of a bounded size, into `exportToString()`'s one string, or into a\n * `ReadableStream<Uint8Array>` for a caller that wants a stream.\n */\n\n/**\n * Text parts an exporter produces.\n * Consumed by the per-format importers and exporters under src/formats.\n * @public\n */\nexport type TextParts = Iterable<string> | AsyncIterable<string>;\n\n/** The target size of one encoded chunk; parts are coalesced up to it and never split. */\nexport const DEFAULT_CHUNK_BYTES = 64 * 1024;\n\n/**\n * Encode text parts as UTF-8 chunks of about `chunkBytes` each. Small parts are coalesced; a part\n * larger than the chunk size is emitted whole. The last chunk may be short; nothing is emitted for\n * an empty document.\n * @param parts - the text parts\n * @param chunkBytes - the target chunk size in bytes\n * @yields UTF-8 chunks\n * @returns nothing\n */\nexport async function* encodeChunks(\n parts: TextParts,\n chunkBytes: number = DEFAULT_CHUNK_BYTES,\n): AsyncGenerator<Uint8Array, void, undefined> {\n const encoder = new TextEncoder();\n let pending: string[] = [];\n let pendingUnits = 0;\n for await (const part of parts) {\n if (part.length === 0) {\n continue;\n }\n pending.push(part);\n pendingUnits += part.length;\n // UTF-16 code units are a lower bound on the UTF-8 byte count; flush when the lower bound reaches the target\n if (pendingUnits >= chunkBytes) {\n yield encoder.encode(pending.length === 1 ? pending[0] : pending.join(\"\"));\n pending = [];\n pendingUnits = 0;\n }\n }\n if (pending.length > 0) {\n yield encoder.encode(pending.length === 1 ? pending[0] : pending.join(\"\"));\n }\n}\n\n/**\n * Join text parts into one string.\n * @param parts - the text parts\n * @returns the whole document\n */\nexport async function joinText(parts: TextParts): Promise<string> {\n const collected: string[] = [];\n for await (const part of parts) {\n collected.push(part);\n }\n return collected.join(\"\");\n}\n\n/**\n * Decode UTF-8 chunks back into one string (for tests and for callers holding an export() result).\n * @param chunks - the chunks\n * @returns the decoded text\n */\nexport async function decodeChunks(chunks: AsyncIterable<Uint8Array>): Promise<string> {\n const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n const parts: string[] = [];\n for await (const chunk of chunks) {\n parts.push(decoder.decode(chunk, { stream: true }));\n }\n parts.push(decoder.decode());\n return parts.join(\"\");\n}\n\n/**\n * Collect UTF-8 chunks into one Uint8Array.\n * @param chunks - the chunks\n * @returns the concatenated bytes\n */\nexport async function collectBytes(chunks: AsyncIterable<Uint8Array>): Promise<Uint8Array> {\n const parts: Uint8Array[] = [];\n let total = 0;\n for await (const chunk of chunks) {\n parts.push(chunk);\n total += chunk.byteLength;\n }\n const out = new Uint8Array(total);\n let offset = 0;\n for (const part of parts) {\n out.set(part, offset);\n offset += part.byteLength;\n }\n return out;\n}\n\n/**\n * Wrap an async iterable of chunks as a ReadableStream, pulling one chunk per read and cancelling\n * the iterable when the stream is cancelled.\n * @param chunks - the chunks\n * @returns a byte stream\n */\nexport function toReadableStream(chunks: AsyncIterable<Uint8Array>): ReadableStream<Uint8Array> {\n const iterator = chunks[Symbol.asyncIterator]();\n return new ReadableStream<Uint8Array>({\n async pull(controller): Promise<void> {\n const { done, value } = await iterator.next();\n if (done) {\n controller.close();\n return;\n }\n controller.enqueue(value);\n },\n async cancel(): Promise<void> {\n await iterator.return?.(undefined);\n },\n });\n}\n"],"names":[],"mappings":"AAgBO,MAAM,sBAAsB,KAAK;AAWxC,gBAAuB,aACnB,OACA,aAAqB,qBACsB;AAC3C,QAAM,UAAU,IAAI,YAAA;AACpB,MAAI,UAAoB,CAAA;AACxB,MAAI,eAAe;AACnB,mBAAiB,QAAQ,OAAO;AAC5B,QAAI,KAAK,WAAW,GAAG;AACnB;AAAA,IACJ;AACA,YAAQ,KAAK,IAAI;AACjB,oBAAgB,KAAK;AAErB,QAAI,gBAAgB,YAAY;AAC5B,YAAM,QAAQ,OAAO,QAAQ,WAAW,IAAI,QAAQ,CAAC,IAAI,QAAQ,KAAK,EAAE,CAAC;AACzE,gBAAU,CAAA;AACV,qBAAe;AAAA,IACnB;AAAA,EACJ;AACA,MAAI,QAAQ,SAAS,GAAG;AACpB,UAAM,QAAQ,OAAO,QAAQ,WAAW,IAAI,QAAQ,CAAC,IAAI,QAAQ,KAAK,EAAE,CAAC;AAAA,EAC7E;AACJ;AAOA,eAAsB,SAAS,OAAmC;AAC9D,QAAM,YAAsB,CAAA;AAC5B,mBAAiB,QAAQ,OAAO;AAC5B,cAAU,KAAK,IAAI;AAAA,EACvB;AACA,SAAO,UAAU,KAAK,EAAE;AAC5B;AAOA,eAAsB,aAAa,QAAoD;AACnF,QAAM,UAAU,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM;AACxD,QAAM,QAAkB,CAAA;AACxB,mBAAiB,SAAS,QAAQ;AAC9B,UAAM,KAAK,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAA,CAAM,CAAC;AAAA,EACtD;AACA,QAAM,KAAK,QAAQ,QAAQ;AAC3B,SAAO,MAAM,KAAK,EAAE;AACxB;AAOA,eAAsB,aAAa,QAAwD;AACvF,QAAM,QAAsB,CAAA;AAC5B,MAAI,QAAQ;AACZ,mBAAiB,SAAS,QAAQ;AAC9B,UAAM,KAAK,KAAK;AAChB,aAAS,MAAM;AAAA,EACnB;AACA,QAAM,MAAM,IAAI,WAAW,KAAK;AAChC,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACtB,QAAI,IAAI,MAAM,MAAM;AACpB,cAAU,KAAK;AAAA,EACnB;AACA,SAAO;AACX;AAQO,SAAS,iBAAiB,QAA+D;AAC5F,QAAM,WAAW,OAAO,OAAO,aAAa,EAAA;AAC5C,SAAO,IAAI,eAA2B;AAAA,IAClC,MAAM,KAAK,YAA2B;AAClC,YAAM,EAAE,MAAM,MAAA,IAAU,MAAM,SAAS,KAAA;AACvC,UAAI,MAAM;AACN,mBAAW,MAAA;AACX;AAAA,MACJ;AACA,iBAAW,QAAQ,KAAK;AAAA,IAC5B;AAAA,IACA,MAAM,SAAwB;AAC1B,YAAM,SAAS,SAAS,MAAS;AAAA,IACrC;AAAA,EAAA,CACH;AACL;"}
package/dist/csv.js CHANGED
@@ -1,9 +1,11 @@
1
- import { aU as DICT_SAMPLE_ROWS, aT as DictHeuristic, a2 as ROLE_TAKEN_CODE$1, v as ID_MERGED_CODE$1, n as DUPLICATE_EDGE_ID_CODE$1, p as DUPLICATE_NODE_CODE$1, N as MISSING_ID_CODE$1, M as MISSING_ENDPOINT_CODE$1, r as EMPTY_INPUT_CODE$1, aD as resolveImportOptions, I as ImportReportBuilder, aA as reportSinkOptions, aB as reportUnusedOptions, q as DirectionResolver, J as IdCoercer, a as throwIfAborted, aE as uniqueColumnName, $ as RENAMED_CODE, as as declareResolved, aC as resolveExportOptions, ay as pairFolding, aR as joinListText, an as canonicalId, O as MIXED_DIRECTION_CODE, k as DIRECTION_FORCED_CODE, l as DIRECTION_REFUSED_CODE, a3 as SINK_OPTION_CODE, V as OPTION_IGNORED_CODE, C as COLUMN_RENAMED_CODE, ag as UNKNOWN_ENCODING_CODE, s as ENCODING_FALLBACK_CODE, z as INVALID_ENCODING_CODE, F as INVALID_UTF8_CODE } from "./chunks/report-BOk0p5y8.js";
1
+ import { aV as DICT_SAMPLE_ROWS, _ as DictHeuristic, R as ROLE_TAKEN_CODE$1, I as ID_MERGED_CODE$1, c as DUPLICATE_EDGE_ID_CODE$1, d as DUPLICATE_NODE_CODE$1, f as MISSING_ID_CODE$1, e as MISSING_ENDPOINT_CODE$1, u as EMPTY_INPUT_CODE$1, v as resolveImportOptions, w as ImportReportBuilder, F as reportSinkOptions, z as reportUnusedOptions, J as DirectionResolver, K as IdCoercer, y as throwIfAborted, Q as uniqueColumnName, at as RENAMED_CODE, L as declareResolved, V as resolveExportOptions, X as pairFolding, aT as joinListText, ax as canonicalId, af as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, a as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, C as COLUMN_RENAMED_CODE, q as UNKNOWN_ENCODING_CODE, E as ENCODING_FALLBACK_CODE, r as INVALID_ENCODING_CODE, s as INVALID_UTF8_CODE } from "./chunks/report-B1z4WT9e.js";
2
2
  import { i as inferTextDtype, T as TextCellWriter, p as parseTextCell, W as WIDENING_UNSUPPORTED_CODE } from "./chunks/text-Dr0Ifpag.js";
3
3
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
4
- import { p as parseWeightText, c as capabilities, L as LOSS, n as joinText, e as encodeChunks, a as checkCapabilities, r as countMixedEdges, f as explicitWeights, k as formatInteger, g as formatDecimal } from "./chunks/writer-GAdltGmC.js";
5
- import { s as sniffNewline, a as sniffDelimiter, C as CsvRecordReader, D as DELIMITER_CANDIDATES, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-Bk9jgodz.js";
6
- import { m as quoteCsvCell } from "./chunks/escape-D-gZWO26.js";
4
+ import { p as parseWeightText, e as explicitWeights, d as formatInteger, b as formatDecimal } from "./chunks/weights-Dzba96G3.js";
5
+ import { s as sniffNewline, a as sniffDelimiter, C as CsvRecordReader, D as DELIMITER_CANDIDATES, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-dbRkxwaq.js";
6
+ import { m as quoteCsvCell } from "./chunks/escape-B-tkk_Cl.js";
7
+ import { c as capabilities, L as LOSS, a as checkCapabilities, d as countMixedEdges } from "./chunks/export-Bh60Dv-n.js";
8
+ import { j as joinText, e as encodeChunks } from "./chunks/writer-C7flM-Ih.js";
7
9
  const SOURCE_NAMES = Object.freeze([
8
10
  "source",
9
11
  "src",