npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vdfplus

v1.0.0

Published

Converted Valve's KeyValue format to JSON and back

Downloads

5

Readme

vdfplus

vdfplus is a small library that aims to help with converting Valve's KeyValue format to JSON and vice versa. vdfplus is special in that it "arrayifies" key-tokens that appear multiple times in the .vdf, e.g. Steam Controller configurations. Per default tt also tries to casts values-tokens into their respective data type.
vdfplus can be used with nodejs, in the browser or via command-line.

Installation

For your project:

npm install vdfplus

For the CLI feature:

npm install vdfplus -g

API

VDF exposes two functions parse and stringify. They are derived from the JSON.parse and JSON.stringify.

VDF.parse(str:string, types?:boolean)

Parses a VDF string into a JavaScript object | Parameter | Type | Description | default | | --- | --- | --- | :---: | | str | string | A VDF string that will be parsed into an object. | - | types | boolean | (Optional) Sets the data type casting of the VDF values | true|

VDF.stringify(obj:object, indentation?:number|string, separator?:string)

Stringifies an object to VDF.

| Parameter | Type | Description | default | | --- |--- | --- | :---: | | object | object | Object that will be stringified into VDF. | - | | indentation | number|string | (Optional): Indentation of the string. Number of spaces or a string of whitespace characters. If an empty string is passed, then line breaks will be disabled | 2 | | separator | number|string |(Optional): Whitespace between key-value pairs. Number of spaces or a string of whitespace characters | \t |

Usage

Library

node.js

const vdfplus = require("vdfplus")
// or ES6
import vdfplus from "vdfplus"

Browser

<script src="node_modules/vdfplus/lib/vdfplus.web.js"></script>
<!-- OR minified-->
<script src="node_modules/vdfplus/lib/vdfplus.web.min.js"></script>

vdfplus is using UMD for exports It supports most common module loaders in the browser or simply adds a global namespace VDF if no loader is present.

Example

  • Read file or get the text from a textarea
  • Parse the VDF into an object
  • Modify object
  • Stringify object
  • Save to file or fill textarea with JSON string
// It is important to use the proper encoding
let vdfRaw = readFileSync("test/testfiles/test.vdf", "utf8")
// or read from textarea
let vdfRaw = document.getElementById("vdf-text").value

// Parse VDF string
let vdf = VDF.parse(vdfRaw)

// Change data
vdf["a-new-root-key"] = {
    "foo": "bar",
    "baz": [
        1, 2, 3, 4, 5
    ]
}

// Stringify the changes to vdf, indent using tabs and separate pairs with two spaces
let str = VDF.stringify(vdf, "\t", "  ")

// Save file
writeFileSync("test/testfiles/test.vdf", "utf8")
// or write to textarea
document.getElementById("json-text").value = str

CLI

vdfplus can also be used via command-line. Per default vdfplus parses VDF to JSON, so adding -j or --json s not needed! Data can be piped in via stdin and will be piped out to stdout if no uutput file was specified.
indentation is used for VDF and for JSON (defaults to 2 spaces [" "]), separate only relevant for VDF (defaults to tabs [\t]). Per default vdfplus will try to cast value-tokens into their respective data types. encoding and output-encoding are only for files

Usage: vdfplus [options] <input> <output>

Options:
    -V, --version                       output the version number
    -j, --json                          VDF to JSON (default behavior)
    -v, --vdf                           JSON to VDF
    -d, --indentation <char or number>  indentation for the VDF/JSON. number or whitespace characters. defaults to 2 spaces
    -s, --separator <char>              space between VDF key-value pairs. defaults to '\t'
    -e, --encoding <encoding>           encoding of input. defaults to 'utf8'
    -o, --output-encoding <encoding>    encoding of the output. defaults to 'utf8'
    -n, --no-types                       disable JSON types. all values will be strings
    -h, --help                          output usage information

Example

Simple VDF to JSON conversion:

$ vdfplus input.vdf output.vdf

Simple JSON to VDF conversion:

$ vdfplus -v input.vdf output.vdf

Piping:

# stdin, file out
$ echo "foo" { "bar" "baz" } | vdfplus - result.json

# stdin, stdout
$ echo "foo" { "bar" "baz" } | vdfplus -
# outputs:
# {
#   "foo":  {
#     "bar":    "baz"
#   }
# }

# file in, stdout
vdfplus result.json -v

Formatting

# create vdf, indent with tabs and use two spaces between pairs
vdfplus -v -i \t -s 2 input.json output.vdf

Notes

  • Unquoted keys and values are not supported
  • Comments will be lost when converting from and to VDF