config_manager 0.3.0 copy "config_manager: ^0.3.0" to clipboard
config_manager: ^0.3.0 copied to clipboard

A JSON-based configuration manager with path-based access to nested values, singleton pattern, and mixin support.

Config Manager #

A Dart configuration manager package that loads JSON configuration files and provides path-based access to configuration values.

Features #

  • Load configuration from JSON files, raw JSON strings, or in-memory maps
  • Access nested values via an explicit key path (List<String>), e.g. ['database', 'host'] — a single top-level key is a one-element list, e.g. ['appName']; an empty list [] addresses the whole configuration map
  • List support with index access (e.g. ['features', '0'])
  • Sector-based configuration, so multiple independent configs can coexist
  • Check whether a sector is loaded (isLoaded) or whether a set of key paths is present (containsKeys)
  • Skip reloading an already-loaded sector with force: false
  • Singleton-based configuration access
  • Mixin-based configuration extension for classes

Usage #

import 'package:config_manager/config_manager.dart';

void main() {
  final config = ConfigManagerSingleton();
  config.loadFromJson('config.json');

  print(config.get(['appName']));
  print(config.get(['database', 'host']));
  print(config[['database', 'credentials', 'user']]);

  print(config.isLoaded());
  print(config.containsKeys([
    ['appName'],
    ['database', 'host'],
  ]));

  // force: false is a no-op when the sector is already loaded.
  config.loadFromJson('config.json', force: false);

  // A key path is always an explicit list of segments, so a literal "."
  // inside a key name is never ambiguous with nesting.
  config.set(['database.host'], 'literal-value');
  print(config.get(['database.host']));
}

Examples #

The example/ folder has one focused file per topic, each runnable on its own (e.g. dart run example/sectors_example.dart). example/main.dart runs all of them in sequence.

  • basic_usage.dart — loading a JSON file, reading values
  • lists_and_paths.dart — lists, casting, index access
  • writes_and_edge_cases.dart — writing nested values, missing keys
  • sectors_example.dart — independent per-sector configuration
  • is_loaded_and_contains_keys.dartisLoaded and containsKeys
  • force_reload.dartforce: false no-op reload
  • nested_vs_flat_keys.dart — nested paths vs. a literal dotted key
  • mixin_extension.dartConfigExtension mixin
  • custom_extension.dart — a custom IConfigExtension implementation

License #

MIT

0
likes
0
points
354
downloads

Publisher

unverified uploader

Weekly Downloads

A JSON-based configuration manager with path-based access to nested values, singleton pattern, and mixin support.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on config_manager