Initial commit: prompt template manager
React + Tailwind frontend, FastAPI backend, settings.json storage. Supports preset CRUD, live variable filling, and AI rewrite via OpenAI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const VAR_RE = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g
|
||||
|
||||
export function parseVars(template) {
|
||||
const seen = new Set()
|
||||
const vars = []
|
||||
let m
|
||||
VAR_RE.lastIndex = 0
|
||||
while ((m = VAR_RE.exec(template)) !== null) {
|
||||
if (!seen.has(m[1])) {
|
||||
seen.add(m[1])
|
||||
vars.push(m[1])
|
||||
}
|
||||
}
|
||||
return vars
|
||||
}
|
||||
|
||||
export function fillTemplate(template, values) {
|
||||
return template.replace(/\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g, (_, k) => values[k] ?? `{{${k}}}`)
|
||||
}
|
||||
Reference in New Issue
Block a user