Git Product home page Git Product logo

minecraft-motd-util's Introduction

minecraft-motd-util

Parse and convert a Minecraft MOTD into various formats.

Installation

npm install minecraft-motd-util

Usage

Parsing

parse(input, options) will parse an MOTD into an array of tokens for easier formatting and generic use. The result of this method can be used as an argument to any other utility that uses an MOTD input. You can supply either a string or a Chat object as the input.

import { parse } from 'minecraft-motd-util';

// Defaults
const options = {
    formattingCharacter: '§'
};

const result = parse('§k;;; §cA §a§lMinecraft §cServer §r§k;;;', options); // `options` is optional

console.log(result);
// => [
//        { text: ';;; ', color: 'white', obfuscated: true },
//        { text: 'A ', color: 'red' },
//        { text: 'Minecraft ', color: 'green', bold: true },
//        { text: 'Server ', color: 'red' },
//        { text: ';;;', color: 'white', obfuscated: true }
//    ]

Formatting

format(input, options) will format the parsed tree or string back into a normalized string with the provided formatting character. Note that this method will prefer resetting color over using §r.

import { format } from 'minecraft-motd-util';

// Defaults
const options = {
    formattingCharacter: '§'
};

const result = format(result, options); // `options` is optional, `result` assumed from example above

console.log(result);
// => '§f§k;;; §cA §a§lMinecraft §cServer §f§k;;;'

Clean

clean(tree, options) will remove all formatting codes and characters from the string with the implied formatting character.

import { clean } from 'minecraft-motd-util';

// Defaults
const options = {
    formattingCharacter: '§'
};

const result = clean(result, options); // `options` is optional, `result` assumed from example above

console.log(result);
// => ';;; A Minecraft Server ;;;'

Convert to HTML

toHTML(input, options) will convert the formatted string or parsed MOTD into an HTML string.

import { toHTML } from 'minecraft-motd-util';

// Defaults
const options = {
    serializers: { ... }, // see `types.ts` for documentation
    rootTag: 'span'
};

const result = toHTML(result, options); // `options` is optional, `result` assumed from example above

console.log(result);
// => '<span><span class="minecraft-formatting-obfuscated" style="color: #FFFFFF;">;;; </span><span style="color: #FF5555;">A </span><span style="color: #55FF55; font-weight: bold;">Minecraft </span><span style="color: #FF5555;">Server </span><span class="minecraft-formatting-obfuscated" style="color: #FFFFFF;">;;;</span></span>'

Support

If you require assistance with this library, you can ask within our official Discord server.

minecraft-motd-util's People

Contributors

passthemayo avatar yan3321 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.