Skip to content

Commit c9f93ae

Browse files
authored
JSON stringify
1 parent c9dd288 commit c9f93ae

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llms-txt-validation.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//[llms-txt-valid]
22
return fetch('/llms.txt')
33
.then(response => {
4-
if (!response.ok) return {"exists":0,"valid":0};
4+
if (!response.ok) return JSON.stringify({valid:0, error: "Non OK status code"});
55
const ct = response.headers.get('Content-Type')||'';
6-
if (!ct.toLowerCase().includes('text/plain')) return {"exists":1,"valid":0};
6+
if (!ct.toLowerCase().includes('text/plain')) return JSON.stringify({valid:0,error: "Invalid content type"});
77
return response.text().then(text => {
88
const m = s=> (text.match(new RegExp(`\\${s}`,'g'))||[]).length;
9-
if ((text.match(/```/g)||[]).length %2) return {"exists":1,"valid":0};
10-
if (m('[')!==m(']')||m('(')!==m(')')) return {"exists":1,"valid":0};
11-
return {"exists":1,"valid":1};
9+
if ((text.match(/```/g)||[]).length %2) return JSON.stringify({valid:0,error:""});
10+
if (m('[')!==m(']')||m('(')!==m(')')) return JSON.stringify({valid:0,error:""});
11+
return JSON.stringify({valid":1});
1212
});
1313
})
1414
.catch(error => {
15-
return JSON.stringify({message: error.message, error: error});
15+
return JSON.stringify({valid:0,message: error.message, error: error});
1616
});

0 commit comments

Comments
 (0)