ubon
Version:
Security scanner for AI-generated React/Next.js and Python apps. Catches hardcoded secrets, accessibility issues, and vulnerabilities that traditional linters miss.
32 lines (31 loc) • 893 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.shannonEntropy = shannonEntropy;
exports.extractQuotedLiterals = extractQuotedLiterals;
function shannonEntropy(input) {
if (!input || input.length === 0)
return 0;
const map = {};
for (const ch of input)
map[ch] = (map[ch] || 0) + 1;
let entropy = 0;
const len = input.length;
for (const k in map) {
const p = map[k] / len;
entropy -= p * Math.log2(p);
}
return entropy;
}
// Extract quoted string-like tokens from a line
function extractQuotedLiterals(line) {
const matches = [];
const regex = /(['"]).*?\1/g; // simple non-greedy quoted
let m;
while ((m = regex.exec(line)) !== null) {
const raw = m[0];
if (raw.length >= 3) {
matches.push(raw.slice(1, -1));
}
}
return matches;
}