MCPcopy Create free account
hub / github.com/garrytan/gstack / extractWeightsFromTable

Function extractWeightsFromTable

test/helpers/skill-parser.ts:180–211  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

178 * Returns Map<category, number> where number is the percentage (e.g., 15).
179 */
180export function extractWeightsFromTable(content: string): Map<string, number> {
181 const weights = new Map<string, number>();
182
183 // Find the ### Weights section
184 const weightsIdx = content.indexOf('### Weights');
185 if (weightsIdx === -1) return weights;
186
187 // Find the table within that section (stop at next heading or end)
188 const section = content.slice(weightsIdx);
189 const lines = section.split('\n');
190
191 for (let i = 1; i < lines.length; i++) {
192 const line = lines[i].trim();
193
194 // Stop at next heading
195 if (line.startsWith('#') && !line.startsWith('###')) break;
196 if (line.startsWith('### ') && i > 0) break;
197
198 // Parse table rows: | Category | N% |
199 const match = line.match(/^\|\s*(\w[\w\s]*\w|\w+)\s*\|\s*(\d+)%\s*\|$/);
200 if (match) {
201 const category = match[1].trim();
202 const pct = parseInt(match[2], 10);
203 // Skip header row
204 if (category !== 'Category' && !isNaN(pct)) {
205 weights.set(category, pct);
206 }
207 }
208 }
209
210 return weights;
211}

Callers 1

Calls 1

setMethod · 0.80

Tested by

no test coverage detected