vdf-faster
TypeScript icon, indicating that this package has built-in type declarations

2.1.6 • Public • Published

vdf-faster

一个高性能的 Valve Data Format (VDF) 解析器,专为 Dota 2 自定义游戏开发优化。 A high-performance Valve Data Format (VDF) parser optimized for Dota 2 custom game development.

特性 | Features

  • 🚀 高性能: 相比其他VDF解析器,提供更快的解析速度 High Performance: Provides faster parsing speed compared to other VDF parsers

  • 🎯 完整的#base支持: 正确处理和解析#base指令 Complete #base Support: Correctly handles and parses #base directives

  • 💪 健壮性: 完善的错误处理和边界情况支持 Robustness: Comprehensive error handling and edge case support

  • 🔄 双向转换: 支持VDF与JSON对象的双向转换 Bidirectional Conversion: Supports bidirectional conversion between VDF and JSON objects

  • 🎮 游戏开发优化: 专为Dota 2自定义游戏开发场景优化 Game Development Optimization: Specially optimized for Dota 2 custom game development scenarios

安装 | Installation

npm install vdf-faster

基础使用 | Basic Usage

import { decode, encode } from 'vdf-faster';

// VDF转JSON
// VDF to JSON
const vdfString = `
"root" {
    "key" "value"
    "nested" {
        "number" "42"
    }
}
`;

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

#base文件处理 | #base File Handling

import { decode } from 'vdf-faster';

const vdfWithBase = `
#base "npc_units_custom.txt"
#base "npc_heroes_custom.txt"

"CustomUnits" {
    // ...
}
`;

// 处理#base指令
// Process #base directives
decode(vdfWithBase, (bases) => {
    console.log('Found base files:', bases);
    // 输出 | Output: ['npc_units_custom.txt', 'npc_heroes_custom.txt']
});

使用Decoder类 | Using the Decoder Class

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

decode(code: string, baseHandle?: (base: string[]) => void): Record<string, object>

将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

encode(data: any): string

将JSON对象转换为VDF格式字符串。

Converts JSON object to VDF formatted string.

  • data: 要转换的JSON对象

    The JSON object to convert

  • 返回: VDF格式字符串

    Returns: VDF formatted string

decoder类 | decoder Class

提供更细粒度的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格式数据

    Get VDF formatted data for the specified key

性能对比 | Performance Comparison

解析器 Parser 解析速度 Parse Speed #base支持 #base Support 备注 Notes
vdf-faster 19.054ms ✅ 完整支持 Complete 性能优化,完整功能 Performance optimized, full features
fast-vdf 13.438ms ❌ 不支持 Not supported 性能最快但功能受限 Fastest but limited features
vdferparser 34.062ms ❌ 解析错误 Parse error -
vdf-reader 39.303ms ⚠️ 部分支持 Partial #base作为普通键处理 #base treated as regular key
vdf-parser 42.146ms ❌ 解析错误 Parse error -
vdf-extra 50.318ms ✅ 支持 Supported 不支持大文件 Doesn't support large files
vdfjs 87.78ms ❌ 不支持 Not supported -

许可证 | License

MIT

Readme

Keywords

Package Sidebar

Install

npm i vdf-faster

Weekly Downloads

18

Version

2.1.6

License

MIT

Unpacked Size

15.7 kB

Total Files

5

Last publish

Collaborators

  • takegine