Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bmfont2json

mattdesl464MIT0.1.9

converts BMFont TXT and XML files to JSON

bmfont, bitmap, fonts, json, xml, txt, angelcode, angel, code, text

readme

Parses BMFont files (XML/TXT) to JSON objects, with a command-line tool for easy conversion.

example

var fs = require('fs');
var bmfont2json = require('bmfont2json');

//grab the Buffer or a string of our data
var data = fs.readFileSync(__dirname + '/myfile.fnt');

//the bitmap font data as an object
var obj = bmfont2json(data);

//we can stringify it if we want...
var json = JSON.stingify( obj );

The function parses a string (or Node Buffer) that is either XML data (with a root element), or TXT data (following Bitmap Font spec).

The output looks something like the following JSON. It tries to stay true to the BMFont spec.

{
     pages: [
         "sheet_0.png", 
         "sheet_1.png"
     ],
     chars: [
         { chnl, height, id, page, width, x, y, xoffset, yoffset, xadvance },
         ...
     ],
     info: { ... },
     common: { ... },
     kernings: [
         { first, second, amount }
     ]
}

Related modules:

spec

See here for a more complete JSON output.

command-line tool

Converts a single file. If no output is provided, it prints to stdout.

Install
    npm install bmfont2json -g

Usage:
    bmfont2json file [options]

Options:
    -o, --ouput the output path
    -p, --pretty pretty print the JSON output