/key-values-ts

A JavaScript/TypeScript parser for the KeyValues data format.

Primary LanguageTypeScriptMIT LicenseMIT

KeyValues.ts

npm package npm downloads CI status Codecov coverage License

A JavaScript/TypeScript parser for the KeyValues data format. KeyValues is an easy-to-use, JSON-like format developed by Valve Corporation. It is used in Steamworks configuration files as well as in several of Valve's games, such as Dota 2.

Installation

Using yarn:

yarn add key-values-ts

Using npm:

npm install key-values-ts

Usage

import KeyValues from 'key-values-ts';

const input = `"key"
{
  "key 1"  "value 1"
  "key 2"  "value 2"
}`;

// Convert the KeyValues text to an object:
const obj = KeyValues.parse(input);
// {
//   key: {
//     'key 1': 'value 1',
//     'key 2': 'value 2'
//   }
// }

// Convert the object back to a KeyValues text:
const output = KeyValues.stringify(obj);
// "key"
// {
//   "key 1"  "value 1"
//   "key 2"  "value 2"
// }