JSPM

kvparser

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

Parses VDF/KeyValues, used Steam and Source engine games

Package Exports

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

Readme

KeyValues/VDF Parser

npm version npm downloads license sponsors

Parses Valve's KeyValues aka VDF format.

Fully compliant with escape sequences and comments.

Usage

Import the package:

const {parse} = require('kvparser');

or

import {parse} from 'kvparser';

parse(data)

Pass a string to the parse function, which will return an object. Since all KV structures begin with a named root key, the output object will have exactly one property, the value of which is an object.

Implementation Details

No extra processing is done to any data types. This means that all numbers are returned as strings. Additionally, proto-arrays are not automatically decoded into arrays. For example, this input data:

ExampleData
{
    "some_key_1"      "1"
    "some_key_2"      "1"
    "some_key_3"      "1"
}

Is decoded as:

{
    "ExampleData": {
        "some_key_1": "1",
        "some_key_2": "1",
        "some_key_3": "1"
    }
}

Any data after the closing } is ignored. Any sequence that begins with // and terminates with a newline is treated as a comment and is ignored.

Escape sequences are supported in quoted strings. Any backslash characters inside a quoted string are removed, and the following character is rendered as-is. Here are some example escape sequences and what they parse into:

  • "\"" becomes '"'
  • "\\" becomes '\\' (a string containing a single backslash, which JavaScript serializes into an escaped backslash)
  • "\n" becomes 'n'