@sfirew/minecraft-motd-parser 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.ts ADDED
@@ -0,0 +1,23 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/recommended"
10
+ ],
11
+ "overrides": [
12
+ ],
13
+ "parser": "@typescript-eslint/parser",
14
+ "parserOptions": {
15
+ "ecmaVersion": "latest",
16
+ "sourceType": "module"
17
+ },
18
+ "plugins": [
19
+ "@typescript-eslint"
20
+ ],
21
+ "rules": {
22
+ }
23
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Kevin Zheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,280 @@
1
+ # Minecraft Server MOTD Parser
2
+ ![Version](https://img.shields.io/github/languages/top/SnowFireWolf/minecraft-motd-parser?style=for-the-badge)
3
+ [![npm version](https://img.shields.io/npm/v/@sfirew/mc-motd-parser?label=version&style=for-the-badge)](https://www.npmjs.com/package/@sfirew/mc-motd-parser?style=for-the-badge)
4
+ [![License](https://img.shields.io/npm/l/minecraft-server-util?style=for-the-badge)](https://github.com/SnowFireWolf/minecraft-motd-parser/blob/master/LICENSE)
5
+ ![npm weekly downloads](https://img.shields.io/npm/dw/@sfirew/mc-motd-parser?style=for-the-badge)
6
+
7
+
8
+
9
+ ## Introduction
10
+ This package support **CommonJS**, **ES Module**, and **tree shaking**
11
+
12
+ Can convert minecraft server MOTD data to text, json, html, and clean tags.
13
+
14
+ Support **1.16** custom **hex color**, and auto check motd data type.
15
+
16
+ Don't have other dependencies.
17
+
18
+
19
+
20
+ ## Installation
21
+ choose your favorite package manager
22
+ ```bash
23
+ # npm
24
+ $ npm install @sfirew/minecraft-motd-parser
25
+
26
+ # yarn
27
+ $ yarn add @sfirew/minecraft-motd-parser
28
+
29
+ # pnpm
30
+ $ pnpm add @sfirew/minecraft-motd-parser
31
+ ```
32
+
33
+
34
+
35
+ ## Usage
36
+ ### CommonJS
37
+ ```typescript
38
+ const { autoToHtml } = require('@sfirew/minecraft-motd-parser');
39
+ ```
40
+
41
+ ### ES6 Modules
42
+ ```typescript
43
+ import { autoToHtml } from '@sfirew/minecraft-motd-parser'
44
+ // or
45
+ import motdParser from '@sfirew/minecraft-motd-parser'
46
+ // motdParser.autoToHtml('motdString');
47
+ ```
48
+
49
+ ### Simple use example
50
+ ```typescript
51
+ import { autoToHtml as motdParser } from '@sfirew/minecraft-motd-parser'
52
+
53
+ const hypixelMotdString = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE";
54
+
55
+ console.log(motdParser(hypixelMotdString));
56
+
57
+ /* result
58
+ <span style="color:#55FF55;">Hypixel Network </span><span style="color:#FF5555;">1.8/1.9/1.10/1.11/1.12 </span><span style="color:#FFFF55;font-weight: bold;">NEW PTL GAME:</span><span style="color:#55FFFF;font-weight: bold;"> THE BRIDGE</span>
59
+ */
60
+ ```
61
+
62
+
63
+ ### Some good custom motd hex color servers
64
+ The parser does not have the Minecraft font by default.
65
+
66
+ #### Minecraft font example
67
+ ![Image_2022_01_2022d-2022h_58___002](https://user-images.githubusercontent.com/14024836/149810729-71909ca5-5705-43cf-ab3c-bdd66db00b78.png)
68
+
69
+ ![Image_2022_01_2022d-2022h_00___004](https://user-images.githubusercontent.com/14024836/149811040-5ddc35a0-38cf-4434-856a-968c94a4d6b4.png)
70
+
71
+ #### No Minecraft font
72
+ ![Image_2022_01_2022d-2022h_04___003](https://user-images.githubusercontent.com/14024836/149811501-d1376d90-d9ad-4092-912a-de1f78fa42eb.png)
73
+
74
+ ![Image_2022_01_2022d-2022h_01___002](https://user-images.githubusercontent.com/14024836/149811151-d9270d63-aead-46f9-b496-c88eb3b00c72.png)
75
+
76
+
77
+ You can try server status view in my created service
78
+ [https://mcsv.top/server/mc.hypixel.net](https://mcsv.top/server/mc.hypixel.net)
79
+
80
+
81
+
82
+ ## More Example
83
+ Some examples here, you can use **TypeScript** or **JavaScript**.
84
+
85
+
86
+ ### `cleanTags(string)`
87
+ clean text color tags.
88
+ ```typescript
89
+ import motdParser from '@sfirew/minecraft-motd-parser'
90
+ import { cleanTags } from '@sfirew/minecraft-motd-parser'
91
+
92
+ const motdText = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE";
93
+ const result = cleanTags(motdText);
94
+ console.log(result);
95
+
96
+ /* result, callback Text:
97
+ * Hypixel Network 1.8/1.9/1.10/1.11/1.12 NEW PTL GAME: THE BRIDGE
98
+ */
99
+ ```
100
+
101
+
102
+ ### `autoToHtml(string | object)`
103
+ auto check MOTD data type then return same html result.
104
+
105
+ ```typescript
106
+ import motdParser from '@sfirew/minecraft-motd-parser'
107
+
108
+ let jsonExample = {
109
+ "extra": [
110
+ {
111
+ "bold": true,
112
+ "color": "gold",
113
+ "text": "Viper "
114
+ },
115
+ {
116
+ "color": "gray",
117
+ "text": "┃ "
118
+ },
119
+ {
120
+ "color": "yellow",
121
+ "text": "Summer Sale"
122
+ },
123
+ {
124
+ "color": "white",
125
+ "text": " at "
126
+ },
127
+ {
128
+ "color": "gold",
129
+ "text": "store.vipermc.net\n"
130
+ },
131
+ {
132
+ "color": "gray",
133
+ "text": "► "
134
+ },
135
+ {
136
+ "color": "yellow",
137
+ "text": "EOTW "
138
+ },
139
+ {
140
+ "color": "white",
141
+ "text": "on "
142
+ },
143
+ {
144
+ "color": "gold",
145
+ "text": "Infernal"
146
+ },
147
+ {
148
+ "color": "white",
149
+ "text": " is this Thursday at "
150
+ },
151
+ {
152
+ "color": "yellow",
153
+ "text": "5PM ET"
154
+ },
155
+ {
156
+ "color": "white",
157
+ "text": "."
158
+ }
159
+ ],
160
+ "text": ""
161
+ };
162
+ let autoJsonResult = motdParser.autoToHtml(jsonExample);
163
+ console.log(autoJsonResult);
164
+
165
+ /* auto JSON Result, callback HTML:
166
+ <span style="color: #FFAA00;font-weight: bold;">Viper </span><span style="color: #AAAAAA;">┃ </span><span style="color: #FFFF55;">Summer Sale</span><span style="color: #FFFFFF;"> at </span><span style="color: #FFAA00;">store.vipermc.net<br/></span><span style="color: #AAAAAA;">► </span><span style="color: #FFFF55;">EOTW </span><span style="color: #FFFFFF;">on </span><span style="color: #FFAA00;">Infernal</span><span style="color: #FFFFFF;"> is this Thursday at </span><span style="color: #FFFF55;">5PM ET</span><span style="color: #FFFFFF;">.</span>
167
+ */
168
+
169
+ let textExample = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE";
170
+ let autoTextResult = motdParser.autoToHtml(textExample);
171
+ console.log(autoTextResult);
172
+
173
+ /* auto Text Result, callback HTML:
174
+ <span style="color: #55FF55;">Hypixel Network <span style="color: #AAAAAA;"><span style="color: #FF5555;">1.8/1.9/1.10/1.11/1.12 <span style="color: #FFFF55;"><span style="font-weight: bold;">NEW PTL GAME:<span style="color: acqua;"><span style="font-weight: bold;"> THE BRIDGE</span></span></span></span></span></span></span>
175
+ */
176
+ ```
177
+
178
+
179
+
180
+ ### `textToHTML(string)`
181
+ convert motd text to html.
182
+ ```typescript
183
+ let motdText = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE";
184
+ let result = motdParser.textToHTML(motdText);
185
+ console.log(result);
186
+
187
+ /* result, callback HTML:
188
+ * <span style="color: #55FF55;">Hypixel Network <span style="color: #AAAAAA;"><span style="color: #FF5555;">1.8/1.9/1.10/1.11/1.12 <span style="color: #FFFF55;"><span style="font-weight: bold;">NEW PTL GAME:<span style="color: acqua;"><span style="font-weight: bold;"> THE BRIDGE</span></span></span></span></span></span></span>
189
+ */
190
+ ```
191
+
192
+ ![Image_2021_08_2021d-2021h_23___001](https://user-images.githubusercontent.com/14024836/129277576-e94914f3-35f7-45a6-8ba3-58163f71d5a1.png)
193
+
194
+
195
+
196
+
197
+ ### `textToJSON(string)`
198
+ convert motd json to html.
199
+ ```typescript
200
+ let motdText = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE";
201
+ let result = motdParser.textToJSON(motdText);
202
+ console.log(result);
203
+
204
+ /* result, callback JSON:
205
+ {
206
+ text: '',
207
+ extra: [
208
+ { text: '', extra: [] },
209
+ { text: 'Hypixel Network ', extra: [], color: '#55FF55' },
210
+ { text: '', extra: [], color: '#AAAAAA' },
211
+ { text: '1.8/1.9/1.10/1.11/1.12 ', extra: [], color: '#FF5555' },
212
+ { text: '', extra: [], color: '#FFFF55' },
213
+ { text: 'NEW PTL GAME:', extra: [], bold: true, color: '#FFFF55' },
214
+ { text: '', extra: [], bold: true, color: '#55FFFF' },
215
+ { text: ' THE BRIDGE', extra: [], bold: true, color: '#55FFFF' }
216
+ ]
217
+ }
218
+ */
219
+ ```
220
+
221
+
222
+ ### `JSONToHtml(object)`
223
+ convert text to motd json.
224
+ ```typescript
225
+ let mcfalloutJson = {
226
+ "extra": [
227
+ {
228
+ "color": "gray",
229
+ "text": " "
230
+ },
231
+ {
232
+ "color": "gold",
233
+ "text": "廢土伺服器 "
234
+ },
235
+ {
236
+ "color": "white",
237
+ "text": "mcFallout.net"
238
+ },
239
+ {
240
+ "color": "dark_gray",
241
+ "text": " - "
242
+ },
243
+ {
244
+ "color": "gray",
245
+ "text": "版本 1.17.1 "
246
+ },
247
+ {
248
+ "color": "gold",
249
+ "text": "洞穴"
250
+ },
251
+ {
252
+ "color": "light_purple",
253
+ "text": "與"
254
+ },
255
+ {
256
+ "color": "aqua",
257
+ "text": "山崖\n"
258
+ },
259
+ {
260
+ "color": "gray",
261
+ "text": " "
262
+ },
263
+ {
264
+ "color": "dark_gray",
265
+ "text": "享受工廠、農場、建築與紅石"
266
+ }
267
+ ],
268
+ "text": ""
269
+ }
270
+ let result = motdParser.JSONToHtml(mcfalloutJson);
271
+ console.log(result)
272
+
273
+ /* result, callback HTML:
274
+ <span style="color: #AAAAAA;">  </span><span style="color: #FFAA00;">廢土伺服器  </span><span style="color: #FFFFFF;">mcFallout.net</span><span style="color: #555555;"> - </span><span style="color: #AAAAAA;">版本 1.17.1 </span><span style="color: #FFAA00;">洞穴</span><span style="color: #FF55FF;">與</span><span style="color: #55FFFF;">山崖<br/></span><span style="color: #AAAAAA;">  </span><span style="color: #555555;">享受工廠、農場、建築與紅石</span>
275
+ */
276
+ ```
277
+
278
+ ![Image_2021_08_2021d-2021h_24___001](https://user-images.githubusercontent.com/14024836/129277638-fe8c5735-54fe-4ff1-afc5-4b5493706be9.png)
279
+
280
+
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var F=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var A=(t,e,o)=>e in t?F(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,g=(t,e)=>{for(var o in e||(e={}))h.call(e,o)&&A(t,o,e[o]);if(m)for(var o of m(e))N.call(e,o)&&A(t,o,e[o]);return t};var R=(t,e)=>{for(var o in e)F(t,o,{get:e[o],enumerable:!0})},J=(t,e,o,f)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of E(e))!h.call(t,i)&&i!==o&&F(t,i,{get:()=>e[i],enumerable:!(f=H(e,i))||f.enumerable});return t};var M=t=>J(F({},"__esModule",{value:!0}),t);var B={};R(B,{JSONToHtml:()=>X,autoToHtml:()=>v,cleanTags:()=>K,default:()=>z,jsonRender:()=>P,motdParser:()=>p,textToHTML:()=>q,textToJSON:()=>G});module.exports=M(B);function b(t){return!!t}var O=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/\n/g,"<br/>");var S={"\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;"},w={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;"},j={"\xA7k":"obfuscated","\xA7l":"bold","\xA7m":"strikethrough","\xA7n":"underlined","\xA7o":"italic","\xA7r":""},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"},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 C(t){let e=/(?:§)([0-9a-fA-FklmnorFKLMNOR])/g,o="";return o=t.replace(e,""),o}function y(t){let e=t,o=/([§][0-9a-fA-FklmnorFKLMNOR])/g,f=new RegExp(o.source),i=e.split(f),r="",n="",a="";return i.forEach(s=>{let l=s.toLowerCase();if(Object.hasOwn(d,l))n=d[l];else if(Object.hasOwn(S,l))r=S[l];else{let c="",x=s;n!==""&&(c=`color:${n};`),x!==""&&(x=O(x),c.length!==0||r.length!==0?a+=`<span style="${c}${r}">${x}</span>`:a+=x)}}),a}function k(t){let e=t,o=/([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g,f=new RegExp(o.source),i=e.split(f),r="",n="",a={text:"",extra:[]};i.forEach(l=>{let c=l.toLowerCase();if(Object.hasOwn(d,c))n=d[c];else if(Object.hasOwn(j,c))r=j[c];else{let x={text:"",extra:[]};r!==""&&(x[r]=!0),x.text=l,n!==""&&(x.color=n),typeof a.extra=="object"&&a.extra.push(x)}});let s=[];return a.extra&&(a.extra.length>1?a.extra.forEach((l,c)=>{l.text===""?a.extra&&typeof a.extra[c+1]=="object"&&s.push(g(g({},l),a.extra[c+1])):l.text!==(s[s.length-1]&&s[s.length-1].text)&&s.push(l)}):s.push(a.extra[0])),s=s.filter(l=>l.text!==""),{text:a.text,extra:s}}function T(t){let e="",o="",f="";for(let r of Object.keys(t)){if(r=r.toLowerCase(),Object.hasOwn(w,r)&&t[r]&&(f+=`${w[r]}`),r==="color"){let n=t[r];if(typeof n=="string")if(Object.hasOwn(L,n)){o=`color:${L[n]};`;continue}else if(Object.hasOwn(d,n)){o=`color:${d[n]};`;continue}else{o=`color:${n};`;continue}}if(r==="extra"&&typeof t.extra=="object"){t.text!==void 0&&(typeof t.text=="string"||typeof t.text=="number")&&(e+=y(String(t.text)));for(let n of t.extra)b(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+=y(String(r)))}let i="";return f.length!==0||o.length!==0?i=`<span style="${o+f}">${e}</span>`:i=e,i}function u(t){return T(JSON.parse(JSON.stringify(t)))}function $(t){return typeof t=="object"?u(t):typeof t=="string"?u(k(t)):"unknown motd data type"}var _={cleanTags:C,textToHTML:y,textToJSON:k,JSONToHtml:T,jsonRender:u,autoToHtml:$},p=_;var K=p.cleanTags,q=p.textToHTML,G=p.textToJSON,X=p.JSONToHtml,P=p.jsonRender,v=p.autoToHtml,z=p;0&&(module.exports={JSONToHtml,autoToHtml,cleanTags,jsonRender,motdParser,textToHTML,textToJSON});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/motdParser.ts"],"sourcesContent":["import motdParser from \"./motdParser\";\n\nexport { motdParser };\nexport const cleanTags = motdParser.cleanTags;\nexport const textToHTML = motdParser.textToHTML;\nexport const textToJSON = motdParser.textToJSON;\nexport const JSONToHtml = motdParser.JSONToHtml;\nexport const jsonRender = motdParser.jsonRender;\nexport const autoToHtml = motdParser.autoToHtml;\n\nexport default motdParser;\n","/*\n * minecraft motd parser\n * (c) 2023 Kevin Zheng\n * Released under the MIT license\n */\n\nimport { motdJsonType } from \"./types\";\n\n// 類型檢查\nexport function isMotdJSONType(object: object): object is motdJsonType {\n return !!object;\n}\n\n/**\n *\n * #### replace all html tags to &...\n */\nexport const htmlStringFormatting = (text: string): string => {\n return (\n text\n // space\n // .replace(/ /g, \"\\u00a0\")\n //\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#39;\")\n // return\n .replace(/\\n/g, \"<br/>\")\n );\n // .replace(/\\//g, '&#x2F;');\n};\n","/*\n * minecraft motd parser\n * (c) 2023 Kevin Zheng\n * Released under the MIT license\n */\n\nimport { extraLibraryType, motdJsonType } from \"./types\";\nimport { isMotdJSONType, htmlStringFormatting } from \"./utils\";\n\n\n\n// color code to font styles\nconst extras: extraLibraryType = {\n \"§k\": \"obfuscated;\",\n \"§l\": \"font-weight: bold;\",\n \"§m\": \"text-decoration: line-through;\",\n \"§n\": \"text-decoration: underline;\",\n \"§o\": \"font-style: italic;\",\n \"§r\": \"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;\",\n};\n\n// json extra font styles\nconst extraFontStyles: extraLibraryType = {\n bold: \"font-weight: bold;\",\n italic: \"font-style: italic;\",\n underlined: \"text-decoration:underline;\",\n strikethrough: \"text-decoration: line-through;\",\n obfuscated: \"mc_obfuscated;\",\n reset: \"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;\",\n};\n\n// text to json extra name\nconst textToJsonExtras: extraLibraryType = {\n \"§k\": \"obfuscated\",\n \"§l\": \"bold\",\n \"§m\": \"strikethrough\",\n \"§n\": \"underlined\",\n \"§o\": \"italic\",\n \"§r\": \"\",\n};\n\n// base color hex\nconst colorCodeToHex: extraLibraryType = {\n \"§0\": \"#000000\",\n \"§1\": \"#0000AA\",\n \"§2\": \"#00AA00\",\n \"§3\": \"#00AAAA\",\n \"§4\": \"#AA0000\",\n \"§5\": \"#AA00AA\",\n \"§6\": \"#FFAA00\",\n \"§7\": \"#AAAAAA\",\n \"§8\": \"#555555\",\n \"§9\": \"#5555FF\",\n \"§a\": \"#55FF55\",\n \"§b\": \"#55FFFF\",\n \"§c\": \"#FF5555\",\n \"§d\": \"#FF55FF\",\n \"§e\": \"#FFFF55\",\n \"§f\": \"#FFFFFF\",\n};\n\n// json extra to hex color\nconst extraColorsToHex: extraLibraryType = {\n black: \"#000000\",\n dark_blue: \"#0000AA\",\n dark_green: \"#00AA00\",\n dark_aqua: \"#00AAAA\",\n dark_red: \"#AA0000\",\n dark_purple: \"#AA00AA\",\n gold: \"#FFAA00\",\n gray: \"#AAAAAA\",\n dark_gray: \"#555555\",\n blue: \"#5555FF\",\n green: \"#55FF55\",\n aqua: \"#55FFFF\",\n red: \"#FF5555\",\n light_purple: \"#FF55FF\",\n yellow: \"#FFFF55\",\n white: \"#FFFFFF\",\n};\n\n\n\n// clean tags\n/**\n * #### `cleanTags(string)`\n * Clean all tags from motd source string.\n */\nfunction cleanTags(text: string) {\n const REGEX = /(?:§)([0-9a-fA-FklmnorFKLMNOR])/g;\n let textResult = \"\";\n\n textResult = text.replace(REGEX, \"\");\n\n return textResult;\n}\n\n// text to html\n/**\n * #### `textToHTML(string)`\n * Convert motd text to html.\n */\nfunction textToHTML(motdString: string) {\n const motdText = motdString;\n\n const colorCodeReg = /([§][0-9a-fA-FklmnorFKLMNOR])/g;\n const codeREGEX = new RegExp(colorCodeReg.source);\n const codeSplit = motdText.split(codeREGEX);\n\n let fontStyle = \"\";\n let colorHex = \"\";\n let resultHTML = \"\";\n\n codeSplit.forEach((item) => {\n const motdStringToLowerCase = item.toLowerCase();\n\n // 過濾 hex\n if (Object.hasOwn(colorCodeToHex, motdStringToLowerCase)) {\n //console.log(`偵測出 ${ colorCodeToHex[item] }`)\n colorHex = colorCodeToHex[motdStringToLowerCase];\n\n // 過濾文字 style\n } else if (Object.hasOwn(extras, motdStringToLowerCase)) {\n // font style code 轉換\n //console.log(`偵測出 style ${ extras[item] }`)\n fontStyle = extras[motdStringToLowerCase];\n //console.log('textFont: ' + fontStyle)\n // 正常文字\n } else {\n let resultColor = \"\";\n let textContent = item;\n //console.log(fontStyle)\n\n // 檢查 Hex color\n if (colorHex !== \"\") {\n resultColor = `color:${colorHex};`;\n }\n\n if (textContent !== \"\") {\n //console.log('font: ' + fontStyle)\n //console.log('color: ' + colorHex)\n //console.log('text: ' + item)\n //console.log('---------------------------------')\n // replace html tags\n textContent = htmlStringFormatting(textContent);\n\n if (resultColor.length !== 0 || fontStyle.length !== 0) {\n resultHTML += `<span style=\"${resultColor}${fontStyle}\">${textContent}</span>`;\n } else {\n resultHTML += textContent;\n }\n }\n }\n });\n\n return resultHTML;\n}\n\n// text to json\n/**\n * #### `textToJSON(string)`\n * Convert motd text to JSON.\n */\nfunction parseTextToJSON(text: string) {\n const motdText = text;\n\n // color code regex: /([§][0-9a-fklmnor])/g\n // color hex regex: /^#(?:[0-9a-f]{3}){1,2}$/g\n const colorCodeReg = /([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g;\n const codeREGEX = new RegExp(colorCodeReg.source);\n const textSplit = motdText.split(codeREGEX);\n let fontStyle = \"\";\n let colorHex = \"\";\n\n const resultObject: motdJsonType = {\n text: \"\",\n extra: [],\n };\n\n // console.log('textSplit', textSplit);\n textSplit.forEach((item) => {\n const stringToLowerCase = item.toLowerCase();\n\n // color code 轉換成 hex\n if (Object.hasOwn(colorCodeToHex, stringToLowerCase)) {\n //console.log(`偵測出 ${ colorCodeToHex[item] }`)\n colorHex = colorCodeToHex[stringToLowerCase];\n } else if (Object.hasOwn(textToJsonExtras, stringToLowerCase)) {\n // font style code 轉換\n //console.log(`偵測出 style ${ textToJsonExtras[item] }`)\n fontStyle = textToJsonExtras[stringToLowerCase];\n } else {\n const innerObject: motdJsonType = {\n text: \"\",\n extra: [],\n };\n\n // 其餘字串\n if (fontStyle !== \"\") {\n innerObject[fontStyle] = true;\n }\n\n innerObject.text = item;\n\n if (colorHex !== \"\") {\n innerObject.color = colorHex;\n }\n\n if (typeof resultObject.extra === \"object\") {\n resultObject.extra.push(innerObject);\n }\n }\n });\n\n // console.log('resultObject', resultObject);\n\n // code styles merge\n let newExtra: Array<motdJsonType> = [];\n // console.log('resultObject', resultObject);\n if (resultObject.extra) {\n if (resultObject.extra.length > 1) {\n // if text is '', remove it and merge to next array\n resultObject.extra.forEach((item, index) => {\n // console.log('item', item);\n if (item.text === \"\") {\n if (\n resultObject.extra\n && typeof resultObject.extra[index + 1] === \"object\"\n ) {\n newExtra.push({\n ...(item as motdJsonType),\n ...resultObject.extra[index + 1],\n });\n }\n } else {\n if (\n item.text !== (newExtra[newExtra.length - 1]\n && newExtra[newExtra.length - 1].text)\n ) {\n newExtra.push(item as motdJsonType);\n }\n }\n });\n } else {\n newExtra.push(resultObject.extra[0] as motdJsonType);\n }\n }\n\n // console.log('newExtra', newExtra);\n // remove blank content\n newExtra = newExtra.filter((item) => item.text !== \"\");\n // console.log('newExtra', newExtra);\n\n return {\n text: resultObject.text,\n extra: newExtra,\n };\n}\n\n// json convert to html\n/**\n * #### `JSONToString(string)`\n * Convert JSON to HTML.\n */\nfunction parseJSONToHTML(\n sourceJson: motdJsonType,\n) {\n let htmlElement = \"\";\n let colorHex = \"\";\n let fontStyle = \"\";\n\n // console.log('sourceJson', sourceJson);\n // console.log('---------');\n\n for (let key of Object.keys(sourceJson)) {\n // console.log('sourceJson key', key);\n key = key.toLowerCase();\n\n // text styles\n if (Object.hasOwn(extraFontStyles, key)) {\n if (sourceJson[key]) {\n fontStyle += `${extraFontStyles[key]}`;\n }\n }\n\n // ---------- old text process ----------\n // if (key === \"text\") {\n // if (\n // typeof sourceJson.text === \"string\" ||\n // typeof sourceJson.text === \"number\"\n // ) {\n // // convert all type to string\n // htmlElement += textToHTML(String(sourceJson.text));\n // }\n // }\n\n // color\n if (key === \"color\") {\n const colorKey = sourceJson[key];\n\n if (typeof colorKey === \"string\") {\n // Hex color\n if (Object.hasOwn(extraColorsToHex, colorKey)) {\n colorHex = `color:${extraColorsToHex[colorKey]};`;\n continue;\n // color code\n } else if (Object.hasOwn(colorCodeToHex, colorKey)) {\n colorHex = `color:${colorCodeToHex[colorKey]};`;\n continue;\n // custom color\n } else {\n // custom hex color code mode\n colorHex = `color:${colorKey};`;\n continue;\n }\n }\n }\n\n // extra\n if (key === \"extra\" && typeof sourceJson.extra === \"object\") {\n // ---------- with extra text ----------\n if (sourceJson.text !== undefined\n && (typeof sourceJson.text === \"string\" || typeof sourceJson.text === \"number\")\n ) {\n // content to html\n htmlElement += textToHTML(String(sourceJson.text));\n }\n\n // ---------- foreach extra data and parse ----------\n for (const sourceJsonExtra of sourceJson.extra) {\n // console.log('sourceJsonExtra', sourceJsonExtra);\n if (isMotdJSONType(sourceJsonExtra)) {\n htmlElement += parseJSONToHTML(sourceJsonExtra);\n }\n }\n }\n }\n\n // ---------- without extra text content ----------\n if (sourceJson.extra === undefined && sourceJson.text !== undefined) {\n const currentText = sourceJson.text;\n if (\n typeof sourceJson.text === \"string\" ||\n typeof sourceJson.text === \"number\"\n ) {\n // convert all type to string\n htmlElement += textToHTML(String(currentText));\n }\n }\n\n\n\n let returnHTML = \"\";\n if (fontStyle.length !== 0 || colorHex.length !== 0) {\n returnHTML = `<span style=\"${colorHex + fontStyle}\">${htmlElement}</span>`;\n } else {\n returnHTML = htmlElement;\n }\n\n return returnHTML;\n}\n\n// JSON full convert include newline\nfunction jsonRender(json: motdJsonType | object) {\n return parseJSONToHTML(JSON.parse(JSON.stringify(json)));\n}\n\n/**\n * ### `autoToHtml(object | string)`\n * auto check data type then convert to html.\n */\nfunction autoToHtml(motd: motdJsonType | string | object): string {\n // type check\n if (typeof motd === \"object\") {\n // console.log('process mode: Object mode');\n return jsonRender(motd);\n } else if (typeof motd === \"string\") {\n // console.log('process mode: String mode');\n return jsonRender(parseTextToJSON(motd));\n } else {\n return \"unknown motd data type\";\n }\n}\n\n\n\n/*\n * #### minecraft motd parser\n * * [github](https://github.com/SnowFireWolf/minecraft-motd-parser/tree/main#minecraft-server-motd-parser)\n * * [npm](https://www.npmjs.com/package/@sfirew/mc-motd-parser)\n * (c) 2023 Kevin Zheng\n *\n * Released under the MIT license\n */\nconst defaultModules = {\n // delete all tags\n cleanTags,\n // text convert to HTML\n textToHTML,\n // text convert to JSON\n textToJSON: parseTextToJSON,\n // JSON convert to HTML\n JSONToHtml: parseJSONToHTML,\n // JSON full convert HTML (include enter)\n jsonRender,\n // auto check type to convert\n autoToHtml,\n};\n\nexport default defaultModules;\n"],"mappings":"4rBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,eAAAC,EAAA,cAAAC,EAAA,YAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,eAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAV,GCSO,SAASW,EAAeC,EAAwC,CACrE,MAAO,CAAC,CAACA,CACX,CAMO,IAAMC,EAAwBC,GAEjCA,EAIG,QAAQ,KAAM,OAAO,EACrB,QAAQ,KAAM,MAAM,EACpB,QAAQ,KAAM,MAAM,EACpB,QAAQ,KAAM,QAAQ,EACtB,QAAQ,KAAM,OAAO,EAErB,QAAQ,MAAO,OAAO,ECjB7B,IAAMC,EAA2B,CAC/B,QAAM,cACN,QAAM,qBACN,QAAM,iCACN,QAAM,8BACN,QAAM,sBACN,QAAM,4GACR,EAGMC,EAAoC,CACxC,KAAM,qBACN,OAAQ,sBACR,WAAY,6BACZ,cAAe,iCACf,WAAY,iBACZ,MAAO,4GACT,EAGMC,EAAqC,CACzC,QAAM,aACN,QAAM,OACN,QAAM,gBACN,QAAM,aACN,QAAM,SACN,QAAM,EACR,EAGMC,EAAmC,CACvC,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,SACR,EAGMC,EAAqC,CACzC,MAAO,UACP,UAAW,UACX,WAAY,UACZ,UAAW,UACX,SAAU,UACV,YAAa,UACb,KAAM,UACN,KAAM,UACN,UAAW,UACX,KAAM,UACN,MAAO,UACP,KAAM,UACN,IAAK,UACL,aAAc,UACd,OAAQ,UACR,MAAO,SACT,EASA,SAASC,EAAUC,EAAc,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,OAAOA,EAAW,MAAS,YAGtEC,GAAexB,EAAW,OAAOuB,EAAW,IAAI,CAAC,GAInD,QAAWI,KAAmBJ,EAAW,MAEnCK,EAAeD,CAAe,IAChCH,GAAeF,EAAgBK,CAAe,EAGpD,CACF,CAGA,GAAIJ,EAAW,QAAU,QAAaA,EAAW,OAAS,OAAW,CACnE,IAAMM,EAAcN,EAAW,MAE7B,OAAOA,EAAW,MAAS,UAC3B,OAAOA,EAAW,MAAS,YAG3BC,GAAexB,EAAW,OAAO6B,CAAW,CAAC,EAEjD,CAIA,IAAIC,EAAa,GACjB,OAAIxB,EAAU,SAAW,GAAKC,EAAS,SAAW,EAChDuB,EAAa,gBAAgBvB,EAAWD,MAAckB,WAEtDM,EAAaN,EAGRM,CACT,CAGA,SAASC,EAAWC,EAA6B,CAC/C,OAAOV,EAAgB,KAAK,MAAM,KAAK,UAAUU,CAAI,CAAC,CAAC,CACzD,CAMA,SAASC,EAAWC,EAA8C,CAEhE,OAAI,OAAOA,GAAS,SAEXH,EAAWG,CAAI,EACb,OAAOA,GAAS,SAElBH,EAAWjB,EAAgBoB,CAAI,CAAC,EAEhC,wBAEX,CAYA,IAAMC,EAAiB,CAErB,UAAAvC,EAEA,WAAAI,EAEA,WAAYc,EAEZ,WAAYQ,EAEZ,WAAAS,EAEA,WAAAE,CACF,EAEOG,EAAQD,EFtZR,IAAME,EAAYC,EAAW,UACvBC,EAAaD,EAAW,WACxBE,EAAaF,EAAW,WACxBG,EAAaH,EAAW,WACxBI,EAAaJ,EAAW,WACxBK,EAAaL,EAAW,WAE9BM,EAAQN","names":["src_exports","__export","JSONToHtml","autoToHtml","cleanTags","src_default","jsonRender","motdParser_default","textToHTML","textToJSON","__toCommonJS","isMotdJSONType","object","htmlStringFormatting","text","extras","extraFontStyles","textToJsonExtras","colorCodeToHex","extraColorsToHex","cleanTags","text","REGEX","textResult","textToHTML","motdString","motdText","colorCodeReg","codeREGEX","codeSplit","fontStyle","colorHex","resultHTML","item","motdStringToLowerCase","resultColor","textContent","htmlStringFormatting","parseTextToJSON","textSplit","resultObject","stringToLowerCase","innerObject","newExtra","index","__spreadValues","parseJSONToHTML","sourceJson","htmlElement","key","colorKey","sourceJsonExtra","isMotdJSONType","currentText","returnHTML","jsonRender","json","autoToHtml","motd","defaultModules","motdParser_default","cleanTags","motdParser_default","textToHTML","textToJSON","JSONToHtml","jsonRender","autoToHtml","src_default"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ var L=Object.defineProperty;var T=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var m=(t,o,e)=>o in t?L(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,F=(t,o)=>{for(var e in o||(o={}))k.call(o,e)&&m(t,e,o[e]);if(T)for(var e of T(o))H.call(o,e)&&m(t,e,o[e]);return t};function A(t){return!!t}var h=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/\n/g,"<br/>");var b={"\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":""},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"},w={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 E(t){let o=/(?:§)([0-9a-fA-FklmnorFKLMNOR])/g,e="";return e=t.replace(o,""),e}function g(t){let o=t,e=/([§][0-9a-fA-FklmnorFKLMNOR])/g,x=new RegExp(e.source),p=o.split(x),r="",n="",a="";return p.forEach(i=>{let l=i.toLowerCase();if(Object.hasOwn(d,l))n=d[l];else if(Object.hasOwn(b,l))r=b[l];else{let s="",c=i;n!==""&&(s=`color:${n};`),c!==""&&(c=h(c),s.length!==0||r.length!==0?a+=`<span style="${s}${r}">${c}</span>`:a+=c)}}),a}function j(t){let o=t,e=/([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g,x=new RegExp(e.source),p=o.split(x),r="",n="",a={text:"",extra:[]};p.forEach(l=>{let s=l.toLowerCase();if(Object.hasOwn(d,s))n=d[s];else if(Object.hasOwn(S,s))r=S[s];else{let c={text:"",extra:[]};r!==""&&(c[r]=!0),c.text=l,n!==""&&(c.color=n),typeof a.extra=="object"&&a.extra.push(c)}});let i=[];return a.extra&&(a.extra.length>1?a.extra.forEach((l,s)=>{l.text===""?a.extra&&typeof a.extra[s+1]=="object"&&i.push(F(F({},l),a.extra[s+1])):l.text!==(i[i.length-1]&&i[i.length-1].text)&&i.push(l)}):i.push(a.extra[0])),i=i.filter(l=>l.text!==""),{text:a.text,extra:i}}function u(t){let o="",e="",x="";for(let r of Object.keys(t)){if(r=r.toLowerCase(),Object.hasOwn(O,r)&&t[r]&&(x+=`${O[r]}`),r==="color"){let n=t[r];if(typeof n=="string")if(Object.hasOwn(w,n)){e=`color:${w[n]};`;continue}else if(Object.hasOwn(d,n)){e=`color:${d[n]};`;continue}else{e=`color:${n};`;continue}}if(r==="extra"&&typeof t.extra=="object"){t.text!==void 0&&(typeof t.text=="string"||typeof t.text=="number")&&(o+=g(String(t.text)));for(let n of t.extra)A(n)&&(o+=u(n))}}if(t.extra===void 0&&t.text!==void 0){let r=t.text;(typeof t.text=="string"||typeof t.text=="number")&&(o+=g(String(r)))}let p="";return x.length!==0||e.length!==0?p=`<span style="${e+x}">${o}</span>`:p=o,p}function y(t){return u(JSON.parse(JSON.stringify(t)))}function N(t){return typeof t=="object"?y(t):typeof t=="string"?y(j(t)):"unknown motd data type"}var R={cleanTags:E,textToHTML:g,textToJSON:j,JSONToHtml:u,jsonRender:y,autoToHtml:N},f=R;var q=f.cleanTags,G=f.textToHTML,X=f.textToJSON,P=f.JSONToHtml,v=f.jsonRender,z=f.autoToHtml,B=f;export{P as JSONToHtml,z as autoToHtml,q as cleanTags,B as default,v as jsonRender,f as motdParser,G as textToHTML,X as textToJSON};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/motdParser.ts","../src/index.ts"],"sourcesContent":["/*\n * minecraft motd parser\n * (c) 2023 Kevin Zheng\n * Released under the MIT license\n */\n\nimport { motdJsonType } from \"./types\";\n\n// 類型檢查\nexport function isMotdJSONType(object: object): object is motdJsonType {\n return !!object;\n}\n\n/**\n *\n * #### replace all html tags to &...\n */\nexport const htmlStringFormatting = (text: string): string => {\n return (\n text\n // space\n // .replace(/ /g, \"\\u00a0\")\n //\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#39;\")\n // return\n .replace(/\\n/g, \"<br/>\")\n );\n // .replace(/\\//g, '&#x2F;');\n};\n","/*\n * minecraft motd parser\n * (c) 2023 Kevin Zheng\n * Released under the MIT license\n */\n\nimport { extraLibraryType, motdJsonType } from \"./types\";\nimport { isMotdJSONType, htmlStringFormatting } from \"./utils\";\n\n\n\n// color code to font styles\nconst extras: extraLibraryType = {\n \"§k\": \"obfuscated;\",\n \"§l\": \"font-weight: bold;\",\n \"§m\": \"text-decoration: line-through;\",\n \"§n\": \"text-decoration: underline;\",\n \"§o\": \"font-style: italic;\",\n \"§r\": \"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;\",\n};\n\n// json extra font styles\nconst extraFontStyles: extraLibraryType = {\n bold: \"font-weight: bold;\",\n italic: \"font-style: italic;\",\n underlined: \"text-decoration:underline;\",\n strikethrough: \"text-decoration: line-through;\",\n obfuscated: \"mc_obfuscated;\",\n reset: \"color: inherit;text-decoration: none !important;font-weight:normal!important;font-style: normal!important;\",\n};\n\n// text to json extra name\nconst textToJsonExtras: extraLibraryType = {\n \"§k\": \"obfuscated\",\n \"§l\": \"bold\",\n \"§m\": \"strikethrough\",\n \"§n\": \"underlined\",\n \"§o\": \"italic\",\n \"§r\": \"\",\n};\n\n// base color hex\nconst colorCodeToHex: extraLibraryType = {\n \"§0\": \"#000000\",\n \"§1\": \"#0000AA\",\n \"§2\": \"#00AA00\",\n \"§3\": \"#00AAAA\",\n \"§4\": \"#AA0000\",\n \"§5\": \"#AA00AA\",\n \"§6\": \"#FFAA00\",\n \"§7\": \"#AAAAAA\",\n \"§8\": \"#555555\",\n \"§9\": \"#5555FF\",\n \"§a\": \"#55FF55\",\n \"§b\": \"#55FFFF\",\n \"§c\": \"#FF5555\",\n \"§d\": \"#FF55FF\",\n \"§e\": \"#FFFF55\",\n \"§f\": \"#FFFFFF\",\n};\n\n// json extra to hex color\nconst extraColorsToHex: extraLibraryType = {\n black: \"#000000\",\n dark_blue: \"#0000AA\",\n dark_green: \"#00AA00\",\n dark_aqua: \"#00AAAA\",\n dark_red: \"#AA0000\",\n dark_purple: \"#AA00AA\",\n gold: \"#FFAA00\",\n gray: \"#AAAAAA\",\n dark_gray: \"#555555\",\n blue: \"#5555FF\",\n green: \"#55FF55\",\n aqua: \"#55FFFF\",\n red: \"#FF5555\",\n light_purple: \"#FF55FF\",\n yellow: \"#FFFF55\",\n white: \"#FFFFFF\",\n};\n\n\n\n// clean tags\n/**\n * #### `cleanTags(string)`\n * Clean all tags from motd source string.\n */\nfunction cleanTags(text: string) {\n const REGEX = /(?:§)([0-9a-fA-FklmnorFKLMNOR])/g;\n let textResult = \"\";\n\n textResult = text.replace(REGEX, \"\");\n\n return textResult;\n}\n\n// text to html\n/**\n * #### `textToHTML(string)`\n * Convert motd text to html.\n */\nfunction textToHTML(motdString: string) {\n const motdText = motdString;\n\n const colorCodeReg = /([§][0-9a-fA-FklmnorFKLMNOR])/g;\n const codeREGEX = new RegExp(colorCodeReg.source);\n const codeSplit = motdText.split(codeREGEX);\n\n let fontStyle = \"\";\n let colorHex = \"\";\n let resultHTML = \"\";\n\n codeSplit.forEach((item) => {\n const motdStringToLowerCase = item.toLowerCase();\n\n // 過濾 hex\n if (Object.hasOwn(colorCodeToHex, motdStringToLowerCase)) {\n //console.log(`偵測出 ${ colorCodeToHex[item] }`)\n colorHex = colorCodeToHex[motdStringToLowerCase];\n\n // 過濾文字 style\n } else if (Object.hasOwn(extras, motdStringToLowerCase)) {\n // font style code 轉換\n //console.log(`偵測出 style ${ extras[item] }`)\n fontStyle = extras[motdStringToLowerCase];\n //console.log('textFont: ' + fontStyle)\n // 正常文字\n } else {\n let resultColor = \"\";\n let textContent = item;\n //console.log(fontStyle)\n\n // 檢查 Hex color\n if (colorHex !== \"\") {\n resultColor = `color:${colorHex};`;\n }\n\n if (textContent !== \"\") {\n //console.log('font: ' + fontStyle)\n //console.log('color: ' + colorHex)\n //console.log('text: ' + item)\n //console.log('---------------------------------')\n // replace html tags\n textContent = htmlStringFormatting(textContent);\n\n if (resultColor.length !== 0 || fontStyle.length !== 0) {\n resultHTML += `<span style=\"${resultColor}${fontStyle}\">${textContent}</span>`;\n } else {\n resultHTML += textContent;\n }\n }\n }\n });\n\n return resultHTML;\n}\n\n// text to json\n/**\n * #### `textToJSON(string)`\n * Convert motd text to JSON.\n */\nfunction parseTextToJSON(text: string) {\n const motdText = text;\n\n // color code regex: /([§][0-9a-fklmnor])/g\n // color hex regex: /^#(?:[0-9a-f]{3}){1,2}$/g\n const colorCodeReg = /([§][0-9a-f0-9a-fA-FklmnorFKLMNOR])/g;\n const codeREGEX = new RegExp(colorCodeReg.source);\n const textSplit = motdText.split(codeREGEX);\n let fontStyle = \"\";\n let colorHex = \"\";\n\n const resultObject: motdJsonType = {\n text: \"\",\n extra: [],\n };\n\n // console.log('textSplit', textSplit);\n textSplit.forEach((item) => {\n const stringToLowerCase = item.toLowerCase();\n\n // color code 轉換成 hex\n if (Object.hasOwn(colorCodeToHex, stringToLowerCase)) {\n //console.log(`偵測出 ${ colorCodeToHex[item] }`)\n colorHex = colorCodeToHex[stringToLowerCase];\n } else if (Object.hasOwn(textToJsonExtras, stringToLowerCase)) {\n // font style code 轉換\n //console.log(`偵測出 style ${ textToJsonExtras[item] }`)\n fontStyle = textToJsonExtras[stringToLowerCase];\n } else {\n const innerObject: motdJsonType = {\n text: \"\",\n extra: [],\n };\n\n // 其餘字串\n if (fontStyle !== \"\") {\n innerObject[fontStyle] = true;\n }\n\n innerObject.text = item;\n\n if (colorHex !== \"\") {\n innerObject.color = colorHex;\n }\n\n if (typeof resultObject.extra === \"object\") {\n resultObject.extra.push(innerObject);\n }\n }\n });\n\n // console.log('resultObject', resultObject);\n\n // code styles merge\n let newExtra: Array<motdJsonType> = [];\n // console.log('resultObject', resultObject);\n if (resultObject.extra) {\n if (resultObject.extra.length > 1) {\n // if text is '', remove it and merge to next array\n resultObject.extra.forEach((item, index) => {\n // console.log('item', item);\n if (item.text === \"\") {\n if (\n resultObject.extra\n && typeof resultObject.extra[index + 1] === \"object\"\n ) {\n newExtra.push({\n ...(item as motdJsonType),\n ...resultObject.extra[index + 1],\n });\n }\n } else {\n if (\n item.text !== (newExtra[newExtra.length - 1]\n && newExtra[newExtra.length - 1].text)\n ) {\n newExtra.push(item as motdJsonType);\n }\n }\n });\n } else {\n newExtra.push(resultObject.extra[0] as motdJsonType);\n }\n }\n\n // console.log('newExtra', newExtra);\n // remove blank content\n newExtra = newExtra.filter((item) => item.text !== \"\");\n // console.log('newExtra', newExtra);\n\n return {\n text: resultObject.text,\n extra: newExtra,\n };\n}\n\n// json convert to html\n/**\n * #### `JSONToString(string)`\n * Convert JSON to HTML.\n */\nfunction parseJSONToHTML(\n sourceJson: motdJsonType,\n) {\n let htmlElement = \"\";\n let colorHex = \"\";\n let fontStyle = \"\";\n\n // console.log('sourceJson', sourceJson);\n // console.log('---------');\n\n for (let key of Object.keys(sourceJson)) {\n // console.log('sourceJson key', key);\n key = key.toLowerCase();\n\n // text styles\n if (Object.hasOwn(extraFontStyles, key)) {\n if (sourceJson[key]) {\n fontStyle += `${extraFontStyles[key]}`;\n }\n }\n\n // ---------- old text process ----------\n // if (key === \"text\") {\n // if (\n // typeof sourceJson.text === \"string\" ||\n // typeof sourceJson.text === \"number\"\n // ) {\n // // convert all type to string\n // htmlElement += textToHTML(String(sourceJson.text));\n // }\n // }\n\n // color\n if (key === \"color\") {\n const colorKey = sourceJson[key];\n\n if (typeof colorKey === \"string\") {\n // Hex color\n if (Object.hasOwn(extraColorsToHex, colorKey)) {\n colorHex = `color:${extraColorsToHex[colorKey]};`;\n continue;\n // color code\n } else if (Object.hasOwn(colorCodeToHex, colorKey)) {\n colorHex = `color:${colorCodeToHex[colorKey]};`;\n continue;\n // custom color\n } else {\n // custom hex color code mode\n colorHex = `color:${colorKey};`;\n continue;\n }\n }\n }\n\n // extra\n if (key === \"extra\" && typeof sourceJson.extra === \"object\") {\n // ---------- with extra text ----------\n if (sourceJson.text !== undefined\n && (typeof sourceJson.text === \"string\" || typeof sourceJson.text === \"number\")\n ) {\n // content to html\n htmlElement += textToHTML(String(sourceJson.text));\n }\n\n // ---------- foreach extra data and parse ----------\n for (const sourceJsonExtra of sourceJson.extra) {\n // console.log('sourceJsonExtra', sourceJsonExtra);\n if (isMotdJSONType(sourceJsonExtra)) {\n htmlElement += parseJSONToHTML(sourceJsonExtra);\n }\n }\n }\n }\n\n // ---------- without extra text content ----------\n if (sourceJson.extra === undefined && sourceJson.text !== undefined) {\n const currentText = sourceJson.text;\n if (\n typeof sourceJson.text === \"string\" ||\n typeof sourceJson.text === \"number\"\n ) {\n // convert all type to string\n htmlElement += textToHTML(String(currentText));\n }\n }\n\n\n\n let returnHTML = \"\";\n if (fontStyle.length !== 0 || colorHex.length !== 0) {\n returnHTML = `<span style=\"${colorHex + fontStyle}\">${htmlElement}</span>`;\n } else {\n returnHTML = htmlElement;\n }\n\n return returnHTML;\n}\n\n// JSON full convert include newline\nfunction jsonRender(json: motdJsonType | object) {\n return parseJSONToHTML(JSON.parse(JSON.stringify(json)));\n}\n\n/**\n * ### `autoToHtml(object | string)`\n * auto check data type then convert to html.\n */\nfunction autoToHtml(motd: motdJsonType | string | object): string {\n // type check\n if (typeof motd === \"object\") {\n // console.log('process mode: Object mode');\n return jsonRender(motd);\n } else if (typeof motd === \"string\") {\n // console.log('process mode: String mode');\n return jsonRender(parseTextToJSON(motd));\n } else {\n return \"unknown motd data type\";\n }\n}\n\n\n\n/*\n * #### minecraft motd parser\n * * [github](https://github.com/SnowFireWolf/minecraft-motd-parser/tree/main#minecraft-server-motd-parser)\n * * [npm](https://www.npmjs.com/package/@sfirew/mc-motd-parser)\n * (c) 2023 Kevin Zheng\n *\n * Released under the MIT license\n */\nconst defaultModules = {\n // delete all tags\n cleanTags,\n // text convert to HTML\n textToHTML,\n // text convert to JSON\n textToJSON: parseTextToJSON,\n // JSON convert to HTML\n JSONToHtml: parseJSONToHTML,\n // JSON full convert HTML (include enter)\n jsonRender,\n // auto check type to convert\n autoToHtml,\n};\n\nexport default defaultModules;\n","import motdParser from \"./motdParser\";\n\nexport { motdParser };\nexport const cleanTags = motdParser.cleanTags;\nexport const textToHTML = motdParser.textToHTML;\nexport const textToJSON = motdParser.textToJSON;\nexport const JSONToHtml = motdParser.JSONToHtml;\nexport const jsonRender = motdParser.jsonRender;\nexport const autoToHtml = motdParser.autoToHtml;\n\nexport default motdParser;\n"],"mappings":"yVASO,SAASA,EAAeC,EAAwC,CACrE,MAAO,CAAC,CAACA,CACX,CAMO,IAAMC,EAAwBC,GAEjCA,EAIG,QAAQ,KAAM,OAAO,EACrB,QAAQ,KAAM,MAAM,EACpB,QAAQ,KAAM,MAAM,EACpB,QAAQ,KAAM,QAAQ,EACtB,QAAQ,KAAM,OAAO,EAErB,QAAQ,MAAO,OAAO,ECjB7B,IAAMC,EAA2B,CAC/B,QAAM,cACN,QAAM,qBACN,QAAM,iCACN,QAAM,8BACN,QAAM,sBACN,QAAM,4GACR,EAGMC,EAAoC,CACxC,KAAM,qBACN,OAAQ,sBACR,WAAY,6BACZ,cAAe,iCACf,WAAY,iBACZ,MAAO,4GACT,EAGMC,EAAqC,CACzC,QAAM,aACN,QAAM,OACN,QAAM,gBACN,QAAM,aACN,QAAM,SACN,QAAM,EACR,EAGMC,EAAmC,CACvC,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,UACN,QAAM,SACR,EAGMC,EAAqC,CACzC,MAAO,UACP,UAAW,UACX,WAAY,UACZ,UAAW,UACX,SAAU,UACV,YAAa,UACb,KAAM,UACN,KAAM,UACN,UAAW,UACX,KAAM,UACN,MAAO,UACP,KAAM,UACN,IAAK,UACL,aAAc,UACd,OAAQ,UACR,MAAO,SACT,EASA,SAASC,EAAUC,EAAc,CAC/B,IAAMC,EAAQ,mCACVC,EAAa,GAEjB,OAAAA,EAAaF,EAAK,QAAQC,EAAO,EAAE,EAE5BC,CACT,CAOA,SAASC,EAAWC,EAAoB,CACtC,IAAMC,EAAWD,EAEXE,EAAe,iCACfC,EAAY,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AIJ,EAAW,QAAU,QAAaA,EAAW,OAAS,OAAW,CACnE,IAAMM,EAAcN,EAAW,MAE7B,OAAOA,EAAW,MAAS,UAC3B,OAAOA,EAAW,MAAS,YAG3BC,GAAexB,EAAW,OAAO6B,CAAW,CAAC,EAEjD,CAIA,IAAIC,EAAa,GACjB,OAAIxB,EAAU,SAAW,GAAKC,EAAS,SAAW,EAChDuB,EAAa,gBAAgBvB,EAAWD,MAAckB,WAEtDM,EAAaN,EAGRM,CACT,CAGA,SAASC,EAAWC,EAA6B,CAC/C,OAAOV,EAAgB,KAAK,MAAM,KAAK,UAAUU,CAAI,CAAC,CAAC,CACzD,CAMA,SAASC,EAAWC,EAA8C,CAEhE,OAAI,OAAOA,GAAS,SAEXH,EAAWG,CAAI,EACb,OAAOA,GAAS,SAElBH,EAAWjB,EAAgBoB,CAAI,CAAC,EAEhC,wBAEX,CAYA,IAAMC,EAAiB,CAErB,UAAAvC,EAEA,WAAAI,EAEA,WAAYc,EAEZ,WAAYQ,EAEZ,WAAAS,EAEA,WAAAE,CACF,EAEOG,EAAQD,ECtZR,IAAME,EAAYC,EAAW,UACvBC,EAAaD,EAAW,WACxBE,EAAaF,EAAW,WACxBG,EAAaH,EAAW,WACxBI,EAAaJ,EAAW,WACxBK,EAAaL,EAAW,WAE9BM,EAAQN","names":["isMotdJSONType","object","htmlStringFormatting","text","extras","extraFontStyles","textToJsonExtras","colorCodeToHex","extraColorsToHex","cleanTags","text","REGEX","textResult","textToHTML","motdString","motdText","colorCodeReg","codeREGEX","codeSplit","fontStyle","colorHex","resultHTML","item","motdStringToLowerCase","resultColor","textContent","htmlStringFormatting","parseTextToJSON","textSplit","resultObject","stringToLowerCase","innerObject","newExtra","index","__spreadValues","parseJSONToHTML","sourceJson","htmlElement","key","colorKey","sourceJsonExtra","isMotdJSONType","currentText","returnHTML","jsonRender","json","autoToHtml","motd","defaultModules","motdParser_default","cleanTags","motdParser_default","textToHTML","textToJSON","JSONToHtml","jsonRender","autoToHtml","src_default"]}
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@sfirew/minecraft-motd-parser",
3
+ "description": "Minecraft Server MOTD Parser, can convert to html, json, text.",
4
+ "version": "1.1.1",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "types/index.d.ts",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "test": "jest",
11
+ "test-self": "ts-node ./src/test.ts",
12
+ "build": "yarn build:dist && yarn build:declarations",
13
+ "build:dist": "tsup --format cjs,esm",
14
+ "build:declarations": "tsc --emitDeclarationOnly --declaration --outDir types",
15
+ "format": "prettier --write \"**/*.+(ts)\""
16
+ },
17
+ "tsup": {
18
+ "entry": [
19
+ "src/index.ts"
20
+ ],
21
+ "splitting": false,
22
+ "sourcemap": true,
23
+ "clean": true,
24
+ "minify": true
25
+ },
26
+ "devDependencies": {
27
+ "@jest/globals": "^29.4.3",
28
+ "@types/node": "^16.6.0",
29
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
30
+ "@typescript-eslint/parser": "^5.41.0",
31
+ "eslint": "^8.26.0",
32
+ "jest": "^29.4.3",
33
+ "prettier": "^2.7.1",
34
+ "ts-jest": "^29.0.5",
35
+ "ts-node": "^10.9.1",
36
+ "tsup": "^6.3.0",
37
+ "typescript": "^4.7.4"
38
+ },
39
+ "repository": "https://github.com/SnowFireWolf/minecraft-motd-parser.git",
40
+ "author": "SnowFireWolf",
41
+ "keywords": [
42
+ "minecraft",
43
+ "java",
44
+ "bedrock",
45
+ "server",
46
+ "motd",
47
+ "color",
48
+ "hex",
49
+ "parser",
50
+ "html",
51
+ "formatting",
52
+ "javascript",
53
+ "typescript"
54
+ ],
55
+ "publishConfig": {
56
+ "@snowfirewolf:registry": "https://npm.pkg.github.com"
57
+ }
58
+ }
@@ -0,0 +1,12 @@
1
+ import motdParser from "./motdParser";
2
+ export { motdParser };
3
+ export declare const cleanTags: (text: string) => string;
4
+ export declare const textToHTML: (motdString: string) => string;
5
+ export declare const textToJSON: (text: string) => {
6
+ text: string | number;
7
+ extra: import("./types").motdJsonType[];
8
+ };
9
+ export declare const JSONToHtml: (sourceJson: import("./types").motdJsonType) => string;
10
+ export declare const jsonRender: (json: object | import("./types").motdJsonType) => string;
11
+ export declare const autoToHtml: (motd: string | object | import("./types").motdJsonType) => string;
12
+ export default motdParser;
@@ -0,0 +1,39 @@
1
+ import { motdJsonType } from "./types";
2
+ /**
3
+ * #### `cleanTags(string)`
4
+ * Clean all tags from motd source string.
5
+ */
6
+ declare function cleanTags(text: string): string;
7
+ /**
8
+ * #### `textToHTML(string)`
9
+ * Convert motd text to html.
10
+ */
11
+ declare function textToHTML(motdString: string): string;
12
+ /**
13
+ * #### `textToJSON(string)`
14
+ * Convert motd text to JSON.
15
+ */
16
+ declare function parseTextToJSON(text: string): {
17
+ text: string | number;
18
+ extra: motdJsonType[];
19
+ };
20
+ /**
21
+ * #### `JSONToString(string)`
22
+ * Convert JSON to HTML.
23
+ */
24
+ declare function parseJSONToHTML(sourceJson: motdJsonType): string;
25
+ declare function jsonRender(json: motdJsonType | object): string;
26
+ /**
27
+ * ### `autoToHtml(object | string)`
28
+ * auto check data type then convert to html.
29
+ */
30
+ declare function autoToHtml(motd: motdJsonType | string | object): string;
31
+ declare const defaultModules: {
32
+ cleanTags: typeof cleanTags;
33
+ textToHTML: typeof textToHTML;
34
+ textToJSON: typeof parseTextToJSON;
35
+ JSONToHtml: typeof parseJSONToHTML;
36
+ jsonRender: typeof jsonRender;
37
+ autoToHtml: typeof autoToHtml;
38
+ };
39
+ export default defaultModules;
@@ -0,0 +1,18 @@
1
+ interface extraLibraryType {
2
+ [key: string]: string;
3
+ }
4
+ interface motdJsonType {
5
+ text: string | number;
6
+ extra?: {
7
+ color?: string;
8
+ text?: string | number;
9
+ bold?: boolean;
10
+ strikethrough?: boolean;
11
+ underlined?: boolean;
12
+ obfuscated?: boolean;
13
+ italic?: boolean;
14
+ extra?: object[];
15
+ }[];
16
+ [key: string]: string | boolean | number | object | Array<object> | undefined;
17
+ }
18
+ export type { extraLibraryType, motdJsonType };
@@ -0,0 +1,7 @@
1
+ import { motdJsonType } from "./types";
2
+ export declare function isMotdJSONType(object: object): object is motdJsonType;
3
+ /**
4
+ *
5
+ * #### replace all html tags to &...
6
+ */
7
+ export declare const htmlStringFormatting: (text: string) => string;