minecraft-text
Version:
Parse Minecraft text into many formats including HTML.
38 lines • 1.35 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const serialize_1 = __importDefault(require("./serialize"));
const static_1 = require("./static");
function parse(text, delimiter = "§") {
text = (0, serialize_1.default)(text, delimiter);
const result = { text: "", extra: [] };
let section = result;
const chars = text.split("");
for (let i = 0; i < chars.length; i++) {
if (chars[i] !== "§") {
section.text += chars[i];
continue;
}
if (chars[i + 1] === "r") {
const innerObj = { text: "", extra: [] };
result.extra.push(innerObj);
section = innerObj;
i++;
continue;
}
const codeStr = `§${chars[i + 1]}`;
const innerObj = { text: "", extra: [] };
if (static_1.Colors.hasOwnProperty(codeStr))
innerObj.color = static_1.Colors[codeStr];
if (static_1.Formats.hasOwnProperty(codeStr))
innerObj[static_1.Formats[codeStr]] = true;
section.extra.push(innerObj);
section = innerObj;
i++;
}
return result;
}
exports.default = parse;
//# sourceMappingURL=parse.js.map
;