{"name":"prismarine-chat","version":"1.11.0","keywords":["prismarine","chat"],"author":{"name":"Romain Beaumont"},"license":"MIT","_id":"prismarine-chat@1.11.0","maintainers":[{"name":"rom1504","email":"romain.rom1@gmail.com"}],"homepage":"https://github.com/PrismarineJS/prismarine-chat#readme","bugs":{"url":"https://github.com/PrismarineJS/prismarine-chat/issues"},"dist":{"shasum":"c85dfd4120da83ed1d3bf609e68c377f864d4122","tarball":"http://registry-npm.ywwl.com/prismarine-chat/download/prismarine-chat-1.11.0.tgz","fileCount":21,"integrity":"sha512-VJT/MWYB3qoiznUhrgvSQh76YFpzpCZpY85kJKxHLbd3UVoM0wsfs43Eg8dOltiZG92wc5/DTMLlT07TEeoa9w==","signatures":[{"sig":"MEUCIQDd6VAwcNQMeKMO5x2FgRIBqDjvHqiFRwJf7YEASssVtQIgYvc0ELkJq03dew4jhtoAZfYb4E5IE4VoIe06+isyzAk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":57040,"size":16429,"noattachment":false,"key":"/prismarine-chat/-/prismarine-chat-1.11.0.tgz"},"main":"index.js","types":"./index.d.ts","gitHead":"b526b317469034399bab99172406adf07e9a4cf4","scripts":{"fix":"standard --fix","lint":"standard","test":"mocha --reporter spec --exit","pretest":"npm run lint"},"_npmUser":{"name":"rom1504","email":"romain.rom1@gmail.com"},"repository":{"url":"git+https://github.com/PrismarineJS/prismarine-chat.git","type":"git"},"_npmVersion":"10.5.1","description":"Wrapper for a minecraft chat message","directories":{},"_nodeVersion":"22.0.0","dependencies":{"mojangson":"^2.0.1","prismarine-nbt":"^2.0.0","prismarine-registry":"^1.4.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^11.0.1","expect":"^29.1.0","standard":"^17.0.0","prismarine-chat":"file:.","prismarine-item":"^1.10.0"},"_npmOperationalInternal":{"tmp":"tmp/prismarine-chat_1.11.0_1737929536841_0.7006624684143692","host":"s3://npm-registry-packages-npm-production"},"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":1737929537044,"_cnpm_publish_time":1737929537044,"dist-tags":{"latest":"1.13.0"}}