functional-examples 0.0.0-alpha.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 (202) hide show
  1. package/README.md +148 -0
  2. package/dist/cli/commands/generate.d.ts +10 -0
  3. package/dist/cli/commands/generate.d.ts.map +1 -0
  4. package/dist/cli/commands/generate.js +64 -0
  5. package/dist/cli/commands/generate.js.map +1 -0
  6. package/dist/cli/commands/init.d.ts +14 -0
  7. package/dist/cli/commands/init.d.ts.map +1 -0
  8. package/dist/cli/commands/init.js +95 -0
  9. package/dist/cli/commands/init.js.map +1 -0
  10. package/dist/cli/commands/scan.d.ts +20 -0
  11. package/dist/cli/commands/scan.d.ts.map +1 -0
  12. package/dist/cli/commands/scan.js +182 -0
  13. package/dist/cli/commands/scan.js.map +1 -0
  14. package/dist/cli/commands/validate.d.ts +10 -0
  15. package/dist/cli/commands/validate.d.ts.map +1 -0
  16. package/dist/cli/commands/validate.js +65 -0
  17. package/dist/cli/commands/validate.js.map +1 -0
  18. package/dist/cli/index.d.ts +88 -0
  19. package/dist/cli/index.d.ts.map +1 -0
  20. package/dist/cli/index.js +43 -0
  21. package/dist/cli/index.js.map +1 -0
  22. package/dist/cli/plugin-commands.d.ts +17 -0
  23. package/dist/cli/plugin-commands.d.ts.map +1 -0
  24. package/dist/cli/plugin-commands.js +45 -0
  25. package/dist/cli/plugin-commands.js.map +1 -0
  26. package/dist/config/index.d.ts +11 -0
  27. package/dist/config/index.d.ts.map +1 -0
  28. package/dist/config/index.js +9 -0
  29. package/dist/config/index.js.map +1 -0
  30. package/dist/config/index.spec.d.ts +5 -0
  31. package/dist/config/index.spec.d.ts.map +1 -0
  32. package/dist/config/index.spec.js +142 -0
  33. package/dist/config/index.spec.js.map +1 -0
  34. package/dist/config/loader.d.ts +7 -0
  35. package/dist/config/loader.d.ts.map +1 -0
  36. package/dist/config/loader.js +85 -0
  37. package/dist/config/loader.js.map +1 -0
  38. package/dist/config/merger.d.ts +27 -0
  39. package/dist/config/merger.d.ts.map +1 -0
  40. package/dist/config/merger.js +41 -0
  41. package/dist/config/merger.js.map +1 -0
  42. package/dist/config/resolver.d.ts +28 -0
  43. package/dist/config/resolver.d.ts.map +1 -0
  44. package/dist/config/resolver.js +165 -0
  45. package/dist/config/resolver.js.map +1 -0
  46. package/dist/config/schema.d.ts +53 -0
  47. package/dist/config/schema.d.ts.map +1 -0
  48. package/dist/config/schema.js +42 -0
  49. package/dist/config/schema.js.map +1 -0
  50. package/dist/config/types.d.ts +17 -0
  51. package/dist/config/types.d.ts.map +1 -0
  52. package/dist/config/types.js +5 -0
  53. package/dist/config/types.js.map +1 -0
  54. package/dist/config/validator.d.ts +6 -0
  55. package/dist/config/validator.d.ts.map +1 -0
  56. package/dist/config/validator.js +17 -0
  57. package/dist/config/validator.js.map +1 -0
  58. package/dist/extractors/index.d.ts +9 -0
  59. package/dist/extractors/index.d.ts.map +1 -0
  60. package/dist/extractors/index.js +9 -0
  61. package/dist/extractors/index.js.map +1 -0
  62. package/dist/extractors/loader.d.ts +19 -0
  63. package/dist/extractors/loader.d.ts.map +1 -0
  64. package/dist/extractors/loader.js +120 -0
  65. package/dist/extractors/loader.js.map +1 -0
  66. package/dist/extractors/meta-yml-fn.d.ts +19 -0
  67. package/dist/extractors/meta-yml-fn.d.ts.map +1 -0
  68. package/dist/extractors/meta-yml-fn.js +66 -0
  69. package/dist/extractors/meta-yml-fn.js.map +1 -0
  70. package/dist/extractors/meta-yml.d.ts +24 -0
  71. package/dist/extractors/meta-yml.d.ts.map +1 -0
  72. package/dist/extractors/meta-yml.js +65 -0
  73. package/dist/extractors/meta-yml.js.map +1 -0
  74. package/dist/extractors/registry.d.ts +58 -0
  75. package/dist/extractors/registry.d.ts.map +1 -0
  76. package/dist/extractors/registry.js +114 -0
  77. package/dist/extractors/registry.js.map +1 -0
  78. package/dist/extractors/registry.spec.d.ts +2 -0
  79. package/dist/extractors/registry.spec.d.ts.map +1 -0
  80. package/dist/extractors/registry.spec.js +102 -0
  81. package/dist/extractors/registry.spec.js.map +1 -0
  82. package/dist/extractors/types.d.ts +34 -0
  83. package/dist/extractors/types.d.ts.map +1 -0
  84. package/dist/extractors/types.js +8 -0
  85. package/dist/extractors/types.js.map +1 -0
  86. package/dist/extractors/yaml-frontmatter-fn.d.ts +18 -0
  87. package/dist/extractors/yaml-frontmatter-fn.d.ts.map +1 -0
  88. package/dist/extractors/yaml-frontmatter-fn.js +73 -0
  89. package/dist/extractors/yaml-frontmatter-fn.js.map +1 -0
  90. package/dist/extractors/yaml-frontmatter.d.ts +22 -0
  91. package/dist/extractors/yaml-frontmatter.d.ts.map +1 -0
  92. package/dist/extractors/yaml-frontmatter.js +83 -0
  93. package/dist/extractors/yaml-frontmatter.js.map +1 -0
  94. package/dist/extractors/yaml-frontmatter.spec.d.ts +2 -0
  95. package/dist/extractors/yaml-frontmatter.spec.d.ts.map +1 -0
  96. package/dist/extractors/yaml-frontmatter.spec.js +134 -0
  97. package/dist/extractors/yaml-frontmatter.spec.js.map +1 -0
  98. package/dist/files/index.d.ts +5 -0
  99. package/dist/files/index.d.ts.map +1 -0
  100. package/dist/files/index.js +5 -0
  101. package/dist/files/index.js.map +1 -0
  102. package/dist/files/reader.d.ts +50 -0
  103. package/dist/files/reader.d.ts.map +1 -0
  104. package/dist/files/reader.js +62 -0
  105. package/dist/files/reader.js.map +1 -0
  106. package/dist/index.d.ts +29 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +22 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/plugins/index.d.ts +4 -0
  111. package/dist/plugins/index.d.ts.map +1 -0
  112. package/dist/plugins/index.js +4 -0
  113. package/dist/plugins/index.js.map +1 -0
  114. package/dist/plugins/pipeline.d.ts +11 -0
  115. package/dist/plugins/pipeline.d.ts.map +1 -0
  116. package/dist/plugins/pipeline.js +24 -0
  117. package/dist/plugins/pipeline.js.map +1 -0
  118. package/dist/plugins/registry.d.ts +57 -0
  119. package/dist/plugins/registry.d.ts.map +1 -0
  120. package/dist/plugins/registry.js +93 -0
  121. package/dist/plugins/registry.js.map +1 -0
  122. package/dist/plugins/validation.d.ts +64 -0
  123. package/dist/plugins/validation.d.ts.map +1 -0
  124. package/dist/plugins/validation.js +55 -0
  125. package/dist/plugins/validation.js.map +1 -0
  126. package/dist/regions/index.d.ts +7 -0
  127. package/dist/regions/index.d.ts.map +1 -0
  128. package/dist/regions/index.js +6 -0
  129. package/dist/regions/index.js.map +1 -0
  130. package/dist/regions/languages.d.ts +15 -0
  131. package/dist/regions/languages.d.ts.map +1 -0
  132. package/dist/regions/languages.js +182 -0
  133. package/dist/regions/languages.js.map +1 -0
  134. package/dist/regions/parser.d.ts +63 -0
  135. package/dist/regions/parser.d.ts.map +1 -0
  136. package/dist/regions/parser.js +175 -0
  137. package/dist/regions/parser.js.map +1 -0
  138. package/dist/regions/parser.spec.d.ts +2 -0
  139. package/dist/regions/parser.spec.d.ts.map +1 -0
  140. package/dist/regions/parser.spec.js +190 -0
  141. package/dist/regions/parser.spec.js.map +1 -0
  142. package/dist/regions/types.d.ts +37 -0
  143. package/dist/regions/types.d.ts.map +1 -0
  144. package/dist/regions/types.js +5 -0
  145. package/dist/regions/types.js.map +1 -0
  146. package/dist/scanner/candidates.d.ts +24 -0
  147. package/dist/scanner/candidates.d.ts.map +1 -0
  148. package/dist/scanner/candidates.js +83 -0
  149. package/dist/scanner/candidates.js.map +1 -0
  150. package/dist/scanner/index.d.ts +8 -0
  151. package/dist/scanner/index.d.ts.map +1 -0
  152. package/dist/scanner/index.js +6 -0
  153. package/dist/scanner/index.js.map +1 -0
  154. package/dist/scanner/scan.d.ts +40 -0
  155. package/dist/scanner/scan.d.ts.map +1 -0
  156. package/dist/scanner/scan.js +44 -0
  157. package/dist/scanner/scan.js.map +1 -0
  158. package/dist/scanner/scanner.d.ts +29 -0
  159. package/dist/scanner/scanner.d.ts.map +1 -0
  160. package/dist/scanner/scanner.js +296 -0
  161. package/dist/scanner/scanner.js.map +1 -0
  162. package/dist/scanner/scanner.spec.d.ts +2 -0
  163. package/dist/scanner/scanner.spec.d.ts.map +1 -0
  164. package/dist/scanner/scanner.spec.js +262 -0
  165. package/dist/scanner/scanner.spec.js.map +1 -0
  166. package/dist/scanner/types.d.ts +43 -0
  167. package/dist/scanner/types.d.ts.map +1 -0
  168. package/dist/scanner/types.js +5 -0
  169. package/dist/scanner/types.js.map +1 -0
  170. package/dist/schema/index.d.ts +4 -0
  171. package/dist/schema/index.d.ts.map +1 -0
  172. package/dist/schema/index.js +4 -0
  173. package/dist/schema/index.js.map +1 -0
  174. package/dist/schema/merger.d.ts +35 -0
  175. package/dist/schema/merger.d.ts.map +1 -0
  176. package/dist/schema/merger.js +161 -0
  177. package/dist/schema/merger.js.map +1 -0
  178. package/dist/schema/typegen.d.ts +13 -0
  179. package/dist/schema/typegen.d.ts.map +1 -0
  180. package/dist/schema/typegen.js +125 -0
  181. package/dist/schema/typegen.js.map +1 -0
  182. package/dist/schema/validator.d.ts +7 -0
  183. package/dist/schema/validator.d.ts.map +1 -0
  184. package/dist/schema/validator.js +32 -0
  185. package/dist/schema/validator.js.map +1 -0
  186. package/dist/types/default-map.d.ts +21 -0
  187. package/dist/types/default-map.d.ts.map +1 -0
  188. package/dist/types/default-map.js +32 -0
  189. package/dist/types/default-map.js.map +1 -0
  190. package/dist/types/extended-iterable.d.ts +197 -0
  191. package/dist/types/extended-iterable.d.ts.map +1 -0
  192. package/dist/types/extended-iterable.js +769 -0
  193. package/dist/types/extended-iterable.js.map +1 -0
  194. package/dist/types/guards.d.ts +2 -0
  195. package/dist/types/guards.d.ts.map +1 -0
  196. package/dist/types/guards.js +2 -0
  197. package/dist/types/guards.js.map +1 -0
  198. package/dist/types/index.d.ts +11 -0
  199. package/dist/types/index.d.ts.map +1 -0
  200. package/dist/types/index.js +10 -0
  201. package/dist/types/index.js.map +1 -0
  202. package/package.json +61 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Validate plugin options before extraction.
