1.0.0 • Published 7 months ago

@mann-conomy/vdf-utils v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

vdf-utils

A Node.js utility library for parsing and converting objects in Valve's Data File (VDF) format.

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

Installation

Using npm:

$ npm install @mann-conomy/vdf-utils

Using yarn:

$ yarn add @mann-conomy/vdf-utils

Testing

Using npm:

$ npm test

Using yarn:

$ yarn test

Examples

Parsing item schemas from Team Fortress 2 into JavaScript objects.

import { readFile } from "fs/promises";
import { VDF } from "@mann-conomy/vdf-utils";
import type { ItemSchema } from "@mann-conomy/tf-schema";

(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");
        const file = await response.text();

        // Parse the result into an ItemSchema object
        const { items_game } = VDF.parse<ItemSchema>(file);

        console.log(items_game.qualities.vintage.value); // 3
        console.log(items_game.qualities.strange.value); // 11
    } catch (error) {
        console.error("Error parsing item schema", error.message);
    }
})();

Converting JavaScript objects into VDF-formatted strings.

import { VDF } from "@mann-conomy/vdf-utils";

const countries = {
    lang: {
        Language: "english",
        Tokens: {
            Steam_Country_US: "United States",
            Steam_Country_AU: "Australia"
            Steam_Country_GB: "United Kingdom"
        }
    }
}

try {
    const result = VDF.stringify(countries);

    console.log(result)
    /**
     * "lang"
     * {
     *      "Language"	"english"
     *      "Tokens"
     *      {
     *          "Steam_Country_US"		"United States"						
     *          "Steam_Country_AU"		"Australia"				
     *          "Steam_Country_GB"		"United Kingdom"			
     *      }
     *  }
     */
} catch (error) {
    console.error("Error converting countries to VDF", 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