All files / scripts/validators/executive-brief-translations/counters words.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                              19x 1143x    
/**
 * @module scripts/validators/executive-brief-translations/counters/words
 * @description Top-level word count for executive-brief translations
 *              (rough: split on whitespace after stripping fences/comments).
 *
 *              Rule census: extracted from
 *              `scripts/validate-executive-brief-translations.ts` lines
 *              189–193. Logic is byte-identical to the original.
 *
 *              NOTE: This is the executive-brief-flavoured `countWords`
 *              and differs from `scripts/validators/article/rules/citation-density`
 *              `countWords` — the article variant strips additional
 *              markdown (links, tables, blockquotes) because it feeds
 *              the citation-density ratio rather than parity comparisons.
 *
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { stripFencesAndComments } from '../strippers.js';
 
/** Top-level word count (rough: split on whitespace after stripping fences/comments). */
export function countWords(md: string): number {
  const stripped = stripFencesAndComments(md);
  return stripped.split(/\s+/).filter((w) => /\p{L}|\p{N}/u.test(w)).length;
}