JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q36999F
  • License MIT

A parser for Valve's KeyValue text file format (VDF)

Package Exports

  • @hinw/vdf-parser
  • @hinw/vdf-parser/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 (@hinw/vdf-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@hinw/vdf-parser

A parser for Valve's KeyValue text file format (VDF) https://developer.valvesoftware.com/wiki/KeyValues

Interfaces

Parse a file

import { VdfParser } from '@hinw/vdf-parser';

// file content: "key" { "nested_key" "value" }"
const filePath = 'input/sample.vdf';

const parser = new VdfParser();
const result = await parser.parseFile(filePath);

// assert.assertEqual(result, { key: { nested_key: 'value' } });

Parse a read stream

import stream from 'node:stream';
import { VdfParser } from '@hinw/vdf-parser';

const readStream = stream.Readable.from(`"key" { "nested_key" "value" }"`);
const parser = new VdfParser();
const result = await parser.parseStream(readStream);

// assert.assertEqual(result, { key: { nested_key: 'value' } });

Parse a string

import { VdfParser } from '@hinw/vdf-parser';

const input = `"key" { "nested_key" "value" }"`;
const parser = new VdfParser();
const result = parser.parseText(input);

// assert.assertEqual(result, { key: { nested_key: 'value' } });

Options

Escape sequence

By default, the parser will handle escape sequence. To disable this behavior, you can set disableEscape to true

import { VdfParser } from '@hinw/vdf-parser';

const input = `"\\"quoted key\\"" "value"`;
const parser = new VdfParser({ disableEscape: true });
const result = parser.parseText(input);

// assert.assertEqual(result, { '\\"quoted key\\"': 'value' });

Handling duplicate keys

By default, the parser will use the earliest seen value for duplicated keys

import { VdfParser } from '@hinw/vdf-parser';

const input = `"key" { "nested_key" "value" }" "key" "value"`;
const parser = new VdfParser();
const result = parser.parseText(input);

// assert.assertEqual(result, { key: { nested_key: 'value' } });

However, you can set useLatestValue to true to use the latest seen value

import { VdfParser } from '@hinw/vdf-parser';

const input = `"key" { "nested_key" "value" }" "key" "value"`;
const parser = new VdfParser({ useLatestValue: true });
const result = parser.parseText(input);

// assert.assertEqual(result, { 'key': 'value' });