npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minecraft-protocol-chat-parser

v3.0.2

Published

A small library to transform a string with Minecraft format caracter into a JavaScript object compatible with Minecraft's chat protocol

Downloads

15

Readme

minecraft-protocol-chat-parser

npm version

A small library to transform a string with Minecraft format character into a JavaScript object compatible with Minecraft's chat protocol

Functions

parseString(message: string, acceptAndChar?: boolean)

const parseString = require('minecraft-protocol-chat-parser')(735).parseString // replace 735 by the protocol number of the targeted minecraft version, 735 is 1.16

console.log(parseString('§4Hello §bWorld'));

Output

{
  text: 'Hello ',   
  color: 'dark_red',
  bold: false,      
  italic: false,
  underlined: false,
  strikethrough: false,
  obfuscated: false,
  extra: [
    {
      text: 'World',
      color: 'aqua',
      bold: false,
      italic: false,
      underlined: false,
      strikethrough: false,
      obfuscated: false
    }
  ]
}

parseJSON(message: string | object, useAndChar?: boolean)

Version 2.0.0 include a partial support to parse a JSON chat protocol data into a string. It's only support formatting properties and will crash if the data contain hoverEvent, clickEvent or others properties who aren't used for text formatting.

let parsed = parseJSON({
    text: "Hello ",
    extra: [
        {
            text: "Grooble ",
            color: "black",
            bold: false,
            italic: false,
            underlined: false,
            strikethrough: false,
            obfuscated: false

        },
        {
            text: "How are u ",
            color: "dark_purple",
            bold: false,
            italic: true,
            underlined: true,
            strikethrough: false,
            obfuscated: false

        },
        {
            text: "?",
            color: "yellow",
            bold: true,
            italic: false,
            underlined: false,
            strikethrough: false,
            obfuscated: false

        }
    ]
})

console.log(parsed);

Output

Hello §0Grooble §5§o§nHow are u §e§l?

If the argument useAndChar is set to true the § will be replaced by & in the result string.

parseExtra(extra: string | object, useAndChar?: boolean)

The method parseExtra(extra, useAndChar) take only one extra not the full message.

If the argument useAndChar is set to true the § will be replaced by & in the result string.

Variables

jsonCodes

{
    'bold': 'l',
    'italic': 'o',
    'underlined': 'n',
    'strikethrough': 'm',
    'obfuscated': 'k',
    'black': '0',
    'dark_blue': '1',
    'dark_green': '2',
    'dark_cyan': '3',
    'dark_red': '4',
    'dark_purple': '5',
    'gold': '6',
    'gray': '7',
    'dark_gray': '8',
    'blue': '9',
    'green': 'a',
    'aqua': 'b',
    'red': 'c',
    'light_purple': 'd',
    'yellow': 'e',
    'white': 'f'
}

stringCodes

{
    '0': 'black',
    '1': 'dark_blue',
    '2': 'dark_green',
    '3': 'dark_cyan',
    '4': 'dark_red',
    '5': 'dark_purple',
    '6': 'gold',
    '7': 'gray',
    '8': 'dark_gray',
    '9': 'blue',
    'a': 'green',
    'b': 'aqua',
    'c': 'red',
    'd': 'light_purple',
    'e': 'yellow',
    'f': 'white',
    'k': 'obfuscated',
    'l': 'bold',
    'm': 'strikethrough',
    'n': 'underlined',
    'o': 'italic',
    'r': 'reset',
    '&': '&',
    '§': '&'
}

More examples.