3
+ * Runs each plugin's options validator against its configured options.
4
+ */
5
+ export function validatePluginOptions(context) {
6
+ const errors = [];
7
+ for (const { pluginName, validate } of context.validators) {
8
+ const options = context.pluginOptions.get(pluginName);
9
+ // Skip if no options provided for this plugin
10
+ if (options === undefined) {
11
+ continue;
12
+ }
13
+ const result = validate(options);
14
+ if (!result.success) {
15
+ for (const error of result.errors) {
16
+ errors.push({
17
+ pluginName,
18
+ path: error.path,
19
+ message: error.message,
20
+ });
21
+ }
22
+ }
23
+ }
24
+ return {
25
+ success: errors.length === 0,
26
+ errors,
27
+ };
28
+ }
29
+ /**
30
+ * Validate example metadata after extraction.
31
+ * Runs all metadata validators against each example's metadata.
32
+ */
33
+ export function validateExampleMetadata(context) {
34
+ const errors = [];
35
+ for (const example of context.examples) {
36
+ for (const { pluginName, validate } of context.validators) {
37
+ const result = validate(example.metadata);
38
+ if (!result.success) {
39
+ for (const error of result.errors) {
40
+ errors.push({
41
+ exampleId: example.id,
42
+ pluginName,
43
+ path: error.path,
44
+ message: error.message,
45
+ });
46
+ }
47
+ }
48
+ }
49
+ }
50
+ return {
51
+ success: errors.length === 0,
52
+ errors,
53
+ };
54
+ }
55
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/plugins/validation.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAuC;IAEvC,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,KAAK,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEtD,8CAA8C;QAC9C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEjC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU;oBACV,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC;AAoCD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAkC;IAElC,MAAM,MAAM,GAA8B,EAAE,CAAC;IAE7C,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACvC,KAAK,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE1C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;oBAClC,MAAM,CAAC,IAAI,CAAC;wBACV,SAAS,EAAE,OAAO,CAAC,EAAE;wBACrB,UAAU;wBACV,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;qBACvB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Region extraction system for code examples
3
+ */
4
+ export type { RegionInfo, RegionMap, RegionOptions, LanguageConfig, } from './types.js';
5
+ export { LANGUAGE_CONFIGS, getLanguageConfig } from './languages.js';
6
+ export { parseRegions, extractRegion, stripRegionMarkers, listRegions, } from './parser.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/regions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Region extraction system for code examples
3
+ */
4
+ export { LANGUAGE_CONFIGS, getLanguageConfig } from './languages.js';
5
+ export { parseRegions, extractRegion, stripRegionMarkers, listRegions, } from './parser.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/regions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Language configuration for region markers
3
+ */
4
+ import type { LanguageConfig } from './types.js';
5
+ /**
6
+ * Comment syntax configuration for various programming languages.
7
+ * Maps file extensions to their comment patterns.
8
+ */
9
+ export declare const LANGUAGE_CONFIGS: Record<string, LanguageConfig>;
10
+ /**
11
+ * Get the language configuration for a file extension.
12
+ * Falls back to JavaScript-style comments if unknown.
13
+ */
14
+ export declare function getLanguageConfig(extension: string): LanguageConfig;
15
+ //# sourceMappingURL=languages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../src/regions/languages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAgN3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAInE"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Language configuration for region markers
3
+ */
4
+ /**
5
+ * Comment syntax configuration for various programming languages.
6
+ * Maps file extensions to their comment patterns.
7
+ */
8
+ export const LANGUAGE_CONFIGS = {
9
+ // JavaScript/TypeScript family
10
+ js: { lineComment: '//', blockComment: ['/*', '*/'] },
11
+ jsx: { lineComment: '//', blockComment: ['/*', '*/'] },
12
+ ts: { lineComment: '//', blockComment: ['/*', '*/'] },
13
+ tsx: { lineComment: '//', blockComment: ['/*', '*/'] },
14
+ mjs: { lineComment: '//', blockComment: ['/*', '*/'] },
15
+ cjs: { lineComment: '//', blockComment: ['/*', '*/'] },
16
+ mts: { lineComment: '//', blockComment: ['/*', '*/'] },
17
+ cts: { lineComment: '//', blockComment: ['/*', '*/'] },
18
+ // C family
19
+ c: { lineComment: '//', blockComment: ['/*', '*/'] },
20
+ h: { lineComment: '//', blockComment: ['/*', '*/'] },
21
+ cpp: { lineComment: '//', blockComment: ['/*', '*/'] },
22
+ hpp: { lineComment: '//', blockComment: ['/*', '*/'] },
23
+ cc: { lineComment: '//', blockComment: ['/*', '*/'] },
24
+ cxx: { lineComment: '//', blockComment: ['/*', '*/'] },
25
+ // Java/Kotlin/Scala
26
+ java: { lineComment: '//', blockComment: ['/*', '*/'] },
27
+ kt: { lineComment: '//', blockComment: ['/*', '*/'] },
28
+ kts: { lineComment: '//', blockComment: ['/*', '*/'] },
29
+ scala: { lineComment: '//', blockComment: ['/*', '*/'] },
30
+ groovy: { lineComment: '//', blockComment: ['/*', '*/'] },
31
+ // C#/F#
32
+ cs: { lineComment: '//', blockComment: ['/*', '*/'] },
33
+ fs: { lineComment: '//', blockComment: ['(*', '*)'] },
34
+ fsx: { lineComment: '//', blockComment: ['(*', '*)'] },
35
+ // Go/Rust/Swift
36
+ go: { lineComment: '//', blockComment: ['/*', '*/'] },
37
+ rs: { lineComment: '//', blockComment: ['/*', '*/'] },
38
+ swift: { lineComment: '//', blockComment: ['/*', '*/'] },
39
+ // PHP
40
+ php: { lineComment: '//', blockComment: ['/*', '*/'] },
41
+ // Python
42
+ py: { lineComment: '#' },
43
+ pyw: { lineComment: '#' },
44
+ pyi: { lineComment: '#' },
45
+ // Ruby
46
+ rb: { lineComment: '#' },
47
+ rake: { lineComment: '#' },
48
+ gemspec: { lineComment: '#' },
49
+ // Shell/Bash
50
+ sh: { lineComment: '#' },
51
+ bash: { lineComment: '#' },
52
+ zsh: { lineComment: '#' },
53
+ fish: { lineComment: '#' },
54
+ // PowerShell
55
+ ps1: { lineComment: '#', blockComment: ['<#', '#>'] },
56
+ psm1: { lineComment: '#', blockComment: ['<#', '#>'] },
57
+ // Perl
58
+ pl: { lineComment: '#' },
59
+ pm: { lineComment: '#' },
60
+ // R
61
+ r: { lineComment: '#' },
62
+ R: { lineComment: '#' },
63
+ // YAML/TOML
64
+ yml: { lineComment: '#' },
65
+ yaml: { lineComment: '#' },
66
+ toml: { lineComment: '#' },
67
+ // Config files
68
+ ini: { lineComment: ';' },
69
+ conf: { lineComment: '#' },
70
+ cfg: { lineComment: '#' },
71
+ // SQL
72
+ sql: { lineComment: '--', blockComment: ['/*', '*/'] },
73
+ // Lua
74
+ lua: { lineComment: '--', blockComment: ['--[[', ']]'] },
75
+ // Haskell
76
+ hs: { lineComment: '--', blockComment: ['{-', '-}'] },
77
+ lhs: { lineComment: '--', blockComment: ['{-', '-}'] },
78
+ // Elm
79
+ elm: { lineComment: '--', blockComment: ['{-', '-}'] },
80
+ // HTML/XML
81
+ html: { blockComment: ['<!--', '-->'] },
82
+ htm: { blockComment: ['<!--', '-->'] },
83
+ xml: { blockComment: ['<!--', '-->'] },
84
+ xhtml: { blockComment: ['<!--', '-->'] },
85
+ svg: { blockComment: ['<!--', '-->'] },
86
+ vue: { blockComment: ['<!--', '-->'] },
87
+ // CSS/SCSS/LESS
88
+ css: { blockComment: ['/*', '*/'] },
89
+ scss: { lineComment: '//', blockComment: ['/*', '*/'] },
90
+ sass: { lineComment: '//', blockComment: ['/*', '*/'] },
91
+ less: { lineComment: '//', blockComment: ['/*', '*/'] },
92
+ // Markdown (HTML comments)
93
+ md: { blockComment: ['<!--', '-->'] },
94
+ mdx: { blockComment: ['<!--', '-->'] },
95
+ // Dockerfile
96
+ dockerfile: { lineComment: '#' },
97
+ // Makefile
98
+ makefile: { lineComment: '#' },
99
+ mk: { lineComment: '#' },
100
+ // Terraform/HCL
101
+ tf: { lineComment: '#', blockComment: ['/*', '*/'] },
102
+ tfvars: { lineComment: '#', blockComment: ['/*', '*/'] },
103
+ hcl: { lineComment: '#', blockComment: ['/*', '*/'] },
104
+ // Nix
105
+ nix: { lineComment: '#', blockComment: ['/*', '*/'] },
106
+ // Zig
107
+ zig: { lineComment: '//' },
108
+ // V
109
+ v: { lineComment: '//', blockComment: ['/*', '*/'] },
110
+ // Nim
111
+ nim: { lineComment: '#', blockComment: ['#[', ']#'] },
112
+ // Julia
113
+ jl: { lineComment: '#', blockComment: ['#=', '=#'] },
114
+ // Clojure
115
+ clj: { lineComment: ';' },
116
+ cljs: { lineComment: ';' },
117
+ cljc: { lineComment: ';' },
118
+ edn: { lineComment: ';' },
119
+ // Lisp/Scheme
120
+ lisp: { lineComment: ';' },
121
+ el: { lineComment: ';' },
122
+ scm: { lineComment: ';' },
123
+ rkt: { lineComment: ';' },
124
+ // OCaml
125
+ ml: { blockComment: ['(*', '*)'] },
126
+ mli: { blockComment: ['(*', '*)'] },
127
+ // Erlang/Elixir
128
+ erl: { lineComment: '%' },
129
+ hrl: { lineComment: '%' },
130
+ ex: { lineComment: '#' },
131
+ exs: { lineComment: '#' },
132
+ // Prolog
133
+ pro: { lineComment: '%', blockComment: ['/*', '*/'] },
134
+ // Note: .pl is typically Perl, not Prolog
135
+ // Fortran
136
+ f90: { lineComment: '!' },
137
+ f95: { lineComment: '!' },
138
+ f03: { lineComment: '!' },
139
+ f08: { lineComment: '!' },
140
+ for: { lineComment: '!' },
141
+ // VHDL/Verilog
142
+ vhd: { lineComment: '--' },
143
+ vhdl: { lineComment: '--' },
144
+ // Note: .v is used by both V lang (above) and Verilog - keeping V lang definition
145
+ sv: { lineComment: '//', blockComment: ['/*', '*/'] },
146
+ // Assembly
147
+ asm: { lineComment: ';' },
148
+ s: { lineComment: ';' },
149
+ // Batch
150
+ bat: { lineComment: 'REM' },
151
+ cmd: { lineComment: 'REM' },
152
+ // AppleScript
153
+ applescript: { lineComment: '--', blockComment: ['(*', '*)'] },
154
+ // CoffeeScript
155
+ coffee: { lineComment: '#', blockComment: ['###', '###'] },
156
+ // Dart
157
+ dart: { lineComment: '//', blockComment: ['/*', '*/'] },
158
+ // GLSL/HLSL
159
+ glsl: { lineComment: '//', blockComment: ['/*', '*/'] },
160
+ hlsl: { lineComment: '//', blockComment: ['/*', '*/'] },
161
+ vert: { lineComment: '//', blockComment: ['/*', '*/'] },
162
+ frag: { lineComment: '//', blockComment: ['/*', '*/'] },
163
+ // Jsonnet
164
+ jsonnet: { lineComment: '//', blockComment: ['/*', '*/'] },
165
+ libsonnet: { lineComment: '//', blockComment: ['/*', '*/'] },
166
+ // Starlark/Bazel
167
+ bzl: { lineComment: '#' },
168
+ bazel: { lineComment: '#' },
169
+ BUILD: { lineComment: '#' },
170
+ // Protobuf
171
+ proto: { lineComment: '//', blockComment: ['/*', '*/'] },
172
+ };
173
+ /**
174
+ * Get the language configuration for a file extension.
175
+ * Falls back to JavaScript-style comments if unknown.
176
+ */
177
+ export function getLanguageConfig(extension) {
178
+ // Normalize extension (remove leading dot, lowercase)
179
+ const normalized = extension.replace(/^\./, '').toLowerCase();
180
+ return LANGUAGE_CONFIGS[normalized] ?? { lineComment: '//' };
181
+ }
182
+ //# sourceMappingURL=languages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/regions/languages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAmC;IAC9D,+BAA+B;IAC/B,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACrD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACrD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACtD,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IAEtD,WAAW;IACX,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACpD,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC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W,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACvD,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IACvD,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IAEvD,UAAU;IACV,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IAC1D,SAAS,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;IAE5D,iBAAiB;IACjB,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE;IACzB,KAAK,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE;IAC3B,KAAK,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE;IAE3B,WAAW;IACX,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;CACzD,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,sDAAsD;IACtD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9D,OAAO,gBAAgB,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Region parsing implementation
3
+ */
4
+ import type { RegionMap, RegionOptions } from './types.js';
5
+ /**
6
+ * Parse all #region/#endregion pairs from code.
7
+ * Supports nested regions and language-specific comment syntax.
8
+ *
9
+ * @param code - The source code to parse
10
+ * @param options - Options including file extension for language detection
11
+ * @returns Map of region IDs to their content
12
+ * @throws Error on unclosed or mismatched regions
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const regions = parseRegions(tsCode, { extension: 'ts' });
17
+ * const setupCode = regions['setup']?.content;
18
+ * ```
19
+ */
20
+ export declare function parseRegions(code: string, options?: RegionOptions): RegionMap;
21
+ /**
22
+ * Extract a specific region's content by ID.
23
+ *
24
+ * @param code - The source code to parse
25
+ * @param regionId - The ID of the region to extract
26
+ * @param options - Options including file extension for language detection
27
+ * @returns The region's content
28
+ * @throws Error if region not found
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const setupCode = extractRegion(code, 'setup', { extension: 'py' });
33
+ * ```
34
+ */
35
+ export declare function extractRegion(code: string, regionId: string, options?: RegionOptions): string;
36
+ /**
37
+ * Remove all region marker lines from code.
38
+ *
39
+ * @param code - The source code to clean
40
+ * @param options - Options including file extension for language detection
41
+ * @returns Code with all region markers removed
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const cleanCode = stripRegionMarkers(code, { extension: 'ts' });
46
+ * ```
47
+ */
48
+ export declare function stripRegionMarkers(code: string, options?: RegionOptions): string;
49
+ /**
50
+ * List all region IDs found in code.
51
+ *
52
+ * @param code - The source code to scan
53
+ * @param options - Options including file extension for language detection
54
+ * @returns Array of region IDs
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const regionIds = listRegions(code, { extension: 'ts' });
59
+ * // ['setup', 'main', 'cleanup']
60
+ * ```
61
+ */
62
+ export declare function listRegions(code: string, options?: RegionOptions): string[];
63
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/regions/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAwE3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAkB,GAC1B,SAAS,CA4DX;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAaR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAYR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAAkB,GAC1B,MAAM,EAAE,CAGV"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Region parsing implementation
3
+ */
4
+ import { getLanguageConfig } from './languages.js';
5
+ /**
6
+ * Create regex patterns for region markers based on comment syntax
7
+ */
8
+ function createRegionPatterns(lineComment, blockComment) {
9
+ const patterns = [];
10
+ // Line comment pattern: // #region name
11
+ if (lineComment) {
12
+ const escaped = escapeRegex(lineComment);
13
+ patterns.push(`^\\s*${escaped}\\s*#region\\s+(\\S+)\\s*$`);
14
+ }
15
+ // Block comment pattern: <!-- #region name -->
16
+ if (blockComment) {
17
+ const [start, end] = blockComment.map(escapeRegex);
18
+ patterns.push(`^\\s*${start}\\s*#region\\s+(\\S+)\\s*${end}\\s*$`);
19
+ }
20
+ // Combine patterns
21
+ const startPattern = patterns.length > 0
22
+ ? new RegExp(patterns.join('|'))
23
+ : /^\s*\/\/\s*#region\s+(\S+)\s*$/;
24
+ // Create end patterns similarly
25
+ const endPatterns = [];
26
+ if (lineComment) {
27
+ const escaped = escapeRegex(lineComment);
28
+ endPatterns.push(`^\\s*${escaped}\\s*#endregion\\s+(\\S+)\\s*$`);
29
+ }
30
+ if (blockComment) {
31
+ const [start, end] = blockComment.map(escapeRegex);
32
+ endPatterns.push(`^\\s*${start}\\s*#endregion\\s+(\\S+)\\s*${end}\\s*$`);
33
+ }
34
+ const endPattern = endPatterns.length > 0
35
+ ? new RegExp(endPatterns.join('|'))
36
+ : /^\s*\/\/\s*#endregion\s+(\S+)\s*$/;
37
+ return { start: startPattern, end: endPattern };
38
+ }
39
+ /**
40
+ * Escape special regex characters
41
+ */
42
+ function escapeRegex(str) {
43
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
44
+ }
45
+ /**
46
+ * Extract the region ID from a match result.
47
+ * Handles multiple capture groups from combined patterns.
48
+ */
49
+ function extractRegionId(match) {
50
+ // Find the first non-undefined capture group
51
+ for (let i = 1; i < match.length; i++) {
52
+ if (match[i] !== undefined) {
53
+ return match[i];
54
+ }
55
+ }
56
+ throw new Error('No region ID captured');
57
+ }
58
+ /**
59
+ * Parse all #region/#endregion pairs from code.
60
+ * Supports nested regions and language-specific comment syntax.
61
+ *
62
+ * @param code - The source code to parse
63
+ * @param options - Options including file extension for language detection
64
+ * @returns Map of region IDs to their content
65
+ * @throws Error on unclosed or mismatched regions
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const regions = parseRegions(tsCode, { extension: 'ts' });
70
+ * const setupCode = regions['setup']?.content;
71
+ * ```
72
+ */
73
+ export function parseRegions(code, options = {}) {
74
+ const config = getLanguageConfig(options.extension ?? 'ts');
75
+ const { start: REGION_START, end: REGION_END } = createRegionPatterns(config.lineComment, config.blockComment);
76
+ const lines = code.split('\n');
77
+ const regions = {};
78
+ const stack = [];
79
+ for (let i = 0; i < lines.length; i++) {
80
+ const line = lines[i];
81
+ const startMatch = line.match(REGION_START);
82
+ if (startMatch) {
83
+ const id = extractRegionId(startMatch);
84
+ stack.push({ id, startLine: i + 1, startIndex: i });
85
+ continue;
86
+ }
87
+ const endMatch = line.match(REGION_END);
88
+ if (endMatch) {
89
+ const endId = extractRegionId(endMatch);
90
+ const openRegion = stack.pop();
91
+ if (!openRegion) {
92
+ throw new Error(`Unexpected #endregion '${endId}' at line ${i + 1}`);
93
+ }
94
+ if (openRegion.id !== endId) {
95
+ throw new Error(`Mismatched region: opened '${openRegion.id}' at line ${openRegion.startLine}, closed '${endId}' at line ${i + 1}`);
96
+ }
97
+ // Extract content between markers (exclusive)
98
+ const contentLines = lines.slice(openRegion.startIndex + 1, i);
99
+ // Strip nested region markers from content
100
+ const content = stripRegionMarkers(contentLines.join('\n'), options);
101
+ regions[openRegion.id] = {
102
+ startLine: openRegion.startLine,
103
+ endLine: i + 1,
104
+ content: content.trim(),
105
+ };
106
+ }
107
+ }
108
+ if (stack.length > 0) {
109
+ const unclosed = stack[stack.length - 1];
110
+ throw new Error(`Unclosed region '${unclosed.id}' starting at line ${unclosed.startLine}`);
111
+ }
112
+ return regions;
113
+ }
114
+ /**
115
+ * Extract a specific region's content by ID.
116
+ *
117
+ * @param code - The source code to parse
118
+ * @param regionId - The ID of the region to extract
119
+ * @param options - Options including file extension for language detection
120
+ * @returns The region's content
121
+ * @throws Error if region not found
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const setupCode = extractRegion(code, 'setup', { extension: 'py' });
126
+ * ```
127
+ */
128
+ export function extractRegion(code, regionId, options = {}) {
129
+ const regions = parseRegions(code, options);
130
+ if (!(regionId in regions)) {
131
+ const available = Object.keys(regions);
132
+ const hint = available.length > 0
133
+ ? ` Available regions: ${available.join(', ')}`
134
+ : ' No regions found in code.';
135
+ throw new Error(`Region '${regionId}' not found.${hint}`);
136
+ }
137
+ return regions[regionId].content;
138
+ }
139
+ /**
140
+ * Remove all region marker lines from code.
141
+ *
142
+ * @param code - The source code to clean
143
+ * @param options - Options including file extension for language detection
144
+ * @returns Code with all region markers removed
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const cleanCode = stripRegionMarkers(code, { extension: 'ts' });
149
+ * ```
150
+ */
151
+ export function stripRegionMarkers(code, options = {}) {
152
+ const config = getLanguageConfig(options.extension ?? 'ts');
153
+ const { start: REGION_START, end: REGION_END } = createRegionPatterns(config.lineComment, config.blockComment);
154
+ const lines = code.split('\n');
155
+ const filtered = lines.filter((line) => !REGION_START.test(line) && !REGION_END.test(line));
156
+ return filtered.join('\n');
157
+ }
158
+ /**
159
+ * List all region IDs found in code.
160
+ *
161
+ * @param code - The source code to scan
162
+ * @param options - Options including file extension for language detection
163
+ * @returns Array of region IDs
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const regionIds = listRegions(code, { extension: 'ts' });
168
+ * // ['setup', 'main', 'cleanup']
169
+ * ```
170
+ */
171
+ export function listRegions(code, options = {}) {
172
+ const regions = parseRegions(code, options);
173
+ return Object.keys(regions);
174
+ }
175
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/regions/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;GAEG;AACH,SAAS,oBAAoB,CAC3B,WAAoB,EACpB,YAA+B;IAE/B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,wCAAwC;IACxC,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,QAAQ,OAAO,4BAA4B,CAAC,CAAC;IAC7D,CAAC;IAED,+CAA+C;IAC/C,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACnD,QAAQ,CAAC,IAAI,CAAC,QAAQ,KAAK,4BAA4B,GAAG,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,mBAAmB;IACnB,MAAM,YAAY,GAChB,QAAQ,CAAC,MAAM,GAAG,CAAC;QACjB,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC,CAAC,gCAAgC,CAAC;IAEvC,gCAAgC;IAChC,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,IAAI,WAAW,EAAE,CA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