UNPKG

@geometrically/minecraft-motd-parser

Version:

Minecraft Server MOTD Parser, can convert to html, json, text.

2 lines 5.29 kB
var b=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var M=(t,e,o)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,S=(t,e)=>{for(var o in e||(e={}))N.call(e,o)&&M(t,o,e[o]);if(k)for(var o of k(e))R.call(e,o)&&M(t,o,e[o]);return t};var _=(t,e)=>{for(var o in e)b(t,o,{get:e[o],enumerable:!0})},$=(t,e,o,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of J(e))!N.call(t,p)&&p!==o&&b(t,p,{get:()=>e[p],enumerable:!(l=E(e,p))||l.enumerable});return t};var K=t=>$(b({},"__esModule",{value:!0}),t);var P={};_(P,{JSONRender:()=>A,JSONToCleanedText:()=>y,JSONToHTML:()=>T,autoCleanToText:()=>O,autoToHTML:()=>h,cleanCodes:()=>c,cleanHtmlTags:()=>L,default:()=>X,htmlStringFormatting:()=>F,isMotdJSONType:()=>g,textToHTML:()=>s,textToJSON:()=>u});module.exports=K(P);function g(t){return!!t}function F(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/\n/g,"<br/>")}function L(t){return t.replace(/<[^>]*>?/gm,"")}function c(t){let e=/(?:§)([0-9a-fA-FklmnorFKLMNOR])/g,o="";return o=t.replace(e,""),o}var C={"\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;"},H={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;"},w={"\xA7k":"obfuscated","\xA7l":"bold","\xA7m":"strikethrough","\xA7n":"underlined","\xA7o":"italic","\xA7r":"reset"},d={"\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"},j={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,l=new RegExp(o.source),p=e.split(l).filter(f=>f!==""),r="",n="",i="";return p.forEach(f=>{let a=f.toLowerCase();if(Object.hasOwn(d,a))n=d[a],a==="\xA7f"&&(r="");else if(Object.hasOwn(C,a))a==="\xA7r"?(n="",r=""):r+=C[a];else{let x="",m=f;n!==""&&(x=`color:${n};`),m!==""&&(m=F(m),x.length!==0||r.length!==0?i+=`<span style="${x}${r}">${m}</span>`:i+=m)}}),i}function T(t){let e="",o="",l="";for(let r of Object.keys(t)){if(r=r.toLowerCase(),Object.hasOwn(H,r)&&t[r]&&(l+=`${H[r]}`),r==="color"){let n=t[r],i="";typeof n=="string"&&(Object.hasOwn(j,n)?i=j[n]:Object.hasOwn(d,n)?i=d[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 p="";return l.length!==0||o.length!==0?p=`<span style="${o+l}">${e}</span>`:p=e,p}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 l of t.extra)typeof l=="string"?e+=c(l):g(l)&&(e+=y(l))}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,l=new RegExp(o.source),p=e.split(l),r="",n="",i={text:"",extra:[]};p.forEach(a=>{let x=a.toLowerCase();if(Object.hasOwn(d,x))n=d[x],x==="\xA7f"&&(r="");else if(Object.hasOwn(w,x))x==="\xA7r"?(r="",n=""):r=w[x];else{let m={text:"",extra:[]};r!==""&&(m[r]=!0),m.text=a,n!==""&&(m.color=n),typeof i.extra=="object"&&i.extra.push(m)}});let f=[];return i.extra&&(i.extra.length>1?i.extra.forEach((a,x)=>{a.text===""?i.extra&&typeof i.extra[x+1]=="object"&&f.push(S(S({},a),i.extra[x+1])):a.text!==(f[f.length-1]&&f[f.length-1].text)&&f.push(a)}):f.push(i.extra[0])),f=f.filter(a=>a.text!==""),{text:i.text,extra:f}}function A(t){return T(t)}function h(t){return typeof t=="object"?A(t):typeof t=="string"?s(t):"unknown motd data type"}function q(t){return typeof t=="object"?y(t):typeof t=="string"?c(t):"unknown motd data type"}var O=q;var G={textToHTML:s,textToJSON:u,JSONToHTML:T,JSONRender:A,autoToHTML:h,htmlStringFormatting:F,cleanCodes:c,cleanHtmlTags:L,JSONToCleanedText:y,autoCleanToText:O},X=G;0&&(module.exports={JSONRender,JSONToCleanedText,JSONToHTML,autoCleanToText,autoToHTML,cleanCodes,cleanHtmlTags,htmlStringFormatting,isMotdJSONType,textToHTML,textToJSON}); //# sourceMappingURL=index.js.map