Skip to content

Commit

Permalink
Merge pull request #9 from SnowFireWolf/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
SnowFireWolf authored Jul 30, 2022
2 parents 0cfe7eb + 87b0220 commit a795a79
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 144 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.motdParser=void 0;var motdParser_1=require("./motdParser");Object.defineProperty(exports,"motdParser",{enumerable:!0,get:function(){return motdParser_1.motdParser}})
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.motdParser = void 0;
var motdParser_1 = require("./motdParser");
Object.defineProperty(exports, "motdParser", { enumerable: true, get: function () { return motdParser_1.motdParser; } });
2 changes: 1 addition & 1 deletion dist/motdParser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sfirew/mc-motd-parser",
"description": "Minecraft Server MOTD Parser, can convert to html, json, text.",
"version": "1.0.9-3",
"version": "1.0.9-7",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
Expand Down
41 changes: 22 additions & 19 deletions src/motdParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ function parseTextToJSON(text: string) {
}

// console.log('textSplit', textSplit);
// const filterBlank = textSplit.filter(item => (item !== ''));
// console.log('filterBlank', filterBlank);

textSplit.forEach((item) => {
let stringToLowerCase = item.toLowerCase();

Expand Down Expand Up @@ -244,7 +241,11 @@ function parseTextToJSON(text: string) {
newExtra.push({
...item as motdJsonType,
...resultObject.extra[index + 1],
})
});
}
} else {
if (item.text !== (newExtra[newExtra.length - 1] && newExtra[newExtra.length - 1].text)) {
newExtra.push(item as motdJsonType);
}
}
});
Expand Down Expand Up @@ -283,25 +284,27 @@ function parseJSONToHTML(sourceJson: motdJsonType) {
if (extraFontStyles.hasOwnProperty(key)) {
if (sourceJson[key]) {
fontStyle += `${extraFontStyles[key]}`
} else {
if (key === 'bold') {
fontStyle += `font-weight:normal !important;`;
}

} else if (key === 'italic') {
fontStyle += `font-style: normal !important;`;
// else {
// if (key === 'bold') {
// fontStyle += `font-weight:normal !important;`;

} else if (key === 'underline') {
fontStyle += 'text-decoration: none !important;';
// } else if (key === 'italic') {
// fontStyle += `font-style: normal !important;`;

} else if (key === 'strikethrough') {
fontStyle += 'text-decoration: line-through !important;';
// } else if (key === 'underline') {
// fontStyle += 'text-decoration: none !important;';

} else if (key === 'obfuscated') {
fontStyle += ``
} else {
fontStyle = ""
}
}
// } else if (key === 'strikethrough') {
// fontStyle += 'text-decoration: line-through !important;';

// } else if (key === 'obfuscated') {
// fontStyle += ``
// } else {
// fontStyle = ""
// }
// }
continue;
}

Expand Down
295 changes: 173 additions & 122 deletions test/bugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import { motdParser } from '../src';
import type { motdJsonType } from '../src/types';


const testString = ` §aHypixel Network §c[1.8-1.19]
§b§lNEW: DROPPER §7§l| §6§lSUMMER EVENT§7§l+§e§lSALE`;

const testFromCode = `&r&f &r&9&m&l &r&8&m&l[ &r&f &r&6&lMineplex&r&f &r&f&lGames&r&f &r&8&m&l ]&r&9&m&l &r&f
&r&e&lSTATS REVAMP&r &a&l&n testesest
`;
const replacedString = testFromCode.replace(/&/g, '§');
const replacedString = testString.replace(/&/g, '§');
console.log(motdParser.autoToHtml(replacedString));


// const testFromCodeBug = `&r&f &r&9&m&l &r&8&m&l[ &r&f &r&6&lMineplex&r&f &r&f&lGames&r&f &r&8&m&l ]&r&9&m&l &r&f
// &r&e&lSTATS REVAMP&r &a&l&n testesest
// `;
// const replacedString = testFromCodeBug.replace(/&/g, '§');
// console.log(motdParser.autoToHtml(replacedString));






// const testNumberContentFromJson: motdJsonType = {
// "extra":
// [{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"green","text":"life boost: "},
Expand All @@ -20,121 +30,162 @@ console.log(motdParser.autoToHtml(replacedString));



console.log('--------------------------------------------');
const testString = 'Minecraft Server';
console.log(motdParser.autoToHtml(testString));



