UNPKG

1.35 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const serialize_1 = __importDefault(require("./serialize"));
7const static_1 = require("./static");
8function parse(text, delimiter = "§") {
9 text = (0, serialize_1.default)(text, delimiter);
10 const result = { text: "", extra: [] };
11 let section = result;
12 const chars = text.split("");
13 for (let i = 0; i < chars.length; i++) {
14 if (chars[i] !== "§") {
15 section.text += chars[i];
16 continue;
17 }
18 if (chars[i + 1] === "r") {
19 const innerObj = { text: "", extra: [] };
20 result.extra.push(innerObj);
21 section = innerObj;
22 i++;
23 continue;
24 }
25 const codeStr = ${chars[i + 1]}`;
26 const innerObj = { text: "", extra: [] };
27 if (static_1.Colors.hasOwnProperty(codeStr))
28 innerObj.color = static_1.Colors[codeStr];
29 if (static_1.Formats.hasOwnProperty(codeStr))
30 innerObj[static_1.Formats[codeStr]] = true;
31 section.extra.push(innerObj);
32 section = innerObj;
33 i++;
34 }
35 return result;
36}
37exports.default = parse;
38//# sourceMappingURL=parse.js.map
\No newline at end of file