yamlcfg 1.0.2 copy "yamlcfg: ^1.0.2" to clipboard
yamlcfg: ^1.0.2 copied to clipboard

A type-safe configuration file parser with support for YAML notation.

yamlcfg #

A type-safe configuration file parser with support for YAML notation.

Features #

  • Lightweight and fast
  • Type-safe
  • Fallback handlers
  • Readable and few exceptions
  • Versatile input formats

Getting started #

Add yamlcfg to your project with the command dart pub add yamlcfg.

Usage #

To use yamlcfg, simply create a new YamlCfg. The constructor takes a YamlMap, but a file can be provided via the YamlCfg.fromFile factory, or a string can be provided via the YamlCfg.fromString factory.

From there, the usage is quite simple. To retrieve the value of a field, use the get method, providing a type to check against. For example:


final yamlCfg = YamlCfg.fromFile('pubspec.yaml');
final name = yamlCfg.get<String>('name');
copied to clipboard

If the specified field does not exist, a MissingFieldException is thrown. If the field does exist, but the field is not of the specified type, a TypeMismatchException is thrown. An onFallback handler can be given to return a fallback value and avoid a MissingFieldException. For example:


final yamlCfg = YamlCfg.fromFile('pubspec.yaml');
final name = yamlCfg.get<String>('does-not-exist', () => 'backup-name');
copied to clipboard

To dig deeper in the YAML tree, use get but specify the type as YamlCfg. Alternatively, use the wrapper method into to accomplish the same thing. For example:


final yamlCfg = YamlCfg.fromFile('pubspec.yaml');
final testViaGet = yamlCfg.get<YamlCfg>('dev_dependencies').get<String>('test');

// or...

final testViaInto = yamlCfg.into('dev_dependencies').get<String>('test');
copied to clipboard
0
likes
160
points
44
downloads

Publisher

verified publishertytydraco.xyz

Weekly Downloads

2024.06.28 - 2025.01.10

A type-safe configuration file parser with support for YAML notation.

Repository

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

yaml

More

Packages that depend on yamlcfg