const testObject: motdJsonType = {
text: '',
extra: [
{
"extra": [
{
"bold": true,
"color": "green",
"text": "╔════════"
},
{
"text": " "
},
{
"color": "#f38ab5",
"extra": [
{
"bold": true,
"text": "The Pink Tree"
},
{
"text": " "
},
{
"bold": true,
"color": "green",
"text": "═══════╗"
}
],
"text": ""
}
],
"text": ""
},
{
"text": "\n"
},
{
"extra": [
{
"bold": true,
"color": "green",
"text": "╚═══════"
},
{
"text": " "
},
{
"bold": true,
"extra": [
{
"color": "#f3801f",
"text": "世"
},
{
"color": "#c4c402",
"text": "界"
},
{
"color": "#7ff30c",
"text": "的"
},
{
"color": "#3bfd3b",
"text": "奥"
},
{
"color": "#0cdf80",
"text": "秘"
},
{
"color": "#02a3c4",
"text": "将"
},
{
"color": "#205cf3",
"text": "由"
},
{
"color": "#5c20fd",
"text": "你"
},
{
"color": "#a302df",
"text": "来"
},
{
"color": "#e00ca3",
"text": "解"
},
{
"color": "#fd3b5c",
"text": "开"
}
],
"text": ""
},
{
"text": " "
},
{
"bold": true,
"color": "green",
"text": "══════╝"
}
],
"text": ""
}
]
}

console.log(motdParser.autoToHtml(testObject));




// console.log('--------------------------------------------');
// const testString = 'Minecraft Server';
// console.log(motdParser.autoToHtml(testString));






// console.log('----------------------------------------');
// const testFromCode = `§e§l§m-------------§r§7§l[ §f§lMC §c§lPGST §7§l]§e§l§m------------§r
// §7Pixelmon §f8.4.2 §8| §e§l造型寶可夢 §8| §e§l懸賞系統 §8| §e§l自製系統 `;
// console.log(motdParser.autoToHtml(testFromCode));
// console.log('----------------------------------------');





// const testFromJSON = {
// "extra": [
// {
// "color": "#808080",
// "text": " "
// },
// {
// "bold": true,
// "italic": false,
// "underlined": false,
// "strikethrough": false,
// "obfuscated": false,
// "extra": [
// {
// "color": "#1991EA",
// "text": "D"
// },
// {
// "color": "#1C93EB",
// "text": "r"
// },
// {
// "color": "#2096EC",
// "text": "e"
// },
// {
// "color": "#2499ED",
// "text": "a"
// },
// {
// "color": "#289CEE",
// "text": "m"
// },
// {
// "color": "#2C9EEF",
// "text": "C"
// },
// {
// "color": "#30A1F0",
// "text": "r"
// },
// {
// "color": "#33A4F1",
// "text": "a"
// },
// {
// "color": "#37A7F2",
// "text": "f"
// },
// {
// "color": "#3BA9F3",
// "text": "t"
// },
// {
// "color": "#3FACF4",
// "text": "e"
// },
// {
// "color": "#43AFF5",
// "text": "r"
// },
// {
// "color": "#47B2F6",
// "text": " "
// },
// {
// "color": "#4BB4F7",
// "text": "N"
// },
// {
// "color": "#4EB7F8",
// "text": "e"
// },
// {
// "color": "#52BAF9",
// "text": "t"
// },
// {
// "color": "#56BDFA",
// "text": "w"
// },
// {
// "color": "#5ABFFB",
// "text": "o"
// },
// {
// "color": "#5EC2FC",
// "text": "r"
// },
// {
// "color": "#62C5FD",
// "text": "k"
// }
// ],
// "text": ""
// },
// {
// "text": " "
// },
// {
// "color": "#1f92ed",
// "text": "- "
// },
// {
// "bold": true,
// "italic": false,
// "underlined": false,
// "strikethrough": false,
// "obfuscated": false,
// "extra": [
// {
// "color": "#66C8FF",
// "text": "築"
// },
// {
// "color": "#52BAF9",
// "text": "夢"
// },
// {
// "color": "#3FACF4",
// "text": "物"
// },
// {
// "color": "#2C9EEF",
// "text": "語"
// }
// ],
// "text": ""
// },
// {
// "text": "\n §f 在這裡 -- 實現你的理想! "
// }
// ],
// "text": ""
// };
// console.log(motdParser.autoToHtml(testFromJSON));

0 comments on commit a795a79

Please sign in to comment.