npm

flipr-yaml

2.0.1 • Public • Published

node-flipr-yaml

NPM

Build Status

This project is part of the flipr family.

node-flipr-yaml is a flipr source for retrieving flipr configuration data from yaml files.

node-flipr

How does it work?

The examples below show you how to create the flipr yaml source. A source by itself isn't very useful. You'll still need to give the source to flipr, so that it can use it to do awesome things. See the flipr documentation for how to use a source.

Here's the simplest example:

---
# Here's a basic YAML config file. Assume it exists at config/simple.yaml 
someConfigKey:
  description: >
    This is some config key that has some value.
  value: someValue
const FliprYaml = require('flipr-yaml');
const source = new FliprYaml({
  filePath: 'config/simple.yaml',
});
source.getConfig().then(
  config => console.log(config),
  err => console.log(err),
);

Validating your yaml files

flipr-yaml has the ability to validate your yaml files. This is very useful if you're storing your yaml files alongside your app code and using a CICD pipeline to automatically deploy changes. You can create a unit test that runs flipr-yaml's config validation, thereby catching any breaking changes to the config before they are released. The validation only catches syntax errors in the config. If you provide flipr-yaml the flipr rules you use in your application, it will catch some logical errors as well, like the values of a percent rule not adding up to 100%. See here for an example.

Would you like to know more?

Methods

In most cases, you should not need to call flipr-yaml's methods directly, flipr takes care of that. However, it can be useful for testing and config validation.

  • async getConfig() - Returns yaml config as an object. The first call to this method caches the config, which can be cleared by calling the async flush() method.
  • async preload() - Loads the config into cache. Does the same thing as getConfig. It's called preload to fulfill flipr's source contract.
  • async flush() - Flushes all cached values in flipr-yaml.
  • async validateConfig(rules) - Validates the yaml files based on flipr's configuration syntax. See flipr-validation for more information.

Constructor Options

  • filePath - required - string, array - The yaml config file path(s) relative to the process's cwd. Supports glob patterns based on minimatch patterns.
  • duplicateKeysOverride - bool - If true, duplicate keys in a multi-file scenario will be overridden by whichever is read last. Default is false, which results in an error thrown.

Package Sidebar

Install

npm i flipr-yaml

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

65.4 kB

Total Files

22

Last publish

Collaborators

  • gshively