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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mana-scribe

v2.2.0

Published

Library for parsing and querying Magic: The Gathering mana costs — with support for CMC, devotion, and color identity.

Downloads

171

Readme

mana-scribe

Tests codecov

Mana Scribe is a utility for working with Magic: The Gathering mana costs and activation costs.

Supports both brace {3}{R/U} and shortform 3R/U notation.

Features

  • Parse MTG mana costs into structured objects
  • Supports all major symbols: generic, colored, 2-5 color hybrid, phyrexian, generic hybrid, phyrexian hybrid, snow, energy, tap/untap, variable
  • Works with both Scryfall braces and shortform notation
  • Compute:
    • Converted mana cost
    • Color identity
    • Devotion
  • Compare mana costs (equality, greater than, less than)
  • Easily add custom colors, types of mana, or other extra symbols

Note: When the parser encounters an unrecognized symbol it stops parsing and returns the symbols it parsed so far. You can access the unparsed string component through the property remainingStr.

Installation

npm install mana-scribe

Usage

import { ManaCost } from 'mana-scribe';

const cost = ManaCost.parse('{3}{R}{R}{R}');
console.log(cost.cmc);                // 6
console.log(cost.colors);             // ['R']
console.log(cost.getDevotionTo('R')); // 3

console.log(cost.toString(true));     // "{3}{R}{R}{R}"
console.log(cost.toString(false));    // "3RRR"

Shortform example

const cost = ManaCost.parse('2WU/B');
console.log(cost.cmc);     // 4
console.log(cost.colors);  // ['W','U','B']

Comparison example

The ManaCost class supports equality and comparison operators under superset semantics:

  • equals(other) → true if the costs are exactly the same
  • greaterThan(other) → true if this cost includes all symbols of other plus additional ones, or generic mana cost is higher.
  • lessThan(other) → true if this cost is a strict subset of other, or generic mana cost is lower.
const a = ManaCost.parse('{3}{B}{B}{B}');
const b = ManaCost.parse('{1}{B}{B}{B}');

console.log(a.equals(b));       // false
console.log(a.greaterThan(b));  // true
console.log(b.lessThan(a));     // true

Activation costs

ActivationCost offers the same functionality as the ManaCost class, but supports additional symbols such as Tap, Untap, and Energy. It does not have comparison functions.

import { ActivationCost } from 'mana-scribe';

const cost = ActivationCost.parse('{1}{G}{T}');
console.log(cost.symbols.map(s => s.type)); // ["genericMana", "coloredMana", "tap"]
console.log(cost.toString(true));           // "{1}{G}{T}"

Extending

Custom colors

You can add custom colors of mana with symbolRegistry.addColor.

import { symbolRegistry, ManaCost } from 'mana-scribe';

symbolRegistry.addColor({ id: 'P', name: 'Purple' });
const cost = ManaCost.parse('{3}{R/P}{P}');
console.log(cost.symbols.map(s => s.type)); // ["genericMana", "twoColorHybridMana", "coloredMana"]
console.log(cost.cmc); // 5
console.log(cost.colors);  // ['R','P']
console.log(cost.getDevotionTo('P')); // 2

Custom mana types

You can add custom types of mana with symbolRegistry.addManaType. This is for mana produced by specific sources, like snow mana.

import { symbolRegistry, ActivationCost } from 'mana-scribe';

symbolRegistry.addManaType({ id: 'A', name: 'Artificial' }); // mana produced by an artifact
const cost = ActivationCost.parse('{A}{A}{T}');
console.log(cost.symbols.map(s => s.type)); // ["typedMana", "typedMana", "tap"]
console.log(cost.colors);  // []

Extra symbols

You can add additional symbols for use in activation costs with symbolRegistry.addExtraSym. This is used for things like the energy symbol.

import { symbolRegistry, ActivationCost } from 'mana-scribe';

symbolRegistry.addManaType({ id: '\\@', name: 'Chaos' });
const cost = ActivationCost.parse('{@}');
console.log(cost.symbols.map(s => s.type)); // ["extra"]
console.log(cost.colors);  // []

License

This project is licensed under the MIT License. See LICENSE for more info.