{"name":"prismarine-chat","version":"1.9.0","description":"Wrapper for a minecraft chat message","main":"index.js","scripts":{"test":"mocha --reporter spec --exit","pretest":"npm run lint","lint":"standard","fix":"standard --fix"},"repository":{"type":"git","url":"git+https://github.com/PrismarineJS/prismarine-chat.git"},"keywords":["prismarine","chat"],"author":{"name":"Romain Beaumont"},"license":"MIT","bugs":{"url":"https://github.com/PrismarineJS/prismarine-chat/issues"},"homepage":"https://github.com/PrismarineJS/prismarine-chat#readme","devDependencies":{"expect":"^29.1.0","mocha":"^10.0.0","prismarine-chat":"file:.","standard":"^17.0.0"},"dependencies":{"mojangson":"^2.0.1","prismarine-item":"^1.10.0","prismarine-nbt":"^2.0.0","prismarine-registry":"^1.4.0"},"types":"./index.d.ts","gitHead":"4f40566e0aee384bfe5023235bbfd3fcd9e41ba7","_id":"prismarine-chat@1.9.0","_nodeVersion":"18.0.0","_npmVersion":"8.6.0","dist":{"integrity":"sha512-HFOrMy+5xfu2LqYTP0X2TUygy+nAupZ+hqeoWbznct0peZOQumL0ko+OIXqaOmouSXtyMfgmYSYtdagk0TMqFw==","shasum":"6e6da66c11ca94a260c7ab2613bfd79b6f15ce74","tarball":"http://registry-npm.ywwl.com/prismarine-chat/download/prismarine-chat-1.9.0.tgz","fileCount":21,"unpackedSize":53243,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC5HgWoKEBHhb7cJpmsPi12Gf9x8pSRt+7Y7rUhKYeoCAiBDan518GBiWMOi+cwDJ/hPQSnliecVFs/1kxNLKxkp5w=="}],"size":15219,"noattachment":false,"key":"/prismarine-chat/-/prismarine-chat-1.9.0.tgz"},"_npmUser":{"name":"rom1504","email":"romain.rom1@gmail.com"},"directories":{},"maintainers":[{"name":"rom1504","email":"romain.rom1@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismarine-chat_1.9.0_1691964977538_0.7162809236301919"},"_hasShrinkwrap":false,"readme":"# prismarine-chat\n[![NPM version](https://img.shields.io/npm/v/prismarine-chat.svg)](http://npmjs.com/package/prismarine-chat)\n[![Build Status](https://github.com/PrismarineJS/prismarine-chat/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-chat/actions?query=workflow%3A%22CI%22)\n[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)\n[![Gitter](https://img.shields.io/badge/chat-on%20gitter-brightgreen.svg)](https://gitter.im/PrismarineJS/general)\n[![Irc](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg)](https://irc.gitter.im/)\n[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-chat)\n\nA parser for a minecraft chat message\n\n\n## Usage\n\n```js\nconst registry = require('prismarine-registry')('1.16')\nconst ChatMessage = require('prismarine-chat')(registry)\n\nconst msg = new ChatMessage({\"text\":\"Example chat mesasge\"})\nconsole.log(msg.toString()) // Example chat message\n\n```\n## API\n\n### ChatMessage(message,[displayWarning])\n* `message` - Can be either text or a minecraft chat JSON object\n* `displayWarning` - Display warnings if true, default to false\n\n#### chat.toString([lang])\n\nFlattens the message in to plain-text\n * `lang` - (optional) - Set a custom lang (defaults to registry.language)\n\n#### chat.toMotd([lang], parent)\n\nConverts to motd format\n * `lang` - (optional) - Set a custom lang (defaults to registry.language)\n * `parent` - Set a custom lang (defaults to mcData.language)\n\n#### chat.getText(idx, [lang])\n\nReturns a text part from the message\n * `idx` - Index of the part\n * `lang` - (optional) - Set a custom lang (defaults to registry.language)\n\n#### chat.toAnsi([lang], [codes])\n\nConverts to ansi format\n * `lang` - (optional) - Set a custom lang (defaults to registry.language)\n * `codes` - (optional) - Specify which ANSI formatting codes should be used for each Minecraft color code\n\n#### chat.toHTML([lang], [codes], [allowedFormats])\nConverts to escaped HTML\n* `lang` - (optional) - Set a custom lang (defaults to registry.language)\n* `codes` - (optional) - Specify which CSS style props should be used for each Minecraft color code\n* `allowedFormats` - The set of allowed formats. Default is ['color', 'bold', 'strikethrough', 'underlined', 'italic']\n\n#### chat.length()\n\nReturns the count of text extras and child ChatMessages\nDoes not count recursively in to the children\n\n#### chat.append(ChatMessage)\n\nAppends another ChatMessage or a string\n\n#### chat.clone()\n\nReturns a clone of the ChatMessage\n\n```js\nconst registry = require('prismarine-registry')('1.16')\nconst { MessageBuilder } = require('prismarine-chat')(registry)\n\nconst msg = new MessageBuilder().setText('Example chat mesasge')\nconsole.log(JSON.stringify(msg)) // The string as a message component\n\n```\n\n#### static ChatMessage.fromNotch(msg)\n\nReturns a prismarine-chat representation of the message recieved from the 'chat' packet, example shown [here](examples/minecraftprotocol_fromnotch/fromnotch.js)\n\n#### static ChatMessage.fromNetwork(messageType, messageParameters)\n\n(1.19+) Loads a chat message sent by server that needs to be formatted on client side.\n\n### MessageBuilder()\n\n#### setBold (val: boolean) : this\n#### setItalic (val: boolean) : this\n#### setUnderlined (val: boolean) : this\n#### setStrikethrough (val: boolean) : this\n#### setObfuscated (val: boolean) : this\n#### setColor (val: string) : this\n#### setText (val: string) : this\n\n> check code for examples (and explanations) from here on\n\n#### setFont (val: string) : this\n#### setTranslate (val: string) : this\n#### setInsertion (val: string) : this\n#### setKeybind (val: string) : this\n#### setScore (name: string, objective: string) : this\n#### setClickEvent (action: string, value: object) : this\n#### setHoverEvent (action: string, data: object, type?: 'contents'|'value') : this\n#### addExtra (...val: MessageBuilder | string) : this\n#### addWith (...val: MessageBuilder | string) : this\n#### resetFormatting () : void\nsets every one of the formatting options to false and sets text to `reset` type\n\n#### toJSON () : object\n`builder.toJSON()` is the same thing as `JSON.stringify(builder)`\n\n#### toString () : string\nruns `JSON.stringify()` on `this`\n\n#### static MessageBuilder.fromString(str, {colorSeparator = '&'}) : MessageBuilder\nconvert string with color codes like `&4Hello&cWorld` to a `MessageBuilder` object\n\n### processNbtMessage\n\nThis method is internally called by fromNotch.\n\nmcpc 1.20.3 uses NBT instead of JSON in some places to store chat, so the schema is a bit different.\n`processNbtMessage` normalizes the JS object obtained from nbt derealization to the old JSON schema,\nso it can be used to instantiate a ChatMessage.\n","publish_time":1691964977766,"_cnpm_publish_time":1691964977766,"dist-tags":{"latest":"1.13.0"}}