@mann-conomy/tf-parser
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

tf-parser

A Node.js parser for converting Team Fortress 2 game files to JSON objects.

npm version npm downloads Node.js version GitHub actions GitHub license

Installation

Using npm:

$ npm install @mann-conomy/tf-parser

Using yarn:

$ yarn add @mann-conomy/tf-parser

Testing

Using npm:

$ npm test

Using yarn:

$ yarn test

Examples

Parsing UTF-16 encoded localization files from the Team Fortress 2 game client into JSON objects.

import { readFile } from "fs/promises";
import { LocalizationParser } from "@mann-conomy/tf-parser";

(async () => {
    try {
        // Read the contents of the tf_english.txt file
        const file = await readFile("tf_english.txt", { encoding: "utf16le" });

        // Parse english language translations
        const { lang } = LocalizationParser.parse(file);

        console.log(lang.Language); // English
        console.log(lang.Tokens.rarity4); // Unusual
    } catch (error) {
        console.error("Error parsing tf_english.txt", error.message);
    }
})();

Parsing the client schema from the Steam Web API.

import { SchemaParser } from "@mann-conomy/tf-parser";

(async() => {
    try {
        // Fetch the client schema from the Steam Web API
        const response = await fetch("https://media.steampowered.com/apps/440/scripts/items/items_game.bdc614ad776fb2d43c1f247fce870485d2299152.txt");

        // Resolve the response into a UTF-8 string
        const items = await response.text();

        // Parse the in-game items
        const { items_game } = SchemaParser.parse(items);

        console.log(items_game.rarities.unusual?.value); // 99
        console.log(items_game.qualities.vintage?.value); // 3
    } catch (error: unknown) {
        if (error instanceof Error) {
            console.error("Error parsing items_game.txt", error.message);
        }
    }
})();

Some more examples are available in the examples and test directories.

Documentation

See the Wiki pages for further documentation.

License

MIT

Copyright 2025, The Mann-Conomy Project

Package Sidebar

Install

npm i @mann-conomy/tf-parser

Weekly Downloads

2

Version

2.0.2

License

MIT

Unpacked Size

118 kB

Total Files

21

Last publish

Collaborators

  • snabe