Package Exports
- valve-key-values-binary
- valve-key-values-binary/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (valve-key-values-binary) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
valve-key-values-binary
A simple parser of the KeyValues binary format (or Binary VDF) from Valve
Usage
Parsing
VKVB.parse returned parsed Map from your file
import VKVB, { Map } from "./index.js";
type ShortcutsRoot = {
shortcuts: Shortcut[];
}
type Shortcut = {
appid: number;
AppName: string;
}
const buffer = readFileSync('path/to/file');
const root:Map<ShortcutsRoot> = VKVB.parse<ShortcutsRoot>(buffer);
console.log("OUTPUT:\n", root.toJSON());Serializate
VKVB.serializate takes as an argument the Map object returned by the VKVB.parse
// root from Usage -> Parsing
const buffer = VKVB.serializate(root);
writeFileSync('path/to/file', buffer);How to parse and serializate specific files, such as AppInfo and PackageInfo
AppInfo and PackageInfo are supported by default. To work with other specific files, you can extend the Parser and Serializer classes provided in the package.
Examples:
Work with Map
To get and set the data in the Map, use the get[Type](key: string) and set[Type](key: string, value: T) methods
Supported data types: (Type -> T)
- Int -> number
const myValue: number = root.getInt('my_key');
root.setInt('my_key', 1);- Ptr -> number
const myValue: number = root.getPtr('my_key');
root.setInt('my_key', 1);- UInt64 -> bigint
const myValue: bigint = root.getUInt64('my_key');
root.setUInt64('my_key', 1n);- String -> string
const myValue: string = root.getString('my_key');
root.setString('my_key', 'my string');- WString -> string
const myValue: string = root.getWString('my_key');
root.setWString('my_key', 'my string');- Map -> Map
const myValue: Map = root.getMap('my_key');
const myMap = new Map<T>();
// ...
root.setMap('my_key', myMap);Another methods
delete(key:string)remove key from mapgetKeys()return all setted keys in mapgetKeysWithType()returnRecord<Keys, VKVB.TYPE>getKeysWithSType()returnRecord<Keys, string>, where string is name typegetKeyType(key: string)returnVKVB.TYPEby key ornullif key not exsistgetKeySType(key: string)return name type by key ornullif key not exsisttoJSON()return simple object.
[WARNING] bigint cannot be converted to a JSON value. You may need to define BigInt.prototype.toJSON.