@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +13651 -0
  3. package/dist/directive.d.ts +40 -0
  4. package/dist/editing.d.ts +46 -0
  5. package/dist/enrichment.d.ts +5 -0
  6. package/dist/expression.d.ts +26 -0
  7. package/dist/image-destinations.d.ts +3 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/index.js +10118 -0
  10. package/dist/parser.d.ts +40 -0
  11. package/dist/registry.d.ts +144 -0
  12. package/dist/source.d.ts +28 -0
  13. package/package.json +280 -3
  14. package/parser-provenance.json +1419 -0
  15. package/patches/README.md +5 -0
  16. package/patches/micromark.patch +84 -0
  17. package/vendor/@noble/hashes/LICENSE +21 -0
  18. package/vendor/@noble/hashes/_md.js +209 -0
  19. package/vendor/@noble/hashes/_u64.js +77 -0
  20. package/vendor/@noble/hashes/package.json +91 -0
  21. package/vendor/@noble/hashes/sha2.js +446 -0
  22. package/vendor/@noble/hashes/utils.js +687 -0
  23. package/vendor/character-entities/index.js +2132 -0
  24. package/vendor/character-entities/license +22 -0
  25. package/vendor/character-entities/package.json +78 -0
  26. package/vendor/decode-named-character-reference/index.js +19 -0
  27. package/vendor/decode-named-character-reference/license +22 -0
  28. package/vendor/decode-named-character-reference/package.json +90 -0
  29. package/vendor/devlop/lib/default.js +9 -0
  30. package/vendor/devlop/license +22 -0
  31. package/vendor/devlop/package.json +80 -0
  32. package/vendor/longest-streak/index.js +36 -0
  33. package/vendor/longest-streak/license +22 -0
  34. package/vendor/longest-streak/package.json +73 -0
  35. package/vendor/markdown-table/index.js +393 -0
  36. package/vendor/markdown-table/license +22 -0
  37. package/vendor/markdown-table/package.json +77 -0
  38. package/vendor/mdast-util-from-markdown/index.js +2 -0
  39. package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
  40. package/vendor/mdast-util-from-markdown/license +22 -0
  41. package/vendor/mdast-util-from-markdown/package.json +98 -0
  42. package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
  43. package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
  44. package/vendor/mdast-util-gfm-strikethrough/license +22 -0
  45. package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
  46. package/vendor/mdast-util-gfm-table/index.js +2 -0
  47. package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
  48. package/vendor/mdast-util-gfm-table/license +22 -0
  49. package/vendor/mdast-util-gfm-table/package.json +101 -0
  50. package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
  51. package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
  52. package/vendor/mdast-util-gfm-task-list-item/license +22 -0
  53. package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
  54. package/vendor/mdast-util-phrasing/index.js +1 -0
  55. package/vendor/mdast-util-phrasing/lib/index.js +45 -0
  56. package/vendor/mdast-util-phrasing/license +23 -0
  57. package/vendor/mdast-util-phrasing/package.json +78 -0
  58. package/vendor/mdast-util-to-markdown/index.js +3 -0
  59. package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
  60. package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
  61. package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
  62. package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
  63. package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
  64. package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
  65. package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
  66. package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
  67. package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
  68. package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
  69. package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
  70. package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
  71. package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
  72. package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
  73. package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
  74. package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
  75. package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
  76. package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
  77. package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
  78. package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
  79. package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
  80. package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
  81. package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
  82. package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
  83. package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
  84. package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
  85. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
  86. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
  87. package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
  88. package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
  89. package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
  90. package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
  91. package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
  92. package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
  93. package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
  94. package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
  95. package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
  96. package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
  97. package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
  98. package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
  99. package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
  100. package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
  101. package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
  102. package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
  103. package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  104. package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
  105. package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
  106. package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
  107. package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
  108. package/vendor/mdast-util-to-markdown/license +22 -0
  109. package/vendor/mdast-util-to-markdown/package.json +88 -0
  110. package/vendor/mdast-util-to-string/index.js +5 -0
  111. package/vendor/mdast-util-to-string/lib/index.js +108 -0
  112. package/vendor/mdast-util-to-string/license +22 -0
  113. package/vendor/mdast-util-to-string/package.json +78 -0
  114. package/vendor/micromark/index.js +60 -0
  115. package/vendor/micromark/lib/compile.js +1068 -0
  116. package/vendor/micromark/lib/constructs.js +85 -0
  117. package/vendor/micromark/lib/create-tokenizer.js +615 -0
  118. package/vendor/micromark/lib/initialize/content.js +79 -0
  119. package/vendor/micromark/lib/initialize/document.js +370 -0
  120. package/vendor/micromark/lib/initialize/flow.js +58 -0
  121. package/vendor/micromark/lib/initialize/text.js +216 -0
  122. package/vendor/micromark/lib/parse.js +56 -0
  123. package/vendor/micromark/lib/postprocess.js +18 -0
  124. package/vendor/micromark/lib/preprocess.js +112 -0
  125. package/vendor/micromark/license +22 -0
  126. package/vendor/micromark/package.json +87 -0
  127. package/vendor/micromark-core-commonmark/index.js +22 -0
  128. package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
  129. package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
  130. package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
  131. package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
  132. package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
  133. package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
  134. package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
  135. package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
  136. package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
  137. package/vendor/micromark-core-commonmark/lib/content.js +163 -0
  138. package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
  139. package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
  140. package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
  141. package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
  142. package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
  143. package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
  144. package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
  145. package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
  146. package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
  147. package/vendor/micromark-core-commonmark/lib/list.js +213 -0
  148. package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
  149. package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
  150. package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
  151. package/vendor/micromark-core-commonmark/license +22 -0
  152. package/vendor/micromark-core-commonmark/package.json +62 -0
  153. package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
  154. package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
  155. package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
  156. package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
  157. package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
  158. package/vendor/micromark-extension-gfm-table/index.js +2 -0
  159. package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
  160. package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
  161. package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
  162. package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
  163. package/vendor/micromark-extension-gfm-table/license +22 -0
  164. package/vendor/micromark-extension-gfm-table/package.json +86 -0
  165. package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
  166. package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
  167. package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
  168. package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
  169. package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
  170. package/vendor/micromark-factory-destination/index.js +206 -0
  171. package/vendor/micromark-factory-destination/license +22 -0
  172. package/vendor/micromark-factory-destination/package.json +57 -0
  173. package/vendor/micromark-factory-label/index.js +148 -0
  174. package/vendor/micromark-factory-label/license +22 -0
  175. package/vendor/micromark-factory-label/package.json +60 -0
  176. package/vendor/micromark-factory-space/index.js +116 -0
  177. package/vendor/micromark-factory-space/license +22 -0
  178. package/vendor/micromark-factory-space/package.json +46 -0
  179. package/vendor/micromark-factory-title/index.js +158 -0
  180. package/vendor/micromark-factory-title/license +22 -0
  181. package/vendor/micromark-factory-title/package.json +58 -0
  182. package/vendor/micromark-factory-whitespace/index.js +44 -0
  183. package/vendor/micromark-factory-whitespace/license +22 -0
  184. package/vendor/micromark-factory-whitespace/package.json +57 -0
  185. package/vendor/micromark-util-character/index.js +246 -0
  186. package/vendor/micromark-util-character/license +22 -0
  187. package/vendor/micromark-util-character/package.json +57 -0
  188. package/vendor/micromark-util-chunked/index.js +81 -0
  189. package/vendor/micromark-util-chunked/license +22 -0
  190. package/vendor/micromark-util-chunked/package.json +57 -0
  191. package/vendor/micromark-util-classify-character/index.js +27 -0
  192. package/vendor/micromark-util-classify-character/license +22 -0
  193. package/vendor/micromark-util-classify-character/package.json +59 -0
  194. package/vendor/micromark-util-combine-extensions/index.js +143 -0
  195. package/vendor/micromark-util-combine-extensions/license +22 -0
  196. package/vendor/micromark-util-combine-extensions/package.json +52 -0
  197. package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
  198. package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
  199. package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
  200. package/vendor/micromark-util-decode-string/index.js +45 -0
  201. package/vendor/micromark-util-decode-string/license +22 -0
  202. package/vendor/micromark-util-decode-string/package.json +63 -0
  203. package/vendor/micromark-util-edit-map/index.js +225 -0
  204. package/vendor/micromark-util-edit-map/license +22 -0
  205. package/vendor/micromark-util-edit-map/package.json +48 -0
  206. package/vendor/micromark-util-encode/index.js +33 -0
  207. package/vendor/micromark-util-encode/license +22 -0
  208. package/vendor/micromark-util-encode/package.json +47 -0
  209. package/vendor/micromark-util-html-tag-name/index.js +93 -0
  210. package/vendor/micromark-util-html-tag-name/license +22 -0
  211. package/vendor/micromark-util-html-tag-name/package.json +47 -0
  212. package/vendor/micromark-util-normalize-identifier/index.js +33 -0
  213. package/vendor/micromark-util-normalize-identifier/license +22 -0
  214. package/vendor/micromark-util-normalize-identifier/package.json +58 -0
  215. package/vendor/micromark-util-resolve-all/index.js +32 -0
  216. package/vendor/micromark-util-resolve-all/license +22 -0
  217. package/vendor/micromark-util-resolve-all/package.json +48 -0
  218. package/vendor/micromark-util-sanitize-uri/index.js +107 -0
  219. package/vendor/micromark-util-sanitize-uri/license +22 -0
  220. package/vendor/micromark-util-sanitize-uri/package.json +59 -0
  221. package/vendor/micromark-util-subtokenize/index.js +228 -0
  222. package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
  223. package/vendor/micromark-util-subtokenize/license +22 -0
  224. package/vendor/micromark-util-subtokenize/package.json +60 -0
  225. package/vendor/unist-util-is/index.js +7 -0
  226. package/vendor/unist-util-is/lib/index.js +296 -0
  227. package/vendor/unist-util-is/license +22 -0
  228. package/vendor/unist-util-is/package.json +103 -0
  229. package/vendor/unist-util-stringify-position/index.js +1 -0
  230. package/vendor/unist-util-stringify-position/lib/index.js +84 -0
  231. package/vendor/unist-util-stringify-position/license +22 -0
  232. package/vendor/unist-util-stringify-position/package.json +80 -0
  233. package/vendor/unist-util-visit/index.js +2 -0
  234. package/vendor/unist-util-visit/lib/index.js +312 -0
  235. package/vendor/unist-util-visit/license +22 -0
  236. package/vendor/unist-util-visit/package.json +108 -0
  237. package/vendor/unist-util-visit-parents/index.js +2 -0
  238. package/vendor/unist-util-visit-parents/lib/color.js +7 -0
  239. package/vendor/unist-util-visit-parents/lib/index.js +399 -0
  240. package/vendor/unist-util-visit-parents/license +22 -0
  241. package/vendor/unist-util-visit-parents/package.json +106 -0
  242. package/vendor/zwitch/index.js +118 -0
  243. package/vendor/zwitch/license +22 -0
  244. package/vendor/zwitch/package.json +72 -0
  245. package/README.md +0 -3
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "unist-util-is",
3
+ "version": "6.0.1",
4
+ "description": "unist utility to check if a node passes a test",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "unist",
8
+ "unist-util",
9
+ "util",
10
+ "utility",
11
+ "tree",
12
+ "node",
13
+ "is",
14
+ "equal",
15
+ "check",
16
+ "test",
17
+ "type"
18
+ ],
19
+ "repository": "syntax-tree/unist-util-is",
20
+ "bugs": "https://github.com/syntax-tree/unist-util-is/issues",
21
+ "funding": {
22
+ "type": "opencollective",
23
+ "url": "https://opencollective.com/unified"
24
+ },
25
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
26
+ "contributors": [
27
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
28
+ "Christian Murphy <christian.murphy.42@gmail.com>",
29
+ "Lucas Brandstaetter <lucas@brandstaetter.tech> (https://github.com/Roang-zero1)"
30
+ ],
31
+ "sideEffects": false,
32
+ "type": "module",
33
+ "exports": "./index.js",
34
+ "files": [
35
+ "lib/",
36
+ "index.d.ts.map",
37
+ "index.d.ts",
38
+ "index.js"
39
+ ],
40
+ "dependencies": {
41
+ "@types/unist": "^3.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/mdast": "^4.0.0",
45
+ "@types/node": "^24.0.0",
46
+ "c8": "^10.0.0",
47
+ "prettier": "^3.0.0",
48
+ "remark-cli": "^12.0.0",
49
+ "remark-preset-wooorm": "^11.0.0",
50
+ "tsd": "^0.33.0",
51
+ "type-coverage": "^2.0.0",
52
+ "typescript": "^5.0.0",
53
+ "xo": "^0.58.0"
54
+ },
55
+ "scripts": {
56
+ "prepack": "npm run build && npm run format",
57
+ "build": "tsc --build --clean && tsc --build && tsd && type-coverage",
58
+ "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
59
+ "test-api": "node --conditions development test/index.js",
60
+ "test-coverage": "c8 --100 --reporter lcov npm run test-api",
61
+ "test": "npm run build && npm run format && npm run test-coverage"
62
+ },
63
+ "prettier": {
64
+ "bracketSpacing": false,
65
+ "semi": false,
66
+ "singleQuote": true,
67
+ "tabWidth": 2,
68
+ "trailingComma": "none",
69
+ "useTabs": false
70
+ },
71
+ "remarkConfig": {
72
+ "plugins": [
73
+ "remark-preset-wooorm"
74
+ ]
75
+ },
76
+ "typeCoverage": {
77
+ "atLeast": 100,
78
+ "detail": true,
79
+ "#": "needed `any`s",
80
+ "ignoreFiles": [
81
+ "lib/index.d.ts"
82
+ ],
83
+ "ignoreCatch": true,
84
+ "strict": true
85
+ },
86
+ "xo": {
87
+ "overrides": [
88
+ {
89
+ "files": [
90
+ "**/*.ts"
91
+ ],
92
+ "rules": {
93
+ "@typescript-eslint/consistent-type-definitions": "off",
94
+ "@typescript-eslint/no-unnecessary-type-arguments": "off",
95
+ "@typescript-eslint/no-unsafe-argument": "off",
96
+ "@typescript-eslint/no-unsafe-assignment": "off",
97
+ "import/no-extraneous-dependencies": "off"
98
+ }
99
+ }
100
+ ],
101
+ "prettier": true
102
+ }
103
+ }
@@ -0,0 +1 @@
1
+ export {stringifyPosition} from './lib/index.js'
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @typedef {import('unist').Node} Node
3
+ * @typedef {import('unist').Point} Point
4
+ * @typedef {import('unist').Position} Position
5
+ */
6
+
7
+ /**
8
+ * @typedef NodeLike
9
+ * @property {string} type
10
+ * @property {PositionLike | null | undefined} [position]
11
+ *
12
+ * @typedef PointLike
13
+ * @property {number | null | undefined} [line]
14
+ * @property {number | null | undefined} [column]
15
+ * @property {number | null | undefined} [offset]
16
+ *
17
+ * @typedef PositionLike
18
+ * @property {PointLike | null | undefined} [start]
19
+ * @property {PointLike | null | undefined} [end]
20
+ */
21
+
22
+ /**
23
+ * Serialize the positional info of a point, position (start and end points),
24
+ * or node.
25
+ *
26
+ * @param {Node | NodeLike | Point | PointLike | Position | PositionLike | null | undefined} [value]
27
+ * Node, position, or point.
28
+ * @returns {string}
29
+ * Pretty printed positional info of a node (`string`).
30
+ *
31
+ * In the format of a range `ls:cs-le:ce` (when given `node` or `position`)
32
+ * or a point `l:c` (when given `point`), where `l` stands for line, `c` for
33
+ * column, `s` for `start`, and `e` for end.
34
+ * An empty string (`''`) is returned if the given value is neither `node`,
35
+ * `position`, nor `point`.
36
+ */
37
+ export function stringifyPosition(value) {
38
+ // Nothing.
39
+ if (!value || typeof value !== 'object') {
40
+ return ''
41
+ }
42
+
43
+ // Node.
44
+ if ('position' in value || 'type' in value) {
45
+ return position(value.position)
46
+ }
47
+
48
+ // Position.
49
+ if ('start' in value || 'end' in value) {
50
+ return position(value)
51
+ }
52
+
53
+ // Point.
54
+ if ('line' in value || 'column' in value) {
55
+ return point(value)
56
+ }
57
+
58
+ // ?
59
+ return ''
60
+ }
61
+
62
+ /**
63
+ * @param {Point | PointLike | null | undefined} point
64
+ * @returns {string}
65
+ */
66
+ function point(point) {
67
+ return index(point && point.line) + ':' + index(point && point.column)
68
+ }
69
+
70
+ /**
71
+ * @param {Position | PositionLike | null | undefined} pos
72
+ * @returns {string}
73
+ */
74
+ function position(pos) {
75
+ return point(pos && pos.start) + '-' + point(pos && pos.end)
76
+ }
77
+
78
+ /**
79
+ * @param {number | null | undefined} value
80
+ * @returns {number}
81
+ */
82
+ function index(value) {
83
+ return value && typeof value === 'number' ? value : 1
84
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "unist-util-stringify-position",
3
+ "version": "4.0.0",
4
+ "description": "unist utility to serialize a node, position, or point as a human readable location",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "unist",
8
+ "unist-util",
9
+ "util",
10
+ "utility",
11
+ "position",
12
+ "location",
13
+ "point",
14
+ "node",
15
+ "stringify",
16
+ "tostring"
17
+ ],
18
+ "repository": "syntax-tree/unist-util-stringify-position",
19
+ "bugs": "https://github.com/syntax-tree/unist-util-stringify-position/issues",
20
+ "funding": {
21
+ "type": "opencollective",
22
+ "url": "https://opencollective.com/unified"
23
+ },
24
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
25
+ "contributors": [
26
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
27
+ ],
28
+ "sideEffects": false,
29
+ "type": "module",
30
+ "exports": "./index.js",
31
+ "files": [
32
+ "lib/",
33
+ "index.d.ts",
34
+ "index.js"
35
+ ],
36
+ "dependencies": {
37
+ "@types/unist": "^3.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/mdast": "^4.0.0",
41
+ "@types/node": "^20.0.0",
42
+ "c8": "^8.0.0",
43
+ "prettier": "^2.0.0",
44
+ "remark-cli": "^11.0.0",
45
+ "remark-preset-wooorm": "^9.0.0",
46
+ "type-coverage": "^2.0.0",
47
+ "typescript": "^5.0.0",
48
+ "xo": "^0.54.0"
49
+ },
50
+ "scripts": {
51
+ "prepack": "npm run build && npm run format",
52
+ "build": "tsc --build --clean && tsc --build && type-coverage",
53
+ "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
54
+ "test-api": "node --conditions development test.js",
55
+ "test-coverage": "c8 --100 --reporter lcov npm run test-api",
56
+ "test": "npm run build && npm run format && npm run test-coverage"
57
+ },
58
+ "prettier": {
59
+ "bracketSpacing": false,
60
+ "semi": false,
61
+ "singleQuote": true,
62
+ "tabWidth": 2,
63
+ "trailingComma": "none",
64
+ "useTabs": false
65
+ },
66
+ "remarkConfig": {
67
+ "plugins": [
68
+ "remark-preset-wooorm"
69
+ ]
70
+ },
71
+ "typeCoverage": {
72
+ "atLeast": 100,
73
+ "detail": true,
74
+ "ignoreCatch": true,
75
+ "strict": true
76
+ },
77
+ "xo": {
78
+ "prettier": true
79
+ }
80
+ }
@@ -0,0 +1,2 @@
1
+ // Note: types exported from `index.d.ts`
2
+ export {CONTINUE, EXIT, SKIP, visit} from './lib/index.js'
@@ -0,0 +1,312 @@
1
+ /**
2
+ * @import {Node as UnistNode, Parent as UnistParent} from 'unist'
3
+ * @import {VisitorResult} from 'unist-util-visit-parents'
4
+ */
5
+
6
+ /**
7
+ * @typedef {Exclude<import('unist-util-is').Test, undefined> | undefined} Test
8
+ * Test from `unist-util-is`.
9
+ *
10
+ * Note: we have remove and add `undefined`, because otherwise when generating
11
+ * automatic `.d.ts` files, TS tries to flatten paths from a local perspective,
12
+ * which doesn’t work when publishing on npm.
13
+ */
14
+
15
+ // To do: use types from `unist-util-visit-parents` when it’s released.
16
+
17
+ /**
18
+ * @typedef {(
19
+ * Fn extends (value: any) => value is infer Thing
20
+ * ? Thing
21
+ * : Fallback
22
+ * )} Predicate
23
+ * Get the value of a type guard `Fn`.
24
+ * @template Fn
25
+ * Value; typically function that is a type guard (such as `(x): x is Y`).
26
+ * @template Fallback
27
+ * Value to yield if `Fn` is not a type guard.
28
+ */
29
+
30
+ /**
31
+ * @typedef {(
32
+ * Check extends null | undefined // No test.
33
+ * ? Value
34
+ * : Value extends {type: Check} // String (type) test.
35
+ * ? Value
36
+ * : Value extends Check // Partial test.
37
+ * ? Value
38
+ * : Check extends Function // Function test.
39
+ * ? Predicate<Check, Value> extends Value
40
+ * ? Predicate<Check, Value>
41
+ * : never
42
+ * : never // Some other test?
43
+ * )} MatchesOne
44
+ * Check whether a node matches a primitive check in the type system.
45
+ * @template Value
46
+ * Value; typically unist `Node`.
47
+ * @template Check
48
+ * Value; typically `unist-util-is`-compatible test, but not arrays.
49
+ */
50
+
51
+ /**
52
+ * @typedef {(
53
+ * Check extends ReadonlyArray<any>
54
+ * ? MatchesOne<Value, Check[number]>
55
+ * : MatchesOne<Value, Check>
56
+ * )} Matches
57
+ * Check whether a node matches a check in the type system.
58
+ * @template Value
59
+ * Value; typically unist `Node`.
60
+ * @template Check
61
+ * Value; typically `unist-util-is`-compatible test.
62
+ */
63
+
64
+ /**
65
+ * @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
66
+ * Number; capped reasonably.
67
+ */
68
+
69
+ /**
70
+ * @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment
71
+ * Increment a number in the type system.
72
+ * @template {Uint} [I=0]
73
+ * Index.
74
+ */
75
+
76
+ /**
77
+ * @typedef {(
78
+ * Node extends UnistParent
79
+ * ? Node extends {children: Array<infer Children>}
80
+ * ? Child extends Children ? Node : never
81
+ * : never
82
+ * : never
83
+ * )} InternalParent
84
+ * Collect nodes that can be parents of `Child`.
85
+ * @template {UnistNode} Node
86
+ * All node types in a tree.
87
+ * @template {UnistNode} Child
88
+ * Node to search for.
89
+ */
90
+
91
+ /**
92
+ * @typedef {InternalParent<InclusiveDescendant<Tree>, Child>} Parent
93
+ * Collect nodes in `Tree` that can be parents of `Child`.
94
+ * @template {UnistNode} Tree
95
+ * All node types in a tree.
96
+ * @template {UnistNode} Child
97
+ * Node to search for.
98
+ */
99
+
100
+ /**
101
+ * @typedef {(
102
+ * Depth extends Max
103
+ * ? never
104
+ * :
105
+ * | InternalParent<Node, Child>
106
+ * | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
107
+ * )} InternalAncestor
108
+ * Collect nodes in `Tree` that can be ancestors of `Child`.
109
+ * @template {UnistNode} Node
110
+ * All node types in a tree.
111
+ * @template {UnistNode} Child
112
+ * Node to search for.
113
+ * @template {Uint} [Max=10]
114
+ * Max; searches up to this depth.
115
+ * @template {Uint} [Depth=0]
116
+ * Current depth.
117
+ */
118
+
119
+ /**
120
+ * @typedef {(
121
+ * Tree extends UnistParent
122
+ * ? Depth extends Max
123
+ * ? Tree
124
+ * : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
125
+ * : Tree
126
+ * )} InclusiveDescendant
127
+ * Collect all (inclusive) descendants of `Tree`.
128
+ *
129
+ * > 👉 **Note**: for performance reasons, this seems to be the fastest way to
130
+ * > recurse without actually running into an infinite loop, which the
131
+ * > previous version did.
132
+ * >
133
+ * > Practically, a max of `2` is typically enough assuming a `Root` is
134
+ * > passed, but it doesn’t improve performance.
135
+ * > It gets higher with `List > ListItem > Table > TableRow > TableCell`.
136
+ * > Using up to `10` doesn’t hurt or help either.
137
+ * @template {UnistNode} Tree
138
+ * Tree type.
139
+ * @template {Uint} [Max=10]
140
+ * Max; searches up to this depth.
141
+ * @template {Uint} [Depth=0]
142
+ * Current depth.
143
+ */
144
+
145
+ /**
146
+ * @callback Visitor
147
+ * Handle a node (matching `test`, if given).
148
+ *
149
+ * Visitors are free to transform `node`.
150
+ * They can also transform `parent`.
151
+ *
152
+ * Replacing `node` itself, if `SKIP` is not returned, still causes its
153
+ * descendants to be walked (which is a bug).
154
+ *
155
+ * When adding or removing previous siblings of `node` (or next siblings, in
156
+ * case of reverse), the `Visitor` should return a new `Index` to specify the
157
+ * sibling to traverse after `node` is traversed.
158
+ * Adding or removing next siblings of `node` (or previous siblings, in case
159
+ * of reverse) is handled as expected without needing to return a new `Index`.
160
+ *
161
+ * Removing the children property of `parent` still results in them being
162
+ * traversed.
163
+ * @param {Visited} node
164
+ * Found node.
165
+ * @param {Visited extends UnistNode ? number | undefined : never} index
166
+ * Index of `node` in `parent`.
167
+ * @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
168
+ * Parent of `node`.
169
+ * @returns {VisitorResult}
170
+ * What to do next.
171
+ *
172
+ * An `Index` is treated as a tuple of `[CONTINUE, Index]`.
173
+ * An `Action` is treated as a tuple of `[Action]`.
174
+ *
175
+ * Passing a tuple back only makes sense if the `Action` is `SKIP`.
176
+ * When the `Action` is `EXIT`, that action can be returned.
177
+ * When the `Action` is `CONTINUE`, `Index` can be returned.
178
+ * @template {UnistNode} [Visited=UnistNode]
179
+ * Visited node type.
180
+ * @template {UnistParent} [Ancestor=UnistParent]
181
+ * Ancestor type.
182
+ */
183
+
184
+ /**
185
+ * @typedef {Visitor<Visited, Parent<Ancestor, Visited>>} BuildVisitorFromMatch
186
+ * Build a typed `Visitor` function from a node and all possible parents.
187
+ *
188
+ * It will infer which values are passed as `node` and which as `parent`.
189
+ * @template {UnistNode} Visited
190
+ * Node type.
191
+ * @template {UnistParent} Ancestor
192
+ * Parent type.
193
+ */
194
+
195
+ /**
196
+ * @typedef {(
197
+ * BuildVisitorFromMatch<
198
+ * Matches<Descendant, Check>,
199
+ * Extract<Descendant, UnistParent>
200
+ * >
201
+ * )} BuildVisitorFromDescendants
202
+ * Build a typed `Visitor` function from a list of descendants and a test.
203
+ *
204
+ * It will infer which values are passed as `node` and which as `parent`.
205
+ * @template {UnistNode} Descendant
206
+ * Node type.
207
+ * @template {Test} Check
208
+ * Test type.
209
+ */
210
+
211
+ /**
212
+ * @typedef {(
213
+ * BuildVisitorFromDescendants<
214
+ * InclusiveDescendant<Tree>,
215
+ * Check
216
+ * >
217
+ * )} BuildVisitor
218
+ * Build a typed `Visitor` function from a tree and a test.
219
+ *
220
+ * It will infer which values are passed as `node` and which as `parent`.
221
+ * @template {UnistNode} [Tree=UnistNode]
222
+ * Node type.
223
+ * @template {Test} [Check=Test]
224
+ * Test type.
225
+ */
226
+
227
+ import {visitParents} from 'unist-util-visit-parents'
228
+
229
+ export {CONTINUE, EXIT, SKIP} from 'unist-util-visit-parents'
230
+
231
+ /**
232
+ * Visit nodes.
233
+ *
234
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
235
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
236
+ *
237
+ * You can choose for which nodes `visitor` is called by passing a `test`.
238
+ * For complex tests, you should test yourself in `visitor`, as it will be
239
+ * faster and will have improved type information.
240
+ *
241
+ * Walking the tree is an intensive task.
242
+ * Make use of the return values of the visitor when possible.
243
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
244
+ * to check if a node matches, and then perform different operations.
245
+ *
246
+ * You can change the tree.
247
+ * See `Visitor` for more info.
248
+ *
249
+ * @overload
250
+ * @param {Tree} tree
251
+ * @param {Check} check
252
+ * @param {BuildVisitor<Tree, Check>} visitor
253
+ * @param {boolean | null | undefined} [reverse]
254
+ * @returns {undefined}
255
+ *
256
+ * @overload
257
+ * @param {Tree} tree
258
+ * @param {BuildVisitor<Tree>} visitor
259
+ * @param {boolean | null | undefined} [reverse]
260
+ * @returns {undefined}
261
+ *
262
+ * @param {UnistNode} tree
263
+ * Tree to traverse.
264
+ * @param {Visitor | Test} testOrVisitor
265
+ * `unist-util-is`-compatible test (optional, omit to pass a visitor).
266
+ * @param {Visitor | boolean | null | undefined} [visitorOrReverse]
267
+ * Handle each node (when test is omitted, pass `reverse`).
268
+ * @param {boolean | null | undefined} [maybeReverse=false]
269
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
270
+ * @returns {undefined}
271
+ * Nothing.
272
+ *
273
+ * @template {UnistNode} Tree
274
+ * Node type.
275
+ * @template {Test} Check
276
+ * `unist-util-is`-compatible test.
277
+ */
278
+ export function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
279
+ /** @type {boolean | null | undefined} */
280
+ let reverse
281
+ /** @type {Test} */
282
+ let test
283
+ /** @type {Visitor} */
284
+ let visitor
285
+
286
+ if (
287
+ typeof testOrVisitor === 'function' &&
288
+ typeof visitorOrReverse !== 'function'
289
+ ) {
290
+ test = undefined
291
+ visitor = testOrVisitor
292
+ reverse = visitorOrReverse
293
+ } else {
294
+ // @ts-expect-error: assume the overload with test was given.
295
+ test = testOrVisitor
296
+ // @ts-expect-error: assume the overload with test was given.
297
+ visitor = visitorOrReverse
298
+ reverse = maybeReverse
299
+ }
300
+
301
+ visitParents(tree, test, overload, reverse)
302
+
303
+ /**
304
+ * @param {UnistNode} node
305
+ * @param {Array<UnistParent>} parents
306
+ */
307
+ function overload(node, parents) {
308
+ const parent = parents[parents.length - 1]
309
+ const index = parent ? parent.children.indexOf(node) : undefined
310
+ return visitor(node, index, parent)
311
+ }
312
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.