@graphty/graph-io 0.0.0 → 0.2.1

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 (339) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +250 -28
  3. package/dist/chunks/children-CL3Cy0ez.js +238 -0
  4. package/dist/chunks/children-CL3Cy0ez.js.map +1 -0
  5. package/dist/chunks/escape-DyI8JofU.js +938 -0
  6. package/dist/chunks/escape-DyI8JofU.js.map +1 -0
  7. package/dist/chunks/importer-CQnJuWJw.js +2987 -0
  8. package/dist/chunks/importer-CQnJuWJw.js.map +1 -0
  9. package/dist/chunks/importer-CpCpfbxr.js +2015 -0
  10. package/dist/chunks/importer-CpCpfbxr.js.map +1 -0
  11. package/dist/chunks/importer-DbnGYr3_.js +2342 -0
  12. package/dist/chunks/importer-DbnGYr3_.js.map +1 -0
  13. package/dist/chunks/importer-GozH8DkN.js +3050 -0
  14. package/dist/chunks/importer-GozH8DkN.js.map +1 -0
  15. package/dist/chunks/records-CGpxszm1.js +605 -0
  16. package/dist/chunks/records-CGpxszm1.js.map +1 -0
  17. package/dist/chunks/text-CajMdVFy.js +189 -0
  18. package/dist/chunks/text-CajMdVFy.js.map +1 -0
  19. package/dist/chunks/writer-DxSKC7TL.js +2842 -0
  20. package/dist/chunks/writer-DxSKC7TL.js.map +1 -0
  21. package/dist/csv.d.ts +1 -0
  22. package/dist/csv.js +1702 -0
  23. package/dist/csv.js.map +1 -0
  24. package/dist/dot.d.ts +1 -0
  25. package/dist/dot.js +8 -0
  26. package/dist/dot.js.map +1 -0
  27. package/dist/gexf.d.ts +1 -0
  28. package/dist/gexf.js +3466 -0
  29. package/dist/gexf.js.map +1 -0
  30. package/dist/gml.d.ts +1 -0
  31. package/dist/gml.js +2647 -0
  32. package/dist/gml.js.map +1 -0
  33. package/dist/graph-io.d.ts +1 -0
  34. package/dist/graph-io.js +790 -0
  35. package/dist/graph-io.js.map +1 -0
  36. package/dist/graphml.d.ts +1 -0
  37. package/dist/graphml.js +8 -0
  38. package/dist/graphml.js.map +1 -0
  39. package/dist/json.d.ts +1 -0
  40. package/dist/json.js +11 -0
  41. package/dist/json.js.map +1 -0
  42. package/dist/neo4j.d.ts +1 -0
  43. package/dist/neo4j.js +2046 -0
  44. package/dist/neo4j.js.map +1 -0
  45. package/dist/pajek.d.ts +1 -0
  46. package/dist/pajek.js +8 -0
  47. package/dist/pajek.js.map +1 -0
  48. package/dist/src/children.d.ts +134 -0
  49. package/dist/src/children.d.ts.map +1 -0
  50. package/dist/src/children.js +274 -0
  51. package/dist/src/children.js.map +1 -0
  52. package/dist/src/common/attributes.d.ts +229 -0
  53. package/dist/src/common/attributes.d.ts.map +1 -0
  54. package/dist/src/common/attributes.js +368 -0
  55. package/dist/src/common/attributes.js.map +1 -0
  56. package/dist/src/common/codes.d.ts +105 -0
  57. package/dist/src/common/codes.d.ts.map +1 -0
  58. package/dist/src/common/codes.js +107 -0
  59. package/dist/src/common/codes.js.map +1 -0
  60. package/dist/src/common/declared-types.d.ts +84 -0
  61. package/dist/src/common/declared-types.d.ts.map +1 -0
  62. package/dist/src/common/declared-types.js +326 -0
  63. package/dist/src/common/declared-types.js.map +1 -0
  64. package/dist/src/common/direction.d.ts +206 -0
  65. package/dist/src/common/direction.d.ts.map +1 -0
  66. package/dist/src/common/direction.js +370 -0
  67. package/dist/src/common/direction.js.map +1 -0
  68. package/dist/src/common/escape.d.ts +92 -0
  69. package/dist/src/common/escape.d.ts.map +1 -0
  70. package/dist/src/common/escape.js +212 -0
  71. package/dist/src/common/escape.js.map +1 -0
  72. package/dist/src/common/export.d.ts +249 -0
  73. package/dist/src/common/export.d.ts.map +1 -0
  74. package/dist/src/common/export.js +594 -0
  75. package/dist/src/common/export.js.map +1 -0
  76. package/dist/src/common/format.d.ts +59 -0
  77. package/dist/src/common/format.d.ts.map +1 -0
  78. package/dist/src/common/format.js +106 -0
  79. package/dist/src/common/format.js.map +1 -0
  80. package/dist/src/common/ids.d.ts +83 -0
  81. package/dist/src/common/ids.d.ts.map +1 -0
  82. package/dist/src/common/ids.js +158 -0
  83. package/dist/src/common/ids.js.map +1 -0
  84. package/dist/src/common/input.d.ts +100 -0
  85. package/dist/src/common/input.d.ts.map +1 -0
  86. package/dist/src/common/input.js +335 -0
  87. package/dist/src/common/input.js.map +1 -0
  88. package/dist/src/common/lists.d.ts +34 -0
  89. package/dist/src/common/lists.d.ts.map +1 -0
  90. package/dist/src/common/lists.js +185 -0
  91. package/dist/src/common/lists.js.map +1 -0
  92. package/dist/src/common/options.d.ts +108 -0
  93. package/dist/src/common/options.d.ts.map +1 -0
  94. package/dist/src/common/options.js +265 -0
  95. package/dist/src/common/options.js.map +1 -0
  96. package/dist/src/common/report.d.ts +187 -0
  97. package/dist/src/common/report.d.ts.map +1 -0
  98. package/dist/src/common/report.js +274 -0
  99. package/dist/src/common/report.js.map +1 -0
  100. package/dist/src/common/temporal.d.ts +71 -0
  101. package/dist/src/common/temporal.d.ts.map +1 -0
  102. package/dist/src/common/temporal.js +266 -0
  103. package/dist/src/common/temporal.js.map +1 -0
  104. package/dist/src/common/text.d.ts +104 -0
  105. package/dist/src/common/text.d.ts.map +1 -0
  106. package/dist/src/common/text.js +255 -0
  107. package/dist/src/common/text.js.map +1 -0
  108. package/dist/src/common/weights.d.ts +77 -0
  109. package/dist/src/common/weights.d.ts.map +1 -0
  110. package/dist/src/common/weights.js +156 -0
  111. package/dist/src/common/weights.js.map +1 -0
  112. package/dist/src/common/writer.d.ts +51 -0
  113. package/dist/src/common/writer.d.ts.map +1 -0
  114. package/dist/src/common/writer.js +108 -0
  115. package/dist/src/common/writer.js.map +1 -0
  116. package/dist/src/common/xml.d.ts +245 -0
  117. package/dist/src/common/xml.d.ts.map +1 -0
  118. package/dist/src/common/xml.js +942 -0
  119. package/dist/src/common/xml.js.map +1 -0
  120. package/dist/src/formats/csv/exporter.d.ts +70 -0
  121. package/dist/src/formats/csv/exporter.d.ts.map +1 -0
  122. package/dist/src/formats/csv/exporter.js +682 -0
  123. package/dist/src/formats/csv/exporter.js.map +1 -0
  124. package/dist/src/formats/csv/header.d.ts +66 -0
  125. package/dist/src/formats/csv/header.d.ts.map +1 -0
  126. package/dist/src/formats/csv/header.js +152 -0
  127. package/dist/src/formats/csv/header.js.map +1 -0
  128. package/dist/src/formats/csv/importer.d.ts +82 -0
  129. package/dist/src/formats/csv/importer.d.ts.map +1 -0
  130. package/dist/src/formats/csv/importer.js +849 -0
  131. package/dist/src/formats/csv/importer.js.map +1 -0
  132. package/dist/src/formats/csv/index.d.ts +60 -0
  133. package/dist/src/formats/csv/index.d.ts.map +1 -0
  134. package/dist/src/formats/csv/index.js +63 -0
  135. package/dist/src/formats/csv/index.js.map +1 -0
  136. package/dist/src/formats/csv/records.d.ts +188 -0
  137. package/dist/src/formats/csv/records.d.ts.map +1 -0
  138. package/dist/src/formats/csv/records.js +702 -0
  139. package/dist/src/formats/csv/records.js.map +1 -0
  140. package/dist/src/formats/csv/values.d.ts +105 -0
  141. package/dist/src/formats/csv/values.d.ts.map +1 -0
  142. package/dist/src/formats/csv/values.js +192 -0
  143. package/dist/src/formats/csv/values.js.map +1 -0
  144. package/dist/src/formats/dot/exporter.d.ts +52 -0
  145. package/dist/src/formats/dot/exporter.d.ts.map +1 -0
  146. package/dist/src/formats/dot/exporter.js +836 -0
  147. package/dist/src/formats/dot/exporter.js.map +1 -0
  148. package/dist/src/formats/dot/importer.d.ts +102 -0
  149. package/dist/src/formats/dot/importer.d.ts.map +1 -0
  150. package/dist/src/formats/dot/importer.js +1291 -0
  151. package/dist/src/formats/dot/importer.js.map +1 -0
  152. package/dist/src/formats/dot/index.d.ts +7 -0
  153. package/dist/src/formats/dot/index.d.ts.map +1 -0
  154. package/dist/src/formats/dot/index.js +7 -0
  155. package/dist/src/formats/dot/index.js.map +1 -0
  156. package/dist/src/formats/dot/names.d.ts +29 -0
  157. package/dist/src/formats/dot/names.d.ts.map +1 -0
  158. package/dist/src/formats/dot/names.js +28 -0
  159. package/dist/src/formats/dot/names.js.map +1 -0
  160. package/dist/src/formats/dot/tokenizer.d.ts +114 -0
  161. package/dist/src/formats/dot/tokenizer.d.ts.map +1 -0
  162. package/dist/src/formats/dot/tokenizer.js +341 -0
  163. package/dist/src/formats/dot/tokenizer.js.map +1 -0
  164. package/dist/src/formats/gexf/exporter.d.ts +56 -0
  165. package/dist/src/formats/gexf/exporter.d.ts.map +1 -0
  166. package/dist/src/formats/gexf/exporter.js +1395 -0
  167. package/dist/src/formats/gexf/exporter.js.map +1 -0
  168. package/dist/src/formats/gexf/importer.d.ts +73 -0
  169. package/dist/src/formats/gexf/importer.d.ts.map +1 -0
  170. package/dist/src/formats/gexf/importer.js +1880 -0
  171. package/dist/src/formats/gexf/importer.js.map +1 -0
  172. package/dist/src/formats/gexf/index.d.ts +96 -0
  173. package/dist/src/formats/gexf/index.d.ts.map +1 -0
  174. package/dist/src/formats/gexf/index.js +97 -0
  175. package/dist/src/formats/gexf/index.js.map +1 -0
  176. package/dist/src/formats/gexf/schema.d.ts +135 -0
  177. package/dist/src/formats/gexf/schema.d.ts.map +1 -0
  178. package/dist/src/formats/gexf/schema.js +323 -0
  179. package/dist/src/formats/gexf/schema.js.map +1 -0
  180. package/dist/src/formats/gml/exporter.d.ts +69 -0
  181. package/dist/src/formats/gml/exporter.d.ts.map +1 -0
  182. package/dist/src/formats/gml/exporter.js +1093 -0
  183. package/dist/src/formats/gml/exporter.js.map +1 -0
  184. package/dist/src/formats/gml/importer.d.ts +66 -0
  185. package/dist/src/formats/gml/importer.d.ts.map +1 -0
  186. package/dist/src/formats/gml/importer.js +1331 -0
  187. package/dist/src/formats/gml/importer.js.map +1 -0
  188. package/dist/src/formats/gml/index.d.ts +85 -0
  189. package/dist/src/formats/gml/index.d.ts.map +1 -0
  190. package/dist/src/formats/gml/index.js +88 -0
  191. package/dist/src/formats/gml/index.js.map +1 -0
  192. package/dist/src/formats/gml/syntax.d.ts +186 -0
  193. package/dist/src/formats/gml/syntax.d.ts.map +1 -0
  194. package/dist/src/formats/gml/syntax.js +467 -0
  195. package/dist/src/formats/gml/syntax.js.map +1 -0
  196. package/dist/src/formats/graphml/constants.d.ts +169 -0
  197. package/dist/src/formats/graphml/constants.d.ts.map +1 -0
  198. package/dist/src/formats/graphml/constants.js +165 -0
  199. package/dist/src/formats/graphml/constants.js.map +1 -0
  200. package/dist/src/formats/graphml/exporter.d.ts +34 -0
  201. package/dist/src/formats/graphml/exporter.d.ts.map +1 -0
  202. package/dist/src/formats/graphml/exporter.js +1176 -0
  203. package/dist/src/formats/graphml/exporter.js.map +1 -0
  204. package/dist/src/formats/graphml/importer.d.ts +31 -0
  205. package/dist/src/formats/graphml/importer.d.ts.map +1 -0
  206. package/dist/src/formats/graphml/importer.js +1607 -0
  207. package/dist/src/formats/graphml/importer.js.map +1 -0
  208. package/dist/src/formats/graphml/index.d.ts +8 -0
  209. package/dist/src/formats/graphml/index.d.ts.map +1 -0
  210. package/dist/src/formats/graphml/index.js +8 -0
  211. package/dist/src/formats/graphml/index.js.map +1 -0
  212. package/dist/src/formats/graphml/tree.d.ts +72 -0
  213. package/dist/src/formats/graphml/tree.d.ts.map +1 -0
  214. package/dist/src/formats/graphml/tree.js +290 -0
  215. package/dist/src/formats/graphml/tree.js.map +1 -0
  216. package/dist/src/formats/json/dialect.d.ts +125 -0
  217. package/dist/src/formats/json/dialect.d.ts.map +1 -0
  218. package/dist/src/formats/json/dialect.js +262 -0
  219. package/dist/src/formats/json/dialect.js.map +1 -0
  220. package/dist/src/formats/json/exporter.d.ts +89 -0
  221. package/dist/src/formats/json/exporter.d.ts.map +1 -0
  222. package/dist/src/formats/json/exporter.js +1358 -0
  223. package/dist/src/formats/json/exporter.js.map +1 -0
  224. package/dist/src/formats/json/importer.d.ts +108 -0
  225. package/dist/src/formats/json/importer.d.ts.map +1 -0
  226. package/dist/src/formats/json/importer.js +1838 -0
  227. package/dist/src/formats/json/importer.js.map +1 -0
  228. package/dist/src/formats/json/index.d.ts +8 -0
  229. package/dist/src/formats/json/index.d.ts.map +1 -0
  230. package/dist/src/formats/json/index.js +8 -0
  231. package/dist/src/formats/json/index.js.map +1 -0
  232. package/dist/src/formats/neo4j/exporter.d.ts +68 -0
  233. package/dist/src/formats/neo4j/exporter.d.ts.map +1 -0
  234. package/dist/src/formats/neo4j/exporter.js +1055 -0
  235. package/dist/src/formats/neo4j/exporter.js.map +1 -0
  236. package/dist/src/formats/neo4j/header.d.ts +52 -0
  237. package/dist/src/formats/neo4j/header.d.ts.map +1 -0
  238. package/dist/src/formats/neo4j/header.js +131 -0
  239. package/dist/src/formats/neo4j/header.js.map +1 -0
  240. package/dist/src/formats/neo4j/importer.d.ts +73 -0
  241. package/dist/src/formats/neo4j/importer.d.ts.map +1 -0
  242. package/dist/src/formats/neo4j/importer.js +932 -0
  243. package/dist/src/formats/neo4j/importer.js.map +1 -0
  244. package/dist/src/formats/neo4j/index.d.ts +79 -0
  245. package/dist/src/formats/neo4j/index.d.ts.map +1 -0
  246. package/dist/src/formats/neo4j/index.js +83 -0
  247. package/dist/src/formats/neo4j/index.js.map +1 -0
  248. package/dist/src/formats/pajek/exporter.d.ts +58 -0
  249. package/dist/src/formats/pajek/exporter.d.ts.map +1 -0
  250. package/dist/src/formats/pajek/exporter.js +825 -0
  251. package/dist/src/formats/pajek/exporter.js.map +1 -0
  252. package/dist/src/formats/pajek/importer.d.ts +88 -0
  253. package/dist/src/formats/pajek/importer.d.ts.map +1 -0
  254. package/dist/src/formats/pajek/importer.js +1047 -0
  255. package/dist/src/formats/pajek/importer.js.map +1 -0
  256. package/dist/src/formats/pajek/index.d.ts +7 -0
  257. package/dist/src/formats/pajek/index.d.ts.map +1 -0
  258. package/dist/src/formats/pajek/index.js +7 -0
  259. package/dist/src/formats/pajek/index.js.map +1 -0
  260. package/dist/src/formats/pajek/syntax.d.ts +112 -0
  261. package/dist/src/formats/pajek/syntax.d.ts.map +1 -0
  262. package/dist/src/formats/pajek/syntax.js +269 -0
  263. package/dist/src/formats/pajek/syntax.js.map +1 -0
  264. package/dist/src/index.d.ts +35 -0
  265. package/dist/src/index.d.ts.map +1 -0
  266. package/dist/src/index.js +39 -0
  267. package/dist/src/index.js.map +1 -0
  268. package/dist/src/registry.d.ts +207 -0
  269. package/dist/src/registry.d.ts.map +1 -0
  270. package/dist/src/registry.js +481 -0
  271. package/dist/src/registry.js.map +1 -0
  272. package/dist/src/sniff.d.ts +104 -0
  273. package/dist/src/sniff.d.ts.map +1 -0
  274. package/dist/src/sniff.js +357 -0
  275. package/dist/src/sniff.js.map +1 -0
  276. package/dist/src/types.d.ts +238 -0
  277. package/dist/src/types.d.ts.map +1 -0
  278. package/dist/src/types.js +29 -0
  279. package/dist/src/types.js.map +1 -0
  280. package/dist/tsconfig.build.tsbuildinfo +1 -0
  281. package/package.json +122 -7
  282. package/src/children.ts +335 -0
  283. package/src/common/attributes.ts +520 -0
  284. package/src/common/codes.ts +153 -0
  285. package/src/common/declared-types.ts +374 -0
  286. package/src/common/direction.ts +518 -0
  287. package/src/common/escape.ts +231 -0
  288. package/src/common/export.ts +817 -0
  289. package/src/common/format.ts +111 -0
  290. package/src/common/ids.ts +176 -0
  291. package/src/common/input.ts +378 -0
  292. package/src/common/lists.ts +196 -0
  293. package/src/common/options.ts +377 -0
  294. package/src/common/report.ts +352 -0
  295. package/src/common/temporal.ts +302 -0
  296. package/src/common/text.ts +294 -0
  297. package/src/common/weights.ts +202 -0
  298. package/src/common/writer.ts +123 -0
  299. package/src/common/xml.ts +1053 -0
  300. package/src/formats/csv/exporter.ts +894 -0
  301. package/src/formats/csv/header.ts +172 -0
  302. package/src/formats/csv/importer.ts +1104 -0
  303. package/src/formats/csv/index.ts +88 -0
  304. package/src/formats/csv/records.ts +813 -0
  305. package/src/formats/csv/values.ts +224 -0
  306. package/src/formats/dot/exporter.ts +1014 -0
  307. package/src/formats/dot/importer.ts +1549 -0
  308. package/src/formats/dot/index.ts +7 -0
  309. package/src/formats/dot/names.ts +40 -0
  310. package/src/formats/dot/tokenizer.ts +384 -0
  311. package/src/formats/gexf/exporter.ts +1696 -0
  312. package/src/formats/gexf/importer.ts +2333 -0
  313. package/src/formats/gexf/index.ts +142 -0
  314. package/src/formats/gexf/schema.ts +361 -0
  315. package/src/formats/gml/exporter.ts +1404 -0
  316. package/src/formats/gml/importer.ts +1591 -0
  317. package/src/formats/gml/index.ts +128 -0
  318. package/src/formats/gml/syntax.ts +545 -0
  319. package/src/formats/graphml/constants.ts +225 -0
  320. package/src/formats/graphml/exporter.ts +1458 -0
  321. package/src/formats/graphml/importer.ts +2027 -0
  322. package/src/formats/graphml/index.ts +8 -0
  323. package/src/formats/graphml/tree.ts +318 -0
  324. package/src/formats/json/dialect.ts +317 -0
  325. package/src/formats/json/exporter.ts +1616 -0
  326. package/src/formats/json/importer.ts +2271 -0
  327. package/src/formats/json/index.ts +8 -0
  328. package/src/formats/neo4j/exporter.ts +1287 -0
  329. package/src/formats/neo4j/header.ts +156 -0
  330. package/src/formats/neo4j/importer.ts +1220 -0
  331. package/src/formats/neo4j/index.ts +116 -0
  332. package/src/formats/pajek/exporter.ts +1000 -0
  333. package/src/formats/pajek/importer.ts +1311 -0
  334. package/src/formats/pajek/index.ts +7 -0
  335. package/src/formats/pajek/syntax.ts +307 -0
  336. package/src/index.ts +244 -0
  337. package/src/registry.ts +617 -0
  338. package/src/sniff.ts +397 -0
  339. package/src/types.ts +262 -0
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Number formatting for exporters (design section 3.7): an f32 weight is written as the shortest
3
+ * decimal that round-trips through Math.fround (never `String(x)`, which prints
4
+ * 0.10000000149011612 for a stored 0.1); an f64 value as its shortest JS text; a GML real always
5
+ * with a decimal point so the dtype survives (design section 8.5); non-finite values as the
6
+ * spelling the target syntax accepts.
7
+ */
8
+ /**
9
+ * The shortest decimal text that reads back to the same f32 value through Math.fround.
10
+ * @param value - an f32 value (a JS number holding one)
11
+ * @returns the text; "Infinity" / "-Infinity" / "NaN" for the non-finite values, "0" for both zeros
12
+ */
13
+ export declare function formatF32(value: number): string;
14
+ /**
15
+ * The shortest text of an f64 value: `String(x)`, which is already the shortest round-tripping
16
+ * decimal in JS.
17
+ * @param value - the value
18
+ * @returns the text; "Infinity" / "-Infinity" / "NaN" for the non-finite values
19
+ */
20
+ export declare function formatF64(value: number): string;
21
+ /**
22
+ * A decimal text with a decimal point or an exponent guaranteed for a finite value (`2.0`,
23
+ * `1e+21`, `1.5e-7`), so an
24
+ * untyped re-import keeps the column f64 rather than i32 (design section 8.5); negative zero is
25
+ * written `-0.0` so it reads back as -0; non-finite values are the JS spellings (`Infinity`,
26
+ * `-Infinity`, `NaN`), which the CSV / DOT / Pajek importers read back as text. The one
27
+ * implementation of the "decimal point guaranteed" rule for every text format; GML has its own
28
+ * spellings of the non-finite values in formatGmlReal().
29
+ * @param value - the value
30
+ * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text
31
+ * @returns the text
32
+ */
33
+ export declare function formatDecimal(value: number, dtype?: "f32" | "f64" | "i32" | "u32" | "u8"): string;
34
+ /**
35
+ * A GML real: the shortest text with a decimal point guaranteed (`2.0`, `1.0e-7`), so a re-import
36
+ * keeps the column real rather than int. Non-finite values have no GML spelling and are written
37
+ * as the texts NetworkX's writer emits and its reader accepts, `+INF`, `-INF` and `NAN` (the
38
+ * lowercase `inf` / `nan` would lex as keys there).
39
+ * @param value - the value
40
+ * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text
41
+ * @returns the text
42
+ */
43
+ export declare function formatGmlReal(value: number, dtype?: "f32" | "f64" | "i32" | "u32" | "u8"): string;
44
+ /**
45
+ * An integer text for a value known to be integral (an i32 / u32 / u8 cell, an f64 that holds an
46
+ * integer), avoiding the exponent form `String()` uses above 1e21.
47
+ * @param value - an integral value
48
+ * @returns the digits
49
+ */
50
+ export declare function formatInteger(value: number): string;
51
+ /**
52
+ * The text of a numeric cell of any numeric dtype, dispatching on the dtype: f32 through
53
+ * formatF32, everything else through formatF64.
54
+ * @param value - the value
55
+ * @param dtype - the column dtype the value came from
56
+ * @returns the text
57
+ */
58
+ export declare function formatNumber(value: number, dtype: "f32" | "f64" | "i32" | "u32" | "u8"): string;
59
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/common/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAc/C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,IAAY,GAAG,MAAM,CAUxG;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,IAAY,GAAG,MAAM,CAcxG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,CAE/F"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Number formatting for exporters (design section 3.7): an f32 weight is written as the shortest
3
+ * decimal that round-trips through Math.fround (never `String(x)`, which prints
4
+ * 0.10000000149011612 for a stored 0.1); an f64 value as its shortest JS text; a GML real always
5
+ * with a decimal point so the dtype survives (design section 8.5); non-finite values as the
6
+ * spelling the target syntax accepts.
7
+ */
8
+ /**
9
+ * The shortest decimal text that reads back to the same f32 value through Math.fround.
10
+ * @param value - an f32 value (a JS number holding one)
11
+ * @returns the text; "Infinity" / "-Infinity" / "NaN" for the non-finite values, "0" for both zeros
12
+ */
13
+ export function formatF32(value) {
14
+ if (!Number.isFinite(value)) {
15
+ return String(value);
16
+ }
17
+ if (value === 0) {
18
+ return "0";
19
+ }
20
+ for (let digits = 1; digits <= 9; digits++) {
21
+ const text = value.toPrecision(digits);
22
+ if (Math.fround(Number(text)) === value) {
23
+ return String(Number(text));
24
+ }
25
+ }
26
+ return String(value);
27
+ }
28
+ /**
29
+ * The shortest text of an f64 value: `String(x)`, which is already the shortest round-tripping
30
+ * decimal in JS.
31
+ * @param value - the value
32
+ * @returns the text; "Infinity" / "-Infinity" / "NaN" for the non-finite values
33
+ */
34
+ export function formatF64(value) {
35
+ return String(value);
36
+ }
37
+ /**
38
+ * A decimal text with a decimal point or an exponent guaranteed for a finite value (`2.0`,
39
+ * `1e+21`, `1.5e-7`), so an
40
+ * untyped re-import keeps the column f64 rather than i32 (design section 8.5); negative zero is
41
+ * written `-0.0` so it reads back as -0; non-finite values are the JS spellings (`Infinity`,
42
+ * `-Infinity`, `NaN`), which the CSV / DOT / Pajek importers read back as text. The one
43
+ * implementation of the "decimal point guaranteed" rule for every text format; GML has its own
44
+ * spellings of the non-finite values in formatGmlReal().
45
+ * @param value - the value
46
+ * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text
47
+ * @returns the text
48
+ */
49
+ export function formatDecimal(value, dtype = "f64") {
50
+ if (!Number.isFinite(value)) {
51
+ return String(value);
52
+ }
53
+ if (Object.is(value, -0)) {
54
+ return "-0.0";
55
+ }
56
+ const text = formatNumber(value, dtype);
57
+ // an exponent form (`1e+21`, `1.5e-7`) is already f64 text under the 5.1 grammar
58
+ return text.includes(".") || text.includes("e") ? text : `${text}.0`;
59
+ }
60
+ /**
61
+ * A GML real: the shortest text with a decimal point guaranteed (`2.0`, `1.0e-7`), so a re-import
62
+ * keeps the column real rather than int. Non-finite values have no GML spelling and are written
63
+ * as the texts NetworkX's writer emits and its reader accepts, `+INF`, `-INF` and `NAN` (the
64
+ * lowercase `inf` / `nan` would lex as keys there).
65
+ * @param value - the value
66
+ * @param dtype - the column dtype the value comes from; f32 values use the shortest fround-round-trip text
67
+ * @returns the text
68
+ */
69
+ export function formatGmlReal(value, dtype = "f64") {
70
+ if (Number.isNaN(value)) {
71
+ return "NAN";
72
+ }
73
+ if (!Number.isFinite(value)) {
74
+ return value > 0 ? "+INF" : "-INF";
75
+ }
76
+ const text = formatDecimal(value, dtype);
77
+ if (text.includes(".")) {
78
+ return text;
79
+ }
80
+ // NetworkX's real pattern requires a decimal point even in the exponent form (`1.0e-7`)
81
+ const e = text.indexOf("e");
82
+ return `${text.slice(0, e)}.0${text.slice(e)}`;
83
+ }
84
+ /**
85
+ * An integer text for a value known to be integral (an i32 / u32 / u8 cell, an f64 that holds an
86
+ * integer), avoiding the exponent form `String()` uses above 1e21.
87
+ * @param value - an integral value
88
+ * @returns the digits
89
+ */
90
+ export function formatInteger(value) {
91
+ if (Number.isSafeInteger(value) || !Number.isFinite(value)) {
92
+ return String(value);
93
+ }
94
+ return BigInt(value).toString();
95
+ }
96
+ /**
97
+ * The text of a numeric cell of any numeric dtype, dispatching on the dtype: f32 through
98
+ * formatF32, everything else through formatF64.
99
+ * @param value - the value
100
+ * @param dtype - the column dtype the value came from
101
+ * @returns the text
102
+ */
103
+ export function formatNumber(value, dtype) {
104
+ return dtype === "f32" ? formatF32(value) : formatF64(value);
105
+ }
106
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/common/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,KAAK,K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AE,CAAC;QACtB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACvC,CAAC;IACD,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACzC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,wFAAwF;IACxF,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACvC,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAA2C;IACnF,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Id coercion (design section 4.1): the importer-side rule that turns a text cell or a JSON value
3
+ * into a NodeId before it reaches the sink. The core never coerces.
4
+ *
5
+ * - "keep": typed values pass through; anything that is not a string or a number is E_INVALID_ID.
6
+ * - "canonical": text becomes a number iff it is canonical integer text (`/^-?(0|[1-9][0-9]*)$/`
7
+ * and a safe integer, excluding "-0" which would collide with "0"); every other text stays a
8
+ * string. Injective on text, so `String(id)` on export reproduces the cell exactly: "01", "1.0"
9
+ * and "+1" stay strings, "1" becomes 1. Typed values pass through as under "keep".
10
+ * - "string": `String(v)` for strings, numbers, booleans, bigints and null; anything else is
11
+ * E_INVALID_ID.
12
+ * - "number": `Number(text)` for text (empty or whitespace-only text, NaN and non-finite results
13
+ * are E_INVALID_ID); numbers pass through; anything else is E_INVALID_ID. This rule can merge
14
+ * distinct cells ("01" and "1"); IdCoercer counts such merges so the importer can report them as
15
+ * coercion issues.
16
+ */
17
+ import { type IdCoercion, type NodeId } from "@graphty/graph-format";
18
+ import { ID_MERGED_CODE } from "./codes.js";
19
+ export { ID_MERGED_CODE };
20
+ /**
21
+ * The "canonical" rule on one text cell.
22
+ * @param text - the cell text, exactly as read
23
+ * @returns the number for canonical safe-integer text (never for "-0"), the text itself otherwise
24
+ */
25
+ export declare function canonicalId(text: string): NodeId;
26
+ /**
27
+ * Whether a text cell is canonical integer text under the "canonical" rule (a number after import).
28
+ * @param text - the cell text
29
+ * @returns true when canonicalId(text) returns a number
30
+ */
31
+ export declare function isCanonicalIntegerText(text: string): boolean;
32
+ /**
33
+ * Coerce a text cell under a rule.
34
+ * @param text - the cell text, exactly as read
35
+ * @param mode - the coercion rule
36
+ * @returns the id; E_INVALID_ID when the rule rejects the text
37
+ */
38
+ export declare function coerceIdText(text: string, mode: IdCoercion): NodeId;
39
+ /**
40
+ * Coerce a typed value (a JSON scalar, a record field) under a rule.
41
+ * @param value - the value
42
+ * @param mode - the coercion rule
43
+ * @returns the id; E_INVALID_ID when the rule rejects the value
44
+ */
45
+ export declare function coerceId(value: unknown, mode: IdCoercion): NodeId;
46
+ /**
47
+ * A stateful coercer for one import call: applies the rule and, under "number", detects merges
48
+ * (two distinct texts mapping to one number) so the importer can report them as coercion issues
49
+ * (design section 4.1).
50
+ */
51
+ export declare class IdCoercer {
52
+ /** The rule. */
53
+ readonly mode: IdCoercion;
54
+ /** Texts merged into an id another text already produced. */
55
+ mergeCount: number;
56
+ /** The text that first produced each numeric id, kept only under "number". */
57
+ private readonly firstText;
58
+ /** The merge detected by the most recent text() call, or null. */
59
+ lastMerge: {
60
+ readonly id: number;
61
+ readonly text: string;
62
+ readonly previousText: string;
63
+ } | null;
64
+ /**
65
+ * Create a coercer.
66
+ * @param mode - the rule
67
+ */
68
+ constructor(mode: IdCoercion);
69
+ /**
70
+ * Coerce a text cell, recording a merge under "number" when a different text already produced
71
+ * the same number.
72
+ * @param text - the cell text
73
+ * @returns the id
74
+ */
75
+ text(text: string): NodeId;
76
+ /**
77
+ * Coerce a typed value.
78
+ * @param value - the value
79
+ * @returns the id
80
+ */
81
+ value(value: unknown): NodeId;
82
+ }
83
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/common/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAoB,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAsBnE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAcjE;AAgBD;;;;GAIG;AACH,qBAAa,SAAS;IAClB,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAE1B,6DAA6D;IAC7D,UAAU,SAAK;IAEf,8EAA8E;IAC9E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IAEvD,kEAAkE;IAClE,SAAS,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAQ;IAEvG;;;OAGG;gBACS,IAAI,EAAE,UAAU;IAK5B;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAe1B;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAOhC"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Id coercion (design section 4.1): the importer-side rule that turns a text cell or a JSON value
3
+ * into a NodeId before it reaches the sink. The core never coerces.
4
+ *
5
+ * - "keep": typed values pass through; anything that is not a string or a number is E_INVALID_ID.
6
+ * - "canonical": text becomes a number iff it is canonical integer text (`/^-?(0|[1-9][0-9]*)$/`
7
+ * and a safe integer, excluding "-0" which would collide with "0"); every other text stays a
8
+ * string. Injective on text, so `String(id)` on export reproduces the cell exactly: "01", "1.0"
9
+ * and "+1" stay strings, "1" becomes 1. Typed values pass through as under "keep".
10
+ * - "string": `String(v)` for strings, numbers, booleans, bigints and null; anything else is
11
+ * E_INVALID_ID.
12
+ * - "number": `Number(text)` for text (empty or whitespace-only text, NaN and non-finite results
13
+ * are E_INVALID_ID); numbers pass through; anything else is E_INVALID_ID. This rule can merge
14
+ * distinct cells ("01" and "1"); IdCoercer counts such merges so the importer can report them as
15
+ * coercion issues.
16
+ */
17
+ import { GraphFormatError } from "@graphty/graph-format";
18
+ import { ID_MERGED_CODE } from "./codes.js";
19
+ const CANONICAL_INTEGER = /^-?(0|[1-9][0-9]*)$/;
20
+ export { ID_MERGED_CODE };
21
+ /**
22
+ * The "canonical" rule on one text cell.
23
+ * @param text - the cell text, exactly as read
24
+ * @returns the number for canonical safe-integer text (never for "-0"), the text itself otherwise
25
+ */
26
+ export function canonicalId(text) {
27
+ if (text !== "-0" && CANONICAL_INTEGER.test(text)) {
28
+ const n = Number(text);
29
+ if (Number.isSafeInteger(n)) {
30
+ return n;
31
+ }
32
+ }
33
+ return text;
34
+ }
35
+ /**
36
+ * Whether a text cell is canonical integer text under the "canonical" rule (a number after import).
37
+ * @param text - the cell text
38
+ * @returns true when canonicalId(text) returns a number
39
+ */
40
+ export function isCanonicalIntegerText(text) {
41
+ return typeof canonicalId(text) === "number";
42
+ }
43
+ /**
44
+ * Coerce a text cell under a rule.
45
+ * @param text - the cell text, exactly as read
46
+ * @param mode - the coercion rule
47
+ * @returns the id; E_INVALID_ID when the rule rejects the text
48
+ */
49
+ export function coerceIdText(text, mode) {
50
+ switch (mode) {
51
+ case "keep":
52
+ case "string":
53
+ return text;
54
+ case "canonical":
55
+ return canonicalId(text);
56
+ case "number": {
57
+ if (text.trim().length === 0) {
58
+ throw invalidId(text, "empty text is not a number");
59
+ }
60
+ const n = Number(text);
61
+ if (!Number.isFinite(n)) {
62
+ throw invalidId(text, "not a finite number");
63
+ }
64
+ return n;
65
+ }
66
+ default: {
67
+ const name = mode;
68
+ throw new GraphFormatError("E_UNSUPPORTED", `unknown id coercion ${name}`, { option: "ids", found: name });
69
+ }
70
+ }
71
+ }
72
+ /**
73
+ * Coerce a typed value (a JSON scalar, a record field) under a rule.
74
+ * @param value - the value
75
+ * @param mode - the coercion rule
76
+ * @returns the id; E_INVALID_ID when the rule rejects the value
77
+ */
78
+ export function coerceId(value, mode) {
79
+ if (typeof value === "string") {
80
+ return coerceIdText(value, mode);
81
+ }
82
+ if (typeof value === "number") {
83
+ if (!Number.isFinite(value)) {
84
+ throw invalidId(value, "not a finite number");
85
+ }
86
+ return mode === "string" ? String(value) : value;
87
+ }
88
+ if (mode === "string" && (typeof value === "boolean" || typeof value === "bigint" || value === null)) {
89
+ return String(value);
90
+ }
91
+ throw invalidId(value, `a ${value === null ? "null" : typeof value} is not an id under ids: "${mode}"`);
92
+ }
93
+ /**
94
+ * The E_INVALID_ID error of a rejected value.
95
+ * @param value - the rejected value
96
+ * @param reason - why
97
+ * @returns the error
98
+ */
99
+ function invalidId(value, reason) {
100
+ const shown = typeof value === "string" || typeof value === "number" ? value : typeof value;
101
+ return new GraphFormatError("E_INVALID_ID", `invalid node id ${JSON.stringify(shown)}: ${reason}`, {
102
+ reason,
103
+ value: typeof value === "bigint" ? value.toString() : value,
104
+ });
105
+ }
106
+ /**
107
+ * A stateful coercer for one import call: applies the rule and, under "number", detects merges
108
+ * (two distinct texts mapping to one number) so the importer can report them as coercion issues
109
+ * (design section 4.1).
110
+ */
111
+ export class IdCoercer {
112
+ /**
113
+ * Create a coercer.
114
+ * @param mode - the rule
115
+ */
116
+ constructor(mode) {
117
+ /** Texts merged into an id another text already produced. */
118
+ this.mergeCount = 0;
119
+ /** The merge detected by the most recent text() call, or null. */
120
+ this.lastMerge = null;
121
+ this.mode = mode;
122
+ this.firstText = mode === "number" ? new Map() : null;
123
+ }
124
+ /**
125
+ * Coerce a text cell, recording a merge under "number" when a different text already produced
126
+ * the same number.
127
+ * @param text - the cell text
128
+ * @returns the id
129
+ */
130
+ text(text) {
131
+ const id = coerceIdText(text, this.mode);
132
+ this.lastMerge = null;
133
+ if (this.firstText !== null && typeof id === "number") {
134
+ const previous = this.firstText.get(id);
135
+ if (previous === undefined) {
136
+ this.firstText.set(id, text);
137
+ }
138
+ else if (previous !== text) {
139
+ this.mergeCount++;
140
+ this.lastMerge = { id, text, previousText: previous };
141
+ }
142
+ }
143
+ return id;
144
+ }
145
+ /**
146
+ * Coerce a typed value.
147
+ * @param value - the value
148
+ * @returns the id
149
+ */
150
+ value(value) {
151
+ if (typeof value === "string") {
152
+ return this.text(value);
153
+ }
154
+ this.lastMerge = null;
155
+ return coerceId(value, this.mode);
156
+ }
157
+ }
158
+ //# sourceMappingURL=ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../src/common/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,gBAAgB,EAAgC,MAAM,uBAAuB,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,IAAI,IAAI,KAAK,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,CAAC;QACb,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IAC/C,OAAO,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAgB;IACvD,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ;YACT,OAAO,IAAI,CAAC;QAChB,KAAK,WAAW;YACZ,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;QAC7B,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,MAAM,SAAS,CAAC,IAAI,EAAE,4BAA4B,CAAC,CAAC;YACxD,CAAC;YACD,MA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AI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACjC,CAAC;iBAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,IAAI,CAAC,SAAS,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;YAC1D,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAc;QAChB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACJ"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Input handling shared by every importer (design section 8.4): the ImportInput union (whole
3
+ * text, whole bytes, a byte stream, an async iterable of text or byte chunks) read as a sequence of
4
+ * UTF-8 text chunks, as lines, or as one string, with BOM handling, cancellation through an
5
+ * AbortSignal and byte progress.
6
+ *
7
+ * Bytes are decoded with `new TextDecoder("utf-8", { fatal: true })` in streaming mode, so a
8
+ * multi-byte character split across two chunks decodes correctly and an invalid sequence is a
9
+ * parse-error (issue code E_INVALID_UTF8) that aborts the import, never a silent U+FFFD that could
10
+ * alias two ids. A leading U+FEFF is stripped from text and from decoded bytes alike.
11
+ */
12
+ import { type ImportInput } from "../types.js";
13
+ import { INVALID_UTF8_CODE } from "./codes.js";
14
+ import { type ImportReportBuilder } from "./report.js";
15
+ export { INVALID_UTF8_CODE };
16
+ /**
17
+ * Cancellation and progress hooks of the reader; the resolved importer options satisfy this shape.
18
+ * Consumed by the per-format importers and exporters under src/formats.
19
+ * @public
20
+ */
21
+ export interface ReadOptions {
22
+ /** The cancellation signal, or null / undefined for none. */
23
+ readonly signal?: AbortSignal | null | undefined;
24
+ /** The progress callback, or null / undefined for none. */
25
+ readonly onProgress?: ((bytesDone: number, bytesTotal?: number) => void) | null | undefined;
26
+ }
27
+ /**
28
+ * Whether a value is an ImportInput this module can read.
29
+ * @param input - any value
30
+ * @returns true for a string, a Uint8Array, a ReadableStream or an async iterable
31
+ */
32
+ export declare function isImportInput(input: unknown): input is ImportInput;
33
+ /**
34
+ * The total size of an in-memory input (bytes for a Uint8Array, UTF-16 code units for a string),
35
+ * for the `bytesTotal` argument of onProgress; null for a stream or an iterable.
36
+ * @param input - the input
37
+ * @returns the size, or null when unknown up front
38
+ */
39
+ export declare function inputLength(input: ImportInput): number | null;
40
+ /**
41
+ * Throw the signal's reason when it is aborted, exactly as the platform's
42
+ * `AbortSignal.throwIfAborted()` does: the reason as it is (the DOMException named "AbortError"
43
+ * of a reason-less abort, or whatever the caller passed to `abort(reason)`, an Error or not), so a
44
+ * caller can compare the rejection with `signal.reason`. Only a runtime that stores no reason at
45
+ * all gets a synthesised AbortError.
46
+ * @param signal - the signal, or null
47
+ */
48
+ export declare function throwIfAborted(signal: AbortSignal | null | undefined): void;
49
+ /**
50
+ * Read an ImportInput as a sequence of decoded text chunks. Chunk boundaries carry no meaning:
51
+ * a caller that needs lines uses LineReader, one that needs the whole document uses readText().
52
+ * The signal is checked before every chunk; a stream is cancelled when the consumer stops early
53
+ * or the signal fires. Progress is reported after every chunk.
54
+ * @param input - the input
55
+ * @param report - the report the decode error is recorded in (E_INVALID_UTF8, then ImportError)
56
+ * @param options - cancellation and progress
57
+ * @yields decoded text; the first chunk has any leading BOM removed
58
+ * @returns nothing
59
+ */
60
+ export declare function textChunks(input: ImportInput, report: ImportReportBuilder, options?: ReadOptions): AsyncGenerator<string, void, undefined>;
61
+ /**
62
+ * Read the whole input as one string (the GML / DOT / JSON path, design section 8.4).
63
+ * @param input - the input
64
+ * @param report - the report the decode error is recorded in
65
+ * @param options - cancellation and progress
66
+ * @returns the decoded text without a leading BOM
67
+ */
68
+ export declare function readText(input: ImportInput, report: ImportReportBuilder, options?: ReadOptions): Promise<string>;
69
+ /**
70
+ * Lines of an ImportInput without allocating anything per line but the string itself: iterate with
71
+ * `for await (const text of reader)` and read `reader.line` (1-based) for the line just yielded.
72
+ * `\n`, `\r\n` and lone `\r` all end a line; the terminator is not part of the text; a final
73
+ * line without a terminator is yielded when non-empty, and every line in between is yielded even
74
+ * when empty (the importer decides what a blank line means).
75
+ */
76
+ export declare class LineReader implements AsyncIterable<string> {
77
+ private readonly input;
78
+ private readonly report;
79
+ private readonly options;
80
+ private lineNumber;
81
+ /**
82
+ * Create a reader over an input; nothing is read until iteration starts.
83
+ * @param input - the input
84
+ * @param report - the report decode errors are recorded in
85
+ * @param options - cancellation and progress
86
+ */
87
+ constructor(input: ImportInput, report: ImportReportBuilder, options?: ReadOptions);
88
+ /**
89
+ * The 1-based number of the line most recently yielded.
90
+ * @returns the line number; 0 before the first line
91
+ */
92
+ get line(): number;
93
+ /**
94
+ * Iterate the lines.
95
+ * @yields one line at a time, terminator removed
96
+ * @returns nothing
97
+ */
98
+ [Symbol.asyncIterator](): AsyncGenerator<string, void, undefined>;
99
+ }
100
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/common/input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B;;;;GAIG;AACH,MAAM,WAAW,WAAW;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACjD,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