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

@mhesus/mcbe-colors

v2.0.2

Published

A library that implements a simple text coloring system for use within the Minecraft: Bedrock Edition script api.

Downloads

28

Readme

mcbe-colors

A library that implements a simple text coloring system for use within the Minecraft: Bedrock Edition script api.

npm | github

Installation

If you use a bundler to bundle your behaviour pack scripts, you can simply install this library through npm:

npm i @mhesus/mcbe-colors

If you don't use a bundler, I would recommend learning to use one as it is the best and easiest way to use other people's libraries. Some official mojang libraries, such as @minecraft/math, require it.

Self-compilation

Otherwise, you should copy the source files into your own project. If you use javascript, you should clone this repository and build it by executing the following in your terminal:

git clone https://github.com/miguelkjesus/mcbe-colors
cd mcbe-colors
npm run build

You can then copy the /build folder into your project (Make sure to delete the .d.ts files) and rename it something suitable e.g. the name of this library.

Usage

Extending the String Class

In order to extend the string class, you can import the /extend-auto export of this library which will automatically extend the class for you:

import "@mhesus/mcbe-colors/extend-auto";

"Make this red!".red() === "§cMake this red!§r";
"Now gold and italicised!".gold.italic() === "§p§oNow gold and italicised!§r";

Preferrably you should put this import somewhere in your index file.

Another way to extend the string class is importing the /extend export of this library and choose to extend/unextend the class whenever it is needed. This can prove useful in some niche situations, otherwise I would either not extend the class at all, or just use /extend-auto.

import { extend, unextend } from "@mhesus/mcbe-colors/extend";

// Extend the string class
extend();

// Works!!
"Make this blue!".blue() === "§cMake this blue!§r";

// Remove the extensions created by the library
unextend();

// Errors because string no longer has the style methods
"Make this blue!".blue();

Styles

// -- Using the Style class --
import { Style } from "@mhesus/mcbe-colors";

Style.red("Make me red!") === "§cMake me red!§r";
// -- Import the color directly --
import { red } from "@mhesus/mcbe-colors";

red("Make me red!") === "§cMake me red!§r";
// -- Compounding styles --
import { red, italic, aqua } from "@mhesus/mcbe-colors";

// Style codes are applied in the order they're called
red.bold("Red bold.") === "§c§lRed bold.§r";

italic.red("Italic red.") === "§o§cItalic red.§r";

/* All the color codes created in the chain will be applied, 
   even if colors conflict. In game, the last color applied 
   will take effect. */
aqua.green("I will be green.") === "§b§aI will be green.§r";

/* I wouldn't recommend compounding styles like this as then the
   reset symbol at the end will be unnecessarily repeated. */
aqua(green("I will be green.")) === "§b§aI will be green.§r§r";

Style Presets

This isn't necessarily a distinct way of using the library, more is it a useful thing that you can do in addition to using the other methods.

import { red, green, gray } from "@mhesus/mcbe-colors";

// Assigning presets
const success = green;
const error = red.bold;
const info = gray.italic;

// Applying presets
success("Success.") === "§aSuccess.§r";

error("Error!") === "§c§lError!§r";

info("Info?") === "§7§oInfo?§r";