MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / splitSubsections

Function splitSubsections

scripts/prepare-release.mjs:110–128  ·  view source on GitHub ↗

* Split a block body into ordered sub-sections keyed by their * `### Heading`. Lines before the first `### Heading` go in * `leading`. Preserves the original (line-array) body inside each * sub-section so we can splice cleanly when merging.

(body)

Source from the content-addressed store, hash-verified

108 * sub-section so we can splice cleanly when merging.
109 */
110function splitSubsections(body) {
111 const subsectionRe = /^### (\w+)\s*$/;
112 const leading = [];
113 const subs = []; // { heading: 'Added' | 'Fixed' | …, headerLine: string, body: string[] }
114 let cur = null;
115 for (const line of body) {
116 const m = line.match(subsectionRe);
117 if (m) {
118 if (cur) subs.push(cur);
119 cur = { heading: m[1], headerLine: line, body: [] };
120 } else if (cur) {
121 cur.body.push(line);
122 } else {
123 leading.push(line);
124 }
125 }
126 if (cur) subs.push(cur);
127 return { leading, subs };
128}
129
130function rebuildBody({ leading, subs }) {
131 const parts = [];

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected