Featurevisor

Advanced

Custom Parsers

Featurevisor ships with built-in parsers supporting YAML and JSON files, but you can also take advantage of custom parsers allowing you to define your features and segments in a language you are most comfortable with.

Built-in parsers

YAML

By default, Featurevisor assumes all your definitions are written in YAML and no extra configuration is needed in that case:

featurevisor.config.js
module.exports = {
environments: ['staging', 'production'],
tags: ['all'],
// optional if value is "yml"
parser: 'yml',
}

You can find a example project using YAML here.

JSON

If we wish to use JSON files instead of YAMLs, we can do so by specifying the parser option:

featurevisor.config.js
module.exports = {
environments: ['staging', 'production'],
tags: ['all'],
// define the parser to use
parser: 'json',
}

You can find a example project using JSON here.

Custom

If you wish to define your features and segments in some other language besides YAML and JSON, you can provide your own custom parser.

A parser in this case is a function that takes file content as input (string) and returns a parsed object.

Let's say we wish to use TOML files for our definitions.

We start by installing the toml package:

Command
$ npm install --save-dev toml

Now we define a custom parser in our configuration:

featurevisor.config.js
module.exports = {
environments: ['staging', 'production'],
tags: ['all'],
// define the parser to use
parser: {
extension: 'toml',
parse: (content) => require('toml').parse(content),
},
}

You can find a example project using TOML here.

Previous
Namespaces