function isValidString(inputString) {
const index = inputString.indexOf("--");
if (index == -1) {
return true;
}
inputString = inputString.substring(index);
const regex = /--[A-Za-z]+ [A-Za-z0-9:.]+/g;
const matches = inputString.match(regex);
if (!matches) {
return false;
}
const reconstructed = matches.join(' ');
return reconstructed === inputString;
}
function replacePunctuation(input) {
const keywords = [
"Aspect",
"ar",
"chaos",
"fast",
"iw",
"no",
"quality",
"q",
"relax",
"repeat",
"r",
"seed",
"stop",
"style",
"stylize",
"s",
"tile",
"turbo",
"weird",
"w",
];
let output = input.replace(
new RegExp(`--(?!${keywords.join("|")})`, "g"),
","
);
const regExp = /(?![\s.,:-])\p{P}/gu;
output = output.replace(regExp, ",");
output = output.trim();
return output;
}
const finalPrompt = replacePunctuation("An exquisite rose, with velvety petals in shades of deep red, unfurling gracefully amidst a bed of lush green leaves. Each petal is adorned with delicate dewdrops, glistening in the morning sunlight. The flower emits a captivating fragrance, filling the air with its sweet scent. A gentle breeze dances through the garden, causing the petals to sway and come to life. --ar 1:1");
console.log(finalPrompt);
const isValid = isValidString(finalPrompt);
console.log(isValid);
console