one-click-accessibility/modules/scanner/assets/js/utils/split-ai-response.js
VasylD fa2fd11e29
[APP-934] add submit logic (#259)
* [APP-934] add submit logic

* [APP-934] add submit logic

* [APP-934] add submit logic

* [APP-934] add submit logic

* Added replace remediation action

* Add submit logic

* Add submit alt text logic, generate AI alt text

* Add AI generate request, add convert from SVG to png base64, added manual fix block

* Add AI generate request, add convert from SVG to png base64, added manual fix block

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

---------

Co-authored-by: Raz Ohad <admin@bainternet.info>
2025-05-06 00:00:46 +03:00

20 lines
774 B
JavaScript

export const splitDescriptions = (inputString) => {
return inputString
.replace('Here are 5 alt text descriptions for the image:', '')
.replace('Here are 5 concise alt text descriptions for the image:', '')
.split('\n') // Split by newlines
.map((item) => item.trim()) // Trim leading/trailing spaces
.filter((item) => item.length > 0) // Filter out empty lines
.map((item) => {
// Check if the first dot is not the last item
if (item.indexOf('.') !== item.length - 1) {
item = item.replace(/^[^\.]*\.\s*/, ''); // Remove everything before and including the first dot
}
if (item.length >= 2 && item.startsWith('"') && item.endsWith('"')) {
item = item.slice(1, -1);
}
return item; // Leave the item unchanged if dot is last
});
};