Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ A clear and concise description of what you expected to happen.
A clear and concise description of what happens.

## Minimal reproducible example
Calling `LanguageParser.parse()` on the contents of `tf_english.txt` returns "Error parsing tf_english.txt...".
Calling `LocalizationParser.parse()` on the contents of `tf_english.txt` returns "Error parsing tf_english.txt...".

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

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

const { lang } = LanguageParser.parse(file);
const { lang } = LocalizationParser.parse(file);

console.log(lang.Language);
console.log(lang.Tokens.rarity4);
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If applicable, provide an example of how the new feature or improvement would be
```js
import { glob } from "glob";

export default class LanguageParser {
export default class LocalizationParser {
...
static async match(path: string) {
return await glob("tf_*.txt", { cwd: path });
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 The Mann-Conomy Project
Copyright (c) 2025 The Mann-Conomy Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ $ yarn test
```

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

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

```js
import { readFile } from "fs/promises";
import { LanguageParser } from "@mann-conomy/tf-parser";
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 } = LanguageParser.parse(file);
const { lang } = LocalizationParser.parse(file);

console.log(lang.Language); // English
console.log(lang.Tokens.rarity4); // Unusual
Expand All @@ -57,6 +58,32 @@ import { LanguageParser } from "@mann-conomy/tf-parser";
})();
```

Parsing the item schema from the Steam Web API.

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

(async() => {
try {
// Fetch the item 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
Expand All @@ -67,4 +94,4 @@ See the [Wiki pages](https://github.com/Mann-Conomy/tf-parser/wiki) for further

[MIT](LICENSE)

Copyright 2024, The Mann-Conomy Project
Copyright 2025, The Mann-Conomy Project
38 changes: 0 additions & 38 deletions examples/custom-parser.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/parse-language.ts → examples/localization.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { readFile } from "fs/promises";
import LanguageParser from "../src/classes/language.parser";
import { LocalizationParser } from "../src/index";

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

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

console.log(lang.Language); // English
console.log(lang.Tokens.rarity4); // Unusual
Expand Down
6 changes: 3 additions & 3 deletions examples/parse-items.ts → examples/schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ItemsParser from "../src/classes/items.parser";
import { SchemaParser } from "../src/index";

(async() => {
try {
// Fetch the items_game file from Steam
// Fetch the item 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 } = ItemsParser.parse(items);
const { items_game } = SchemaParser.parse(items);

console.log(items_game.rarities.unusual?.value); // 99
console.log(items_game.qualities.vintage?.value); // 3
Expand Down
Loading