Node.js implementation of serialization and deserialization of Valve's KeyValues (KV or VDF) format.
This parser is based on PHPValveKV.
npm install valve-kv
Deserialize a string
import { deserialize } from "valve-kv";
const kv = `"A"
{
"B" "C"
}`;
const kvObject = deserialize(kv);
const b = kvObject["A"]["B"]; // string "C"
Deserialize a file (supports #base
includes):
import { deserializeFile } from "valve-kv";
const itemsFileObject = deserializeFile("items.txt");
// Default encoding is utf-8, but it can be specified
const utf16FileObject = deserializeFile("utf16File.txt", "utf16le");
Serialize an object to KV:
import { serialize } from "valve-kv";
const myObj = { A: { B: "C" } };
const kv = serialize(myObj);
/* kv value:
"A"
{
"B" "C"
}
*/
Serialize arrays to KV:
import { serialize } from "valve-kv";
const myObj = { A: ["C", "D", "E"] };
const kv = serialize(myObj);
/* kv value:
"A"
{
"1" "C"
"2" "D"
"3" "E"
}
*/
Deserialize a string to a KVObject.
Deserialize a file to a KVObject. This supports the usage of #base
includes in the file.
Serialize an object to a KV string.
Check if a KVValue (could be object or basic value) is a KVObject.
Transform an array into a KV object. Example:
const kvobject = arrayToKvObject(["A", "B", "C"]);
// { ["1"]: "A", ["2"]: "B", ["3"]: "C" }
Transform a KV object to an array. Example:
const kvobject = arrayFromKvObject({ ["1"]: "A", ["2"]: "B", ["3"]: "C" });
// ["A", "B", "C"]