https://github.com/mann-conomy/tf-parser
A Node.js parser for converting Team Fortress 2 game files to JSON objects.
https://github.com/mann-conomy/tf-parser
file json localization mann-conomy nodejs parser tf2 typescript
Last synced: 4 months ago
JSON representation
A Node.js parser for converting Team Fortress 2 game files to JSON objects.
- Host: GitHub
- URL: https://github.com/mann-conomy/tf-parser
- Owner: Mann-Conomy
- License: mit
- Created: 2024-05-10T10:37:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-29T14:37:38.000Z (about 1 year ago)
- Last Synced: 2025-08-08T19:12:34.750Z (11 months ago)
- Topics: file, json, localization, mann-conomy, nodejs, parser, tf2, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@mann-conomy/tf-parser
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tf-parser
A Node.js parser for converting Team Fortress 2 game files to JSON objects.
[](https://npmjs.com/package/@mann-conomy/tf-parser)
[](https://npmjs.com/package/@mann-conomy/tf-parser)
[](https://nodejs.org/en/about/releases/)
[](https://github.com/Mann-Conomy/tf-parser/blob/main/.github/workflows/test.yml)
[](https://github.com/Mann-Conomy/tf-parser/blob/main/LICENSE)
## Installation
Using [npm](https://www.npmjs.com/package/@mann-conomy/tf-parser):
```bash
$ npm install @mann-conomy/tf-parser
```
Using [yarn](https://yarnpkg.com/package/@mann-conomy/tf-parser):
```bash
$ yarn add @mann-conomy/tf-parser
```
## Testing
Using [npm](https://docs.npmjs.com/cli/v8/commands/npm-run-script):
```bash
$ npm test
```
Using [yarn](https://classic.yarnpkg.com/lang/en/docs/cli/run/):
```bash
$ yarn test
```
## Examples
Parsing UTF-16 encoded localization files from the Team Fortress 2 game client into JSON objects.
```js
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.
```js
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](https://github.com/Mann-Conomy/tf-parser/tree/main/examples) and [test](https://github.com/Mann-Conomy/tf-parser/tree/main/test) directories.
## Documentation
See the [Wiki pages](https://github.com/Mann-Conomy/tf-parser/wiki) for further documentation.
## License
[MIT](LICENSE)
Copyright 2025, The Mann-Conomy Project