From c288a7132b20fc798cf452367b7c32745f3c17ce Mon Sep 17 00:00:00 2001 From: SnowFireWolf Date: Wed, 2 Aug 2023 03:03:22 +0800 Subject: [PATCH 1/2] update readme and rename function clean tags to clean codes --- README.md | 14 +++++++------- src/index.ts | 6 +++--- src/utils.ts | 6 +++--- test/main.test.ts | 11 ++++++----- test_self/htmlTest.ts | 6 +++--- test_self/index.ts | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 803a74a..339551e 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # Minecraft Server MOTD Parser ![Version](https://img.shields.io/github/languages/top/SnowFireWolf/minecraft-motd-parser?style=for-the-badge) -[![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) +[![npm version](https://img.shields.io/npm/v/@sfirew/minecraft-motd-parser?label=version&style=for-the-badge)](https://www.npmjs.com/package/@sfirew/minecraft-motd-parser?style=for-the-badge) [![License](https://img.shields.io/npm/l/minecraft-server-util?style=for-the-badge)](https://github.com/SnowFireWolf/minecraft-motd-parser/blob/master/LICENSE) -![npm weekly downloads](https://img.shields.io/npm/dw/@sfirew/mc-motd-parser?style=for-the-badge) +![npm weekly downloads](https://img.shields.io/npm/dw/@sfirew/minecraft-motd-parser?style=for-the-badge) ## Introduction This package support **CommonJS**, **ES Module**, and **tree shaking** -Can convert minecraft server MOTD data to text, json, html, and clean tags. +Can convert minecraft server MOTD data to text, json, html, and clean codes. Support **1.16** custom **hex color**, and auto check motd data type. @@ -83,14 +83,14 @@ You can try server status view in my created service Some examples here, you can use **TypeScript** or **JavaScript**. -### `cleanTags(string)` -clean text color tags. +### `cleanCodes(string)` +clean motd text color codes. ```typescript import motdParser from '@sfirew/minecraft-motd-parser' -import { cleanTags } from '@sfirew/minecraft-motd-parser' +import { cleanCodes } from '@sfirew/minecraft-motd-parser' const motdText = "§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE"; -const result = cleanTags(motdText); +const result = cleanCodes(motdText); console.log(result); /* result, callback Text: diff --git a/src/index.ts b/src/index.ts index 6988876..c4951b8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ */ import { htmlStringFormatting, - cleanTags, + cleanCodes, cleanHtmlTags, } from "./utils"; import { @@ -48,8 +48,8 @@ const motdParser = { // utils htmlStringFormatting, - // clean all motd tags - cleanTags, + // clean all motd codes + cleanCodes, // clean all html tags cleanHtmlTags, }; diff --git a/src/utils.ts b/src/utils.ts index c2b34cf..d5de7f1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -54,13 +54,13 @@ export function cleanHtmlTags(text: string): string { /** - * clean motd tags + * clean motd codes * - * Clean all tags from motd source string. + * Clean all codes from motd source string. * * @param {string} text - motd string include tag § will remove */ -export function cleanTags(text: string) { +export function cleanCodes(text: string) { const REGEX = /(?:§)([0-9a-fA-FklmnorFKLMNOR])/g; let textResult = ""; diff --git a/test/main.test.ts b/test/main.test.ts index 3084bbe..c180b12 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -147,8 +147,9 @@ describe("Minecraft MOTD Parser", () => { describe("autoToHTML", () => { describe("- string to HTML", () => { it("should convert MOTD string to HTML", () => { - const expectedOutput = `FC夢幻峽谷FantasyCanyon
<<------------加入冒險!------------>>`; - const result = motdParser.autoToHtml(testMOTDString); + const expectedOutput = `FC夢幻峽谷FantasyCanyon
<<------------加入冒險!------------>>`; + const result = motdParser.autoToHTML(testMOTDString); + console.log('result', result) expect(result).toEqual(expectedOutput); }); }); @@ -156,16 +157,16 @@ describe("Minecraft MOTD Parser", () => { describe("- object (JSON) to HTML", () => { it("should convert MOTD json to HTML", () => { const expectedOutput = ` DreamCrafter Network -
在這裡 -- 實現你的理想! `; - const result = motdParser.autoToHtml(testMotdJSON); + const result = motdParser.autoToHTML(testMotdJSON); expect(result).toEqual(expectedOutput); }); }); }); - describe("cleanTags", () => { + describe("cleanCodes", () => { it("should clean MOTD color tags", () => { const expectedOutput = "『FC夢幻峽谷』 FantasyCanyon \n <<◎------------加入冒險!------------◎>>"; - expect(motdParser.cleanTags(testMOTDString)).toEqual(expectedOutput); + expect(motdParser.cleanCodes(testMOTDString)).toEqual(expectedOutput); }); }); diff --git a/test_self/htmlTest.ts b/test_self/htmlTest.ts index f630cd2..77a974e 100644 --- a/test_self/htmlTest.ts +++ b/test_self/htmlTest.ts @@ -8,7 +8,7 @@ let start = 0; // clean tags console.log("清除 MOTD Tags HTML"); start = new Date().getTime(); -let cleanedString = motdParser.cleanTags(text); +let cleanedString = motdParser.cleanCodes(text); console.log(cleanedString); console.log(`執行時間: ${new Date().getTime() - start} ms`); @@ -17,7 +17,7 @@ console.log(`執行時間: ${new Date().getTime() - start} ms`); console.log("自動轉成 HTML"); start = new Date().getTime(); -const motdHtml = motdParser.autoToHtml(text); +const motdHtml = motdParser.autoToHTML(text); console.log("-------------------------"); console.log(motdHtml); console.log("-------------------------"); @@ -59,7 +59,7 @@ const mcfalloutSourceMotd = { text: "", }; -const mcfalloutMotdHtml = motdParser.autoToHtml(mcfalloutSourceMotd); +const mcfalloutMotdHtml = motdParser.autoToHTML(mcfalloutSourceMotd); console.log("-------------------------"); console.log(mcfalloutMotdHtml); console.log("-------------------------"); diff --git a/test_self/index.ts b/test_self/index.ts index 7c7f4fa..8d4ccf3 100644 --- a/test_self/index.ts +++ b/test_self/index.ts @@ -56,7 +56,7 @@ let start = 0; console.log("-------------------------------------------------------"); console.log("清除 MOTD Tags HTML"); start = new Date().getTime(); -let cleanedString = motdParser.cleanTags(text); +let cleanedString = motdParser.cleanCodes(text); console.log(cleanedString); console.log(`執行時間: ${new Date().getTime() - start} ms`); From bed92a7bd91f76e2566a6266faea0e216a5a6f0d Mon Sep 17 00:00:00 2001 From: SnowFireWolf Date: Wed, 2 Aug 2023 03:04:33 +0800 Subject: [PATCH 2/2] update --- package.json | 2 +- test_self/index.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9e63027..ef45ff5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@sfirew/minecraft-motd-parser", "description": "Minecraft Server MOTD Parser, can convert to html, json, text.", - "version": "1.1.2", + "version": "1.1.2-1", "main": "dist/index.js", "module": "dist/index.mjs", "types": "types/index.d.ts", diff --git a/test_self/index.ts b/test_self/index.ts index 8d4ccf3..1cb79fe 100644 --- a/test_self/index.ts +++ b/test_self/index.ts @@ -83,8 +83,8 @@ console.log(`執行時間: ${new Date().getTime() - start} ms`); console.log("-------------------------------------------------------"); console.log("JSON 轉成 HTML"); start = new Date().getTime(); -let jsonToHtml = motdParser.JSONToHtml(JSON.parse(json)); -let jsonToHtml2 = motdParser.JSONToHtml(mcfalloutJson); +let jsonToHtml = motdParser.JSONToHTML(JSON.parse(json)); +let jsonToHtml2 = motdParser.JSONToHTML(mcfalloutJson); console.log(jsonToHtml); console.log("-------------------------"); @@ -152,8 +152,8 @@ let jsonExample = { let textExample = "§5§m §6>§7§l§6§l>§6§l[§5§l§oPurple §8§l§oPrison§6§l]§6§l<§6<§5§m §R §7 §5§k§l;;;§r §d§lNEW BLACK-MARKET §5§l» §6§L/BLACKMARKET §5§k§l;;;"; -let autoToHtml = motdParser.autoToHtml(jsonExample); -let TextAutoToHtml = motdParser.autoToHtml(textExample); +let autoToHtml = motdParser.autoToHTML(jsonExample); +let TextAutoToHtml = motdParser.autoToHTML(textExample); console.log("-------------------------------------------------------"); console.log(autoToHtml);