A simple parser of the KeyValues binary format from Valve
npm install valve-key-values-binaryVKVB.parse returned parsed Map from your file
ts
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 = VKVB.parse(buffer);
console.log("OUTPUT:\n", root.toJSON());
`
$3
VKVB.serializate takes as an argument the Map object returned by the VKVB.parse
`ts
// root from Usage -> Parsing
const buffer = VKVB.serializate(root);
writeFileSync('path/to/file', buffer);
`
$3
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:
* AppInfoParser
* AppInfoSerializator
* PackageInfoParser
* PackageInfoSerializator
$3
To get and set the data in the Map, use the getType and setType methods
Supported data types: (Type -> T)
* Int -> number
`ts
const myValue: number = root.getInt('my_key');
root.setInt('my_key', 1);
`
* Ptr -> number
`ts
const myValue: number = root.getPtr('my_key');
root.setInt('my_key', 1);
`
* UInt64 -> bigint
`ts
const myValue: bigint = root.getUInt64('my_key');
root.setUInt64('my_key', 1n);
`
* String -> string
`ts
const myValue: string = root.getString('my_key');
root.setString('my_key', 'my string');
`
* WString -> string
`ts
const myValue: string = root.getWString('my_key');
root.setWString('my_key', 'my string');
`
* Map -> Map
`ts
const myValue: Map = root.getMap('my_key');
const myMap = new Map();
// ...
root.setMap('my_key', myMap);
`
#### Another methods
* delete(key:string) remove key from map
* getKeys() return all setted keys in map
* getKeysWithType() return Record
* getKeysWithSType() return Record, where string is name type
* getKeyType(key: string) return VKVB.TYPE by key or null if key not exsist
* getKeySType(key: string) return name type by key or null if key not exsist
* toJSON() return simple object.
[WARNING] bigint cannot be converted to a JSON value. You may need to define BigInt.prototype.toJSON`.