@geometrically/minecraft-motd-parser
Version:
Minecraft Server MOTD Parser, can convert to html, json, text.
2 lines • 4.74 kB
JavaScript
var M=Object.defineProperty;var w=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var j=(t,e,o)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,b=(t,e)=>{for(var o in e||(e={}))N.call(e,o)&&j(t,o,e[o]);if(w)for(var o of w(e))E.call(e,o)&&j(t,o,e[o]);return t};function g(t){return!!t}function F(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\n/g,"<br/>")}function k(t){return t.replace(/<[^>]*>?/gm,"")}function c(t){let e=/(?:§)([0-9a-fA-FklmnorFKLMNOR])/g,o="";return o=t.replace(e,""),o}var h={"\xA7k":"obfuscated;","\xA7l":"font-weight: bold;","\xA7m":"text-decoration: line-through;","\xA7n":"text-decoration: underline;","\xA7o":"font-style: italic;","\xA7r":"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;"},O={bold:"font-weight: bold;",italic:"font-style: italic;",underlined:"text-decoration:underline;",strikethrough:"text-decoration: line-through;",obfuscated:"mc_obfuscated;",reset:"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;"},S={"\xA7k":"obfuscated","\xA7l":"bold","\xA7m":"strikethrough","\xA7n":"underlined","\xA7o":"italic","\xA7r":"reset"},m={"\xA70":"#000000","\xA71":"#0000AA","\xA72":"#00AA00","\xA73":"#00AAAA","\xA74":"#AA0000","\xA75":"#AA00AA","\xA76":"#FFAA00","\xA77":"#AAAAAA","\xA78":"#555555","\xA79":"#5555FF","\xA7a":"#55FF55","\xA7b":"#55FFFF","\xA7c":"#FF5555","\xA7d":"#FF55FF","\xA7e":"#FFFF55","\xA7f":"#FFFFFF"},L={black:"#000000",dark_blue:"#0000AA",dark_green:"#00AA00",dark_aqua:"#00AAAA",dark_red:"#AA0000",dark_purple:"#AA00AA",gold:"#FFAA00",gray:"#AAAAAA",dark_gray:"#555555",blue:"#5555FF",green:"#55FF55",aqua:"#55FFFF",red:"#FF5555",light_purple:"#FF55FF",yellow:"#FFFF55",white:"#FFFFFF"};function s(t){let e=t,o=/([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g,p=new RegExp(o.source),d=e.split(p).filter(l=>l!==""),r="",n="",i="";return d.forEach(l=>{let a=l.toLowerCase();if(Object.hasOwn(m,a))n=m[a],a==="\xA7f"&&(r="");else if(Object.hasOwn(h,a))a==="\xA7r"?(n="",r=""):r+=h[a];else{let f="",x=l;n!==""&&(f=`color:${n};`),x!==""&&(x=F(x),f.length!==0||r.length!==0?i+=`<span style="${f}${r}">${x}</span>`:i+=x)}}),i}function T(t){let e="",o="",p="";for(let r of Object.keys(t)){if(r=r.toLowerCase(),Object.hasOwn(O,r)&&t[r]&&(p+=`${O[r]}`),r==="color"){let n=t[r],i="";typeof n=="string"&&(Object.hasOwn(L,n)?i=L[n]:Object.hasOwn(m,n)?i=m[n]:i=n),i!==""&&(o=`color:${i};`)}if(r==="extra"&&typeof t.extra=="object"){t.text!==void 0&&(typeof t.text=="string"||typeof t.text=="number")&&(e+=s(String(t.text)));for(let n of t.extra)typeof n=="string"?e+=s(n):g(n)&&(e+=T(n))}}if(t.extra===void 0&&t.text!==void 0){let r=t.text;(typeof t.text=="string"||typeof t.text=="number")&&(e+=s(String(r)))}let d="";return p.length!==0||o.length!==0?d=`<span style="${o+p}">${e}</span>`:d=e,d}function y(t){let e="";for(let o of Object.keys(t))if(o=o.toLowerCase(),o==="extra"&&typeof t.extra=="object"){t.text!==void 0&&(typeof t.text=="string"||typeof t.text=="number")&&(e+=c(String(t.text)));for(let p of t.extra)typeof p=="string"?e+=c(p):g(p)&&(e+=y(p))}if(t.extra===void 0&&t.text!==void 0){let o=t.text;(typeof t.text=="string"||typeof t.text=="number")&&(e+=c(String(o)))}return e}function u(t){let e=t,o=/([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g,p=new RegExp(o.source),d=e.split(p),r="",n="",i={text:"",extra:[]};d.forEach(a=>{let f=a.toLowerCase();if(Object.hasOwn(m,f))n=m[f],f==="\xA7f"&&(r="");else if(Object.hasOwn(S,f))f==="\xA7r"?(r="",n=""):r=S[f];else{let x={text:"",extra:[]};r!==""&&(x[r]=!0),x.text=a,n!==""&&(x.color=n),typeof i.extra=="object"&&i.extra.push(x)}});let l=[];return i.extra&&(i.extra.length>1?i.extra.forEach((a,f)=>{a.text===""?i.extra&&typeof i.extra[f+1]=="object"&&l.push(b(b({},a),i.extra[f+1])):a.text!==(l[l.length-1]&&l[l.length-1].text)&&l.push(a)}):l.push(i.extra[0])),l=l.filter(a=>a.text!==""),{text:i.text,extra:l}}function A(t){return T(t)}function C(t){return typeof t=="object"?A(t):typeof t=="string"?s(t):"unknown motd data type"}function J(t){return typeof t=="object"?y(t):typeof t=="string"?c(t):"unknown motd data type"}var H=J;var R={textToHTML:s,textToJSON:u,JSONToHTML:T,JSONRender:A,autoToHTML:C,htmlStringFormatting:F,cleanCodes:c,cleanHtmlTags:k,JSONToCleanedText:y,autoCleanToText:H},st=R;export{A as JSONRender,y as JSONToCleanedText,T as JSONToHTML,H as autoCleanToText,C as autoToHTML,c as cleanCodes,k as cleanHtmlTags,st as default,F as htmlStringFormatting,g as isMotdJSONType,s as textToHTML,u as textToJSON};
//# sourceMappingURL=index.mjs.map