{"id":11523,"library":"parse-bmfont-xml","title":"BMFont XML Parser","description":"parse-bmfont-xml is a focused JavaScript library designed to parse XML-formatted BMFont (Bitmap Font) files generated by AngelCode BMFont. It takes a string or Buffer containing the XML data and converts it into a structured JavaScript object, adhering to the bmfont2json specification. The current stable version is 1.1.6, with the last update approximately seven years ago, indicating a mature but largely inactive maintenance status. Its primary differentiator is its singular focus on the BMFont XML format, providing a straightforward API for font data extraction, including character definitions, kerning pairs, and texture page references. It is suitable for both Node.js environments using `fs` and browser environments via XHR, though browser usage depends on internal DOM parsing APIs.","status":"maintenance","version":"1.1.6","language":"javascript","source_language":"en","source_url":"git://github.com/mattdesl/parse-bmfont-xml","tags":["javascript","xml","parse","convert","bmfont","bm","bitmap","font","bitmaps"],"install":[{"cmd":"npm install parse-bmfont-xml","lang":"bash","label":"npm"},{"cmd":"yarn add parse-bmfont-xml","lang":"bash","label":"yarn"},{"cmd":"pnpm add parse-bmfont-xml","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily a CommonJS module. Direct ES module `import` syntax will typically require a bundler or Node.js's CJS interop for compatibility.","wrong":"import parse from 'parse-bmfont-xml'","symbol":"parse","correct":"const parse = require('parse-bmfont-xml')"},{"note":"The library exports a single function as its default (module.exports). There are no named exports.","wrong":"import { parse } from 'parse-bmfont-xml'","symbol":"parse","correct":"const parse = require('parse-bmfont-xml')"}],"quickstart":{"code":"const fs = require('fs');\nconst parse = require('parse-bmfont-xml');\nconst path = require('path');\n\n// Create a dummy BMFont XML file for demonstration\nconst dummyXmlContent = `\n<font>\n    <info face=\"Arial\" size=\"32\" bold=\"0\" italic=\"0\" charset=\"\" unicode=\"0\" stretchH=\"100\" smooth=\"1\" aa=\"1\" padding=\"0,0,0,0\" spacing=\"1,1\" outline=\"0\"/>\n    <common lineHeight=\"32\" base=\"26\" scaleW=\"256\" scaleH=\"256\" pages=\"1\" packed=\"0\" alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"/>\n    <pages>\n        <page id=\"0\" file=\"sheet0.png\"/>\n    </pages>\n    <chars count=\"1\">\n        <char id=\"65\" x=\"0\" y=\"0\" width=\"20\" height=\"28\" xoffset=\"0\" yoffset=\"4\" xadvance=\"20\" page=\"0\" chnl=\"15\"/>\n    </chars>\n    <kernings count=\"0\"/>\n</font>\n`;\n\nconst filePath = path.join(__dirname, 'dummy.fnt');\nfs.writeFileSync(filePath, dummyXmlContent);\n\n// Read and parse the BMFont file\nfs.readFile(filePath, (err, data) => {\n  if (err) {\n    console.error('Error reading file:', err);\n    return;\n  }\n  try {\n    const result = parse(data);\n    console.log('Font Face:', result.info.face);         // Expected: \"Arial\"\n    console.log('Pages:', result.pages);                 // Expected: [ 'sheet0.png' ]\n    console.log('Number of Chars:', result.chars.length); // Expected: 1\n    console.log('First Char ID:', result.chars[0].id);   // Expected: 65 (for 'A')\n  } catch (parseError) {\n    console.error('Error parsing BMFont XML:', parseError);\n  }\n});\n","lang":"javascript","description":"This quickstart demonstrates how to read an XML BMFont file using Node.js's `fs` module and parse its content into a JavaScript object, then access key properties like font face, pages, and character data."},"warnings":[{"fix":"For non-standard browser-like environments, consider pre-parsing BMFont XML on a server or a build step, or ensure a DOM-compatible environment is available. Test thoroughly in target environments.","message":"The package relies on `xml-parse-from-string` for browser environments. This dependency may not function correctly or at all in environments lacking full DOM API support (e.g., some canvas-only contexts like CocoonJS), potentially leading to runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Audit the package's code and dependencies if using in a critical application. Consider alternatives if modern features or active maintenance are required. Pin specific versions to avoid unexpected dependency updates if relying on an older, stable setup.","message":"This package has not been updated in approximately seven years. While it may still function, it might lack support for newer JavaScript features, security patches, or compatibility fixes for recent Node.js or browser environments. There is a risk of unaddressed vulnerabilities or outdated dependencies.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a bundler (Webpack, Rollup, Parcel) that handles CommonJS interoperability, or for Node.js ESM projects, use `import parse from 'parse-bmfont-xml'` and ensure Node.js's CJS interop is correctly configured for your environment.","message":"As a CommonJS-first module published before widespread ES module adoption, `parse-bmfont-xml` may require specific configuration or bundler setup to be used seamlessly in modern ES module-only projects.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the input data is a valid XML string or Buffer and matches the AngelCode BMFont XML format, particularly having a `<font>` root element. Validate the XML content before passing it to the parser.","cause":"The input string or Buffer provided to `parse()` does not contain well-formed XML data that conforms to the BMFont XML specification.","error":"Error: Failed to parse XML"},{"fix":"For ES module contexts, use `import parse from 'parse-bmfont-xml'` or `import * as parseModule from 'parse-bmfont-xml'; const parse = parseModule.default;`. For CommonJS, use `const parse = require('parse-bmfont-xml')`.","cause":"This typically occurs in an ES module context when trying to import the CommonJS module using named import syntax (e.g., `import { parse } from 'parse-bmfont-xml'`) instead of the correct default import or CommonJS `require`.","error":"TypeError: parse is not a function"}],"ecosystem":"npm"}