prettier-plugin-kv1
v1.0.0
Published
A Prettier plugin for Valve KeyValues1 files
Downloads
291
Maintainers
Readme
prettier-plugin-kv1
A Prettier plugin for Valve's text KeyValues1 format.
The plugin is written in TypeScript and publishes compiled ESM with type declarations.
It supports quoted and unquoted keys and values, nested objects, repeated keys,
conditional values, #base and #include directives, line comments, and block
comments.
Install
npm install --save-dev prettier prettier-plugin-kv1Add the plugin to your Prettier configuration:
{
"plugins": ["prettier-plugin-kv1"]
}For an ESM configuration file, the plugin also provides a default export:
import prettierPluginKv1 from "prettier-plugin-kv1";
export default {
plugins: [prettierPluginKv1],
};Prettier will infer the parser for .gi, .kv, .res, .vdf, .vmf, and
.vmt files. KeyValues1 also commonly appears in files with generic extensions.
Add an override for those files:
{
"plugins": ["prettier-plugin-kv1"],
"overrides": [
{
"files": ["*.games.txt", "*.phrases.txt"],
"options": {
"parser": "kv1"
}
}
]
}Then use Prettier normally:
npx prettier --write "**/*.{gi,kv,res,vdf,vmf,vmt}"Development
Compile the plugin with:
pnpm buildPackage releases can be published automatically from GitHub tags using npm Trusted Publishing. See RELEASING.md for the initial setup and release workflow.
The plugin uses tabs for indentation and between scalar keys and values by
default. It respects Prettier's tabWidth and useTabs options for indentation.
API
import * as prettier from "prettier";
import kv1Plugin from "prettier-plugin-kv1";
const formatted = await prettier.format(source, {
parser: "kv1",
plugins: [kv1Plugin],
});