@publishpress/potomatic 0.0.0-stage → 1.4.5

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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Prompt Loader Utility.
3
+ * Loads the translation system prompt from prompt.md.
4
+ * This is the production prompt loader used by potomatic.js.
5
+ *
6
+ * @since 1.0.0
7
+ */
8
+
9
+ import fs from 'fs';
10
+ import path from 'path';
11
+ import { fileURLToPath } from 'url';
12
+ import { DEFAULT_MODEL, getEncodingForModel } from '../providers/openai/modelCapabilities.js';
13
+ import { getApiTargetLanguage } from './languageMapping.js';
14
+ import { getPluralForms, extractPluralCount } from './poFileUtils.js';
15
+
16
+ /**
17
+ * Loads the system prompt from prompt.md.
18
+ *
19
+ * @since 1.0.0
20
+ *
21
+ * @param {string} promptFilePath - Path to the prompt.md file.
22
+ *
23
+ * @return {string} The system prompt template.
24
+ */
25
+ function loadPromptTemplate(promptFilePath) {
26
+ try {
27
+ const content = fs.readFileSync(promptFilePath, 'utf-8');
28
+ const prompt = content.trim();
29
+
30
+ if (!prompt) {
31
+ throw new Error('Prompt file is empty');
32
+ }
33
+
34
+ return prompt;
35
+ } catch (error) {
36
+ throw new Error(`Failed to load prompt from ${promptFilePath}: ${error.message}`);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Builds a system prompt for translation.
42
+ *
43
+ * @since 1.0.0
44
+ *
45
+ * @param {string} targetLang - Target language code (e.g., 'fr_FR', 'es_ES').
46
+ * @param {string} sourceLang - Source language code (e.g., 'en', 'English').
47
+ * @param {string} promptFilePath - Path to the prompt.md file (optional).
48
+ *
49
+ * @return {string} Complete system prompt ready for use.
50
+ */
51
+ export function buildSystemPrompt(targetLang, sourceLang = 'English', promptFilePath = null, extraPromptPath = null) {
52
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
53
+ const defaultPromptPath = path.resolve(currentDir, '../../config/prompt.md');
54
+
55
+ // --prompt-file-path fully overrides the default prompt.
56
+ // --extra-prompt-path appends to the default prompt (for domain-specific terminology).
57
+ let template;
58
+
59
+ if (promptFilePath) {
60
+ template = loadPromptTemplate(promptFilePath);
61
+ } else {
62
+ template = loadPromptTemplate(defaultPromptPath);
63
+ }
64
+
65
+ if (extraPromptPath) {
66
+ if (!fs.existsSync(extraPromptPath)) {
67
+ throw new Error(`Extra prompt file not found: ${extraPromptPath}`);
68
+ }
69
+
70
+ const extraTemplate = loadPromptTemplate(extraPromptPath);
71
+
72
+ template = template + '\n\n' + extraTemplate;
73
+ }
74
+
75
+ const targetLanguageName = getApiTargetLanguage(targetLang);
76
+ const sourceLanguageName = getApiTargetLanguage(sourceLang);
77
+ const pluralFormsString = getPluralForms(targetLang, { debug: () => {}, warn: () => {} });
78
+ const pluralCount = extractPluralCount(pluralFormsString);
79
+
80
+ return template
81
+ .replace(/\{\{SOURCE_LANGUAGE\}\}/g, sourceLanguageName)
82
+ .replace(/\{\{TARGET_LANGUAGE\}\}/g, targetLanguageName)
83
+ .replace(/\{\{TARGET_LANGUAGE_CODE\}\}/g, targetLang)
84
+ .replace(/\{\{PLURAL_COUNT\}\}/g, pluralCount.toString());
85
+ }
86
+
87
+ /**
88
+ * Gets exact token count for a prompt using tiktoken.
89
+ *
90
+ * @since 1.0.0
91
+ *
92
+ * @param {string} prompt - The prompt text.
93
+ * @param {string} model - The model to get encoding for (defaults to the configured default model).
94
+ *
95
+ * @return {number} Exact token count.
96
+ */
97
+ export function getPromptTokenCount(prompt, model = DEFAULT_MODEL) {
98
+ if (!prompt || typeof prompt !== 'string') {
99
+ return 0;
100
+ }
101
+
102
+ const encoding = getEncodingForModel(model);
103
+
104
+ if (!encoding) {
105
+ return Math.ceil(prompt.length / 4);
106
+ }
107
+
108
+ try {
109
+ return encoding.encode(prompt).length;
110
+ } catch (error) {
111
+ console.warn(`Failed to get exact token count: ${error.message}`);
112
+
113
+ return Math.ceil(prompt.length / 4);
114
+ }
115
+ }
@@ -0,0 +1,417 @@
1
+ import { getStyledColor, getBoldColor } from './colorUtils.js';
2
+ import { calculateAggregateTotals, formatCost, getCostLabel, formatNumber, formatDuration } from './costCalculations.js';
3
+ import { getTotalValidationIssues } from './validationStats.js';
4
+
5
+ /**
6
+ * Creates a logger with configurable verbosity levels.
7
+ * Provides colored output using the centralized color utility for consistent styling.
8
+ *
9
+ * @since 1.0.0
10
+ *
11
+ * @param {number} verboseLevel - Logging verbosity level (0-3).
12
+ * @param {Object} chalkInstance - Chalk instance for colored output.
13
+ *
14
+ * @return {Object} Logger object with error, warn, info, success, debug, log, and raw methods.
15
+ */
16
+ export function createLogger(verboseLevel, chalkInstance) {
17
+ return {
18
+ /**
19
+ * Logs error messages.
20
+ * Always shown regardless of verbosity level.
21
+ *
22
+ * @since 1.0.0
23
+ *
24
+ * @param {string} message - Error message.
25
+ * @param {...any} optionalParams - Additional parameters to log.
26
+ */
27
+ error: (message, ...optionalParams) => {
28
+ if (verboseLevel < 0) {
29
+ return;
30
+ }
31
+
32
+ const styledParams = optionalParams.map((param) => {
33
+ if (param instanceof Error) {
34
+ return chalkInstance.red(param.stack || param.message);
35
+ }
36
+
37
+ return param;
38
+ });
39
+
40
+ console.error(chalkInstance.redBright.bold('ERROR:'), chalkInstance.red(message), ...styledParams);
41
+ },
42
+
43
+ /**
44
+ * Logs warning messages.
45
+ * Shown at verbosity level 1 and above.
46
+ *
47
+ * @since 1.0.0
48
+ *
49
+ * @param {string} message - Warning message.
50
+ * @param {...any} optionalParams - Additional parameters to log.
51
+ */
52
+ warn: (message, ...optionalParams) => {
53
+ if (verboseLevel < 1) {
54
+ return;
55
+ }
56
+
57
+ console.warn(chalkInstance.yellow('WARN:'), chalkInstance.yellow(message), ...optionalParams);
58
+ },
59
+
60
+ /**
61
+ * Logs informational messages with configurable verbosity.
62
+ *
63
+ * @since 1.0.0
64
+ *
65
+ * @param {string} message - Information message.
66
+ * @param {number} verbosity - Minimum verbosity level required (default: 1).
67
+ * @param {...any} optionalParams - Additional parameters to log.
68
+ */
69
+ info: (message, verbosity = 1, ...optionalParams) => {
70
+ if (verboseLevel < verbosity) {
71
+ return;
72
+ }
73
+
74
+ console.log(chalkInstance.blueBright('INFO:'), chalkInstance.blueBright(message), ...optionalParams);
75
+ },
76
+
77
+ /**
78
+ * Logs success messages with configurable verbosity.
79
+ *
80
+ * @since 1.0.0
81
+ *
82
+ * @param {string} message - Success message.
83
+ * @param {number} verbosity - Minimum verbosity level required (default: 0).
84
+ * @param {...any} optionalParams - Additional parameters to log.
85
+ */
86
+ success: (message, verbosity = 0, ...optionalParams) => {
87
+ if (verboseLevel < verbosity) {
88
+ return;
89
+ }
90
+
91
+ console.log(chalkInstance.greenBright.bold('SUCCESS:'), chalkInstance.green(message), ...optionalParams);
92
+ },
93
+
94
+ /**
95
+ * Logs debug messages.
96
+ * Shown at verbosity level 2 and above.
97
+ *
98
+ * @since 1.0.0
99
+ *
100
+ * @param {string} message - Debug message.
101
+ * @param {number} verbosity - Minimum verbosity level required (default: 2).
102
+ * @param {...any} optionalParams - Additional parameters to log.
103
+ */
104
+ debug: (message, verbosity = 2, ...optionalParams) => {
105
+ if (verboseLevel < verbosity) {
106
+ return;
107
+ }
108
+
109
+ console.log(chalkInstance.gray('DEBUG:'), chalkInstance.gray(message), ...optionalParams);
110
+ },
111
+
112
+ /**
113
+ * Logs plain messages with configurable verbosity.
114
+ *
115
+ * @since 1.0.0
116
+ *
117
+ * @param {string} message - Message to log.
118
+ * @param {number} requiredLevel - Minimum verbosity level required (default: 1).
119
+ * @param {...any} optionalParams - Additional parameters to log.
120
+ */
121
+ log: (message, requiredLevel = 1, ...optionalParams) => {
122
+ if (verboseLevel < requiredLevel) {
123
+ return;
124
+ }
125
+
126
+ console.log(message, ...optionalParams);
127
+ },
128
+
129
+ /**
130
+ * Logs raw messages without any formatting.
131
+ * Shown at verbosity level 2 and above by default.
132
+ *
133
+ * @since 1.0.0
134
+ *
135
+ * @param {string} message - Raw message to log.
136
+ * @param {number} requiredLevel - Minimum verbosity level required (default: 2).
137
+ * @param {...any} optionalParams - Additional parameters to log.
138
+ */
139
+ raw: (message, requiredLevel = 2, ...optionalParams) => {
140
+ if (verboseLevel < requiredLevel) {
141
+ return;
142
+ }
143
+
144
+ console.log(message, ...optionalParams);
145
+ },
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Prints a comprehensive summary of the translation run.
151
+ * Shows statistics, results, cost information, and execution times for all processed languages.
152
+ *
153
+ * @since 1.0.0
154
+ *
155
+ * @param {Array} allLanguageStats - Array of language processing statistics.
156
+ * @param {Object} logger - Logger instance for output.
157
+ * @param {Object} effectiveChalk - Chalk instance (or no-op if disabled).
158
+ * @param {number} startTime - Overall process start time in milliseconds.
159
+ * @param {number} endTime - Overall process end time in milliseconds.
160
+ */
161
+ export function printTranslationRunSummary(allLanguageStats, logger, effectiveChalk, startTime, endTime) {
162
+ if (allLanguageStats.length === 0) {
163
+ logger.warn('No language statistics available for summary.');
164
+ return;
165
+ }
166
+
167
+ logger.info(getBoldColor('info')(''), 0);
168
+ logger.info(getBoldColor('info')('=== TRANSLATION RUN SUMMARY ==='), 0);
169
+
170
+ const totals = calculateAggregateTotals(allLanguageStats);
171
+
172
+ // Calculate total execution time from overall start/end times when available.
173
+ // Fall back to summing individual times for backward compatibility (e.g., when called without timing info).
174
+ let totalExecutionTimeMs;
175
+ if (startTime && endTime) {
176
+ totalExecutionTimeMs = endTime - startTime;
177
+ } else {
178
+ totalExecutionTimeMs = allLanguageStats.reduce((sum, stat) => sum + (stat.executionTimeMs || 0), 0);
179
+ }
180
+ const totalExecutionTimeFormatted = formatDuration(totalExecutionTimeMs);
181
+
182
+ // Count languages with warnings.
183
+ const languagesWithWarnings = allLanguageStats.filter((stat) => {
184
+ return stat.validationStats && getTotalValidationIssues(stat.validationStats) > 0;
185
+ }).length;
186
+
187
+ // Print overall results.
188
+ const summaryParts = [`Languages processed: ${getStyledColor('success')(totals.languagesProcessed)}`, `With errors: ${getStyledColor('error')(totals.languagesWithErrors)}`];
189
+
190
+ if (languagesWithWarnings > 0) {
191
+ summaryParts.push(`With warnings: ${getStyledColor('warning')(languagesWithWarnings)}`);
192
+ }
193
+
194
+ logger.info(summaryParts.join(' | '), 0);
195
+
196
+ const resultParts = [];
197
+
198
+ // Calculate detailed totals from all language stats.
199
+ const totalAlreadyTranslated = allLanguageStats.reduce((sum, stat) => sum + (stat.alreadyTranslated || 0), 0);
200
+ const totalSkippedDueToBudget = allLanguageStats.reduce((sum, stat) => sum + (stat.skippedDueToBudget || 0), 0);
201
+ const totalSkippedDueToLimits = allLanguageStats.reduce((sum, stat) => sum + (stat.skippedDueToLimits || 0), 0);
202
+ const totalFailed = allLanguageStats.reduce((sum, stat) => sum + (stat.failedInRun || 0), 0);
203
+
204
+ // Order: Merged, Translated, Skipped, Failed.
205
+ if (totalAlreadyTranslated > 0) {
206
+ resultParts.push(`${getStyledColor('info')(formatNumber(totalAlreadyTranslated))} merged`);
207
+ }
208
+
209
+ resultParts.push(`${getStyledColor('success')(formatNumber(totals.totalTranslated))} translated`);
210
+
211
+ const totalSkipped = totalSkippedDueToBudget + totalSkippedDueToLimits;
212
+
213
+ if (totalSkipped > 0) {
214
+ const skippedParts = [];
215
+
216
+ if (totalSkippedDueToLimits > 0) {
217
+ skippedParts.push(`${formatNumber(totalSkippedDueToLimits)} due to string limits`);
218
+ }
219
+ if (totalSkippedDueToBudget > 0) {
220
+ skippedParts.push(`${formatNumber(totalSkippedDueToBudget)} due to cost limits`);
221
+ }
222
+
223
+ // Only show breakdown if there are multiple reasons for skipping.
224
+ if (skippedParts.length > 1) {
225
+ resultParts.push(`${getStyledColor('warn')(formatNumber(totalSkipped))} skipped (${skippedParts.join(', ')})`);
226
+ } else {
227
+ // Single reason - just show the reason without redundant total.
228
+ const reason = totalSkippedDueToLimits > 0 ? 'due to string limits' : 'due to cost limits';
229
+
230
+ resultParts.push(`${getStyledColor('warn')(formatNumber(totalSkipped))} skipped ${reason}`);
231
+ }
232
+ }
233
+
234
+ if (totalFailed > 0) {
235
+ resultParts.push(`${getStyledColor('error')(formatNumber(totalFailed))} failed`);
236
+ }
237
+
238
+ logger.info(`Total strings: ${resultParts.join(', ')}`, 0);
239
+
240
+ // Print cost information using centralized formatting.
241
+ const costLabel = getCostLabel(allLanguageStats);
242
+
243
+ if (totals.totalCost > 0) {
244
+ logger.info(`${costLabel}: ${getStyledColor('highlight')(formatCost(totals.totalCost))} | Total tokens: ${getStyledColor('info')(formatNumber(totals.totalTokens))}`, 0);
245
+ }
246
+
247
+ // Print execution time information.
248
+ logger.info(`Total execution time: ${getStyledColor('info')(totalExecutionTimeFormatted)}`, 0);
249
+
250
+ logger.info(getBoldColor('info')(''), 0);
251
+ logger.info(getBoldColor('info')('Language Details:'), 0);
252
+
253
+ // Show per-language details.
254
+ allLanguageStats.forEach((stat) => {
255
+ _printLanguageDetail(stat, logger);
256
+ });
257
+
258
+ logger.info(getBoldColor('info')(''), 0);
259
+ logger.info(getBoldColor('info')('=== END SUMMARY ==='), 0);
260
+ }
261
+
262
+ /**
263
+ * Prints detailed information for a single language.
264
+ *
265
+ * @private
266
+ *
267
+ * @since 1.0.0
268
+ *
269
+ * @param {Object} stat - Language statistics object.
270
+ * @param {Object} logger - Logger instance for output.
271
+ */
272
+ function _printLanguageDetail(stat, logger) {
273
+ const languageCode = stat.language;
274
+
275
+ if (stat.error) {
276
+ const executionTime = stat.executionTimeMs ? formatDuration(stat.executionTimeMs) : 'N/A';
277
+
278
+ logger.info(` ${getStyledColor('error')(`✗ ${languageCode}`)} - Error: ${getStyledColor('error')(stat.error)} | Time: ${getStyledColor('muted')(executionTime)}`, 0);
279
+ return;
280
+ }
281
+
282
+ // Use the shared buildLanguageResultLine function for consistent formatting.
283
+ const line = buildLanguageResultLine(stat, {
284
+ includeLanguageCode: true,
285
+ styled: true,
286
+ });
287
+
288
+ logger.info(` ${line}`, 0);
289
+ }
290
+
291
+ /**
292
+ * Builds consistent result parts array for language statistics display.
293
+ * Used by both orchestrator task titles and detailed summaries to ensure consistent terminology.
294
+ *
295
+ * @since 1.0.0
296
+ *
297
+ * @param {Object} stats - Language processing statistics.
298
+ *
299
+ * @return {Array} Array of result description strings.
300
+ */
301
+ export function buildResultParts(stats) {
302
+ const resultParts = [];
303
+
304
+ // Show translated count.
305
+ if (stats.translatedInRun > 0) {
306
+ resultParts.push(`${formatNumber(stats.translatedInRun)} translated`);
307
+ }
308
+
309
+ // Show merged count (actual previously existing translations.).
310
+ if (stats.mergedFromExisting > 0) {
311
+ resultParts.push(`${formatNumber(stats.mergedFromExisting)} merged`);
312
+ }
313
+
314
+ // Show skipped counts with clear reasons.
315
+ if (stats.skippedDueToLimits > 0) {
316
+ resultParts.push(`${formatNumber(stats.skippedDueToLimits)} skipped due to string limits`);
317
+ }
318
+
319
+ if (stats.skippedDueToBudget > 0) {
320
+ resultParts.push(`${formatNumber(stats.skippedDueToBudget)} skipped due to cost limits`);
321
+ }
322
+
323
+ // Show failed count.
324
+ if (stats.failedInRun > 0) {
325
+ resultParts.push(`${formatNumber(stats.failedInRun)} failed`);
326
+ }
327
+
328
+ return resultParts;
329
+ }
330
+
331
+ /**
332
+ * Builds a complete formatted result line for a language with consistent formatting.
333
+ * Used by both orchestrator task titles and detailed summaries to ensure identical output.
334
+ *
335
+ * @since 1.0.0
336
+ *
337
+ * @param {Object} stats - Language processing statistics.
338
+ * @param {Object} options - Formatting options.
339
+ * @param {boolean} options.includeLanguageCode - Whether to include language code prefix.
340
+ * @param {boolean} options.styled - Whether to apply color styling.
341
+ * @param {string} options.prefix - Prefix for the line (e.g., "Finished" or "✓").
342
+ *
343
+ * @return {string} Complete formatted result line.
344
+ */
345
+ export function buildLanguageResultLine(stats, options = {}) {
346
+ const { includeLanguageCode = true, styled = false, prefix = '' } = options;
347
+
348
+ // Get the basic result parts.
349
+ const resultParts = buildResultParts(stats);
350
+
351
+ // Apply styling if requested.
352
+ const formattedParts = styled
353
+ ? resultParts.map((part) => {
354
+ if (part.includes('translated')) {
355
+ return part.replace(/(\d+(?:,\d+)*) translated/, (match, num) => `${getStyledColor('success')(num)} translated`);
356
+ } else if (part.includes('merged')) {
357
+ return part.replace(/(\d+(?:,\d+)*) merged/, (match, num) => `${getStyledColor('info')(num)} merged`);
358
+ } else if (part.includes('skipped')) {
359
+ return part.replace(/(\d+(?:,\d+)*) skipped/, (match, num) => `${getStyledColor('warn')(num)} skipped`);
360
+ } else if (part.includes('failed')) {
361
+ return part.replace(/(\d+(?:,\d+)*) failed/, (match, num) => `${getStyledColor('error')(num)} failed`);
362
+ }
363
+
364
+ return part;
365
+ })
366
+ : resultParts;
367
+
368
+ // Build the main content.
369
+ let line = '';
370
+
371
+ if (prefix && includeLanguageCode) {
372
+ const languageDisplay = styled ? getStyledColor('success')(`${prefix} ${stats.language}`) : `${prefix} ${stats.language}`;
373
+
374
+ line = `${languageDisplay}: ${formattedParts.join(', ')}`;
375
+ } else if (includeLanguageCode) {
376
+ const languageDisplay = styled ? getStyledColor('success')(`✓ ${stats.language}`) : `✓ ${stats.language}`;
377
+
378
+ line = `${languageDisplay} - ${formattedParts.join(', ')}`;
379
+ } else {
380
+ line = formattedParts.join(', ');
381
+ }
382
+
383
+ // Add cost information.
384
+ const cost = stats.costData?.totalCost || 0;
385
+
386
+ if (cost > 0) {
387
+ const costDisplay = stats.costData?.isDryRun ? `Cost (estimated): ${formatCost(cost)}` : `Cost: ${formatCost(cost)}`;
388
+ const styledCost = styled ? getStyledColor('highlight')(costDisplay) : costDisplay;
389
+
390
+ line += ` | ${styledCost}`;
391
+ }
392
+
393
+ // Add token information.
394
+ const tokens = stats.costData?.totalTokens || 0;
395
+
396
+ if (tokens > 0) {
397
+ const tokenDisplay = `${formatNumber(tokens)} tokens`;
398
+ const styledTokens = styled ? getStyledColor('info')(tokenDisplay) : tokenDisplay;
399
+
400
+ line += ` | ${styledTokens}`;
401
+ }
402
+
403
+ // Add execution time.
404
+ const executionTime = stats.executionTimeMs ? formatDuration(stats.executionTimeMs) : 'N/A';
405
+ const styledTime = styled ? getStyledColor('info')(executionTime) : executionTime;
406
+
407
+ line += ` | Time: ${styledTime}`;
408
+
409
+ // Add output file.
410
+ if (stats.outputFile) {
411
+ const styledFile = styled ? getStyledColor('muted')(stats.outputFile) : stats.outputFile;
412
+
413
+ line += ` | ${styledFile}`;
414
+ }
415
+
416
+ return line;
417
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Validation statistics utilities.
3
+ * Centralized validation type definitions and helper functions.
4
+ *
5
+ * @since 1.1.0
6
+ */
7
+
8
+ /**
9
+ * Registry of all validation types with their display names.
10
+ *
11
+ * @since 1.1.0
12
+ */
13
+ export const VALIDATION_TYPES = {
14
+ stringsWithPluralIssues: 'strings with plural issues',
15
+ };
16
+
17
+ /**
18
+ * Creates an empty validation statistics object with all validation types initialized to 0.
19
+ *
20
+ * @since 1.1.0
21
+ *
22
+ * @return {Object} Empty validation stats object.
23
+ */
24
+ export function createEmptyValidationStats() {
25
+ const stats = {};
26
+
27
+ for (const key of Object.keys(VALIDATION_TYPES)) {
28
+ stats[key] = 0;
29
+ }
30
+
31
+ // Track which specific strings were blanked due to placeholder mismatch.
32
+ stats.blankedStrings = [];
33
+
34
+ return stats;
35
+ }
36
+
37
+ /**
38
+ * Calculates the total number of validation issues.
39
+ *
40
+ * @since 1.1.0
41
+ *
42
+ * @param {Object} validationStats - Validation statistics object.
43
+ *
44
+ * @return {number} Total number of validation issues.
45
+ */
46
+ export function getTotalValidationIssues(validationStats) {
47
+ if (!validationStats) {
48
+ return 0;
49
+ }
50
+
51
+ let total = 0;
52
+
53
+ for (const key of Object.keys(VALIDATION_TYPES)) {
54
+ total += validationStats[key] || 0;
55
+ }
56
+
57
+ return total;
58
+ }
59
+
60
+ /**
61
+ * Formats validation stats as a human-readable breakdown string.
62
+ *
63
+ * @since 1.1.0
64
+ *
65
+ * @param {Object} validationStats - Validation statistics object.
66
+ *
67
+ * @return {string} Formatted breakdown string (e.g., "2 strings with plural issues").
68
+ */
69
+ export function formatValidationBreakdown(validationStats) {
70
+ if (!validationStats) {
71
+ return '';
72
+ }
73
+
74
+ const parts = [];
75
+
76
+ for (const [key, label] of Object.entries(VALIDATION_TYPES)) {
77
+ const count = validationStats[key] || 0;
78
+ if (count > 0) {
79
+ parts.push(`${count} ${label}`);
80
+ }
81
+ }
82
+
83
+ return parts.length > 0 ? parts.join(', ') : 'no issues';
84
+ }
85
+
86
+ /**
87
+ * Accumulates validation stats from a source object into a target object.
88
+ *
89
+ * @since 1.1.0
90
+ *
91
+ * @param {Object} target - Target validation stats object to accumulate into.
92
+ * @param {Object} source - Source validation stats object to accumulate from.
93
+ */
94
+ export function accumulateValidationStats(target, source) {
95
+ if (!source) {
96
+ return;
97
+ }
98
+
99
+ for (const key of Object.keys(VALIDATION_TYPES)) {
100
+ target[key] = (target[key] || 0) + (source[key] || 0);
101
+ }
102
+
103
+ if (source.blankedStrings && source.blankedStrings.length > 0) {
104
+ if (!target.blankedStrings) {
105
+ target.blankedStrings = [];
106
+ }
107
+
108
+ target.blankedStrings.push(...source.blankedStrings);
109
+ }
110
+ }