a tools for turn to json to dota2's kv file.//Valve's KeyValues Text File Format serialization library
bash
npm install vdf-faster
`
基础使用 | Basic Usage
`typescript
import { decode, encode } from 'vdf-faster';
// VDF转JSON
// VDF to JSON
const vdfString =
;
const jsonData = decode(vdfString);
console.log(jsonData);
// 输出 | Output: { root: { key: 'value', nested: { number: '42' } } }
// JSON转VDF
// JSON to VDF
const vdfOutput = encode(jsonData);
console.log(vdfOutput);
// 输出VDF格式字符串
// Outputs VDF formatted string
`
高级功能 | Advanced Features
$3
`typescript
import { decode } from 'vdf-faster';
const vdfWithBase =
;
// 处理#base指令
// Process #base directives
decode(vdfWithBase, (bases) => {
console.log('Found base files:', bases);
// 输出 | Output: ['npc_units_custom.txt', 'npc_heroes_custom.txt']
});
`
$3
`typescript
import { decoder } from 'vdf-faster';
// 创建解码器实例
// Create decoder instance
const vdfDecoder = decoder.getNPCDecoder(vdfContent);
// 获取base文件列表
// Get base file list
const baseFiles = vdfDecoder.getBase();
// 获取解析后的数据
// Get parsed data
const jsonData = vdfDecoder.getDataJson('npc_dota_announcer_aghanim');
// 获取原始VDF格式数据
// Get original VDF formatted data
const vdfData = vdfDecoder.getDataCode('npc_dota_announcer_aghanim');
`
API文档 | API Documentation
$3
将VDF格式字符串转换为JSON对象。
Converts VDF formatted string to JSON object.
- code: 要解析的VDF格式字符串
The VDF formatted string to parse
- baseHandle: 可选的回调函数,用于处理#base指令
Optional callback function for handling #base directives
- 返回: 解析后的JSON对象
Returns: Parsed JSON object
$3
将JSON对象转换为VDF格式字符串。
Converts JSON object to VDF formatted string.
- data: 要转换的JSON对象
The JSON object to convert
- 返回: VDF格式字符串
Returns: VDF formatted string
$3
提供更细粒度的VDF解析控制:
Provides more granular VDF parsing control:
- getBase(): 获取所有#base文件路径
Get all #base file paths
- getDataJson(key: string): 获取指定键的JSON格式数据
Get JSON formatted data for the specified key
- getDataCode(key: string)`: 获取指定键的VDF格式数据