properties
一个简单的库,用于在 Dart 中管理属性文件(以及更多功能)
在dart中管理.properties文件
以下为英文项目原文快照,最新内容请访问 GitHub。
Properties is a simple library to manage properties files (and something more) in Dart.
The project aim is to provide a simple and lightweight implementation of properties file management for Dart adding some useful but not so common features. Code and usage are very straightforward, just have a look at the Getting Started section below.
To know something more about the released version have a look at the CHANGELOG to find the version that works best for you.
The best way to get immediately started is to have a look at the unit tests provided along with the source code.
Anyway you can go on reading this quick intro.
Using Properties you can:
Properties p = Properties.fromFile(filepath);
String value = p.get('test.key.1');
..optionally providing a default value..
String defval = p.get('test.key.X', defval:'value X');
..or a default key..
String defkey = p.get('test.key.X', defkey:'test.key.1');
int anInt = p.getInt('test.key.integer');
double aDouble = p.getDouble('test.key.double');
bool aBool = p.getBool('test.key.bool');
List<String> list = p.getList('test.key.listofvalues');
bool added = p.add('test.key.3', 'value 3', true);
and then listen to "property added" or "property updated" events
p.onAdd.listen((AddEvent e) {
eventType = e.type;
key = e.key;
value = e.value;
});
String jsonexport = p.toJSON([prefix, suffix]);
Map<String,String> filtered = p.every((s) => s.startsWith('test'));
To run the tests just run the test/properties_test.dart file.
Output on file is not supported (yet!).