UNPKG

breaker-ai

Version:

CLI to scan prompts for injection risks

22 lines (21 loc) 806 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.maskWordsInText = maskWordsInText; const load_1 = require("../utils/load"); async function maskWordsInText(target, wordList) { const text = await (0, load_1.load)(target); if (!wordList || wordList.length === 0) return text; let maskedText = text; for (const word of wordList) { if (word.length <= 2) { const regex = new RegExp(`\\b${word}\\b`, "gi"); maskedText = maskedText.replace(regex, match => "*".repeat(match.length)); } else { const regex = new RegExp(`\\b${word}\\b`, "gi"); maskedText = maskedText.replace(regex, match => match.slice(0, 2) + "*".repeat(match.length - 2)); } } return maskedText; }