Extending Featurevisor
Custom parsers
Definitions are YAML by default. Switch the whole project to JSON, or give it a parser for any other format.
YAML#
YAML needs no configuration. Every example in these docs is YAML, and the YAML example project is a complete setup.
JSON#
Set parser to json in the configuration:
module.exports = { parser: 'json',}Every definition is then a .json file. The checkout feature from the Quick start becomes:
{ "description": "Checkout redesign", "bucketBy": "userId", "rules": [ { "key": "netherlands", "conditions": "netherlands", "percentage": 100 }, { "key": "everyone", "conditions": "*", "percentage": 25 } ]}The JSON example project is a complete setup.
Another format#
A custom parser is an object with three properties:
| Property | Purpose |
|---|---|
extension | The file extension, such as toml |
parse(content, filePath?) | Turns a file's text into a definition object |
stringify(content, filePath?) | Turns a definition object back into text |
Both functions are synchronous. The file path is there so a parser can say where an error is. Featurevisor checks that both exist when it loads the configuration. It writes definitions with stringify, for example during promote --apply, so a parser must write as well as read.
For TOML, smol-toml does both:
npm install --save-dev smol-tomlconst toml = require('smol-toml')module.exports = { parser: { extension: 'toml', parse: (content) => toml.parse(content), stringify: (content) => toml.stringify(content), },}The TOML example project is a complete setup.
Pick a format that can hold every value your definitions use. TOML has no null, for example. Writing a file through stringify can also change its formatting and drop comments, so check the Git diff after a command writes definitions.
Related#
- Configuration
- Projects
- Datasource, to read definitions from somewhere other than files

